index.js 1.3 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254
  1. 'use strict';
  2. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  3. var fs$1 = _interopDefault(require('fs'));
  4. var os$1 = _interopDefault(require('os'));
  5. var path$2 = _interopDefault(require('path'));
  6. var assert$1 = _interopDefault(require('assert'));
  7. var util$2 = _interopDefault(require('util'));
  8. var events$1 = _interopDefault(require('events'));
  9. var name = "prettier";
  10. var version = "1.19.1";
  11. var description = "Prettier is an opinionated code formatter";
  12. var bin = {
  13. prettier: "./bin/prettier.js"
  14. };
  15. var repository = "prettier/prettier";
  16. var homepage = "https://prettier.io";
  17. var author = "James Long";
  18. var license = "MIT";
  19. var main = "./index.js";
  20. var engines = {
  21. node: ">=8"
  22. };
  23. var dependencies = {
  24. "@angular/compiler": "8.2.13",
  25. "@babel/code-frame": "7.5.5",
  26. "@babel/parser": "7.7.3",
  27. "@glimmer/syntax": "0.41.0",
  28. "@iarna/toml": "2.2.3",
  29. "@typescript-eslint/typescript-estree": "2.6.1",
  30. "angular-estree-parser": "1.1.5",
  31. "angular-html-parser": "1.3.0",
  32. camelcase: "5.3.1",
  33. chalk: "2.4.2",
  34. "cjk-regex": "2.0.0",
  35. cosmiconfig: "5.2.1",
  36. dashify: "2.0.0",
  37. dedent: "0.7.0",
  38. diff: "4.0.1",
  39. editorconfig: "0.15.3",
  40. "editorconfig-to-prettier": "0.1.1",
  41. "escape-string-regexp": "1.0.5",
  42. esutils: "2.0.3",
  43. "find-parent-dir": "0.3.0",
  44. "find-project-root": "1.1.1",
  45. "flow-parser": "0.111.3",
  46. "get-stream": "4.1.0",
  47. globby: "6.1.0",
  48. graphql: "14.5.8",
  49. "html-element-attributes": "2.2.0",
  50. "html-styles": "1.0.0",
  51. "html-tag-names": "1.1.4",
  52. ignore: "4.0.6",
  53. "is-ci": "2.0.0",
  54. "jest-docblock": "24.9.0",
  55. "json-stable-stringify": "1.0.1",
  56. leven: "3.1.0",
  57. "lines-and-columns": "1.1.6",
  58. "linguist-languages": "7.6.0",
  59. "lodash.uniqby": "4.7.0",
  60. mem: "5.1.1",
  61. minimatch: "3.0.4",
  62. minimist: "1.2.0",
  63. "n-readlines": "1.0.0",
  64. "normalize-path": "3.0.0",
  65. "parse-srcset": "ikatyang/parse-srcset#54eb9c1cb21db5c62b4d0e275d7249516df6f0ee",
  66. "postcss-less": "2.0.0",
  67. "postcss-media-query-parser": "0.2.3",
  68. "postcss-scss": "2.0.0",
  69. "postcss-selector-parser": "2.2.3",
  70. "postcss-values-parser": "1.5.0",
  71. "regexp-util": "1.2.2",
  72. "remark-math": "1.0.6",
  73. "remark-parse": "5.0.0",
  74. resolve: "1.12.0",
  75. semver: "6.3.0",
  76. "string-width": "4.1.0",
  77. typescript: "3.7.2",
  78. "unicode-regex": "3.0.0",
  79. unified: "8.4.1",
  80. vnopts: "1.0.2",
  81. "yaml-unist-parser": "1.1.1"
  82. };
  83. var devDependencies = {
  84. "@babel/core": "7.7.2",
  85. "@babel/preset-env": "7.7.1",
  86. "@rollup/plugin-alias": "2.2.0",
  87. "@rollup/plugin-replace": "2.2.1",
  88. "babel-loader": "8.0.6",
  89. benchmark: "2.1.4",
  90. "builtin-modules": "3.1.0",
  91. codecov: "3.6.1",
  92. "cross-env": "6.0.3",
  93. eslint: "6.6.0",
  94. "eslint-config-prettier": "6.5.0",
  95. "eslint-formatter-friendly": "7.0.0",
  96. "eslint-plugin-import": "2.18.2",
  97. "eslint-plugin-prettier": "3.1.1",
  98. "eslint-plugin-react": "7.16.0",
  99. execa: "3.2.0",
  100. jest: "23.3.0",
  101. "jest-junit": "9.0.0",
  102. "jest-snapshot-serializer-ansi": "1.0.0",
  103. "jest-snapshot-serializer-raw": "1.1.0",
  104. "jest-watch-typeahead": "0.4.0",
  105. mkdirp: "0.5.1",
  106. prettier: "1.19.0",
  107. prettylint: "1.0.0",
  108. rimraf: "3.0.0",
  109. rollup: "1.26.3",
  110. "rollup-plugin-babel": "4.3.3",
  111. "rollup-plugin-commonjs": "10.1.0",
  112. "rollup-plugin-json": "4.0.0",
  113. "rollup-plugin-node-globals": "1.4.0",
  114. "rollup-plugin-node-resolve": "5.2.0",
  115. "rollup-plugin-terser": "5.1.2",
  116. shelljs: "0.8.3",
  117. "snapshot-diff": "0.4.0",
  118. "strip-ansi": "5.2.0",
  119. "synchronous-promise": "2.0.10",
  120. tempy: "0.2.1",
  121. "terser-webpack-plugin": "2.2.1",
  122. webpack: "4.41.2"
  123. };
  124. var scripts = {
  125. prepublishOnly: "echo \"Error: must publish from dist/\" && exit 1",
  126. "prepare-release": "yarn && yarn build && yarn test:dist",
  127. test: "jest",
  128. "test:dist": "node ./scripts/test-dist.js",
  129. "test-integration": "jest tests_integration",
  130. "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",
  131. "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",
  132. "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",
  133. "check-types": "tsc",
  134. lint: "cross-env EFF_NO_LINK_RULES=true eslint . --format friendly",
  135. "lint-docs": "prettylint {.,docs,website,website/blog}/*.md",
  136. "lint-dist": "eslint --no-eslintrc --no-ignore --env=browser \"dist/!(bin-prettier|index|third-party).js\"",
  137. build: "node --max-old-space-size=3072 ./scripts/build/build.js",
  138. "build-docs": "node ./scripts/build-docs.js",
  139. "check-deps": "node ./scripts/check-deps.js",
  140. spellcheck: "npx -p cspell@4.0.31 cspell {bin,scripts,src}/**/*.js {docs,website/blog,changelog_unreleased}/**/*.md"
  141. };
  142. var _package = {
  143. name: name,
  144. version: version,
  145. description: description,
  146. bin: bin,
  147. repository: repository,
  148. homepage: homepage,
  149. author: author,
  150. license: license,
  151. main: main,
  152. engines: engines,
  153. dependencies: dependencies,
  154. devDependencies: devDependencies,
  155. scripts: scripts
  156. };
  157. var _package$1 = /*#__PURE__*/Object.freeze({
  158. __proto__: null,
  159. name: name,
  160. version: version,
  161. description: description,
  162. bin: bin,
  163. repository: repository,
  164. homepage: homepage,
  165. author: author,
  166. license: license,
  167. main: main,
  168. engines: engines,
  169. dependencies: dependencies,
  170. devDependencies: devDependencies,
  171. scripts: scripts,
  172. 'default': _package
  173. });
  174. function Diff() {}
  175. Diff.prototype = {
  176. diff: function diff(oldString, newString) {
  177. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  178. var callback = options.callback;
  179. if (typeof options === 'function') {
  180. callback = options;
  181. options = {};
  182. }
  183. this.options = options;
  184. var self = this;
  185. function done(value) {
  186. if (callback) {
  187. setTimeout(function () {
  188. callback(undefined, value);
  189. }, 0);
  190. return true;
  191. } else {
  192. return value;
  193. }
  194. } // Allow subclasses to massage the input prior to running
  195. oldString = this.castInput(oldString);
  196. newString = this.castInput(newString);
  197. oldString = this.removeEmpty(this.tokenize(oldString));
  198. newString = this.removeEmpty(this.tokenize(newString));
  199. var newLen = newString.length,
  200. oldLen = oldString.length;
  201. var editLength = 1;
  202. var maxEditLength = newLen + oldLen;
  203. var bestPath = [{
  204. newPos: -1,
  205. components: []
  206. }]; // Seed editLength = 0, i.e. the content starts with the same values
  207. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  208. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  209. // Identity per the equality and tokenizer
  210. return done([{
  211. value: this.join(newString),
  212. count: newString.length
  213. }]);
  214. } // Main worker method. checks all permutations of a given edit length for acceptance.
  215. function execEditLength() {
  216. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  217. var basePath = void 0;
  218. var addPath = bestPath[diagonalPath - 1],
  219. removePath = bestPath[diagonalPath + 1],
  220. _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  221. if (addPath) {
  222. // No one else is going to attempt to use this value, clear it
  223. bestPath[diagonalPath - 1] = undefined;
  224. }
  225. var canAdd = addPath && addPath.newPos + 1 < newLen,
  226. canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
  227. if (!canAdd && !canRemove) {
  228. // If this path is a terminal then prune
  229. bestPath[diagonalPath] = undefined;
  230. continue;
  231. } // Select the diagonal that we want to branch from. We select the prior
  232. // path whose position in the new string is the farthest from the origin
  233. // and does not pass the bounds of the diff graph
  234. if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
  235. basePath = clonePath(removePath);
  236. self.pushComponent(basePath.components, undefined, true);
  237. } else {
  238. basePath = addPath; // No need to clone, we've pulled it from the list
  239. basePath.newPos++;
  240. self.pushComponent(basePath.components, true, undefined);
  241. }
  242. _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
  243. if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
  244. return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
  245. } else {
  246. // Otherwise track this path as a potential candidate and continue.
  247. bestPath[diagonalPath] = basePath;
  248. }
  249. }
  250. editLength++;
  251. } // Performs the length of edit iteration. Is a bit fugly as this has to support the
  252. // sync and async mode which is never fun. Loops over execEditLength until a value
  253. // is produced.
  254. if (callback) {
  255. (function exec() {
  256. setTimeout(function () {
  257. // This should not happen, but we want to be safe.
  258. /* istanbul ignore next */
  259. if (editLength > maxEditLength) {
  260. return callback();
  261. }
  262. if (!execEditLength()) {
  263. exec();
  264. }
  265. }, 0);
  266. })();
  267. } else {
  268. while (editLength <= maxEditLength) {
  269. var ret = execEditLength();
  270. if (ret) {
  271. return ret;
  272. }
  273. }
  274. }
  275. },
  276. pushComponent: function pushComponent(components, added, removed) {
  277. var last = components[components.length - 1];
  278. if (last && last.added === added && last.removed === removed) {
  279. // We need to clone here as the component clone operation is just
  280. // as shallow array clone
  281. components[components.length - 1] = {
  282. count: last.count + 1,
  283. added: added,
  284. removed: removed
  285. };
  286. } else {
  287. components.push({
  288. count: 1,
  289. added: added,
  290. removed: removed
  291. });
  292. }
  293. },
  294. extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
  295. var newLen = newString.length,
  296. oldLen = oldString.length,
  297. newPos = basePath.newPos,
  298. oldPos = newPos - diagonalPath,
  299. commonCount = 0;
  300. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  301. newPos++;
  302. oldPos++;
  303. commonCount++;
  304. }
  305. if (commonCount) {
  306. basePath.components.push({
  307. count: commonCount
  308. });
  309. }
  310. basePath.newPos = newPos;
  311. return oldPos;
  312. },
  313. equals: function equals(left, right) {
  314. if (this.options.comparator) {
  315. return this.options.comparator(left, right);
  316. } else {
  317. return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
  318. }
  319. },
  320. removeEmpty: function removeEmpty(array) {
  321. var ret = [];
  322. for (var i = 0; i < array.length; i++) {
  323. if (array[i]) {
  324. ret.push(array[i]);
  325. }
  326. }
  327. return ret;
  328. },
  329. castInput: function castInput(value) {
  330. return value;
  331. },
  332. tokenize: function tokenize(value) {
  333. return value.split('');
  334. },
  335. join: function join(chars) {
  336. return chars.join('');
  337. }
  338. };
  339. function buildValues(diff, components, newString, oldString, useLongestToken) {
  340. var componentPos = 0,
  341. componentLen = components.length,
  342. newPos = 0,
  343. oldPos = 0;
  344. for (; componentPos < componentLen; componentPos++) {
  345. var component = components[componentPos];
  346. if (!component.removed) {
  347. if (!component.added && useLongestToken) {
  348. var value = newString.slice(newPos, newPos + component.count);
  349. value = value.map(function (value, i) {
  350. var oldValue = oldString[oldPos + i];
  351. return oldValue.length > value.length ? oldValue : value;
  352. });
  353. component.value = diff.join(value);
  354. } else {
  355. component.value = diff.join(newString.slice(newPos, newPos + component.count));
  356. }
  357. newPos += component.count; // Common case
  358. if (!component.added) {
  359. oldPos += component.count;
  360. }
  361. } else {
  362. component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
  363. oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
  364. // The diffing algorithm is tied to add then remove output and this is the simplest
  365. // route to get the desired output with minimal overhead.
  366. if (componentPos && components[componentPos - 1].added) {
  367. var tmp = components[componentPos - 1];
  368. components[componentPos - 1] = components[componentPos];
  369. components[componentPos] = tmp;
  370. }
  371. }
  372. } // Special case handle for when one terminal is ignored (i.e. whitespace).
  373. // For this case we merge the terminal into the prior string and drop the change.
  374. // This is only available for string mode.
  375. var lastComponent = components[componentLen - 1];
  376. if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
  377. components[componentLen - 2].value += lastComponent.value;
  378. components.pop();
  379. }
  380. return components;
  381. }
  382. function clonePath(path) {
  383. return {
  384. newPos: path.newPos,
  385. components: path.components.slice(0)
  386. };
  387. }
  388. var characterDiff = new Diff();
  389. function diffChars(oldStr, newStr, options) {
  390. return characterDiff.diff(oldStr, newStr, options);
  391. }
  392. function generateOptions(options, defaults) {
  393. if (typeof options === 'function') {
  394. defaults.callback = options;
  395. } else if (options) {
  396. for (var name in options) {
  397. /* istanbul ignore else */
  398. if (options.hasOwnProperty(name)) {
  399. defaults[name] = options[name];
  400. }
  401. }
  402. }
  403. return defaults;
  404. } //
  405. // Ranges and exceptions:
  406. // Latin-1 Supplement, 0080–00FF
  407. // - U+00D7 × Multiplication sign
  408. // - U+00F7 ÷ Division sign
  409. // Latin Extended-A, 0100–017F
  410. // Latin Extended-B, 0180–024F
  411. // IPA Extensions, 0250–02AF
  412. // Spacing Modifier Letters, 02B0–02FF
  413. // - U+02C7 ˇ &#711; Caron
  414. // - U+02D8 ˘ &#728; Breve
  415. // - U+02D9 ˙ &#729; Dot Above
  416. // - U+02DA ˚ &#730; Ring Above
  417. // - U+02DB ˛ &#731; Ogonek
  418. // - U+02DC ˜ &#732; Small Tilde
  419. // - U+02DD ˝ &#733; Double Acute Accent
  420. // Latin Extended Additional, 1E00–1EFF
  421. var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
  422. var reWhitespace = /\S/;
  423. var wordDiff = new Diff();
  424. wordDiff.equals = function (left, right) {
  425. if (this.options.ignoreCase) {
  426. left = left.toLowerCase();
  427. right = right.toLowerCase();
  428. }
  429. return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
  430. };
  431. wordDiff.tokenize = function (value) {
  432. 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.
  433. for (var i = 0; i < tokens.length - 1; i++) {
  434. // If we have an empty string in the next field and we have only word chars before and after, merge
  435. if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
  436. tokens[i] += tokens[i + 2];
  437. tokens.splice(i + 1, 2);
  438. i--;
  439. }
  440. }
  441. return tokens;
  442. };
  443. function diffWords(oldStr, newStr, options) {
  444. options = generateOptions(options, {
  445. ignoreWhitespace: true
  446. });
  447. return wordDiff.diff(oldStr, newStr, options);
  448. }
  449. function diffWordsWithSpace(oldStr, newStr, options) {
  450. return wordDiff.diff(oldStr, newStr, options);
  451. }
  452. var lineDiff = new Diff();
  453. lineDiff.tokenize = function (value) {
  454. var retLines = [],
  455. linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
  456. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  457. linesAndNewlines.pop();
  458. } // Merge the content and line separators into single tokens
  459. for (var i = 0; i < linesAndNewlines.length; i++) {
  460. var line = linesAndNewlines[i];
  461. if (i % 2 && !this.options.newlineIsToken) {
  462. retLines[retLines.length - 1] += line;
  463. } else {
  464. if (this.options.ignoreWhitespace) {
  465. line = line.trim();
  466. }
  467. retLines.push(line);
  468. }
  469. }
  470. return retLines;
  471. };
  472. function diffLines(oldStr, newStr, callback) {
  473. return lineDiff.diff(oldStr, newStr, callback);
  474. }
  475. function diffTrimmedLines(oldStr, newStr, callback) {
  476. var options = generateOptions(callback, {
  477. ignoreWhitespace: true
  478. });
  479. return lineDiff.diff(oldStr, newStr, options);
  480. }
  481. var sentenceDiff = new Diff();
  482. sentenceDiff.tokenize = function (value) {
  483. return value.split(/(\S.+?[.!?])(?=\s+|$)/);
  484. };
  485. function diffSentences(oldStr, newStr, callback) {
  486. return sentenceDiff.diff(oldStr, newStr, callback);
  487. }
  488. var cssDiff = new Diff();
  489. cssDiff.tokenize = function (value) {
  490. return value.split(/([{}:;,]|\s+)/);
  491. };
  492. function diffCss(oldStr, newStr, callback) {
  493. return cssDiff.diff(oldStr, newStr, callback);
  494. }
  495. function _typeof(obj) {
  496. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  497. _typeof = function _typeof(obj) {
  498. return typeof obj;
  499. };
  500. } else {
  501. _typeof = function _typeof(obj) {
  502. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  503. };
  504. }
  505. return _typeof(obj);
  506. }
  507. function _toConsumableArray(arr) {
  508. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
  509. }
  510. function _arrayWithoutHoles(arr) {
  511. if (Array.isArray(arr)) {
  512. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  513. arr2[i] = arr[i];
  514. }
  515. return arr2;
  516. }
  517. }
  518. function _iterableToArray(iter) {
  519. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  520. }
  521. function _nonIterableSpread() {
  522. throw new TypeError("Invalid attempt to spread non-iterable instance");
  523. }
  524. var objectPrototypeToString = Object.prototype.toString;
  525. var jsonDiff = new Diff(); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  526. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  527. jsonDiff.useLongestToken = true;
  528. jsonDiff.tokenize = lineDiff.tokenize;
  529. jsonDiff.castInput = function (value) {
  530. var _this$options = this.options,
  531. undefinedReplacement = _this$options.undefinedReplacement,
  532. _this$options$stringi = _this$options.stringifyReplacer,
  533. stringifyReplacer = _this$options$stringi === void 0 ? function (k, v) {
  534. return typeof v === 'undefined' ? undefinedReplacement : v;
  535. } : _this$options$stringi;
  536. return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, ' ');
  537. };
  538. jsonDiff.equals = function (left, right) {
  539. return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
  540. };
  541. function diffJson(oldObj, newObj, options) {
  542. return jsonDiff.diff(oldObj, newObj, options);
  543. } // This function handles the presence of circular references by bailing out when encountering an
  544. // object that is already on the "stack" of items being processed. Accepts an optional replacer
  545. function canonicalize(obj, stack, replacementStack, replacer, key) {
  546. stack = stack || [];
  547. replacementStack = replacementStack || [];
  548. if (replacer) {
  549. obj = replacer(key, obj);
  550. }
  551. var i;
  552. for (i = 0; i < stack.length; i += 1) {
  553. if (stack[i] === obj) {
  554. return replacementStack[i];
  555. }
  556. }
  557. var canonicalizedObj;
  558. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  559. stack.push(obj);
  560. canonicalizedObj = new Array(obj.length);
  561. replacementStack.push(canonicalizedObj);
  562. for (i = 0; i < obj.length; i += 1) {
  563. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
  564. }
  565. stack.pop();
  566. replacementStack.pop();
  567. return canonicalizedObj;
  568. }
  569. if (obj && obj.toJSON) {
  570. obj = obj.toJSON();
  571. }
  572. if (_typeof(obj) === 'object' && obj !== null) {
  573. stack.push(obj);
  574. canonicalizedObj = {};
  575. replacementStack.push(canonicalizedObj);
  576. var sortedKeys = [],
  577. _key;
  578. for (_key in obj) {
  579. /* istanbul ignore else */
  580. if (obj.hasOwnProperty(_key)) {
  581. sortedKeys.push(_key);
  582. }
  583. }
  584. sortedKeys.sort();
  585. for (i = 0; i < sortedKeys.length; i += 1) {
  586. _key = sortedKeys[i];
  587. canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
  588. }
  589. stack.pop();
  590. replacementStack.pop();
  591. } else {
  592. canonicalizedObj = obj;
  593. }
  594. return canonicalizedObj;
  595. }
  596. var arrayDiff = new Diff();
  597. arrayDiff.tokenize = function (value) {
  598. return value.slice();
  599. };
  600. arrayDiff.join = arrayDiff.removeEmpty = function (value) {
  601. return value;
  602. };
  603. function diffArrays(oldArr, newArr, callback) {
  604. return arrayDiff.diff(oldArr, newArr, callback);
  605. }
  606. function parsePatch(uniDiff) {
  607. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  608. var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
  609. delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  610. list = [],
  611. i = 0;
  612. function parseIndex() {
  613. var index = {};
  614. list.push(index); // Parse diff metadata
  615. while (i < diffstr.length) {
  616. var line = diffstr[i]; // File header found, end parsing diff metadata
  617. if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
  618. break;
  619. } // Diff index
  620. var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
  621. if (header) {
  622. index.index = header[1];
  623. }
  624. i++;
  625. } // Parse file headers if they are defined. Unified diff requires them, but
  626. // there's no technical issues to have an isolated hunk without file header
  627. parseFileHeader(index);
  628. parseFileHeader(index); // Parse hunks
  629. index.hunks = [];
  630. while (i < diffstr.length) {
  631. var _line = diffstr[i];
  632. if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
  633. break;
  634. } else if (/^@@/.test(_line)) {
  635. index.hunks.push(parseHunk());
  636. } else if (_line && options.strict) {
  637. // Ignore unexpected content unless in strict mode
  638. throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
  639. } else {
  640. i++;
  641. }
  642. }
  643. } // Parses the --- and +++ headers, if none are found, no lines
  644. // are consumed.
  645. function parseFileHeader(index) {
  646. var fileHeader = /^(---|\+\+\+)\s+(.*)$/.exec(diffstr[i]);
  647. if (fileHeader) {
  648. var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
  649. var data = fileHeader[2].split('\t', 2);
  650. var fileName = data[0].replace(/\\\\/g, '\\');
  651. if (/^".*"$/.test(fileName)) {
  652. fileName = fileName.substr(1, fileName.length - 2);
  653. }
  654. index[keyPrefix + 'FileName'] = fileName;
  655. index[keyPrefix + 'Header'] = (data[1] || '').trim();
  656. i++;
  657. }
  658. } // Parses a hunk
  659. // This assumes that we are at the start of a hunk.
  660. function parseHunk() {
  661. var chunkHeaderIndex = i,
  662. chunkHeaderLine = diffstr[i++],
  663. chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
  664. var hunk = {
  665. oldStart: +chunkHeader[1],
  666. oldLines: +chunkHeader[2] || 1,
  667. newStart: +chunkHeader[3],
  668. newLines: +chunkHeader[4] || 1,
  669. lines: [],
  670. linedelimiters: []
  671. };
  672. var addCount = 0,
  673. removeCount = 0;
  674. for (; i < diffstr.length; i++) {
  675. // Lines starting with '---' could be mistaken for the "remove line" operation
  676. // But they could be the header for the next file. Therefore prune such cases out.
  677. if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
  678. break;
  679. }
  680. var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
  681. if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
  682. hunk.lines.push(diffstr[i]);
  683. hunk.linedelimiters.push(delimiters[i] || '\n');
  684. if (operation === '+') {
  685. addCount++;
  686. } else if (operation === '-') {
  687. removeCount++;
  688. } else if (operation === ' ') {
  689. addCount++;
  690. removeCount++;
  691. }
  692. } else {
  693. break;
  694. }
  695. } // Handle the empty block count case
  696. if (!addCount && hunk.newLines === 1) {
  697. hunk.newLines = 0;
  698. }
  699. if (!removeCount && hunk.oldLines === 1) {
  700. hunk.oldLines = 0;
  701. } // Perform optional sanity checking
  702. if (options.strict) {
  703. if (addCount !== hunk.newLines) {
  704. throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  705. }
  706. if (removeCount !== hunk.oldLines) {
  707. throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  708. }
  709. }
  710. return hunk;
  711. }
  712. while (i < diffstr.length) {
  713. parseIndex();
  714. }
  715. return list;
  716. } // Iterator that traverses in the range of [min, max], stepping
  717. // by distance from a given start position. I.e. for [0, 4], with
  718. // start of 2, this will iterate 2, 3, 1, 4, 0.
  719. function distanceIterator(start, minLine, maxLine) {
  720. var wantForward = true,
  721. backwardExhausted = false,
  722. forwardExhausted = false,
  723. localOffset = 1;
  724. return function iterator() {
  725. if (wantForward && !forwardExhausted) {
  726. if (backwardExhausted) {
  727. localOffset++;
  728. } else {
  729. wantForward = false;
  730. } // Check if trying to fit beyond text length, and if not, check it fits
  731. // after offset location (or desired location on first iteration)
  732. if (start + localOffset <= maxLine) {
  733. return localOffset;
  734. }
  735. forwardExhausted = true;
  736. }
  737. if (!backwardExhausted) {
  738. if (!forwardExhausted) {
  739. wantForward = true;
  740. } // Check if trying to fit before text beginning, and if not, check it fits
  741. // before offset location
  742. if (minLine <= start - localOffset) {
  743. return -localOffset++;
  744. }
  745. backwardExhausted = true;
  746. return iterator();
  747. } // We tried to fit hunk before text beginning and beyond text length, then
  748. // hunk can't fit on the text. Return undefined
  749. };
  750. }
  751. function applyPatch(source, uniDiff) {
  752. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  753. if (typeof uniDiff === 'string') {
  754. uniDiff = parsePatch(uniDiff);
  755. }
  756. if (Array.isArray(uniDiff)) {
  757. if (uniDiff.length > 1) {
  758. throw new Error('applyPatch only works with a single input.');
  759. }
  760. uniDiff = uniDiff[0];
  761. } // Apply the diff to the input
  762. var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
  763. delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  764. hunks = uniDiff.hunks,
  765. compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) {
  766. return line === patchContent;
  767. },
  768. errorCount = 0,
  769. fuzzFactor = options.fuzzFactor || 0,
  770. minLine = 0,
  771. offset = 0,
  772. removeEOFNL,
  773. addEOFNL;
  774. /**
  775. * Checks if the hunk exactly fits on the provided location
  776. */
  777. function hunkFits(hunk, toPos) {
  778. for (var j = 0; j < hunk.lines.length; j++) {
  779. var line = hunk.lines[j],
  780. operation = line.length > 0 ? line[0] : ' ',
  781. content = line.length > 0 ? line.substr(1) : line;
  782. if (operation === ' ' || operation === '-') {
  783. // Context sanity check
  784. if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
  785. errorCount++;
  786. if (errorCount > fuzzFactor) {
  787. return false;
  788. }
  789. }
  790. toPos++;
  791. }
  792. }
  793. return true;
  794. } // Search best fit offsets for each hunk based on the previous ones
  795. for (var i = 0; i < hunks.length; i++) {
  796. var hunk = hunks[i],
  797. maxLine = lines.length - hunk.oldLines,
  798. localOffset = 0,
  799. toPos = offset + hunk.oldStart - 1;
  800. var iterator = distanceIterator(toPos, minLine, maxLine);
  801. for (; localOffset !== undefined; localOffset = iterator()) {
  802. if (hunkFits(hunk, toPos + localOffset)) {
  803. hunk.offset = offset += localOffset;
  804. break;
  805. }
  806. }
  807. if (localOffset === undefined) {
  808. return false;
  809. } // Set lower text limit to end of the current hunk, so next ones don't try
  810. // to fit over already patched text
  811. minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
  812. } // Apply patch hunks
  813. var diffOffset = 0;
  814. for (var _i = 0; _i < hunks.length; _i++) {
  815. var _hunk = hunks[_i],
  816. _toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
  817. diffOffset += _hunk.newLines - _hunk.oldLines;
  818. if (_toPos < 0) {
  819. // Creating a new file
  820. _toPos = 0;
  821. }
  822. for (var j = 0; j < _hunk.lines.length; j++) {
  823. var line = _hunk.lines[j],
  824. operation = line.length > 0 ? line[0] : ' ',
  825. content = line.length > 0 ? line.substr(1) : line,
  826. delimiter = _hunk.linedelimiters[j];
  827. if (operation === ' ') {
  828. _toPos++;
  829. } else if (operation === '-') {
  830. lines.splice(_toPos, 1);
  831. delimiters.splice(_toPos, 1);
  832. /* istanbul ignore else */
  833. } else if (operation === '+') {
  834. lines.splice(_toPos, 0, content);
  835. delimiters.splice(_toPos, 0, delimiter);
  836. _toPos++;
  837. } else if (operation === '\\') {
  838. var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
  839. if (previousOperation === '+') {
  840. removeEOFNL = true;
  841. } else if (previousOperation === '-') {
  842. addEOFNL = true;
  843. }
  844. }
  845. }
  846. } // Handle EOFNL insertion/removal
  847. if (removeEOFNL) {
  848. while (!lines[lines.length - 1]) {
  849. lines.pop();
  850. delimiters.pop();
  851. }
  852. } else if (addEOFNL) {
  853. lines.push('');
  854. delimiters.push('\n');
  855. }
  856. for (var _k = 0; _k < lines.length - 1; _k++) {
  857. lines[_k] = lines[_k] + delimiters[_k];
  858. }
  859. return lines.join('');
  860. } // Wrapper that supports multiple file patches via callbacks.
  861. function applyPatches(uniDiff, options) {
  862. if (typeof uniDiff === 'string') {
  863. uniDiff = parsePatch(uniDiff);
  864. }
  865. var currentIndex = 0;
  866. function processIndex() {
  867. var index = uniDiff[currentIndex++];
  868. if (!index) {
  869. return options.complete();
  870. }
  871. options.loadFile(index, function (err, data) {
  872. if (err) {
  873. return options.complete(err);
  874. }
  875. var updatedContent = applyPatch(data, index, options);
  876. options.patched(index, updatedContent, function (err) {
  877. if (err) {
  878. return options.complete(err);
  879. }
  880. processIndex();
  881. });
  882. });
  883. }
  884. processIndex();
  885. }
  886. function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  887. if (!options) {
  888. options = {};
  889. }
  890. if (typeof options.context === 'undefined') {
  891. options.context = 4;
  892. }
  893. var diff = diffLines(oldStr, newStr, options);
  894. diff.push({
  895. value: '',
  896. lines: []
  897. }); // Append an empty value to make cleanup easier
  898. function contextLines(lines) {
  899. return lines.map(function (entry) {
  900. return ' ' + entry;
  901. });
  902. }
  903. var hunks = [];
  904. var oldRangeStart = 0,
  905. newRangeStart = 0,
  906. curRange = [],
  907. oldLine = 1,
  908. newLine = 1;
  909. var _loop = function _loop(i) {
  910. var current = diff[i],
  911. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  912. current.lines = lines;
  913. if (current.added || current.removed) {
  914. var _curRange; // If we have previous context, start with that
  915. if (!oldRangeStart) {
  916. var prev = diff[i - 1];
  917. oldRangeStart = oldLine;
  918. newRangeStart = newLine;
  919. if (prev) {
  920. curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
  921. oldRangeStart -= curRange.length;
  922. newRangeStart -= curRange.length;
  923. }
  924. } // Output our changes
  925. (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
  926. return (current.added ? '+' : '-') + entry;
  927. }))); // Track the updated file position
  928. if (current.added) {
  929. newLine += lines.length;
  930. } else {
  931. oldLine += lines.length;
  932. }
  933. } else {
  934. // Identical context lines. Track line changes
  935. if (oldRangeStart) {
  936. // Close out any changes that have been output (or join overlapping)
  937. if (lines.length <= options.context * 2 && i < diff.length - 2) {
  938. var _curRange2; // Overlapping
  939. (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
  940. } else {
  941. var _curRange3; // end the range and output
  942. var contextSize = Math.min(lines.length, options.context);
  943. (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
  944. var hunk = {
  945. oldStart: oldRangeStart,
  946. oldLines: oldLine - oldRangeStart + contextSize,
  947. newStart: newRangeStart,
  948. newLines: newLine - newRangeStart + contextSize,
  949. lines: curRange
  950. };
  951. if (i >= diff.length - 2 && lines.length <= options.context) {
  952. // EOF is inside this hunk
  953. var oldEOFNewline = /\n$/.test(oldStr);
  954. var newEOFNewline = /\n$/.test(newStr);
  955. var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
  956. if (!oldEOFNewline && noNlBeforeAdds) {
  957. // special case: old has no eol and no trailing context; no-nl can end up before adds
  958. curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
  959. }
  960. if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
  961. curRange.push('\\ No newline at end of file');
  962. }
  963. }
  964. hunks.push(hunk);
  965. oldRangeStart = 0;
  966. newRangeStart = 0;
  967. curRange = [];
  968. }
  969. }
  970. oldLine += lines.length;
  971. newLine += lines.length;
  972. }
  973. };
  974. for (var i = 0; i < diff.length; i++) {
  975. _loop(i);
  976. }
  977. return {
  978. oldFileName: oldFileName,
  979. newFileName: newFileName,
  980. oldHeader: oldHeader,
  981. newHeader: newHeader,
  982. hunks: hunks
  983. };
  984. }
  985. function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  986. var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
  987. var ret = [];
  988. if (oldFileName == newFileName) {
  989. ret.push('Index: ' + oldFileName);
  990. }
  991. ret.push('===================================================================');
  992. ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
  993. ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
  994. for (var i = 0; i < diff.hunks.length; i++) {
  995. var hunk = diff.hunks[i];
  996. ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
  997. ret.push.apply(ret, hunk.lines);
  998. }
  999. return ret.join('\n') + '\n';
  1000. }
  1001. function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
  1002. return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
  1003. }
  1004. function arrayEqual(a, b) {
  1005. if (a.length !== b.length) {
  1006. return false;
  1007. }
  1008. return arrayStartsWith(a, b);
  1009. }
  1010. function arrayStartsWith(array, start) {
  1011. if (start.length > array.length) {
  1012. return false;
  1013. }
  1014. for (var i = 0; i < start.length; i++) {
  1015. if (start[i] !== array[i]) {
  1016. return false;
  1017. }
  1018. }
  1019. return true;
  1020. }
  1021. function calcLineCount(hunk) {
  1022. var _calcOldNewLineCount = calcOldNewLineCount(hunk.lines),
  1023. oldLines = _calcOldNewLineCount.oldLines,
  1024. newLines = _calcOldNewLineCount.newLines;
  1025. if (oldLines !== undefined) {
  1026. hunk.oldLines = oldLines;
  1027. } else {
  1028. delete hunk.oldLines;
  1029. }
  1030. if (newLines !== undefined) {
  1031. hunk.newLines = newLines;
  1032. } else {
  1033. delete hunk.newLines;
  1034. }
  1035. }
  1036. function merge(mine, theirs, base) {
  1037. mine = loadPatch(mine, base);
  1038. theirs = loadPatch(theirs, base);
  1039. var ret = {}; // For index we just let it pass through as it doesn't have any necessary meaning.
  1040. // Leaving sanity checks on this to the API consumer that may know more about the
  1041. // meaning in their own context.
  1042. if (mine.index || theirs.index) {
  1043. ret.index = mine.index || theirs.index;
  1044. }
  1045. if (mine.newFileName || theirs.newFileName) {
  1046. if (!fileNameChanged(mine)) {
  1047. // No header or no change in ours, use theirs (and ours if theirs does not exist)
  1048. ret.oldFileName = theirs.oldFileName || mine.oldFileName;
  1049. ret.newFileName = theirs.newFileName || mine.newFileName;
  1050. ret.oldHeader = theirs.oldHeader || mine.oldHeader;
  1051. ret.newHeader = theirs.newHeader || mine.newHeader;
  1052. } else if (!fileNameChanged(theirs)) {
  1053. // No header or no change in theirs, use ours
  1054. ret.oldFileName = mine.oldFileName;
  1055. ret.newFileName = mine.newFileName;
  1056. ret.oldHeader = mine.oldHeader;
  1057. ret.newHeader = mine.newHeader;
  1058. } else {
  1059. // Both changed... figure it out
  1060. ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
  1061. ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
  1062. ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
  1063. ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
  1064. }
  1065. }
  1066. ret.hunks = [];
  1067. var mineIndex = 0,
  1068. theirsIndex = 0,
  1069. mineOffset = 0,
  1070. theirsOffset = 0;
  1071. while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
  1072. var mineCurrent = mine.hunks[mineIndex] || {
  1073. oldStart: Infinity
  1074. },
  1075. theirsCurrent = theirs.hunks[theirsIndex] || {
  1076. oldStart: Infinity
  1077. };
  1078. if (hunkBefore(mineCurrent, theirsCurrent)) {
  1079. // This patch does not overlap with any of the others, yay.
  1080. ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
  1081. mineIndex++;
  1082. theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
  1083. } else if (hunkBefore(theirsCurrent, mineCurrent)) {
  1084. // This patch does not overlap with any of the others, yay.
  1085. ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
  1086. theirsIndex++;
  1087. mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
  1088. } else {
  1089. // Overlap, merge as best we can
  1090. var mergedHunk = {
  1091. oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
  1092. oldLines: 0,
  1093. newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
  1094. newLines: 0,
  1095. lines: []
  1096. };
  1097. mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
  1098. theirsIndex++;
  1099. mineIndex++;
  1100. ret.hunks.push(mergedHunk);
  1101. }
  1102. }
  1103. return ret;
  1104. }
  1105. function loadPatch(param, base) {
  1106. if (typeof param === 'string') {
  1107. if (/^@@/m.test(param) || /^Index:/m.test(param)) {
  1108. return parsePatch(param)[0];
  1109. }
  1110. if (!base) {
  1111. throw new Error('Must provide a base reference or pass in a patch');
  1112. }
  1113. return structuredPatch(undefined, undefined, base, param);
  1114. }
  1115. return param;
  1116. }
  1117. function fileNameChanged(patch) {
  1118. return patch.newFileName && patch.newFileName !== patch.oldFileName;
  1119. }
  1120. function selectField(index, mine, theirs) {
  1121. if (mine === theirs) {
  1122. return mine;
  1123. } else {
  1124. index.conflict = true;
  1125. return {
  1126. mine: mine,
  1127. theirs: theirs
  1128. };
  1129. }
  1130. }
  1131. function hunkBefore(test, check) {
  1132. return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
  1133. }
  1134. function cloneHunk(hunk, offset) {
  1135. return {
  1136. oldStart: hunk.oldStart,
  1137. oldLines: hunk.oldLines,
  1138. newStart: hunk.newStart + offset,
  1139. newLines: hunk.newLines,
  1140. lines: hunk.lines
  1141. };
  1142. }
  1143. function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
  1144. // This will generally result in a conflicted hunk, but there are cases where the context
  1145. // is the only overlap where we can successfully merge the content here.
  1146. var mine = {
  1147. offset: mineOffset,
  1148. lines: mineLines,
  1149. index: 0
  1150. },
  1151. their = {
  1152. offset: theirOffset,
  1153. lines: theirLines,
  1154. index: 0
  1155. }; // Handle any leading content
  1156. insertLeading(hunk, mine, their);
  1157. insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each.
  1158. while (mine.index < mine.lines.length && their.index < their.lines.length) {
  1159. var mineCurrent = mine.lines[mine.index],
  1160. theirCurrent = their.lines[their.index];
  1161. if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
  1162. // Both modified ...
  1163. mutualChange(hunk, mine, their);
  1164. } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
  1165. var _hunk$lines; // Mine inserted
  1166. (_hunk$lines = hunk.lines).push.apply(_hunk$lines, _toConsumableArray(collectChange(mine)));
  1167. } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
  1168. var _hunk$lines2; // Theirs inserted
  1169. (_hunk$lines2 = hunk.lines).push.apply(_hunk$lines2, _toConsumableArray(collectChange(their)));
  1170. } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
  1171. // Mine removed or edited
  1172. removal(hunk, mine, their);
  1173. } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
  1174. // Their removed or edited
  1175. removal(hunk, their, mine, true);
  1176. } else if (mineCurrent === theirCurrent) {
  1177. // Context identity
  1178. hunk.lines.push(mineCurrent);
  1179. mine.index++;
  1180. their.index++;
  1181. } else {
  1182. // Context mismatch
  1183. conflict(hunk, collectChange(mine), collectChange(their));
  1184. }
  1185. } // Now push anything that may be remaining
  1186. insertTrailing(hunk, mine);
  1187. insertTrailing(hunk, their);
  1188. calcLineCount(hunk);
  1189. }
  1190. function mutualChange(hunk, mine, their) {
  1191. var myChanges = collectChange(mine),
  1192. theirChanges = collectChange(their);
  1193. if (allRemoves(myChanges) && allRemoves(theirChanges)) {
  1194. // Special case for remove changes that are supersets of one another
  1195. if (arrayStartsWith(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
  1196. var _hunk$lines3;
  1197. (_hunk$lines3 = hunk.lines).push.apply(_hunk$lines3, _toConsumableArray(myChanges));
  1198. return;
  1199. } else if (arrayStartsWith(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
  1200. var _hunk$lines4;
  1201. (_hunk$lines4 = hunk.lines).push.apply(_hunk$lines4, _toConsumableArray(theirChanges));
  1202. return;
  1203. }
  1204. } else if (arrayEqual(myChanges, theirChanges)) {
  1205. var _hunk$lines5;
  1206. (_hunk$lines5 = hunk.lines).push.apply(_hunk$lines5, _toConsumableArray(myChanges));
  1207. return;
  1208. }
  1209. conflict(hunk, myChanges, theirChanges);
  1210. }
  1211. function removal(hunk, mine, their, swap) {
  1212. var myChanges = collectChange(mine),
  1213. theirChanges = collectContext(their, myChanges);
  1214. if (theirChanges.merged) {
  1215. var _hunk$lines6;
  1216. (_hunk$lines6 = hunk.lines).push.apply(_hunk$lines6, _toConsumableArray(theirChanges.merged));
  1217. } else {
  1218. conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
  1219. }
  1220. }
  1221. function conflict(hunk, mine, their) {
  1222. hunk.conflict = true;
  1223. hunk.lines.push({
  1224. conflict: true,
  1225. mine: mine,
  1226. theirs: their
  1227. });
  1228. }
  1229. function insertLeading(hunk, insert, their) {
  1230. while (insert.offset < their.offset && insert.index < insert.lines.length) {
  1231. var line = insert.lines[insert.index++];
  1232. hunk.lines.push(line);
  1233. insert.offset++;
  1234. }
  1235. }
  1236. function insertTrailing(hunk, insert) {
  1237. while (insert.index < insert.lines.length) {
  1238. var line = insert.lines[insert.index++];
  1239. hunk.lines.push(line);
  1240. }
  1241. }
  1242. function collectChange(state) {
  1243. var ret = [],
  1244. operation = state.lines[state.index][0];
  1245. while (state.index < state.lines.length) {
  1246. var line = state.lines[state.index]; // Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
  1247. if (operation === '-' && line[0] === '+') {
  1248. operation = '+';
  1249. }
  1250. if (operation === line[0]) {
  1251. ret.push(line);
  1252. state.index++;
  1253. } else {
  1254. break;
  1255. }
  1256. }
  1257. return ret;
  1258. }
  1259. function collectContext(state, matchChanges) {
  1260. var changes = [],
  1261. merged = [],
  1262. matchIndex = 0,
  1263. contextChanges = false,
  1264. conflicted = false;
  1265. while (matchIndex < matchChanges.length && state.index < state.lines.length) {
  1266. var change = state.lines[state.index],
  1267. match = matchChanges[matchIndex]; // Once we've hit our add, then we are done
  1268. if (match[0] === '+') {
  1269. break;
  1270. }
  1271. contextChanges = contextChanges || change[0] !== ' ';
  1272. merged.push(match);
  1273. matchIndex++; // Consume any additions in the other block as a conflict to attempt
  1274. // to pull in the remaining context after this
  1275. if (change[0] === '+') {
  1276. conflicted = true;
  1277. while (change[0] === '+') {
  1278. changes.push(change);
  1279. change = state.lines[++state.index];
  1280. }
  1281. }
  1282. if (match.substr(1) === change.substr(1)) {
  1283. changes.push(change);
  1284. state.index++;
  1285. } else {
  1286. conflicted = true;
  1287. }
  1288. }
  1289. if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
  1290. conflicted = true;
  1291. }
  1292. if (conflicted) {
  1293. return changes;
  1294. }
  1295. while (matchIndex < matchChanges.length) {
  1296. merged.push(matchChanges[matchIndex++]);
  1297. }
  1298. return {
  1299. merged: merged,
  1300. changes: changes
  1301. };
  1302. }
  1303. function allRemoves(changes) {
  1304. return changes.reduce(function (prev, change) {
  1305. return prev && change[0] === '-';
  1306. }, true);
  1307. }
  1308. function skipRemoveSuperset(state, removeChanges, delta) {
  1309. for (var i = 0; i < delta; i++) {
  1310. var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
  1311. if (state.lines[state.index + i] !== ' ' + changeContent) {
  1312. return false;
  1313. }
  1314. }
  1315. state.index += delta;
  1316. return true;
  1317. }
  1318. function calcOldNewLineCount(lines) {
  1319. var oldLines = 0;
  1320. var newLines = 0;
  1321. lines.forEach(function (line) {
  1322. if (typeof line !== 'string') {
  1323. var myCount = calcOldNewLineCount(line.mine);
  1324. var theirCount = calcOldNewLineCount(line.theirs);
  1325. if (oldLines !== undefined) {
  1326. if (myCount.oldLines === theirCount.oldLines) {
  1327. oldLines += myCount.oldLines;
  1328. } else {
  1329. oldLines = undefined;
  1330. }
  1331. }
  1332. if (newLines !== undefined) {
  1333. if (myCount.newLines === theirCount.newLines) {
  1334. newLines += myCount.newLines;
  1335. } else {
  1336. newLines = undefined;
  1337. }
  1338. }
  1339. } else {
  1340. if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
  1341. newLines++;
  1342. }
  1343. if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
  1344. oldLines++;
  1345. }
  1346. }
  1347. });
  1348. return {
  1349. oldLines: oldLines,
  1350. newLines: newLines
  1351. };
  1352. } // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  1353. function convertChangesToDMP(changes) {
  1354. var ret = [],
  1355. change,
  1356. operation;
  1357. for (var i = 0; i < changes.length; i++) {
  1358. change = changes[i];
  1359. if (change.added) {
  1360. operation = 1;
  1361. } else if (change.removed) {
  1362. operation = -1;
  1363. } else {
  1364. operation = 0;
  1365. }
  1366. ret.push([operation, change.value]);
  1367. }
  1368. return ret;
  1369. }
  1370. function convertChangesToXML(changes) {
  1371. var ret = [];
  1372. for (var i = 0; i < changes.length; i++) {
  1373. var change = changes[i];
  1374. if (change.added) {
  1375. ret.push('<ins>');
  1376. } else if (change.removed) {
  1377. ret.push('<del>');
  1378. }
  1379. ret.push(escapeHTML(change.value));
  1380. if (change.added) {
  1381. ret.push('</ins>');
  1382. } else if (change.removed) {
  1383. ret.push('</del>');
  1384. }
  1385. }
  1386. return ret.join('');
  1387. }
  1388. function escapeHTML(s) {
  1389. var n = s;
  1390. n = n.replace(/&/g, '&amp;');
  1391. n = n.replace(/</g, '&lt;');
  1392. n = n.replace(/>/g, '&gt;');
  1393. n = n.replace(/"/g, '&quot;');
  1394. return n;
  1395. }
  1396. var index_es6 = /*#__PURE__*/Object.freeze({
  1397. __proto__: null,
  1398. Diff: Diff,
  1399. diffChars: diffChars,
  1400. diffWords: diffWords,
  1401. diffWordsWithSpace: diffWordsWithSpace,
  1402. diffLines: diffLines,
  1403. diffTrimmedLines: diffTrimmedLines,
  1404. diffSentences: diffSentences,
  1405. diffCss: diffCss,
  1406. diffJson: diffJson,
  1407. diffArrays: diffArrays,
  1408. structuredPatch: structuredPatch,
  1409. createTwoFilesPatch: createTwoFilesPatch,
  1410. createPatch: createPatch,
  1411. applyPatch: applyPatch,
  1412. applyPatches: applyPatches,
  1413. parsePatch: parsePatch,
  1414. merge: merge,
  1415. convertChangesToDMP: convertChangesToDMP,
  1416. convertChangesToXML: convertChangesToXML,
  1417. canonicalize: canonicalize
  1418. });
  1419. /*!
  1420. * normalize-path <https://github.com/jonschlinkert/normalize-path>
  1421. *
  1422. * Copyright (c) 2014-2018, Jon Schlinkert.
  1423. * Released under the MIT License.
  1424. */
  1425. var normalizePath = function normalizePath(path, stripTrailing) {
  1426. if (typeof path !== 'string') {
  1427. throw new TypeError('expected path to be a string');
  1428. }
  1429. if (path === '\\' || path === '/') return '/';
  1430. var len = path.length;
  1431. if (len <= 1) return path; // ensure that win32 namespaces has two leading slashes, so that the path is
  1432. // handled properly by the win32 version of path.parse() after being normalized
  1433. // https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
  1434. var prefix = '';
  1435. if (len > 4 && path[3] === '\\') {
  1436. var ch = path[2];
  1437. if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') {
  1438. path = path.slice(2);
  1439. prefix = '//';
  1440. }
  1441. }
  1442. var segs = path.split(/[/\\]+/);
  1443. if (stripTrailing !== false && segs[segs.length - 1] === '') {
  1444. segs.pop();
  1445. }
  1446. return prefix + segs.join('/');
  1447. };
  1448. function _classCallCheck(instance, Constructor) {
  1449. if (!(instance instanceof Constructor)) {
  1450. throw new TypeError("Cannot call a class as a function");
  1451. }
  1452. }
  1453. function _defineProperties(target, props) {
  1454. for (var i = 0; i < props.length; i++) {
  1455. var descriptor = props[i];
  1456. descriptor.enumerable = descriptor.enumerable || false;
  1457. descriptor.configurable = true;
  1458. if ("value" in descriptor) descriptor.writable = true;
  1459. Object.defineProperty(target, descriptor.key, descriptor);
  1460. }
  1461. }
  1462. function _createClass(Constructor, protoProps, staticProps) {
  1463. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  1464. if (staticProps) _defineProperties(Constructor, staticProps);
  1465. return Constructor;
  1466. }
  1467. function _inherits(subClass, superClass) {
  1468. if (typeof superClass !== "function" && superClass !== null) {
  1469. throw new TypeError("Super expression must either be null or a function");
  1470. }
  1471. subClass.prototype = Object.create(superClass && superClass.prototype, {
  1472. constructor: {
  1473. value: subClass,
  1474. writable: true,
  1475. configurable: true
  1476. }
  1477. });
  1478. if (superClass) _setPrototypeOf(subClass, superClass);
  1479. }
  1480. function _getPrototypeOf(o) {
  1481. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  1482. return o.__proto__ || Object.getPrototypeOf(o);
  1483. };
  1484. return _getPrototypeOf(o);
  1485. }
  1486. function _setPrototypeOf(o, p) {
  1487. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1488. o.__proto__ = p;
  1489. return o;
  1490. };
  1491. return _setPrototypeOf(o, p);
  1492. }
  1493. function isNativeReflectConstruct() {
  1494. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  1495. if (Reflect.construct.sham) return false;
  1496. if (typeof Proxy === "function") return true;
  1497. try {
  1498. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  1499. return true;
  1500. } catch (e) {
  1501. return false;
  1502. }
  1503. }
  1504. function _construct(Parent, args, Class) {
  1505. if (isNativeReflectConstruct()) {
  1506. _construct = Reflect.construct;
  1507. } else {
  1508. _construct = function _construct(Parent, args, Class) {
  1509. var a = [null];
  1510. a.push.apply(a, args);
  1511. var Constructor = Function.bind.apply(Parent, a);
  1512. var instance = new Constructor();
  1513. if (Class) _setPrototypeOf(instance, Class.prototype);
  1514. return instance;
  1515. };
  1516. }
  1517. return _construct.apply(null, arguments);
  1518. }
  1519. function _isNativeFunction(fn) {
  1520. return Function.toString.call(fn).indexOf("[native code]") !== -1;
  1521. }
  1522. function _wrapNativeSuper(Class) {
  1523. var _cache = typeof Map === "function" ? new Map() : undefined;
  1524. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  1525. if (Class === null || !_isNativeFunction(Class)) return Class;
  1526. if (typeof Class !== "function") {
  1527. throw new TypeError("Super expression must either be null or a function");
  1528. }
  1529. if (typeof _cache !== "undefined") {
  1530. if (_cache.has(Class)) return _cache.get(Class);
  1531. _cache.set(Class, Wrapper);
  1532. }
  1533. function Wrapper() {
  1534. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  1535. }
  1536. Wrapper.prototype = Object.create(Class.prototype, {
  1537. constructor: {
  1538. value: Wrapper,
  1539. enumerable: false,
  1540. writable: true,
  1541. configurable: true
  1542. }
  1543. });
  1544. return _setPrototypeOf(Wrapper, Class);
  1545. };
  1546. return _wrapNativeSuper(Class);
  1547. }
  1548. function _assertThisInitialized(self) {
  1549. if (self === void 0) {
  1550. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1551. }
  1552. return self;
  1553. }
  1554. function _possibleConstructorReturn(self, call) {
  1555. if (call && (typeof call === "object" || typeof call === "function")) {
  1556. return call;
  1557. }
  1558. return _assertThisInitialized(self);
  1559. }
  1560. function _superPropBase(object, property) {
  1561. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  1562. object = _getPrototypeOf(object);
  1563. if (object === null) break;
  1564. }
  1565. return object;
  1566. }
  1567. function _get(target, property, receiver) {
  1568. if (typeof Reflect !== "undefined" && Reflect.get) {
  1569. _get = Reflect.get;
  1570. } else {
  1571. _get = function _get(target, property, receiver) {
  1572. var base = _superPropBase(target, property);
  1573. if (!base) return;
  1574. var desc = Object.getOwnPropertyDescriptor(base, property);
  1575. if (desc.get) {
  1576. return desc.get.call(receiver);
  1577. }
  1578. return desc.value;
  1579. };
  1580. }
  1581. return _get(target, property, receiver || target);
  1582. }
  1583. function _slicedToArray(arr, i) {
  1584. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
  1585. }
  1586. function _toConsumableArray$1(arr) {
  1587. return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _nonIterableSpread$1();
  1588. }
  1589. function _arrayWithoutHoles$1(arr) {
  1590. if (Array.isArray(arr)) {
  1591. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  1592. return arr2;
  1593. }
  1594. }
  1595. function _arrayWithHoles(arr) {
  1596. if (Array.isArray(arr)) return arr;
  1597. }
  1598. function _iterableToArray$1(iter) {
  1599. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  1600. }
  1601. function _iterableToArrayLimit(arr, i) {
  1602. if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
  1603. return;
  1604. }
  1605. var _arr = [];
  1606. var _n = true;
  1607. var _d = false;
  1608. var _e = undefined;
  1609. try {
  1610. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  1611. _arr.push(_s.value);
  1612. if (i && _arr.length === i) break;
  1613. }
  1614. } catch (err) {
  1615. _d = true;
  1616. _e = err;
  1617. } finally {
  1618. try {
  1619. if (!_n && _i["return"] != null) _i["return"]();
  1620. } finally {
  1621. if (_d) throw _e;
  1622. }
  1623. }
  1624. return _arr;
  1625. }
  1626. function _nonIterableSpread$1() {
  1627. throw new TypeError("Invalid attempt to spread non-iterable instance");
  1628. }
  1629. function _nonIterableRest() {
  1630. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  1631. }
  1632. /**
  1633. * @class
  1634. */
  1635. var LineByLine =
  1636. /*#__PURE__*/
  1637. function () {
  1638. function LineByLine(file, options) {
  1639. _classCallCheck(this, LineByLine);
  1640. options = options || {};
  1641. if (!options.readChunk) options.readChunk = 1024;
  1642. if (!options.newLineCharacter) {
  1643. options.newLineCharacter = 0x0a; //linux line ending
  1644. } else {
  1645. options.newLineCharacter = options.newLineCharacter.charCodeAt(0);
  1646. }
  1647. if (typeof file === 'number') {
  1648. this.fd = file;
  1649. } else {
  1650. this.fd = fs$1.openSync(file, 'r');
  1651. }
  1652. this.options = options;
  1653. this.newLineCharacter = options.newLineCharacter;
  1654. this.reset();
  1655. }
  1656. _createClass(LineByLine, [{
  1657. key: "_searchInBuffer",
  1658. value: function _searchInBuffer(buffer, hexNeedle) {
  1659. var found = -1;
  1660. for (var i = 0; i <= buffer.length; i++) {
  1661. var b_byte = buffer[i];
  1662. if (b_byte === hexNeedle) {
  1663. found = i;
  1664. break;
  1665. }
  1666. }
  1667. return found;
  1668. }
  1669. }, {
  1670. key: "reset",
  1671. value: function reset() {
  1672. this.eofReached = false;
  1673. this.linesCache = [];
  1674. this.fdPosition = 0;
  1675. }
  1676. }, {
  1677. key: "close",
  1678. value: function close() {
  1679. fs$1.closeSync(this.fd);
  1680. this.fd = null;
  1681. }
  1682. }, {
  1683. key: "_extractLines",
  1684. value: function _extractLines(buffer) {
  1685. var line;
  1686. var lines = [];
  1687. var bufferPosition = 0;
  1688. var lastNewLineBufferPosition = 0;
  1689. while (true) {
  1690. var bufferPositionValue = buffer[bufferPosition++];
  1691. if (bufferPositionValue === this.newLineCharacter) {
  1692. line = buffer.slice(lastNewLineBufferPosition, bufferPosition);
  1693. lines.push(line);
  1694. lastNewLineBufferPosition = bufferPosition;
  1695. } else if (!bufferPositionValue) {
  1696. break;
  1697. }
  1698. }
  1699. var leftovers = buffer.slice(lastNewLineBufferPosition, bufferPosition);
  1700. if (leftovers.length) {
  1701. lines.push(leftovers);
  1702. }
  1703. return lines;
  1704. }
  1705. }, {
  1706. key: "_readChunk",
  1707. value: function _readChunk(lineLeftovers) {
  1708. var totalBytesRead = 0;
  1709. var bytesRead;
  1710. var buffers = [];
  1711. do {
  1712. var readBuffer = new Buffer(this.options.readChunk);
  1713. bytesRead = fs$1.readSync(this.fd, readBuffer, 0, this.options.readChunk, this.fdPosition);
  1714. totalBytesRead = totalBytesRead + bytesRead;
  1715. this.fdPosition = this.fdPosition + bytesRead;
  1716. buffers.push(readBuffer);
  1717. } while (bytesRead && this._searchInBuffer(buffers[buffers.length - 1], this.options.newLineCharacter) === -1);
  1718. var bufferData = Buffer.concat(buffers);
  1719. if (bytesRead < this.options.readChunk) {
  1720. this.eofReached = true;
  1721. bufferData = bufferData.slice(0, totalBytesRead);
  1722. }
  1723. if (totalBytesRead) {
  1724. this.linesCache = this._extractLines(bufferData);
  1725. if (lineLeftovers) {
  1726. this.linesCache[0] = Buffer.concat([lineLeftovers, this.linesCache[0]]);
  1727. }
  1728. }
  1729. return totalBytesRead;
  1730. }
  1731. }, {
  1732. key: "next",
  1733. value: function next() {
  1734. if (!this.fd) return false;
  1735. var line = false;
  1736. if (this.eofReached && this.linesCache.length === 0) {
  1737. return line;
  1738. }
  1739. var bytesRead;
  1740. if (!this.linesCache.length) {
  1741. bytesRead = this._readChunk();
  1742. }
  1743. if (this.linesCache.length) {
  1744. line = this.linesCache.shift();
  1745. var lastLineCharacter = line[line.length - 1];
  1746. if (lastLineCharacter !== 0x0a) {
  1747. bytesRead = this._readChunk(line);
  1748. if (bytesRead) {
  1749. line = this.linesCache.shift();
  1750. }
  1751. }
  1752. }
  1753. if (this.eofReached && this.linesCache.length === 0) {
  1754. this.close();
  1755. }
  1756. if (line && line[line.length - 1] === this.newLineCharacter) {
  1757. line = line.slice(0, line.length - 1);
  1758. }
  1759. return line;
  1760. }
  1761. }]);
  1762. return LineByLine;
  1763. }();
  1764. var readlines = LineByLine;
  1765. var ConfigError =
  1766. /*#__PURE__*/
  1767. function (_Error) {
  1768. _inherits(ConfigError, _Error);
  1769. function ConfigError() {
  1770. _classCallCheck(this, ConfigError);
  1771. return _possibleConstructorReturn(this, _getPrototypeOf(ConfigError).apply(this, arguments));
  1772. }
  1773. return ConfigError;
  1774. }(_wrapNativeSuper(Error));
  1775. var DebugError =
  1776. /*#__PURE__*/
  1777. function (_Error2) {
  1778. _inherits(DebugError, _Error2);
  1779. function DebugError() {
  1780. _classCallCheck(this, DebugError);
  1781. return _possibleConstructorReturn(this, _getPrototypeOf(DebugError).apply(this, arguments));
  1782. }
  1783. return DebugError;
  1784. }(_wrapNativeSuper(Error));
  1785. var UndefinedParserError =
  1786. /*#__PURE__*/
  1787. function (_Error3) {
  1788. _inherits(UndefinedParserError, _Error3);
  1789. function UndefinedParserError() {
  1790. _classCallCheck(this, UndefinedParserError);
  1791. return _possibleConstructorReturn(this, _getPrototypeOf(UndefinedParserError).apply(this, arguments));
  1792. }
  1793. return UndefinedParserError;
  1794. }(_wrapNativeSuper(Error));
  1795. var errors = {
  1796. ConfigError,
  1797. DebugError,
  1798. UndefinedParserError
  1799. };
  1800. function unwrapExports (x) {
  1801. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  1802. }
  1803. function createCommonjsModule(fn, module) {
  1804. return module = { exports: {} }, fn(module, module.exports), module.exports;
  1805. }
  1806. function getCjsExportFromNamespace (n) {
  1807. return n && n['default'] || n;
  1808. }
  1809. var semver = createCommonjsModule(function (module, exports) {
  1810. exports = module.exports = SemVer;
  1811. var debug;
  1812. /* istanbul ignore next */
  1813. if (typeof process === 'object' && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG)) {
  1814. debug = function debug() {
  1815. var args = Array.prototype.slice.call(arguments, 0);
  1816. args.unshift('SEMVER');
  1817. console.log.apply(console, args);
  1818. };
  1819. } else {
  1820. debug = function debug() {};
  1821. } // Note: this is the semver.org version of the spec that it implements
  1822. // Not necessarily the package version of this code.
  1823. exports.SEMVER_SPEC_VERSION = '2.0.0';
  1824. var MAX_LENGTH = 256;
  1825. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
  1826. /* istanbul ignore next */
  1827. 9007199254740991; // Max safe segment length for coercion.
  1828. var MAX_SAFE_COMPONENT_LENGTH = 16; // The actual regexps go on exports.re
  1829. var re = exports.re = [];
  1830. var src = exports.src = [];
  1831. var t = exports.tokens = {};
  1832. var R = 0;
  1833. function tok(n) {
  1834. t[n] = R++;
  1835. } // The following Regular Expressions can be used for tokenizing,
  1836. // validating, and parsing SemVer version strings.
  1837. // ## Numeric Identifier
  1838. // A single `0`, or a non-zero digit followed by zero or more digits.
  1839. tok('NUMERICIDENTIFIER');
  1840. src[t.NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  1841. tok('NUMERICIDENTIFIERLOOSE');
  1842. src[t.NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
  1843. // Zero or more digits, followed by a letter or hyphen, and then zero or
  1844. // more letters, digits, or hyphens.
  1845. tok('NONNUMERICIDENTIFIER');
  1846. src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
  1847. // Three dot-separated numeric identifiers.
  1848. tok('MAINVERSION');
  1849. src[t.MAINVERSION] = '(' + src[t.NUMERICIDENTIFIER] + ')\\.' + '(' + src[t.NUMERICIDENTIFIER] + ')\\.' + '(' + src[t.NUMERICIDENTIFIER] + ')';
  1850. tok('MAINVERSIONLOOSE');
  1851. src[t.MAINVERSIONLOOSE] = '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
  1852. // A numeric identifier, or a non-numeric identifier.
  1853. tok('PRERELEASEIDENTIFIER');
  1854. src[t.PRERELEASEIDENTIFIER] = '(?:' + src[t.NUMERICIDENTIFIER] + '|' + src[t.NONNUMERICIDENTIFIER] + ')';
  1855. tok('PRERELEASEIDENTIFIERLOOSE');
  1856. src[t.PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[t.NUMERICIDENTIFIERLOOSE] + '|' + src[t.NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
  1857. // Hyphen, followed by one or more dot-separated pre-release version
  1858. // identifiers.
  1859. tok('PRERELEASE');
  1860. src[t.PRERELEASE] = '(?:-(' + src[t.PRERELEASEIDENTIFIER] + '(?:\\.' + src[t.PRERELEASEIDENTIFIER] + ')*))';
  1861. tok('PRERELEASELOOSE');
  1862. src[t.PRERELEASELOOSE] = '(?:-?(' + src[t.PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[t.PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
  1863. // Any combination of digits, letters, or hyphens.
  1864. tok('BUILDIDENTIFIER');
  1865. src[t.BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
  1866. // Plus sign, followed by one or more period-separated build metadata
  1867. // identifiers.
  1868. tok('BUILD');
  1869. src[t.BUILD] = '(?:\\+(' + src[t.BUILDIDENTIFIER] + '(?:\\.' + src[t.BUILDIDENTIFIER] + ')*))'; // ## Full Version String
  1870. // A main version, followed optionally by a pre-release version and
  1871. // build metadata.
  1872. // Note that the only major, minor, patch, and pre-release sections of
  1873. // the version string are capturing groups. The build metadata is not a
  1874. // capturing group, because it should not ever be used in version
  1875. // comparison.
  1876. tok('FULL');
  1877. tok('FULLPLAIN');
  1878. src[t.FULLPLAIN] = 'v?' + src[t.MAINVERSION] + src[t.PRERELEASE] + '?' + src[t.BUILD] + '?';
  1879. src[t.FULL] = '^' + src[t.FULLPLAIN] + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  1880. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  1881. // common in the npm registry.
  1882. tok('LOOSEPLAIN');
  1883. src[t.LOOSEPLAIN] = '[v=\\s]*' + src[t.MAINVERSIONLOOSE] + src[t.PRERELEASELOOSE] + '?' + src[t.BUILD] + '?';
  1884. tok('LOOSE');
  1885. src[t.LOOSE] = '^' + src[t.LOOSEPLAIN] + '$';
  1886. tok('GTLT');
  1887. src[t.GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
  1888. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  1889. // Only the first item is strictly required.
  1890. tok('XRANGEIDENTIFIERLOOSE');
  1891. src[t.XRANGEIDENTIFIERLOOSE] = src[t.NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  1892. tok('XRANGEIDENTIFIER');
  1893. src[t.XRANGEIDENTIFIER] = src[t.NUMERICIDENTIFIER] + '|x|X|\\*';
  1894. tok('XRANGEPLAIN');
  1895. src[t.XRANGEPLAIN] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' + '(?:' + src[t.PRERELEASE] + ')?' + src[t.BUILD] + '?' + ')?)?';
  1896. tok('XRANGEPLAINLOOSE');
  1897. src[t.XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[t.PRERELEASELOOSE] + ')?' + src[t.BUILD] + '?' + ')?)?';
  1898. tok('XRANGE');
  1899. src[t.XRANGE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAIN] + '$';
  1900. tok('XRANGELOOSE');
  1901. src[t.XRANGELOOSE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAINLOOSE] + '$'; // Coercion.
  1902. // Extract anything that could conceivably be a part of a valid semver
  1903. tok('COERCE');
  1904. src[t.COERCE] = '(^|[^\\d])' + '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:$|[^\\d])';
  1905. tok('COERCERTL');
  1906. re[t.COERCERTL] = new RegExp(src[t.COERCE], 'g'); // Tilde ranges.
  1907. // Meaning is "reasonably at or greater than"
  1908. tok('LONETILDE');
  1909. src[t.LONETILDE] = '(?:~>?)';
  1910. tok('TILDETRIM');
  1911. src[t.TILDETRIM] = '(\\s*)' + src[t.LONETILDE] + '\\s+';
  1912. re[t.TILDETRIM] = new RegExp(src[t.TILDETRIM], 'g');
  1913. var tildeTrimReplace = '$1~';
  1914. tok('TILDE');
  1915. src[t.TILDE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAIN] + '$';
  1916. tok('TILDELOOSE');
  1917. src[t.TILDELOOSE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAINLOOSE] + '$'; // Caret ranges.
  1918. // Meaning is "at least and backwards compatible with"
  1919. tok('LONECARET');
  1920. src[t.LONECARET] = '(?:\\^)';
  1921. tok('CARETTRIM');
  1922. src[t.CARETTRIM] = '(\\s*)' + src[t.LONECARET] + '\\s+';
  1923. re[t.CARETTRIM] = new RegExp(src[t.CARETTRIM], 'g');
  1924. var caretTrimReplace = '$1^';
  1925. tok('CARET');
  1926. src[t.CARET] = '^' + src[t.LONECARET] + src[t.XRANGEPLAIN] + '$';
  1927. tok('CARETLOOSE');
  1928. src[t.CARETLOOSE] = '^' + src[t.LONECARET] + src[t.XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
  1929. tok('COMPARATORLOOSE');
  1930. src[t.COMPARATORLOOSE] = '^' + src[t.GTLT] + '\\s*(' + src[t.LOOSEPLAIN] + ')$|^$';
  1931. tok('COMPARATOR');
  1932. src[t.COMPARATOR] = '^' + src[t.GTLT] + '\\s*(' + src[t.FULLPLAIN] + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
  1933. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  1934. tok('COMPARATORTRIM');
  1935. src[t.COMPARATORTRIM] = '(\\s*)' + src[t.GTLT] + '\\s*(' + src[t.LOOSEPLAIN] + '|' + src[t.XRANGEPLAIN] + ')'; // this one has to use the /g flag
  1936. re[t.COMPARATORTRIM] = new RegExp(src[t.COMPARATORTRIM], 'g');
  1937. var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  1938. // Note that these all use the loose form, because they'll be
  1939. // checked against either the strict or loose comparator form
  1940. // later.
  1941. tok('HYPHENRANGE');
  1942. src[t.HYPHENRANGE] = '^\\s*(' + src[t.XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[t.XRANGEPLAIN] + ')' + '\\s*$';
  1943. tok('HYPHENRANGELOOSE');
  1944. src[t.HYPHENRANGELOOSE] = '^\\s*(' + src[t.XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[t.XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
  1945. tok('STAR');
  1946. src[t.STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
  1947. // All are flag-free, unless they were created above with a flag.
  1948. for (var i = 0; i < R; i++) {
  1949. debug(i, src[i]);
  1950. if (!re[i]) {
  1951. re[i] = new RegExp(src[i]);
  1952. }
  1953. }
  1954. exports.parse = parse;
  1955. function parse(version, options) {
  1956. if (!options || typeof options !== 'object') {
  1957. options = {
  1958. loose: !!options,
  1959. includePrerelease: false
  1960. };
  1961. }
  1962. if (version instanceof SemVer) {
  1963. return version;
  1964. }
  1965. if (typeof version !== 'string') {
  1966. return null;
  1967. }
  1968. if (version.length > MAX_LENGTH) {
  1969. return null;
  1970. }
  1971. var r = options.loose ? re[t.LOOSE] : re[t.FULL];
  1972. if (!r.test(version)) {
  1973. return null;
  1974. }
  1975. try {
  1976. return new SemVer(version, options);
  1977. } catch (er) {
  1978. return null;
  1979. }
  1980. }
  1981. exports.valid = valid;
  1982. function valid(version, options) {
  1983. var v = parse(version, options);
  1984. return v ? v.version : null;
  1985. }
  1986. exports.clean = clean;
  1987. function clean(version, options) {
  1988. var s = parse(version.trim().replace(/^[=v]+/, ''), options);
  1989. return s ? s.version : null;
  1990. }
  1991. exports.SemVer = SemVer;
  1992. function SemVer(version, options) {
  1993. if (!options || typeof options !== 'object') {
  1994. options = {
  1995. loose: !!options,
  1996. includePrerelease: false
  1997. };
  1998. }
  1999. if (version instanceof SemVer) {
  2000. if (version.loose === options.loose) {
  2001. return version;
  2002. } else {
  2003. version = version.version;
  2004. }
  2005. } else if (typeof version !== 'string') {
  2006. throw new TypeError('Invalid Version: ' + version);
  2007. }
  2008. if (version.length > MAX_LENGTH) {
  2009. throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
  2010. }
  2011. if (!(this instanceof SemVer)) {
  2012. return new SemVer(version, options);
  2013. }
  2014. debug('SemVer', version, options);
  2015. this.options = options;
  2016. this.loose = !!options.loose;
  2017. var m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
  2018. if (!m) {
  2019. throw new TypeError('Invalid Version: ' + version);
  2020. }
  2021. this.raw = version; // these are actually numbers
  2022. this.major = +m[1];
  2023. this.minor = +m[2];
  2024. this.patch = +m[3];
  2025. if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
  2026. throw new TypeError('Invalid major version');
  2027. }
  2028. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
  2029. throw new TypeError('Invalid minor version');
  2030. }
  2031. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
  2032. throw new TypeError('Invalid patch version');
  2033. } // numberify any prerelease numeric ids
  2034. if (!m[4]) {
  2035. this.prerelease = [];
  2036. } else {
  2037. this.prerelease = m[4].split('.').map(function (id) {
  2038. if (/^[0-9]+$/.test(id)) {
  2039. var num = +id;
  2040. if (num >= 0 && num < MAX_SAFE_INTEGER) {
  2041. return num;
  2042. }
  2043. }
  2044. return id;
  2045. });
  2046. }
  2047. this.build = m[5] ? m[5].split('.') : [];
  2048. this.format();
  2049. }
  2050. SemVer.prototype.format = function () {
  2051. this.version = this.major + '.' + this.minor + '.' + this.patch;
  2052. if (this.prerelease.length) {
  2053. this.version += '-' + this.prerelease.join('.');
  2054. }
  2055. return this.version;
  2056. };
  2057. SemVer.prototype.toString = function () {
  2058. return this.version;
  2059. };
  2060. SemVer.prototype.compare = function (other) {
  2061. debug('SemVer.compare', this.version, this.options, other);
  2062. if (!(other instanceof SemVer)) {
  2063. other = new SemVer(other, this.options);
  2064. }
  2065. return this.compareMain(other) || this.comparePre(other);
  2066. };
  2067. SemVer.prototype.compareMain = function (other) {
  2068. if (!(other instanceof SemVer)) {
  2069. other = new SemVer(other, this.options);
  2070. }
  2071. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  2072. };
  2073. SemVer.prototype.comparePre = function (other) {
  2074. if (!(other instanceof SemVer)) {
  2075. other = new SemVer(other, this.options);
  2076. } // NOT having a prerelease is > having one
  2077. if (this.prerelease.length && !other.prerelease.length) {
  2078. return -1;
  2079. } else if (!this.prerelease.length && other.prerelease.length) {
  2080. return 1;
  2081. } else if (!this.prerelease.length && !other.prerelease.length) {
  2082. return 0;
  2083. }
  2084. var i = 0;
  2085. do {
  2086. var a = this.prerelease[i];
  2087. var b = other.prerelease[i];
  2088. debug('prerelease compare', i, a, b);
  2089. if (a === undefined && b === undefined) {
  2090. return 0;
  2091. } else if (b === undefined) {
  2092. return 1;
  2093. } else if (a === undefined) {
  2094. return -1;
  2095. } else if (a === b) {
  2096. continue;
  2097. } else {
  2098. return compareIdentifiers(a, b);
  2099. }
  2100. } while (++i);
  2101. };
  2102. SemVer.prototype.compareBuild = function (other) {
  2103. if (!(other instanceof SemVer)) {
  2104. other = new SemVer(other, this.options);
  2105. }
  2106. var i = 0;
  2107. do {
  2108. var a = this.build[i];
  2109. var b = other.build[i];
  2110. debug('prerelease compare', i, a, b);
  2111. if (a === undefined && b === undefined) {
  2112. return 0;
  2113. } else if (b === undefined) {
  2114. return 1;
  2115. } else if (a === undefined) {
  2116. return -1;
  2117. } else if (a === b) {
  2118. continue;
  2119. } else {
  2120. return compareIdentifiers(a, b);
  2121. }
  2122. } while (++i);
  2123. }; // preminor will bump the version up to the next minor release, and immediately
  2124. // down to pre-release. premajor and prepatch work the same way.
  2125. SemVer.prototype.inc = function (release, identifier) {
  2126. switch (release) {
  2127. case 'premajor':
  2128. this.prerelease.length = 0;
  2129. this.patch = 0;
  2130. this.minor = 0;
  2131. this.major++;
  2132. this.inc('pre', identifier);
  2133. break;
  2134. case 'preminor':
  2135. this.prerelease.length = 0;
  2136. this.patch = 0;
  2137. this.minor++;
  2138. this.inc('pre', identifier);
  2139. break;
  2140. case 'prepatch':
  2141. // If this is already a prerelease, it will bump to the next version
  2142. // drop any prereleases that might already exist, since they are not
  2143. // relevant at this point.
  2144. this.prerelease.length = 0;
  2145. this.inc('patch', identifier);
  2146. this.inc('pre', identifier);
  2147. break;
  2148. // If the input is a non-prerelease version, this acts the same as
  2149. // prepatch.
  2150. case 'prerelease':
  2151. if (this.prerelease.length === 0) {
  2152. this.inc('patch', identifier);
  2153. }
  2154. this.inc('pre', identifier);
  2155. break;
  2156. case 'major':
  2157. // If this is a pre-major version, bump up to the same major version.
  2158. // Otherwise increment major.
  2159. // 1.0.0-5 bumps to 1.0.0
  2160. // 1.1.0 bumps to 2.0.0
  2161. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
  2162. this.major++;
  2163. }
  2164. this.minor = 0;
  2165. this.patch = 0;
  2166. this.prerelease = [];
  2167. break;
  2168. case 'minor':
  2169. // If this is a pre-minor version, bump up to the same minor version.
  2170. // Otherwise increment minor.
  2171. // 1.2.0-5 bumps to 1.2.0
  2172. // 1.2.1 bumps to 1.3.0
  2173. if (this.patch !== 0 || this.prerelease.length === 0) {
  2174. this.minor++;
  2175. }
  2176. this.patch = 0;
  2177. this.prerelease = [];
  2178. break;
  2179. case 'patch':
  2180. // If this is not a pre-release version, it will increment the patch.
  2181. // If it is a pre-release it will bump up to the same patch version.
  2182. // 1.2.0-5 patches to 1.2.0
  2183. // 1.2.0 patches to 1.2.1
  2184. if (this.prerelease.length === 0) {
  2185. this.patch++;
  2186. }
  2187. this.prerelease = [];
  2188. break;
  2189. // This probably shouldn't be used publicly.
  2190. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  2191. case 'pre':
  2192. if (this.prerelease.length === 0) {
  2193. this.prerelease = [0];
  2194. } else {
  2195. var i = this.prerelease.length;
  2196. while (--i >= 0) {
  2197. if (typeof this.prerelease[i] === 'number') {
  2198. this.prerelease[i]++;
  2199. i = -2;
  2200. }
  2201. }
  2202. if (i === -1) {
  2203. // didn't increment anything
  2204. this.prerelease.push(0);
  2205. }
  2206. }
  2207. if (identifier) {
  2208. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  2209. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  2210. if (this.prerelease[0] === identifier) {
  2211. if (isNaN(this.prerelease[1])) {
  2212. this.prerelease = [identifier, 0];
  2213. }
  2214. } else {
  2215. this.prerelease = [identifier, 0];
  2216. }
  2217. }
  2218. break;
  2219. default:
  2220. throw new Error('invalid increment argument: ' + release);
  2221. }
  2222. this.format();
  2223. this.raw = this.version;
  2224. return this;
  2225. };
  2226. exports.inc = inc;
  2227. function inc(version, release, loose, identifier) {
  2228. if (typeof loose === 'string') {
  2229. identifier = loose;
  2230. loose = undefined;
  2231. }
  2232. try {
  2233. return new SemVer(version, loose).inc(release, identifier).version;
  2234. } catch (er) {
  2235. return null;
  2236. }
  2237. }
  2238. exports.diff = diff;
  2239. function diff(version1, version2) {
  2240. if (eq(version1, version2)) {
  2241. return null;
  2242. } else {
  2243. var v1 = parse(version1);
  2244. var v2 = parse(version2);
  2245. var prefix = '';
  2246. if (v1.prerelease.length || v2.prerelease.length) {
  2247. prefix = 'pre';
  2248. var defaultResult = 'prerelease';
  2249. }
  2250. for (var key in v1) {
  2251. if (key === 'major' || key === 'minor' || key === 'patch') {
  2252. if (v1[key] !== v2[key]) {
  2253. return prefix + key;
  2254. }
  2255. }
  2256. }
  2257. return defaultResult; // may be undefined
  2258. }
  2259. }
  2260. exports.compareIdentifiers = compareIdentifiers;
  2261. var numeric = /^[0-9]+$/;
  2262. function compareIdentifiers(a, b) {
  2263. var anum = numeric.test(a);
  2264. var bnum = numeric.test(b);
  2265. if (anum && bnum) {
  2266. a = +a;
  2267. b = +b;
  2268. }
  2269. return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
  2270. }
  2271. exports.rcompareIdentifiers = rcompareIdentifiers;
  2272. function rcompareIdentifiers(a, b) {
  2273. return compareIdentifiers(b, a);
  2274. }
  2275. exports.major = major;
  2276. function major(a, loose) {
  2277. return new SemVer(a, loose).major;
  2278. }
  2279. exports.minor = minor;
  2280. function minor(a, loose) {
  2281. return new SemVer(a, loose).minor;
  2282. }
  2283. exports.patch = patch;
  2284. function patch(a, loose) {
  2285. return new SemVer(a, loose).patch;
  2286. }
  2287. exports.compare = compare;
  2288. function compare(a, b, loose) {
  2289. return new SemVer(a, loose).compare(new SemVer(b, loose));
  2290. }
  2291. exports.compareLoose = compareLoose;
  2292. function compareLoose(a, b) {
  2293. return compare(a, b, true);
  2294. }
  2295. exports.compareBuild = compareBuild;
  2296. function compareBuild(a, b, loose) {
  2297. var versionA = new SemVer(a, loose);
  2298. var versionB = new SemVer(b, loose);
  2299. return versionA.compare(versionB) || versionA.compareBuild(versionB);
  2300. }
  2301. exports.rcompare = rcompare;
  2302. function rcompare(a, b, loose) {
  2303. return compare(b, a, loose);
  2304. }
  2305. exports.sort = sort;
  2306. function sort(list, loose) {
  2307. return list.sort(function (a, b) {
  2308. return exports.compareBuild(a, b, loose);
  2309. });
  2310. }
  2311. exports.rsort = rsort;
  2312. function rsort(list, loose) {
  2313. return list.sort(function (a, b) {
  2314. return exports.compareBuild(b, a, loose);
  2315. });
  2316. }
  2317. exports.gt = gt;
  2318. function gt(a, b, loose) {
  2319. return compare(a, b, loose) > 0;
  2320. }
  2321. exports.lt = lt;
  2322. function lt(a, b, loose) {
  2323. return compare(a, b, loose) < 0;
  2324. }
  2325. exports.eq = eq;
  2326. function eq(a, b, loose) {
  2327. return compare(a, b, loose) === 0;
  2328. }
  2329. exports.neq = neq;
  2330. function neq(a, b, loose) {
  2331. return compare(a, b, loose) !== 0;
  2332. }
  2333. exports.gte = gte;
  2334. function gte(a, b, loose) {
  2335. return compare(a, b, loose) >= 0;
  2336. }
  2337. exports.lte = lte;
  2338. function lte(a, b, loose) {
  2339. return compare(a, b, loose) <= 0;
  2340. }
  2341. exports.cmp = cmp;
  2342. function cmp(a, op, b, loose) {
  2343. switch (op) {
  2344. case '===':
  2345. if (typeof a === 'object') a = a.version;
  2346. if (typeof b === 'object') b = b.version;
  2347. return a === b;
  2348. case '!==':
  2349. if (typeof a === 'object') a = a.version;
  2350. if (typeof b === 'object') b = b.version;
  2351. return a !== b;
  2352. case '':
  2353. case '=':
  2354. case '==':
  2355. return eq(a, b, loose);
  2356. case '!=':
  2357. return neq(a, b, loose);
  2358. case '>':
  2359. return gt(a, b, loose);
  2360. case '>=':
  2361. return gte(a, b, loose);
  2362. case '<':
  2363. return lt(a, b, loose);
  2364. case '<=':
  2365. return lte(a, b, loose);
  2366. default:
  2367. throw new TypeError('Invalid operator: ' + op);
  2368. }
  2369. }
  2370. exports.Comparator = Comparator;
  2371. function Comparator(comp, options) {
  2372. if (!options || typeof options !== 'object') {
  2373. options = {
  2374. loose: !!options,
  2375. includePrerelease: false
  2376. };
  2377. }
  2378. if (comp instanceof Comparator) {
  2379. if (comp.loose === !!options.loose) {
  2380. return comp;
  2381. } else {
  2382. comp = comp.value;
  2383. }
  2384. }
  2385. if (!(this instanceof Comparator)) {
  2386. return new Comparator(comp, options);
  2387. }
  2388. debug('comparator', comp, options);
  2389. this.options = options;
  2390. this.loose = !!options.loose;
  2391. this.parse(comp);
  2392. if (this.semver === ANY) {
  2393. this.value = '';
  2394. } else {
  2395. this.value = this.operator + this.semver.version;
  2396. }
  2397. debug('comp', this);
  2398. }
  2399. var ANY = {};
  2400. Comparator.prototype.parse = function (comp) {
  2401. var r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
  2402. var m = comp.match(r);
  2403. if (!m) {
  2404. throw new TypeError('Invalid comparator: ' + comp);
  2405. }
  2406. this.operator = m[1] !== undefined ? m[1] : '';
  2407. if (this.operator === '=') {
  2408. this.operator = '';
  2409. } // if it literally is just '>' or '' then allow anything.
  2410. if (!m[2]) {
  2411. this.semver = ANY;
  2412. } else {
  2413. this.semver = new SemVer(m[2], this.options.loose);
  2414. }
  2415. };
  2416. Comparator.prototype.toString = function () {
  2417. return this.value;
  2418. };
  2419. Comparator.prototype.test = function (version) {
  2420. debug('Comparator.test', version, this.options.loose);
  2421. if (this.semver === ANY || version === ANY) {
  2422. return true;
  2423. }
  2424. if (typeof version === 'string') {
  2425. try {
  2426. version = new SemVer(version, this.options);
  2427. } catch (er) {
  2428. return false;
  2429. }
  2430. }
  2431. return cmp(version, this.operator, this.semver, this.options);
  2432. };
  2433. Comparator.prototype.intersects = function (comp, options) {
  2434. if (!(comp instanceof Comparator)) {
  2435. throw new TypeError('a Comparator is required');
  2436. }
  2437. if (!options || typeof options !== 'object') {
  2438. options = {
  2439. loose: !!options,
  2440. includePrerelease: false
  2441. };
  2442. }
  2443. var rangeTmp;
  2444. if (this.operator === '') {
  2445. if (this.value === '') {
  2446. return true;
  2447. }
  2448. rangeTmp = new Range(comp.value, options);
  2449. return satisfies(this.value, rangeTmp, options);
  2450. } else if (comp.operator === '') {
  2451. if (comp.value === '') {
  2452. return true;
  2453. }
  2454. rangeTmp = new Range(this.value, options);
  2455. return satisfies(comp.semver, rangeTmp, options);
  2456. }
  2457. var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
  2458. var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
  2459. var sameSemVer = this.semver.version === comp.semver.version;
  2460. var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
  2461. var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, options) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
  2462. var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, options) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
  2463. return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  2464. };
  2465. exports.Range = Range;
  2466. function Range(range, options) {
  2467. if (!options || typeof options !== 'object') {
  2468. options = {
  2469. loose: !!options,
  2470. includePrerelease: false
  2471. };
  2472. }
  2473. if (range instanceof Range) {
  2474. if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) {
  2475. return range;
  2476. } else {
  2477. return new Range(range.raw, options);
  2478. }
  2479. }
  2480. if (range instanceof Comparator) {
  2481. return new Range(range.value, options);
  2482. }
  2483. if (!(this instanceof Range)) {
  2484. return new Range(range, options);
  2485. }
  2486. this.options = options;
  2487. this.loose = !!options.loose;
  2488. this.includePrerelease = !!options.includePrerelease; // First, split based on boolean or ||
  2489. this.raw = range;
  2490. this.set = range.split(/\s*\|\|\s*/).map(function (range) {
  2491. return this.parseRange(range.trim());
  2492. }, this).filter(function (c) {
  2493. // throw out any that are not relevant for whatever reason
  2494. return c.length;
  2495. });
  2496. if (!this.set.length) {
  2497. throw new TypeError('Invalid SemVer Range: ' + range);
  2498. }
  2499. this.format();
  2500. }
  2501. Range.prototype.format = function () {
  2502. this.range = this.set.map(function (comps) {
  2503. return comps.join(' ').trim();
  2504. }).join('||').trim();
  2505. return this.range;
  2506. };
  2507. Range.prototype.toString = function () {
  2508. return this.range;
  2509. };
  2510. Range.prototype.parseRange = function (range) {
  2511. var loose = this.options.loose;
  2512. range = range.trim(); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  2513. var hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
  2514. range = range.replace(hr, hyphenReplace);
  2515. debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  2516. range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
  2517. debug('comparator trim', range, re[t.COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
  2518. range = range.replace(re[t.TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
  2519. range = range.replace(re[t.CARETTRIM], caretTrimReplace); // normalize spaces
  2520. range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
  2521. // ready to be split into comparators.
  2522. var compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
  2523. var set = range.split(' ').map(function (comp) {
  2524. return parseComparator(comp, this.options);
  2525. }, this).join(' ').split(/\s+/);
  2526. if (this.options.loose) {
  2527. // in loose mode, throw out any that are not valid comparators
  2528. set = set.filter(function (comp) {
  2529. return !!comp.match(compRe);
  2530. });
  2531. }
  2532. set = set.map(function (comp) {
  2533. return new Comparator(comp, this.options);
  2534. }, this);
  2535. return set;
  2536. };
  2537. Range.prototype.intersects = function (range, options) {
  2538. if (!(range instanceof Range)) {
  2539. throw new TypeError('a Range is required');
  2540. }
  2541. return this.set.some(function (thisComparators) {
  2542. return isSatisfiable(thisComparators, options) && range.set.some(function (rangeComparators) {
  2543. return isSatisfiable(rangeComparators, options) && thisComparators.every(function (thisComparator) {
  2544. return rangeComparators.every(function (rangeComparator) {
  2545. return thisComparator.intersects(rangeComparator, options);
  2546. });
  2547. });
  2548. });
  2549. });
  2550. }; // take a set of comparators and determine whether there
  2551. // exists a version which can satisfy it
  2552. function isSatisfiable(comparators, options) {
  2553. var result = true;
  2554. var remainingComparators = comparators.slice();
  2555. var testComparator = remainingComparators.pop();
  2556. while (result && remainingComparators.length) {
  2557. result = remainingComparators.every(function (otherComparator) {
  2558. return testComparator.intersects(otherComparator, options);
  2559. });
  2560. testComparator = remainingComparators.pop();
  2561. }
  2562. return result;
  2563. } // Mostly just for testing and legacy API reasons
  2564. exports.toComparators = toComparators;
  2565. function toComparators(range, options) {
  2566. return new Range(range, options).set.map(function (comp) {
  2567. return comp.map(function (c) {
  2568. return c.value;
  2569. }).join(' ').trim().split(' ');
  2570. });
  2571. } // comprised of xranges, tildes, stars, and gtlt's at this point.
  2572. // already replaced the hyphen ranges
  2573. // turn into a set of JUST comparators.
  2574. function parseComparator(comp, options) {
  2575. debug('comp', comp, options);
  2576. comp = replaceCarets(comp, options);
  2577. debug('caret', comp);
  2578. comp = replaceTildes(comp, options);
  2579. debug('tildes', comp);
  2580. comp = replaceXRanges(comp, options);
  2581. debug('xrange', comp);
  2582. comp = replaceStars(comp, options);
  2583. debug('stars', comp);
  2584. return comp;
  2585. }
  2586. function isX(id) {
  2587. return !id || id.toLowerCase() === 'x' || id === '*';
  2588. } // ~, ~> --> * (any, kinda silly)
  2589. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  2590. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  2591. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  2592. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  2593. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  2594. function replaceTildes(comp, options) {
  2595. return comp.trim().split(/\s+/).map(function (comp) {
  2596. return replaceTilde(comp, options);
  2597. }).join(' ');
  2598. }
  2599. function replaceTilde(comp, options) {
  2600. var r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
  2601. return comp.replace(r, function (_, M, m, p, pr) {
  2602. debug('tilde', comp, _, M, m, p, pr);
  2603. var ret;
  2604. if (isX(M)) {
  2605. ret = '';
  2606. } else if (isX(m)) {
  2607. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  2608. } else if (isX(p)) {
  2609. // ~1.2 == >=1.2.0 <1.3.0
  2610. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  2611. } else if (pr) {
  2612. debug('replaceTilde pr', pr);
  2613. ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + M + '.' + (+m + 1) + '.0';
  2614. } else {
  2615. // ~1.2.3 == >=1.2.3 <1.3.0
  2616. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  2617. }
  2618. debug('tilde return', ret);
  2619. return ret;
  2620. });
  2621. } // ^ --> * (any, kinda silly)
  2622. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  2623. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  2624. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  2625. // ^1.2.3 --> >=1.2.3 <2.0.0
  2626. // ^1.2.0 --> >=1.2.0 <2.0.0
  2627. function replaceCarets(comp, options) {
  2628. return comp.trim().split(/\s+/).map(function (comp) {
  2629. return replaceCaret(comp, options);
  2630. }).join(' ');
  2631. }
  2632. function replaceCaret(comp, options) {
  2633. debug('caret', comp, options);
  2634. var r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
  2635. return comp.replace(r, function (_, M, m, p, pr) {
  2636. debug('caret', comp, _, M, m, p, pr);
  2637. var ret;
  2638. if (isX(M)) {
  2639. ret = '';
  2640. } else if (isX(m)) {
  2641. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  2642. } else if (isX(p)) {
  2643. if (M === '0') {
  2644. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  2645. } else {
  2646. ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  2647. }
  2648. } else if (pr) {
  2649. debug('replaceCaret pr', pr);
  2650. if (M === '0') {
  2651. if (m === '0') {
  2652. ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + M + '.' + m + '.' + (+p + 1);
  2653. } else {
  2654. ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + M + '.' + (+m + 1) + '.0';
  2655. }
  2656. } else {
  2657. ret = '>=' + M + '.' + m + '.' + p + '-' + pr + ' <' + (+M + 1) + '.0.0';
  2658. }
  2659. } else {
  2660. debug('no pr');
  2661. if (M === '0') {
  2662. if (m === '0') {
  2663. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);
  2664. } else {
  2665. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  2666. }
  2667. } else {
  2668. ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
  2669. }
  2670. }
  2671. debug('caret return', ret);
  2672. return ret;
  2673. });
  2674. }
  2675. function replaceXRanges(comp, options) {
  2676. debug('replaceXRanges', comp, options);
  2677. return comp.split(/\s+/).map(function (comp) {
  2678. return replaceXRange(comp, options);
  2679. }).join(' ');
  2680. }
  2681. function replaceXRange(comp, options) {
  2682. comp = comp.trim();
  2683. var r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
  2684. return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
  2685. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  2686. var xM = isX(M);
  2687. var xm = xM || isX(m);
  2688. var xp = xm || isX(p);
  2689. var anyX = xp;
  2690. if (gtlt === '=' && anyX) {
  2691. gtlt = '';
  2692. } // if we're including prereleases in the match, then we need
  2693. // to fix this to -0, the lowest possible prerelease value
  2694. pr = options.includePrerelease ? '-0' : '';
  2695. if (xM) {
  2696. if (gtlt === '>' || gtlt === '<') {
  2697. // nothing is allowed
  2698. ret = '<0.0.0-0';
  2699. } else {
  2700. // nothing is forbidden
  2701. ret = '*';
  2702. }
  2703. } else if (gtlt && anyX) {
  2704. // we know patch is an x, because we have any x at all.
  2705. // replace X with 0
  2706. if (xm) {
  2707. m = 0;
  2708. }
  2709. p = 0;
  2710. if (gtlt === '>') {
  2711. // >1 => >=2.0.0
  2712. // >1.2 => >=1.3.0
  2713. // >1.2.3 => >= 1.2.4
  2714. gtlt = '>=';
  2715. if (xm) {
  2716. M = +M + 1;
  2717. m = 0;
  2718. p = 0;
  2719. } else {
  2720. m = +m + 1;
  2721. p = 0;
  2722. }
  2723. } else if (gtlt === '<=') {
  2724. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  2725. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  2726. gtlt = '<';
  2727. if (xm) {
  2728. M = +M + 1;
  2729. } else {
  2730. m = +m + 1;
  2731. }
  2732. }
  2733. ret = gtlt + M + '.' + m + '.' + p + pr;
  2734. } else if (xm) {
  2735. ret = '>=' + M + '.0.0' + pr + ' <' + (+M + 1) + '.0.0' + pr;
  2736. } else if (xp) {
  2737. ret = '>=' + M + '.' + m + '.0' + pr + ' <' + M + '.' + (+m + 1) + '.0' + pr;
  2738. }
  2739. debug('xRange return', ret);
  2740. return ret;
  2741. });
  2742. } // Because * is AND-ed with everything else in the comparator,
  2743. // and '' means "any version", just remove the *s entirely.
  2744. function replaceStars(comp, options) {
  2745. debug('replaceStars', comp, options); // Looseness is ignored here. star is always as loose as it gets!
  2746. return comp.trim().replace(re[t.STAR], '');
  2747. } // This function is passed to string.replace(re[t.HYPHENRANGE])
  2748. // M, m, patch, prerelease, build
  2749. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  2750. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  2751. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  2752. function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
  2753. if (isX(fM)) {
  2754. from = '';
  2755. } else if (isX(fm)) {
  2756. from = '>=' + fM + '.0.0';
  2757. } else if (isX(fp)) {
  2758. from = '>=' + fM + '.' + fm + '.0';
  2759. } else {
  2760. from = '>=' + from;
  2761. }
  2762. if (isX(tM)) {
  2763. to = '';
  2764. } else if (isX(tm)) {
  2765. to = '<' + (+tM + 1) + '.0.0';
  2766. } else if (isX(tp)) {
  2767. to = '<' + tM + '.' + (+tm + 1) + '.0';
  2768. } else if (tpr) {
  2769. to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
  2770. } else {
  2771. to = '<=' + to;
  2772. }
  2773. return (from + ' ' + to).trim();
  2774. } // if ANY of the sets match ALL of its comparators, then pass
  2775. Range.prototype.test = function (version) {
  2776. if (!version) {
  2777. return false;
  2778. }
  2779. if (typeof version === 'string') {
  2780. try {
  2781. version = new SemVer(version, this.options);
  2782. } catch (er) {
  2783. return false;
  2784. }
  2785. }
  2786. for (var i = 0; i < this.set.length; i++) {
  2787. if (testSet(this.set[i], version, this.options)) {
  2788. return true;
  2789. }
  2790. }
  2791. return false;
  2792. };
  2793. function testSet(set, version, options) {
  2794. for (var i = 0; i < set.length; i++) {
  2795. if (!set[i].test(version)) {
  2796. return false;
  2797. }
  2798. }
  2799. if (version.prerelease.length && !options.includePrerelease) {
  2800. // Find the set of versions that are allowed to have prereleases
  2801. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  2802. // That should allow `1.2.3-pr.2` to pass.
  2803. // However, `1.2.4-alpha.notready` should NOT be allowed,
  2804. // even though it's within the range set by the comparators.
  2805. for (i = 0; i < set.length; i++) {
  2806. debug(set[i].semver);
  2807. if (set[i].semver === ANY) {
  2808. continue;
  2809. }
  2810. if (set[i].semver.prerelease.length > 0) {
  2811. var allowed = set[i].semver;
  2812. if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) {
  2813. return true;
  2814. }
  2815. }
  2816. } // Version has a -pre, but it's not one of the ones we like.
  2817. return false;
  2818. }
  2819. return true;
  2820. }
  2821. exports.satisfies = satisfies;
  2822. function satisfies(version, range, options) {
  2823. try {
  2824. range = new Range(range, options);
  2825. } catch (er) {
  2826. return false;
  2827. }
  2828. return range.test(version);
  2829. }
  2830. exports.maxSatisfying = maxSatisfying;
  2831. function maxSatisfying(versions, range, options) {
  2832. var max = null;
  2833. var maxSV = null;
  2834. try {
  2835. var rangeObj = new Range(range, options);
  2836. } catch (er) {
  2837. return null;
  2838. }
  2839. versions.forEach(function (v) {
  2840. if (rangeObj.test(v)) {
  2841. // satisfies(v, range, options)
  2842. if (!max || maxSV.compare(v) === -1) {
  2843. // compare(max, v, true)
  2844. max = v;
  2845. maxSV = new SemVer(max, options);
  2846. }
  2847. }
  2848. });
  2849. return max;
  2850. }
  2851. exports.minSatisfying = minSatisfying;
  2852. function minSatisfying(versions, range, options) {
  2853. var min = null;
  2854. var minSV = null;
  2855. try {
  2856. var rangeObj = new Range(range, options);
  2857. } catch (er) {
  2858. return null;
  2859. }
  2860. versions.forEach(function (v) {
  2861. if (rangeObj.test(v)) {
  2862. // satisfies(v, range, options)
  2863. if (!min || minSV.compare(v) === 1) {
  2864. // compare(min, v, true)
  2865. min = v;
  2866. minSV = new SemVer(min, options);
  2867. }
  2868. }
  2869. });
  2870. return min;
  2871. }
  2872. exports.minVersion = minVersion;
  2873. function minVersion(range, loose) {
  2874. range = new Range(range, loose);
  2875. var minver = new SemVer('0.0.0');
  2876. if (range.test(minver)) {
  2877. return minver;
  2878. }
  2879. minver = new SemVer('0.0.0-0');
  2880. if (range.test(minver)) {
  2881. return minver;
  2882. }
  2883. minver = null;
  2884. for (var i = 0; i < range.set.length; ++i) {
  2885. var comparators = range.set[i];
  2886. comparators.forEach(function (comparator) {
  2887. // Clone to avoid manipulating the comparator's semver object.
  2888. var compver = new SemVer(comparator.semver.version);
  2889. switch (comparator.operator) {
  2890. case '>':
  2891. if (compver.prerelease.length === 0) {
  2892. compver.patch++;
  2893. } else {
  2894. compver.prerelease.push(0);
  2895. }
  2896. compver.raw = compver.format();
  2897. /* fallthrough */
  2898. case '':
  2899. case '>=':
  2900. if (!minver || gt(minver, compver)) {
  2901. minver = compver;
  2902. }
  2903. break;
  2904. case '<':
  2905. case '<=':
  2906. /* Ignore maximum versions */
  2907. break;
  2908. /* istanbul ignore next */
  2909. default:
  2910. throw new Error('Unexpected operation: ' + comparator.operator);
  2911. }
  2912. });
  2913. }
  2914. if (minver && range.test(minver)) {
  2915. return minver;
  2916. }
  2917. return null;
  2918. }
  2919. exports.validRange = validRange;
  2920. function validRange(range, options) {
  2921. try {
  2922. // Return '*' instead of '' so that truthiness works.
  2923. // This will throw if it's invalid anyway
  2924. return new Range(range, options).range || '*';
  2925. } catch (er) {
  2926. return null;
  2927. }
  2928. } // Determine if version is less than all the versions possible in the range
  2929. exports.ltr = ltr;
  2930. function ltr(version, range, options) {
  2931. return outside(version, range, '<', options);
  2932. } // Determine if version is greater than all the versions possible in the range.
  2933. exports.gtr = gtr;
  2934. function gtr(version, range, options) {
  2935. return outside(version, range, '>', options);
  2936. }
  2937. exports.outside = outside;
  2938. function outside(version, range, hilo, options) {
  2939. version = new SemVer(version, options);
  2940. range = new Range(range, options);
  2941. var gtfn, ltefn, ltfn, comp, ecomp;
  2942. switch (hilo) {
  2943. case '>':
  2944. gtfn = gt;
  2945. ltefn = lte;
  2946. ltfn = lt;
  2947. comp = '>';
  2948. ecomp = '>=';
  2949. break;
  2950. case '<':
  2951. gtfn = lt;
  2952. ltefn = gte;
  2953. ltfn = gt;
  2954. comp = '<';
  2955. ecomp = '<=';
  2956. break;
  2957. default:
  2958. throw new TypeError('Must provide a hilo val of "<" or ">"');
  2959. } // If it satisifes the range it is not outside
  2960. if (satisfies(version, range, options)) {
  2961. return false;
  2962. } // From now on, variable terms are as if we're in "gtr" mode.
  2963. // but note that everything is flipped for the "ltr" function.
  2964. for (var i = 0; i < range.set.length; ++i) {
  2965. var comparators = range.set[i];
  2966. var high = null;
  2967. var low = null;
  2968. comparators.forEach(function (comparator) {
  2969. if (comparator.semver === ANY) {
  2970. comparator = new Comparator('>=0.0.0');
  2971. }
  2972. high = high || comparator;
  2973. low = low || comparator;
  2974. if (gtfn(comparator.semver, high.semver, options)) {
  2975. high = comparator;
  2976. } else if (ltfn(comparator.semver, low.semver, options)) {
  2977. low = comparator;
  2978. }
  2979. }); // If the edge version comparator has a operator then our version
  2980. // isn't outside it
  2981. if (high.operator === comp || high.operator === ecomp) {
  2982. return false;
  2983. } // If the lowest version comparator has an operator and our version
  2984. // is less than it then it isn't higher than the range
  2985. if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
  2986. return false;
  2987. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  2988. return false;
  2989. }
  2990. }
  2991. return true;
  2992. }
  2993. exports.prerelease = prerelease;
  2994. function prerelease(version, options) {
  2995. var parsed = parse(version, options);
  2996. return parsed && parsed.prerelease.length ? parsed.prerelease : null;
  2997. }
  2998. exports.intersects = intersects;
  2999. function intersects(r1, r2, options) {
  3000. r1 = new Range(r1, options);
  3001. r2 = new Range(r2, options);
  3002. return r1.intersects(r2);
  3003. }
  3004. exports.coerce = coerce;
  3005. function coerce(version, options) {
  3006. if (version instanceof SemVer) {
  3007. return version;
  3008. }
  3009. if (typeof version === 'number') {
  3010. version = String(version);
  3011. }
  3012. if (typeof version !== 'string') {
  3013. return null;
  3014. }
  3015. options = options || {};
  3016. var match = null;
  3017. if (!options.rtl) {
  3018. match = version.match(re[t.COERCE]);
  3019. } else {
  3020. // Find the right-most coercible string that does not share
  3021. // a terminus with a more left-ward coercible string.
  3022. // Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
  3023. //
  3024. // Walk through the string checking with a /g regexp
  3025. // Manually set the index so as to pick up overlapping matches.
  3026. // Stop when we get a match that ends at the string end, since no
  3027. // coercible string can be more right-ward without the same terminus.
  3028. var next;
  3029. while ((next = re[t.COERCERTL].exec(version)) && (!match || match.index + match[0].length !== version.length)) {
  3030. if (!match || next.index + next[0].length !== match.index + match[0].length) {
  3031. match = next;
  3032. }
  3033. re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length;
  3034. } // leave it in a clean state
  3035. re[t.COERCERTL].lastIndex = -1;
  3036. }
  3037. if (match === null) {
  3038. return null;
  3039. }
  3040. return parse(match[2] + '.' + (match[3] || '0') + '.' + (match[4] || '0'), options);
  3041. }
  3042. });
  3043. var semver_1 = semver.SEMVER_SPEC_VERSION;
  3044. var semver_2 = semver.re;
  3045. var semver_3 = semver.src;
  3046. var semver_4 = semver.tokens;
  3047. var semver_5 = semver.parse;
  3048. var semver_6 = semver.valid;
  3049. var semver_7 = semver.clean;
  3050. var semver_8 = semver.SemVer;
  3051. var semver_9 = semver.inc;
  3052. var semver_10 = semver.diff;
  3053. var semver_11 = semver.compareIdentifiers;
  3054. var semver_12 = semver.rcompareIdentifiers;
  3055. var semver_13 = semver.major;
  3056. var semver_14 = semver.minor;
  3057. var semver_15 = semver.patch;
  3058. var semver_16 = semver.compare;
  3059. var semver_17 = semver.compareLoose;
  3060. var semver_18 = semver.compareBuild;
  3061. var semver_19 = semver.rcompare;
  3062. var semver_20 = semver.sort;
  3063. var semver_21 = semver.rsort;
  3064. var semver_22 = semver.gt;
  3065. var semver_23 = semver.lt;
  3066. var semver_24 = semver.eq;
  3067. var semver_25 = semver.neq;
  3068. var semver_26 = semver.gte;
  3069. var semver_27 = semver.lte;
  3070. var semver_28 = semver.cmp;
  3071. var semver_29 = semver.Comparator;
  3072. var semver_30 = semver.Range;
  3073. var semver_31 = semver.toComparators;
  3074. var semver_32 = semver.satisfies;
  3075. var semver_33 = semver.maxSatisfying;
  3076. var semver_34 = semver.minSatisfying;
  3077. var semver_35 = semver.minVersion;
  3078. var semver_36 = semver.validRange;
  3079. var semver_37 = semver.ltr;
  3080. var semver_38 = semver.gtr;
  3081. var semver_39 = semver.outside;
  3082. var semver_40 = semver.prerelease;
  3083. var semver_41 = semver.intersects;
  3084. var semver_42 = semver.coerce;
  3085. var arrayify = function arrayify(object, keyName) {
  3086. return Object.keys(object).reduce(function (array, key) {
  3087. return array.concat(Object.assign({
  3088. [keyName]: key
  3089. }, object[key]));
  3090. }, []);
  3091. };
  3092. var dedent_1 = createCommonjsModule(function (module) {
  3093. function dedent(strings) {
  3094. var raw = void 0;
  3095. if (typeof strings === "string") {
  3096. // dedent can be used as a plain function
  3097. raw = [strings];
  3098. } else {
  3099. raw = strings.raw;
  3100. } // first, perform interpolation
  3101. var result = "";
  3102. for (var i = 0; i < raw.length; i++) {
  3103. result += raw[i]. // join lines when there is a suppressed newline
  3104. replace(/\\\n[ \t]*/g, ""). // handle escaped backticks
  3105. replace(/\\`/g, "`");
  3106. if (i < (arguments.length <= 1 ? 0 : arguments.length - 1)) {
  3107. result += arguments.length <= i + 1 ? undefined : arguments[i + 1];
  3108. }
  3109. } // now strip indentation
  3110. var lines = result.split("\n");
  3111. var mindent = null;
  3112. lines.forEach(function (l) {
  3113. var m = l.match(/^(\s+)\S+/);
  3114. if (m) {
  3115. var indent = m[1].length;
  3116. if (!mindent) {
  3117. // this is the first indented line
  3118. mindent = indent;
  3119. } else {
  3120. mindent = Math.min(mindent, indent);
  3121. }
  3122. }
  3123. });
  3124. if (mindent !== null) {
  3125. result = lines.map(function (l) {
  3126. return l[0] === " " ? l.slice(mindent) : l;
  3127. }).join("\n");
  3128. } // dedent eats leading and trailing whitespace too
  3129. result = result.trim(); // handle escaped newlines at the end to ensure they don't get stripped too
  3130. return result.replace(/\\n/g, "\n");
  3131. }
  3132. {
  3133. module.exports = dedent;
  3134. }
  3135. });
  3136. var CATEGORY_CONFIG = "Config";
  3137. var CATEGORY_EDITOR = "Editor";
  3138. var CATEGORY_FORMAT = "Format";
  3139. var CATEGORY_OTHER = "Other";
  3140. var CATEGORY_OUTPUT = "Output";
  3141. var CATEGORY_GLOBAL = "Global";
  3142. var CATEGORY_SPECIAL = "Special";
  3143. /**
  3144. * @typedef {Object} OptionInfo
  3145. * @property {string} [since] - available since version
  3146. * @property {string} category
  3147. * @property {'int' | 'boolean' | 'choice' | 'path'} type
  3148. * @property {boolean} [array] - indicate it's an array of the specified type
  3149. * @property {OptionValueInfo} [default]
  3150. * @property {OptionRangeInfo} [range] - for type int
  3151. * @property {string} description
  3152. * @property {string} [deprecated] - deprecated since version
  3153. * @property {OptionRedirectInfo} [redirect] - redirect deprecated option
  3154. * @property {(value: any) => boolean} [exception]
  3155. * @property {OptionChoiceInfo[]} [choices] - for type choice
  3156. * @property {string} [cliName]
  3157. * @property {string} [cliCategory]
  3158. * @property {string} [cliDescription]
  3159. *
  3160. * @typedef {number | boolean | string} OptionValue
  3161. * @typedef {OptionValue | [{ value: OptionValue[] }] | Array<{ since: string, value: OptionValue}>} OptionValueInfo
  3162. *
  3163. * @typedef {Object} OptionRedirectInfo
  3164. * @property {string} option
  3165. * @property {OptionValue} value
  3166. *
  3167. * @typedef {Object} OptionRangeInfo
  3168. * @property {number} start - recommended range start
  3169. * @property {number} end - recommended range end
  3170. * @property {number} step - recommended range step
  3171. *
  3172. * @typedef {Object} OptionChoiceInfo
  3173. * @property {boolean | string} value - boolean for the option that is originally boolean type
  3174. * @property {string} description
  3175. * @property {string} [since] - undefined if available since the first version of the option
  3176. * @property {string} [deprecated] - deprecated since version
  3177. * @property {OptionValueInfo} [redirect] - redirect deprecated value
  3178. */
  3179. /** @type {{ [name: string]: OptionInfo }} */
  3180. var options = {
  3181. cursorOffset: {
  3182. since: "1.4.0",
  3183. category: CATEGORY_SPECIAL,
  3184. type: "int",
  3185. default: -1,
  3186. range: {
  3187. start: -1,
  3188. end: Infinity,
  3189. step: 1
  3190. },
  3191. description: dedent_1`
  3192. Print (to stderr) where a cursor at the given position would move to after formatting.
  3193. This option cannot be used with --range-start and --range-end.
  3194. `,
  3195. cliCategory: CATEGORY_EDITOR
  3196. },
  3197. endOfLine: {
  3198. since: "1.15.0",
  3199. category: CATEGORY_GLOBAL,
  3200. type: "choice",
  3201. default: "auto",
  3202. description: "Which end of line characters to apply.",
  3203. choices: [{
  3204. value: "auto",
  3205. description: dedent_1`
  3206. Maintain existing
  3207. (mixed values within one file are normalised by looking at what's used after the first line)
  3208. `
  3209. }, {
  3210. value: "lf",
  3211. description: "Line Feed only (\\n), common on Linux and macOS as well as inside git repos"
  3212. }, {
  3213. value: "crlf",
  3214. description: "Carriage Return + Line Feed characters (\\r\\n), common on Windows"
  3215. }, {
  3216. value: "cr",
  3217. description: "Carriage Return character only (\\r), used very rarely"
  3218. }]
  3219. },
  3220. filepath: {
  3221. since: "1.4.0",
  3222. category: CATEGORY_SPECIAL,
  3223. type: "path",
  3224. description: "Specify the input filepath. This will be used to do parser inference.",
  3225. cliName: "stdin-filepath",
  3226. cliCategory: CATEGORY_OTHER,
  3227. cliDescription: "Path to the file to pretend that stdin comes from."
  3228. },
  3229. insertPragma: {
  3230. since: "1.8.0",
  3231. category: CATEGORY_SPECIAL,
  3232. type: "boolean",
  3233. default: false,
  3234. description: "Insert @format pragma into file's first docblock comment.",
  3235. cliCategory: CATEGORY_OTHER
  3236. },
  3237. parser: {
  3238. since: "0.0.10",
  3239. category: CATEGORY_GLOBAL,
  3240. type: "choice",
  3241. default: [{
  3242. since: "0.0.10",
  3243. value: "babylon"
  3244. }, {
  3245. since: "1.13.0",
  3246. value: undefined
  3247. }],
  3248. description: "Which parser to use.",
  3249. exception: function exception(value) {
  3250. return typeof value === "string" || typeof value === "function";
  3251. },
  3252. choices: [{
  3253. value: "flow",
  3254. description: "Flow"
  3255. }, {
  3256. value: "babylon",
  3257. description: "JavaScript",
  3258. deprecated: "1.16.0",
  3259. redirect: "babel"
  3260. }, {
  3261. value: "babel",
  3262. since: "1.16.0",
  3263. description: "JavaScript"
  3264. }, {
  3265. value: "babel-flow",
  3266. since: "1.16.0",
  3267. description: "Flow"
  3268. }, {
  3269. value: "typescript",
  3270. since: "1.4.0",
  3271. description: "TypeScript"
  3272. }, {
  3273. value: "css",
  3274. since: "1.7.1",
  3275. description: "CSS"
  3276. }, {
  3277. value: "postcss",
  3278. since: "1.4.0",
  3279. description: "CSS/Less/SCSS",
  3280. deprecated: "1.7.1",
  3281. redirect: "css"
  3282. }, {
  3283. value: "less",
  3284. since: "1.7.1",
  3285. description: "Less"
  3286. }, {
  3287. value: "scss",
  3288. since: "1.7.1",
  3289. description: "SCSS"
  3290. }, {
  3291. value: "json",
  3292. since: "1.5.0",
  3293. description: "JSON"
  3294. }, {
  3295. value: "json5",
  3296. since: "1.13.0",
  3297. description: "JSON5"
  3298. }, {
  3299. value: "json-stringify",
  3300. since: "1.13.0",
  3301. description: "JSON.stringify"
  3302. }, {
  3303. value: "graphql",
  3304. since: "1.5.0",
  3305. description: "GraphQL"
  3306. }, {
  3307. value: "markdown",
  3308. since: "1.8.0",
  3309. description: "Markdown"
  3310. }, {
  3311. value: "mdx",
  3312. since: "1.15.0",
  3313. description: "MDX"
  3314. }, {
  3315. value: "vue",
  3316. since: "1.10.0",
  3317. description: "Vue"
  3318. }, {
  3319. value: "yaml",
  3320. since: "1.14.0",
  3321. description: "YAML"
  3322. }, {
  3323. value: "glimmer",
  3324. since: null,
  3325. description: "Handlebars"
  3326. }, {
  3327. value: "html",
  3328. since: "1.15.0",
  3329. description: "HTML"
  3330. }, {
  3331. value: "angular",
  3332. since: "1.15.0",
  3333. description: "Angular"
  3334. }, {
  3335. value: "lwc",
  3336. since: "1.17.0",
  3337. description: "Lightning Web Components"
  3338. }]
  3339. },
  3340. plugins: {
  3341. since: "1.10.0",
  3342. type: "path",
  3343. array: true,
  3344. default: [{
  3345. value: []
  3346. }],
  3347. category: CATEGORY_GLOBAL,
  3348. description: "Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
  3349. exception: function exception(value) {
  3350. return typeof value === "string" || typeof value === "object";
  3351. },
  3352. cliName: "plugin",
  3353. cliCategory: CATEGORY_CONFIG
  3354. },
  3355. pluginSearchDirs: {
  3356. since: "1.13.0",
  3357. type: "path",
  3358. array: true,
  3359. default: [{
  3360. value: []
  3361. }],
  3362. category: CATEGORY_GLOBAL,
  3363. description: dedent_1`
  3364. Custom directory that contains prettier plugins in node_modules subdirectory.
  3365. Overrides default behavior when plugins are searched relatively to the location of Prettier.
  3366. Multiple values are accepted.
  3367. `,
  3368. exception: function exception(value) {
  3369. return typeof value === "string" || typeof value === "object";
  3370. },
  3371. cliName: "plugin-search-dir",
  3372. cliCategory: CATEGORY_CONFIG
  3373. },
  3374. printWidth: {
  3375. since: "0.0.0",
  3376. category: CATEGORY_GLOBAL,
  3377. type: "int",
  3378. default: 80,
  3379. description: "The line length where Prettier will try wrap.",
  3380. range: {
  3381. start: 0,
  3382. end: Infinity,
  3383. step: 1
  3384. }
  3385. },
  3386. rangeEnd: {
  3387. since: "1.4.0",
  3388. category: CATEGORY_SPECIAL,
  3389. type: "int",
  3390. default: Infinity,
  3391. range: {
  3392. start: 0,
  3393. end: Infinity,
  3394. step: 1
  3395. },
  3396. description: dedent_1`
  3397. Format code ending at a given character offset (exclusive).
  3398. The range will extend forwards to the end of the selected statement.
  3399. This option cannot be used with --cursor-offset.
  3400. `,
  3401. cliCategory: CATEGORY_EDITOR
  3402. },
  3403. rangeStart: {
  3404. since: "1.4.0",
  3405. category: CATEGORY_SPECIAL,
  3406. type: "int",
  3407. default: 0,
  3408. range: {
  3409. start: 0,
  3410. end: Infinity,
  3411. step: 1
  3412. },
  3413. description: dedent_1`
  3414. Format code starting at a given character offset.
  3415. The range will extend backwards to the start of the first line containing the selected statement.
  3416. This option cannot be used with --cursor-offset.
  3417. `,
  3418. cliCategory: CATEGORY_EDITOR
  3419. },
  3420. requirePragma: {
  3421. since: "1.7.0",
  3422. category: CATEGORY_SPECIAL,
  3423. type: "boolean",
  3424. default: false,
  3425. description: dedent_1`
  3426. Require either '@prettier' or '@format' to be present in the file's first docblock comment
  3427. in order for it to be formatted.
  3428. `,
  3429. cliCategory: CATEGORY_OTHER
  3430. },
  3431. tabWidth: {
  3432. type: "int",
  3433. category: CATEGORY_GLOBAL,
  3434. default: 2,
  3435. description: "Number of spaces per indentation level.",
  3436. range: {
  3437. start: 0,
  3438. end: Infinity,
  3439. step: 1
  3440. }
  3441. },
  3442. useFlowParser: {
  3443. since: "0.0.0",
  3444. category: CATEGORY_GLOBAL,
  3445. type: "boolean",
  3446. default: [{
  3447. since: "0.0.0",
  3448. value: false
  3449. }, {
  3450. since: "1.15.0",
  3451. value: undefined
  3452. }],
  3453. deprecated: "0.0.10",
  3454. description: "Use flow parser.",
  3455. redirect: {
  3456. option: "parser",
  3457. value: "flow"
  3458. },
  3459. cliName: "flow-parser"
  3460. },
  3461. useTabs: {
  3462. since: "1.0.0",
  3463. category: CATEGORY_GLOBAL,
  3464. type: "boolean",
  3465. default: false,
  3466. description: "Indent with tabs instead of spaces."
  3467. }
  3468. };
  3469. var coreOptions = {
  3470. CATEGORY_CONFIG,
  3471. CATEGORY_EDITOR,
  3472. CATEGORY_FORMAT,
  3473. CATEGORY_OTHER,
  3474. CATEGORY_OUTPUT,
  3475. CATEGORY_GLOBAL,
  3476. CATEGORY_SPECIAL,
  3477. options
  3478. };
  3479. var require$$0 = getCjsExportFromNamespace(_package$1);
  3480. var currentVersion = require$$0.version;
  3481. var coreOptions$1 = coreOptions.options;
  3482. function getSupportInfo(version, opts) {
  3483. opts = Object.assign({
  3484. plugins: [],
  3485. showUnreleased: false,
  3486. showDeprecated: false,
  3487. showInternal: false
  3488. }, opts);
  3489. if (!version) {
  3490. // pre-release version is smaller than the normal version in semver,
  3491. // we need to treat it as the normal one so as to test new features.
  3492. version = currentVersion.split("-", 1)[0];
  3493. }
  3494. var plugins = opts.plugins;
  3495. var options = arrayify(Object.assign(plugins.reduce(function (currentOptions, plugin) {
  3496. return Object.assign(currentOptions, plugin.options);
  3497. }, {}), coreOptions$1), "name").sort(function (a, b) {
  3498. return a.name === b.name ? 0 : a.name < b.name ? -1 : 1;
  3499. }).filter(filterSince).filter(filterDeprecated).map(mapDeprecated).map(mapInternal).map(function (option) {
  3500. var newOption = Object.assign({}, option);
  3501. if (Array.isArray(newOption.default)) {
  3502. newOption.default = newOption.default.length === 1 ? newOption.default[0].value : newOption.default.filter(filterSince).sort(function (info1, info2) {
  3503. return semver.compare(info2.since, info1.since);
  3504. })[0].value;
  3505. }
  3506. if (Array.isArray(newOption.choices)) {
  3507. newOption.choices = newOption.choices.filter(filterSince).filter(filterDeprecated).map(mapDeprecated);
  3508. }
  3509. return newOption;
  3510. }).map(function (option) {
  3511. var filteredPlugins = plugins.filter(function (plugin) {
  3512. return plugin.defaultOptions && plugin.defaultOptions[option.name] !== undefined;
  3513. });
  3514. var pluginDefaults = filteredPlugins.reduce(function (reduced, plugin) {
  3515. reduced[plugin.name] = plugin.defaultOptions[option.name];
  3516. return reduced;
  3517. }, {});
  3518. return Object.assign(option, {
  3519. pluginDefaults
  3520. });
  3521. });
  3522. var usePostCssParser = semver.lt(version, "1.7.1");
  3523. var useBabylonParser = semver.lt(version, "1.16.0");
  3524. var languages = plugins.reduce(function (all, plugin) {
  3525. return all.concat(plugin.languages || []);
  3526. }, []).filter(filterSince).map(function (language) {
  3527. // Prevent breaking changes
  3528. if (language.name === "Markdown") {
  3529. return Object.assign({}, language, {
  3530. parsers: ["markdown"]
  3531. });
  3532. }
  3533. if (language.name === "TypeScript") {
  3534. return Object.assign({}, language, {
  3535. parsers: ["typescript"]
  3536. });
  3537. } // "babylon" was renamed to "babel" in 1.16.0
  3538. if (useBabylonParser && language.parsers.indexOf("babel") !== -1) {
  3539. return Object.assign({}, language, {
  3540. parsers: language.parsers.map(function (parser) {
  3541. return parser === "babel" ? "babylon" : parser;
  3542. })
  3543. });
  3544. }
  3545. if (usePostCssParser && (language.name === "CSS" || language.group === "CSS")) {
  3546. return Object.assign({}, language, {
  3547. parsers: ["postcss"]
  3548. });
  3549. }
  3550. return language;
  3551. });
  3552. return {
  3553. languages,
  3554. options
  3555. };
  3556. function filterSince(object) {
  3557. return opts.showUnreleased || !("since" in object) || object.since && semver.gte(version, object.since);
  3558. }
  3559. function filterDeprecated(object) {
  3560. return opts.showDeprecated || !("deprecated" in object) || object.deprecated && semver.lt(version, object.deprecated);
  3561. }
  3562. function mapDeprecated(object) {
  3563. if (!object.deprecated || opts.showDeprecated) {
  3564. return object;
  3565. }
  3566. var newObject = Object.assign({}, object);
  3567. delete newObject.deprecated;
  3568. delete newObject.redirect;
  3569. return newObject;
  3570. }
  3571. function mapInternal(object) {
  3572. if (opts.showInternal) {
  3573. return object;
  3574. }
  3575. var newObject = Object.assign({}, object);
  3576. delete newObject.cliName;
  3577. delete newObject.cliCategory;
  3578. delete newObject.cliDescription;
  3579. return newObject;
  3580. }
  3581. }
  3582. var support = {
  3583. getSupportInfo
  3584. };
  3585. /*! *****************************************************************************
  3586. Copyright (c) Microsoft Corporation. All rights reserved.
  3587. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  3588. this file except in compliance with the License. You may obtain a copy of the
  3589. License at http://www.apache.org/licenses/LICENSE-2.0
  3590. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  3591. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  3592. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  3593. MERCHANTABLITY OR NON-INFRINGEMENT.
  3594. See the Apache Version 2.0 License for specific language governing permissions
  3595. and limitations under the License.
  3596. ***************************************************************************** */
  3597. /* global Reflect, Promise */
  3598. var _extendStatics = function extendStatics(d, b) {
  3599. _extendStatics = Object.setPrototypeOf || {
  3600. __proto__: []
  3601. } instanceof Array && function (d, b) {
  3602. d.__proto__ = b;
  3603. } || function (d, b) {
  3604. for (var p in b) {
  3605. if (b.hasOwnProperty(p)) d[p] = b[p];
  3606. }
  3607. };
  3608. return _extendStatics(d, b);
  3609. };
  3610. function __extends(d, b) {
  3611. _extendStatics(d, b);
  3612. function __() {
  3613. this.constructor = d;
  3614. }
  3615. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  3616. }
  3617. var _assign = function __assign() {
  3618. _assign = Object.assign || function __assign(t) {
  3619. for (var s, i = 1, n = arguments.length; i < n; i++) {
  3620. s = arguments[i];
  3621. for (var p in s) {
  3622. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  3623. }
  3624. }
  3625. return t;
  3626. };
  3627. return _assign.apply(this, arguments);
  3628. };
  3629. function __rest(s, e) {
  3630. var t = {};
  3631. for (var p in s) {
  3632. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  3633. }
  3634. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  3635. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  3636. }
  3637. return t;
  3638. }
  3639. function __decorate(decorators, target, key, desc) {
  3640. var c = arguments.length,
  3641. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  3642. d;
  3643. 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--) {
  3644. if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  3645. }
  3646. return c > 3 && r && Object.defineProperty(target, key, r), r;
  3647. }
  3648. function __param(paramIndex, decorator) {
  3649. return function (target, key) {
  3650. decorator(target, key, paramIndex);
  3651. };
  3652. }
  3653. function __metadata(metadataKey, metadataValue) {
  3654. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  3655. }
  3656. function __awaiter(thisArg, _arguments, P, generator) {
  3657. return new (P || (P = Promise))(function (resolve, reject) {
  3658. function fulfilled(value) {
  3659. try {
  3660. step(generator.next(value));
  3661. } catch (e) {
  3662. reject(e);
  3663. }
  3664. }
  3665. function rejected(value) {
  3666. try {
  3667. step(generator["throw"](value));
  3668. } catch (e) {
  3669. reject(e);
  3670. }
  3671. }
  3672. function step(result) {
  3673. result.done ? resolve(result.value) : new P(function (resolve) {
  3674. resolve(result.value);
  3675. }).then(fulfilled, rejected);
  3676. }
  3677. step((generator = generator.apply(thisArg, _arguments || [])).next());
  3678. });
  3679. }
  3680. function __generator(thisArg, body) {
  3681. var _ = {
  3682. label: 0,
  3683. sent: function sent() {
  3684. if (t[0] & 1) throw t[1];
  3685. return t[1];
  3686. },
  3687. trys: [],
  3688. ops: []
  3689. },
  3690. f,
  3691. y,
  3692. t,
  3693. g;
  3694. return g = {
  3695. next: verb(0),
  3696. "throw": verb(1),
  3697. "return": verb(2)
  3698. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  3699. return this;
  3700. }), g;
  3701. function verb(n) {
  3702. return function (v) {
  3703. return step([n, v]);
  3704. };
  3705. }
  3706. function step(op) {
  3707. if (f) throw new TypeError("Generator is already executing.");
  3708. while (_) {
  3709. try {
  3710. 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;
  3711. if (y = 0, t) op = [op[0] & 2, t.value];
  3712. switch (op[0]) {
  3713. case 0:
  3714. case 1:
  3715. t = op;
  3716. break;
  3717. case 4:
  3718. _.label++;
  3719. return {
  3720. value: op[1],
  3721. done: false
  3722. };
  3723. case 5:
  3724. _.label++;
  3725. y = op[1];
  3726. op = [0];
  3727. continue;
  3728. case 7:
  3729. op = _.ops.pop();
  3730. _.trys.pop();
  3731. continue;
  3732. default:
  3733. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  3734. _ = 0;
  3735. continue;
  3736. }
  3737. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  3738. _.label = op[1];
  3739. break;
  3740. }
  3741. if (op[0] === 6 && _.label < t[1]) {
  3742. _.label = t[1];
  3743. t = op;
  3744. break;
  3745. }
  3746. if (t && _.label < t[2]) {
  3747. _.label = t[2];
  3748. _.ops.push(op);
  3749. break;
  3750. }
  3751. if (t[2]) _.ops.pop();
  3752. _.trys.pop();
  3753. continue;
  3754. }
  3755. op = body.call(thisArg, _);
  3756. } catch (e) {
  3757. op = [6, e];
  3758. y = 0;
  3759. } finally {
  3760. f = t = 0;
  3761. }
  3762. }
  3763. if (op[0] & 5) throw op[1];
  3764. return {
  3765. value: op[0] ? op[1] : void 0,
  3766. done: true
  3767. };
  3768. }
  3769. }
  3770. function __exportStar(m, exports) {
  3771. for (var p in m) {
  3772. if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  3773. }
  3774. }
  3775. function __values(o) {
  3776. var m = typeof Symbol === "function" && o[Symbol.iterator],
  3777. i = 0;
  3778. if (m) return m.call(o);
  3779. return {
  3780. next: function next() {
  3781. if (o && i >= o.length) o = void 0;
  3782. return {
  3783. value: o && o[i++],
  3784. done: !o
  3785. };
  3786. }
  3787. };
  3788. }
  3789. function __read(o, n) {
  3790. var m = typeof Symbol === "function" && o[Symbol.iterator];
  3791. if (!m) return o;
  3792. var i = m.call(o),
  3793. r,
  3794. ar = [],
  3795. e;
  3796. try {
  3797. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
  3798. ar.push(r.value);
  3799. }
  3800. } catch (error) {
  3801. e = {
  3802. error: error
  3803. };
  3804. } finally {
  3805. try {
  3806. if (r && !r.done && (m = i["return"])) m.call(i);
  3807. } finally {
  3808. if (e) throw e.error;
  3809. }
  3810. }
  3811. return ar;
  3812. }
  3813. function __spread() {
  3814. for (var ar = [], i = 0; i < arguments.length; i++) {
  3815. ar = ar.concat(__read(arguments[i]));
  3816. }
  3817. return ar;
  3818. }
  3819. function __spreadArrays() {
  3820. for (var s = 0, i = 0, il = arguments.length; i < il; i++) {
  3821. s += arguments[i].length;
  3822. }
  3823. for (var r = Array(s), k = 0, i = 0; i < il; i++) {
  3824. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) {
  3825. r[k] = a[j];
  3826. }
  3827. }
  3828. return r;
  3829. }
  3830. function __await(v) {
  3831. return this instanceof __await ? (this.v = v, this) : new __await(v);
  3832. }
  3833. function __asyncGenerator(thisArg, _arguments, generator) {
  3834. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  3835. var g = generator.apply(thisArg, _arguments || []),
  3836. i,
  3837. q = [];
  3838. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
  3839. return this;
  3840. }, i;
  3841. function verb(n) {
  3842. if (g[n]) i[n] = function (v) {
  3843. return new Promise(function (a, b) {
  3844. q.push([n, v, a, b]) > 1 || resume(n, v);
  3845. });
  3846. };
  3847. }
  3848. function resume(n, v) {
  3849. try {
  3850. step(g[n](v));
  3851. } catch (e) {
  3852. settle(q[0][3], e);
  3853. }
  3854. }
  3855. function step(r) {
  3856. r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
  3857. }
  3858. function fulfill(value) {
  3859. resume("next", value);
  3860. }
  3861. function reject(value) {
  3862. resume("throw", value);
  3863. }
  3864. function settle(f, v) {
  3865. if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
  3866. }
  3867. }
  3868. function __asyncDelegator(o) {
  3869. var i, p;
  3870. return i = {}, verb("next"), verb("throw", function (e) {
  3871. throw e;
  3872. }), verb("return"), i[Symbol.iterator] = function () {
  3873. return this;
  3874. }, i;
  3875. function verb(n, f) {
  3876. i[n] = o[n] ? function (v) {
  3877. return (p = !p) ? {
  3878. value: __await(o[n](v)),
  3879. done: n === "return"
  3880. } : f ? f(v) : v;
  3881. } : f;
  3882. }
  3883. }
  3884. function __asyncValues(o) {
  3885. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  3886. var m = o[Symbol.asyncIterator],
  3887. i;
  3888. 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 () {
  3889. return this;
  3890. }, i);
  3891. function verb(n) {
  3892. i[n] = o[n] && function (v) {
  3893. return new Promise(function (resolve, reject) {
  3894. v = o[n](v), settle(resolve, reject, v.done, v.value);
  3895. });
  3896. };
  3897. }
  3898. function settle(resolve, reject, d, v) {
  3899. Promise.resolve(v).then(function (v) {
  3900. resolve({
  3901. value: v,
  3902. done: d
  3903. });
  3904. }, reject);
  3905. }
  3906. }
  3907. function __makeTemplateObject(cooked, raw) {
  3908. if (Object.defineProperty) {
  3909. Object.defineProperty(cooked, "raw", {
  3910. value: raw
  3911. });
  3912. } else {
  3913. cooked.raw = raw;
  3914. }
  3915. return cooked;
  3916. }
  3917. function __importStar(mod) {
  3918. if (mod && mod.__esModule) return mod;
  3919. var result = {};
  3920. if (mod != null) for (var k in mod) {
  3921. if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  3922. }
  3923. result.default = mod;
  3924. return result;
  3925. }
  3926. function __importDefault(mod) {
  3927. return mod && mod.__esModule ? mod : {
  3928. default: mod
  3929. };
  3930. }
  3931. var tslib_es6 = /*#__PURE__*/Object.freeze({
  3932. __proto__: null,
  3933. __extends: __extends,
  3934. get __assign () { return _assign; },
  3935. __rest: __rest,
  3936. __decorate: __decorate,
  3937. __param: __param,
  3938. __metadata: __metadata,
  3939. __awaiter: __awaiter,
  3940. __generator: __generator,
  3941. __exportStar: __exportStar,
  3942. __values: __values,
  3943. __read: __read,
  3944. __spread: __spread,
  3945. __spreadArrays: __spreadArrays,
  3946. __await: __await,
  3947. __asyncGenerator: __asyncGenerator,
  3948. __asyncDelegator: __asyncDelegator,
  3949. __asyncValues: __asyncValues,
  3950. __makeTemplateObject: __makeTemplateObject,
  3951. __importStar: __importStar,
  3952. __importDefault: __importDefault
  3953. });
  3954. var api = createCommonjsModule(function (module, exports) {
  3955. Object.defineProperty(exports, "__esModule", {
  3956. value: true
  3957. });
  3958. exports.apiDescriptor = {
  3959. key: function key(_key) {
  3960. return /^[$_a-zA-Z][$_a-zA-Z0-9]*$/.test(_key) ? _key : JSON.stringify(_key);
  3961. },
  3962. value(value) {
  3963. if (value === null || typeof value !== 'object') {
  3964. return JSON.stringify(value);
  3965. }
  3966. if (Array.isArray(value)) {
  3967. return `[${value.map(function (subValue) {
  3968. return exports.apiDescriptor.value(subValue);
  3969. }).join(', ')}]`;
  3970. }
  3971. var keys = Object.keys(value);
  3972. return keys.length === 0 ? '{}' : `{ ${keys.map(function (key) {
  3973. return `${exports.apiDescriptor.key(key)}: ${exports.apiDescriptor.value(value[key])}`;
  3974. }).join(', ')} }`;
  3975. },
  3976. pair: function pair(_ref) {
  3977. var key = _ref.key,
  3978. value = _ref.value;
  3979. return exports.apiDescriptor.value({
  3980. [key]: value
  3981. });
  3982. }
  3983. };
  3984. });
  3985. unwrapExports(api);
  3986. var api_1 = api.apiDescriptor;
  3987. var descriptors = createCommonjsModule(function (module, exports) {
  3988. Object.defineProperty(exports, "__esModule", {
  3989. value: true
  3990. });
  3991. tslib_es6.__exportStar(api, exports);
  3992. });
  3993. unwrapExports(descriptors);
  3994. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  3995. var escapeStringRegexp = function escapeStringRegexp(str) {
  3996. if (typeof str !== 'string') {
  3997. throw new TypeError('Expected a string');
  3998. }
  3999. return str.replace(matchOperatorsRe, '\\$&');
  4000. };
  4001. var colorName = {
  4002. "aliceblue": [240, 248, 255],
  4003. "antiquewhite": [250, 235, 215],
  4004. "aqua": [0, 255, 255],
  4005. "aquamarine": [127, 255, 212],
  4006. "azure": [240, 255, 255],
  4007. "beige": [245, 245, 220],
  4008. "bisque": [255, 228, 196],
  4009. "black": [0, 0, 0],
  4010. "blanchedalmond": [255, 235, 205],
  4011. "blue": [0, 0, 255],
  4012. "blueviolet": [138, 43, 226],
  4013. "brown": [165, 42, 42],
  4014. "burlywood": [222, 184, 135],
  4015. "cadetblue": [95, 158, 160],
  4016. "chartreuse": [127, 255, 0],
  4017. "chocolate": [210, 105, 30],
  4018. "coral": [255, 127, 80],
  4019. "cornflowerblue": [100, 149, 237],
  4020. "cornsilk": [255, 248, 220],
  4021. "crimson": [220, 20, 60],
  4022. "cyan": [0, 255, 255],
  4023. "darkblue": [0, 0, 139],
  4024. "darkcyan": [0, 139, 139],
  4025. "darkgoldenrod": [184, 134, 11],
  4026. "darkgray": [169, 169, 169],
  4027. "darkgreen": [0, 100, 0],
  4028. "darkgrey": [169, 169, 169],
  4029. "darkkhaki": [189, 183, 107],
  4030. "darkmagenta": [139, 0, 139],
  4031. "darkolivegreen": [85, 107, 47],
  4032. "darkorange": [255, 140, 0],
  4033. "darkorchid": [153, 50, 204],
  4034. "darkred": [139, 0, 0],
  4035. "darksalmon": [233, 150, 122],
  4036. "darkseagreen": [143, 188, 143],
  4037. "darkslateblue": [72, 61, 139],
  4038. "darkslategray": [47, 79, 79],
  4039. "darkslategrey": [47, 79, 79],
  4040. "darkturquoise": [0, 206, 209],
  4041. "darkviolet": [148, 0, 211],
  4042. "deeppink": [255, 20, 147],
  4043. "deepskyblue": [0, 191, 255],
  4044. "dimgray": [105, 105, 105],
  4045. "dimgrey": [105, 105, 105],
  4046. "dodgerblue": [30, 144, 255],
  4047. "firebrick": [178, 34, 34],
  4048. "floralwhite": [255, 250, 240],
  4049. "forestgreen": [34, 139, 34],
  4050. "fuchsia": [255, 0, 255],
  4051. "gainsboro": [220, 220, 220],
  4052. "ghostwhite": [248, 248, 255],
  4053. "gold": [255, 215, 0],
  4054. "goldenrod": [218, 165, 32],
  4055. "gray": [128, 128, 128],
  4056. "green": [0, 128, 0],
  4057. "greenyellow": [173, 255, 47],
  4058. "grey": [128, 128, 128],
  4059. "honeydew": [240, 255, 240],
  4060. "hotpink": [255, 105, 180],
  4061. "indianred": [205, 92, 92],
  4062. "indigo": [75, 0, 130],
  4063. "ivory": [255, 255, 240],
  4064. "khaki": [240, 230, 140],
  4065. "lavender": [230, 230, 250],
  4066. "lavenderblush": [255, 240, 245],
  4067. "lawngreen": [124, 252, 0],
  4068. "lemonchiffon": [255, 250, 205],
  4069. "lightblue": [173, 216, 230],
  4070. "lightcoral": [240, 128, 128],
  4071. "lightcyan": [224, 255, 255],
  4072. "lightgoldenrodyellow": [250, 250, 210],
  4073. "lightgray": [211, 211, 211],
  4074. "lightgreen": [144, 238, 144],
  4075. "lightgrey": [211, 211, 211],
  4076. "lightpink": [255, 182, 193],
  4077. "lightsalmon": [255, 160, 122],
  4078. "lightseagreen": [32, 178, 170],
  4079. "lightskyblue": [135, 206, 250],
  4080. "lightslategray": [119, 136, 153],
  4081. "lightslategrey": [119, 136, 153],
  4082. "lightsteelblue": [176, 196, 222],
  4083. "lightyellow": [255, 255, 224],
  4084. "lime": [0, 255, 0],
  4085. "limegreen": [50, 205, 50],
  4086. "linen": [250, 240, 230],
  4087. "magenta": [255, 0, 255],
  4088. "maroon": [128, 0, 0],
  4089. "mediumaquamarine": [102, 205, 170],
  4090. "mediumblue": [0, 0, 205],
  4091. "mediumorchid": [186, 85, 211],
  4092. "mediumpurple": [147, 112, 219],
  4093. "mediumseagreen": [60, 179, 113],
  4094. "mediumslateblue": [123, 104, 238],
  4095. "mediumspringgreen": [0, 250, 154],
  4096. "mediumturquoise": [72, 209, 204],
  4097. "mediumvioletred": [199, 21, 133],
  4098. "midnightblue": [25, 25, 112],
  4099. "mintcream": [245, 255, 250],
  4100. "mistyrose": [255, 228, 225],
  4101. "moccasin": [255, 228, 181],
  4102. "navajowhite": [255, 222, 173],
  4103. "navy": [0, 0, 128],
  4104. "oldlace": [253, 245, 230],
  4105. "olive": [128, 128, 0],
  4106. "olivedrab": [107, 142, 35],
  4107. "orange": [255, 165, 0],
  4108. "orangered": [255, 69, 0],
  4109. "orchid": [218, 112, 214],
  4110. "palegoldenrod": [238, 232, 170],
  4111. "palegreen": [152, 251, 152],
  4112. "paleturquoise": [175, 238, 238],
  4113. "palevioletred": [219, 112, 147],
  4114. "papayawhip": [255, 239, 213],
  4115. "peachpuff": [255, 218, 185],
  4116. "peru": [205, 133, 63],
  4117. "pink": [255, 192, 203],
  4118. "plum": [221, 160, 221],
  4119. "powderblue": [176, 224, 230],
  4120. "purple": [128, 0, 128],
  4121. "rebeccapurple": [102, 51, 153],
  4122. "red": [255, 0, 0],
  4123. "rosybrown": [188, 143, 143],
  4124. "royalblue": [65, 105, 225],
  4125. "saddlebrown": [139, 69, 19],
  4126. "salmon": [250, 128, 114],
  4127. "sandybrown": [244, 164, 96],
  4128. "seagreen": [46, 139, 87],
  4129. "seashell": [255, 245, 238],
  4130. "sienna": [160, 82, 45],
  4131. "silver": [192, 192, 192],
  4132. "skyblue": [135, 206, 235],
  4133. "slateblue": [106, 90, 205],
  4134. "slategray": [112, 128, 144],
  4135. "slategrey": [112, 128, 144],
  4136. "snow": [255, 250, 250],
  4137. "springgreen": [0, 255, 127],
  4138. "steelblue": [70, 130, 180],
  4139. "tan": [210, 180, 140],
  4140. "teal": [0, 128, 128],
  4141. "thistle": [216, 191, 216],
  4142. "tomato": [255, 99, 71],
  4143. "turquoise": [64, 224, 208],
  4144. "violet": [238, 130, 238],
  4145. "wheat": [245, 222, 179],
  4146. "white": [255, 255, 255],
  4147. "whitesmoke": [245, 245, 245],
  4148. "yellow": [255, 255, 0],
  4149. "yellowgreen": [154, 205, 50]
  4150. };
  4151. var conversions = createCommonjsModule(function (module) {
  4152. /* MIT license */
  4153. // NOTE: conversions should only return primitive values (i.e. arrays, or
  4154. // values that give correct `typeof` results).
  4155. // do not use box values types (i.e. Number(), String(), etc.)
  4156. var reverseKeywords = {};
  4157. for (var key in colorName) {
  4158. if (colorName.hasOwnProperty(key)) {
  4159. reverseKeywords[colorName[key]] = key;
  4160. }
  4161. }
  4162. var convert = module.exports = {
  4163. rgb: {
  4164. channels: 3,
  4165. labels: 'rgb'
  4166. },
  4167. hsl: {
  4168. channels: 3,
  4169. labels: 'hsl'
  4170. },
  4171. hsv: {
  4172. channels: 3,
  4173. labels: 'hsv'
  4174. },
  4175. hwb: {
  4176. channels: 3,
  4177. labels: 'hwb'
  4178. },
  4179. cmyk: {
  4180. channels: 4,
  4181. labels: 'cmyk'
  4182. },
  4183. xyz: {
  4184. channels: 3,
  4185. labels: 'xyz'
  4186. },
  4187. lab: {
  4188. channels: 3,
  4189. labels: 'lab'
  4190. },
  4191. lch: {
  4192. channels: 3,
  4193. labels: 'lch'
  4194. },
  4195. hex: {
  4196. channels: 1,
  4197. labels: ['hex']
  4198. },
  4199. keyword: {
  4200. channels: 1,
  4201. labels: ['keyword']
  4202. },
  4203. ansi16: {
  4204. channels: 1,
  4205. labels: ['ansi16']
  4206. },
  4207. ansi256: {
  4208. channels: 1,
  4209. labels: ['ansi256']
  4210. },
  4211. hcg: {
  4212. channels: 3,
  4213. labels: ['h', 'c', 'g']
  4214. },
  4215. apple: {
  4216. channels: 3,
  4217. labels: ['r16', 'g16', 'b16']
  4218. },
  4219. gray: {
  4220. channels: 1,
  4221. labels: ['gray']
  4222. }
  4223. }; // hide .channels and .labels properties
  4224. for (var model in convert) {
  4225. if (convert.hasOwnProperty(model)) {
  4226. if (!('channels' in convert[model])) {
  4227. throw new Error('missing channels property: ' + model);
  4228. }
  4229. if (!('labels' in convert[model])) {
  4230. throw new Error('missing channel labels property: ' + model);
  4231. }
  4232. if (convert[model].labels.length !== convert[model].channels) {
  4233. throw new Error('channel and label counts mismatch: ' + model);
  4234. }
  4235. var channels = convert[model].channels;
  4236. var labels = convert[model].labels;
  4237. delete convert[model].channels;
  4238. delete convert[model].labels;
  4239. Object.defineProperty(convert[model], 'channels', {
  4240. value: channels
  4241. });
  4242. Object.defineProperty(convert[model], 'labels', {
  4243. value: labels
  4244. });
  4245. }
  4246. }
  4247. convert.rgb.hsl = function (rgb) {
  4248. var r = rgb[0] / 255;
  4249. var g = rgb[1] / 255;
  4250. var b = rgb[2] / 255;
  4251. var min = Math.min(r, g, b);
  4252. var max = Math.max(r, g, b);
  4253. var delta = max - min;
  4254. var h;
  4255. var s;
  4256. var l;
  4257. if (max === min) {
  4258. h = 0;
  4259. } else if (r === max) {
  4260. h = (g - b) / delta;
  4261. } else if (g === max) {
  4262. h = 2 + (b - r) / delta;
  4263. } else if (b === max) {
  4264. h = 4 + (r - g) / delta;
  4265. }
  4266. h = Math.min(h * 60, 360);
  4267. if (h < 0) {
  4268. h += 360;
  4269. }
  4270. l = (min + max) / 2;
  4271. if (max === min) {
  4272. s = 0;
  4273. } else if (l <= 0.5) {
  4274. s = delta / (max + min);
  4275. } else {
  4276. s = delta / (2 - max - min);
  4277. }
  4278. return [h, s * 100, l * 100];
  4279. };
  4280. convert.rgb.hsv = function (rgb) {
  4281. var r = rgb[0];
  4282. var g = rgb[1];
  4283. var b = rgb[2];
  4284. var min = Math.min(r, g, b);
  4285. var max = Math.max(r, g, b);
  4286. var delta = max - min;
  4287. var h;
  4288. var s;
  4289. var v;
  4290. if (max === 0) {
  4291. s = 0;
  4292. } else {
  4293. s = delta / max * 1000 / 10;
  4294. }
  4295. if (max === min) {
  4296. h = 0;
  4297. } else if (r === max) {
  4298. h = (g - b) / delta;
  4299. } else if (g === max) {
  4300. h = 2 + (b - r) / delta;
  4301. } else if (b === max) {
  4302. h = 4 + (r - g) / delta;
  4303. }
  4304. h = Math.min(h * 60, 360);
  4305. if (h < 0) {
  4306. h += 360;
  4307. }
  4308. v = max / 255 * 1000 / 10;
  4309. return [h, s, v];
  4310. };
  4311. convert.rgb.hwb = function (rgb) {
  4312. var r = rgb[0];
  4313. var g = rgb[1];
  4314. var b = rgb[2];
  4315. var h = convert.rgb.hsl(rgb)[0];
  4316. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  4317. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  4318. return [h, w * 100, b * 100];
  4319. };
  4320. convert.rgb.cmyk = function (rgb) {
  4321. var r = rgb[0] / 255;
  4322. var g = rgb[1] / 255;
  4323. var b = rgb[2] / 255;
  4324. var c;
  4325. var m;
  4326. var y;
  4327. var k;
  4328. k = Math.min(1 - r, 1 - g, 1 - b);
  4329. c = (1 - r - k) / (1 - k) || 0;
  4330. m = (1 - g - k) / (1 - k) || 0;
  4331. y = (1 - b - k) / (1 - k) || 0;
  4332. return [c * 100, m * 100, y * 100, k * 100];
  4333. };
  4334. /**
  4335. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  4336. * */
  4337. function comparativeDistance(x, y) {
  4338. return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
  4339. }
  4340. convert.rgb.keyword = function (rgb) {
  4341. var reversed = reverseKeywords[rgb];
  4342. if (reversed) {
  4343. return reversed;
  4344. }
  4345. var currentClosestDistance = Infinity;
  4346. var currentClosestKeyword;
  4347. for (var keyword in colorName) {
  4348. if (colorName.hasOwnProperty(keyword)) {
  4349. var value = colorName[keyword]; // Compute comparative distance
  4350. var distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  4351. if (distance < currentClosestDistance) {
  4352. currentClosestDistance = distance;
  4353. currentClosestKeyword = keyword;
  4354. }
  4355. }
  4356. }
  4357. return currentClosestKeyword;
  4358. };
  4359. convert.keyword.rgb = function (keyword) {
  4360. return colorName[keyword];
  4361. };
  4362. convert.rgb.xyz = function (rgb) {
  4363. var r = rgb[0] / 255;
  4364. var g = rgb[1] / 255;
  4365. var b = rgb[2] / 255; // assume sRGB
  4366. r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
  4367. g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
  4368. b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
  4369. var x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  4370. var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  4371. var z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  4372. return [x * 100, y * 100, z * 100];
  4373. };
  4374. convert.rgb.lab = function (rgb) {
  4375. var xyz = convert.rgb.xyz(rgb);
  4376. var x = xyz[0];
  4377. var y = xyz[1];
  4378. var z = xyz[2];
  4379. var l;
  4380. var a;
  4381. var b;
  4382. x /= 95.047;
  4383. y /= 100;
  4384. z /= 108.883;
  4385. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  4386. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  4387. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  4388. l = 116 * y - 16;
  4389. a = 500 * (x - y);
  4390. b = 200 * (y - z);
  4391. return [l, a, b];
  4392. };
  4393. convert.hsl.rgb = function (hsl) {
  4394. var h = hsl[0] / 360;
  4395. var s = hsl[1] / 100;
  4396. var l = hsl[2] / 100;
  4397. var t1;
  4398. var t2;
  4399. var t3;
  4400. var rgb;
  4401. var val;
  4402. if (s === 0) {
  4403. val = l * 255;
  4404. return [val, val, val];
  4405. }
  4406. if (l < 0.5) {
  4407. t2 = l * (1 + s);
  4408. } else {
  4409. t2 = l + s - l * s;
  4410. }
  4411. t1 = 2 * l - t2;
  4412. rgb = [0, 0, 0];
  4413. for (var i = 0; i < 3; i++) {
  4414. t3 = h + 1 / 3 * -(i - 1);
  4415. if (t3 < 0) {
  4416. t3++;
  4417. }
  4418. if (t3 > 1) {
  4419. t3--;
  4420. }
  4421. if (6 * t3 < 1) {
  4422. val = t1 + (t2 - t1) * 6 * t3;
  4423. } else if (2 * t3 < 1) {
  4424. val = t2;
  4425. } else if (3 * t3 < 2) {
  4426. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  4427. } else {
  4428. val = t1;
  4429. }
  4430. rgb[i] = val * 255;
  4431. }
  4432. return rgb;
  4433. };
  4434. convert.hsl.hsv = function (hsl) {
  4435. var h = hsl[0];
  4436. var s = hsl[1] / 100;
  4437. var l = hsl[2] / 100;
  4438. var smin = s;
  4439. var lmin = Math.max(l, 0.01);
  4440. var sv;
  4441. var v;
  4442. l *= 2;
  4443. s *= l <= 1 ? l : 2 - l;
  4444. smin *= lmin <= 1 ? lmin : 2 - lmin;
  4445. v = (l + s) / 2;
  4446. sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  4447. return [h, sv * 100, v * 100];
  4448. };
  4449. convert.hsv.rgb = function (hsv) {
  4450. var h = hsv[0] / 60;
  4451. var s = hsv[1] / 100;
  4452. var v = hsv[2] / 100;
  4453. var hi = Math.floor(h) % 6;
  4454. var f = h - Math.floor(h);
  4455. var p = 255 * v * (1 - s);
  4456. var q = 255 * v * (1 - s * f);
  4457. var t = 255 * v * (1 - s * (1 - f));
  4458. v *= 255;
  4459. switch (hi) {
  4460. case 0:
  4461. return [v, t, p];
  4462. case 1:
  4463. return [q, v, p];
  4464. case 2:
  4465. return [p, v, t];
  4466. case 3:
  4467. return [p, q, v];
  4468. case 4:
  4469. return [t, p, v];
  4470. case 5:
  4471. return [v, p, q];
  4472. }
  4473. };
  4474. convert.hsv.hsl = function (hsv) {
  4475. var h = hsv[0];
  4476. var s = hsv[1] / 100;
  4477. var v = hsv[2] / 100;
  4478. var vmin = Math.max(v, 0.01);
  4479. var lmin;
  4480. var sl;
  4481. var l;
  4482. l = (2 - s) * v;
  4483. lmin = (2 - s) * vmin;
  4484. sl = s * vmin;
  4485. sl /= lmin <= 1 ? lmin : 2 - lmin;
  4486. sl = sl || 0;
  4487. l /= 2;
  4488. return [h, sl * 100, l * 100];
  4489. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  4490. convert.hwb.rgb = function (hwb) {
  4491. var h = hwb[0] / 360;
  4492. var wh = hwb[1] / 100;
  4493. var bl = hwb[2] / 100;
  4494. var ratio = wh + bl;
  4495. var i;
  4496. var v;
  4497. var f;
  4498. var n; // wh + bl cant be > 1
  4499. if (ratio > 1) {
  4500. wh /= ratio;
  4501. bl /= ratio;
  4502. }
  4503. i = Math.floor(6 * h);
  4504. v = 1 - bl;
  4505. f = 6 * h - i;
  4506. if ((i & 0x01) !== 0) {
  4507. f = 1 - f;
  4508. }
  4509. n = wh + f * (v - wh); // linear interpolation
  4510. var r;
  4511. var g;
  4512. var b;
  4513. switch (i) {
  4514. default:
  4515. case 6:
  4516. case 0:
  4517. r = v;
  4518. g = n;
  4519. b = wh;
  4520. break;
  4521. case 1:
  4522. r = n;
  4523. g = v;
  4524. b = wh;
  4525. break;
  4526. case 2:
  4527. r = wh;
  4528. g = v;
  4529. b = n;
  4530. break;
  4531. case 3:
  4532. r = wh;
  4533. g = n;
  4534. b = v;
  4535. break;
  4536. case 4:
  4537. r = n;
  4538. g = wh;
  4539. b = v;
  4540. break;
  4541. case 5:
  4542. r = v;
  4543. g = wh;
  4544. b = n;
  4545. break;
  4546. }
  4547. return [r * 255, g * 255, b * 255];
  4548. };
  4549. convert.cmyk.rgb = function (cmyk) {
  4550. var c = cmyk[0] / 100;
  4551. var m = cmyk[1] / 100;
  4552. var y = cmyk[2] / 100;
  4553. var k = cmyk[3] / 100;
  4554. var r;
  4555. var g;
  4556. var b;
  4557. r = 1 - Math.min(1, c * (1 - k) + k);
  4558. g = 1 - Math.min(1, m * (1 - k) + k);
  4559. b = 1 - Math.min(1, y * (1 - k) + k);
  4560. return [r * 255, g * 255, b * 255];
  4561. };
  4562. convert.xyz.rgb = function (xyz) {
  4563. var x = xyz[0] / 100;
  4564. var y = xyz[1] / 100;
  4565. var z = xyz[2] / 100;
  4566. var r;
  4567. var g;
  4568. var b;
  4569. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  4570. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  4571. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // assume sRGB
  4572. r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
  4573. g = g > 0.0031308 ? 1.055 * Math.pow(g, 1.0 / 2.4) - 0.055 : g * 12.92;
  4574. b = b > 0.0031308 ? 1.055 * Math.pow(b, 1.0 / 2.4) - 0.055 : b * 12.92;
  4575. r = Math.min(Math.max(0, r), 1);
  4576. g = Math.min(Math.max(0, g), 1);
  4577. b = Math.min(Math.max(0, b), 1);
  4578. return [r * 255, g * 255, b * 255];
  4579. };
  4580. convert.xyz.lab = function (xyz) {
  4581. var x = xyz[0];
  4582. var y = xyz[1];
  4583. var z = xyz[2];
  4584. var l;
  4585. var a;
  4586. var b;
  4587. x /= 95.047;
  4588. y /= 100;
  4589. z /= 108.883;
  4590. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  4591. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  4592. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  4593. l = 116 * y - 16;
  4594. a = 500 * (x - y);
  4595. b = 200 * (y - z);
  4596. return [l, a, b];
  4597. };
  4598. convert.lab.xyz = function (lab) {
  4599. var l = lab[0];
  4600. var a = lab[1];
  4601. var b = lab[2];
  4602. var x;
  4603. var y;
  4604. var z;
  4605. y = (l + 16) / 116;
  4606. x = a / 500 + y;
  4607. z = y - b / 200;
  4608. var y2 = Math.pow(y, 3);
  4609. var x2 = Math.pow(x, 3);
  4610. var z2 = Math.pow(z, 3);
  4611. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  4612. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  4613. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  4614. x *= 95.047;
  4615. y *= 100;
  4616. z *= 108.883;
  4617. return [x, y, z];
  4618. };
  4619. convert.lab.lch = function (lab) {
  4620. var l = lab[0];
  4621. var a = lab[1];
  4622. var b = lab[2];
  4623. var hr;
  4624. var h;
  4625. var c;
  4626. hr = Math.atan2(b, a);
  4627. h = hr * 360 / 2 / Math.PI;
  4628. if (h < 0) {
  4629. h += 360;
  4630. }
  4631. c = Math.sqrt(a * a + b * b);
  4632. return [l, c, h];
  4633. };
  4634. convert.lch.lab = function (lch) {
  4635. var l = lch[0];
  4636. var c = lch[1];
  4637. var h = lch[2];
  4638. var a;
  4639. var b;
  4640. var hr;
  4641. hr = h / 360 * 2 * Math.PI;
  4642. a = c * Math.cos(hr);
  4643. b = c * Math.sin(hr);
  4644. return [l, a, b];
  4645. };
  4646. convert.rgb.ansi16 = function (args) {
  4647. var r = args[0];
  4648. var g = args[1];
  4649. var b = args[2];
  4650. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  4651. value = Math.round(value / 50);
  4652. if (value === 0) {
  4653. return 30;
  4654. }
  4655. var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  4656. if (value === 2) {
  4657. ansi += 60;
  4658. }
  4659. return ansi;
  4660. };
  4661. convert.hsv.ansi16 = function (args) {
  4662. // optimization here; we already know the value and don't need to get
  4663. // it converted for us.
  4664. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  4665. };
  4666. convert.rgb.ansi256 = function (args) {
  4667. var r = args[0];
  4668. var g = args[1];
  4669. var b = args[2]; // we use the extended greyscale palette here, with the exception of
  4670. // black and white. normal palette only has 4 greyscale shades.
  4671. if (r === g && g === b) {
  4672. if (r < 8) {
  4673. return 16;
  4674. }
  4675. if (r > 248) {
  4676. return 231;
  4677. }
  4678. return Math.round((r - 8) / 247 * 24) + 232;
  4679. }
  4680. var ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  4681. return ansi;
  4682. };
  4683. convert.ansi16.rgb = function (args) {
  4684. var color = args % 10; // handle greyscale
  4685. if (color === 0 || color === 7) {
  4686. if (args > 50) {
  4687. color += 3.5;
  4688. }
  4689. color = color / 10.5 * 255;
  4690. return [color, color, color];
  4691. }
  4692. var mult = (~~(args > 50) + 1) * 0.5;
  4693. var r = (color & 1) * mult * 255;
  4694. var g = (color >> 1 & 1) * mult * 255;
  4695. var b = (color >> 2 & 1) * mult * 255;
  4696. return [r, g, b];
  4697. };
  4698. convert.ansi256.rgb = function (args) {
  4699. // handle greyscale
  4700. if (args >= 232) {
  4701. var c = (args - 232) * 10 + 8;
  4702. return [c, c, c];
  4703. }
  4704. args -= 16;
  4705. var rem;
  4706. var r = Math.floor(args / 36) / 5 * 255;
  4707. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  4708. var b = rem % 6 / 5 * 255;
  4709. return [r, g, b];
  4710. };
  4711. convert.rgb.hex = function (args) {
  4712. var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  4713. var string = integer.toString(16).toUpperCase();
  4714. return '000000'.substring(string.length) + string;
  4715. };
  4716. convert.hex.rgb = function (args) {
  4717. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  4718. if (!match) {
  4719. return [0, 0, 0];
  4720. }
  4721. var colorString = match[0];
  4722. if (match[0].length === 3) {
  4723. colorString = colorString.split('').map(function (char) {
  4724. return char + char;
  4725. }).join('');
  4726. }
  4727. var integer = parseInt(colorString, 16);
  4728. var r = integer >> 16 & 0xFF;
  4729. var g = integer >> 8 & 0xFF;
  4730. var b = integer & 0xFF;
  4731. return [r, g, b];
  4732. };
  4733. convert.rgb.hcg = function (rgb) {
  4734. var r = rgb[0] / 255;
  4735. var g = rgb[1] / 255;
  4736. var b = rgb[2] / 255;
  4737. var max = Math.max(Math.max(r, g), b);
  4738. var min = Math.min(Math.min(r, g), b);
  4739. var chroma = max - min;
  4740. var grayscale;
  4741. var hue;
  4742. if (chroma < 1) {
  4743. grayscale = min / (1 - chroma);
  4744. } else {
  4745. grayscale = 0;
  4746. }
  4747. if (chroma <= 0) {
  4748. hue = 0;
  4749. } else if (max === r) {
  4750. hue = (g - b) / chroma % 6;
  4751. } else if (max === g) {
  4752. hue = 2 + (b - r) / chroma;
  4753. } else {
  4754. hue = 4 + (r - g) / chroma + 4;
  4755. }
  4756. hue /= 6;
  4757. hue %= 1;
  4758. return [hue * 360, chroma * 100, grayscale * 100];
  4759. };
  4760. convert.hsl.hcg = function (hsl) {
  4761. var s = hsl[1] / 100;
  4762. var l = hsl[2] / 100;
  4763. var c = 1;
  4764. var f = 0;
  4765. if (l < 0.5) {
  4766. c = 2.0 * s * l;
  4767. } else {
  4768. c = 2.0 * s * (1.0 - l);
  4769. }
  4770. if (c < 1.0) {
  4771. f = (l - 0.5 * c) / (1.0 - c);
  4772. }
  4773. return [hsl[0], c * 100, f * 100];
  4774. };
  4775. convert.hsv.hcg = function (hsv) {
  4776. var s = hsv[1] / 100;
  4777. var v = hsv[2] / 100;
  4778. var c = s * v;
  4779. var f = 0;
  4780. if (c < 1.0) {
  4781. f = (v - c) / (1 - c);
  4782. }
  4783. return [hsv[0], c * 100, f * 100];
  4784. };
  4785. convert.hcg.rgb = function (hcg) {
  4786. var h = hcg[0] / 360;
  4787. var c = hcg[1] / 100;
  4788. var g = hcg[2] / 100;
  4789. if (c === 0.0) {
  4790. return [g * 255, g * 255, g * 255];
  4791. }
  4792. var pure = [0, 0, 0];
  4793. var hi = h % 1 * 6;
  4794. var v = hi % 1;
  4795. var w = 1 - v;
  4796. var mg = 0;
  4797. switch (Math.floor(hi)) {
  4798. case 0:
  4799. pure[0] = 1;
  4800. pure[1] = v;
  4801. pure[2] = 0;
  4802. break;
  4803. case 1:
  4804. pure[0] = w;
  4805. pure[1] = 1;
  4806. pure[2] = 0;
  4807. break;
  4808. case 2:
  4809. pure[0] = 0;
  4810. pure[1] = 1;
  4811. pure[2] = v;
  4812. break;
  4813. case 3:
  4814. pure[0] = 0;
  4815. pure[1] = w;
  4816. pure[2] = 1;
  4817. break;
  4818. case 4:
  4819. pure[0] = v;
  4820. pure[1] = 0;
  4821. pure[2] = 1;
  4822. break;
  4823. default:
  4824. pure[0] = 1;
  4825. pure[1] = 0;
  4826. pure[2] = w;
  4827. }
  4828. mg = (1.0 - c) * g;
  4829. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  4830. };
  4831. convert.hcg.hsv = function (hcg) {
  4832. var c = hcg[1] / 100;
  4833. var g = hcg[2] / 100;
  4834. var v = c + g * (1.0 - c);
  4835. var f = 0;
  4836. if (v > 0.0) {
  4837. f = c / v;
  4838. }
  4839. return [hcg[0], f * 100, v * 100];
  4840. };
  4841. convert.hcg.hsl = function (hcg) {
  4842. var c = hcg[1] / 100;
  4843. var g = hcg[2] / 100;
  4844. var l = g * (1.0 - c) + 0.5 * c;
  4845. var s = 0;
  4846. if (l > 0.0 && l < 0.5) {
  4847. s = c / (2 * l);
  4848. } else if (l >= 0.5 && l < 1.0) {
  4849. s = c / (2 * (1 - l));
  4850. }
  4851. return [hcg[0], s * 100, l * 100];
  4852. };
  4853. convert.hcg.hwb = function (hcg) {
  4854. var c = hcg[1] / 100;
  4855. var g = hcg[2] / 100;
  4856. var v = c + g * (1.0 - c);
  4857. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  4858. };
  4859. convert.hwb.hcg = function (hwb) {
  4860. var w = hwb[1] / 100;
  4861. var b = hwb[2] / 100;
  4862. var v = 1 - b;
  4863. var c = v - w;
  4864. var g = 0;
  4865. if (c < 1) {
  4866. g = (v - c) / (1 - c);
  4867. }
  4868. return [hwb[0], c * 100, g * 100];
  4869. };
  4870. convert.apple.rgb = function (apple) {
  4871. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  4872. };
  4873. convert.rgb.apple = function (rgb) {
  4874. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  4875. };
  4876. convert.gray.rgb = function (args) {
  4877. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  4878. };
  4879. convert.gray.hsl = convert.gray.hsv = function (args) {
  4880. return [0, 0, args[0]];
  4881. };
  4882. convert.gray.hwb = function (gray) {
  4883. return [0, 100, gray[0]];
  4884. };
  4885. convert.gray.cmyk = function (gray) {
  4886. return [0, 0, 0, gray[0]];
  4887. };
  4888. convert.gray.lab = function (gray) {
  4889. return [gray[0], 0, 0];
  4890. };
  4891. convert.gray.hex = function (gray) {
  4892. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  4893. var integer = (val << 16) + (val << 8) + val;
  4894. var string = integer.toString(16).toUpperCase();
  4895. return '000000'.substring(string.length) + string;
  4896. };
  4897. convert.rgb.gray = function (rgb) {
  4898. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  4899. return [val / 255 * 100];
  4900. };
  4901. });
  4902. var conversions_1 = conversions.rgb;
  4903. var conversions_2 = conversions.hsl;
  4904. var conversions_3 = conversions.hsv;
  4905. var conversions_4 = conversions.hwb;
  4906. var conversions_5 = conversions.cmyk;
  4907. var conversions_6 = conversions.xyz;
  4908. var conversions_7 = conversions.lab;
  4909. var conversions_8 = conversions.lch;
  4910. var conversions_9 = conversions.hex;
  4911. var conversions_10 = conversions.keyword;
  4912. var conversions_11 = conversions.ansi16;
  4913. var conversions_12 = conversions.ansi256;
  4914. var conversions_13 = conversions.hcg;
  4915. var conversions_14 = conversions.apple;
  4916. var conversions_15 = conversions.gray;
  4917. /*
  4918. this function routes a model to all other models.
  4919. all functions that are routed have a property `.conversion` attached
  4920. to the returned synthetic function. This property is an array
  4921. of strings, each with the steps in between the 'from' and 'to'
  4922. color models (inclusive).
  4923. conversions that are not possible simply are not included.
  4924. */
  4925. // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  4926. var models = Object.keys(conversions);
  4927. function buildGraph() {
  4928. var graph = {};
  4929. for (var len = models.length, i = 0; i < len; i++) {
  4930. graph[models[i]] = {
  4931. // http://jsperf.com/1-vs-infinity
  4932. // micro-opt, but this is simple.
  4933. distance: -1,
  4934. parent: null
  4935. };
  4936. }
  4937. return graph;
  4938. } // https://en.wikipedia.org/wiki/Breadth-first_search
  4939. function deriveBFS(fromModel) {
  4940. var graph = buildGraph();
  4941. var queue = [fromModel]; // unshift -> queue -> pop
  4942. graph[fromModel].distance = 0;
  4943. while (queue.length) {
  4944. var current = queue.pop();
  4945. var adjacents = Object.keys(conversions[current]);
  4946. for (var len = adjacents.length, i = 0; i < len; i++) {
  4947. var adjacent = adjacents[i];
  4948. var node = graph[adjacent];
  4949. if (node.distance === -1) {
  4950. node.distance = graph[current].distance + 1;
  4951. node.parent = current;
  4952. queue.unshift(adjacent);
  4953. }
  4954. }
  4955. }
  4956. return graph;
  4957. }
  4958. function link(from, to) {
  4959. return function (args) {
  4960. return to(from(args));
  4961. };
  4962. }
  4963. function wrapConversion(toModel, graph) {
  4964. var path = [graph[toModel].parent, toModel];
  4965. var fn = conversions[graph[toModel].parent][toModel];
  4966. var cur = graph[toModel].parent;
  4967. while (graph[cur].parent) {
  4968. path.unshift(graph[cur].parent);
  4969. fn = link(conversions[graph[cur].parent][cur], fn);
  4970. cur = graph[cur].parent;
  4971. }
  4972. fn.conversion = path;
  4973. return fn;
  4974. }
  4975. var route = function route(fromModel) {
  4976. var graph = deriveBFS(fromModel);
  4977. var conversion = {};
  4978. var models = Object.keys(graph);
  4979. for (var len = models.length, i = 0; i < len; i++) {
  4980. var toModel = models[i];
  4981. var node = graph[toModel];
  4982. if (node.parent === null) {
  4983. // no possible conversion, or this node is the source model.
  4984. continue;
  4985. }
  4986. conversion[toModel] = wrapConversion(toModel, graph);
  4987. }
  4988. return conversion;
  4989. };
  4990. var convert = {};
  4991. var models$1 = Object.keys(conversions);
  4992. function wrapRaw(fn) {
  4993. var wrappedFn = function wrappedFn(args) {
  4994. if (args === undefined || args === null) {
  4995. return args;
  4996. }
  4997. if (arguments.length > 1) {
  4998. args = Array.prototype.slice.call(arguments);
  4999. }
  5000. return fn(args);
  5001. }; // preserve .conversion property if there is one
  5002. if ('conversion' in fn) {
  5003. wrappedFn.conversion = fn.conversion;
  5004. }
  5005. return wrappedFn;
  5006. }
  5007. function wrapRounded(fn) {
  5008. var wrappedFn = function wrappedFn(args) {
  5009. if (args === undefined || args === null) {
  5010. return args;
  5011. }
  5012. if (arguments.length > 1) {
  5013. args = Array.prototype.slice.call(arguments);
  5014. }
  5015. var result = fn(args); // we're assuming the result is an array here.
  5016. // see notice in conversions.js; don't use box types
  5017. // in conversion functions.
  5018. if (typeof result === 'object') {
  5019. for (var len = result.length, i = 0; i < len; i++) {
  5020. result[i] = Math.round(result[i]);
  5021. }
  5022. }
  5023. return result;
  5024. }; // preserve .conversion property if there is one
  5025. if ('conversion' in fn) {
  5026. wrappedFn.conversion = fn.conversion;
  5027. }
  5028. return wrappedFn;
  5029. }
  5030. models$1.forEach(function (fromModel) {
  5031. convert[fromModel] = {};
  5032. Object.defineProperty(convert[fromModel], 'channels', {
  5033. value: conversions[fromModel].channels
  5034. });
  5035. Object.defineProperty(convert[fromModel], 'labels', {
  5036. value: conversions[fromModel].labels
  5037. });
  5038. var routes = route(fromModel);
  5039. var routeModels = Object.keys(routes);
  5040. routeModels.forEach(function (toModel) {
  5041. var fn = routes[toModel];
  5042. convert[fromModel][toModel] = wrapRounded(fn);
  5043. convert[fromModel][toModel].raw = wrapRaw(fn);
  5044. });
  5045. });
  5046. var colorConvert = convert;
  5047. var ansiStyles = createCommonjsModule(function (module) {
  5048. var wrapAnsi16 = function wrapAnsi16(fn, offset) {
  5049. return function () {
  5050. var code = fn.apply(colorConvert, arguments);
  5051. return `\u001B[${code + offset}m`;
  5052. };
  5053. };
  5054. var wrapAnsi256 = function wrapAnsi256(fn, offset) {
  5055. return function () {
  5056. var code = fn.apply(colorConvert, arguments);
  5057. return `\u001B[${38 + offset};5;${code}m`;
  5058. };
  5059. };
  5060. var wrapAnsi16m = function wrapAnsi16m(fn, offset) {
  5061. return function () {
  5062. var rgb = fn.apply(colorConvert, arguments);
  5063. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  5064. };
  5065. };
  5066. function assembleStyles() {
  5067. var codes = new Map();
  5068. var styles = {
  5069. modifier: {
  5070. reset: [0, 0],
  5071. // 21 isn't widely supported and 22 does the same thing
  5072. bold: [1, 22],
  5073. dim: [2, 22],
  5074. italic: [3, 23],
  5075. underline: [4, 24],
  5076. inverse: [7, 27],
  5077. hidden: [8, 28],
  5078. strikethrough: [9, 29]
  5079. },
  5080. color: {
  5081. black: [30, 39],
  5082. red: [31, 39],
  5083. green: [32, 39],
  5084. yellow: [33, 39],
  5085. blue: [34, 39],
  5086. magenta: [35, 39],
  5087. cyan: [36, 39],
  5088. white: [37, 39],
  5089. gray: [90, 39],
  5090. // Bright color
  5091. redBright: [91, 39],
  5092. greenBright: [92, 39],
  5093. yellowBright: [93, 39],
  5094. blueBright: [94, 39],
  5095. magentaBright: [95, 39],
  5096. cyanBright: [96, 39],
  5097. whiteBright: [97, 39]
  5098. },
  5099. bgColor: {
  5100. bgBlack: [40, 49],
  5101. bgRed: [41, 49],
  5102. bgGreen: [42, 49],
  5103. bgYellow: [43, 49],
  5104. bgBlue: [44, 49],
  5105. bgMagenta: [45, 49],
  5106. bgCyan: [46, 49],
  5107. bgWhite: [47, 49],
  5108. // Bright color
  5109. bgBlackBright: [100, 49],
  5110. bgRedBright: [101, 49],
  5111. bgGreenBright: [102, 49],
  5112. bgYellowBright: [103, 49],
  5113. bgBlueBright: [104, 49],
  5114. bgMagentaBright: [105, 49],
  5115. bgCyanBright: [106, 49],
  5116. bgWhiteBright: [107, 49]
  5117. }
  5118. }; // Fix humans
  5119. styles.color.grey = styles.color.gray;
  5120. for (var _i = 0, _Object$keys = Object.keys(styles); _i < _Object$keys.length; _i++) {
  5121. var groupName = _Object$keys[_i];
  5122. var group = styles[groupName];
  5123. for (var _i3 = 0, _Object$keys3 = Object.keys(group); _i3 < _Object$keys3.length; _i3++) {
  5124. var styleName = _Object$keys3[_i3];
  5125. var style = group[styleName];
  5126. styles[styleName] = {
  5127. open: `\u001B[${style[0]}m`,
  5128. close: `\u001B[${style[1]}m`
  5129. };
  5130. group[styleName] = styles[styleName];
  5131. codes.set(style[0], style[1]);
  5132. }
  5133. Object.defineProperty(styles, groupName, {
  5134. value: group,
  5135. enumerable: false
  5136. });
  5137. Object.defineProperty(styles, 'codes', {
  5138. value: codes,
  5139. enumerable: false
  5140. });
  5141. }
  5142. var ansi2ansi = function ansi2ansi(n) {
  5143. return n;
  5144. };
  5145. var rgb2rgb = function rgb2rgb(r, g, b) {
  5146. return [r, g, b];
  5147. };
  5148. styles.color.close = '\u001B[39m';
  5149. styles.bgColor.close = '\u001B[49m';
  5150. styles.color.ansi = {
  5151. ansi: wrapAnsi16(ansi2ansi, 0)
  5152. };
  5153. styles.color.ansi256 = {
  5154. ansi256: wrapAnsi256(ansi2ansi, 0)
  5155. };
  5156. styles.color.ansi16m = {
  5157. rgb: wrapAnsi16m(rgb2rgb, 0)
  5158. };
  5159. styles.bgColor.ansi = {
  5160. ansi: wrapAnsi16(ansi2ansi, 10)
  5161. };
  5162. styles.bgColor.ansi256 = {
  5163. ansi256: wrapAnsi256(ansi2ansi, 10)
  5164. };
  5165. styles.bgColor.ansi16m = {
  5166. rgb: wrapAnsi16m(rgb2rgb, 10)
  5167. };
  5168. for (var _i2 = 0, _Object$keys2 = Object.keys(colorConvert); _i2 < _Object$keys2.length; _i2++) {
  5169. var key = _Object$keys2[_i2];
  5170. if (typeof colorConvert[key] !== 'object') {
  5171. continue;
  5172. }
  5173. var suite = colorConvert[key];
  5174. if (key === 'ansi16') {
  5175. key = 'ansi';
  5176. }
  5177. if ('ansi16' in suite) {
  5178. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  5179. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  5180. }
  5181. if ('ansi256' in suite) {
  5182. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  5183. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  5184. }
  5185. if ('rgb' in suite) {
  5186. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  5187. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  5188. }
  5189. }
  5190. return styles;
  5191. } // Make the export immutable
  5192. Object.defineProperty(module, 'exports', {
  5193. enumerable: true,
  5194. get: assembleStyles
  5195. });
  5196. });
  5197. var hasFlag = function hasFlag(flag, argv) {
  5198. argv = argv || process.argv;
  5199. var prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
  5200. var pos = argv.indexOf(prefix + flag);
  5201. var terminatorPos = argv.indexOf('--');
  5202. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  5203. };
  5204. var env = process.env;
  5205. var forceColor;
  5206. if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
  5207. forceColor = false;
  5208. } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
  5209. forceColor = true;
  5210. }
  5211. if ('FORCE_COLOR' in env) {
  5212. forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
  5213. }
  5214. function translateLevel(level) {
  5215. if (level === 0) {
  5216. return false;
  5217. }
  5218. return {
  5219. level,
  5220. hasBasic: true,
  5221. has256: level >= 2,
  5222. has16m: level >= 3
  5223. };
  5224. }
  5225. function supportsColor(stream) {
  5226. if (forceColor === false) {
  5227. return 0;
  5228. }
  5229. if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
  5230. return 3;
  5231. }
  5232. if (hasFlag('color=256')) {
  5233. return 2;
  5234. }
  5235. if (stream && !stream.isTTY && forceColor !== true) {
  5236. return 0;
  5237. }
  5238. var min = forceColor ? 1 : 0;
  5239. if (process.platform === 'win32') {
  5240. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  5241. // libuv that enables 256 color output on Windows. Anything earlier and it
  5242. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  5243. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  5244. // release that supports 256 colors. Windows 10 build 14931 is the first release
  5245. // that supports 16m/TrueColor.
  5246. var osRelease = os$1.release().split('.');
  5247. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  5248. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  5249. }
  5250. return 1;
  5251. }
  5252. if ('CI' in env) {
  5253. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(function (sign) {
  5254. return sign in env;
  5255. }) || env.CI_NAME === 'codeship') {
  5256. return 1;
  5257. }
  5258. return min;
  5259. }
  5260. if ('TEAMCITY_VERSION' in env) {
  5261. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  5262. }
  5263. if (env.COLORTERM === 'truecolor') {
  5264. return 3;
  5265. }
  5266. if ('TERM_PROGRAM' in env) {
  5267. var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  5268. switch (env.TERM_PROGRAM) {
  5269. case 'iTerm.app':
  5270. return version >= 3 ? 3 : 2;
  5271. case 'Apple_Terminal':
  5272. return 2;
  5273. // No default
  5274. }
  5275. }
  5276. if (/-256(color)?$/i.test(env.TERM)) {
  5277. return 2;
  5278. }
  5279. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  5280. return 1;
  5281. }
  5282. if ('COLORTERM' in env) {
  5283. return 1;
  5284. }
  5285. if (env.TERM === 'dumb') {
  5286. return min;
  5287. }
  5288. return min;
  5289. }
  5290. function getSupportLevel(stream) {
  5291. var level = supportsColor(stream);
  5292. return translateLevel(level);
  5293. }
  5294. var supportsColor_1 = {
  5295. supportsColor: getSupportLevel,
  5296. stdout: getSupportLevel(process.stdout),
  5297. stderr: getSupportLevel(process.stderr)
  5298. };
  5299. var TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  5300. var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  5301. var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  5302. var ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  5303. var ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  5304. function unescape(c) {
  5305. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  5306. return String.fromCharCode(parseInt(c.slice(1), 16));
  5307. }
  5308. return ESCAPES.get(c) || c;
  5309. }
  5310. function parseArguments(name, args) {
  5311. var results = [];
  5312. var chunks = args.trim().split(/\s*,\s*/g);
  5313. var matches;
  5314. var _iteratorNormalCompletion = true;
  5315. var _didIteratorError = false;
  5316. var _iteratorError = undefined;
  5317. try {
  5318. for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5319. var chunk = _step.value;
  5320. if (!isNaN(chunk)) {
  5321. results.push(Number(chunk));
  5322. } else if (matches = chunk.match(STRING_REGEX)) {
  5323. results.push(matches[2].replace(ESCAPE_REGEX, function (m, escape, chr) {
  5324. return escape ? unescape(escape) : chr;
  5325. }));
  5326. } else {
  5327. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  5328. }
  5329. }
  5330. } catch (err) {
  5331. _didIteratorError = true;
  5332. _iteratorError = err;
  5333. } finally {
  5334. try {
  5335. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5336. _iterator.return();
  5337. }
  5338. } finally {
  5339. if (_didIteratorError) {
  5340. throw _iteratorError;
  5341. }
  5342. }
  5343. }
  5344. return results;
  5345. }
  5346. function parseStyle(style) {
  5347. STYLE_REGEX.lastIndex = 0;
  5348. var results = [];
  5349. var matches;
  5350. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  5351. var name = matches[1];
  5352. if (matches[2]) {
  5353. var args = parseArguments(name, matches[2]);
  5354. results.push([name].concat(args));
  5355. } else {
  5356. results.push([name]);
  5357. }
  5358. }
  5359. return results;
  5360. }
  5361. function buildStyle(chalk, styles) {
  5362. var enabled = {};
  5363. var _iteratorNormalCompletion2 = true;
  5364. var _didIteratorError2 = false;
  5365. var _iteratorError2 = undefined;
  5366. try {
  5367. for (var _iterator2 = styles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  5368. var layer = _step2.value;
  5369. var _iteratorNormalCompletion3 = true;
  5370. var _didIteratorError3 = false;
  5371. var _iteratorError3 = undefined;
  5372. try {
  5373. for (var _iterator3 = layer.styles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  5374. var style = _step3.value;
  5375. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  5376. }
  5377. } catch (err) {
  5378. _didIteratorError3 = true;
  5379. _iteratorError3 = err;
  5380. } finally {
  5381. try {
  5382. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  5383. _iterator3.return();
  5384. }
  5385. } finally {
  5386. if (_didIteratorError3) {
  5387. throw _iteratorError3;
  5388. }
  5389. }
  5390. }
  5391. }
  5392. } catch (err) {
  5393. _didIteratorError2 = true;
  5394. _iteratorError2 = err;
  5395. } finally {
  5396. try {
  5397. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  5398. _iterator2.return();
  5399. }
  5400. } finally {
  5401. if (_didIteratorError2) {
  5402. throw _iteratorError2;
  5403. }
  5404. }
  5405. }
  5406. var current = chalk;
  5407. for (var _i = 0, _Object$keys = Object.keys(enabled); _i < _Object$keys.length; _i++) {
  5408. var styleName = _Object$keys[_i];
  5409. if (Array.isArray(enabled[styleName])) {
  5410. if (!(styleName in current)) {
  5411. throw new Error(`Unknown Chalk style: ${styleName}`);
  5412. }
  5413. if (enabled[styleName].length > 0) {
  5414. current = current[styleName].apply(current, enabled[styleName]);
  5415. } else {
  5416. current = current[styleName];
  5417. }
  5418. }
  5419. }
  5420. return current;
  5421. }
  5422. var templates = function templates(chalk, tmp) {
  5423. var styles = [];
  5424. var chunks = [];
  5425. var chunk = []; // eslint-disable-next-line max-params
  5426. tmp.replace(TEMPLATE_REGEX, function (m, escapeChar, inverse, style, close, chr) {
  5427. if (escapeChar) {
  5428. chunk.push(unescape(escapeChar));
  5429. } else if (style) {
  5430. var str = chunk.join('');
  5431. chunk = [];
  5432. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  5433. styles.push({
  5434. inverse,
  5435. styles: parseStyle(style)
  5436. });
  5437. } else if (close) {
  5438. if (styles.length === 0) {
  5439. throw new Error('Found extraneous } in Chalk template literal');
  5440. }
  5441. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  5442. chunk = [];
  5443. styles.pop();
  5444. } else {
  5445. chunk.push(chr);
  5446. }
  5447. });
  5448. chunks.push(chunk.join(''));
  5449. if (styles.length > 0) {
  5450. var errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  5451. throw new Error(errMsg);
  5452. }
  5453. return chunks.join('');
  5454. };
  5455. var chalk = createCommonjsModule(function (module) {
  5456. var stdoutColor = supportsColor_1.stdout;
  5457. var isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  5458. var levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  5459. var skipModels = new Set(['gray']);
  5460. var styles = Object.create(null);
  5461. function applyOptions(obj, options) {
  5462. options = options || {}; // Detect level if not set manually
  5463. var scLevel = stdoutColor ? stdoutColor.level : 0;
  5464. obj.level = options.level === undefined ? scLevel : options.level;
  5465. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  5466. }
  5467. function Chalk(options) {
  5468. // We check for this.template here since calling `chalk.constructor()`
  5469. // by itself will have a `this` of a previously constructed chalk object
  5470. if (!this || !(this instanceof Chalk) || this.template) {
  5471. var _chalk = {};
  5472. applyOptions(_chalk, options);
  5473. _chalk.template = function () {
  5474. var args = [].slice.call(arguments);
  5475. return chalkTag.apply(null, [_chalk.template].concat(args));
  5476. };
  5477. Object.setPrototypeOf(_chalk, Chalk.prototype);
  5478. Object.setPrototypeOf(_chalk.template, _chalk);
  5479. _chalk.template.constructor = Chalk;
  5480. return _chalk.template;
  5481. }
  5482. applyOptions(this, options);
  5483. } // Use bright blue on Windows as the normal blue color is illegible
  5484. if (isSimpleWindowsTerm) {
  5485. ansiStyles.blue.open = '\u001B[94m';
  5486. }
  5487. var _loop = function _loop() {
  5488. var key = _Object$keys[_i];
  5489. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  5490. styles[key] = {
  5491. get() {
  5492. var codes = ansiStyles[key];
  5493. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  5494. }
  5495. };
  5496. };
  5497. for (var _i = 0, _Object$keys = Object.keys(ansiStyles); _i < _Object$keys.length; _i++) {
  5498. _loop();
  5499. }
  5500. styles.visible = {
  5501. get() {
  5502. return build.call(this, this._styles || [], true, 'visible');
  5503. }
  5504. };
  5505. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  5506. var _loop2 = function _loop2() {
  5507. var model = _Object$keys2[_i2];
  5508. if (skipModels.has(model)) {
  5509. return "continue";
  5510. }
  5511. styles[model] = {
  5512. get() {
  5513. var level = this.level;
  5514. return function () {
  5515. var open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  5516. var codes = {
  5517. open,
  5518. close: ansiStyles.color.close,
  5519. closeRe: ansiStyles.color.closeRe
  5520. };
  5521. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  5522. };
  5523. }
  5524. };
  5525. };
  5526. for (var _i2 = 0, _Object$keys2 = Object.keys(ansiStyles.color.ansi); _i2 < _Object$keys2.length; _i2++) {
  5527. var _ret = _loop2();
  5528. if (_ret === "continue") continue;
  5529. }
  5530. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  5531. var _loop3 = function _loop3() {
  5532. var model = _Object$keys3[_i3];
  5533. if (skipModels.has(model)) {
  5534. return "continue";
  5535. }
  5536. var bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  5537. styles[bgModel] = {
  5538. get() {
  5539. var level = this.level;
  5540. return function () {
  5541. var open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  5542. var codes = {
  5543. open,
  5544. close: ansiStyles.bgColor.close,
  5545. closeRe: ansiStyles.bgColor.closeRe
  5546. };
  5547. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  5548. };
  5549. }
  5550. };
  5551. };
  5552. for (var _i3 = 0, _Object$keys3 = Object.keys(ansiStyles.bgColor.ansi); _i3 < _Object$keys3.length; _i3++) {
  5553. var _ret2 = _loop3();
  5554. if (_ret2 === "continue") continue;
  5555. }
  5556. var proto = Object.defineProperties(function () {}, styles);
  5557. function build(_styles, _empty, key) {
  5558. var builder = function builder() {
  5559. return applyStyle.apply(builder, arguments);
  5560. };
  5561. builder._styles = _styles;
  5562. builder._empty = _empty;
  5563. var self = this;
  5564. Object.defineProperty(builder, 'level', {
  5565. enumerable: true,
  5566. get() {
  5567. return self.level;
  5568. },
  5569. set(level) {
  5570. self.level = level;
  5571. }
  5572. });
  5573. Object.defineProperty(builder, 'enabled', {
  5574. enumerable: true,
  5575. get() {
  5576. return self.enabled;
  5577. },
  5578. set(enabled) {
  5579. self.enabled = enabled;
  5580. }
  5581. }); // See below for fix regarding invisible grey/dim combination on Windows
  5582. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  5583. // no way to create a function with a different prototype
  5584. builder.__proto__ = proto; // eslint-disable-line no-proto
  5585. return builder;
  5586. }
  5587. function applyStyle() {
  5588. // Support varags, but simply cast to string in case there's only one arg
  5589. var args = arguments;
  5590. var argsLen = args.length;
  5591. var str = String(arguments[0]);
  5592. if (argsLen === 0) {
  5593. return '';
  5594. }
  5595. if (argsLen > 1) {
  5596. // Don't slice `arguments`, it prevents V8 optimizations
  5597. for (var a = 1; a < argsLen; a++) {
  5598. str += ' ' + args[a];
  5599. }
  5600. }
  5601. if (!this.enabled || this.level <= 0 || !str) {
  5602. return this._empty ? '' : str;
  5603. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  5604. // see https://github.com/chalk/chalk/issues/58
  5605. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  5606. var originalDim = ansiStyles.dim.open;
  5607. if (isSimpleWindowsTerm && this.hasGrey) {
  5608. ansiStyles.dim.open = '';
  5609. }
  5610. var _iteratorNormalCompletion = true;
  5611. var _didIteratorError = false;
  5612. var _iteratorError = undefined;
  5613. try {
  5614. for (var _iterator = this._styles.slice().reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5615. var code = _step.value;
  5616. // Replace any instances already present with a re-opening code
  5617. // otherwise only the part of the string until said closing code
  5618. // will be colored, and the rest will simply be 'plain'.
  5619. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  5620. // after next line to fix a bleed issue on macOS
  5621. // https://github.com/chalk/chalk/pull/92
  5622. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  5623. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  5624. } catch (err) {
  5625. _didIteratorError = true;
  5626. _iteratorError = err;
  5627. } finally {
  5628. try {
  5629. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5630. _iterator.return();
  5631. }
  5632. } finally {
  5633. if (_didIteratorError) {
  5634. throw _iteratorError;
  5635. }
  5636. }
  5637. }
  5638. ansiStyles.dim.open = originalDim;
  5639. return str;
  5640. }
  5641. function chalkTag(chalk, strings) {
  5642. if (!Array.isArray(strings)) {
  5643. // If chalk() was called by itself or with a string,
  5644. // return the string itself as a string.
  5645. return [].slice.call(arguments, 1).join(' ');
  5646. }
  5647. var args = [].slice.call(arguments, 2);
  5648. var parts = [strings.raw[0]];
  5649. for (var i = 1; i < strings.length; i++) {
  5650. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  5651. parts.push(String(strings.raw[i]));
  5652. }
  5653. return templates(chalk, parts.join(''));
  5654. }
  5655. Object.defineProperties(Chalk.prototype, styles);
  5656. module.exports = Chalk(); // eslint-disable-line new-cap
  5657. module.exports.supportsColor = stdoutColor;
  5658. module.exports.default = module.exports; // For TypeScript
  5659. });
  5660. var chalk_1 = chalk.supportsColor;
  5661. var common = createCommonjsModule(function (module, exports) {
  5662. Object.defineProperty(exports, "__esModule", {
  5663. value: true
  5664. });
  5665. exports.commonDeprecatedHandler = function (keyOrPair, redirectTo, _ref) {
  5666. var descriptor = _ref.descriptor;
  5667. var messages = [`${chalk.default.yellow(typeof keyOrPair === 'string' ? descriptor.key(keyOrPair) : descriptor.pair(keyOrPair))} is deprecated`];
  5668. if (redirectTo) {
  5669. messages.push(`we now treat it as ${chalk.default.blue(typeof redirectTo === 'string' ? descriptor.key(redirectTo) : descriptor.pair(redirectTo))}`);
  5670. }
  5671. return messages.join('; ') + '.';
  5672. };
  5673. });
  5674. unwrapExports(common);
  5675. var common_1 = common.commonDeprecatedHandler;
  5676. var deprecated = createCommonjsModule(function (module, exports) {
  5677. Object.defineProperty(exports, "__esModule", {
  5678. value: true
  5679. });
  5680. tslib_es6.__exportStar(common, exports);
  5681. });
  5682. unwrapExports(deprecated);
  5683. var common$1 = createCommonjsModule(function (module, exports) {
  5684. Object.defineProperty(exports, "__esModule", {
  5685. value: true
  5686. });
  5687. exports.commonInvalidHandler = function (key, value, utils) {
  5688. return [`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(' ');
  5689. };
  5690. });
  5691. unwrapExports(common$1);
  5692. var common_1$1 = common$1.commonInvalidHandler;
  5693. var invalid = createCommonjsModule(function (module, exports) {
  5694. Object.defineProperty(exports, "__esModule", {
  5695. value: true
  5696. });
  5697. tslib_es6.__exportStar(common$1, exports);
  5698. });
  5699. unwrapExports(invalid);
  5700. /* eslint-disable no-nested-ternary */
  5701. var arr = [];
  5702. var charCodeCache = [];
  5703. var leven = function leven(a, b) {
  5704. if (a === b) {
  5705. return 0;
  5706. }
  5707. var swap = a; // Swapping the strings if `a` is longer than `b` so we know which one is the
  5708. // shortest & which one is the longest
  5709. if (a.length > b.length) {
  5710. a = b;
  5711. b = swap;
  5712. }
  5713. var aLen = a.length;
  5714. var bLen = b.length;
  5715. if (aLen === 0) {
  5716. return bLen;
  5717. }
  5718. if (bLen === 0) {
  5719. return aLen;
  5720. } // Performing suffix trimming:
  5721. // We can linearly drop suffix common to both strings since they
  5722. // don't increase distance at all
  5723. // Note: `~-` is the bitwise way to perform a `- 1` operation
  5724. while (aLen > 0 && a.charCodeAt(~-aLen) === b.charCodeAt(~-bLen)) {
  5725. aLen--;
  5726. bLen--;
  5727. }
  5728. if (aLen === 0) {
  5729. return bLen;
  5730. } // Performing prefix trimming
  5731. // We can linearly drop prefix common to both strings since they
  5732. // don't increase distance at all
  5733. var start = 0;
  5734. while (start < aLen && a.charCodeAt(start) === b.charCodeAt(start)) {
  5735. start++;
  5736. }
  5737. aLen -= start;
  5738. bLen -= start;
  5739. if (aLen === 0) {
  5740. return bLen;
  5741. }
  5742. var bCharCode;
  5743. var ret;
  5744. var tmp;
  5745. var tmp2;
  5746. var i = 0;
  5747. var j = 0;
  5748. while (i < aLen) {
  5749. charCodeCache[start + i] = a.charCodeAt(start + i);
  5750. arr[i] = ++i;
  5751. }
  5752. while (j < bLen) {
  5753. bCharCode = b.charCodeAt(start + j);
  5754. tmp = j++;
  5755. ret = j;
  5756. for (i = 0; i < aLen; i++) {
  5757. tmp2 = bCharCode === charCodeCache[start + i] ? tmp : tmp + 1;
  5758. tmp = arr[i];
  5759. ret = arr[i] = tmp > ret ? tmp2 > ret ? ret + 1 : tmp2 : tmp2 > tmp ? tmp + 1 : tmp2;
  5760. }
  5761. }
  5762. return ret;
  5763. };
  5764. var leven_1 = createCommonjsModule(function (module, exports) {
  5765. Object.defineProperty(exports, "__esModule", {
  5766. value: true
  5767. });
  5768. exports.levenUnknownHandler = function (key, value, _ref) {
  5769. var descriptor = _ref.descriptor,
  5770. logger = _ref.logger,
  5771. schemas = _ref.schemas;
  5772. var messages = [`Ignored unknown option ${chalk.default.yellow(descriptor.pair({
  5773. key,
  5774. value
  5775. }))}.`];
  5776. var suggestion = Object.keys(schemas).sort().find(function (knownKey) {
  5777. return leven(key, knownKey) < 3;
  5778. });
  5779. if (suggestion) {
  5780. messages.push(`Did you mean ${chalk.default.blue(descriptor.key(suggestion))}?`);
  5781. }
  5782. logger.warn(messages.join(' '));
  5783. };
  5784. });
  5785. unwrapExports(leven_1);
  5786. var leven_2 = leven_1.levenUnknownHandler;
  5787. var unknown = createCommonjsModule(function (module, exports) {
  5788. Object.defineProperty(exports, "__esModule", {
  5789. value: true
  5790. });
  5791. tslib_es6.__exportStar(leven_1, exports);
  5792. });
  5793. unwrapExports(unknown);
  5794. var handlers = createCommonjsModule(function (module, exports) {
  5795. Object.defineProperty(exports, "__esModule", {
  5796. value: true
  5797. });
  5798. tslib_es6.__exportStar(deprecated, exports);
  5799. tslib_es6.__exportStar(invalid, exports);
  5800. tslib_es6.__exportStar(unknown, exports);
  5801. });
  5802. unwrapExports(handlers);
  5803. var schema = createCommonjsModule(function (module, exports) {
  5804. Object.defineProperty(exports, "__esModule", {
  5805. value: true
  5806. });
  5807. var HANDLER_KEYS = ['default', 'expected', 'validate', 'deprecated', 'forward', 'redirect', 'overlap', 'preprocess', 'postprocess'];
  5808. function createSchema(SchemaConstructor, parameters) {
  5809. var schema = new SchemaConstructor(parameters);
  5810. var subSchema = Object.create(schema);
  5811. var _iteratorNormalCompletion = true;
  5812. var _didIteratorError = false;
  5813. var _iteratorError = undefined;
  5814. try {
  5815. for (var _iterator = HANDLER_KEYS[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5816. var handlerKey = _step.value;
  5817. if (handlerKey in parameters) {
  5818. subSchema[handlerKey] = normalizeHandler(parameters[handlerKey], schema, Schema.prototype[handlerKey].length);
  5819. }
  5820. }
  5821. } catch (err) {
  5822. _didIteratorError = true;
  5823. _iteratorError = err;
  5824. } finally {
  5825. try {
  5826. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5827. _iterator.return();
  5828. }
  5829. } finally {
  5830. if (_didIteratorError) {
  5831. throw _iteratorError;
  5832. }
  5833. }
  5834. }
  5835. return subSchema;
  5836. }
  5837. exports.createSchema = createSchema;
  5838. var Schema =
  5839. /*#__PURE__*/
  5840. function () {
  5841. function Schema(parameters) {
  5842. _classCallCheck(this, Schema);
  5843. this.name = parameters.name;
  5844. }
  5845. _createClass(Schema, [{
  5846. key: "default",
  5847. value: function _default(_utils) {
  5848. return undefined;
  5849. } // istanbul ignore next: this is actually an abstract method but we need a placeholder to get `function.length`
  5850. }, {
  5851. key: "expected",
  5852. value: function expected(_utils) {
  5853. return 'nothing';
  5854. } // istanbul ignore next: this is actually an abstract method but we need a placeholder to get `function.length`
  5855. }, {
  5856. key: "validate",
  5857. value: function validate(_value, _utils) {
  5858. return false;
  5859. }
  5860. }, {
  5861. key: "deprecated",
  5862. value: function deprecated(_value, _utils) {
  5863. return false;
  5864. }
  5865. }, {
  5866. key: "forward",
  5867. value: function forward(_value, _utils) {
  5868. return undefined;
  5869. }
  5870. }, {
  5871. key: "redirect",
  5872. value: function redirect(_value, _utils) {
  5873. return undefined;
  5874. }
  5875. }, {
  5876. key: "overlap",
  5877. value: function overlap(currentValue, _newValue, _utils) {
  5878. return currentValue;
  5879. }
  5880. }, {
  5881. key: "preprocess",
  5882. value: function preprocess(value, _utils) {
  5883. return value;
  5884. }
  5885. }, {
  5886. key: "postprocess",
  5887. value: function postprocess(value, _utils) {
  5888. return value;
  5889. }
  5890. }], [{
  5891. key: "create",
  5892. value: function create(parameters) {
  5893. // @ts-ignore: https://github.com/Microsoft/TypeScript/issues/5863
  5894. return createSchema(this, parameters);
  5895. }
  5896. }]);
  5897. return Schema;
  5898. }();
  5899. exports.Schema = Schema;
  5900. function normalizeHandler(handler, superSchema, handlerArgumentsLength) {
  5901. return typeof handler === 'function' ? function () {
  5902. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  5903. args[_key] = arguments[_key];
  5904. }
  5905. return handler.apply(void 0, _toConsumableArray$1(args.slice(0, handlerArgumentsLength - 1)).concat([superSchema], _toConsumableArray$1(args.slice(handlerArgumentsLength - 1))));
  5906. } : function () {
  5907. return handler;
  5908. };
  5909. }
  5910. });
  5911. unwrapExports(schema);
  5912. var schema_1 = schema.createSchema;
  5913. var schema_2 = schema.Schema;
  5914. var alias = createCommonjsModule(function (module, exports) {
  5915. Object.defineProperty(exports, "__esModule", {
  5916. value: true
  5917. });
  5918. var AliasSchema =
  5919. /*#__PURE__*/
  5920. function (_schema_1$Schema) {
  5921. _inherits(AliasSchema, _schema_1$Schema);
  5922. function AliasSchema(parameters) {
  5923. var _this;
  5924. _classCallCheck(this, AliasSchema);
  5925. _this = _possibleConstructorReturn(this, _getPrototypeOf(AliasSchema).call(this, parameters));
  5926. _this._sourceName = parameters.sourceName;
  5927. return _this;
  5928. }
  5929. _createClass(AliasSchema, [{
  5930. key: "expected",
  5931. value: function expected(utils) {
  5932. return utils.schemas[this._sourceName].expected(utils);
  5933. }
  5934. }, {
  5935. key: "validate",
  5936. value: function validate(value, utils) {
  5937. return utils.schemas[this._sourceName].validate(value, utils);
  5938. }
  5939. }, {
  5940. key: "redirect",
  5941. value: function redirect(_value, _utils) {
  5942. return this._sourceName;
  5943. }
  5944. }]);
  5945. return AliasSchema;
  5946. }(schema.Schema);
  5947. exports.AliasSchema = AliasSchema;
  5948. });
  5949. unwrapExports(alias);
  5950. var alias_1 = alias.AliasSchema;
  5951. var any = createCommonjsModule(function (module, exports) {
  5952. Object.defineProperty(exports, "__esModule", {
  5953. value: true
  5954. });
  5955. var AnySchema =
  5956. /*#__PURE__*/
  5957. function (_schema_1$Schema) {
  5958. _inherits(AnySchema, _schema_1$Schema);
  5959. function AnySchema() {
  5960. _classCallCheck(this, AnySchema);
  5961. return _possibleConstructorReturn(this, _getPrototypeOf(AnySchema).apply(this, arguments));
  5962. }
  5963. _createClass(AnySchema, [{
  5964. key: "expected",
  5965. value: function expected() {
  5966. return 'anything';
  5967. }
  5968. }, {
  5969. key: "validate",
  5970. value: function validate() {
  5971. return true;
  5972. }
  5973. }]);
  5974. return AnySchema;
  5975. }(schema.Schema);
  5976. exports.AnySchema = AnySchema;
  5977. });
  5978. unwrapExports(any);
  5979. var any_1 = any.AnySchema;
  5980. var array = createCommonjsModule(function (module, exports) {
  5981. Object.defineProperty(exports, "__esModule", {
  5982. value: true
  5983. });
  5984. var ArraySchema =
  5985. /*#__PURE__*/
  5986. function (_schema_1$Schema) {
  5987. _inherits(ArraySchema, _schema_1$Schema);
  5988. function ArraySchema(_a) {
  5989. var _this;
  5990. _classCallCheck(this, ArraySchema);
  5991. var valueSchema = _a.valueSchema,
  5992. _a$name = _a.name,
  5993. name = _a$name === void 0 ? valueSchema.name : _a$name,
  5994. handlers = tslib_es6.__rest(_a, ["valueSchema", "name"]);
  5995. _this = _possibleConstructorReturn(this, _getPrototypeOf(ArraySchema).call(this, Object.assign({}, handlers, {
  5996. name
  5997. })));
  5998. _this._valueSchema = valueSchema;
  5999. return _this;
  6000. }
  6001. _createClass(ArraySchema, [{
  6002. key: "expected",
  6003. value: function expected(utils) {
  6004. return `an array of ${this._valueSchema.expected(utils)}`;
  6005. }
  6006. }, {
  6007. key: "validate",
  6008. value: function validate(value, utils) {
  6009. if (!Array.isArray(value)) {
  6010. return false;
  6011. }
  6012. var invalidValues = [];
  6013. var _iteratorNormalCompletion = true;
  6014. var _didIteratorError = false;
  6015. var _iteratorError = undefined;
  6016. try {
  6017. for (var _iterator = value[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  6018. var subValue = _step.value;
  6019. var subValidateResult = utils.normalizeValidateResult(this._valueSchema.validate(subValue, utils), subValue);
  6020. if (subValidateResult !== true) {
  6021. invalidValues.push(subValidateResult.value);
  6022. }
  6023. }
  6024. } catch (err) {
  6025. _didIteratorError = true;
  6026. _iteratorError = err;
  6027. } finally {
  6028. try {
  6029. if (!_iteratorNormalCompletion && _iterator.return != null) {
  6030. _iterator.return();
  6031. }
  6032. } finally {
  6033. if (_didIteratorError) {
  6034. throw _iteratorError;
  6035. }
  6036. }
  6037. }
  6038. return invalidValues.length === 0 ? true : {
  6039. value: invalidValues
  6040. };
  6041. }
  6042. }, {
  6043. key: "deprecated",
  6044. value: function deprecated(value, utils) {
  6045. var deprecatedResult = [];
  6046. var _iteratorNormalCompletion2 = true;
  6047. var _didIteratorError2 = false;
  6048. var _iteratorError2 = undefined;
  6049. try {
  6050. for (var _iterator2 = value[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  6051. var subValue = _step2.value;
  6052. var subDeprecatedResult = utils.normalizeDeprecatedResult(this._valueSchema.deprecated(subValue, utils), subValue);
  6053. if (subDeprecatedResult !== false) {
  6054. deprecatedResult.push.apply(deprecatedResult, _toConsumableArray$1(subDeprecatedResult.map(function (_ref) {
  6055. var deprecatedValue = _ref.value;
  6056. return {
  6057. value: [deprecatedValue]
  6058. };
  6059. })));
  6060. }
  6061. }
  6062. } catch (err) {
  6063. _didIteratorError2 = true;
  6064. _iteratorError2 = err;
  6065. } finally {
  6066. try {
  6067. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  6068. _iterator2.return();
  6069. }
  6070. } finally {
  6071. if (_didIteratorError2) {
  6072. throw _iteratorError2;
  6073. }
  6074. }
  6075. }
  6076. return deprecatedResult;
  6077. }
  6078. }, {
  6079. key: "forward",
  6080. value: function forward(value, utils) {
  6081. var forwardResult = [];
  6082. var _iteratorNormalCompletion3 = true;
  6083. var _didIteratorError3 = false;
  6084. var _iteratorError3 = undefined;
  6085. try {
  6086. for (var _iterator3 = value[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  6087. var subValue = _step3.value;
  6088. var subForwardResult = utils.normalizeForwardResult(this._valueSchema.forward(subValue, utils), subValue);
  6089. forwardResult.push.apply(forwardResult, _toConsumableArray$1(subForwardResult.map(wrapTransferResult)));
  6090. }
  6091. } catch (err) {
  6092. _didIteratorError3 = true;
  6093. _iteratorError3 = err;
  6094. } finally {
  6095. try {
  6096. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  6097. _iterator3.return();
  6098. }
  6099. } finally {
  6100. if (_didIteratorError3) {
  6101. throw _iteratorError3;
  6102. }
  6103. }
  6104. }
  6105. return forwardResult;
  6106. }
  6107. }, {
  6108. key: "redirect",
  6109. value: function redirect(value, utils) {
  6110. var remain = [];
  6111. var redirect = [];
  6112. var _iteratorNormalCompletion4 = true;
  6113. var _didIteratorError4 = false;
  6114. var _iteratorError4 = undefined;
  6115. try {
  6116. for (var _iterator4 = value[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  6117. var subValue = _step4.value;
  6118. var subRedirectResult = utils.normalizeRedirectResult(this._valueSchema.redirect(subValue, utils), subValue);
  6119. if ('remain' in subRedirectResult) {
  6120. remain.push(subRedirectResult.remain);
  6121. }
  6122. redirect.push.apply(redirect, _toConsumableArray$1(subRedirectResult.redirect.map(wrapTransferResult)));
  6123. }
  6124. } catch (err) {
  6125. _didIteratorError4 = true;
  6126. _iteratorError4 = err;
  6127. } finally {
  6128. try {
  6129. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  6130. _iterator4.return();
  6131. }
  6132. } finally {
  6133. if (_didIteratorError4) {
  6134. throw _iteratorError4;
  6135. }
  6136. }
  6137. }
  6138. return remain.length === 0 ? {
  6139. redirect
  6140. } : {
  6141. redirect,
  6142. remain
  6143. };
  6144. }
  6145. }, {
  6146. key: "overlap",
  6147. value: function overlap(currentValue, newValue) {
  6148. return currentValue.concat(newValue);
  6149. }
  6150. }]);
  6151. return ArraySchema;
  6152. }(schema.Schema);
  6153. exports.ArraySchema = ArraySchema;
  6154. function wrapTransferResult(_ref2) {
  6155. var from = _ref2.from,
  6156. to = _ref2.to;
  6157. return {
  6158. from: [from],
  6159. to
  6160. };
  6161. }
  6162. });
  6163. unwrapExports(array);
  6164. var array_1 = array.ArraySchema;
  6165. var boolean_1 = createCommonjsModule(function (module, exports) {
  6166. Object.defineProperty(exports, "__esModule", {
  6167. value: true
  6168. });
  6169. var BooleanSchema =
  6170. /*#__PURE__*/
  6171. function (_schema_1$Schema) {
  6172. _inherits(BooleanSchema, _schema_1$Schema);
  6173. function BooleanSchema() {
  6174. _classCallCheck(this, BooleanSchema);
  6175. return _possibleConstructorReturn(this, _getPrototypeOf(BooleanSchema).apply(this, arguments));
  6176. }
  6177. _createClass(BooleanSchema, [{
  6178. key: "expected",
  6179. value: function expected() {
  6180. return 'true or false';
  6181. }
  6182. }, {
  6183. key: "validate",
  6184. value: function validate(value) {
  6185. return typeof value === 'boolean';
  6186. }
  6187. }]);
  6188. return BooleanSchema;
  6189. }(schema.Schema);
  6190. exports.BooleanSchema = BooleanSchema;
  6191. });
  6192. unwrapExports(boolean_1);
  6193. var boolean_2 = boolean_1.BooleanSchema;
  6194. var utils = createCommonjsModule(function (module, exports) {
  6195. Object.defineProperty(exports, "__esModule", {
  6196. value: true
  6197. });
  6198. function recordFromArray(array, mainKey) {
  6199. var record = Object.create(null);
  6200. var _iteratorNormalCompletion = true;
  6201. var _didIteratorError = false;
  6202. var _iteratorError = undefined;
  6203. try {
  6204. for (var _iterator = array[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  6205. var value = _step.value;
  6206. var key = value[mainKey]; // istanbul ignore next
  6207. if (record[key]) {
  6208. throw new Error(`Duplicate ${mainKey} ${JSON.stringify(key)}`);
  6209. } // @ts-ignore
  6210. record[key] = value;
  6211. }
  6212. } catch (err) {
  6213. _didIteratorError = true;
  6214. _iteratorError = err;
  6215. } finally {
  6216. try {
  6217. if (!_iteratorNormalCompletion && _iterator.return != null) {
  6218. _iterator.return();
  6219. }
  6220. } finally {
  6221. if (_didIteratorError) {
  6222. throw _iteratorError;
  6223. }
  6224. }
  6225. }
  6226. return record;
  6227. }
  6228. exports.recordFromArray = recordFromArray;
  6229. function mapFromArray(array, mainKey) {
  6230. var map = new Map();
  6231. var _iteratorNormalCompletion2 = true;
  6232. var _didIteratorError2 = false;
  6233. var _iteratorError2 = undefined;
  6234. try {
  6235. for (var _iterator2 = array[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  6236. var value = _step2.value;
  6237. var key = value[mainKey]; // istanbul ignore next
  6238. if (map.has(key)) {
  6239. throw new Error(`Duplicate ${mainKey} ${JSON.stringify(key)}`);
  6240. }
  6241. map.set(key, value);
  6242. }
  6243. } catch (err) {
  6244. _didIteratorError2 = true;
  6245. _iteratorError2 = err;
  6246. } finally {
  6247. try {
  6248. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  6249. _iterator2.return();
  6250. }
  6251. } finally {
  6252. if (_didIteratorError2) {
  6253. throw _iteratorError2;
  6254. }
  6255. }
  6256. }
  6257. return map;
  6258. }
  6259. exports.mapFromArray = mapFromArray;
  6260. function createAutoChecklist() {
  6261. var map = Object.create(null);
  6262. return function (id) {
  6263. var idString = JSON.stringify(id);
  6264. if (map[idString]) {
  6265. return true;
  6266. }
  6267. map[idString] = true;
  6268. return false;
  6269. };
  6270. }
  6271. exports.createAutoChecklist = createAutoChecklist;
  6272. function partition(array, predicate) {
  6273. var trueArray = [];
  6274. var falseArray = [];
  6275. var _iteratorNormalCompletion3 = true;
  6276. var _didIteratorError3 = false;
  6277. var _iteratorError3 = undefined;
  6278. try {
  6279. for (var _iterator3 = array[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  6280. var value = _step3.value;
  6281. if (predicate(value)) {
  6282. trueArray.push(value);
  6283. } else {
  6284. falseArray.push(value);
  6285. }
  6286. }
  6287. } catch (err) {
  6288. _didIteratorError3 = true;
  6289. _iteratorError3 = err;
  6290. } finally {
  6291. try {
  6292. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  6293. _iterator3.return();
  6294. }
  6295. } finally {
  6296. if (_didIteratorError3) {
  6297. throw _iteratorError3;
  6298. }
  6299. }
  6300. }
  6301. return [trueArray, falseArray];
  6302. }
  6303. exports.partition = partition;
  6304. function isInt(value) {
  6305. return value === Math.floor(value);
  6306. }
  6307. exports.isInt = isInt;
  6308. function comparePrimitive(a, b) {
  6309. if (a === b) {
  6310. return 0;
  6311. }
  6312. var typeofA = typeof a;
  6313. var typeofB = typeof b;
  6314. var orders = ['undefined', 'object', 'boolean', 'number', 'string'];
  6315. if (typeofA !== typeofB) {
  6316. return orders.indexOf(typeofA) - orders.indexOf(typeofB);
  6317. }
  6318. if (typeofA !== 'string') {
  6319. return Number(a) - Number(b);
  6320. }
  6321. return a.localeCompare(b);
  6322. }
  6323. exports.comparePrimitive = comparePrimitive;
  6324. function normalizeDefaultResult(result) {
  6325. return result === undefined ? {} : result;
  6326. }
  6327. exports.normalizeDefaultResult = normalizeDefaultResult;
  6328. function normalizeValidateResult(result, value) {
  6329. return result === true ? true : result === false ? {
  6330. value
  6331. } : result;
  6332. }
  6333. exports.normalizeValidateResult = normalizeValidateResult;
  6334. function normalizeDeprecatedResult(result, value) {
  6335. var doNotNormalizeTrue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  6336. return result === false ? false : result === true ? doNotNormalizeTrue ? true : [{
  6337. value
  6338. }] : 'value' in result ? [result] : result.length === 0 ? false : result;
  6339. }
  6340. exports.normalizeDeprecatedResult = normalizeDeprecatedResult;
  6341. function normalizeTransferResult(result, value) {
  6342. return typeof result === 'string' || 'key' in result ? {
  6343. from: value,
  6344. to: result
  6345. } : 'from' in result ? {
  6346. from: result.from,
  6347. to: result.to
  6348. } : {
  6349. from: value,
  6350. to: result.to
  6351. };
  6352. }
  6353. exports.normalizeTransferResult = normalizeTransferResult;
  6354. function normalizeForwardResult(result, value) {
  6355. return result === undefined ? [] : Array.isArray(result) ? result.map(function (transferResult) {
  6356. return normalizeTransferResult(transferResult, value);
  6357. }) : [normalizeTransferResult(result, value)];
  6358. }
  6359. exports.normalizeForwardResult = normalizeForwardResult;
  6360. function normalizeRedirectResult(result, value) {
  6361. var redirect = normalizeForwardResult(typeof result === 'object' && 'redirect' in result ? result.redirect : result, value);
  6362. return redirect.length === 0 ? {
  6363. remain: value,
  6364. redirect
  6365. } : typeof result === 'object' && 'remain' in result ? {
  6366. remain: result.remain,
  6367. redirect
  6368. } : {
  6369. redirect
  6370. };
  6371. }
  6372. exports.normalizeRedirectResult = normalizeRedirectResult;
  6373. });
  6374. unwrapExports(utils);
  6375. var utils_1 = utils.recordFromArray;
  6376. var utils_2 = utils.mapFromArray;
  6377. var utils_3 = utils.createAutoChecklist;
  6378. var utils_4 = utils.partition;
  6379. var utils_5 = utils.isInt;
  6380. var utils_6 = utils.comparePrimitive;
  6381. var utils_7 = utils.normalizeDefaultResult;
  6382. var utils_8 = utils.normalizeValidateResult;
  6383. var utils_9 = utils.normalizeDeprecatedResult;
  6384. var utils_10 = utils.normalizeTransferResult;
  6385. var utils_11 = utils.normalizeForwardResult;
  6386. var utils_12 = utils.normalizeRedirectResult;
  6387. var choice = createCommonjsModule(function (module, exports) {
  6388. Object.defineProperty(exports, "__esModule", {
  6389. value: true
  6390. });
  6391. var ChoiceSchema =
  6392. /*#__PURE__*/
  6393. function (_schema_1$Schema) {
  6394. _inherits(ChoiceSchema, _schema_1$Schema);
  6395. function ChoiceSchema(parameters) {
  6396. var _this;
  6397. _classCallCheck(this, ChoiceSchema);
  6398. _this = _possibleConstructorReturn(this, _getPrototypeOf(ChoiceSchema).call(this, parameters));
  6399. _this._choices = utils.mapFromArray(parameters.choices.map(function (choice) {
  6400. return choice && typeof choice === 'object' ? choice : {
  6401. value: choice
  6402. };
  6403. }), 'value');
  6404. return _this;
  6405. }
  6406. _createClass(ChoiceSchema, [{
  6407. key: "expected",
  6408. value: function expected(_ref) {
  6409. var _this2 = this;
  6410. var descriptor = _ref.descriptor;
  6411. var choiceValues = Array.from(this._choices.keys()).map(function (value) {
  6412. return _this2._choices.get(value);
  6413. }).filter(function (choiceInfo) {
  6414. return !choiceInfo.deprecated;
  6415. }).map(function (choiceInfo) {
  6416. return choiceInfo.value;
  6417. }).sort(utils.comparePrimitive).map(descriptor.value);
  6418. var head = choiceValues.slice(0, -2);
  6419. var tail = choiceValues.slice(-2);
  6420. return head.concat(tail.join(' or ')).join(', ');
  6421. }
  6422. }, {
  6423. key: "validate",
  6424. value: function validate(value) {
  6425. return this._choices.has(value);
  6426. }
  6427. }, {
  6428. key: "deprecated",
  6429. value: function deprecated(value) {
  6430. var choiceInfo = this._choices.get(value);
  6431. return choiceInfo && choiceInfo.deprecated ? {
  6432. value
  6433. } : false;
  6434. }
  6435. }, {
  6436. key: "forward",
  6437. value: function forward(value) {
  6438. var choiceInfo = this._choices.get(value);
  6439. return choiceInfo ? choiceInfo.forward : undefined;
  6440. }
  6441. }, {
  6442. key: "redirect",
  6443. value: function redirect(value) {
  6444. var choiceInfo = this._choices.get(value);
  6445. return choiceInfo ? choiceInfo.redirect : undefined;
  6446. }
  6447. }]);
  6448. return ChoiceSchema;
  6449. }(schema.Schema);
  6450. exports.ChoiceSchema = ChoiceSchema;
  6451. });
  6452. unwrapExports(choice);
  6453. var choice_1 = choice.ChoiceSchema;
  6454. var number = createCommonjsModule(function (module, exports) {
  6455. Object.defineProperty(exports, "__esModule", {
  6456. value: true
  6457. });
  6458. var NumberSchema =
  6459. /*#__PURE__*/
  6460. function (_schema_1$Schema) {
  6461. _inherits(NumberSchema, _schema_1$Schema);
  6462. function NumberSchema() {
  6463. _classCallCheck(this, NumberSchema);
  6464. return _possibleConstructorReturn(this, _getPrototypeOf(NumberSchema).apply(this, arguments));
  6465. }
  6466. _createClass(NumberSchema, [{
  6467. key: "expected",
  6468. value: function expected() {
  6469. return 'a number';
  6470. }
  6471. }, {
  6472. key: "validate",
  6473. value: function validate(value, _utils) {
  6474. return typeof value === 'number';
  6475. }
  6476. }]);
  6477. return NumberSchema;
  6478. }(schema.Schema);
  6479. exports.NumberSchema = NumberSchema;
  6480. });
  6481. unwrapExports(number);
  6482. var number_1 = number.NumberSchema;
  6483. var integer = createCommonjsModule(function (module, exports) {
  6484. Object.defineProperty(exports, "__esModule", {
  6485. value: true
  6486. });
  6487. var IntegerSchema =
  6488. /*#__PURE__*/
  6489. function (_number_1$NumberSchem) {
  6490. _inherits(IntegerSchema, _number_1$NumberSchem);
  6491. function IntegerSchema() {
  6492. _classCallCheck(this, IntegerSchema);
  6493. return _possibleConstructorReturn(this, _getPrototypeOf(IntegerSchema).apply(this, arguments));
  6494. }
  6495. _createClass(IntegerSchema, [{
  6496. key: "expected",
  6497. value: function expected() {
  6498. return 'an integer';
  6499. }
  6500. }, {
  6501. key: "validate",
  6502. value: function validate(value, utils$1) {
  6503. return utils$1.normalizeValidateResult(_get(_getPrototypeOf(IntegerSchema.prototype), "validate", this).call(this, value, utils$1), value) === true && utils.isInt(value);
  6504. }
  6505. }]);
  6506. return IntegerSchema;
  6507. }(number.NumberSchema);
  6508. exports.IntegerSchema = IntegerSchema;
  6509. });
  6510. unwrapExports(integer);
  6511. var integer_1 = integer.IntegerSchema;
  6512. var string = createCommonjsModule(function (module, exports) {
  6513. Object.defineProperty(exports, "__esModule", {
  6514. value: true
  6515. });
  6516. var StringSchema =
  6517. /*#__PURE__*/
  6518. function (_schema_1$Schema) {
  6519. _inherits(StringSchema, _schema_1$Schema);
  6520. function StringSchema() {
  6521. _classCallCheck(this, StringSchema);
  6522. return _possibleConstructorReturn(this, _getPrototypeOf(StringSchema).apply(this, arguments));
  6523. }
  6524. _createClass(StringSchema, [{
  6525. key: "expected",
  6526. value: function expected() {
  6527. return 'a string';
  6528. }
  6529. }, {
  6530. key: "validate",
  6531. value: function validate(value) {
  6532. return typeof value === 'string';
  6533. }
  6534. }]);
  6535. return StringSchema;
  6536. }(schema.Schema);
  6537. exports.StringSchema = StringSchema;
  6538. });
  6539. unwrapExports(string);
  6540. var string_1 = string.StringSchema;
  6541. var schemas = createCommonjsModule(function (module, exports) {
  6542. Object.defineProperty(exports, "__esModule", {
  6543. value: true
  6544. });
  6545. tslib_es6.__exportStar(alias, exports);
  6546. tslib_es6.__exportStar(any, exports);
  6547. tslib_es6.__exportStar(array, exports);
  6548. tslib_es6.__exportStar(boolean_1, exports);
  6549. tslib_es6.__exportStar(choice, exports);
  6550. tslib_es6.__exportStar(integer, exports);
  6551. tslib_es6.__exportStar(number, exports);
  6552. tslib_es6.__exportStar(string, exports);
  6553. });
  6554. unwrapExports(schemas);
  6555. var defaults = createCommonjsModule(function (module, exports) {
  6556. Object.defineProperty(exports, "__esModule", {
  6557. value: true
  6558. });
  6559. exports.defaultDescriptor = api.apiDescriptor;
  6560. exports.defaultUnknownHandler = leven_1.levenUnknownHandler;
  6561. exports.defaultInvalidHandler = invalid.commonInvalidHandler;
  6562. exports.defaultDeprecatedHandler = common.commonDeprecatedHandler;
  6563. });
  6564. unwrapExports(defaults);
  6565. var defaults_1 = defaults.defaultDescriptor;
  6566. var defaults_2 = defaults.defaultUnknownHandler;
  6567. var defaults_3 = defaults.defaultInvalidHandler;
  6568. var defaults_4 = defaults.defaultDeprecatedHandler;
  6569. var normalize = createCommonjsModule(function (module, exports) {
  6570. Object.defineProperty(exports, "__esModule", {
  6571. value: true
  6572. });
  6573. exports.normalize = function (options, schemas, opts) {
  6574. return new Normalizer(schemas, opts).normalize(options);
  6575. };
  6576. var Normalizer =
  6577. /*#__PURE__*/
  6578. function () {
  6579. function Normalizer(schemas, opts) {
  6580. _classCallCheck(this, Normalizer);
  6581. // istanbul ignore next
  6582. var _ref = opts || {},
  6583. _ref$logger = _ref.logger,
  6584. logger = _ref$logger === void 0 ? console : _ref$logger,
  6585. _ref$descriptor = _ref.descriptor,
  6586. descriptor = _ref$descriptor === void 0 ? defaults.defaultDescriptor : _ref$descriptor,
  6587. _ref$unknown = _ref.unknown,
  6588. unknown = _ref$unknown === void 0 ? defaults.defaultUnknownHandler : _ref$unknown,
  6589. _ref$invalid = _ref.invalid,
  6590. invalid = _ref$invalid === void 0 ? defaults.defaultInvalidHandler : _ref$invalid,
  6591. _ref$deprecated = _ref.deprecated,
  6592. deprecated = _ref$deprecated === void 0 ? defaults.defaultDeprecatedHandler : _ref$deprecated;
  6593. this._utils = {
  6594. descriptor,
  6595. logger:
  6596. /* istanbul ignore next */
  6597. logger || {
  6598. warn: function warn() {}
  6599. },
  6600. schemas: utils.recordFromArray(schemas, 'name'),
  6601. normalizeDefaultResult: utils.normalizeDefaultResult,
  6602. normalizeDeprecatedResult: utils.normalizeDeprecatedResult,
  6603. normalizeForwardResult: utils.normalizeForwardResult,
  6604. normalizeRedirectResult: utils.normalizeRedirectResult,
  6605. normalizeValidateResult: utils.normalizeValidateResult
  6606. };
  6607. this._unknownHandler = unknown;
  6608. this._invalidHandler = invalid;
  6609. this._deprecatedHandler = deprecated;
  6610. this.cleanHistory();
  6611. }
  6612. _createClass(Normalizer, [{
  6613. key: "cleanHistory",
  6614. value: function cleanHistory() {
  6615. this._hasDeprecationWarned = utils.createAutoChecklist();
  6616. }
  6617. }, {
  6618. key: "normalize",
  6619. value: function normalize(options) {
  6620. var _this = this;
  6621. var normalized = {};
  6622. var restOptionsArray = [options];
  6623. var applyNormalization = function applyNormalization() {
  6624. while (restOptionsArray.length !== 0) {
  6625. var currentOptions = restOptionsArray.shift();
  6626. var transferredOptionsArray = _this._applyNormalization(currentOptions, normalized);
  6627. restOptionsArray.push.apply(restOptionsArray, _toConsumableArray$1(transferredOptionsArray));
  6628. }
  6629. };
  6630. applyNormalization();
  6631. for (var _i = 0, _Object$keys = Object.keys(this._utils.schemas); _i < _Object$keys.length; _i++) {
  6632. var key = _Object$keys[_i];
  6633. var schema = this._utils.schemas[key];
  6634. if (!(key in normalized)) {
  6635. var defaultResult = utils.normalizeDefaultResult(schema.default(this._utils));
  6636. if ('value' in defaultResult) {
  6637. restOptionsArray.push({
  6638. [key]: defaultResult.value
  6639. });
  6640. }
  6641. }
  6642. }
  6643. applyNormalization();
  6644. for (var _i2 = 0, _Object$keys2 = Object.keys(this._utils.schemas); _i2 < _Object$keys2.length; _i2++) {
  6645. var _key = _Object$keys2[_i2];
  6646. var _schema = this._utils.schemas[_key];
  6647. if (_key in normalized) {
  6648. normalized[_key] = _schema.postprocess(normalized[_key], this._utils);
  6649. }
  6650. }
  6651. return normalized;
  6652. }
  6653. }, {
  6654. key: "_applyNormalization",
  6655. value: function _applyNormalization(options, normalized) {
  6656. var _this2 = this;
  6657. var transferredOptionsArray = [];
  6658. var _utils_1$partition = utils.partition(Object.keys(options), function (key) {
  6659. return key in _this2._utils.schemas;
  6660. }),
  6661. _utils_1$partition2 = _slicedToArray(_utils_1$partition, 2),
  6662. knownOptionNames = _utils_1$partition2[0],
  6663. unknownOptionNames = _utils_1$partition2[1];
  6664. var _iteratorNormalCompletion = true;
  6665. var _didIteratorError = false;
  6666. var _iteratorError = undefined;
  6667. try {
  6668. var _loop = function _loop() {
  6669. var key = _step.value;
  6670. var schema = _this2._utils.schemas[key];
  6671. var value = schema.preprocess(options[key], _this2._utils);
  6672. var validateResult = utils.normalizeValidateResult(schema.validate(value, _this2._utils), value);
  6673. if (validateResult !== true) {
  6674. var invalidValue = validateResult.value;
  6675. var errorMessageOrError = _this2._invalidHandler(key, invalidValue, _this2._utils);
  6676. throw typeof errorMessageOrError === 'string' ? new Error(errorMessageOrError) :
  6677. /* istanbul ignore next*/
  6678. errorMessageOrError;
  6679. }
  6680. var appendTransferredOptions = function appendTransferredOptions(_ref2) {
  6681. var from = _ref2.from,
  6682. to = _ref2.to;
  6683. transferredOptionsArray.push(typeof to === 'string' ? {
  6684. [to]: from
  6685. } : {
  6686. [to.key]: to.value
  6687. });
  6688. };
  6689. var warnDeprecated = function warnDeprecated(_ref3) {
  6690. var currentValue = _ref3.value,
  6691. redirectTo = _ref3.redirectTo;
  6692. var deprecatedResult = utils.normalizeDeprecatedResult(schema.deprecated(currentValue, _this2._utils), value,
  6693. /* doNotNormalizeTrue */
  6694. true);
  6695. if (deprecatedResult === false) {
  6696. return;
  6697. }
  6698. if (deprecatedResult === true) {
  6699. if (!_this2._hasDeprecationWarned(key)) {
  6700. _this2._utils.logger.warn(_this2._deprecatedHandler(key, redirectTo, _this2._utils));
  6701. }
  6702. } else {
  6703. var _iteratorNormalCompletion3 = true;
  6704. var _didIteratorError3 = false;
  6705. var _iteratorError3 = undefined;
  6706. try {
  6707. for (var _iterator3 = deprecatedResult[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  6708. var deprecatedValue = _step3.value.value;
  6709. var pair = {
  6710. key,
  6711. value: deprecatedValue
  6712. };
  6713. if (!_this2._hasDeprecationWarned(pair)) {
  6714. var redirectToPair = typeof redirectTo === 'string' ? {
  6715. key: redirectTo,
  6716. value: deprecatedValue
  6717. } : redirectTo;
  6718. _this2._utils.logger.warn(_this2._deprecatedHandler(pair, redirectToPair, _this2._utils));
  6719. }
  6720. }
  6721. } catch (err) {
  6722. _didIteratorError3 = true;
  6723. _iteratorError3 = err;
  6724. } finally {
  6725. try {
  6726. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  6727. _iterator3.return();
  6728. }
  6729. } finally {
  6730. if (_didIteratorError3) {
  6731. throw _iteratorError3;
  6732. }
  6733. }
  6734. }
  6735. }
  6736. };
  6737. var forwardResult = utils.normalizeForwardResult(schema.forward(value, _this2._utils), value);
  6738. forwardResult.forEach(appendTransferredOptions);
  6739. var redirectResult = utils.normalizeRedirectResult(schema.redirect(value, _this2._utils), value);
  6740. redirectResult.redirect.forEach(appendTransferredOptions);
  6741. if ('remain' in redirectResult) {
  6742. var remainingValue = redirectResult.remain;
  6743. normalized[key] = key in normalized ? schema.overlap(normalized[key], remainingValue, _this2._utils) : remainingValue;
  6744. warnDeprecated({
  6745. value: remainingValue
  6746. });
  6747. }
  6748. var _iteratorNormalCompletion4 = true;
  6749. var _didIteratorError4 = false;
  6750. var _iteratorError4 = undefined;
  6751. try {
  6752. for (var _iterator4 = redirectResult.redirect[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  6753. var _step4$value = _step4.value,
  6754. from = _step4$value.from,
  6755. to = _step4$value.to;
  6756. warnDeprecated({
  6757. value: from,
  6758. redirectTo: to
  6759. });
  6760. }
  6761. } catch (err) {
  6762. _didIteratorError4 = true;
  6763. _iteratorError4 = err;
  6764. } finally {
  6765. try {
  6766. if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
  6767. _iterator4.return();
  6768. }
  6769. } finally {
  6770. if (_didIteratorError4) {
  6771. throw _iteratorError4;
  6772. }
  6773. }
  6774. }
  6775. };
  6776. for (var _iterator = knownOptionNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  6777. _loop();
  6778. }
  6779. } catch (err) {
  6780. _didIteratorError = true;
  6781. _iteratorError = err;
  6782. } finally {
  6783. try {
  6784. if (!_iteratorNormalCompletion && _iterator.return != null) {
  6785. _iterator.return();
  6786. }
  6787. } finally {
  6788. if (_didIteratorError) {
  6789. throw _iteratorError;
  6790. }
  6791. }
  6792. }
  6793. var _iteratorNormalCompletion2 = true;
  6794. var _didIteratorError2 = false;
  6795. var _iteratorError2 = undefined;
  6796. try {
  6797. for (var _iterator2 = unknownOptionNames[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  6798. var key = _step2.value;
  6799. var value = options[key];
  6800. var unknownResult = this._unknownHandler(key, value, this._utils);
  6801. if (unknownResult) {
  6802. for (var _i3 = 0, _Object$keys3 = Object.keys(unknownResult); _i3 < _Object$keys3.length; _i3++) {
  6803. var unknownKey = _Object$keys3[_i3];
  6804. var unknownOption = {
  6805. [unknownKey]: unknownResult[unknownKey]
  6806. };
  6807. if (unknownKey in this._utils.schemas) {
  6808. transferredOptionsArray.push(unknownOption);
  6809. } else {
  6810. Object.assign(normalized, unknownOption);
  6811. }
  6812. }
  6813. }
  6814. }
  6815. } catch (err) {
  6816. _didIteratorError2 = true;
  6817. _iteratorError2 = err;
  6818. } finally {
  6819. try {
  6820. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  6821. _iterator2.return();
  6822. }
  6823. } finally {
  6824. if (_didIteratorError2) {
  6825. throw _iteratorError2;
  6826. }
  6827. }
  6828. }
  6829. return transferredOptionsArray;
  6830. }
  6831. }]);
  6832. return Normalizer;
  6833. }();
  6834. exports.Normalizer = Normalizer;
  6835. });
  6836. unwrapExports(normalize);
  6837. var normalize_1 = normalize.normalize;
  6838. var normalize_2 = normalize.Normalizer;
  6839. var lib = createCommonjsModule(function (module, exports) {
  6840. Object.defineProperty(exports, "__esModule", {
  6841. value: true
  6842. });
  6843. tslib_es6.__exportStar(descriptors, exports);
  6844. tslib_es6.__exportStar(handlers, exports);
  6845. tslib_es6.__exportStar(schemas, exports);
  6846. tslib_es6.__exportStar(normalize, exports);
  6847. tslib_es6.__exportStar(schema, exports);
  6848. });
  6849. unwrapExports(lib);
  6850. var array$1 = [];
  6851. var charCodeCache$1 = [];
  6852. var leven$1 = function leven(left, right) {
  6853. if (left === right) {
  6854. return 0;
  6855. }
  6856. var swap = left; // Swapping the strings if `a` is longer than `b` so we know which one is the
  6857. // shortest & which one is the longest
  6858. if (left.length > right.length) {
  6859. left = right;
  6860. right = swap;
  6861. }
  6862. var leftLength = left.length;
  6863. var rightLength = right.length; // Performing suffix trimming:
  6864. // We can linearly drop suffix common to both strings since they
  6865. // don't increase distance at all
  6866. // Note: `~-` is the bitwise way to perform a `- 1` operation
  6867. while (leftLength > 0 && left.charCodeAt(~-leftLength) === right.charCodeAt(~-rightLength)) {
  6868. leftLength--;
  6869. rightLength--;
  6870. } // Performing prefix trimming
  6871. // We can linearly drop prefix common to both strings since they
  6872. // don't increase distance at all
  6873. var start = 0;
  6874. while (start < leftLength && left.charCodeAt(start) === right.charCodeAt(start)) {
  6875. start++;
  6876. }
  6877. leftLength -= start;
  6878. rightLength -= start;
  6879. if (leftLength === 0) {
  6880. return rightLength;
  6881. }
  6882. var bCharCode;
  6883. var result;
  6884. var temp;
  6885. var temp2;
  6886. var i = 0;
  6887. var j = 0;
  6888. while (i < leftLength) {
  6889. charCodeCache$1[i] = left.charCodeAt(start + i);
  6890. array$1[i] = ++i;
  6891. }
  6892. while (j < rightLength) {
  6893. bCharCode = right.charCodeAt(start + j);
  6894. temp = j++;
  6895. result = j;
  6896. for (i = 0; i < leftLength; i++) {
  6897. temp2 = bCharCode === charCodeCache$1[i] ? temp : temp + 1;
  6898. temp = array$1[i]; // eslint-disable-next-line no-multi-assign
  6899. result = array$1[i] = temp > result ? temp2 > result ? result + 1 : temp2 : temp2 > temp ? temp + 1 : temp2;
  6900. }
  6901. }
  6902. return result;
  6903. };
  6904. var leven_1$1 = leven$1; // TODO: Remove this for the next major release
  6905. var default_1 = leven$1;
  6906. leven_1$1.default = default_1;
  6907. var cliDescriptor = {
  6908. key: function key(_key) {
  6909. return _key.length === 1 ? `-${_key}` : `--${_key}`;
  6910. },
  6911. value: function value(_value) {
  6912. return lib.apiDescriptor.value(_value);
  6913. },
  6914. pair: function pair(_ref) {
  6915. var key = _ref.key,
  6916. value = _ref.value;
  6917. return value === false ? `--no-${key}` : value === true ? cliDescriptor.key(key) : value === "" ? `${cliDescriptor.key(key)} without an argument` : `${cliDescriptor.key(key)}=${value}`;
  6918. }
  6919. };
  6920. var FlagSchema =
  6921. /*#__PURE__*/
  6922. function (_vnopts$ChoiceSchema) {
  6923. _inherits(FlagSchema, _vnopts$ChoiceSchema);
  6924. function FlagSchema(_ref2) {
  6925. var _this;
  6926. var name = _ref2.name,
  6927. flags = _ref2.flags;
  6928. _classCallCheck(this, FlagSchema);
  6929. _this = _possibleConstructorReturn(this, _getPrototypeOf(FlagSchema).call(this, {
  6930. name,
  6931. choices: flags
  6932. }));
  6933. _this._flags = flags.slice().sort();
  6934. return _this;
  6935. }
  6936. _createClass(FlagSchema, [{
  6937. key: "preprocess",
  6938. value: function preprocess(value, utils) {
  6939. if (typeof value === "string" && value.length !== 0 && this._flags.indexOf(value) === -1) {
  6940. var suggestion = this._flags.find(function (flag) {
  6941. return leven_1$1(flag, value) < 3;
  6942. });
  6943. if (suggestion) {
  6944. utils.logger.warn([`Unknown flag ${chalk.yellow(utils.descriptor.value(value))},`, `did you mean ${chalk.blue(utils.descriptor.value(suggestion))}?`].join(" "));
  6945. return suggestion;
  6946. }
  6947. }
  6948. return value;
  6949. }
  6950. }, {
  6951. key: "expected",
  6952. value: function expected() {
  6953. return "a flag";
  6954. }
  6955. }]);
  6956. return FlagSchema;
  6957. }(lib.ChoiceSchema);
  6958. var hasDeprecationWarned;
  6959. function normalizeOptions(options, optionInfos) {
  6960. var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
  6961. logger = _ref3.logger,
  6962. _ref3$isCLI = _ref3.isCLI,
  6963. isCLI = _ref3$isCLI === void 0 ? false : _ref3$isCLI,
  6964. _ref3$passThrough = _ref3.passThrough,
  6965. passThrough = _ref3$passThrough === void 0 ? false : _ref3$passThrough;
  6966. var unknown = !passThrough ? lib.levenUnknownHandler : Array.isArray(passThrough) ? function (key, value) {
  6967. return passThrough.indexOf(key) === -1 ? undefined : {
  6968. [key]: value
  6969. };
  6970. } : function (key, value) {
  6971. return {
  6972. [key]: value
  6973. };
  6974. };
  6975. var descriptor = isCLI ? cliDescriptor : lib.apiDescriptor;
  6976. var schemas = optionInfosToSchemas(optionInfos, {
  6977. isCLI
  6978. });
  6979. var normalizer = new lib.Normalizer(schemas, {
  6980. logger,
  6981. unknown,
  6982. descriptor
  6983. });
  6984. var shouldSuppressDuplicateDeprecationWarnings = logger !== false;
  6985. if (shouldSuppressDuplicateDeprecationWarnings && hasDeprecationWarned) {
  6986. normalizer._hasDeprecationWarned = hasDeprecationWarned;
  6987. }
  6988. var normalized = normalizer.normalize(options);
  6989. if (shouldSuppressDuplicateDeprecationWarnings) {
  6990. hasDeprecationWarned = normalizer._hasDeprecationWarned;
  6991. }
  6992. return normalized;
  6993. }
  6994. function optionInfosToSchemas(optionInfos, _ref4) {
  6995. var isCLI = _ref4.isCLI;
  6996. var schemas = [];
  6997. if (isCLI) {
  6998. schemas.push(lib.AnySchema.create({
  6999. name: "_"
  7000. }));
  7001. }
  7002. var _iteratorNormalCompletion = true;
  7003. var _didIteratorError = false;
  7004. var _iteratorError = undefined;
  7005. try {
  7006. for (var _iterator = optionInfos[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7007. var optionInfo = _step.value;
  7008. schemas.push(optionInfoToSchema(optionInfo, {
  7009. isCLI,
  7010. optionInfos
  7011. }));
  7012. if (optionInfo.alias && isCLI) {
  7013. schemas.push(lib.AliasSchema.create({
  7014. name: optionInfo.alias,
  7015. sourceName: optionInfo.name
  7016. }));
  7017. }
  7018. }
  7019. } catch (err) {
  7020. _didIteratorError = true;
  7021. _iteratorError = err;
  7022. } finally {
  7023. try {
  7024. if (!_iteratorNormalCompletion && _iterator.return != null) {
  7025. _iterator.return();
  7026. }
  7027. } finally {
  7028. if (_didIteratorError) {
  7029. throw _iteratorError;
  7030. }
  7031. }
  7032. }
  7033. return schemas;
  7034. }
  7035. function optionInfoToSchema(optionInfo, _ref5) {
  7036. var isCLI = _ref5.isCLI,
  7037. optionInfos = _ref5.optionInfos;
  7038. var SchemaConstructor;
  7039. var parameters = {
  7040. name: optionInfo.name
  7041. };
  7042. var handlers = {};
  7043. switch (optionInfo.type) {
  7044. case "int":
  7045. SchemaConstructor = lib.IntegerSchema;
  7046. if (isCLI) {
  7047. parameters.preprocess = function (value) {
  7048. return Number(value);
  7049. };
  7050. }
  7051. break;
  7052. case "string":
  7053. SchemaConstructor = lib.StringSchema;
  7054. break;
  7055. case "choice":
  7056. SchemaConstructor = lib.ChoiceSchema;
  7057. parameters.choices = optionInfo.choices.map(function (choiceInfo) {
  7058. return typeof choiceInfo === "object" && choiceInfo.redirect ? Object.assign({}, choiceInfo, {
  7059. redirect: {
  7060. to: {
  7061. key: optionInfo.name,
  7062. value: choiceInfo.redirect
  7063. }
  7064. }
  7065. }) : choiceInfo;
  7066. });
  7067. break;
  7068. case "boolean":
  7069. SchemaConstructor = lib.BooleanSchema;
  7070. break;
  7071. case "flag":
  7072. SchemaConstructor = FlagSchema;
  7073. parameters.flags = optionInfos.map(function (optionInfo) {
  7074. return [].concat(optionInfo.alias || [], optionInfo.description ? optionInfo.name : [], optionInfo.oppositeDescription ? `no-${optionInfo.name}` : []);
  7075. }).reduce(function (a, b) {
  7076. return a.concat(b);
  7077. }, []);
  7078. break;
  7079. case "path":
  7080. SchemaConstructor = lib.StringSchema;
  7081. break;
  7082. default:
  7083. throw new Error(`Unexpected type ${optionInfo.type}`);
  7084. }
  7085. if (optionInfo.exception) {
  7086. parameters.validate = function (value, schema, utils) {
  7087. return optionInfo.exception(value) || schema.validate(value, utils);
  7088. };
  7089. } else {
  7090. parameters.validate = function (value, schema, utils) {
  7091. return value === undefined || schema.validate(value, utils);
  7092. };
  7093. }
  7094. if (optionInfo.redirect) {
  7095. handlers.redirect = function (value) {
  7096. return !value ? undefined : {
  7097. to: {
  7098. key: optionInfo.redirect.option,
  7099. value: optionInfo.redirect.value
  7100. }
  7101. };
  7102. };
  7103. }
  7104. if (optionInfo.deprecated) {
  7105. handlers.deprecated = true;
  7106. } // allow CLI overriding, e.g., prettier package.json --tab-width 1 --tab-width 2
  7107. if (isCLI && !optionInfo.array) {
  7108. var originalPreprocess = parameters.preprocess || function (x) {
  7109. return x;
  7110. };
  7111. parameters.preprocess = function (value, schema, utils) {
  7112. return schema.preprocess(originalPreprocess(Array.isArray(value) ? value[value.length - 1] : value), utils);
  7113. };
  7114. }
  7115. return optionInfo.array ? lib.ArraySchema.create(Object.assign(isCLI ? {
  7116. preprocess: function preprocess(v) {
  7117. return [].concat(v);
  7118. }
  7119. } : {}, handlers, {
  7120. valueSchema: SchemaConstructor.create(parameters)
  7121. })) : SchemaConstructor.create(Object.assign({}, parameters, handlers));
  7122. }
  7123. function normalizeApiOptions(options, optionInfos, opts) {
  7124. return normalizeOptions(options, optionInfos, opts);
  7125. }
  7126. function normalizeCliOptions(options, optionInfos, opts) {
  7127. return normalizeOptions(options, optionInfos, Object.assign({
  7128. isCLI: true
  7129. }, opts));
  7130. }
  7131. var optionsNormalizer = {
  7132. normalizeApiOptions,
  7133. normalizeCliOptions
  7134. };
  7135. var getLast = function getLast(arr) {
  7136. return arr.length > 0 ? arr[arr.length - 1] : null;
  7137. };
  7138. function locStart(node, opts) {
  7139. opts = opts || {}; // Handle nodes with decorators. They should start at the first decorator
  7140. if (!opts.ignoreDecorators && node.declaration && node.declaration.decorators && node.declaration.decorators.length > 0) {
  7141. return locStart(node.declaration.decorators[0]);
  7142. }
  7143. if (!opts.ignoreDecorators && node.decorators && node.decorators.length > 0) {
  7144. return locStart(node.decorators[0]);
  7145. }
  7146. if (node.__location) {
  7147. return node.__location.startOffset;
  7148. }
  7149. if (node.range) {
  7150. return node.range[0];
  7151. }
  7152. if (typeof node.start === "number") {
  7153. return node.start;
  7154. }
  7155. if (node.loc) {
  7156. return node.loc.start;
  7157. }
  7158. return null;
  7159. }
  7160. function locEnd(node) {
  7161. var endNode = node.nodes && getLast(node.nodes);
  7162. if (endNode && node.source && !node.source.end) {
  7163. node = endNode;
  7164. }
  7165. if (node.__location) {
  7166. return node.__location.endOffset;
  7167. }
  7168. var loc = node.range ? node.range[1] : typeof node.end === "number" ? node.end : null;
  7169. if (node.typeAnnotation) {
  7170. return Math.max(loc, locEnd(node.typeAnnotation));
  7171. }
  7172. if (node.loc && !loc) {
  7173. return node.loc.end;
  7174. }
  7175. return loc;
  7176. }
  7177. var loc = {
  7178. locStart,
  7179. locEnd
  7180. };
  7181. var jsTokens = createCommonjsModule(function (module, exports) {
  7182. // Copyright 2014, 2015, 2016, 2017, 2018 Simon Lydell
  7183. // License: MIT. (See LICENSE.)
  7184. Object.defineProperty(exports, "__esModule", {
  7185. value: true
  7186. }); // This regex comes from regex.coffee, and is inserted here by generate-index.js
  7187. // (run `npm run build`).
  7188. 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;
  7189. exports.matchToToken = function (match) {
  7190. var token = {
  7191. type: "invalid",
  7192. value: match[0],
  7193. closed: undefined
  7194. };
  7195. 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";
  7196. return token;
  7197. };
  7198. });
  7199. unwrapExports(jsTokens);
  7200. var jsTokens_1 = jsTokens.matchToToken;
  7201. var ast = createCommonjsModule(function (module) {
  7202. /*
  7203. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7204. Redistribution and use in source and binary forms, with or without
  7205. modification, are permitted provided that the following conditions are met:
  7206. * Redistributions of source code must retain the above copyright
  7207. notice, this list of conditions and the following disclaimer.
  7208. * Redistributions in binary form must reproduce the above copyright
  7209. notice, this list of conditions and the following disclaimer in the
  7210. documentation and/or other materials provided with the distribution.
  7211. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
  7212. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7213. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7214. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7215. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7216. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7217. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7218. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7219. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7220. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7221. */
  7222. (function () {
  7223. function isExpression(node) {
  7224. if (node == null) {
  7225. return false;
  7226. }
  7227. switch (node.type) {
  7228. case 'ArrayExpression':
  7229. case 'AssignmentExpression':
  7230. case 'BinaryExpression':
  7231. case 'CallExpression':
  7232. case 'ConditionalExpression':
  7233. case 'FunctionExpression':
  7234. case 'Identifier':
  7235. case 'Literal':
  7236. case 'LogicalExpression':
  7237. case 'MemberExpression':
  7238. case 'NewExpression':
  7239. case 'ObjectExpression':
  7240. case 'SequenceExpression':
  7241. case 'ThisExpression':
  7242. case 'UnaryExpression':
  7243. case 'UpdateExpression':
  7244. return true;
  7245. }
  7246. return false;
  7247. }
  7248. function isIterationStatement(node) {
  7249. if (node == null) {
  7250. return false;
  7251. }
  7252. switch (node.type) {
  7253. case 'DoWhileStatement':
  7254. case 'ForInStatement':
  7255. case 'ForStatement':
  7256. case 'WhileStatement':
  7257. return true;
  7258. }
  7259. return false;
  7260. }
  7261. function isStatement(node) {
  7262. if (node == null) {
  7263. return false;
  7264. }
  7265. switch (node.type) {
  7266. case 'BlockStatement':
  7267. case 'BreakStatement':
  7268. case 'ContinueStatement':
  7269. case 'DebuggerStatement':
  7270. case 'DoWhileStatement':
  7271. case 'EmptyStatement':
  7272. case 'ExpressionStatement':
  7273. case 'ForInStatement':
  7274. case 'ForStatement':
  7275. case 'IfStatement':
  7276. case 'LabeledStatement':
  7277. case 'ReturnStatement':
  7278. case 'SwitchStatement':
  7279. case 'ThrowStatement':
  7280. case 'TryStatement':
  7281. case 'VariableDeclaration':
  7282. case 'WhileStatement':
  7283. case 'WithStatement':
  7284. return true;
  7285. }
  7286. return false;
  7287. }
  7288. function isSourceElement(node) {
  7289. return isStatement(node) || node != null && node.type === 'FunctionDeclaration';
  7290. }
  7291. function trailingStatement(node) {
  7292. switch (node.type) {
  7293. case 'IfStatement':
  7294. if (node.alternate != null) {
  7295. return node.alternate;
  7296. }
  7297. return node.consequent;
  7298. case 'LabeledStatement':
  7299. case 'ForStatement':
  7300. case 'ForInStatement':
  7301. case 'WhileStatement':
  7302. case 'WithStatement':
  7303. return node.body;
  7304. }
  7305. return null;
  7306. }
  7307. function isProblematicIfStatement(node) {
  7308. var current;
  7309. if (node.type !== 'IfStatement') {
  7310. return false;
  7311. }
  7312. if (node.alternate == null) {
  7313. return false;
  7314. }
  7315. current = node.consequent;
  7316. do {
  7317. if (current.type === 'IfStatement') {
  7318. if (current.alternate == null) {
  7319. return true;
  7320. }
  7321. }
  7322. current = trailingStatement(current);
  7323. } while (current);
  7324. return false;
  7325. }
  7326. module.exports = {
  7327. isExpression: isExpression,
  7328. isStatement: isStatement,
  7329. isIterationStatement: isIterationStatement,
  7330. isSourceElement: isSourceElement,
  7331. isProblematicIfStatement: isProblematicIfStatement,
  7332. trailingStatement: trailingStatement
  7333. };
  7334. })();
  7335. /* vim: set sw=4 ts=4 et tw=80 : */
  7336. });
  7337. var ast_1 = ast.isExpression;
  7338. var ast_2 = ast.isStatement;
  7339. var ast_3 = ast.isIterationStatement;
  7340. var ast_4 = ast.isSourceElement;
  7341. var ast_5 = ast.isProblematicIfStatement;
  7342. var ast_6 = ast.trailingStatement;
  7343. var code = createCommonjsModule(function (module) {
  7344. /*
  7345. Copyright (C) 2013-2014 Yusuke Suzuki <utatane.tea@gmail.com>
  7346. Copyright (C) 2014 Ivan Nikulin <ifaaan@gmail.com>
  7347. Redistribution and use in source and binary forms, with or without
  7348. modification, are permitted provided that the following conditions are met:
  7349. * Redistributions of source code must retain the above copyright
  7350. notice, this list of conditions and the following disclaimer.
  7351. * Redistributions in binary form must reproduce the above copyright
  7352. notice, this list of conditions and the following disclaimer in the
  7353. documentation and/or other materials provided with the distribution.
  7354. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7355. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7356. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7357. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7358. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7359. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7360. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7361. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7362. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7363. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7364. */
  7365. (function () {
  7366. var ES6Regex, ES5Regex, NON_ASCII_WHITESPACES, IDENTIFIER_START, IDENTIFIER_PART, ch; // See `tools/generate-identifier-regex.js`.
  7367. ES5Regex = {
  7368. // ECMAScript 5.1/Unicode v9.0.0 NonAsciiIdentifierStart:
  7369. 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]/,
  7370. // ECMAScript 5.1/Unicode v9.0.0 NonAsciiIdentifierPart:
  7371. 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]/
  7372. };
  7373. ES6Regex = {
  7374. // ECMAScript 6/Unicode v9.0.0 NonAsciiIdentifierStart:
  7375. 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]/,
  7376. // ECMAScript 6/Unicode v9.0.0 NonAsciiIdentifierPart:
  7377. 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]/
  7378. };
  7379. function isDecimalDigit(ch) {
  7380. return 0x30 <= ch && ch <= 0x39; // 0..9
  7381. }
  7382. function isHexDigit(ch) {
  7383. return 0x30 <= ch && ch <= 0x39 || // 0..9
  7384. 0x61 <= ch && ch <= 0x66 || // a..f
  7385. 0x41 <= ch && ch <= 0x46; // A..F
  7386. }
  7387. function isOctalDigit(ch) {
  7388. return ch >= 0x30 && ch <= 0x37; // 0..7
  7389. } // 7.2 White Space
  7390. NON_ASCII_WHITESPACES = [0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF];
  7391. function isWhiteSpace(ch) {
  7392. return ch === 0x20 || ch === 0x09 || ch === 0x0B || ch === 0x0C || ch === 0xA0 || ch >= 0x1680 && NON_ASCII_WHITESPACES.indexOf(ch) >= 0;
  7393. } // 7.3 Line Terminators
  7394. function isLineTerminator(ch) {
  7395. return ch === 0x0A || ch === 0x0D || ch === 0x2028 || ch === 0x2029;
  7396. } // 7.6 Identifier Names and Identifiers
  7397. function fromCodePoint(cp) {
  7398. if (cp <= 0xFFFF) {
  7399. return String.fromCharCode(cp);
  7400. }
  7401. var cu1 = String.fromCharCode(Math.floor((cp - 0x10000) / 0x400) + 0xD800);
  7402. var cu2 = String.fromCharCode((cp - 0x10000) % 0x400 + 0xDC00);
  7403. return cu1 + cu2;
  7404. }
  7405. IDENTIFIER_START = new Array(0x80);
  7406. for (ch = 0; ch < 0x80; ++ch) {
  7407. IDENTIFIER_START[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  7408. ch >= 0x41 && ch <= 0x5A || // A..Z
  7409. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  7410. }
  7411. IDENTIFIER_PART = new Array(0x80);
  7412. for (ch = 0; ch < 0x80; ++ch) {
  7413. IDENTIFIER_PART[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  7414. ch >= 0x41 && ch <= 0x5A || // A..Z
  7415. ch >= 0x30 && ch <= 0x39 || // 0..9
  7416. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  7417. }
  7418. function isIdentifierStartES5(ch) {
  7419. return ch < 0x80 ? IDENTIFIER_START[ch] : ES5Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  7420. }
  7421. function isIdentifierPartES5(ch) {
  7422. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES5Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  7423. }
  7424. function isIdentifierStartES6(ch) {
  7425. return ch < 0x80 ? IDENTIFIER_START[ch] : ES6Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  7426. }
  7427. function isIdentifierPartES6(ch) {
  7428. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES6Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  7429. }
  7430. module.exports = {
  7431. isDecimalDigit: isDecimalDigit,
  7432. isHexDigit: isHexDigit,
  7433. isOctalDigit: isOctalDigit,
  7434. isWhiteSpace: isWhiteSpace,
  7435. isLineTerminator: isLineTerminator,
  7436. isIdentifierStartES5: isIdentifierStartES5,
  7437. isIdentifierPartES5: isIdentifierPartES5,
  7438. isIdentifierStartES6: isIdentifierStartES6,
  7439. isIdentifierPartES6: isIdentifierPartES6
  7440. };
  7441. })();
  7442. /* vim: set sw=4 ts=4 et tw=80 : */
  7443. });
  7444. var code_1 = code.isDecimalDigit;
  7445. var code_2 = code.isHexDigit;
  7446. var code_3 = code.isOctalDigit;
  7447. var code_4 = code.isWhiteSpace;
  7448. var code_5 = code.isLineTerminator;
  7449. var code_6 = code.isIdentifierStartES5;
  7450. var code_7 = code.isIdentifierPartES5;
  7451. var code_8 = code.isIdentifierStartES6;
  7452. var code_9 = code.isIdentifierPartES6;
  7453. var keyword = createCommonjsModule(function (module) {
  7454. /*
  7455. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7456. Redistribution and use in source and binary forms, with or without
  7457. modification, are permitted provided that the following conditions are met:
  7458. * Redistributions of source code must retain the above copyright
  7459. notice, this list of conditions and the following disclaimer.
  7460. * Redistributions in binary form must reproduce the above copyright
  7461. notice, this list of conditions and the following disclaimer in the
  7462. documentation and/or other materials provided with the distribution.
  7463. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7464. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7465. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7466. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7467. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7468. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7469. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7470. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7471. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7472. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7473. */
  7474. (function () {
  7475. var code$1 = code;
  7476. function isStrictModeReservedWordES6(id) {
  7477. switch (id) {
  7478. case 'implements':
  7479. case 'interface':
  7480. case 'package':
  7481. case 'private':
  7482. case 'protected':
  7483. case 'public':
  7484. case 'static':
  7485. case 'let':
  7486. return true;
  7487. default:
  7488. return false;
  7489. }
  7490. }
  7491. function isKeywordES5(id, strict) {
  7492. // yield should not be treated as keyword under non-strict mode.
  7493. if (!strict && id === 'yield') {
  7494. return false;
  7495. }
  7496. return isKeywordES6(id, strict);
  7497. }
  7498. function isKeywordES6(id, strict) {
  7499. if (strict && isStrictModeReservedWordES6(id)) {
  7500. return true;
  7501. }
  7502. switch (id.length) {
  7503. case 2:
  7504. return id === 'if' || id === 'in' || id === 'do';
  7505. case 3:
  7506. return id === 'var' || id === 'for' || id === 'new' || id === 'try';
  7507. case 4:
  7508. return id === 'this' || id === 'else' || id === 'case' || id === 'void' || id === 'with' || id === 'enum';
  7509. case 5:
  7510. return id === 'while' || id === 'break' || id === 'catch' || id === 'throw' || id === 'const' || id === 'yield' || id === 'class' || id === 'super';
  7511. case 6:
  7512. return id === 'return' || id === 'typeof' || id === 'delete' || id === 'switch' || id === 'export' || id === 'import';
  7513. case 7:
  7514. return id === 'default' || id === 'finally' || id === 'extends';
  7515. case 8:
  7516. return id === 'function' || id === 'continue' || id === 'debugger';
  7517. case 10:
  7518. return id === 'instanceof';
  7519. default:
  7520. return false;
  7521. }
  7522. }
  7523. function isReservedWordES5(id, strict) {
  7524. return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);
  7525. }
  7526. function isReservedWordES6(id, strict) {
  7527. return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);
  7528. }
  7529. function isRestrictedWord(id) {
  7530. return id === 'eval' || id === 'arguments';
  7531. }
  7532. function isIdentifierNameES5(id) {
  7533. var i, iz, ch;
  7534. if (id.length === 0) {
  7535. return false;
  7536. }
  7537. ch = id.charCodeAt(0);
  7538. if (!code$1.isIdentifierStartES5(ch)) {
  7539. return false;
  7540. }
  7541. for (i = 1, iz = id.length; i < iz; ++i) {
  7542. ch = id.charCodeAt(i);
  7543. if (!code$1.isIdentifierPartES5(ch)) {
  7544. return false;
  7545. }
  7546. }
  7547. return true;
  7548. }
  7549. function decodeUtf16(lead, trail) {
  7550. return (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  7551. }
  7552. function isIdentifierNameES6(id) {
  7553. var i, iz, ch, lowCh, check;
  7554. if (id.length === 0) {
  7555. return false;
  7556. }
  7557. check = code$1.isIdentifierStartES6;
  7558. for (i = 0, iz = id.length; i < iz; ++i) {
  7559. ch = id.charCodeAt(i);
  7560. if (0xD800 <= ch && ch <= 0xDBFF) {
  7561. ++i;
  7562. if (i >= iz) {
  7563. return false;
  7564. }
  7565. lowCh = id.charCodeAt(i);
  7566. if (!(0xDC00 <= lowCh && lowCh <= 0xDFFF)) {
  7567. return false;
  7568. }
  7569. ch = decodeUtf16(ch, lowCh);
  7570. }
  7571. if (!check(ch)) {
  7572. return false;
  7573. }
  7574. check = code$1.isIdentifierPartES6;
  7575. }
  7576. return true;
  7577. }
  7578. function isIdentifierES5(id, strict) {
  7579. return isIdentifierNameES5(id) && !isReservedWordES5(id, strict);
  7580. }
  7581. function isIdentifierES6(id, strict) {
  7582. return isIdentifierNameES6(id) && !isReservedWordES6(id, strict);
  7583. }
  7584. module.exports = {
  7585. isKeywordES5: isKeywordES5,
  7586. isKeywordES6: isKeywordES6,
  7587. isReservedWordES5: isReservedWordES5,
  7588. isReservedWordES6: isReservedWordES6,
  7589. isRestrictedWord: isRestrictedWord,
  7590. isIdentifierNameES5: isIdentifierNameES5,
  7591. isIdentifierNameES6: isIdentifierNameES6,
  7592. isIdentifierES5: isIdentifierES5,
  7593. isIdentifierES6: isIdentifierES6
  7594. };
  7595. })();
  7596. /* vim: set sw=4 ts=4 et tw=80 : */
  7597. });
  7598. var keyword_1 = keyword.isKeywordES5;
  7599. var keyword_2 = keyword.isKeywordES6;
  7600. var keyword_3 = keyword.isReservedWordES5;
  7601. var keyword_4 = keyword.isReservedWordES6;
  7602. var keyword_5 = keyword.isRestrictedWord;
  7603. var keyword_6 = keyword.isIdentifierNameES5;
  7604. var keyword_7 = keyword.isIdentifierNameES6;
  7605. var keyword_8 = keyword.isIdentifierES5;
  7606. var keyword_9 = keyword.isIdentifierES6;
  7607. var utils$1 = createCommonjsModule(function (module, exports) {
  7608. /*
  7609. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7610. Redistribution and use in source and binary forms, with or without
  7611. modification, are permitted provided that the following conditions are met:
  7612. * Redistributions of source code must retain the above copyright
  7613. notice, this list of conditions and the following disclaimer.
  7614. * Redistributions in binary form must reproduce the above copyright
  7615. notice, this list of conditions and the following disclaimer in the
  7616. documentation and/or other materials provided with the distribution.
  7617. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7618. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7619. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7620. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7621. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7622. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7623. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7624. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7625. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7626. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7627. */
  7628. (function () {
  7629. exports.ast = ast;
  7630. exports.code = code;
  7631. exports.keyword = keyword;
  7632. })();
  7633. /* vim: set sw=4 ts=4 et tw=80 : */
  7634. });
  7635. var utils_1$1 = utils$1.ast;
  7636. var utils_2$1 = utils$1.code;
  7637. var utils_3$1 = utils$1.keyword;
  7638. var lib$1 = createCommonjsModule(function (module, exports) {
  7639. Object.defineProperty(exports, "__esModule", {
  7640. value: true
  7641. });
  7642. exports.shouldHighlight = shouldHighlight;
  7643. exports.getChalk = getChalk;
  7644. exports.default = highlight;
  7645. function _jsTokens() {
  7646. var data = _interopRequireWildcard(jsTokens);
  7647. _jsTokens = function _jsTokens() {
  7648. return data;
  7649. };
  7650. return data;
  7651. }
  7652. function _esutils() {
  7653. var data = _interopRequireDefault(utils$1);
  7654. _esutils = function _esutils() {
  7655. return data;
  7656. };
  7657. return data;
  7658. }
  7659. function _chalk() {
  7660. var data = _interopRequireDefault(chalk);
  7661. _chalk = function _chalk() {
  7662. return data;
  7663. };
  7664. return data;
  7665. }
  7666. function _interopRequireDefault(obj) {
  7667. return obj && obj.__esModule ? obj : {
  7668. default: obj
  7669. };
  7670. }
  7671. function _interopRequireWildcard(obj) {
  7672. if (obj && obj.__esModule) {
  7673. return obj;
  7674. } else {
  7675. var newObj = {};
  7676. if (obj != null) {
  7677. for (var key in obj) {
  7678. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  7679. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
  7680. if (desc.get || desc.set) {
  7681. Object.defineProperty(newObj, key, desc);
  7682. } else {
  7683. newObj[key] = obj[key];
  7684. }
  7685. }
  7686. }
  7687. }
  7688. newObj.default = obj;
  7689. return newObj;
  7690. }
  7691. }
  7692. function getDefs(chalk) {
  7693. return {
  7694. keyword: chalk.cyan,
  7695. capitalized: chalk.yellow,
  7696. jsx_tag: chalk.yellow,
  7697. punctuator: chalk.yellow,
  7698. number: chalk.magenta,
  7699. string: chalk.green,
  7700. regex: chalk.magenta,
  7701. comment: chalk.grey,
  7702. invalid: chalk.white.bgRed.bold
  7703. };
  7704. }
  7705. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  7706. var JSX_TAG = /^[a-z][\w-]*$/i;
  7707. var BRACKET = /^[()[\]{}]$/;
  7708. function getTokenType(match) {
  7709. var _match$slice = match.slice(-2),
  7710. _match$slice2 = _slicedToArray(_match$slice, 2),
  7711. offset = _match$slice2[0],
  7712. text = _match$slice2[1];
  7713. var token = (0, _jsTokens().matchToToken)(match);
  7714. if (token.type === "name") {
  7715. if (_esutils().default.keyword.isReservedWordES6(token.value)) {
  7716. return "keyword";
  7717. }
  7718. if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
  7719. return "jsx_tag";
  7720. }
  7721. if (token.value[0] !== token.value[0].toLowerCase()) {
  7722. return "capitalized";
  7723. }
  7724. }
  7725. if (token.type === "punctuator" && BRACKET.test(token.value)) {
  7726. return "bracket";
  7727. }
  7728. if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
  7729. return "punctuator";
  7730. }
  7731. return token.type;
  7732. }
  7733. function highlightTokens(defs, text) {
  7734. return text.replace(_jsTokens().default, function () {
  7735. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  7736. args[_key] = arguments[_key];
  7737. }
  7738. var type = getTokenType(args);
  7739. var colorize = defs[type];
  7740. if (colorize) {
  7741. return args[0].split(NEWLINE).map(function (str) {
  7742. return colorize(str);
  7743. }).join("\n");
  7744. } else {
  7745. return args[0];
  7746. }
  7747. });
  7748. }
  7749. function shouldHighlight(options) {
  7750. return _chalk().default.supportsColor || options.forceColor;
  7751. }
  7752. function getChalk(options) {
  7753. var chalk = _chalk().default;
  7754. if (options.forceColor) {
  7755. chalk = new (_chalk().default.constructor)({
  7756. enabled: true,
  7757. level: 1
  7758. });
  7759. }
  7760. return chalk;
  7761. }
  7762. function highlight(code) {
  7763. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  7764. if (shouldHighlight(options)) {
  7765. var chalk = getChalk(options);
  7766. var defs = getDefs(chalk);
  7767. return highlightTokens(defs, code);
  7768. } else {
  7769. return code;
  7770. }
  7771. }
  7772. });
  7773. unwrapExports(lib$1);
  7774. var lib_1 = lib$1.shouldHighlight;
  7775. var lib_2 = lib$1.getChalk;
  7776. var lib$2 = createCommonjsModule(function (module, exports) {
  7777. Object.defineProperty(exports, "__esModule", {
  7778. value: true
  7779. });
  7780. exports.codeFrameColumns = codeFrameColumns;
  7781. exports.default = _default;
  7782. function _highlight() {
  7783. var data = _interopRequireWildcard(lib$1);
  7784. _highlight = function _highlight() {
  7785. return data;
  7786. };
  7787. return data;
  7788. }
  7789. function _interopRequireWildcard(obj) {
  7790. if (obj && obj.__esModule) {
  7791. return obj;
  7792. } else {
  7793. var newObj = {};
  7794. if (obj != null) {
  7795. for (var key in obj) {
  7796. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  7797. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
  7798. if (desc.get || desc.set) {
  7799. Object.defineProperty(newObj, key, desc);
  7800. } else {
  7801. newObj[key] = obj[key];
  7802. }
  7803. }
  7804. }
  7805. }
  7806. newObj.default = obj;
  7807. return newObj;
  7808. }
  7809. }
  7810. var deprecationWarningShown = false;
  7811. function getDefs(chalk) {
  7812. return {
  7813. gutter: chalk.grey,
  7814. marker: chalk.red.bold,
  7815. message: chalk.red.bold
  7816. };
  7817. }
  7818. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  7819. function getMarkerLines(loc, source, opts) {
  7820. var startLoc = Object.assign({
  7821. column: 0,
  7822. line: -1
  7823. }, loc.start);
  7824. var endLoc = Object.assign({}, startLoc, loc.end);
  7825. var _ref = opts || {},
  7826. _ref$linesAbove = _ref.linesAbove,
  7827. linesAbove = _ref$linesAbove === void 0 ? 2 : _ref$linesAbove,
  7828. _ref$linesBelow = _ref.linesBelow,
  7829. linesBelow = _ref$linesBelow === void 0 ? 3 : _ref$linesBelow;
  7830. var startLine = startLoc.line;
  7831. var startColumn = startLoc.column;
  7832. var endLine = endLoc.line;
  7833. var endColumn = endLoc.column;
  7834. var start = Math.max(startLine - (linesAbove + 1), 0);
  7835. var end = Math.min(source.length, endLine + linesBelow);
  7836. if (startLine === -1) {
  7837. start = 0;
  7838. }
  7839. if (endLine === -1) {
  7840. end = source.length;
  7841. }
  7842. var lineDiff = endLine - startLine;
  7843. var markerLines = {};
  7844. if (lineDiff) {
  7845. for (var i = 0; i <= lineDiff; i++) {
  7846. var lineNumber = i + startLine;
  7847. if (!startColumn) {
  7848. markerLines[lineNumber] = true;
  7849. } else if (i === 0) {
  7850. var sourceLength = source[lineNumber - 1].length;
  7851. markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
  7852. } else if (i === lineDiff) {
  7853. markerLines[lineNumber] = [0, endColumn];
  7854. } else {
  7855. var _sourceLength = source[lineNumber - i].length;
  7856. markerLines[lineNumber] = [0, _sourceLength];
  7857. }
  7858. }
  7859. } else {
  7860. if (startColumn === endColumn) {
  7861. if (startColumn) {
  7862. markerLines[startLine] = [startColumn, 0];
  7863. } else {
  7864. markerLines[startLine] = true;
  7865. }
  7866. } else {
  7867. markerLines[startLine] = [startColumn, endColumn - startColumn];
  7868. }
  7869. }
  7870. return {
  7871. start,
  7872. end,
  7873. markerLines
  7874. };
  7875. }
  7876. function codeFrameColumns(rawLines, loc) {
  7877. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  7878. var highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight().shouldHighlight)(opts);
  7879. var chalk = (0, _highlight().getChalk)(opts);
  7880. var defs = getDefs(chalk);
  7881. var maybeHighlight = function maybeHighlight(chalkFn, string) {
  7882. return highlighted ? chalkFn(string) : string;
  7883. };
  7884. var lines = rawLines.split(NEWLINE);
  7885. var _getMarkerLines = getMarkerLines(loc, lines, opts),
  7886. start = _getMarkerLines.start,
  7887. end = _getMarkerLines.end,
  7888. markerLines = _getMarkerLines.markerLines;
  7889. var hasColumns = loc.start && typeof loc.start.column === "number";
  7890. var numberMaxWidth = String(end).length;
  7891. var highlightedLines = highlighted ? (0, _highlight().default)(rawLines, opts) : rawLines;
  7892. var frame = highlightedLines.split(NEWLINE).slice(start, end).map(function (line, index) {
  7893. var number = start + 1 + index;
  7894. var paddedNumber = ` ${number}`.slice(-numberMaxWidth);
  7895. var gutter = ` ${paddedNumber} | `;
  7896. var hasMarker = markerLines[number];
  7897. var lastMarkerLine = !markerLines[number + 1];
  7898. if (hasMarker) {
  7899. var markerLine = "";
  7900. if (Array.isArray(hasMarker)) {
  7901. var markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  7902. var numberOfMarkers = hasMarker[1] || 1;
  7903. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  7904. if (lastMarkerLine && opts.message) {
  7905. markerLine += " " + maybeHighlight(defs.message, opts.message);
  7906. }
  7907. }
  7908. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
  7909. } else {
  7910. return ` ${maybeHighlight(defs.gutter, gutter)}${line}`;
  7911. }
  7912. }).join("\n");
  7913. if (opts.message && !hasColumns) {
  7914. frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
  7915. }
  7916. if (highlighted) {
  7917. return chalk.reset(frame);
  7918. } else {
  7919. return frame;
  7920. }
  7921. }
  7922. function _default(rawLines, lineNumber, colNumber) {
  7923. var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  7924. if (!deprecationWarningShown) {
  7925. deprecationWarningShown = true;
  7926. var message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
  7927. if (process.emitWarning) {
  7928. process.emitWarning(message, "DeprecationWarning");
  7929. } else {
  7930. var deprecationError = new Error(message);
  7931. deprecationError.name = "DeprecationWarning";
  7932. console.warn(new Error(message));
  7933. }
  7934. }
  7935. colNumber = Math.max(colNumber, 0);
  7936. var location = {
  7937. start: {
  7938. column: colNumber,
  7939. line: lineNumber
  7940. }
  7941. };
  7942. return codeFrameColumns(rawLines, location, opts);
  7943. }
  7944. });
  7945. unwrapExports(lib$2);
  7946. var lib_1$1 = lib$2.codeFrameColumns;
  7947. var ConfigError$1 = errors.ConfigError;
  7948. var locStart$1 = loc.locStart,
  7949. locEnd$1 = loc.locEnd; // Use defineProperties()/getOwnPropertyDescriptor() to prevent
  7950. // triggering the parsers getters.
  7951. var ownNames = Object.getOwnPropertyNames;
  7952. var ownDescriptor = Object.getOwnPropertyDescriptor;
  7953. function getParsers(options) {
  7954. var parsers = {};
  7955. var _iteratorNormalCompletion = true;
  7956. var _didIteratorError = false;
  7957. var _iteratorError = undefined;
  7958. try {
  7959. for (var _iterator = options.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7960. var plugin = _step.value;
  7961. if (!plugin.parsers) {
  7962. continue;
  7963. }
  7964. var _iteratorNormalCompletion2 = true;
  7965. var _didIteratorError2 = false;
  7966. var _iteratorError2 = undefined;
  7967. try {
  7968. for (var _iterator2 = ownNames(plugin.parsers)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  7969. var name = _step2.value;
  7970. Object.defineProperty(parsers, name, ownDescriptor(plugin.parsers, name));
  7971. }
  7972. } catch (err) {
  7973. _didIteratorError2 = true;
  7974. _iteratorError2 = err;
  7975. } finally {
  7976. try {
  7977. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  7978. _iterator2.return();
  7979. }
  7980. } finally {
  7981. if (_didIteratorError2) {
  7982. throw _iteratorError2;
  7983. }
  7984. }
  7985. }
  7986. }
  7987. } catch (err) {
  7988. _didIteratorError = true;
  7989. _iteratorError = err;
  7990. } finally {
  7991. try {
  7992. if (!_iteratorNormalCompletion && _iterator.return != null) {
  7993. _iterator.return();
  7994. }
  7995. } finally {
  7996. if (_didIteratorError) {
  7997. throw _iteratorError;
  7998. }
  7999. }
  8000. }
  8001. return parsers;
  8002. }
  8003. function resolveParser(opts, parsers) {
  8004. parsers = parsers || getParsers(opts);
  8005. if (typeof opts.parser === "function") {
  8006. // Custom parser API always works with JavaScript.
  8007. return {
  8008. parse: opts.parser,
  8009. astFormat: "estree",
  8010. locStart: locStart$1,
  8011. locEnd: locEnd$1
  8012. };
  8013. }
  8014. if (typeof opts.parser === "string") {
  8015. if (Object.prototype.hasOwnProperty.call(parsers, opts.parser)) {
  8016. return parsers[opts.parser];
  8017. }
  8018. /* istanbul ignore next */
  8019. {
  8020. try {
  8021. return {
  8022. parse: require(path$2.resolve(process.cwd(), opts.parser)),
  8023. astFormat: "estree",
  8024. locStart: locStart$1,
  8025. locEnd: locEnd$1
  8026. };
  8027. } catch (err) {
  8028. /* istanbul ignore next */
  8029. throw new ConfigError$1(`Couldn't resolve parser "${opts.parser}"`);
  8030. }
  8031. }
  8032. }
  8033. }
  8034. function parse(text, opts) {
  8035. var parsers = getParsers(opts); // Create a new object {parserName: parseFn}. Uses defineProperty() to only call
  8036. // the parsers getters when actually calling the parser `parse` function.
  8037. var parsersForCustomParserApi = Object.keys(parsers).reduce(function (object, parserName) {
  8038. return Object.defineProperty(object, parserName, {
  8039. enumerable: true,
  8040. get() {
  8041. return parsers[parserName].parse;
  8042. }
  8043. });
  8044. }, {});
  8045. var parser = resolveParser(opts, parsers);
  8046. try {
  8047. if (parser.preprocess) {
  8048. text = parser.preprocess(text, opts);
  8049. }
  8050. return {
  8051. text,
  8052. ast: parser.parse(text, parsersForCustomParserApi, opts)
  8053. };
  8054. } catch (error) {
  8055. var loc = error.loc;
  8056. if (loc) {
  8057. var codeFrame = lib$2;
  8058. error.codeFrame = codeFrame.codeFrameColumns(text, loc, {
  8059. highlightCode: true
  8060. });
  8061. error.message += "\n" + error.codeFrame;
  8062. throw error;
  8063. }
  8064. /* istanbul ignore next */
  8065. throw error.stack;
  8066. }
  8067. }
  8068. var parser = {
  8069. parse,
  8070. resolveParser
  8071. };
  8072. var UndefinedParserError$1 = errors.UndefinedParserError;
  8073. var getSupportInfo$1 = support.getSupportInfo;
  8074. var resolveParser$1 = parser.resolveParser;
  8075. var hiddenDefaults = {
  8076. astFormat: "estree",
  8077. printer: {},
  8078. originalText: undefined,
  8079. locStart: null,
  8080. locEnd: null
  8081. }; // Copy options and fill in default values.
  8082. function normalize$1(options, opts) {
  8083. opts = opts || {};
  8084. var rawOptions = Object.assign({}, options);
  8085. var supportOptions = getSupportInfo$1(null, {
  8086. plugins: options.plugins,
  8087. showUnreleased: true,
  8088. showDeprecated: true
  8089. }).options;
  8090. var defaults = supportOptions.reduce(function (reduced, optionInfo) {
  8091. return optionInfo.default !== undefined ? Object.assign(reduced, {
  8092. [optionInfo.name]: optionInfo.default
  8093. }) : reduced;
  8094. }, Object.assign({}, hiddenDefaults));
  8095. if (!rawOptions.parser) {
  8096. if (!rawOptions.filepath) {
  8097. var logger = opts.logger || console;
  8098. 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.");
  8099. rawOptions.parser = "babel";
  8100. } else {
  8101. rawOptions.parser = inferParser(rawOptions.filepath, rawOptions.plugins);
  8102. if (!rawOptions.parser) {
  8103. throw new UndefinedParserError$1(`No parser could be inferred for file: ${rawOptions.filepath}`);
  8104. }
  8105. }
  8106. }
  8107. var parser = resolveParser$1(optionsNormalizer.normalizeApiOptions(rawOptions, [supportOptions.find(function (x) {
  8108. return x.name === "parser";
  8109. })], {
  8110. passThrough: true,
  8111. logger: false
  8112. }));
  8113. rawOptions.astFormat = parser.astFormat;
  8114. rawOptions.locEnd = parser.locEnd;
  8115. rawOptions.locStart = parser.locStart;
  8116. var plugin = getPlugin(rawOptions);
  8117. rawOptions.printer = plugin.printers[rawOptions.astFormat];
  8118. var pluginDefaults = supportOptions.filter(function (optionInfo) {
  8119. return optionInfo.pluginDefaults && optionInfo.pluginDefaults[plugin.name] !== undefined;
  8120. }).reduce(function (reduced, optionInfo) {
  8121. return Object.assign(reduced, {
  8122. [optionInfo.name]: optionInfo.pluginDefaults[plugin.name]
  8123. });
  8124. }, {});
  8125. var mixedDefaults = Object.assign({}, defaults, pluginDefaults);
  8126. Object.keys(mixedDefaults).forEach(function (k) {
  8127. if (rawOptions[k] == null) {
  8128. rawOptions[k] = mixedDefaults[k];
  8129. }
  8130. });
  8131. if (rawOptions.parser === "json") {
  8132. rawOptions.trailingComma = "none";
  8133. }
  8134. return optionsNormalizer.normalizeApiOptions(rawOptions, supportOptions, Object.assign({
  8135. passThrough: Object.keys(hiddenDefaults)
  8136. }, opts));
  8137. }
  8138. function getPlugin(options) {
  8139. var astFormat = options.astFormat;
  8140. if (!astFormat) {
  8141. throw new Error("getPlugin() requires astFormat to be set");
  8142. }
  8143. var printerPlugin = options.plugins.find(function (plugin) {
  8144. return plugin.printers && plugin.printers[astFormat];
  8145. });
  8146. if (!printerPlugin) {
  8147. throw new Error(`Couldn't find plugin for AST format "${astFormat}"`);
  8148. }
  8149. return printerPlugin;
  8150. }
  8151. function getInterpreter(filepath) {
  8152. if (typeof filepath !== "string") {
  8153. return "";
  8154. }
  8155. var fd;
  8156. try {
  8157. fd = fs$1.openSync(filepath, "r");
  8158. } catch (err) {
  8159. return "";
  8160. }
  8161. try {
  8162. var liner = new readlines(fd);
  8163. var firstLine = liner.next().toString("utf8"); // #!/bin/env node, #!/usr/bin/env node
  8164. var m1 = firstLine.match(/^#!\/(?:usr\/)?bin\/env\s+(\S+)/);
  8165. if (m1) {
  8166. return m1[1];
  8167. } // #!/bin/node, #!/usr/bin/node, #!/usr/local/bin/node
  8168. var m2 = firstLine.match(/^#!\/(?:usr\/(?:local\/)?)?bin\/(\S+)/);
  8169. if (m2) {
  8170. return m2[1];
  8171. }
  8172. return "";
  8173. } catch (err) {
  8174. // There are some weird cases where paths are missing, causing Jest
  8175. // failures. It's unclear what these correspond to in the real world.
  8176. return "";
  8177. } finally {
  8178. try {
  8179. // There are some weird cases where paths are missing, causing Jest
  8180. // failures. It's unclear what these correspond to in the real world.
  8181. fs$1.closeSync(fd);
  8182. } catch (err) {// nop
  8183. }
  8184. }
  8185. }
  8186. function inferParser(filepath, plugins) {
  8187. var filepathParts = normalizePath(filepath).split("/");
  8188. var filename = filepathParts[filepathParts.length - 1].toLowerCase(); // If the file has no extension, we can try to infer the language from the
  8189. // interpreter in the shebang line, if any; but since this requires FS access,
  8190. // do it last.
  8191. var language = getSupportInfo$1(null, {
  8192. plugins
  8193. }).languages.find(function (language) {
  8194. return language.since !== null && (language.extensions && language.extensions.some(function (extension) {
  8195. return filename.endsWith(extension);
  8196. }) || language.filenames && language.filenames.find(function (name) {
  8197. return name.toLowerCase() === filename;
  8198. }) || filename.indexOf(".") === -1 && language.interpreters && language.interpreters.indexOf(getInterpreter(filepath)) !== -1);
  8199. });
  8200. return language && language.parsers[0];
  8201. }
  8202. var options$1 = {
  8203. normalize: normalize$1,
  8204. hiddenDefaults,
  8205. inferParser
  8206. };
  8207. function massageAST(ast, options, parent) {
  8208. if (Array.isArray(ast)) {
  8209. return ast.map(function (e) {
  8210. return massageAST(e, options, parent);
  8211. }).filter(function (e) {
  8212. return e;
  8213. });
  8214. }
  8215. if (!ast || typeof ast !== "object") {
  8216. return ast;
  8217. }
  8218. var newObj = {};
  8219. for (var _i = 0, _Object$keys = Object.keys(ast); _i < _Object$keys.length; _i++) {
  8220. var key = _Object$keys[_i];
  8221. if (typeof ast[key] !== "function") {
  8222. newObj[key] = massageAST(ast[key], options, ast);
  8223. }
  8224. }
  8225. if (options.printer.massageAstNode) {
  8226. var result = options.printer.massageAstNode(ast, newObj, parent);
  8227. if (result === null) {
  8228. return undefined;
  8229. }
  8230. if (result) {
  8231. return result;
  8232. }
  8233. }
  8234. return newObj;
  8235. }
  8236. var massageAst = massageAST;
  8237. /**
  8238. * @param {Doc[]} parts
  8239. * @returns Doc
  8240. */
  8241. function concat(parts) {
  8242. // access the internals of a document directly.
  8243. // if(parts.length === 1) {
  8244. // // If it's a single document, no need to concat it.
  8245. // return parts[0];
  8246. // }
  8247. return {
  8248. type: "concat",
  8249. parts
  8250. };
  8251. }
  8252. /**
  8253. * @param {Doc} contents
  8254. * @returns Doc
  8255. */
  8256. function indent(contents) {
  8257. return {
  8258. type: "indent",
  8259. contents
  8260. };
  8261. }
  8262. /**
  8263. * @param {number} n
  8264. * @param {Doc} contents
  8265. * @returns Doc
  8266. */
  8267. function align(n, contents) {
  8268. return {
  8269. type: "align",
  8270. contents,
  8271. n
  8272. };
  8273. }
  8274. /**
  8275. * @param {Doc} contents
  8276. * @param {object} [opts] - TBD ???
  8277. * @returns Doc
  8278. */
  8279. function group(contents, opts) {
  8280. opts = opts || {};
  8281. return {
  8282. type: "group",
  8283. id: opts.id,
  8284. contents: contents,
  8285. break: !!opts.shouldBreak,
  8286. expandedStates: opts.expandedStates
  8287. };
  8288. }
  8289. /**
  8290. * @param {Doc} contents
  8291. * @returns Doc
  8292. */
  8293. function dedentToRoot(contents) {
  8294. return align(-Infinity, contents);
  8295. }
  8296. /**
  8297. * @param {Doc} contents
  8298. * @returns Doc
  8299. */
  8300. function markAsRoot(contents) {
  8301. // @ts-ignore - TBD ???:
  8302. return align({
  8303. type: "root"
  8304. }, contents);
  8305. }
  8306. /**
  8307. * @param {Doc} contents
  8308. * @returns Doc
  8309. */
  8310. function dedent(contents) {
  8311. return align(-1, contents);
  8312. }
  8313. /**
  8314. * @param {Doc[]} states
  8315. * @param {object} [opts] - TBD ???
  8316. * @returns Doc
  8317. */
  8318. function conditionalGroup(states, opts) {
  8319. return group(states[0], Object.assign(opts || {}, {
  8320. expandedStates: states
  8321. }));
  8322. }
  8323. /**
  8324. * @param {Doc[]} parts
  8325. * @returns Doc
  8326. */
  8327. function fill(parts) {
  8328. return {
  8329. type: "fill",
  8330. parts
  8331. };
  8332. }
  8333. /**
  8334. * @param {Doc} [breakContents]
  8335. * @param {Doc} [flatContents]
  8336. * @param {object} [opts] - TBD ???
  8337. * @returns Doc
  8338. */
  8339. function ifBreak(breakContents, flatContents, opts) {
  8340. opts = opts || {};
  8341. return {
  8342. type: "if-break",
  8343. breakContents,
  8344. flatContents,
  8345. groupId: opts.groupId
  8346. };
  8347. }
  8348. /**
  8349. * @param {Doc} contents
  8350. * @returns Doc
  8351. */
  8352. function lineSuffix(contents) {
  8353. return {
  8354. type: "line-suffix",
  8355. contents
  8356. };
  8357. }
  8358. var lineSuffixBoundary = {
  8359. type: "line-suffix-boundary"
  8360. };
  8361. var breakParent = {
  8362. type: "break-parent"
  8363. };
  8364. var trim = {
  8365. type: "trim"
  8366. };
  8367. var line = {
  8368. type: "line"
  8369. };
  8370. var softline = {
  8371. type: "line",
  8372. soft: true
  8373. };
  8374. var hardline = concat([{
  8375. type: "line",
  8376. hard: true
  8377. }, breakParent]);
  8378. var literalline = concat([{
  8379. type: "line",
  8380. hard: true,
  8381. literal: true
  8382. }, breakParent]);
  8383. var cursor = {
  8384. type: "cursor",
  8385. placeholder: Symbol("cursor")
  8386. };
  8387. /**
  8388. * @param {Doc} sep
  8389. * @param {Doc[]} arr
  8390. * @returns Doc
  8391. */
  8392. function join(sep, arr) {
  8393. var res = [];
  8394. for (var i = 0; i < arr.length; i++) {
  8395. if (i !== 0) {
  8396. res.push(sep);
  8397. }
  8398. res.push(arr[i]);
  8399. }
  8400. return concat(res);
  8401. }
  8402. /**
  8403. * @param {Doc} doc
  8404. * @param {number} size
  8405. * @param {number} tabWidth
  8406. */
  8407. function addAlignmentToDoc(doc, size, tabWidth) {
  8408. var aligned = doc;
  8409. if (size > 0) {
  8410. // Use indent to add tabs for all the levels of tabs we need
  8411. for (var i = 0; i < Math.floor(size / tabWidth); ++i) {
  8412. aligned = indent(aligned);
  8413. } // Use align for all the spaces that are needed
  8414. aligned = align(size % tabWidth, aligned); // size is absolute from 0 and not relative to the current
  8415. // indentation, so we use -Infinity to reset the indentation to 0
  8416. aligned = align(-Infinity, aligned);
  8417. }
  8418. return aligned;
  8419. }
  8420. var docBuilders = {
  8421. concat,
  8422. join,
  8423. line,
  8424. softline,
  8425. hardline,
  8426. literalline,
  8427. group,
  8428. conditionalGroup,
  8429. fill,
  8430. lineSuffix,
  8431. lineSuffixBoundary,
  8432. cursor,
  8433. breakParent,
  8434. ifBreak,
  8435. trim,
  8436. indent,
  8437. align,
  8438. addAlignmentToDoc,
  8439. markAsRoot,
  8440. dedentToRoot,
  8441. dedent
  8442. };
  8443. var ansiRegex = function ansiRegex(options) {
  8444. options = Object.assign({
  8445. onlyFirst: false
  8446. }, options);
  8447. var pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|');
  8448. return new RegExp(pattern, options.onlyFirst ? undefined : 'g');
  8449. };
  8450. var stripAnsi = function stripAnsi(string) {
  8451. return typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
  8452. };
  8453. var stripAnsi_1 = stripAnsi;
  8454. var default_1$1 = stripAnsi;
  8455. stripAnsi_1.default = default_1$1;
  8456. /* eslint-disable yoda */
  8457. var isFullwidthCodePoint = function isFullwidthCodePoint(codePoint) {
  8458. if (Number.isNaN(codePoint)) {
  8459. return false;
  8460. } // Code points are derived from:
  8461. // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
  8462. if (codePoint >= 0x1100 && (codePoint <= 0x115F || // Hangul Jamo
  8463. codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  8464. codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
  8465. // CJK Radicals Supplement .. Enclosed CJK Letters and Months
  8466. 0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
  8467. 0x3250 <= codePoint && codePoint <= 0x4DBF || // CJK Unified Ideographs .. Yi Radicals
  8468. 0x4E00 <= codePoint && codePoint <= 0xA4C6 || // Hangul Jamo Extended-A
  8469. 0xA960 <= codePoint && codePoint <= 0xA97C || // Hangul Syllables
  8470. 0xAC00 <= codePoint && codePoint <= 0xD7A3 || // CJK Compatibility Ideographs
  8471. 0xF900 <= codePoint && codePoint <= 0xFAFF || // Vertical Forms
  8472. 0xFE10 <= codePoint && codePoint <= 0xFE19 || // CJK Compatibility Forms .. Small Form Variants
  8473. 0xFE30 <= codePoint && codePoint <= 0xFE6B || // Halfwidth and Fullwidth Forms
  8474. 0xFF01 <= codePoint && codePoint <= 0xFF60 || 0xFFE0 <= codePoint && codePoint <= 0xFFE6 || // Kana Supplement
  8475. 0x1B000 <= codePoint && codePoint <= 0x1B001 || // Enclosed Ideographic Supplement
  8476. 0x1F200 <= codePoint && codePoint <= 0x1F251 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
  8477. 0x20000 <= codePoint && codePoint <= 0x3FFFD)) {
  8478. return true;
  8479. }
  8480. return false;
  8481. };
  8482. var isFullwidthCodePoint_1 = isFullwidthCodePoint;
  8483. var default_1$2 = isFullwidthCodePoint;
  8484. isFullwidthCodePoint_1.default = default_1$2;
  8485. var emojiRegex = function emojiRegex() {
  8486. // https://mths.be/emoji
  8487. 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;
  8488. };
  8489. var stringWidth = function stringWidth(string) {
  8490. string = string.replace(emojiRegex(), ' ');
  8491. if (typeof string !== 'string' || string.length === 0) {
  8492. return 0;
  8493. }
  8494. string = stripAnsi_1(string);
  8495. var width = 0;
  8496. for (var i = 0; i < string.length; i++) {
  8497. var code = string.codePointAt(i); // Ignore control characters
  8498. if (code <= 0x1F || code >= 0x7F && code <= 0x9F) {
  8499. continue;
  8500. } // Ignore combining characters
  8501. if (code >= 0x300 && code <= 0x36F) {
  8502. continue;
  8503. } // Surrogates
  8504. if (code > 0xFFFF) {
  8505. i++;
  8506. }
  8507. width += isFullwidthCodePoint_1(code) ? 2 : 1;
  8508. }
  8509. return width;
  8510. };
  8511. var stringWidth_1 = stringWidth; // TODO: remove this in the next major version
  8512. var default_1$3 = stringWidth;
  8513. stringWidth_1.default = default_1$3;
  8514. var notAsciiRegex = /[^\x20-\x7F]/;
  8515. function isExportDeclaration(node) {
  8516. if (node) {
  8517. switch (node.type) {
  8518. case "ExportDefaultDeclaration":
  8519. case "ExportDefaultSpecifier":
  8520. case "DeclareExportDeclaration":
  8521. case "ExportNamedDeclaration":
  8522. case "ExportAllDeclaration":
  8523. return true;
  8524. }
  8525. }
  8526. return false;
  8527. }
  8528. function getParentExportDeclaration(path) {
  8529. var parentNode = path.getParentNode();
  8530. if (path.getName() === "declaration" && isExportDeclaration(parentNode)) {
  8531. return parentNode;
  8532. }
  8533. return null;
  8534. }
  8535. function getPenultimate(arr) {
  8536. if (arr.length > 1) {
  8537. return arr[arr.length - 2];
  8538. }
  8539. return null;
  8540. }
  8541. /**
  8542. * @typedef {{backwards?: boolean}} SkipOptions
  8543. */
  8544. /**
  8545. * @param {string | RegExp} chars
  8546. * @returns {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  8547. */
  8548. function skip(chars) {
  8549. return function (text, index, opts) {
  8550. var backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
  8551. // to check for failures (did someone say monads?).
  8552. if (index === false) {
  8553. return false;
  8554. }
  8555. var length = text.length;
  8556. var cursor = index;
  8557. while (cursor >= 0 && cursor < length) {
  8558. var c = text.charAt(cursor);
  8559. if (chars instanceof RegExp) {
  8560. if (!chars.test(c)) {
  8561. return cursor;
  8562. }
  8563. } else if (chars.indexOf(c) === -1) {
  8564. return cursor;
  8565. }
  8566. backwards ? cursor-- : cursor++;
  8567. }
  8568. if (cursor === -1 || cursor === length) {
  8569. // If we reached the beginning or end of the file, return the
  8570. // out-of-bounds cursor. It's up to the caller to handle this
  8571. // correctly. We don't want to indicate `false` though if it
  8572. // actually skipped valid characters.
  8573. return cursor;
  8574. }
  8575. return false;
  8576. };
  8577. }
  8578. /**
  8579. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  8580. */
  8581. var skipWhitespace = skip(/\s/);
  8582. /**
  8583. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  8584. */
  8585. var skipSpaces = skip(" \t");
  8586. /**
  8587. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  8588. */
  8589. var skipToLineEnd = skip(",; \t");
  8590. /**
  8591. * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
  8592. */
  8593. var skipEverythingButNewLine = skip(/[^\r\n]/);
  8594. /**
  8595. * @param {string} text
  8596. * @param {number | false} index
  8597. * @returns {number | false}
  8598. */
  8599. function skipInlineComment(text, index) {
  8600. if (index === false) {
  8601. return false;
  8602. }
  8603. if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
  8604. for (var i = index + 2; i < text.length; ++i) {
  8605. if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
  8606. return i + 2;
  8607. }
  8608. }
  8609. }
  8610. return index;
  8611. }
  8612. /**
  8613. * @param {string} text
  8614. * @param {number | false} index
  8615. * @returns {number | false}
  8616. */
  8617. function skipTrailingComment(text, index) {
  8618. if (index === false) {
  8619. return false;
  8620. }
  8621. if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
  8622. return skipEverythingButNewLine(text, index);
  8623. }
  8624. return index;
  8625. } // This one doesn't use the above helper function because it wants to
  8626. // test \r\n in order and `skip` doesn't support ordering and we only
  8627. // want to skip one newline. It's simple to implement.
  8628. /**
  8629. * @param {string} text
  8630. * @param {number | false} index
  8631. * @param {SkipOptions=} opts
  8632. * @returns {number | false}
  8633. */
  8634. function skipNewline(text, index, opts) {
  8635. var backwards = opts && opts.backwards;
  8636. if (index === false) {
  8637. return false;
  8638. }
  8639. var atIndex = text.charAt(index);
  8640. if (backwards) {
  8641. if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
  8642. return index - 2;
  8643. }
  8644. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  8645. return index - 1;
  8646. }
  8647. } else {
  8648. if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
  8649. return index + 2;
  8650. }
  8651. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  8652. return index + 1;
  8653. }
  8654. }
  8655. return index;
  8656. }
  8657. /**
  8658. * @param {string} text
  8659. * @param {number} index
  8660. * @param {SkipOptions=} opts
  8661. * @returns {boolean}
  8662. */
  8663. function hasNewline(text, index, opts) {
  8664. opts = opts || {};
  8665. var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  8666. var idx2 = skipNewline(text, idx, opts);
  8667. return idx !== idx2;
  8668. }
  8669. /**
  8670. * @param {string} text
  8671. * @param {number} start
  8672. * @param {number} end
  8673. * @returns {boolean}
  8674. */
  8675. function hasNewlineInRange(text, start, end) {
  8676. for (var i = start; i < end; ++i) {
  8677. if (text.charAt(i) === "\n") {
  8678. return true;
  8679. }
  8680. }
  8681. return false;
  8682. } // Note: this function doesn't ignore leading comments unlike isNextLineEmpty
  8683. /**
  8684. * @template N
  8685. * @param {string} text
  8686. * @param {N} node
  8687. * @param {(node: N) => number} locStart
  8688. */
  8689. function isPreviousLineEmpty(text, node, locStart) {
  8690. /** @type {number | false} */
  8691. var idx = locStart(node) - 1;
  8692. idx = skipSpaces(text, idx, {
  8693. backwards: true
  8694. });
  8695. idx = skipNewline(text, idx, {
  8696. backwards: true
  8697. });
  8698. idx = skipSpaces(text, idx, {
  8699. backwards: true
  8700. });
  8701. var idx2 = skipNewline(text, idx, {
  8702. backwards: true
  8703. });
  8704. return idx !== idx2;
  8705. }
  8706. /**
  8707. * @param {string} text
  8708. * @param {number} index
  8709. * @returns {boolean}
  8710. */
  8711. function isNextLineEmptyAfterIndex(text, index) {
  8712. /** @type {number | false} */
  8713. var oldIdx = null;
  8714. /** @type {number | false} */
  8715. var idx = index;
  8716. while (idx !== oldIdx) {
  8717. // We need to skip all the potential trailing inline comments
  8718. oldIdx = idx;
  8719. idx = skipToLineEnd(text, idx);
  8720. idx = skipInlineComment(text, idx);
  8721. idx = skipSpaces(text, idx);
  8722. }
  8723. idx = skipTrailingComment(text, idx);
  8724. idx = skipNewline(text, idx);
  8725. return idx !== false && hasNewline(text, idx);
  8726. }
  8727. /**
  8728. * @template N
  8729. * @param {string} text
  8730. * @param {N} node
  8731. * @param {(node: N) => number} locEnd
  8732. * @returns {boolean}
  8733. */
  8734. function isNextLineEmpty(text, node, locEnd) {
  8735. return isNextLineEmptyAfterIndex(text, locEnd(node));
  8736. }
  8737. /**
  8738. * @param {string} text
  8739. * @param {number} idx
  8740. * @returns {number | false}
  8741. */
  8742. function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
  8743. /** @type {number | false} */
  8744. var oldIdx = null;
  8745. /** @type {number | false} */
  8746. var nextIdx = idx;
  8747. while (nextIdx !== oldIdx) {
  8748. oldIdx = nextIdx;
  8749. nextIdx = skipSpaces(text, nextIdx);
  8750. nextIdx = skipInlineComment(text, nextIdx);
  8751. nextIdx = skipTrailingComment(text, nextIdx);
  8752. nextIdx = skipNewline(text, nextIdx);
  8753. }
  8754. return nextIdx;
  8755. }
  8756. /**
  8757. * @template N
  8758. * @param {string} text
  8759. * @param {N} node
  8760. * @param {(node: N) => number} locEnd
  8761. * @returns {number | false}
  8762. */
  8763. function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
  8764. return getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, locEnd(node));
  8765. }
  8766. /**
  8767. * @template N
  8768. * @param {string} text
  8769. * @param {N} node
  8770. * @param {(node: N) => number} locEnd
  8771. * @returns {string}
  8772. */
  8773. function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
  8774. return text.charAt( // @ts-ignore => TBD: can return false, should we define a fallback?
  8775. getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd));
  8776. }
  8777. /**
  8778. * @param {string} text
  8779. * @param {number} index
  8780. * @param {SkipOptions=} opts
  8781. * @returns {boolean}
  8782. */
  8783. function hasSpaces(text, index, opts) {
  8784. opts = opts || {};
  8785. var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  8786. return idx !== index;
  8787. }
  8788. /**
  8789. * @param {{range?: [number, number], start?: number}} node
  8790. * @param {number} index
  8791. */
  8792. function setLocStart(node, index) {
  8793. if (node.range) {
  8794. node.range[0] = index;
  8795. } else {
  8796. node.start = index;
  8797. }
  8798. }
  8799. /**
  8800. * @param {{range?: [number, number], end?: number}} node
  8801. * @param {number} index
  8802. */
  8803. function setLocEnd(node, index) {
  8804. if (node.range) {
  8805. node.range[1] = index;
  8806. } else {
  8807. node.end = index;
  8808. }
  8809. }
  8810. var PRECEDENCE = {};
  8811. [["|>"], ["??"], ["||"], ["&&"], ["|"], ["^"], ["&"], ["==", "===", "!=", "!=="], ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], ["*", "/", "%"], ["**"]].forEach(function (tier, i) {
  8812. tier.forEach(function (op) {
  8813. PRECEDENCE[op] = i;
  8814. });
  8815. });
  8816. function getPrecedence(op) {
  8817. return PRECEDENCE[op];
  8818. }
  8819. var equalityOperators = {
  8820. "==": true,
  8821. "!=": true,
  8822. "===": true,
  8823. "!==": true
  8824. };
  8825. var multiplicativeOperators = {
  8826. "*": true,
  8827. "/": true,
  8828. "%": true
  8829. };
  8830. var bitshiftOperators = {
  8831. ">>": true,
  8832. ">>>": true,
  8833. "<<": true
  8834. };
  8835. function shouldFlatten(parentOp, nodeOp) {
  8836. if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) {
  8837. return false;
  8838. } // ** is right-associative
  8839. // x ** y ** z --> x ** (y ** z)
  8840. if (parentOp === "**") {
  8841. return false;
  8842. } // x == y == z --> (x == y) == z
  8843. if (equalityOperators[parentOp] && equalityOperators[nodeOp]) {
  8844. return false;
  8845. } // x * y % z --> (x * y) % z
  8846. if (nodeOp === "%" && multiplicativeOperators[parentOp] || parentOp === "%" && multiplicativeOperators[nodeOp]) {
  8847. return false;
  8848. } // x * y / z --> (x * y) / z
  8849. // x / y * z --> (x / y) * z
  8850. if (nodeOp !== parentOp && multiplicativeOperators[nodeOp] && multiplicativeOperators[parentOp]) {
  8851. return false;
  8852. } // x << y << z --> (x << y) << z
  8853. if (bitshiftOperators[parentOp] && bitshiftOperators[nodeOp]) {
  8854. return false;
  8855. }
  8856. return true;
  8857. }
  8858. function isBitwiseOperator(operator) {
  8859. return !!bitshiftOperators[operator] || operator === "|" || operator === "^" || operator === "&";
  8860. } // Tests if an expression starts with `{`, or (if forbidFunctionClassAndDoExpr
  8861. // holds) `function`, `class`, or `do {}`. Will be overzealous if there's
  8862. // already necessary grouping parentheses.
  8863. function startsWithNoLookaheadToken(node, forbidFunctionClassAndDoExpr) {
  8864. node = getLeftMost(node);
  8865. switch (node.type) {
  8866. case "FunctionExpression":
  8867. case "ClassExpression":
  8868. case "DoExpression":
  8869. return forbidFunctionClassAndDoExpr;
  8870. case "ObjectExpression":
  8871. return true;
  8872. case "MemberExpression":
  8873. case "OptionalMemberExpression":
  8874. return startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  8875. case "TaggedTemplateExpression":
  8876. if (node.tag.type === "FunctionExpression") {
  8877. // IIFEs are always already parenthesized
  8878. return false;
  8879. }
  8880. return startsWithNoLookaheadToken(node.tag, forbidFunctionClassAndDoExpr);
  8881. case "CallExpression":
  8882. case "OptionalCallExpression":
  8883. if (node.callee.type === "FunctionExpression") {
  8884. // IIFEs are always already parenthesized
  8885. return false;
  8886. }
  8887. return startsWithNoLookaheadToken(node.callee, forbidFunctionClassAndDoExpr);
  8888. case "ConditionalExpression":
  8889. return startsWithNoLookaheadToken(node.test, forbidFunctionClassAndDoExpr);
  8890. case "UpdateExpression":
  8891. return !node.prefix && startsWithNoLookaheadToken(node.argument, forbidFunctionClassAndDoExpr);
  8892. case "BindExpression":
  8893. return node.object && startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  8894. case "SequenceExpression":
  8895. return startsWithNoLookaheadToken(node.expressions[0], forbidFunctionClassAndDoExpr);
  8896. case "TSAsExpression":
  8897. return startsWithNoLookaheadToken(node.expression, forbidFunctionClassAndDoExpr);
  8898. default:
  8899. return false;
  8900. }
  8901. }
  8902. function getLeftMost(node) {
  8903. if (node.left) {
  8904. return getLeftMost(node.left);
  8905. }
  8906. return node;
  8907. }
  8908. /**
  8909. * @param {string} value
  8910. * @param {number} tabWidth
  8911. * @param {number=} startIndex
  8912. * @returns {number}
  8913. */
  8914. function getAlignmentSize(value, tabWidth, startIndex) {
  8915. startIndex = startIndex || 0;
  8916. var size = 0;
  8917. for (var i = startIndex; i < value.length; ++i) {
  8918. if (value[i] === "\t") {
  8919. // Tabs behave in a way that they are aligned to the nearest
  8920. // multiple of tabWidth:
  8921. // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
  8922. // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
  8923. size = size + tabWidth - size % tabWidth;
  8924. } else {
  8925. size++;
  8926. }
  8927. }
  8928. return size;
  8929. }
  8930. /**
  8931. * @param {string} value
  8932. * @param {number} tabWidth
  8933. * @returns {number}
  8934. */
  8935. function getIndentSize(value, tabWidth) {
  8936. var lastNewlineIndex = value.lastIndexOf("\n");
  8937. if (lastNewlineIndex === -1) {
  8938. return 0;
  8939. }
  8940. return getAlignmentSize( // All the leading whitespaces
  8941. value.slice(lastNewlineIndex + 1).match(/^[ \t]*/)[0], tabWidth);
  8942. }
  8943. /**
  8944. * @typedef {'"' | "'"} Quote
  8945. */
  8946. /**
  8947. *
  8948. * @param {string} raw
  8949. * @param {Quote} preferredQuote
  8950. * @returns {Quote}
  8951. */
  8952. function getPreferredQuote(raw, preferredQuote) {
  8953. // `rawContent` is the string exactly like it appeared in the input source
  8954. // code, without its enclosing quotes.
  8955. var rawContent = raw.slice(1, -1);
  8956. /** @type {{ quote: '"', regex: RegExp }} */
  8957. var double = {
  8958. quote: '"',
  8959. regex: /"/g
  8960. };
  8961. /** @type {{ quote: "'", regex: RegExp }} */
  8962. var single = {
  8963. quote: "'",
  8964. regex: /'/g
  8965. };
  8966. var preferred = preferredQuote === "'" ? single : double;
  8967. var alternate = preferred === single ? double : single;
  8968. var result = preferred.quote; // If `rawContent` contains at least one of the quote preferred for enclosing
  8969. // the string, we might want to enclose with the alternate quote instead, to
  8970. // minimize the number of escaped quotes.
  8971. if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
  8972. var numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
  8973. var numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
  8974. result = numPreferredQuotes > numAlternateQuotes ? alternate.quote : preferred.quote;
  8975. }
  8976. return result;
  8977. }
  8978. function printString(raw, options, isDirectiveLiteral) {
  8979. // `rawContent` is the string exactly like it appeared in the input source
  8980. // code, without its enclosing quotes.
  8981. var rawContent = raw.slice(1, -1); // Check for the alternate quote, to determine if we're allowed to swap
  8982. // the quotes on a DirectiveLiteral.
  8983. var canChangeDirectiveQuotes = !rawContent.includes('"') && !rawContent.includes("'");
  8984. /** @type {Quote} */
  8985. var enclosingQuote = options.parser === "json" ? '"' : options.__isInHtmlAttribute ? "'" : getPreferredQuote(raw, options.singleQuote ? "'" : '"'); // Directives are exact code unit sequences, which means that you can't
  8986. // change the escape sequences they use.
  8987. // See https://github.com/prettier/prettier/issues/1555
  8988. // and https://tc39.github.io/ecma262/#directive-prologue
  8989. if (isDirectiveLiteral) {
  8990. if (canChangeDirectiveQuotes) {
  8991. return enclosingQuote + rawContent + enclosingQuote;
  8992. }
  8993. return raw;
  8994. } // It might sound unnecessary to use `makeString` even if the string already
  8995. // is enclosed with `enclosingQuote`, but it isn't. The string could contain
  8996. // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
  8997. // sure that we consistently output the minimum amount of escaped quotes.
  8998. return makeString(rawContent, enclosingQuote, !(options.parser === "css" || options.parser === "less" || options.parser === "scss" || options.embeddedInHtml));
  8999. }
  9000. /**
  9001. * @param {string} rawContent
  9002. * @param {Quote} enclosingQuote
  9003. * @param {boolean=} unescapeUnnecessaryEscapes
  9004. * @returns {string}
  9005. */
  9006. function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
  9007. var otherQuote = enclosingQuote === '"' ? "'" : '"'; // Matches _any_ escape and unescaped quotes (both single and double).
  9008. var regex = /\\([\s\S])|(['"])/g; // Escape and unescape single and double quotes as needed to be able to
  9009. // enclose `rawContent` with `enclosingQuote`.
  9010. var newContent = rawContent.replace(regex, function (match, escaped, quote) {
  9011. // If we matched an escape, and the escaped character is a quote of the
  9012. // other type than we intend to enclose the string with, there's no need for
  9013. // it to be escaped, so return it _without_ the backslash.
  9014. if (escaped === otherQuote) {
  9015. return escaped;
  9016. } // If we matched an unescaped quote and it is of the _same_ type as we
  9017. // intend to enclose the string with, it must be escaped, so return it with
  9018. // a backslash.
  9019. if (quote === enclosingQuote) {
  9020. return "\\" + quote;
  9021. }
  9022. if (quote) {
  9023. return quote;
  9024. } // Unescape any unnecessarily escaped character.
  9025. // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
  9026. return unescapeUnnecessaryEscapes && /^[^\\nrvtbfux\r\n\u2028\u2029"'0-7]$/.test(escaped) ? escaped : "\\" + escaped;
  9027. });
  9028. return enclosingQuote + newContent + enclosingQuote;
  9029. }
  9030. function printNumber(rawNumber) {
  9031. return rawNumber.toLowerCase() // Remove unnecessary plus and zeroes from scientific notation.
  9032. .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3") // Remove unnecessary scientific notation (1e0).
  9033. .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1") // Make sure numbers always start with a digit.
  9034. .replace(/^([+-])?\./, "$10.") // Remove extraneous trailing decimal zeroes.
  9035. .replace(/(\.\d+?)0+(?=e|$)/, "$1") // Remove trailing dot.
  9036. .replace(/\.(?=e|$)/, "");
  9037. }
  9038. /**
  9039. * @param {string} str
  9040. * @param {string} target
  9041. * @returns {number}
  9042. */
  9043. function getMaxContinuousCount(str, target) {
  9044. var results = str.match(new RegExp(`(${escapeStringRegexp(target)})+`, "g"));
  9045. if (results === null) {
  9046. return 0;
  9047. }
  9048. return results.reduce(function (maxCount, result) {
  9049. return Math.max(maxCount, result.length / target.length);
  9050. }, 0);
  9051. }
  9052. function getMinNotPresentContinuousCount(str, target) {
  9053. var matches = str.match(new RegExp(`(${escapeStringRegexp(target)})+`, "g"));
  9054. if (matches === null) {
  9055. return 0;
  9056. }
  9057. var countPresent = new Map();
  9058. var max = 0;
  9059. var _iteratorNormalCompletion = true;
  9060. var _didIteratorError = false;
  9061. var _iteratorError = undefined;
  9062. try {
  9063. for (var _iterator = matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  9064. var match = _step.value;
  9065. var count = match.length / target.length;
  9066. countPresent.set(count, true);
  9067. if (count > max) {
  9068. max = count;
  9069. }
  9070. }
  9071. } catch (err) {
  9072. _didIteratorError = true;
  9073. _iteratorError = err;
  9074. } finally {
  9075. try {
  9076. if (!_iteratorNormalCompletion && _iterator.return != null) {
  9077. _iterator.return();
  9078. }
  9079. } finally {
  9080. if (_didIteratorError) {
  9081. throw _iteratorError;
  9082. }
  9083. }
  9084. }
  9085. for (var i = 1; i < max; i++) {
  9086. if (!countPresent.get(i)) {
  9087. return i;
  9088. }
  9089. }
  9090. return max + 1;
  9091. }
  9092. /**
  9093. * @param {string} text
  9094. * @returns {number}
  9095. */
  9096. function getStringWidth(text) {
  9097. if (!text) {
  9098. return 0;
  9099. } // shortcut to avoid needless string `RegExp`s, replacements, and allocations within `string-width`
  9100. if (!notAsciiRegex.test(text)) {
  9101. return text.length;
  9102. }
  9103. return stringWidth_1(text);
  9104. }
  9105. function hasIgnoreComment(path) {
  9106. var node = path.getValue();
  9107. return hasNodeIgnoreComment(node);
  9108. }
  9109. function hasNodeIgnoreComment(node) {
  9110. return node && node.comments && node.comments.length > 0 && node.comments.some(function (comment) {
  9111. return comment.value.trim() === "prettier-ignore";
  9112. });
  9113. }
  9114. function matchAncestorTypes(path, types, index) {
  9115. index = index || 0;
  9116. types = types.slice();
  9117. while (types.length) {
  9118. var parent = path.getParentNode(index);
  9119. var type = types.shift();
  9120. if (!parent || parent.type !== type) {
  9121. return false;
  9122. }
  9123. index++;
  9124. }
  9125. return true;
  9126. }
  9127. function addCommentHelper(node, comment) {
  9128. var comments = node.comments || (node.comments = []);
  9129. comments.push(comment);
  9130. comment.printed = false; // For some reason, TypeScript parses `// x` inside of JSXText as a comment
  9131. // We already "print" it via the raw text, we don't need to re-print it as a
  9132. // comment
  9133. if (node.type === "JSXText") {
  9134. comment.printed = true;
  9135. }
  9136. }
  9137. function addLeadingComment(node, comment) {
  9138. comment.leading = true;
  9139. comment.trailing = false;
  9140. addCommentHelper(node, comment);
  9141. }
  9142. function addDanglingComment(node, comment) {
  9143. comment.leading = false;
  9144. comment.trailing = false;
  9145. addCommentHelper(node, comment);
  9146. }
  9147. function addTrailingComment(node, comment) {
  9148. comment.leading = false;
  9149. comment.trailing = true;
  9150. addCommentHelper(node, comment);
  9151. }
  9152. function isWithinParentArrayProperty(path, propertyName) {
  9153. var node = path.getValue();
  9154. var parent = path.getParentNode();
  9155. if (parent == null) {
  9156. return false;
  9157. }
  9158. if (!Array.isArray(parent[propertyName])) {
  9159. return false;
  9160. }
  9161. var key = path.getName();
  9162. return parent[propertyName][key] === node;
  9163. }
  9164. function replaceEndOfLineWith(text, replacement) {
  9165. var parts = [];
  9166. var _iteratorNormalCompletion2 = true;
  9167. var _didIteratorError2 = false;
  9168. var _iteratorError2 = undefined;
  9169. try {
  9170. for (var _iterator2 = text.split("\n")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  9171. var part = _step2.value;
  9172. if (parts.length !== 0) {
  9173. parts.push(replacement);
  9174. }
  9175. parts.push(part);
  9176. }
  9177. } catch (err) {
  9178. _didIteratorError2 = true;
  9179. _iteratorError2 = err;
  9180. } finally {
  9181. try {
  9182. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  9183. _iterator2.return();
  9184. }
  9185. } finally {
  9186. if (_didIteratorError2) {
  9187. throw _iteratorError2;
  9188. }
  9189. }
  9190. }
  9191. return parts;
  9192. }
  9193. var util = {
  9194. replaceEndOfLineWith,
  9195. getStringWidth,
  9196. getMaxContinuousCount,
  9197. getMinNotPresentContinuousCount,
  9198. getPrecedence,
  9199. shouldFlatten,
  9200. isBitwiseOperator,
  9201. isExportDeclaration,
  9202. getParentExportDeclaration,
  9203. getPenultimate,
  9204. getLast,
  9205. getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
  9206. getNextNonSpaceNonCommentCharacterIndex,
  9207. getNextNonSpaceNonCommentCharacter,
  9208. skip,
  9209. skipWhitespace,
  9210. skipSpaces,
  9211. skipToLineEnd,
  9212. skipEverythingButNewLine,
  9213. skipInlineComment,
  9214. skipTrailingComment,
  9215. skipNewline,
  9216. isNextLineEmptyAfterIndex,
  9217. isNextLineEmpty,
  9218. isPreviousLineEmpty,
  9219. hasNewline,
  9220. hasNewlineInRange,
  9221. hasSpaces,
  9222. setLocStart,
  9223. setLocEnd,
  9224. startsWithNoLookaheadToken,
  9225. getAlignmentSize,
  9226. getIndentSize,
  9227. getPreferredQuote,
  9228. printString,
  9229. printNumber,
  9230. hasIgnoreComment,
  9231. hasNodeIgnoreComment,
  9232. makeString,
  9233. matchAncestorTypes,
  9234. addLeadingComment,
  9235. addDanglingComment,
  9236. addTrailingComment,
  9237. isWithinParentArrayProperty
  9238. };
  9239. function guessEndOfLine(text) {
  9240. var index = text.indexOf("\r");
  9241. if (index >= 0) {
  9242. return text.charAt(index + 1) === "\n" ? "crlf" : "cr";
  9243. }
  9244. return "lf";
  9245. }
  9246. function convertEndOfLineToChars(value) {
  9247. switch (value) {
  9248. case "cr":
  9249. return "\r";
  9250. case "crlf":
  9251. return "\r\n";
  9252. default:
  9253. return "\n";
  9254. }
  9255. }
  9256. var endOfLine = {
  9257. guessEndOfLine,
  9258. convertEndOfLineToChars
  9259. };
  9260. var getStringWidth$1 = util.getStringWidth;
  9261. var convertEndOfLineToChars$1 = endOfLine.convertEndOfLineToChars;
  9262. var concat$1 = docBuilders.concat,
  9263. fill$1 = docBuilders.fill,
  9264. cursor$1 = docBuilders.cursor;
  9265. /** @type {Record<symbol, typeof MODE_BREAK | typeof MODE_FLAT>} */
  9266. var groupModeMap;
  9267. var MODE_BREAK = 1;
  9268. var MODE_FLAT = 2;
  9269. function rootIndent() {
  9270. return {
  9271. value: "",
  9272. length: 0,
  9273. queue: []
  9274. };
  9275. }
  9276. function makeIndent(ind, options) {
  9277. return generateInd(ind, {
  9278. type: "indent"
  9279. }, options);
  9280. }
  9281. function makeAlign(ind, n, options) {
  9282. return n === -Infinity ? ind.root || rootIndent() : n < 0 ? generateInd(ind, {
  9283. type: "dedent"
  9284. }, options) : !n ? ind : n.type === "root" ? Object.assign({}, ind, {
  9285. root: ind
  9286. }) : typeof n === "string" ? generateInd(ind, {
  9287. type: "stringAlign",
  9288. n
  9289. }, options) : generateInd(ind, {
  9290. type: "numberAlign",
  9291. n
  9292. }, options);
  9293. }
  9294. function generateInd(ind, newPart, options) {
  9295. var queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : ind.queue.concat(newPart);
  9296. var value = "";
  9297. var length = 0;
  9298. var lastTabs = 0;
  9299. var lastSpaces = 0;
  9300. var _iteratorNormalCompletion = true;
  9301. var _didIteratorError = false;
  9302. var _iteratorError = undefined;
  9303. try {
  9304. for (var _iterator = queue[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  9305. var part = _step.value;
  9306. switch (part.type) {
  9307. case "indent":
  9308. flush();
  9309. if (options.useTabs) {
  9310. addTabs(1);
  9311. } else {
  9312. addSpaces(options.tabWidth);
  9313. }
  9314. break;
  9315. case "stringAlign":
  9316. flush();
  9317. value += part.n;
  9318. length += part.n.length;
  9319. break;
  9320. case "numberAlign":
  9321. lastTabs += 1;
  9322. lastSpaces += part.n;
  9323. break;
  9324. /* istanbul ignore next */
  9325. default:
  9326. throw new Error(`Unexpected type '${part.type}'`);
  9327. }
  9328. }
  9329. } catch (err) {
  9330. _didIteratorError = true;
  9331. _iteratorError = err;
  9332. } finally {
  9333. try {
  9334. if (!_iteratorNormalCompletion && _iterator.return != null) {
  9335. _iterator.return();
  9336. }
  9337. } finally {
  9338. if (_didIteratorError) {
  9339. throw _iteratorError;
  9340. }
  9341. }
  9342. }
  9343. flushSpaces();
  9344. return Object.assign({}, ind, {
  9345. value,
  9346. length,
  9347. queue
  9348. });
  9349. function addTabs(count) {
  9350. value += "\t".repeat(count);
  9351. length += options.tabWidth * count;
  9352. }
  9353. function addSpaces(count) {
  9354. value += " ".repeat(count);
  9355. length += count;
  9356. }
  9357. function flush() {
  9358. if (options.useTabs) {
  9359. flushTabs();
  9360. } else {
  9361. flushSpaces();
  9362. }
  9363. }
  9364. function flushTabs() {
  9365. if (lastTabs > 0) {
  9366. addTabs(lastTabs);
  9367. }
  9368. resetLast();
  9369. }
  9370. function flushSpaces() {
  9371. if (lastSpaces > 0) {
  9372. addSpaces(lastSpaces);
  9373. }
  9374. resetLast();
  9375. }
  9376. function resetLast() {
  9377. lastTabs = 0;
  9378. lastSpaces = 0;
  9379. }
  9380. }
  9381. function trim$1(out) {
  9382. if (out.length === 0) {
  9383. return 0;
  9384. }
  9385. var trimCount = 0; // Trim whitespace at the end of line
  9386. while (out.length > 0 && typeof out[out.length - 1] === "string" && out[out.length - 1].match(/^[ \t]*$/)) {
  9387. trimCount += out.pop().length;
  9388. }
  9389. if (out.length && typeof out[out.length - 1] === "string") {
  9390. var trimmed = out[out.length - 1].replace(/[ \t]*$/, "");
  9391. trimCount += out[out.length - 1].length - trimmed.length;
  9392. out[out.length - 1] = trimmed;
  9393. }
  9394. return trimCount;
  9395. }
  9396. function fits(next, restCommands, width, options, mustBeFlat) {
  9397. var restIdx = restCommands.length;
  9398. var cmds = [next]; // `out` is only used for width counting because `trim` requires to look
  9399. // backwards for space characters.
  9400. var out = [];
  9401. while (width >= 0) {
  9402. if (cmds.length === 0) {
  9403. if (restIdx === 0) {
  9404. return true;
  9405. }
  9406. cmds.push(restCommands[restIdx - 1]);
  9407. restIdx--;
  9408. continue;
  9409. }
  9410. var x = cmds.pop();
  9411. var ind = x[0];
  9412. var mode = x[1];
  9413. var doc = x[2];
  9414. if (typeof doc === "string") {
  9415. out.push(doc);
  9416. width -= getStringWidth$1(doc);
  9417. } else {
  9418. switch (doc.type) {
  9419. case "concat":
  9420. for (var i = doc.parts.length - 1; i >= 0; i--) {
  9421. cmds.push([ind, mode, doc.parts[i]]);
  9422. }
  9423. break;
  9424. case "indent":
  9425. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  9426. break;
  9427. case "align":
  9428. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  9429. break;
  9430. case "trim":
  9431. width += trim$1(out);
  9432. break;
  9433. case "group":
  9434. if (mustBeFlat && doc.break) {
  9435. return false;
  9436. }
  9437. cmds.push([ind, doc.break ? MODE_BREAK : mode, doc.contents]);
  9438. if (doc.id) {
  9439. groupModeMap[doc.id] = cmds[cmds.length - 1][1];
  9440. }
  9441. break;
  9442. case "fill":
  9443. for (var _i = doc.parts.length - 1; _i >= 0; _i--) {
  9444. cmds.push([ind, mode, doc.parts[_i]]);
  9445. }
  9446. break;
  9447. case "if-break":
  9448. {
  9449. var groupMode = doc.groupId ? groupModeMap[doc.groupId] : mode;
  9450. if (groupMode === MODE_BREAK) {
  9451. if (doc.breakContents) {
  9452. cmds.push([ind, mode, doc.breakContents]);
  9453. }
  9454. }
  9455. if (groupMode === MODE_FLAT) {
  9456. if (doc.flatContents) {
  9457. cmds.push([ind, mode, doc.flatContents]);
  9458. }
  9459. }
  9460. break;
  9461. }
  9462. case "line":
  9463. switch (mode) {
  9464. // fallthrough
  9465. case MODE_FLAT:
  9466. if (!doc.hard) {
  9467. if (!doc.soft) {
  9468. out.push(" ");
  9469. width -= 1;
  9470. }
  9471. break;
  9472. }
  9473. return true;
  9474. case MODE_BREAK:
  9475. return true;
  9476. }
  9477. break;
  9478. }
  9479. }
  9480. }
  9481. return false;
  9482. }
  9483. function printDocToString(doc, options) {
  9484. groupModeMap = {};
  9485. var width = options.printWidth;
  9486. var newLine = convertEndOfLineToChars$1(options.endOfLine);
  9487. var pos = 0; // cmds is basically a stack. We've turned a recursive call into a
  9488. // while loop which is much faster. The while loop below adds new
  9489. // cmds to the array instead of recursively calling `print`.
  9490. var cmds = [[rootIndent(), MODE_BREAK, doc]];
  9491. var out = [];
  9492. var shouldRemeasure = false;
  9493. var lineSuffix = [];
  9494. while (cmds.length !== 0) {
  9495. var x = cmds.pop();
  9496. var ind = x[0];
  9497. var mode = x[1];
  9498. var _doc = x[2];
  9499. if (typeof _doc === "string") {
  9500. out.push(_doc);
  9501. pos += getStringWidth$1(_doc);
  9502. } else {
  9503. switch (_doc.type) {
  9504. case "cursor":
  9505. out.push(cursor$1.placeholder);
  9506. break;
  9507. case "concat":
  9508. for (var i = _doc.parts.length - 1; i >= 0; i--) {
  9509. cmds.push([ind, mode, _doc.parts[i]]);
  9510. }
  9511. break;
  9512. case "indent":
  9513. cmds.push([makeIndent(ind, options), mode, _doc.contents]);
  9514. break;
  9515. case "align":
  9516. cmds.push([makeAlign(ind, _doc.n, options), mode, _doc.contents]);
  9517. break;
  9518. case "trim":
  9519. pos -= trim$1(out);
  9520. break;
  9521. case "group":
  9522. switch (mode) {
  9523. case MODE_FLAT:
  9524. if (!shouldRemeasure) {
  9525. cmds.push([ind, _doc.break ? MODE_BREAK : MODE_FLAT, _doc.contents]);
  9526. break;
  9527. }
  9528. // fallthrough
  9529. case MODE_BREAK:
  9530. {
  9531. shouldRemeasure = false;
  9532. var next = [ind, MODE_FLAT, _doc.contents];
  9533. var rem = width - pos;
  9534. if (!_doc.break && fits(next, cmds, rem, options)) {
  9535. cmds.push(next);
  9536. } else {
  9537. // Expanded states are a rare case where a document
  9538. // can manually provide multiple representations of
  9539. // itself. It provides an array of documents
  9540. // going from the least expanded (most flattened)
  9541. // representation first to the most expanded. If a
  9542. // group has these, we need to manually go through
  9543. // these states and find the first one that fits.
  9544. if (_doc.expandedStates) {
  9545. var mostExpanded = _doc.expandedStates[_doc.expandedStates.length - 1];
  9546. if (_doc.break) {
  9547. cmds.push([ind, MODE_BREAK, mostExpanded]);
  9548. break;
  9549. } else {
  9550. for (var _i2 = 1; _i2 < _doc.expandedStates.length + 1; _i2++) {
  9551. if (_i2 >= _doc.expandedStates.length) {
  9552. cmds.push([ind, MODE_BREAK, mostExpanded]);
  9553. break;
  9554. } else {
  9555. var state = _doc.expandedStates[_i2];
  9556. var cmd = [ind, MODE_FLAT, state];
  9557. if (fits(cmd, cmds, rem, options)) {
  9558. cmds.push(cmd);
  9559. break;
  9560. }
  9561. }
  9562. }
  9563. }
  9564. } else {
  9565. cmds.push([ind, MODE_BREAK, _doc.contents]);
  9566. }
  9567. }
  9568. break;
  9569. }
  9570. }
  9571. if (_doc.id) {
  9572. groupModeMap[_doc.id] = cmds[cmds.length - 1][1];
  9573. }
  9574. break;
  9575. // Fills each line with as much code as possible before moving to a new
  9576. // line with the same indentation.
  9577. //
  9578. // Expects doc.parts to be an array of alternating content and
  9579. // whitespace. The whitespace contains the linebreaks.
  9580. //
  9581. // For example:
  9582. // ["I", line, "love", line, "monkeys"]
  9583. // or
  9584. // [{ type: group, ... }, softline, { type: group, ... }]
  9585. //
  9586. // It uses this parts structure to handle three main layout cases:
  9587. // * The first two content items fit on the same line without
  9588. // breaking
  9589. // -> output the first content item and the whitespace "flat".
  9590. // * Only the first content item fits on the line without breaking
  9591. // -> output the first content item "flat" and the whitespace with
  9592. // "break".
  9593. // * Neither content item fits on the line without breaking
  9594. // -> output the first content item and the whitespace with "break".
  9595. case "fill":
  9596. {
  9597. var _rem = width - pos;
  9598. var parts = _doc.parts;
  9599. if (parts.length === 0) {
  9600. break;
  9601. }
  9602. var content = parts[0];
  9603. var contentFlatCmd = [ind, MODE_FLAT, content];
  9604. var contentBreakCmd = [ind, MODE_BREAK, content];
  9605. var contentFits = fits(contentFlatCmd, [], _rem, options, true);
  9606. if (parts.length === 1) {
  9607. if (contentFits) {
  9608. cmds.push(contentFlatCmd);
  9609. } else {
  9610. cmds.push(contentBreakCmd);
  9611. }
  9612. break;
  9613. }
  9614. var whitespace = parts[1];
  9615. var whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
  9616. var whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
  9617. if (parts.length === 2) {
  9618. if (contentFits) {
  9619. cmds.push(whitespaceFlatCmd);
  9620. cmds.push(contentFlatCmd);
  9621. } else {
  9622. cmds.push(whitespaceBreakCmd);
  9623. cmds.push(contentBreakCmd);
  9624. }
  9625. break;
  9626. } // At this point we've handled the first pair (context, separator)
  9627. // and will create a new fill doc for the rest of the content.
  9628. // Ideally we wouldn't mutate the array here but coping all the
  9629. // elements to a new array would make this algorithm quadratic,
  9630. // which is unusable for large arrays (e.g. large texts in JSX).
  9631. parts.splice(0, 2);
  9632. var remainingCmd = [ind, mode, fill$1(parts)];
  9633. var secondContent = parts[0];
  9634. var firstAndSecondContentFlatCmd = [ind, MODE_FLAT, concat$1([content, whitespace, secondContent])];
  9635. var firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], _rem, options, true);
  9636. if (firstAndSecondContentFits) {
  9637. cmds.push(remainingCmd);
  9638. cmds.push(whitespaceFlatCmd);
  9639. cmds.push(contentFlatCmd);
  9640. } else if (contentFits) {
  9641. cmds.push(remainingCmd);
  9642. cmds.push(whitespaceBreakCmd);
  9643. cmds.push(contentFlatCmd);
  9644. } else {
  9645. cmds.push(remainingCmd);
  9646. cmds.push(whitespaceBreakCmd);
  9647. cmds.push(contentBreakCmd);
  9648. }
  9649. break;
  9650. }
  9651. case "if-break":
  9652. {
  9653. var groupMode = _doc.groupId ? groupModeMap[_doc.groupId] : mode;
  9654. if (groupMode === MODE_BREAK) {
  9655. if (_doc.breakContents) {
  9656. cmds.push([ind, mode, _doc.breakContents]);
  9657. }
  9658. }
  9659. if (groupMode === MODE_FLAT) {
  9660. if (_doc.flatContents) {
  9661. cmds.push([ind, mode, _doc.flatContents]);
  9662. }
  9663. }
  9664. break;
  9665. }
  9666. case "line-suffix":
  9667. lineSuffix.push([ind, mode, _doc.contents]);
  9668. break;
  9669. case "line-suffix-boundary":
  9670. if (lineSuffix.length > 0) {
  9671. cmds.push([ind, mode, {
  9672. type: "line",
  9673. hard: true
  9674. }]);
  9675. }
  9676. break;
  9677. case "line":
  9678. switch (mode) {
  9679. case MODE_FLAT:
  9680. if (!_doc.hard) {
  9681. if (!_doc.soft) {
  9682. out.push(" ");
  9683. pos += 1;
  9684. }
  9685. break;
  9686. } else {
  9687. // This line was forced into the output even if we
  9688. // were in flattened mode, so we need to tell the next
  9689. // group that no matter what, it needs to remeasure
  9690. // because the previous measurement didn't accurately
  9691. // capture the entire expression (this is necessary
  9692. // for nested groups)
  9693. shouldRemeasure = true;
  9694. }
  9695. // fallthrough
  9696. case MODE_BREAK:
  9697. if (lineSuffix.length) {
  9698. cmds.push([ind, mode, _doc]);
  9699. [].push.apply(cmds, lineSuffix.reverse());
  9700. lineSuffix = [];
  9701. break;
  9702. }
  9703. if (_doc.literal) {
  9704. if (ind.root) {
  9705. out.push(newLine, ind.root.value);
  9706. pos = ind.root.length;
  9707. } else {
  9708. out.push(newLine);
  9709. pos = 0;
  9710. }
  9711. } else {
  9712. pos -= trim$1(out);
  9713. out.push(newLine + ind.value);
  9714. pos = ind.length;
  9715. }
  9716. break;
  9717. }
  9718. break;
  9719. }
  9720. }
  9721. }
  9722. var cursorPlaceholderIndex = out.indexOf(cursor$1.placeholder);
  9723. if (cursorPlaceholderIndex !== -1) {
  9724. var otherCursorPlaceholderIndex = out.indexOf(cursor$1.placeholder, cursorPlaceholderIndex + 1);
  9725. var beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
  9726. var aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
  9727. var afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
  9728. return {
  9729. formatted: beforeCursor + aroundCursor + afterCursor,
  9730. cursorNodeStart: beforeCursor.length,
  9731. cursorNodeText: aroundCursor
  9732. };
  9733. }
  9734. return {
  9735. formatted: out.join("")
  9736. };
  9737. }
  9738. var docPrinter = {
  9739. printDocToString
  9740. };
  9741. var traverseDocOnExitStackMarker = {};
  9742. function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
  9743. var docsStack = [doc];
  9744. while (docsStack.length !== 0) {
  9745. var _doc = docsStack.pop();
  9746. if (_doc === traverseDocOnExitStackMarker) {
  9747. onExit(docsStack.pop());
  9748. continue;
  9749. }
  9750. var shouldRecurse = true;
  9751. if (onEnter) {
  9752. if (onEnter(_doc) === false) {
  9753. shouldRecurse = false;
  9754. }
  9755. }
  9756. if (onExit) {
  9757. docsStack.push(_doc);
  9758. docsStack.push(traverseDocOnExitStackMarker);
  9759. }
  9760. if (shouldRecurse) {
  9761. // When there are multiple parts to process,
  9762. // the parts need to be pushed onto the stack in reverse order,
  9763. // so that they are processed in the original order
  9764. // when the stack is popped.
  9765. if (_doc.type === "concat" || _doc.type === "fill") {
  9766. for (var ic = _doc.parts.length, i = ic - 1; i >= 0; --i) {
  9767. docsStack.push(_doc.parts[i]);
  9768. }
  9769. } else if (_doc.type === "if-break") {
  9770. if (_doc.flatContents) {
  9771. docsStack.push(_doc.flatContents);
  9772. }
  9773. if (_doc.breakContents) {
  9774. docsStack.push(_doc.breakContents);
  9775. }
  9776. } else if (_doc.type === "group" && _doc.expandedStates) {
  9777. if (shouldTraverseConditionalGroups) {
  9778. for (var _ic = _doc.expandedStates.length, _i = _ic - 1; _i >= 0; --_i) {
  9779. docsStack.push(_doc.expandedStates[_i]);
  9780. }
  9781. } else {
  9782. docsStack.push(_doc.contents);
  9783. }
  9784. } else if (_doc.contents) {
  9785. docsStack.push(_doc.contents);
  9786. }
  9787. }
  9788. }
  9789. }
  9790. function mapDoc(doc, cb) {
  9791. if (doc.type === "concat" || doc.type === "fill") {
  9792. var parts = doc.parts.map(function (part) {
  9793. return mapDoc(part, cb);
  9794. });
  9795. return cb(Object.assign({}, doc, {
  9796. parts
  9797. }));
  9798. } else if (doc.type === "if-break") {
  9799. var breakContents = doc.breakContents && mapDoc(doc.breakContents, cb);
  9800. var flatContents = doc.flatContents && mapDoc(doc.flatContents, cb);
  9801. return cb(Object.assign({}, doc, {
  9802. breakContents,
  9803. flatContents
  9804. }));
  9805. } else if (doc.contents) {
  9806. var contents = mapDoc(doc.contents, cb);
  9807. return cb(Object.assign({}, doc, {
  9808. contents
  9809. }));
  9810. }
  9811. return cb(doc);
  9812. }
  9813. function findInDoc(doc, fn, defaultValue) {
  9814. var result = defaultValue;
  9815. var hasStopped = false;
  9816. function findInDocOnEnterFn(doc) {
  9817. var maybeResult = fn(doc);
  9818. if (maybeResult !== undefined) {
  9819. hasStopped = true;
  9820. result = maybeResult;
  9821. }
  9822. if (hasStopped) {
  9823. return false;
  9824. }
  9825. }
  9826. traverseDoc(doc, findInDocOnEnterFn);
  9827. return result;
  9828. }
  9829. function isEmpty(n) {
  9830. return typeof n === "string" && n.length === 0;
  9831. }
  9832. function isLineNextFn(doc) {
  9833. if (typeof doc === "string") {
  9834. return false;
  9835. }
  9836. if (doc.type === "line") {
  9837. return true;
  9838. }
  9839. }
  9840. function isLineNext(doc) {
  9841. return findInDoc(doc, isLineNextFn, false);
  9842. }
  9843. function willBreakFn(doc) {
  9844. if (doc.type === "group" && doc.break) {
  9845. return true;
  9846. }
  9847. if (doc.type === "line" && doc.hard) {
  9848. return true;
  9849. }
  9850. if (doc.type === "break-parent") {
  9851. return true;
  9852. }
  9853. }
  9854. function willBreak(doc) {
  9855. return findInDoc(doc, willBreakFn, false);
  9856. }
  9857. function breakParentGroup(groupStack) {
  9858. if (groupStack.length > 0) {
  9859. var parentGroup = groupStack[groupStack.length - 1]; // Breaks are not propagated through conditional groups because
  9860. // the user is expected to manually handle what breaks.
  9861. if (!parentGroup.expandedStates) {
  9862. parentGroup.break = true;
  9863. }
  9864. }
  9865. return null;
  9866. }
  9867. function propagateBreaks(doc) {
  9868. var alreadyVisitedSet = new Set();
  9869. var groupStack = [];
  9870. function propagateBreaksOnEnterFn(doc) {
  9871. if (doc.type === "break-parent") {
  9872. breakParentGroup(groupStack);
  9873. }
  9874. if (doc.type === "group") {
  9875. groupStack.push(doc);
  9876. if (alreadyVisitedSet.has(doc)) {
  9877. return false;
  9878. }
  9879. alreadyVisitedSet.add(doc);
  9880. }
  9881. }
  9882. function propagateBreaksOnExitFn(doc) {
  9883. if (doc.type === "group") {
  9884. var group = groupStack.pop();
  9885. if (group.break) {
  9886. breakParentGroup(groupStack);
  9887. }
  9888. }
  9889. }
  9890. traverseDoc(doc, propagateBreaksOnEnterFn, propagateBreaksOnExitFn,
  9891. /* shouldTraverseConditionalGroups */
  9892. true);
  9893. }
  9894. function removeLinesFn(doc) {
  9895. // Force this doc into flat mode by statically converting all
  9896. // lines into spaces (or soft lines into nothing). Hard lines
  9897. // should still output because there's too great of a chance
  9898. // of breaking existing assumptions otherwise.
  9899. if (doc.type === "line" && !doc.hard) {
  9900. return doc.soft ? "" : " ";
  9901. } else if (doc.type === "if-break") {
  9902. return doc.flatContents || "";
  9903. }
  9904. return doc;
  9905. }
  9906. function removeLines(doc) {
  9907. return mapDoc(doc, removeLinesFn);
  9908. }
  9909. function stripTrailingHardline(doc) {
  9910. // HACK remove ending hardline, original PR: #1984
  9911. if (doc.type === "concat" && doc.parts.length !== 0) {
  9912. var lastPart = doc.parts[doc.parts.length - 1];
  9913. if (lastPart.type === "concat") {
  9914. if (lastPart.parts.length === 2 && lastPart.parts[0].hard && lastPart.parts[1].type === "break-parent") {
  9915. return {
  9916. type: "concat",
  9917. parts: doc.parts.slice(0, -1)
  9918. };
  9919. }
  9920. return {
  9921. type: "concat",
  9922. parts: doc.parts.slice(0, -1).concat(stripTrailingHardline(lastPart))
  9923. };
  9924. }
  9925. }
  9926. return doc;
  9927. }
  9928. var docUtils = {
  9929. isEmpty,
  9930. willBreak,
  9931. isLineNext,
  9932. traverseDoc,
  9933. findInDoc,
  9934. mapDoc,
  9935. propagateBreaks,
  9936. removeLines,
  9937. stripTrailingHardline
  9938. };
  9939. function flattenDoc(doc) {
  9940. if (doc.type === "concat") {
  9941. var res = [];
  9942. for (var i = 0; i < doc.parts.length; ++i) {
  9943. var doc2 = doc.parts[i];
  9944. if (typeof doc2 !== "string" && doc2.type === "concat") {
  9945. [].push.apply(res, flattenDoc(doc2).parts);
  9946. } else {
  9947. var flattened = flattenDoc(doc2);
  9948. if (flattened !== "") {
  9949. res.push(flattened);
  9950. }
  9951. }
  9952. }
  9953. return Object.assign({}, doc, {
  9954. parts: res
  9955. });
  9956. } else if (doc.type === "if-break") {
  9957. return Object.assign({}, doc, {
  9958. breakContents: doc.breakContents != null ? flattenDoc(doc.breakContents) : null,
  9959. flatContents: doc.flatContents != null ? flattenDoc(doc.flatContents) : null
  9960. });
  9961. } else if (doc.type === "group") {
  9962. return Object.assign({}, doc, {
  9963. contents: flattenDoc(doc.contents),
  9964. expandedStates: doc.expandedStates ? doc.expandedStates.map(flattenDoc) : doc.expandedStates
  9965. });
  9966. } else if (doc.contents) {
  9967. return Object.assign({}, doc, {
  9968. contents: flattenDoc(doc.contents)
  9969. });
  9970. }
  9971. return doc;
  9972. }
  9973. function printDoc(doc) {
  9974. if (typeof doc === "string") {
  9975. return JSON.stringify(doc);
  9976. }
  9977. if (doc.type === "line") {
  9978. if (doc.literal) {
  9979. return "literalline";
  9980. }
  9981. if (doc.hard) {
  9982. return "hardline";
  9983. }
  9984. if (doc.soft) {
  9985. return "softline";
  9986. }
  9987. return "line";
  9988. }
  9989. if (doc.type === "break-parent") {
  9990. return "breakParent";
  9991. }
  9992. if (doc.type === "trim") {
  9993. return "trim";
  9994. }
  9995. if (doc.type === "concat") {
  9996. return "[" + doc.parts.map(printDoc).join(", ") + "]";
  9997. }
  9998. if (doc.type === "indent") {
  9999. return "indent(" + printDoc(doc.contents) + ")";
  10000. }
  10001. if (doc.type === "align") {
  10002. 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) + ")";
  10003. }
  10004. if (doc.type === "if-break") {
  10005. return "ifBreak(" + printDoc(doc.breakContents) + (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") + ")";
  10006. }
  10007. if (doc.type === "group") {
  10008. if (doc.expandedStates) {
  10009. return "conditionalGroup(" + "[" + doc.expandedStates.map(printDoc).join(",") + "])";
  10010. }
  10011. return (doc.break ? "wrappedGroup" : "group") + "(" + printDoc(doc.contents) + ")";
  10012. }
  10013. if (doc.type === "fill") {
  10014. return "fill" + "(" + doc.parts.map(printDoc).join(", ") + ")";
  10015. }
  10016. if (doc.type === "line-suffix") {
  10017. return "lineSuffix(" + printDoc(doc.contents) + ")";
  10018. }
  10019. if (doc.type === "line-suffix-boundary") {
  10020. return "lineSuffixBoundary";
  10021. }
  10022. throw new Error("Unknown doc type " + doc.type);
  10023. }
  10024. var docDebug = {
  10025. printDocToDebug: function printDocToDebug(doc) {
  10026. return printDoc(flattenDoc(doc));
  10027. }
  10028. };
  10029. var doc = {
  10030. builders: docBuilders,
  10031. printer: docPrinter,
  10032. utils: docUtils,
  10033. debug: docDebug
  10034. };
  10035. var mapDoc$1 = doc.utils.mapDoc;
  10036. function isNextLineEmpty$1(text, node, options) {
  10037. return util.isNextLineEmpty(text, node, options.locEnd);
  10038. }
  10039. function isPreviousLineEmpty$1(text, node, options) {
  10040. return util.isPreviousLineEmpty(text, node, options.locStart);
  10041. }
  10042. function getNextNonSpaceNonCommentCharacterIndex$1(text, node, options) {
  10043. return util.getNextNonSpaceNonCommentCharacterIndex(text, node, options.locEnd);
  10044. }
  10045. var utilShared = {
  10046. getMaxContinuousCount: util.getMaxContinuousCount,
  10047. getStringWidth: util.getStringWidth,
  10048. getAlignmentSize: util.getAlignmentSize,
  10049. getIndentSize: util.getIndentSize,
  10050. skip: util.skip,
  10051. skipWhitespace: util.skipWhitespace,
  10052. skipSpaces: util.skipSpaces,
  10053. skipNewline: util.skipNewline,
  10054. skipToLineEnd: util.skipToLineEnd,
  10055. skipEverythingButNewLine: util.skipEverythingButNewLine,
  10056. skipInlineComment: util.skipInlineComment,
  10057. skipTrailingComment: util.skipTrailingComment,
  10058. hasNewline: util.hasNewline,
  10059. hasNewlineInRange: util.hasNewlineInRange,
  10060. hasSpaces: util.hasSpaces,
  10061. isNextLineEmpty: isNextLineEmpty$1,
  10062. isNextLineEmptyAfterIndex: util.isNextLineEmptyAfterIndex,
  10063. isPreviousLineEmpty: isPreviousLineEmpty$1,
  10064. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$1,
  10065. mapDoc: mapDoc$1,
  10066. // TODO: remove in 2.0, we already exposed it in docUtils
  10067. makeString: util.makeString,
  10068. addLeadingComment: util.addLeadingComment,
  10069. addDanglingComment: util.addDanglingComment,
  10070. addTrailingComment: util.addTrailingComment
  10071. };
  10072. var _require$$0$builders = doc.builders,
  10073. concat$2 = _require$$0$builders.concat,
  10074. hardline$1 = _require$$0$builders.hardline,
  10075. breakParent$1 = _require$$0$builders.breakParent,
  10076. indent$1 = _require$$0$builders.indent,
  10077. lineSuffix$1 = _require$$0$builders.lineSuffix,
  10078. join$1 = _require$$0$builders.join,
  10079. cursor$2 = _require$$0$builders.cursor;
  10080. var hasNewline$1 = util.hasNewline,
  10081. skipNewline$1 = util.skipNewline,
  10082. isPreviousLineEmpty$2 = util.isPreviousLineEmpty;
  10083. var addLeadingComment$1 = utilShared.addLeadingComment,
  10084. addDanglingComment$1 = utilShared.addDanglingComment,
  10085. addTrailingComment$1 = utilShared.addTrailingComment;
  10086. var childNodesCacheKey = Symbol("child-nodes");
  10087. function getSortedChildNodes(node, options, resultArray) {
  10088. if (!node) {
  10089. return;
  10090. }
  10091. var printer = options.printer,
  10092. locStart = options.locStart,
  10093. locEnd = options.locEnd;
  10094. if (resultArray) {
  10095. if (node && printer.canAttachComment && printer.canAttachComment(node)) {
  10096. // This reverse insertion sort almost always takes constant
  10097. // time because we almost always (maybe always?) append the
  10098. // nodes in order anyway.
  10099. var i;
  10100. for (i = resultArray.length - 1; i >= 0; --i) {
  10101. if (locStart(resultArray[i]) <= locStart(node) && locEnd(resultArray[i]) <= locEnd(node)) {
  10102. break;
  10103. }
  10104. }
  10105. resultArray.splice(i + 1, 0, node);
  10106. return;
  10107. }
  10108. } else if (node[childNodesCacheKey]) {
  10109. return node[childNodesCacheKey];
  10110. }
  10111. var childNodes;
  10112. if (printer.getCommentChildNodes) {
  10113. childNodes = printer.getCommentChildNodes(node);
  10114. } else if (node && typeof node === "object") {
  10115. childNodes = Object.keys(node).filter(function (n) {
  10116. return n !== "enclosingNode" && n !== "precedingNode" && n !== "followingNode";
  10117. }).map(function (n) {
  10118. return node[n];
  10119. });
  10120. }
  10121. if (!childNodes) {
  10122. return;
  10123. }
  10124. if (!resultArray) {
  10125. Object.defineProperty(node, childNodesCacheKey, {
  10126. value: resultArray = [],
  10127. enumerable: false
  10128. });
  10129. }
  10130. childNodes.forEach(function (childNode) {
  10131. getSortedChildNodes(childNode, options, resultArray);
  10132. });
  10133. return resultArray;
  10134. } // As efficiently as possible, decorate the comment object with
  10135. // .precedingNode, .enclosingNode, and/or .followingNode properties, at
  10136. // least one of which is guaranteed to be defined.
  10137. function decorateComment(node, comment, options) {
  10138. var locStart = options.locStart,
  10139. locEnd = options.locEnd;
  10140. var childNodes = getSortedChildNodes(node, options);
  10141. var precedingNode;
  10142. var followingNode; // Time to dust off the old binary search robes and wizard hat.
  10143. var left = 0;
  10144. var right = childNodes.length;
  10145. while (left < right) {
  10146. var middle = left + right >> 1;
  10147. var child = childNodes[middle];
  10148. if (locStart(child) - locStart(comment) <= 0 && locEnd(comment) - locEnd(child) <= 0) {
  10149. // The comment is completely contained by this child node.
  10150. comment.enclosingNode = child;
  10151. decorateComment(child, comment, options);
  10152. return; // Abandon the binary search at this level.
  10153. }
  10154. if (locEnd(child) - locStart(comment) <= 0) {
  10155. // This child node falls completely before the comment.
  10156. // Because we will never consider this node or any nodes
  10157. // before it again, this node must be the closest preceding
  10158. // node we have encountered so far.
  10159. precedingNode = child;
  10160. left = middle + 1;
  10161. continue;
  10162. }
  10163. if (locEnd(comment) - locStart(child) <= 0) {
  10164. // This child node falls completely after the comment.
  10165. // Because we will never consider this node or any nodes after
  10166. // it again, this node must be the closest following node we
  10167. // have encountered so far.
  10168. followingNode = child;
  10169. right = middle;
  10170. continue;
  10171. }
  10172. /* istanbul ignore next */
  10173. throw new Error("Comment location overlaps with node location");
  10174. } // We don't want comments inside of different expressions inside of the same
  10175. // template literal to move to another expression.
  10176. if (comment.enclosingNode && comment.enclosingNode.type === "TemplateLiteral") {
  10177. var quasis = comment.enclosingNode.quasis;
  10178. var commentIndex = findExpressionIndexForComment(quasis, comment, options);
  10179. if (precedingNode && findExpressionIndexForComment(quasis, precedingNode, options) !== commentIndex) {
  10180. precedingNode = null;
  10181. }
  10182. if (followingNode && findExpressionIndexForComment(quasis, followingNode, options) !== commentIndex) {
  10183. followingNode = null;
  10184. }
  10185. }
  10186. if (precedingNode) {
  10187. comment.precedingNode = precedingNode;
  10188. }
  10189. if (followingNode) {
  10190. comment.followingNode = followingNode;
  10191. }
  10192. }
  10193. function attach(comments, ast, text, options) {
  10194. if (!Array.isArray(comments)) {
  10195. return;
  10196. }
  10197. var tiesToBreak = [];
  10198. var locStart = options.locStart,
  10199. locEnd = options.locEnd;
  10200. comments.forEach(function (comment, i) {
  10201. if (options.parser === "json" || options.parser === "json5" || options.parser === "__js_expression" || options.parser === "__vue_expression") {
  10202. if (locStart(comment) - locStart(ast) <= 0) {
  10203. addLeadingComment$1(ast, comment);
  10204. return;
  10205. }
  10206. if (locEnd(comment) - locEnd(ast) >= 0) {
  10207. addTrailingComment$1(ast, comment);
  10208. return;
  10209. }
  10210. }
  10211. decorateComment(ast, comment, options);
  10212. var precedingNode = comment.precedingNode,
  10213. enclosingNode = comment.enclosingNode,
  10214. followingNode = comment.followingNode;
  10215. var pluginHandleOwnLineComment = options.printer.handleComments && options.printer.handleComments.ownLine ? options.printer.handleComments.ownLine : function () {
  10216. return false;
  10217. };
  10218. var pluginHandleEndOfLineComment = options.printer.handleComments && options.printer.handleComments.endOfLine ? options.printer.handleComments.endOfLine : function () {
  10219. return false;
  10220. };
  10221. var pluginHandleRemainingComment = options.printer.handleComments && options.printer.handleComments.remaining ? options.printer.handleComments.remaining : function () {
  10222. return false;
  10223. };
  10224. var isLastComment = comments.length - 1 === i;
  10225. if (hasNewline$1(text, locStart(comment), {
  10226. backwards: true
  10227. })) {
  10228. // If a comment exists on its own line, prefer a leading comment.
  10229. // We also need to check if it's the first line of the file.
  10230. if (pluginHandleOwnLineComment(comment, text, options, ast, isLastComment)) ; else if (followingNode) {
  10231. // Always a leading comment.
  10232. addLeadingComment$1(followingNode, comment);
  10233. } else if (precedingNode) {
  10234. addTrailingComment$1(precedingNode, comment);
  10235. } else if (enclosingNode) {
  10236. addDanglingComment$1(enclosingNode, comment);
  10237. } else {
  10238. // There are no nodes, let's attach it to the root of the ast
  10239. /* istanbul ignore next */
  10240. addDanglingComment$1(ast, comment);
  10241. }
  10242. } else if (hasNewline$1(text, locEnd(comment))) {
  10243. if (pluginHandleEndOfLineComment(comment, text, options, ast, isLastComment)) ; else if (precedingNode) {
  10244. // There is content before this comment on the same line, but
  10245. // none after it, so prefer a trailing comment of the previous node.
  10246. addTrailingComment$1(precedingNode, comment);
  10247. } else if (followingNode) {
  10248. addLeadingComment$1(followingNode, comment);
  10249. } else if (enclosingNode) {
  10250. addDanglingComment$1(enclosingNode, comment);
  10251. } else {
  10252. // There are no nodes, let's attach it to the root of the ast
  10253. /* istanbul ignore next */
  10254. addDanglingComment$1(ast, comment);
  10255. }
  10256. } else {
  10257. if (pluginHandleRemainingComment(comment, text, options, ast, isLastComment)) ; else if (precedingNode && followingNode) {
  10258. // Otherwise, text exists both before and after the comment on
  10259. // the same line. If there is both a preceding and following
  10260. // node, use a tie-breaking algorithm to determine if it should
  10261. // be attached to the next or previous node. In the last case,
  10262. // simply attach the right node;
  10263. var tieCount = tiesToBreak.length;
  10264. if (tieCount > 0) {
  10265. var lastTie = tiesToBreak[tieCount - 1];
  10266. if (lastTie.followingNode !== comment.followingNode) {
  10267. breakTies(tiesToBreak, text, options);
  10268. }
  10269. }
  10270. tiesToBreak.push(comment);
  10271. } else if (precedingNode) {
  10272. addTrailingComment$1(precedingNode, comment);
  10273. } else if (followingNode) {
  10274. addLeadingComment$1(followingNode, comment);
  10275. } else if (enclosingNode) {
  10276. addDanglingComment$1(enclosingNode, comment);
  10277. } else {
  10278. // There are no nodes, let's attach it to the root of the ast
  10279. /* istanbul ignore next */
  10280. addDanglingComment$1(ast, comment);
  10281. }
  10282. }
  10283. });
  10284. breakTies(tiesToBreak, text, options);
  10285. comments.forEach(function (comment) {
  10286. // These node references were useful for breaking ties, but we
  10287. // don't need them anymore, and they create cycles in the AST that
  10288. // may lead to infinite recursion if we don't delete them here.
  10289. delete comment.precedingNode;
  10290. delete comment.enclosingNode;
  10291. delete comment.followingNode;
  10292. });
  10293. }
  10294. function breakTies(tiesToBreak, text, options) {
  10295. var tieCount = tiesToBreak.length;
  10296. if (tieCount === 0) {
  10297. return;
  10298. }
  10299. var _tiesToBreak$ = tiesToBreak[0],
  10300. precedingNode = _tiesToBreak$.precedingNode,
  10301. followingNode = _tiesToBreak$.followingNode;
  10302. var gapEndPos = options.locStart(followingNode); // Iterate backwards through tiesToBreak, examining the gaps
  10303. // between the tied comments. In order to qualify as leading, a
  10304. // comment must be separated from followingNode by an unbroken series of
  10305. // gaps (or other comments). Gaps should only contain whitespace or open
  10306. // parentheses.
  10307. var indexOfFirstLeadingComment;
  10308. for (indexOfFirstLeadingComment = tieCount; indexOfFirstLeadingComment > 0; --indexOfFirstLeadingComment) {
  10309. var comment = tiesToBreak[indexOfFirstLeadingComment - 1];
  10310. assert$1.strictEqual(comment.precedingNode, precedingNode);
  10311. assert$1.strictEqual(comment.followingNode, followingNode);
  10312. var gap = text.slice(options.locEnd(comment), gapEndPos);
  10313. if (/^[\s(]*$/.test(gap)) {
  10314. gapEndPos = options.locStart(comment);
  10315. } else {
  10316. // The gap string contained something other than whitespace or open
  10317. // parentheses.
  10318. break;
  10319. }
  10320. }
  10321. tiesToBreak.forEach(function (comment, i) {
  10322. if (i < indexOfFirstLeadingComment) {
  10323. addTrailingComment$1(precedingNode, comment);
  10324. } else {
  10325. addLeadingComment$1(followingNode, comment);
  10326. }
  10327. });
  10328. tiesToBreak.length = 0;
  10329. }
  10330. function printComment(commentPath, options) {
  10331. var comment = commentPath.getValue();
  10332. comment.printed = true;
  10333. return options.printer.printComment(commentPath, options);
  10334. }
  10335. function findExpressionIndexForComment(quasis, comment, options) {
  10336. var startPos = options.locStart(comment) - 1;
  10337. for (var i = 1; i < quasis.length; ++i) {
  10338. if (startPos < getQuasiRange(quasis[i]).start) {
  10339. return i - 1;
  10340. }
  10341. } // We haven't found it, it probably means that some of the locations are off.
  10342. // Let's just return the first one.
  10343. /* istanbul ignore next */
  10344. return 0;
  10345. }
  10346. function getQuasiRange(expr) {
  10347. if (expr.start !== undefined) {
  10348. // Babel
  10349. return {
  10350. start: expr.start,
  10351. end: expr.end
  10352. };
  10353. } // Flow
  10354. return {
  10355. start: expr.range[0],
  10356. end: expr.range[1]
  10357. };
  10358. }
  10359. function printLeadingComment(commentPath, print, options) {
  10360. var comment = commentPath.getValue();
  10361. var contents = printComment(commentPath, options);
  10362. if (!contents) {
  10363. return "";
  10364. }
  10365. var isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // Leading block comments should see if they need to stay on the
  10366. // same line or not.
  10367. if (isBlock) {
  10368. return concat$2([contents, hasNewline$1(options.originalText, options.locEnd(comment)) ? hardline$1 : " "]);
  10369. }
  10370. return concat$2([contents, hardline$1]);
  10371. }
  10372. function printTrailingComment(commentPath, print, options) {
  10373. var comment = commentPath.getValue();
  10374. var contents = printComment(commentPath, options);
  10375. if (!contents) {
  10376. return "";
  10377. }
  10378. var isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // We don't want the line to break
  10379. // when the parentParentNode is a ClassDeclaration/-Expression
  10380. // And the parentNode is in the superClass property
  10381. var parentNode = commentPath.getNode(1);
  10382. var parentParentNode = commentPath.getNode(2);
  10383. var isParentSuperClass = parentParentNode && (parentParentNode.type === "ClassDeclaration" || parentParentNode.type === "ClassExpression") && parentParentNode.superClass === parentNode;
  10384. if (hasNewline$1(options.originalText, options.locStart(comment), {
  10385. backwards: true
  10386. })) {
  10387. // This allows comments at the end of nested structures:
  10388. // {
  10389. // x: 1,
  10390. // y: 2
  10391. // // A comment
  10392. // }
  10393. // Those kinds of comments are almost always leading comments, but
  10394. // here it doesn't go "outside" the block and turns it into a
  10395. // trailing comment for `2`. We can simulate the above by checking
  10396. // if this a comment on its own line; normal trailing comments are
  10397. // always at the end of another expression.
  10398. var isLineBeforeEmpty = isPreviousLineEmpty$2(options.originalText, comment, options.locStart);
  10399. return lineSuffix$1(concat$2([hardline$1, isLineBeforeEmpty ? hardline$1 : "", contents]));
  10400. } else if (isBlock || isParentSuperClass) {
  10401. // Trailing block comments never need a newline
  10402. return concat$2([" ", contents]);
  10403. }
  10404. return concat$2([lineSuffix$1(concat$2([" ", contents])), !isBlock ? breakParent$1 : ""]);
  10405. }
  10406. function printDanglingComments(path, options, sameIndent, filter) {
  10407. var parts = [];
  10408. var node = path.getValue();
  10409. if (!node || !node.comments) {
  10410. return "";
  10411. }
  10412. path.each(function (commentPath) {
  10413. var comment = commentPath.getValue();
  10414. if (comment && !comment.leading && !comment.trailing && (!filter || filter(comment))) {
  10415. parts.push(printComment(commentPath, options));
  10416. }
  10417. }, "comments");
  10418. if (parts.length === 0) {
  10419. return "";
  10420. }
  10421. if (sameIndent) {
  10422. return join$1(hardline$1, parts);
  10423. }
  10424. return indent$1(concat$2([hardline$1, join$1(hardline$1, parts)]));
  10425. }
  10426. function prependCursorPlaceholder(path, options, printed) {
  10427. if (path.getNode() === options.cursorNode && path.getValue()) {
  10428. return concat$2([cursor$2, printed, cursor$2]);
  10429. }
  10430. return printed;
  10431. }
  10432. function printComments(path, print, options, needsSemi) {
  10433. var value = path.getValue();
  10434. var printed = print(path);
  10435. var comments = value && value.comments;
  10436. if (!comments || comments.length === 0) {
  10437. return prependCursorPlaceholder(path, options, printed);
  10438. }
  10439. var leadingParts = [];
  10440. var trailingParts = [needsSemi ? ";" : "", printed];
  10441. path.each(function (commentPath) {
  10442. var comment = commentPath.getValue();
  10443. var leading = comment.leading,
  10444. trailing = comment.trailing;
  10445. if (leading) {
  10446. var contents = printLeadingComment(commentPath, print, options);
  10447. if (!contents) {
  10448. return;
  10449. }
  10450. leadingParts.push(contents);
  10451. var text = options.originalText;
  10452. var index = skipNewline$1(text, options.locEnd(comment));
  10453. if (index !== false && hasNewline$1(text, index)) {
  10454. leadingParts.push(hardline$1);
  10455. }
  10456. } else if (trailing) {
  10457. trailingParts.push(printTrailingComment(commentPath, print, options));
  10458. }
  10459. }, "comments");
  10460. return prependCursorPlaceholder(path, options, concat$2(leadingParts.concat(trailingParts)));
  10461. }
  10462. var comments = {
  10463. attach,
  10464. printComments,
  10465. printDanglingComments,
  10466. getSortedChildNodes
  10467. };
  10468. function FastPath(value) {
  10469. assert$1.ok(this instanceof FastPath);
  10470. this.stack = [value];
  10471. } // The name of the current property is always the penultimate element of
  10472. // this.stack, and always a String.
  10473. FastPath.prototype.getName = function getName() {
  10474. var s = this.stack;
  10475. var len = s.length;
  10476. if (len > 1) {
  10477. return s[len - 2];
  10478. } // Since the name is always a string, null is a safe sentinel value to
  10479. // return if we do not know the name of the (root) value.
  10480. /* istanbul ignore next */
  10481. return null;
  10482. }; // The value of the current property is always the final element of
  10483. // this.stack.
  10484. FastPath.prototype.getValue = function getValue() {
  10485. var s = this.stack;
  10486. return s[s.length - 1];
  10487. };
  10488. function getNodeHelper(path, count) {
  10489. var stackIndex = getNodeStackIndexHelper(path.stack, count);
  10490. return stackIndex === -1 ? null : path.stack[stackIndex];
  10491. }
  10492. function getNodeStackIndexHelper(stack, count) {
  10493. for (var i = stack.length - 1; i >= 0; i -= 2) {
  10494. var value = stack[i];
  10495. if (value && !Array.isArray(value) && --count < 0) {
  10496. return i;
  10497. }
  10498. }
  10499. return -1;
  10500. }
  10501. FastPath.prototype.getNode = function getNode(count) {
  10502. return getNodeHelper(this, ~~count);
  10503. };
  10504. FastPath.prototype.getParentNode = function getParentNode(count) {
  10505. return getNodeHelper(this, ~~count + 1);
  10506. }; // Temporarily push properties named by string arguments given after the
  10507. // callback function onto this.stack, then call the callback with a
  10508. // reference to this (modified) FastPath object. Note that the stack will
  10509. // be restored to its original state after the callback is finished, so it
  10510. // is probably a mistake to retain a reference to the path.
  10511. FastPath.prototype.call = function call(callback
  10512. /*, name1, name2, ... */
  10513. ) {
  10514. var s = this.stack;
  10515. var origLen = s.length;
  10516. var value = s[origLen - 1];
  10517. var argc = arguments.length;
  10518. for (var i = 1; i < argc; ++i) {
  10519. var name = arguments[i];
  10520. value = value[name];
  10521. s.push(name, value);
  10522. }
  10523. var result = callback(this);
  10524. s.length = origLen;
  10525. return result;
  10526. };
  10527. FastPath.prototype.callParent = function callParent(callback, count) {
  10528. var stackIndex = getNodeStackIndexHelper(this.stack, ~~count + 1);
  10529. var parentValues = this.stack.splice(stackIndex + 1);
  10530. var result = callback(this);
  10531. Array.prototype.push.apply(this.stack, parentValues);
  10532. return result;
  10533. }; // Similar to FastPath.prototype.call, except that the value obtained by
  10534. // accessing this.getValue()[name1][name2]... should be array-like. The
  10535. // callback will be called with a reference to this path object for each
  10536. // element of the array.
  10537. FastPath.prototype.each = function each(callback
  10538. /*, name1, name2, ... */
  10539. ) {
  10540. var s = this.stack;
  10541. var origLen = s.length;
  10542. var value = s[origLen - 1];
  10543. var argc = arguments.length;
  10544. for (var i = 1; i < argc; ++i) {
  10545. var name = arguments[i];
  10546. value = value[name];
  10547. s.push(name, value);
  10548. }
  10549. for (var _i = 0; _i < value.length; ++_i) {
  10550. if (_i in value) {
  10551. s.push(_i, value[_i]); // If the callback needs to know the value of i, call
  10552. // path.getName(), assuming path is the parameter name.
  10553. callback(this);
  10554. s.length -= 2;
  10555. }
  10556. }
  10557. s.length = origLen;
  10558. }; // Similar to FastPath.prototype.each, except that the results of the
  10559. // callback function invocations are stored in an array and returned at
  10560. // the end of the iteration.
  10561. FastPath.prototype.map = function map(callback
  10562. /*, name1, name2, ... */
  10563. ) {
  10564. var s = this.stack;
  10565. var origLen = s.length;
  10566. var value = s[origLen - 1];
  10567. var argc = arguments.length;
  10568. for (var i = 1; i < argc; ++i) {
  10569. var name = arguments[i];
  10570. value = value[name];
  10571. s.push(name, value);
  10572. }
  10573. var result = new Array(value.length);
  10574. for (var _i2 = 0; _i2 < value.length; ++_i2) {
  10575. if (_i2 in value) {
  10576. s.push(_i2, value[_i2]);
  10577. result[_i2] = callback(this, _i2);
  10578. s.length -= 2;
  10579. }
  10580. }
  10581. s.length = origLen;
  10582. return result;
  10583. };
  10584. var fastPath = FastPath;
  10585. var normalize$2 = options$1.normalize;
  10586. function printSubtree(path, print, options, printAstToDoc) {
  10587. if (options.printer.embed) {
  10588. return options.printer.embed(path, print, function (text, partialNextOptions) {
  10589. return textToDoc(text, partialNextOptions, options, printAstToDoc);
  10590. }, options);
  10591. }
  10592. }
  10593. function textToDoc(text, partialNextOptions, parentOptions, printAstToDoc) {
  10594. var nextOptions = normalize$2(Object.assign({}, parentOptions, partialNextOptions, {
  10595. parentParser: parentOptions.parser,
  10596. embeddedInHtml: !!(parentOptions.embeddedInHtml || parentOptions.parser === "html" || parentOptions.parser === "vue" || parentOptions.parser === "angular" || parentOptions.parser === "lwc"),
  10597. originalText: text
  10598. }), {
  10599. passThrough: true
  10600. });
  10601. var result = parser.parse(text, nextOptions);
  10602. var ast = result.ast;
  10603. text = result.text;
  10604. var astComments = ast.comments;
  10605. delete ast.comments;
  10606. comments.attach(astComments, ast, text, nextOptions);
  10607. return printAstToDoc(ast, nextOptions);
  10608. }
  10609. var multiparser = {
  10610. printSubtree
  10611. };
  10612. var doc$1 = doc;
  10613. var docBuilders$1 = doc$1.builders;
  10614. var concat$3 = docBuilders$1.concat;
  10615. var hardline$2 = docBuilders$1.hardline;
  10616. var addAlignmentToDoc$1 = docBuilders$1.addAlignmentToDoc;
  10617. var docUtils$1 = doc$1.utils;
  10618. /**
  10619. * Takes an abstract syntax tree (AST) and recursively converts it to a
  10620. * document (series of printing primitives).
  10621. *
  10622. * This is done by descending down the AST recursively. The recursion
  10623. * involves two functions that call each other:
  10624. *
  10625. * 1. printGenerically(), which is defined as an inner function here.
  10626. * It basically takes care of node caching.
  10627. * 2. callPluginPrintFunction(), which checks for some options, and
  10628. * ultimately calls the print() function provided by the plugin.
  10629. *
  10630. * The plugin function will call printGenerically() again for child nodes
  10631. * of the current node, which will do its housekeeping, then call the
  10632. * plugin function again, and so on.
  10633. *
  10634. * All the while, these functions pass a "path" variable around, which
  10635. * is a stack-like data structure (FastPath) that maintains the current
  10636. * state of the recursion. It is called "path", because it represents
  10637. * the path to the current node through the Abstract Syntax Tree.
  10638. */
  10639. function printAstToDoc(ast, options) {
  10640. var alignmentSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  10641. var printer = options.printer;
  10642. if (printer.preprocess) {
  10643. ast = printer.preprocess(ast, options);
  10644. }
  10645. var cache = new Map();
  10646. function printGenerically(path, args) {
  10647. var node = path.getValue();
  10648. var shouldCache = node && typeof node === "object" && args === undefined;
  10649. if (shouldCache && cache.has(node)) {
  10650. return cache.get(node);
  10651. } // We let JSXElement print its comments itself because it adds () around
  10652. // UnionTypeAnnotation has to align the child without the comments
  10653. var res;
  10654. if (printer.willPrintOwnComments && printer.willPrintOwnComments(path, options)) {
  10655. res = callPluginPrintFunction(path, options, printGenerically, args);
  10656. } else {
  10657. // printComments will call the plugin print function and check for
  10658. // comments to print
  10659. res = comments.printComments(path, function (p) {
  10660. return callPluginPrintFunction(p, options, printGenerically, args);
  10661. }, options, args && args.needsSemi);
  10662. }
  10663. if (shouldCache) {
  10664. cache.set(node, res);
  10665. }
  10666. return res;
  10667. }
  10668. var doc = printGenerically(new fastPath(ast));
  10669. if (alignmentSize > 0) {
  10670. // Add a hardline to make the indents take effect
  10671. // It should be removed in index.js format()
  10672. doc = addAlignmentToDoc$1(concat$3([hardline$2, doc]), alignmentSize, options.tabWidth);
  10673. }
  10674. docUtils$1.propagateBreaks(doc);
  10675. return doc;
  10676. }
  10677. function callPluginPrintFunction(path, options, printPath, args) {
  10678. assert$1.ok(path instanceof fastPath);
  10679. var node = path.getValue();
  10680. var printer = options.printer; // Escape hatch
  10681. if (printer.hasPrettierIgnore && printer.hasPrettierIgnore(path)) {
  10682. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  10683. }
  10684. if (node) {
  10685. try {
  10686. // Potentially switch to a different parser
  10687. var sub = multiparser.printSubtree(path, printPath, options, printAstToDoc);
  10688. if (sub) {
  10689. return sub;
  10690. }
  10691. } catch (error) {
  10692. /* istanbul ignore if */
  10693. if (process.env.PRETTIER_DEBUG) {
  10694. throw error;
  10695. } // Continue with current parser
  10696. }
  10697. }
  10698. return printer.print(path, options, printPath, args);
  10699. }
  10700. var astToDoc = printAstToDoc;
  10701. function findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts) {
  10702. var resultStartNode = startNodeAndParents.node;
  10703. var resultEndNode = endNodeAndParents.node;
  10704. if (resultStartNode === resultEndNode) {
  10705. return {
  10706. startNode: resultStartNode,
  10707. endNode: resultEndNode
  10708. };
  10709. }
  10710. var _iteratorNormalCompletion = true;
  10711. var _didIteratorError = false;
  10712. var _iteratorError = undefined;
  10713. try {
  10714. for (var _iterator = endNodeAndParents.parentNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  10715. var endParent = _step.value;
  10716. if (endParent.type !== "Program" && endParent.type !== "File" && opts.locStart(endParent) >= opts.locStart(startNodeAndParents.node)) {
  10717. resultEndNode = endParent;
  10718. } else {
  10719. break;
  10720. }
  10721. }
  10722. } catch (err) {
  10723. _didIteratorError = true;
  10724. _iteratorError = err;
  10725. } finally {
  10726. try {
  10727. if (!_iteratorNormalCompletion && _iterator.return != null) {
  10728. _iterator.return();
  10729. }
  10730. } finally {
  10731. if (_didIteratorError) {
  10732. throw _iteratorError;
  10733. }
  10734. }
  10735. }
  10736. var _iteratorNormalCompletion2 = true;
  10737. var _didIteratorError2 = false;
  10738. var _iteratorError2 = undefined;
  10739. try {
  10740. for (var _iterator2 = startNodeAndParents.parentNodes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  10741. var startParent = _step2.value;
  10742. if (startParent.type !== "Program" && startParent.type !== "File" && opts.locEnd(startParent) <= opts.locEnd(endNodeAndParents.node)) {
  10743. resultStartNode = startParent;
  10744. } else {
  10745. break;
  10746. }
  10747. }
  10748. } catch (err) {
  10749. _didIteratorError2 = true;
  10750. _iteratorError2 = err;
  10751. } finally {
  10752. try {
  10753. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  10754. _iterator2.return();
  10755. }
  10756. } finally {
  10757. if (_didIteratorError2) {
  10758. throw _iteratorError2;
  10759. }
  10760. }
  10761. }
  10762. return {
  10763. startNode: resultStartNode,
  10764. endNode: resultEndNode
  10765. };
  10766. }
  10767. function findNodeAtOffset(node, offset, options, predicate, parentNodes) {
  10768. predicate = predicate || function () {
  10769. return true;
  10770. };
  10771. parentNodes = parentNodes || [];
  10772. var start = options.locStart(node, options.locStart);
  10773. var end = options.locEnd(node, options.locEnd);
  10774. if (start <= offset && offset <= end) {
  10775. var _iteratorNormalCompletion3 = true;
  10776. var _didIteratorError3 = false;
  10777. var _iteratorError3 = undefined;
  10778. try {
  10779. for (var _iterator3 = comments.getSortedChildNodes(node, options)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  10780. var childNode = _step3.value;
  10781. var childResult = findNodeAtOffset(childNode, offset, options, predicate, [node].concat(parentNodes));
  10782. if (childResult) {
  10783. return childResult;
  10784. }
  10785. }
  10786. } catch (err) {
  10787. _didIteratorError3 = true;
  10788. _iteratorError3 = err;
  10789. } finally {
  10790. try {
  10791. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  10792. _iterator3.return();
  10793. }
  10794. } finally {
  10795. if (_didIteratorError3) {
  10796. throw _iteratorError3;
  10797. }
  10798. }
  10799. }
  10800. if (predicate(node)) {
  10801. return {
  10802. node: node,
  10803. parentNodes: parentNodes
  10804. };
  10805. }
  10806. }
  10807. } // See https://www.ecma-international.org/ecma-262/5.1/#sec-A.5
  10808. function isSourceElement(opts, node) {
  10809. if (node == null) {
  10810. return false;
  10811. } // JS and JS like to avoid repetitions
  10812. var jsSourceElements = ["FunctionDeclaration", "BlockStatement", "BreakStatement", "ContinueStatement", "DebuggerStatement", "DoWhileStatement", "EmptyStatement", "ExpressionStatement", "ForInStatement", "ForStatement", "IfStatement", "LabeledStatement", "ReturnStatement", "SwitchStatement", "ThrowStatement", "TryStatement", "VariableDeclaration", "WhileStatement", "WithStatement", "ClassDeclaration", // ES 2015
  10813. "ImportDeclaration", // Module
  10814. "ExportDefaultDeclaration", // Module
  10815. "ExportNamedDeclaration", // Module
  10816. "ExportAllDeclaration", // Module
  10817. "TypeAlias", // Flow
  10818. "InterfaceDeclaration", // Flow, TypeScript
  10819. "TypeAliasDeclaration", // TypeScript
  10820. "ExportAssignment", // TypeScript
  10821. "ExportDeclaration" // TypeScript
  10822. ];
  10823. var jsonSourceElements = ["ObjectExpression", "ArrayExpression", "StringLiteral", "NumericLiteral", "BooleanLiteral", "NullLiteral"];
  10824. var graphqlSourceElements = ["OperationDefinition", "FragmentDefinition", "VariableDefinition", "TypeExtensionDefinition", "ObjectTypeDefinition", "FieldDefinition", "DirectiveDefinition", "EnumTypeDefinition", "EnumValueDefinition", "InputValueDefinition", "InputObjectTypeDefinition", "SchemaDefinition", "OperationTypeDefinition", "InterfaceTypeDefinition", "UnionTypeDefinition", "ScalarTypeDefinition"];
  10825. switch (opts.parser) {
  10826. case "flow":
  10827. case "babel":
  10828. case "typescript":
  10829. return jsSourceElements.indexOf(node.type) > -1;
  10830. case "json":
  10831. return jsonSourceElements.indexOf(node.type) > -1;
  10832. case "graphql":
  10833. return graphqlSourceElements.indexOf(node.kind) > -1;
  10834. case "vue":
  10835. return node.tag !== "root";
  10836. }
  10837. return false;
  10838. }
  10839. function calculateRange(text, opts, ast) {
  10840. // Contract the range so that it has non-whitespace characters at its endpoints.
  10841. // This ensures we can format a range that doesn't end on a node.
  10842. var rangeStringOrig = text.slice(opts.rangeStart, opts.rangeEnd);
  10843. var startNonWhitespace = Math.max(opts.rangeStart + rangeStringOrig.search(/\S/), opts.rangeStart);
  10844. var endNonWhitespace;
  10845. for (endNonWhitespace = opts.rangeEnd; endNonWhitespace > opts.rangeStart; --endNonWhitespace) {
  10846. if (text[endNonWhitespace - 1].match(/\S/)) {
  10847. break;
  10848. }
  10849. }
  10850. var startNodeAndParents = findNodeAtOffset(ast, startNonWhitespace, opts, function (node) {
  10851. return isSourceElement(opts, node);
  10852. });
  10853. var endNodeAndParents = findNodeAtOffset(ast, endNonWhitespace, opts, function (node) {
  10854. return isSourceElement(opts, node);
  10855. });
  10856. if (!startNodeAndParents || !endNodeAndParents) {
  10857. return {
  10858. rangeStart: 0,
  10859. rangeEnd: 0
  10860. };
  10861. }
  10862. var siblingAncestors = findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts);
  10863. var startNode = siblingAncestors.startNode,
  10864. endNode = siblingAncestors.endNode;
  10865. var rangeStart = Math.min(opts.locStart(startNode, opts.locStart), opts.locStart(endNode, opts.locStart));
  10866. var rangeEnd = Math.max(opts.locEnd(startNode, opts.locEnd), opts.locEnd(endNode, opts.locEnd));
  10867. return {
  10868. rangeStart: rangeStart,
  10869. rangeEnd: rangeEnd
  10870. };
  10871. }
  10872. var rangeUtil = {
  10873. calculateRange,
  10874. findNodeAtOffset
  10875. };
  10876. var normalizeOptions$1 = options$1.normalize;
  10877. var guessEndOfLine$1 = endOfLine.guessEndOfLine,
  10878. convertEndOfLineToChars$2 = endOfLine.convertEndOfLineToChars;
  10879. var mapDoc$2 = doc.utils.mapDoc,
  10880. printDocToString$1 = doc.printer.printDocToString,
  10881. printDocToDebug = doc.debug.printDocToDebug;
  10882. var UTF8BOM = 0xfeff;
  10883. var CURSOR = Symbol("cursor");
  10884. var PLACEHOLDERS = {
  10885. cursorOffset: "<<<PRETTIER_CURSOR>>>",
  10886. rangeStart: "<<<PRETTIER_RANGE_START>>>",
  10887. rangeEnd: "<<<PRETTIER_RANGE_END>>>"
  10888. };
  10889. function ensureAllCommentsPrinted(astComments) {
  10890. if (!astComments) {
  10891. return;
  10892. }
  10893. for (var i = 0; i < astComments.length; ++i) {
  10894. if (astComments[i].value.trim() === "prettier-ignore") {
  10895. // If there's a prettier-ignore, we're not printing that sub-tree so we
  10896. // don't know if the comments was printed or not.
  10897. return;
  10898. }
  10899. }
  10900. astComments.forEach(function (comment) {
  10901. if (!comment.printed) {
  10902. throw new Error('Comment "' + comment.value.trim() + '" was not printed. Please report this error!');
  10903. }
  10904. delete comment.printed;
  10905. });
  10906. }
  10907. function attachComments(text, ast, opts) {
  10908. var astComments = ast.comments;
  10909. if (astComments) {
  10910. delete ast.comments;
  10911. comments.attach(astComments, ast, text, opts);
  10912. }
  10913. ast.tokens = [];
  10914. opts.originalText = opts.parser === "yaml" ? text : text.trimRight();
  10915. return astComments;
  10916. }
  10917. function coreFormat(text, opts, addAlignmentSize) {
  10918. if (!text || !text.trim().length) {
  10919. return {
  10920. formatted: "",
  10921. cursorOffset: 0
  10922. };
  10923. }
  10924. addAlignmentSize = addAlignmentSize || 0;
  10925. var parsed = parser.parse(text, opts);
  10926. var ast = parsed.ast;
  10927. text = parsed.text;
  10928. if (opts.cursorOffset >= 0) {
  10929. var nodeResult = rangeUtil.findNodeAtOffset(ast, opts.cursorOffset, opts);
  10930. if (nodeResult && nodeResult.node) {
  10931. opts.cursorNode = nodeResult.node;
  10932. }
  10933. }
  10934. var astComments = attachComments(text, ast, opts);
  10935. var doc = astToDoc(ast, opts, addAlignmentSize);
  10936. var eol = convertEndOfLineToChars$2(opts.endOfLine);
  10937. var result = printDocToString$1(opts.endOfLine === "lf" ? doc : mapDoc$2(doc, function (currentDoc) {
  10938. return typeof currentDoc === "string" && currentDoc.indexOf("\n") !== -1 ? currentDoc.replace(/\n/g, eol) : currentDoc;
  10939. }), opts);
  10940. ensureAllCommentsPrinted(astComments); // Remove extra leading indentation as well as the added indentation after last newline
  10941. if (addAlignmentSize > 0) {
  10942. var trimmed = result.formatted.trim();
  10943. if (result.cursorNodeStart !== undefined) {
  10944. result.cursorNodeStart -= result.formatted.indexOf(trimmed);
  10945. }
  10946. result.formatted = trimmed + convertEndOfLineToChars$2(opts.endOfLine);
  10947. }
  10948. if (opts.cursorOffset >= 0) {
  10949. var oldCursorNodeStart;
  10950. var oldCursorNodeText;
  10951. var cursorOffsetRelativeToOldCursorNode;
  10952. var newCursorNodeStart;
  10953. var newCursorNodeText;
  10954. if (opts.cursorNode && result.cursorNodeText) {
  10955. oldCursorNodeStart = opts.locStart(opts.cursorNode);
  10956. oldCursorNodeText = text.slice(oldCursorNodeStart, opts.locEnd(opts.cursorNode));
  10957. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset - oldCursorNodeStart;
  10958. newCursorNodeStart = result.cursorNodeStart;
  10959. newCursorNodeText = result.cursorNodeText;
  10960. } else {
  10961. oldCursorNodeStart = 0;
  10962. oldCursorNodeText = text;
  10963. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset;
  10964. newCursorNodeStart = 0;
  10965. newCursorNodeText = result.formatted;
  10966. }
  10967. if (oldCursorNodeText === newCursorNodeText) {
  10968. return {
  10969. formatted: result.formatted,
  10970. cursorOffset: newCursorNodeStart + cursorOffsetRelativeToOldCursorNode
  10971. };
  10972. } // diff old and new cursor node texts, with a special cursor
  10973. // symbol inserted to find out where it moves to
  10974. var oldCursorNodeCharArray = oldCursorNodeText.split("");
  10975. oldCursorNodeCharArray.splice(cursorOffsetRelativeToOldCursorNode, 0, CURSOR);
  10976. var newCursorNodeCharArray = newCursorNodeText.split("");
  10977. var cursorNodeDiff = index_es6.diffArrays(oldCursorNodeCharArray, newCursorNodeCharArray);
  10978. var cursorOffset = newCursorNodeStart;
  10979. var _iteratorNormalCompletion = true;
  10980. var _didIteratorError = false;
  10981. var _iteratorError = undefined;
  10982. try {
  10983. for (var _iterator = cursorNodeDiff[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  10984. var entry = _step.value;
  10985. if (entry.removed) {
  10986. if (entry.value.indexOf(CURSOR) > -1) {
  10987. break;
  10988. }
  10989. } else {
  10990. cursorOffset += entry.count;
  10991. }
  10992. }
  10993. } catch (err) {
  10994. _didIteratorError = true;
  10995. _iteratorError = err;
  10996. } finally {
  10997. try {
  10998. if (!_iteratorNormalCompletion && _iterator.return != null) {
  10999. _iterator.return();
  11000. }
  11001. } finally {
  11002. if (_didIteratorError) {
  11003. throw _iteratorError;
  11004. }
  11005. }
  11006. }
  11007. return {
  11008. formatted: result.formatted,
  11009. cursorOffset
  11010. };
  11011. }
  11012. return {
  11013. formatted: result.formatted
  11014. };
  11015. }
  11016. function formatRange(text, opts) {
  11017. var parsed = parser.parse(text, opts);
  11018. var ast = parsed.ast;
  11019. text = parsed.text;
  11020. var range = rangeUtil.calculateRange(text, opts, ast);
  11021. var rangeStart = range.rangeStart;
  11022. var rangeEnd = range.rangeEnd;
  11023. var rangeString = text.slice(rangeStart, rangeEnd); // Try to extend the range backwards to the beginning of the line.
  11024. // This is so we can detect indentation correctly and restore it.
  11025. // Use `Math.min` since `lastIndexOf` returns 0 when `rangeStart` is 0
  11026. var rangeStart2 = Math.min(rangeStart, text.lastIndexOf("\n", rangeStart) + 1);
  11027. var indentString = text.slice(rangeStart2, rangeStart);
  11028. var alignmentSize = util.getAlignmentSize(indentString, opts.tabWidth);
  11029. var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
  11030. rangeStart: 0,
  11031. rangeEnd: Infinity,
  11032. // track the cursor offset only if it's within our range
  11033. cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
  11034. }), alignmentSize); // Since the range contracts to avoid trailing whitespace,
  11035. // we need to remove the newline that was inserted by the `format` call.
  11036. var rangeTrimmed = rangeResult.formatted.trimRight();
  11037. var rangeLeft = text.slice(0, rangeStart);
  11038. var rangeRight = text.slice(rangeEnd);
  11039. var cursorOffset = opts.cursorOffset;
  11040. if (opts.cursorOffset >= rangeEnd) {
  11041. // handle the case where the cursor was past the end of the range
  11042. cursorOffset = opts.cursorOffset - rangeEnd + (rangeStart + rangeTrimmed.length);
  11043. } else if (rangeResult.cursorOffset !== undefined) {
  11044. // handle the case where the cursor was in the range
  11045. cursorOffset = rangeResult.cursorOffset + rangeStart;
  11046. } // keep the cursor as it was if it was before the start of the range
  11047. var formatted;
  11048. if (opts.endOfLine === "lf") {
  11049. formatted = rangeLeft + rangeTrimmed + rangeRight;
  11050. } else {
  11051. var eol = convertEndOfLineToChars$2(opts.endOfLine);
  11052. if (cursorOffset >= 0) {
  11053. var parts = [rangeLeft, rangeTrimmed, rangeRight];
  11054. var partIndex = 0;
  11055. var partOffset = cursorOffset;
  11056. while (partIndex < parts.length) {
  11057. var part = parts[partIndex];
  11058. if (partOffset < part.length) {
  11059. parts[partIndex] = parts[partIndex].slice(0, partOffset) + PLACEHOLDERS.cursorOffset + parts[partIndex].slice(partOffset);
  11060. break;
  11061. }
  11062. partIndex++;
  11063. partOffset -= part.length;
  11064. }
  11065. var newRangeLeft = parts[0],
  11066. newRangeTrimmed = parts[1],
  11067. newRangeRight = parts[2];
  11068. formatted = (newRangeLeft.replace(/\n/g, eol) + newRangeTrimmed + newRangeRight.replace(/\n/g, eol)).replace(PLACEHOLDERS.cursorOffset, function (_, index) {
  11069. cursorOffset = index;
  11070. return "";
  11071. });
  11072. } else {
  11073. formatted = rangeLeft.replace(/\n/g, eol) + rangeTrimmed + rangeRight.replace(/\n/g, eol);
  11074. }
  11075. }
  11076. return {
  11077. formatted,
  11078. cursorOffset
  11079. };
  11080. }
  11081. function format(text, opts) {
  11082. var selectedParser = parser.resolveParser(opts);
  11083. var hasPragma = !selectedParser.hasPragma || selectedParser.hasPragma(text);
  11084. if (opts.requirePragma && !hasPragma) {
  11085. return {
  11086. formatted: text
  11087. };
  11088. }
  11089. if (opts.endOfLine === "auto") {
  11090. opts.endOfLine = guessEndOfLine$1(text);
  11091. }
  11092. var hasCursor = opts.cursorOffset >= 0;
  11093. var hasRangeStart = opts.rangeStart > 0;
  11094. var hasRangeEnd = opts.rangeEnd < text.length; // get rid of CR/CRLF parsing
  11095. if (text.indexOf("\r") !== -1) {
  11096. var offsetKeys = [hasCursor && "cursorOffset", hasRangeStart && "rangeStart", hasRangeEnd && "rangeEnd"].filter(Boolean).sort(function (aKey, bKey) {
  11097. return opts[aKey] - opts[bKey];
  11098. });
  11099. for (var i = offsetKeys.length - 1; i >= 0; i--) {
  11100. var key = offsetKeys[i];
  11101. text = text.slice(0, opts[key]) + PLACEHOLDERS[key] + text.slice(opts[key]);
  11102. }
  11103. text = text.replace(/\r\n?/g, "\n");
  11104. var _loop = function _loop(_i) {
  11105. var key = offsetKeys[_i];
  11106. text = text.replace(PLACEHOLDERS[key], function (_, index) {
  11107. opts[key] = index;
  11108. return "";
  11109. });
  11110. };
  11111. for (var _i = 0; _i < offsetKeys.length; _i++) {
  11112. _loop(_i);
  11113. }
  11114. }
  11115. var hasUnicodeBOM = text.charCodeAt(0) === UTF8BOM;
  11116. if (hasUnicodeBOM) {
  11117. text = text.substring(1);
  11118. if (hasCursor) {
  11119. opts.cursorOffset++;
  11120. }
  11121. if (hasRangeStart) {
  11122. opts.rangeStart++;
  11123. }
  11124. if (hasRangeEnd) {
  11125. opts.rangeEnd++;
  11126. }
  11127. }
  11128. if (!hasCursor) {
  11129. opts.cursorOffset = -1;
  11130. }
  11131. if (opts.rangeStart < 0) {
  11132. opts.rangeStart = 0;
  11133. }
  11134. if (opts.rangeEnd > text.length) {
  11135. opts.rangeEnd = text.length;
  11136. }
  11137. var result = hasRangeStart || hasRangeEnd ? formatRange(text, opts) : coreFormat(opts.insertPragma && opts.printer.insertPragma && !hasPragma ? opts.printer.insertPragma(text) : text, opts);
  11138. if (hasUnicodeBOM) {
  11139. result.formatted = String.fromCharCode(UTF8BOM) + result.formatted;
  11140. if (hasCursor) {
  11141. result.cursorOffset++;
  11142. }
  11143. }
  11144. return result;
  11145. }
  11146. var core = {
  11147. formatWithCursor(text, opts) {
  11148. opts = normalizeOptions$1(opts);
  11149. return format(text, opts);
  11150. },
  11151. parse(text, opts, massage) {
  11152. opts = normalizeOptions$1(opts);
  11153. if (text.indexOf("\r") !== -1) {
  11154. text = text.replace(/\r\n?/g, "\n");
  11155. }
  11156. var parsed = parser.parse(text, opts);
  11157. if (massage) {
  11158. parsed.ast = massageAst(parsed.ast, opts);
  11159. }
  11160. return parsed;
  11161. },
  11162. formatAST(ast, opts) {
  11163. opts = normalizeOptions$1(opts);
  11164. var doc = astToDoc(ast, opts);
  11165. return printDocToString$1(doc, opts);
  11166. },
  11167. // Doesn't handle shebang for now
  11168. formatDoc(doc, opts) {
  11169. var debug = printDocToDebug(doc);
  11170. opts = normalizeOptions$1(Object.assign({}, opts, {
  11171. parser: "babel"
  11172. }));
  11173. return format(debug, opts).formatted;
  11174. },
  11175. printToDoc(text, opts) {
  11176. opts = normalizeOptions$1(opts);
  11177. var parsed = parser.parse(text, opts);
  11178. var ast = parsed.ast;
  11179. text = parsed.text;
  11180. attachComments(text, ast, opts);
  11181. return astToDoc(ast, opts);
  11182. },
  11183. printDocToString(doc, opts) {
  11184. return printDocToString$1(doc, normalizeOptions$1(opts));
  11185. }
  11186. };
  11187. // A simple implementation of make-array
  11188. function make_array(subject) {
  11189. return Array.isArray(subject) ? subject : [subject];
  11190. }
  11191. var REGEX_BLANK_LINE = /^\s+$/;
  11192. var REGEX_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
  11193. var REGEX_LEADING_EXCAPED_HASH = /^\\#/;
  11194. var SLASH = '/';
  11195. var KEY_IGNORE = typeof Symbol !== 'undefined' ? Symbol.for('node-ignore')
  11196. /* istanbul ignore next */
  11197. : 'node-ignore';
  11198. var define = function define(object, key, value) {
  11199. return Object.defineProperty(object, key, {
  11200. value
  11201. });
  11202. };
  11203. var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; // Sanitize the range of a regular expression
  11204. // The cases are complicated, see test cases for details
  11205. var sanitizeRange = function sanitizeRange(range) {
  11206. return range.replace(REGEX_REGEXP_RANGE, function (match, from, to) {
  11207. return from.charCodeAt(0) <= to.charCodeAt(0) ? match // Invalid range (out of order) which is ok for gitignore rules but
  11208. // fatal for JavaScript regular expression, so eliminate it.
  11209. : '';
  11210. });
  11211. }; // > If the pattern ends with a slash,
  11212. // > it is removed for the purpose of the following description,
  11213. // > but it would only find a match with a directory.
  11214. // > In other words, foo/ will match a directory foo and paths underneath it,
  11215. // > but will not match a regular file or a symbolic link foo
  11216. // > (this is consistent with the way how pathspec works in general in Git).
  11217. // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
  11218. // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
  11219. // you could use option `mark: true` with `glob`
  11220. // '`foo/`' should not continue with the '`..`'
  11221. var DEFAULT_REPLACER_PREFIX = [// > Trailing spaces are ignored unless they are quoted with backslash ("\")
  11222. [// (a\ ) -> (a )
  11223. // (a ) -> (a)
  11224. // (a \ ) -> (a )
  11225. /\\?\s+$/, function (match) {
  11226. return match.indexOf('\\') === 0 ? ' ' : '';
  11227. }], // replace (\ ) with ' '
  11228. [/\\\s/g, function () {
  11229. return ' ';
  11230. }], // Escape metacharacters
  11231. // which is written down by users but means special for regular expressions.
  11232. // > There are 12 characters with special meanings:
  11233. // > - the backslash \,
  11234. // > - the caret ^,
  11235. // > - the dollar sign $,
  11236. // > - the period or dot .,
  11237. // > - the vertical bar or pipe symbol |,
  11238. // > - the question mark ?,
  11239. // > - the asterisk or star *,
  11240. // > - the plus sign +,
  11241. // > - the opening parenthesis (,
  11242. // > - the closing parenthesis ),
  11243. // > - and the opening square bracket [,
  11244. // > - the opening curly brace {,
  11245. // > These special characters are often called "metacharacters".
  11246. [/[\\^$.|*+(){]/g, function (match) {
  11247. return `\\${match}`;
  11248. }], [// > [abc] matches any character inside the brackets
  11249. // > (in this case a, b, or c);
  11250. /\[([^\]/]*)($|\])/g, function (match, p1, p2) {
  11251. return p2 === ']' ? `[${sanitizeRange(p1)}]` : `\\${match}`;
  11252. }], [// > a question mark (?) matches a single character
  11253. /(?!\\)\?/g, function () {
  11254. return '[^/]';
  11255. }], // leading slash
  11256. [// > A leading slash matches the beginning of the pathname.
  11257. // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
  11258. // A leading slash matches the beginning of the pathname
  11259. /^\//, function () {
  11260. return '^';
  11261. }], // replace special metacharacter slash after the leading slash
  11262. [/\//g, function () {
  11263. return '\\/';
  11264. }], [// > A leading "**" followed by a slash means match in all directories.
  11265. // > For example, "**/foo" matches file or directory "foo" anywhere,
  11266. // > the same as pattern "foo".
  11267. // > "**/foo/bar" matches file or directory "bar" anywhere that is directly
  11268. // > under directory "foo".
  11269. // Notice that the '*'s have been replaced as '\\*'
  11270. /^\^*\\\*\\\*\\\//, // '**/foo' <-> 'foo'
  11271. function () {
  11272. return '^(?:.*\\/)?';
  11273. }]];
  11274. var DEFAULT_REPLACER_SUFFIX = [// starting
  11275. [// there will be no leading '/'
  11276. // (which has been replaced by section "leading slash")
  11277. // If starts with '**', adding a '^' to the regular expression also works
  11278. /^(?=[^^])/, function startingReplacer() {
  11279. return !/\/(?!$)/.test(this) // > If the pattern does not contain a slash /,
  11280. // > Git treats it as a shell glob pattern
  11281. // Actually, if there is only a trailing slash,
  11282. // git also treats it as a shell glob pattern
  11283. ? '(?:^|\\/)' // > Otherwise, Git treats the pattern as a shell glob suitable for
  11284. // > consumption by fnmatch(3)
  11285. : '^';
  11286. }], // two globstars
  11287. [// Use lookahead assertions so that we could match more than one `'/**'`
  11288. /\\\/\\\*\\\*(?=\\\/|$)/g, // Zero, one or several directories
  11289. // should not use '*', or it will be replaced by the next replacer
  11290. // Check if it is not the last `'/**'`
  11291. function (match, index, str) {
  11292. return index + 6 < str.length // case: /**/
  11293. // > A slash followed by two consecutive asterisks then a slash matches
  11294. // > zero or more directories.
  11295. // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
  11296. // '/**/'
  11297. ? '(?:\\/[^\\/]+)*' // case: /**
  11298. // > A trailing `"/**"` matches everything inside.
  11299. // #21: everything inside but it should not include the current folder
  11300. : '\\/.+';
  11301. }], // intermediate wildcards
  11302. [// Never replace escaped '*'
  11303. // ignore rule '\*' will match the path '*'
  11304. // 'abc.*/' -> go
  11305. // 'abc.*' -> skip this rule
  11306. /(^|[^\\]+)\\\*(?=.+)/g, // '*.js' matches '.js'
  11307. // '*.js' doesn't match 'abc'
  11308. function (match, p1) {
  11309. return `${p1}[^\\/]*`;
  11310. }], // trailing wildcard
  11311. [/(\^|\\\/)?\\\*$/, function (match, p1) {
  11312. var prefix = p1 // '\^':
  11313. // '/*' does not match ''
  11314. // '/*' does not match everything
  11315. // '\\\/':
  11316. // 'abc/*' does not match 'abc/'
  11317. ? `${p1}[^/]+` // 'a*' matches 'a'
  11318. // 'a*' matches 'aa'
  11319. : '[^/]*';
  11320. return `${prefix}(?=$|\\/$)`;
  11321. }], [// unescape
  11322. /\\\\\\/g, function () {
  11323. return '\\';
  11324. }]];
  11325. var POSITIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [// 'f'
  11326. // matches
  11327. // - /f(end)
  11328. // - /f/
  11329. // - (start)f(end)
  11330. // - (start)f/
  11331. // doesn't match
  11332. // - oof
  11333. // - foo
  11334. // pseudo:
  11335. // -> (^|/)f(/|$)
  11336. // ending
  11337. [// 'js' will not match 'js.'
  11338. // 'ab' will not match 'abc'
  11339. /(?:[^*/])$/, // 'js*' will not match 'a.js'
  11340. // 'js/' will not match 'a.js'
  11341. // 'js' will match 'a.js' and 'a.js/'
  11342. function (match) {
  11343. return `${match}(?=$|\\/)`;
  11344. }]], DEFAULT_REPLACER_SUFFIX);
  11345. var NEGATIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [// #24, #38
  11346. // The MISSING rule of [gitignore docs](https://git-scm.com/docs/gitignore)
  11347. // A negative pattern without a trailing wildcard should not
  11348. // re-include the things inside that directory.
  11349. // eg:
  11350. // ['node_modules/*', '!node_modules']
  11351. // should ignore `node_modules/a.js`
  11352. [/(?:[^*])$/, function (match) {
  11353. return `${match}(?=$|\\/$)`;
  11354. }]], DEFAULT_REPLACER_SUFFIX); // A simple cache, because an ignore rule only has only one certain meaning
  11355. var cache = Object.create(null); // @param {pattern}
  11356. var make_regex = function make_regex(pattern, negative, ignorecase) {
  11357. var r = cache[pattern];
  11358. if (r) {
  11359. return r;
  11360. }
  11361. var replacers = negative ? NEGATIVE_REPLACERS : POSITIVE_REPLACERS;
  11362. var source = replacers.reduce(function (prev, current) {
  11363. return prev.replace(current[0], current[1].bind(pattern));
  11364. }, pattern);
  11365. return cache[pattern] = ignorecase ? new RegExp(source, 'i') : new RegExp(source);
  11366. }; // > A blank line matches no files, so it can serve as a separator for readability.
  11367. var checkPattern = function checkPattern(pattern) {
  11368. return pattern && typeof pattern === 'string' && !REGEX_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment.
  11369. && pattern.indexOf('#') !== 0;
  11370. };
  11371. var createRule = function createRule(pattern, ignorecase) {
  11372. var origin = pattern;
  11373. var negative = false; // > An optional prefix "!" which negates the pattern;
  11374. if (pattern.indexOf('!') === 0) {
  11375. negative = true;
  11376. pattern = pattern.substr(1);
  11377. }
  11378. pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that
  11379. // > begin with a literal "!", for example, `"\!important!.txt"`.
  11380. .replace(REGEX_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that
  11381. // > begin with a hash.
  11382. .replace(REGEX_LEADING_EXCAPED_HASH, '#');
  11383. var regex = make_regex(pattern, negative, ignorecase);
  11384. return {
  11385. origin,
  11386. pattern,
  11387. negative,
  11388. regex
  11389. };
  11390. };
  11391. var IgnoreBase =
  11392. /*#__PURE__*/
  11393. function () {
  11394. function IgnoreBase() {
  11395. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  11396. _ref$ignorecase = _ref.ignorecase,
  11397. ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase;
  11398. _classCallCheck(this, IgnoreBase);
  11399. this._rules = [];
  11400. this._ignorecase = ignorecase;
  11401. define(this, KEY_IGNORE, true);
  11402. this._initCache();
  11403. }
  11404. _createClass(IgnoreBase, [{
  11405. key: "_initCache",
  11406. value: function _initCache() {
  11407. this._cache = Object.create(null);
  11408. } // @param {Array.<string>|string|Ignore} pattern
  11409. }, {
  11410. key: "add",
  11411. value: function add(pattern) {
  11412. this._added = false;
  11413. if (typeof pattern === 'string') {
  11414. pattern = pattern.split(/\r?\n/g);
  11415. }
  11416. make_array(pattern).forEach(this._addPattern, this); // Some rules have just added to the ignore,
  11417. // making the behavior changed.
  11418. if (this._added) {
  11419. this._initCache();
  11420. }
  11421. return this;
  11422. } // legacy
  11423. }, {
  11424. key: "addPattern",
  11425. value: function addPattern(pattern) {
  11426. return this.add(pattern);
  11427. }
  11428. }, {
  11429. key: "_addPattern",
  11430. value: function _addPattern(pattern) {
  11431. // #32
  11432. if (pattern && pattern[KEY_IGNORE]) {
  11433. this._rules = this._rules.concat(pattern._rules);
  11434. this._added = true;
  11435. return;
  11436. }
  11437. if (checkPattern(pattern)) {
  11438. var rule = createRule(pattern, this._ignorecase);
  11439. this._added = true;
  11440. this._rules.push(rule);
  11441. }
  11442. }
  11443. }, {
  11444. key: "filter",
  11445. value: function filter(paths) {
  11446. var _this = this;
  11447. return make_array(paths).filter(function (path) {
  11448. return _this._filter(path);
  11449. });
  11450. }
  11451. }, {
  11452. key: "createFilter",
  11453. value: function createFilter() {
  11454. var _this2 = this;
  11455. return function (path) {
  11456. return _this2._filter(path);
  11457. };
  11458. }
  11459. }, {
  11460. key: "ignores",
  11461. value: function ignores(path) {
  11462. return !this._filter(path);
  11463. } // @returns `Boolean` true if the `path` is NOT ignored
  11464. }, {
  11465. key: "_filter",
  11466. value: function _filter(path, slices) {
  11467. if (!path) {
  11468. return false;
  11469. }
  11470. if (path in this._cache) {
  11471. return this._cache[path];
  11472. }
  11473. if (!slices) {
  11474. // path/to/a.js
  11475. // ['path', 'to', 'a.js']
  11476. slices = path.split(SLASH);
  11477. }
  11478. slices.pop();
  11479. return this._cache[path] = slices.length // > It is not possible to re-include a file if a parent directory of
  11480. // > that file is excluded.
  11481. // If the path contains a parent directory, check the parent first
  11482. ? this._filter(slices.join(SLASH) + SLASH, slices) && this._test(path) // Or only test the path
  11483. : this._test(path);
  11484. } // @returns {Boolean} true if a file is NOT ignored
  11485. }, {
  11486. key: "_test",
  11487. value: function _test(path) {
  11488. // Explicitly define variable type by setting matched to `0`
  11489. var matched = 0;
  11490. this._rules.forEach(function (rule) {
  11491. // if matched = true, then we only test negative rules
  11492. // if matched = false, then we test non-negative rules
  11493. if (!(matched ^ rule.negative)) {
  11494. matched = rule.negative ^ rule.regex.test(path);
  11495. }
  11496. });
  11497. return !matched;
  11498. }
  11499. }]);
  11500. return IgnoreBase;
  11501. }(); // Windows
  11502. // --------------------------------------------------------------
  11503. /* istanbul ignore if */
  11504. if ( // Detect `process` so that it can run in browsers.
  11505. typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) {
  11506. var filter = IgnoreBase.prototype._filter;
  11507. /* eslint no-control-regex: "off" */
  11508. var make_posix = function make_posix(str) {
  11509. return /^\\\\\?\\/.test(str) || /[^\x00-\x80]+/.test(str) ? str : str.replace(/\\/g, '/');
  11510. };
  11511. IgnoreBase.prototype._filter = function filterWin32(path, slices) {
  11512. path = make_posix(path);
  11513. return filter.call(this, path, slices);
  11514. };
  11515. }
  11516. var ignore = function ignore(options) {
  11517. return new IgnoreBase(options);
  11518. };
  11519. /**
  11520. * @param {string} filename
  11521. * @returns {Promise<null | string>}
  11522. */
  11523. function getFileContentOrNull(filename) {
  11524. return new Promise(function (resolve, reject) {
  11525. fs$1.readFile(filename, "utf8", function (error, data) {
  11526. if (error && error.code !== "ENOENT") {
  11527. reject(createError(filename, error));
  11528. } else {
  11529. resolve(error ? null : data);
  11530. }
  11531. });
  11532. });
  11533. }
  11534. /**
  11535. * @param {string} filename
  11536. * @returns {null | string}
  11537. */
  11538. getFileContentOrNull.sync = function (filename) {
  11539. try {
  11540. return fs$1.readFileSync(filename, "utf8");
  11541. } catch (error) {
  11542. if (error && error.code === "ENOENT") {
  11543. return null;
  11544. }
  11545. throw createError(filename, error);
  11546. }
  11547. };
  11548. function createError(filename, error) {
  11549. return new Error(`Unable to read ${filename}: ${error.message}`);
  11550. }
  11551. var getFileContentOrNull_1 = getFileContentOrNull;
  11552. /**
  11553. * @param {undefined | string} ignorePath
  11554. * @param {undefined | boolean} withNodeModules
  11555. */
  11556. function createIgnorer(ignorePath, withNodeModules) {
  11557. return (!ignorePath ? Promise.resolve(null) : getFileContentOrNull_1(path$2.resolve(ignorePath))).then(function (ignoreContent) {
  11558. return _createIgnorer(ignoreContent, withNodeModules);
  11559. });
  11560. }
  11561. /**
  11562. * @param {undefined | string} ignorePath
  11563. * @param {undefined | boolean} withNodeModules
  11564. */
  11565. createIgnorer.sync = function (ignorePath, withNodeModules) {
  11566. var ignoreContent = !ignorePath ? null : getFileContentOrNull_1.sync(path$2.resolve(ignorePath));
  11567. return _createIgnorer(ignoreContent, withNodeModules);
  11568. };
  11569. /**
  11570. * @param {null | string} ignoreContent
  11571. * @param {undefined | boolean} withNodeModules
  11572. */
  11573. function _createIgnorer(ignoreContent, withNodeModules) {
  11574. var ignorer = ignore().add(ignoreContent || "");
  11575. if (!withNodeModules) {
  11576. ignorer.add("node_modules");
  11577. }
  11578. return ignorer;
  11579. }
  11580. var createIgnorer_1 = createIgnorer;
  11581. var thirdParty = require("./third-party");
  11582. var concatMap = function concatMap(xs, fn) {
  11583. var res = [];
  11584. for (var i = 0; i < xs.length; i++) {
  11585. var x = fn(xs[i], i);
  11586. if (isArray(x)) res.push.apply(res, x);else res.push(x);
  11587. }
  11588. return res;
  11589. };
  11590. var isArray = Array.isArray || function (xs) {
  11591. return Object.prototype.toString.call(xs) === '[object Array]';
  11592. };
  11593. var balancedMatch = balanced;
  11594. function balanced(a, b, str) {
  11595. if (a instanceof RegExp) a = maybeMatch(a, str);
  11596. if (b instanceof RegExp) b = maybeMatch(b, str);
  11597. var r = range(a, b, str);
  11598. return r && {
  11599. start: r[0],
  11600. end: r[1],
  11601. pre: str.slice(0, r[0]),
  11602. body: str.slice(r[0] + a.length, r[1]),
  11603. post: str.slice(r[1] + b.length)
  11604. };
  11605. }
  11606. function maybeMatch(reg, str) {
  11607. var m = str.match(reg);
  11608. return m ? m[0] : null;
  11609. }
  11610. balanced.range = range;
  11611. function range(a, b, str) {
  11612. var begs, beg, left, right, result;
  11613. var ai = str.indexOf(a);
  11614. var bi = str.indexOf(b, ai + 1);
  11615. var i = ai;
  11616. if (ai >= 0 && bi > 0) {
  11617. begs = [];
  11618. left = str.length;
  11619. while (i >= 0 && !result) {
  11620. if (i == ai) {
  11621. begs.push(i);
  11622. ai = str.indexOf(a, i + 1);
  11623. } else if (begs.length == 1) {
  11624. result = [begs.pop(), bi];
  11625. } else {
  11626. beg = begs.pop();
  11627. if (beg < left) {
  11628. left = beg;
  11629. right = bi;
  11630. }
  11631. bi = str.indexOf(b, i + 1);
  11632. }
  11633. i = ai < bi && ai >= 0 ? ai : bi;
  11634. }
  11635. if (begs.length) {
  11636. result = [left, right];
  11637. }
  11638. }
  11639. return result;
  11640. }
  11641. var braceExpansion = expandTop;
  11642. var escSlash = '\0SLASH' + Math.random() + '\0';
  11643. var escOpen = '\0OPEN' + Math.random() + '\0';
  11644. var escClose = '\0CLOSE' + Math.random() + '\0';
  11645. var escComma = '\0COMMA' + Math.random() + '\0';
  11646. var escPeriod = '\0PERIOD' + Math.random() + '\0';
  11647. function numeric(str) {
  11648. return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
  11649. }
  11650. function escapeBraces(str) {
  11651. return str.split('\\\\').join(escSlash).split('\\{').join(escOpen).split('\\}').join(escClose).split('\\,').join(escComma).split('\\.').join(escPeriod);
  11652. }
  11653. function unescapeBraces(str) {
  11654. return str.split(escSlash).join('\\').split(escOpen).join('{').split(escClose).join('}').split(escComma).join(',').split(escPeriod).join('.');
  11655. } // Basically just str.split(","), but handling cases
  11656. // where we have nested braced sections, which should be
  11657. // treated as individual members, like {a,{b,c},d}
  11658. function parseCommaParts(str) {
  11659. if (!str) return [''];
  11660. var parts = [];
  11661. var m = balancedMatch('{', '}', str);
  11662. if (!m) return str.split(',');
  11663. var pre = m.pre;
  11664. var body = m.body;
  11665. var post = m.post;
  11666. var p = pre.split(',');
  11667. p[p.length - 1] += '{' + body + '}';
  11668. var postParts = parseCommaParts(post);
  11669. if (post.length) {
  11670. p[p.length - 1] += postParts.shift();
  11671. p.push.apply(p, postParts);
  11672. }
  11673. parts.push.apply(parts, p);
  11674. return parts;
  11675. }
  11676. function expandTop(str) {
  11677. if (!str) return []; // I don't know why Bash 4.3 does this, but it does.
  11678. // Anything starting with {} will have the first two bytes preserved
  11679. // but *only* at the top level, so {},a}b will not expand to anything,
  11680. // but a{},b}c will be expanded to [a}c,abc].
  11681. // One could argue that this is a bug in Bash, but since the goal of
  11682. // this module is to match Bash's rules, we escape a leading {}
  11683. if (str.substr(0, 2) === '{}') {
  11684. str = '\\{\\}' + str.substr(2);
  11685. }
  11686. return expand(escapeBraces(str), true).map(unescapeBraces);
  11687. }
  11688. function embrace(str) {
  11689. return '{' + str + '}';
  11690. }
  11691. function isPadded(el) {
  11692. return /^-?0\d/.test(el);
  11693. }
  11694. function lte(i, y) {
  11695. return i <= y;
  11696. }
  11697. function gte(i, y) {
  11698. return i >= y;
  11699. }
  11700. function expand(str, isTop) {
  11701. var expansions = [];
  11702. var m = balancedMatch('{', '}', str);
  11703. if (!m || /\$$/.test(m.pre)) return [str];
  11704. var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
  11705. var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
  11706. var isSequence = isNumericSequence || isAlphaSequence;
  11707. var isOptions = m.body.indexOf(',') >= 0;
  11708. if (!isSequence && !isOptions) {
  11709. // {a},b}
  11710. if (m.post.match(/,.*\}/)) {
  11711. str = m.pre + '{' + m.body + escClose + m.post;
  11712. return expand(str);
  11713. }
  11714. return [str];
  11715. }
  11716. var n;
  11717. if (isSequence) {
  11718. n = m.body.split(/\.\./);
  11719. } else {
  11720. n = parseCommaParts(m.body);
  11721. if (n.length === 1) {
  11722. // x{{a,b}}y ==> x{a}y x{b}y
  11723. n = expand(n[0], false).map(embrace);
  11724. if (n.length === 1) {
  11725. var post = m.post.length ? expand(m.post, false) : [''];
  11726. return post.map(function (p) {
  11727. return m.pre + n[0] + p;
  11728. });
  11729. }
  11730. }
  11731. } // at this point, n is the parts, and we know it's not a comma set
  11732. // with a single entry.
  11733. // no need to expand pre, since it is guaranteed to be free of brace-sets
  11734. var pre = m.pre;
  11735. var post = m.post.length ? expand(m.post, false) : [''];
  11736. var N;
  11737. if (isSequence) {
  11738. var x = numeric(n[0]);
  11739. var y = numeric(n[1]);
  11740. var width = Math.max(n[0].length, n[1].length);
  11741. var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
  11742. var test = lte;
  11743. var reverse = y < x;
  11744. if (reverse) {
  11745. incr *= -1;
  11746. test = gte;
  11747. }
  11748. var pad = n.some(isPadded);
  11749. N = [];
  11750. for (var i = x; test(i, y); i += incr) {
  11751. var c;
  11752. if (isAlphaSequence) {
  11753. c = String.fromCharCode(i);
  11754. if (c === '\\') c = '';
  11755. } else {
  11756. c = String(i);
  11757. if (pad) {
  11758. var need = width - c.length;
  11759. if (need > 0) {
  11760. var z = new Array(need + 1).join('0');
  11761. if (i < 0) c = '-' + z + c.slice(1);else c = z + c;
  11762. }
  11763. }
  11764. }
  11765. N.push(c);
  11766. }
  11767. } else {
  11768. N = concatMap(n, function (el) {
  11769. return expand(el, false);
  11770. });
  11771. }
  11772. for (var j = 0; j < N.length; j++) {
  11773. for (var k = 0; k < post.length; k++) {
  11774. var expansion = pre + N[j] + post[k];
  11775. if (!isTop || isSequence || expansion) expansions.push(expansion);
  11776. }
  11777. }
  11778. return expansions;
  11779. }
  11780. var minimatch_1 = minimatch;
  11781. minimatch.Minimatch = Minimatch;
  11782. var path = {
  11783. sep: '/'
  11784. };
  11785. try {
  11786. path = path$2;
  11787. } catch (er) {}
  11788. var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
  11789. var plTypes = {
  11790. '!': {
  11791. open: '(?:(?!(?:',
  11792. close: '))[^/]*?)'
  11793. },
  11794. '?': {
  11795. open: '(?:',
  11796. close: ')?'
  11797. },
  11798. '+': {
  11799. open: '(?:',
  11800. close: ')+'
  11801. },
  11802. '*': {
  11803. open: '(?:',
  11804. close: ')*'
  11805. },
  11806. '@': {
  11807. open: '(?:',
  11808. close: ')'
  11809. }
  11810. }; // any single thing other than /
  11811. // don't need to escape / when using new RegExp()
  11812. var qmark = '[^/]'; // * => any number of characters
  11813. var star = qmark + '*?'; // ** when dots are allowed. Anything goes, except .. and .
  11814. // not (^ or / followed by one or two dots followed by $ or /),
  11815. // followed by anything, any number of times.
  11816. var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'; // not a ^ or / followed by a dot,
  11817. // followed by anything, any number of times.
  11818. var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'; // characters that need to be escaped in RegExp.
  11819. var reSpecials = charSet('().*{}+?[]^$\\!'); // "abc" -> { a:true, b:true, c:true }
  11820. function charSet(s) {
  11821. return s.split('').reduce(function (set, c) {
  11822. set[c] = true;
  11823. return set;
  11824. }, {});
  11825. } // normalizes slashes.
  11826. var slashSplit = /\/+/;
  11827. minimatch.filter = filter$1;
  11828. function filter$1(pattern, options) {
  11829. options = options || {};
  11830. return function (p, i, list) {
  11831. return minimatch(p, pattern, options);
  11832. };
  11833. }
  11834. function ext(a, b) {
  11835. a = a || {};
  11836. b = b || {};
  11837. var t = {};
  11838. Object.keys(b).forEach(function (k) {
  11839. t[k] = b[k];
  11840. });
  11841. Object.keys(a).forEach(function (k) {
  11842. t[k] = a[k];
  11843. });
  11844. return t;
  11845. }
  11846. minimatch.defaults = function (def) {
  11847. if (!def || !Object.keys(def).length) return minimatch;
  11848. var orig = minimatch;
  11849. var m = function minimatch(p, pattern, options) {
  11850. return orig.minimatch(p, pattern, ext(def, options));
  11851. };
  11852. m.Minimatch = function Minimatch(pattern, options) {
  11853. return new orig.Minimatch(pattern, ext(def, options));
  11854. };
  11855. return m;
  11856. };
  11857. Minimatch.defaults = function (def) {
  11858. if (!def || !Object.keys(def).length) return Minimatch;
  11859. return minimatch.defaults(def).Minimatch;
  11860. };
  11861. function minimatch(p, pattern, options) {
  11862. if (typeof pattern !== 'string') {
  11863. throw new TypeError('glob pattern string required');
  11864. }
  11865. if (!options) options = {}; // shortcut: comments match nothing.
  11866. if (!options.nocomment && pattern.charAt(0) === '#') {
  11867. return false;
  11868. } // "" only matches ""
  11869. if (pattern.trim() === '') return p === '';
  11870. return new Minimatch(pattern, options).match(p);
  11871. }
  11872. function Minimatch(pattern, options) {
  11873. if (!(this instanceof Minimatch)) {
  11874. return new Minimatch(pattern, options);
  11875. }
  11876. if (typeof pattern !== 'string') {
  11877. throw new TypeError('glob pattern string required');
  11878. }
  11879. if (!options) options = {};
  11880. pattern = pattern.trim(); // windows support: need to use /, not \
  11881. if (path.sep !== '/') {
  11882. pattern = pattern.split(path.sep).join('/');
  11883. }
  11884. this.options = options;
  11885. this.set = [];
  11886. this.pattern = pattern;
  11887. this.regexp = null;
  11888. this.negate = false;
  11889. this.comment = false;
  11890. this.empty = false; // make the set of regexps etc.
  11891. this.make();
  11892. }
  11893. Minimatch.prototype.debug = function () {};
  11894. Minimatch.prototype.make = make;
  11895. function make() {
  11896. // don't do it more than once.
  11897. if (this._made) return;
  11898. var pattern = this.pattern;
  11899. var options = this.options; // empty patterns and comments match nothing.
  11900. if (!options.nocomment && pattern.charAt(0) === '#') {
  11901. this.comment = true;
  11902. return;
  11903. }
  11904. if (!pattern) {
  11905. this.empty = true;
  11906. return;
  11907. } // step 1: figure out negation, etc.
  11908. this.parseNegate(); // step 2: expand braces
  11909. var set = this.globSet = this.braceExpand();
  11910. if (options.debug) this.debug = console.error;
  11911. this.debug(this.pattern, set); // step 3: now we have a set, so turn each one into a series of path-portion
  11912. // matching patterns.
  11913. // These will be regexps, except in the case of "**", which is
  11914. // set to the GLOBSTAR object for globstar behavior,
  11915. // and will not contain any / characters
  11916. set = this.globParts = set.map(function (s) {
  11917. return s.split(slashSplit);
  11918. });
  11919. this.debug(this.pattern, set); // glob --> regexps
  11920. set = set.map(function (s, si, set) {
  11921. return s.map(this.parse, this);
  11922. }, this);
  11923. this.debug(this.pattern, set); // filter out everything that didn't compile properly.
  11924. set = set.filter(function (s) {
  11925. return s.indexOf(false) === -1;
  11926. });
  11927. this.debug(this.pattern, set);
  11928. this.set = set;
  11929. }
  11930. Minimatch.prototype.parseNegate = parseNegate;
  11931. function parseNegate() {
  11932. var pattern = this.pattern;
  11933. var negate = false;
  11934. var options = this.options;
  11935. var negateOffset = 0;
  11936. if (options.nonegate) return;
  11937. for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === '!'; i++) {
  11938. negate = !negate;
  11939. negateOffset++;
  11940. }
  11941. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  11942. this.negate = negate;
  11943. } // Brace expansion:
  11944. // a{b,c}d -> abd acd
  11945. // a{b,}c -> abc ac
  11946. // a{0..3}d -> a0d a1d a2d a3d
  11947. // a{b,c{d,e}f}g -> abg acdfg acefg
  11948. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  11949. //
  11950. // Invalid sets are not expanded.
  11951. // a{2..}b -> a{2..}b
  11952. // a{b}c -> a{b}c
  11953. minimatch.braceExpand = function (pattern, options) {
  11954. return braceExpand(pattern, options);
  11955. };
  11956. Minimatch.prototype.braceExpand = braceExpand;
  11957. function braceExpand(pattern, options) {
  11958. if (!options) {
  11959. if (this instanceof Minimatch) {
  11960. options = this.options;
  11961. } else {
  11962. options = {};
  11963. }
  11964. }
  11965. pattern = typeof pattern === 'undefined' ? this.pattern : pattern;
  11966. if (typeof pattern === 'undefined') {
  11967. throw new TypeError('undefined pattern');
  11968. }
  11969. if (options.nobrace || !pattern.match(/\{.*\}/)) {
  11970. // shortcut. no need to expand.
  11971. return [pattern];
  11972. }
  11973. return braceExpansion(pattern);
  11974. } // parse a component of the expanded set.
  11975. // At this point, no pattern may contain "/" in it
  11976. // so we're going to return a 2d array, where each entry is the full
  11977. // pattern, split on '/', and then turned into a regular expression.
  11978. // A regexp is made at the end which joins each array with an
  11979. // escaped /, and another full one which joins each regexp with |.
  11980. //
  11981. // Following the lead of Bash 4.1, note that "**" only has special meaning
  11982. // when it is the *only* thing in a path portion. Otherwise, any series
  11983. // of * is equivalent to a single *. Globstar behavior is enabled by
  11984. // default, and can be disabled by setting options.noglobstar.
  11985. Minimatch.prototype.parse = parse$1;
  11986. var SUBPARSE = {};
  11987. function parse$1(pattern, isSub) {
  11988. if (pattern.length > 1024 * 64) {
  11989. throw new TypeError('pattern is too long');
  11990. }
  11991. var options = this.options; // shortcuts
  11992. if (!options.noglobstar && pattern === '**') return GLOBSTAR;
  11993. if (pattern === '') return '';
  11994. var re = '';
  11995. var hasMagic = !!options.nocase;
  11996. var escaping = false; // ? => one single character
  11997. var patternListStack = [];
  11998. var negativeLists = [];
  11999. var stateChar;
  12000. var inClass = false;
  12001. var reClassStart = -1;
  12002. var classStart = -1; // . and .. never match anything that doesn't start with .,
  12003. // even when options.dot is set.
  12004. var patternStart = pattern.charAt(0) === '.' ? '' // anything
  12005. // not (start or / followed by . or .. followed by / or end)
  12006. : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' : '(?!\\.)';
  12007. var self = this;
  12008. function clearStateChar() {
  12009. if (stateChar) {
  12010. // we had some state-tracking character
  12011. // that wasn't consumed by this pass.
  12012. switch (stateChar) {
  12013. case '*':
  12014. re += star;
  12015. hasMagic = true;
  12016. break;
  12017. case '?':
  12018. re += qmark;
  12019. hasMagic = true;
  12020. break;
  12021. default:
  12022. re += '\\' + stateChar;
  12023. break;
  12024. }
  12025. self.debug('clearStateChar %j %j', stateChar, re);
  12026. stateChar = false;
  12027. }
  12028. }
  12029. for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
  12030. this.debug('%s\t%s %s %j', pattern, i, re, c); // skip over any that are escaped.
  12031. if (escaping && reSpecials[c]) {
  12032. re += '\\' + c;
  12033. escaping = false;
  12034. continue;
  12035. }
  12036. switch (c) {
  12037. case '/':
  12038. // completely not allowed, even escaped.
  12039. // Should already be path-split by now.
  12040. return false;
  12041. case '\\':
  12042. clearStateChar();
  12043. escaping = true;
  12044. continue;
  12045. // the various stateChar values
  12046. // for the "extglob" stuff.
  12047. case '?':
  12048. case '*':
  12049. case '+':
  12050. case '@':
  12051. case '!':
  12052. this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c); // all of those are literals inside a class, except that
  12053. // the glob [!a] means [^a] in regexp
  12054. if (inClass) {
  12055. this.debug(' in class');
  12056. if (c === '!' && i === classStart + 1) c = '^';
  12057. re += c;
  12058. continue;
  12059. } // if we already have a stateChar, then it means
  12060. // that there was something like ** or +? in there.
  12061. // Handle the stateChar, then proceed with this one.
  12062. self.debug('call clearStateChar %j', stateChar);
  12063. clearStateChar();
  12064. stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
  12065. // just clear the statechar *now*, rather than even diving into
  12066. // the patternList stuff.
  12067. if (options.noext) clearStateChar();
  12068. continue;
  12069. case '(':
  12070. if (inClass) {
  12071. re += '(';
  12072. continue;
  12073. }
  12074. if (!stateChar) {
  12075. re += '\\(';
  12076. continue;
  12077. }
  12078. patternListStack.push({
  12079. type: stateChar,
  12080. start: i - 1,
  12081. reStart: re.length,
  12082. open: plTypes[stateChar].open,
  12083. close: plTypes[stateChar].close
  12084. }); // negation is (?:(?!js)[^/]*)
  12085. re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
  12086. this.debug('plType %j %j', stateChar, re);
  12087. stateChar = false;
  12088. continue;
  12089. case ')':
  12090. if (inClass || !patternListStack.length) {
  12091. re += '\\)';
  12092. continue;
  12093. }
  12094. clearStateChar();
  12095. hasMagic = true;
  12096. var pl = patternListStack.pop(); // negation is (?:(?!js)[^/]*)
  12097. // The others are (?:<pattern>)<type>
  12098. re += pl.close;
  12099. if (pl.type === '!') {
  12100. negativeLists.push(pl);
  12101. }
  12102. pl.reEnd = re.length;
  12103. continue;
  12104. case '|':
  12105. if (inClass || !patternListStack.length || escaping) {
  12106. re += '\\|';
  12107. escaping = false;
  12108. continue;
  12109. }
  12110. clearStateChar();
  12111. re += '|';
  12112. continue;
  12113. // these are mostly the same in regexp and glob
  12114. case '[':
  12115. // swallow any state-tracking char before the [
  12116. clearStateChar();
  12117. if (inClass) {
  12118. re += '\\' + c;
  12119. continue;
  12120. }
  12121. inClass = true;
  12122. classStart = i;
  12123. reClassStart = re.length;
  12124. re += c;
  12125. continue;
  12126. case ']':
  12127. // a right bracket shall lose its special
  12128. // meaning and represent itself in
  12129. // a bracket expression if it occurs
  12130. // first in the list. -- POSIX.2 2.8.3.2
  12131. if (i === classStart + 1 || !inClass) {
  12132. re += '\\' + c;
  12133. escaping = false;
  12134. continue;
  12135. } // handle the case where we left a class open.
  12136. // "[z-a]" is valid, equivalent to "\[z-a\]"
  12137. if (inClass) {
  12138. // split where the last [ was, make sure we don't have
  12139. // an invalid re. if so, re-walk the contents of the
  12140. // would-be class to re-translate any characters that
  12141. // were passed through as-is
  12142. // TODO: It would probably be faster to determine this
  12143. // without a try/catch and a new RegExp, but it's tricky
  12144. // to do safely. For now, this is safe and works.
  12145. var cs = pattern.substring(classStart + 1, i);
  12146. try {
  12147. RegExp('[' + cs + ']');
  12148. } catch (er) {
  12149. // not a valid class!
  12150. var sp = this.parse(cs, SUBPARSE);
  12151. re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
  12152. hasMagic = hasMagic || sp[1];
  12153. inClass = false;
  12154. continue;
  12155. }
  12156. } // finish up the class.
  12157. hasMagic = true;
  12158. inClass = false;
  12159. re += c;
  12160. continue;
  12161. default:
  12162. // swallow any state char that wasn't consumed
  12163. clearStateChar();
  12164. if (escaping) {
  12165. // no need
  12166. escaping = false;
  12167. } else if (reSpecials[c] && !(c === '^' && inClass)) {
  12168. re += '\\';
  12169. }
  12170. re += c;
  12171. } // switch
  12172. } // for
  12173. // handle the case where we left a class open.
  12174. // "[abc" is valid, equivalent to "\[abc"
  12175. if (inClass) {
  12176. // split where the last [ was, and escape it
  12177. // this is a huge pita. We now have to re-walk
  12178. // the contents of the would-be class to re-translate
  12179. // any characters that were passed through as-is
  12180. cs = pattern.substr(classStart + 1);
  12181. sp = this.parse(cs, SUBPARSE);
  12182. re = re.substr(0, reClassStart) + '\\[' + sp[0];
  12183. hasMagic = hasMagic || sp[1];
  12184. } // handle the case where we had a +( thing at the *end*
  12185. // of the pattern.
  12186. // each pattern list stack adds 3 chars, and we need to go through
  12187. // and escape any | chars that were passed through as-is for the regexp.
  12188. // Go through and escape them, taking care not to double-escape any
  12189. // | chars that were already escaped.
  12190. for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
  12191. var tail = re.slice(pl.reStart + pl.open.length);
  12192. this.debug('setting tail', re, pl); // maybe some even number of \, then maybe 1 \, followed by a |
  12193. tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
  12194. if (!$2) {
  12195. // the | isn't already escaped, so escape it.
  12196. $2 = '\\';
  12197. } // need to escape all those slashes *again*, without escaping the
  12198. // one that we need for escaping the | character. As it works out,
  12199. // escaping an even number of slashes can be done by simply repeating
  12200. // it exactly after itself. That's why this trick works.
  12201. //
  12202. // I am sorry that you have to see this.
  12203. return $1 + $1 + $2 + '|';
  12204. });
  12205. this.debug('tail=%j\n %s', tail, tail, pl, re);
  12206. var t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
  12207. hasMagic = true;
  12208. re = re.slice(0, pl.reStart) + t + '\\(' + tail;
  12209. } // handle trailing things that only matter at the very end.
  12210. clearStateChar();
  12211. if (escaping) {
  12212. // trailing \\
  12213. re += '\\\\';
  12214. } // only need to apply the nodot start if the re starts with
  12215. // something that could conceivably capture a dot
  12216. var addPatternStart = false;
  12217. switch (re.charAt(0)) {
  12218. case '.':
  12219. case '[':
  12220. case '(':
  12221. addPatternStart = true;
  12222. } // Hack to work around lack of negative lookbehind in JS
  12223. // A pattern like: *.!(x).!(y|z) needs to ensure that a name
  12224. // like 'a.xyz.yz' doesn't match. So, the first negative
  12225. // lookahead, has to look ALL the way ahead, to the end of
  12226. // the pattern.
  12227. for (var n = negativeLists.length - 1; n > -1; n--) {
  12228. var nl = negativeLists[n];
  12229. var nlBefore = re.slice(0, nl.reStart);
  12230. var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
  12231. var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
  12232. var nlAfter = re.slice(nl.reEnd);
  12233. nlLast += nlAfter; // Handle nested stuff like *(*.js|!(*.json)), where open parens
  12234. // mean that we should *not* include the ) in the bit that is considered
  12235. // "after" the negated section.
  12236. var openParensBefore = nlBefore.split('(').length - 1;
  12237. var cleanAfter = nlAfter;
  12238. for (i = 0; i < openParensBefore; i++) {
  12239. cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
  12240. }
  12241. nlAfter = cleanAfter;
  12242. var dollar = '';
  12243. if (nlAfter === '' && isSub !== SUBPARSE) {
  12244. dollar = '$';
  12245. }
  12246. var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
  12247. re = newRe;
  12248. } // if the re is not "" at this point, then we need to make sure
  12249. // it doesn't match against an empty path part.
  12250. // Otherwise a/* will match a/, which it should not.
  12251. if (re !== '' && hasMagic) {
  12252. re = '(?=.)' + re;
  12253. }
  12254. if (addPatternStart) {
  12255. re = patternStart + re;
  12256. } // parsing just a piece of a larger pattern.
  12257. if (isSub === SUBPARSE) {
  12258. return [re, hasMagic];
  12259. } // skip the regexp for non-magical patterns
  12260. // unescape anything in it, though, so that it'll be
  12261. // an exact match against a file etc.
  12262. if (!hasMagic) {
  12263. return globUnescape(pattern);
  12264. }
  12265. var flags = options.nocase ? 'i' : '';
  12266. try {
  12267. var regExp = new RegExp('^' + re + '$', flags);
  12268. } catch (er) {
  12269. // If it was an invalid regular expression, then it can't match
  12270. // anything. This trick looks for a character after the end of
  12271. // the string, which is of course impossible, except in multi-line
  12272. // mode, but it's not a /m regex.
  12273. return new RegExp('$.');
  12274. }
  12275. regExp._glob = pattern;
  12276. regExp._src = re;
  12277. return regExp;
  12278. }
  12279. minimatch.makeRe = function (pattern, options) {
  12280. return new Minimatch(pattern, options || {}).makeRe();
  12281. };
  12282. Minimatch.prototype.makeRe = makeRe;
  12283. function makeRe() {
  12284. if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
  12285. // pattern strings, or "**".
  12286. //
  12287. // It's better to use .match(). This function shouldn't
  12288. // be used, really, but it's pretty convenient sometimes,
  12289. // when you just want to work with a regex.
  12290. var set = this.set;
  12291. if (!set.length) {
  12292. this.regexp = false;
  12293. return this.regexp;
  12294. }
  12295. var options = this.options;
  12296. var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
  12297. var flags = options.nocase ? 'i' : '';
  12298. var re = set.map(function (pattern) {
  12299. return pattern.map(function (p) {
  12300. return p === GLOBSTAR ? twoStar : typeof p === 'string' ? regExpEscape(p) : p._src;
  12301. }).join('\\\/');
  12302. }).join('|'); // must match entire pattern
  12303. // ending in a * or ** will make it less strict.
  12304. re = '^(?:' + re + ')$'; // can match anything, as long as it's not this.
  12305. if (this.negate) re = '^(?!' + re + ').*$';
  12306. try {
  12307. this.regexp = new RegExp(re, flags);
  12308. } catch (ex) {
  12309. this.regexp = false;
  12310. }
  12311. return this.regexp;
  12312. }
  12313. minimatch.match = function (list, pattern, options) {
  12314. options = options || {};
  12315. var mm = new Minimatch(pattern, options);
  12316. list = list.filter(function (f) {
  12317. return mm.match(f);
  12318. });
  12319. if (mm.options.nonull && !list.length) {
  12320. list.push(pattern);
  12321. }
  12322. return list;
  12323. };
  12324. Minimatch.prototype.match = match;
  12325. function match(f, partial) {
  12326. this.debug('match', f, this.pattern); // short-circuit in the case of busted things.
  12327. // comments, etc.
  12328. if (this.comment) return false;
  12329. if (this.empty) return f === '';
  12330. if (f === '/' && partial) return true;
  12331. var options = this.options; // windows: need to use /, not \
  12332. if (path.sep !== '/') {
  12333. f = f.split(path.sep).join('/');
  12334. } // treat the test path as a set of pathparts.
  12335. f = f.split(slashSplit);
  12336. this.debug(this.pattern, 'split', f); // just ONE of the pattern sets in this.set needs to match
  12337. // in order for it to be valid. If negating, then just one
  12338. // match means that we have failed.
  12339. // Either way, return on the first hit.
  12340. var set = this.set;
  12341. this.debug(this.pattern, 'set', set); // Find the basename of the path by looking for the last non-empty segment
  12342. var filename;
  12343. var i;
  12344. for (i = f.length - 1; i >= 0; i--) {
  12345. filename = f[i];
  12346. if (filename) break;
  12347. }
  12348. for (i = 0; i < set.length; i++) {
  12349. var pattern = set[i];
  12350. var file = f;
  12351. if (options.matchBase && pattern.length === 1) {
  12352. file = [filename];
  12353. }
  12354. var hit = this.matchOne(file, pattern, partial);
  12355. if (hit) {
  12356. if (options.flipNegate) return true;
  12357. return !this.negate;
  12358. }
  12359. } // didn't get any hits. this is success if it's a negative
  12360. // pattern, failure otherwise.
  12361. if (options.flipNegate) return false;
  12362. return this.negate;
  12363. } // set partial to true to test if, for example,
  12364. // "/a/b" matches the start of "/*/b/*/d"
  12365. // Partial means, if you run out of file before you run
  12366. // out of pattern, then that's fine, as long as all
  12367. // the parts match.
  12368. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  12369. var options = this.options;
  12370. this.debug('matchOne', {
  12371. 'this': this,
  12372. file: file,
  12373. pattern: pattern
  12374. });
  12375. this.debug('matchOne', file.length, pattern.length);
  12376. for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
  12377. this.debug('matchOne loop');
  12378. var p = pattern[pi];
  12379. var f = file[fi];
  12380. this.debug(pattern, p, f); // should be impossible.
  12381. // some invalid regexp stuff in the set.
  12382. if (p === false) return false;
  12383. if (p === GLOBSTAR) {
  12384. this.debug('GLOBSTAR', [pattern, p, f]); // "**"
  12385. // a/**/b/**/c would match the following:
  12386. // a/b/x/y/z/c
  12387. // a/x/y/z/b/c
  12388. // a/b/x/b/x/c
  12389. // a/b/c
  12390. // To do this, take the rest of the pattern after
  12391. // the **, and see if it would match the file remainder.
  12392. // If so, return success.
  12393. // If not, the ** "swallows" a segment, and try again.
  12394. // This is recursively awful.
  12395. //
  12396. // a/**/b/**/c matching a/b/x/y/z/c
  12397. // - a matches a
  12398. // - doublestar
  12399. // - matchOne(b/x/y/z/c, b/**/c)
  12400. // - b matches b
  12401. // - doublestar
  12402. // - matchOne(x/y/z/c, c) -> no
  12403. // - matchOne(y/z/c, c) -> no
  12404. // - matchOne(z/c, c) -> no
  12405. // - matchOne(c, c) yes, hit
  12406. var fr = fi;
  12407. var pr = pi + 1;
  12408. if (pr === pl) {
  12409. this.debug('** at the end'); // a ** at the end will just swallow the rest.
  12410. // We have found a match.
  12411. // however, it will not swallow /.x, unless
  12412. // options.dot is set.
  12413. // . and .. are *never* matched by **, for explosively
  12414. // exponential reasons.
  12415. for (; fi < fl; fi++) {
  12416. if (file[fi] === '.' || file[fi] === '..' || !options.dot && file[fi].charAt(0) === '.') return false;
  12417. }
  12418. return true;
  12419. } // ok, let's see if we can swallow whatever we can.
  12420. while (fr < fl) {
  12421. var swallowee = file[fr];
  12422. this.debug('\nglobstar while', file, fr, pattern, pr, swallowee); // XXX remove this slice. Just pass the start index.
  12423. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  12424. this.debug('globstar found match!', fr, fl, swallowee); // found a match.
  12425. return true;
  12426. } else {
  12427. // can't swallow "." or ".." ever.
  12428. // can only swallow ".foo" when explicitly asked.
  12429. if (swallowee === '.' || swallowee === '..' || !options.dot && swallowee.charAt(0) === '.') {
  12430. this.debug('dot detected!', file, fr, pattern, pr);
  12431. break;
  12432. } // ** swallows a segment, and continue.
  12433. this.debug('globstar swallow a segment, and continue');
  12434. fr++;
  12435. }
  12436. } // no match was found.
  12437. // However, in partial mode, we can't say this is necessarily over.
  12438. // If there's more *pattern* left, then
  12439. if (partial) {
  12440. // ran out of file
  12441. this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
  12442. if (fr === fl) return true;
  12443. }
  12444. return false;
  12445. } // something other than **
  12446. // non-magic patterns just have to match exactly
  12447. // patterns with magic have been turned into regexps.
  12448. var hit;
  12449. if (typeof p === 'string') {
  12450. if (options.nocase) {
  12451. hit = f.toLowerCase() === p.toLowerCase();
  12452. } else {
  12453. hit = f === p;
  12454. }
  12455. this.debug('string match', p, f, hit);
  12456. } else {
  12457. hit = f.match(p);
  12458. this.debug('pattern match', p, f, hit);
  12459. }
  12460. if (!hit) return false;
  12461. } // Note: ending in / means that we'll get a final ""
  12462. // at the end of the pattern. This can only match a
  12463. // corresponding "" at the end of the file.
  12464. // If the file ends in /, then it can only match a
  12465. // a pattern that ends in /, unless the pattern just
  12466. // doesn't have any more for it. But, a/b/ should *not*
  12467. // match "a/b/*", even though "" matches against the
  12468. // [^/]*? pattern, except in partial mode, where it might
  12469. // simply not be reached yet.
  12470. // However, a/b/ should still satisfy a/*
  12471. // now either we fell off the end of the pattern, or we're done.
  12472. if (fi === fl && pi === pl) {
  12473. // ran out of pattern and filename at the same time.
  12474. // an exact hit!
  12475. return true;
  12476. } else if (fi === fl) {
  12477. // ran out of file, but still had pattern left.
  12478. // this is ok if we're doing the match as part of
  12479. // a glob fs traversal.
  12480. return partial;
  12481. } else if (pi === pl) {
  12482. // ran out of pattern, still have file left.
  12483. // this is only acceptable if we're on the very last
  12484. // empty segment of a file with a trailing slash.
  12485. // a/* should match a/b/
  12486. var emptyFileEnd = fi === fl - 1 && file[fi] === '';
  12487. return emptyFileEnd;
  12488. } // should be unreachable.
  12489. throw new Error('wtf?');
  12490. }; // replace stuff like \* with *
  12491. function globUnescape(s) {
  12492. return s.replace(/\\(.)/g, '$1');
  12493. }
  12494. function regExpEscape(s) {
  12495. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
  12496. }
  12497. var assert = true;
  12498. var async_hooks = ">= 8";
  12499. var buffer_ieee754 = "< 0.9.7";
  12500. var buffer = true;
  12501. var child_process = true;
  12502. var cluster = true;
  12503. var console$1 = true;
  12504. var constants = true;
  12505. var crypto = true;
  12506. var _debug_agent = ">= 1 && < 8";
  12507. var _debugger = "< 8";
  12508. var dgram = true;
  12509. var dns = true;
  12510. var domain = true;
  12511. var events = true;
  12512. var freelist = "< 6";
  12513. var fs = true;
  12514. var _http_agent = ">= 0.11.1";
  12515. var _http_client = ">= 0.11.1";
  12516. var _http_common = ">= 0.11.1";
  12517. var _http_incoming = ">= 0.11.1";
  12518. var _http_outgoing = ">= 0.11.1";
  12519. var _http_server = ">= 0.11.1";
  12520. var http = true;
  12521. var http2 = ">= 8.8";
  12522. var https = true;
  12523. var inspector = ">= 8.0.0";
  12524. var _linklist = "< 8";
  12525. var module$1 = true;
  12526. var net = true;
  12527. var os = true;
  12528. var path$1 = true;
  12529. var perf_hooks = ">= 8.5";
  12530. var process$1 = ">= 1";
  12531. var punycode = true;
  12532. var querystring = true;
  12533. var readline = true;
  12534. var repl = true;
  12535. var smalloc = ">= 0.11.5 && < 3";
  12536. var _stream_duplex = ">= 0.9.4";
  12537. var _stream_transform = ">= 0.9.4";
  12538. var _stream_wrap = ">= 1.4.1";
  12539. var _stream_passthrough = ">= 0.9.4";
  12540. var _stream_readable = ">= 0.9.4";
  12541. var _stream_writable = ">= 0.9.4";
  12542. var stream = true;
  12543. var string_decoder = true;
  12544. var sys = true;
  12545. var timers = true;
  12546. var _tls_common = ">= 0.11.13";
  12547. var _tls_legacy = ">= 0.11.3 && < 10";
  12548. var _tls_wrap = ">= 0.11.3";
  12549. var tls = true;
  12550. var trace_events = ">= 10";
  12551. var tty = true;
  12552. var url = true;
  12553. var util$1 = true;
  12554. var v8 = ">= 1";
  12555. var vm = true;
  12556. var worker_threads = ">= 11.7";
  12557. var zlib = true;
  12558. var core$1 = {
  12559. assert: assert,
  12560. async_hooks: async_hooks,
  12561. buffer_ieee754: buffer_ieee754,
  12562. buffer: buffer,
  12563. child_process: child_process,
  12564. cluster: cluster,
  12565. console: console$1,
  12566. constants: constants,
  12567. crypto: crypto,
  12568. _debug_agent: _debug_agent,
  12569. _debugger: _debugger,
  12570. dgram: dgram,
  12571. dns: dns,
  12572. domain: domain,
  12573. events: events,
  12574. freelist: freelist,
  12575. fs: fs,
  12576. "fs/promises": ">= 10 && < 10.1",
  12577. _http_agent: _http_agent,
  12578. _http_client: _http_client,
  12579. _http_common: _http_common,
  12580. _http_incoming: _http_incoming,
  12581. _http_outgoing: _http_outgoing,
  12582. _http_server: _http_server,
  12583. http: http,
  12584. http2: http2,
  12585. https: https,
  12586. inspector: inspector,
  12587. _linklist: _linklist,
  12588. module: module$1,
  12589. net: net,
  12590. "node-inspect/lib/_inspect": ">= 7.6.0 && < 12",
  12591. "node-inspect/lib/internal/inspect_client": ">= 7.6.0 && < 12",
  12592. "node-inspect/lib/internal/inspect_repl": ">= 7.6.0 && < 12",
  12593. os: os,
  12594. path: path$1,
  12595. perf_hooks: perf_hooks,
  12596. process: process$1,
  12597. punycode: punycode,
  12598. querystring: querystring,
  12599. readline: readline,
  12600. repl: repl,
  12601. smalloc: smalloc,
  12602. _stream_duplex: _stream_duplex,
  12603. _stream_transform: _stream_transform,
  12604. _stream_wrap: _stream_wrap,
  12605. _stream_passthrough: _stream_passthrough,
  12606. _stream_readable: _stream_readable,
  12607. _stream_writable: _stream_writable,
  12608. stream: stream,
  12609. string_decoder: string_decoder,
  12610. sys: sys,
  12611. timers: timers,
  12612. _tls_common: _tls_common,
  12613. _tls_legacy: _tls_legacy,
  12614. _tls_wrap: _tls_wrap,
  12615. tls: tls,
  12616. trace_events: trace_events,
  12617. tty: tty,
  12618. url: url,
  12619. util: util$1,
  12620. "v8/tools/arguments": ">= 10 && < 12",
  12621. "v8/tools/codemap": [
  12622. ">= 4.4.0 && < 5",
  12623. ">= 5.2.0 && < 12"
  12624. ],
  12625. "v8/tools/consarray": [
  12626. ">= 4.4.0 && < 5",
  12627. ">= 5.2.0 && < 12"
  12628. ],
  12629. "v8/tools/csvparser": [
  12630. ">= 4.4.0 && < 5",
  12631. ">= 5.2.0 && < 12"
  12632. ],
  12633. "v8/tools/logreader": [
  12634. ">= 4.4.0 && < 5",
  12635. ">= 5.2.0 && < 12"
  12636. ],
  12637. "v8/tools/profile_view": [
  12638. ">= 4.4.0 && < 5",
  12639. ">= 5.2.0 && < 12"
  12640. ],
  12641. "v8/tools/splaytree": [
  12642. ">= 4.4.0 && < 5",
  12643. ">= 5.2.0 && < 12"
  12644. ],
  12645. v8: v8,
  12646. vm: vm,
  12647. worker_threads: worker_threads,
  12648. zlib: zlib
  12649. };
  12650. var core$2 = /*#__PURE__*/Object.freeze({
  12651. __proto__: null,
  12652. assert: assert,
  12653. async_hooks: async_hooks,
  12654. buffer_ieee754: buffer_ieee754,
  12655. buffer: buffer,
  12656. child_process: child_process,
  12657. cluster: cluster,
  12658. console: console$1,
  12659. constants: constants,
  12660. crypto: crypto,
  12661. _debug_agent: _debug_agent,
  12662. _debugger: _debugger,
  12663. dgram: dgram,
  12664. dns: dns,
  12665. domain: domain,
  12666. events: events,
  12667. freelist: freelist,
  12668. fs: fs,
  12669. _http_agent: _http_agent,
  12670. _http_client: _http_client,
  12671. _http_common: _http_common,
  12672. _http_incoming: _http_incoming,
  12673. _http_outgoing: _http_outgoing,
  12674. _http_server: _http_server,
  12675. http: http,
  12676. http2: http2,
  12677. https: https,
  12678. inspector: inspector,
  12679. _linklist: _linklist,
  12680. module: module$1,
  12681. net: net,
  12682. os: os,
  12683. path: path$1,
  12684. perf_hooks: perf_hooks,
  12685. process: process$1,
  12686. punycode: punycode,
  12687. querystring: querystring,
  12688. readline: readline,
  12689. repl: repl,
  12690. smalloc: smalloc,
  12691. _stream_duplex: _stream_duplex,
  12692. _stream_transform: _stream_transform,
  12693. _stream_wrap: _stream_wrap,
  12694. _stream_passthrough: _stream_passthrough,
  12695. _stream_readable: _stream_readable,
  12696. _stream_writable: _stream_writable,
  12697. stream: stream,
  12698. string_decoder: string_decoder,
  12699. sys: sys,
  12700. timers: timers,
  12701. _tls_common: _tls_common,
  12702. _tls_legacy: _tls_legacy,
  12703. _tls_wrap: _tls_wrap,
  12704. tls: tls,
  12705. trace_events: trace_events,
  12706. tty: tty,
  12707. url: url,
  12708. util: util$1,
  12709. v8: v8,
  12710. vm: vm,
  12711. worker_threads: worker_threads,
  12712. zlib: zlib,
  12713. 'default': core$1
  12714. });
  12715. var data = getCjsExportFromNamespace(core$2);
  12716. var current = process.versions && process.versions.node && process.versions.node.split('.') || [];
  12717. function specifierIncluded(specifier) {
  12718. var parts = specifier.split(' ');
  12719. var op = parts.length > 1 ? parts[0] : '=';
  12720. var versionParts = (parts.length > 1 ? parts[1] : parts[0]).split('.');
  12721. for (var i = 0; i < 3; ++i) {
  12722. var cur = Number(current[i] || 0);
  12723. var ver = Number(versionParts[i] || 0);
  12724. if (cur === ver) {
  12725. continue; // eslint-disable-line no-restricted-syntax, no-continue
  12726. }
  12727. if (op === '<') {
  12728. return cur < ver;
  12729. } else if (op === '>=') {
  12730. return cur >= ver;
  12731. } else {
  12732. return false;
  12733. }
  12734. }
  12735. return op === '>=';
  12736. }
  12737. function matchesRange(range) {
  12738. var specifiers = range.split(/ ?&& ?/);
  12739. if (specifiers.length === 0) {
  12740. return false;
  12741. }
  12742. for (var i = 0; i < specifiers.length; ++i) {
  12743. if (!specifierIncluded(specifiers[i])) {
  12744. return false;
  12745. }
  12746. }
  12747. return true;
  12748. }
  12749. function versionIncluded(specifierValue) {
  12750. if (typeof specifierValue === 'boolean') {
  12751. return specifierValue;
  12752. }
  12753. if (specifierValue && typeof specifierValue === 'object') {
  12754. for (var i = 0; i < specifierValue.length; ++i) {
  12755. if (matchesRange(specifierValue[i])) {
  12756. return true;
  12757. }
  12758. }
  12759. return false;
  12760. }
  12761. return matchesRange(specifierValue);
  12762. }
  12763. var core$3 = {};
  12764. for (var mod in data) {
  12765. // eslint-disable-line no-restricted-syntax
  12766. if (Object.prototype.hasOwnProperty.call(data, mod)) {
  12767. core$3[mod] = versionIncluded(data[mod]);
  12768. }
  12769. }
  12770. var core_1 = core$3;
  12771. var caller = function caller() {
  12772. // see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
  12773. var origPrepareStackTrace = Error.prepareStackTrace;
  12774. Error.prepareStackTrace = function (_, stack) {
  12775. return stack;
  12776. };
  12777. var stack = new Error().stack;
  12778. Error.prepareStackTrace = origPrepareStackTrace;
  12779. return stack[2].getFileName();
  12780. };
  12781. var pathParse = createCommonjsModule(function (module) {
  12782. var isWindows = process.platform === 'win32'; // Regex to split a windows path into three parts: [*, device, slash,
  12783. // tail] windows-only
  12784. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/; // Regex to split the tail part of the above into [*, dir, basename, ext]
  12785. var splitTailRe = /^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
  12786. var win32 = {}; // Function to split a filename into [root, dir, basename, ext]
  12787. function win32SplitPath(filename) {
  12788. // Separate device+slash from tail
  12789. var result = splitDeviceRe.exec(filename),
  12790. device = (result[1] || '') + (result[2] || ''),
  12791. tail = result[3] || ''; // Split the tail into dir, basename and extension
  12792. var result2 = splitTailRe.exec(tail),
  12793. dir = result2[1],
  12794. basename = result2[2],
  12795. ext = result2[3];
  12796. return [device, dir, basename, ext];
  12797. }
  12798. win32.parse = function (pathString) {
  12799. if (typeof pathString !== 'string') {
  12800. throw new TypeError("Parameter 'pathString' must be a string, not " + typeof pathString);
  12801. }
  12802. var allParts = win32SplitPath(pathString);
  12803. if (!allParts || allParts.length !== 4) {
  12804. throw new TypeError("Invalid path '" + pathString + "'");
  12805. }
  12806. return {
  12807. root: allParts[0],
  12808. dir: allParts[0] + allParts[1].slice(0, -1),
  12809. base: allParts[2],
  12810. ext: allParts[3],
  12811. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  12812. };
  12813. }; // Split a filename into [root, dir, basename, ext], unix version
  12814. // 'root' is just a slash, or nothing.
  12815. var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  12816. var posix = {};
  12817. function posixSplitPath(filename) {
  12818. return splitPathRe.exec(filename).slice(1);
  12819. }
  12820. posix.parse = function (pathString) {
  12821. if (typeof pathString !== 'string') {
  12822. throw new TypeError("Parameter 'pathString' must be a string, not " + typeof pathString);
  12823. }
  12824. var allParts = posixSplitPath(pathString);
  12825. if (!allParts || allParts.length !== 4) {
  12826. throw new TypeError("Invalid path '" + pathString + "'");
  12827. }
  12828. allParts[1] = allParts[1] || '';
  12829. allParts[2] = allParts[2] || '';
  12830. allParts[3] = allParts[3] || '';
  12831. return {
  12832. root: allParts[0],
  12833. dir: allParts[0] + allParts[1].slice(0, -1),
  12834. base: allParts[2],
  12835. ext: allParts[3],
  12836. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  12837. };
  12838. };
  12839. if (isWindows) module.exports = win32.parse;else
  12840. /* posix */
  12841. module.exports = posix.parse;
  12842. module.exports.posix = posix.parse;
  12843. module.exports.win32 = win32.parse;
  12844. });
  12845. var pathParse_1 = pathParse.posix;
  12846. var pathParse_2 = pathParse.win32;
  12847. var parse$2 = path$2.parse || pathParse;
  12848. var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) {
  12849. var prefix = '/';
  12850. if (/^([A-Za-z]:)/.test(absoluteStart)) {
  12851. prefix = '';
  12852. } else if (/^\\\\/.test(absoluteStart)) {
  12853. prefix = '\\\\';
  12854. }
  12855. var paths = [absoluteStart];
  12856. var parsed = parse$2(absoluteStart);
  12857. while (parsed.dir !== paths[paths.length - 1]) {
  12858. paths.push(parsed.dir);
  12859. parsed = parse$2(parsed.dir);
  12860. }
  12861. return paths.reduce(function (dirs, aPath) {
  12862. return dirs.concat(modules.map(function (moduleDir) {
  12863. return path$2.resolve(prefix, aPath, moduleDir);
  12864. }));
  12865. }, []);
  12866. };
  12867. var nodeModulesPaths = function nodeModulesPaths(start, opts, request) {
  12868. var modules = opts && opts.moduleDirectory ? [].concat(opts.moduleDirectory) : ['node_modules'];
  12869. if (opts && typeof opts.paths === 'function') {
  12870. return opts.paths(request, start, function () {
  12871. return getNodeModulesDirs(start, modules);
  12872. }, opts);
  12873. }
  12874. var dirs = getNodeModulesDirs(start, modules);
  12875. return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
  12876. };
  12877. var normalizeOptions$2 = function normalizeOptions(x, opts) {
  12878. /**
  12879. * This file is purposefully a passthrough. It's expected that third-party
  12880. * environments will override it at runtime in order to inject special logic
  12881. * into `resolve` (by manipulating the options). One such example is the PnP
  12882. * code path in Yarn.
  12883. */
  12884. return opts || {};
  12885. };
  12886. var defaultIsFile = function isFile(file, cb) {
  12887. fs$1.stat(file, function (err, stat) {
  12888. if (!err) {
  12889. return cb(null, stat.isFile() || stat.isFIFO());
  12890. }
  12891. if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
  12892. return cb(err);
  12893. });
  12894. };
  12895. var defaultIsDir = function isDirectory(dir, cb) {
  12896. fs$1.stat(dir, function (err, stat) {
  12897. if (!err) {
  12898. return cb(null, stat.isDirectory());
  12899. }
  12900. if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
  12901. return cb(err);
  12902. });
  12903. };
  12904. var maybeUnwrapSymlink = function maybeUnwrapSymlink(x, opts, cb) {
  12905. if (opts && opts.preserveSymlinks === false) {
  12906. fs$1.realpath(x, function (realPathErr, realPath) {
  12907. if (realPathErr && realPathErr.code !== 'ENOENT') cb(realPathErr);else cb(null, realPathErr ? x : realPath);
  12908. });
  12909. } else {
  12910. cb(null, x);
  12911. }
  12912. };
  12913. var async = function resolve(x, options, callback) {
  12914. var cb = callback;
  12915. var opts = options;
  12916. if (typeof options === 'function') {
  12917. cb = opts;
  12918. opts = {};
  12919. }
  12920. if (typeof x !== 'string') {
  12921. var err = new TypeError('Path must be a string.');
  12922. return process.nextTick(function () {
  12923. cb(err);
  12924. });
  12925. }
  12926. opts = normalizeOptions$2(x, opts);
  12927. var isFile = opts.isFile || defaultIsFile;
  12928. var isDirectory = opts.isDirectory || defaultIsDir;
  12929. var readFile = opts.readFile || fs$1.readFile;
  12930. var extensions = opts.extensions || ['.js'];
  12931. var basedir = opts.basedir || path$2.dirname(caller());
  12932. var parent = opts.filename || basedir;
  12933. opts.paths = opts.paths || []; // ensure that `basedir` is an absolute path at this point, resolving against the process' current working directory
  12934. var absoluteStart = path$2.resolve(basedir);
  12935. maybeUnwrapSymlink(absoluteStart, opts, function (err, realStart) {
  12936. if (err) cb(err);else init(realStart);
  12937. });
  12938. var res;
  12939. function init(basedir) {
  12940. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  12941. res = path$2.resolve(basedir, x);
  12942. if (x === '..' || x.slice(-1) === '/') res += '/';
  12943. if (/\/$/.test(x) && res === basedir) {
  12944. loadAsDirectory(res, opts.package, onfile);
  12945. } else loadAsFile(res, opts.package, onfile);
  12946. } else loadNodeModules(x, basedir, function (err, n, pkg) {
  12947. if (err) cb(err);else if (core_1[x]) return cb(null, x);else if (n) {
  12948. return maybeUnwrapSymlink(n, opts, function (err, realN) {
  12949. if (err) {
  12950. cb(err);
  12951. } else {
  12952. cb(null, realN, pkg);
  12953. }
  12954. });
  12955. } else {
  12956. var moduleError = new Error("Cannot find module '" + x + "' from '" + parent + "'");
  12957. moduleError.code = 'MODULE_NOT_FOUND';
  12958. cb(moduleError);
  12959. }
  12960. });
  12961. }
  12962. function onfile(err, m, pkg) {
  12963. if (err) cb(err);else if (m) cb(null, m, pkg);else loadAsDirectory(res, function (err, d, pkg) {
  12964. if (err) cb(err);else if (d) {
  12965. maybeUnwrapSymlink(d, opts, function (err, realD) {
  12966. if (err) {
  12967. cb(err);
  12968. } else {
  12969. cb(null, realD, pkg);
  12970. }
  12971. });
  12972. } else {
  12973. var moduleError = new Error("Cannot find module '" + x + "' from '" + parent + "'");
  12974. moduleError.code = 'MODULE_NOT_FOUND';
  12975. cb(moduleError);
  12976. }
  12977. });
  12978. }
  12979. function loadAsFile(x, thePackage, callback) {
  12980. var loadAsFilePackage = thePackage;
  12981. var cb = callback;
  12982. if (typeof loadAsFilePackage === 'function') {
  12983. cb = loadAsFilePackage;
  12984. loadAsFilePackage = undefined;
  12985. }
  12986. var exts = [''].concat(extensions);
  12987. load(exts, x, loadAsFilePackage);
  12988. function load(exts, x, loadPackage) {
  12989. if (exts.length === 0) return cb(null, undefined, loadPackage);
  12990. var file = x + exts[0];
  12991. var pkg = loadPackage;
  12992. if (pkg) onpkg(null, pkg);else loadpkg(path$2.dirname(file), onpkg);
  12993. function onpkg(err, pkg_, dir) {
  12994. pkg = pkg_;
  12995. if (err) return cb(err);
  12996. if (dir && pkg && opts.pathFilter) {
  12997. var rfile = path$2.relative(dir, file);
  12998. var rel = rfile.slice(0, rfile.length - exts[0].length);
  12999. var r = opts.pathFilter(pkg, x, rel);
  13000. if (r) return load([''].concat(extensions.slice()), path$2.resolve(dir, r), pkg);
  13001. }
  13002. isFile(file, onex);
  13003. }
  13004. function onex(err, ex) {
  13005. if (err) return cb(err);
  13006. if (ex) return cb(null, file, pkg);
  13007. load(exts.slice(1), x, pkg);
  13008. }
  13009. }
  13010. }
  13011. function loadpkg(dir, cb) {
  13012. if (dir === '' || dir === '/') return cb(null);
  13013. if (process.platform === 'win32' && /^\w:[/\\]*$/.test(dir)) {
  13014. return cb(null);
  13015. }
  13016. if (/[/\\]node_modules[/\\]*$/.test(dir)) return cb(null);
  13017. var pkgfile = path$2.join(dir, 'package.json');
  13018. isFile(pkgfile, function (err, ex) {
  13019. // on err, ex is false
  13020. if (!ex) return loadpkg(path$2.dirname(dir), cb);
  13021. readFile(pkgfile, function (err, body) {
  13022. if (err) cb(err);
  13023. try {
  13024. var pkg = JSON.parse(body);
  13025. } catch (jsonErr) {}
  13026. if (pkg && opts.packageFilter) {
  13027. pkg = opts.packageFilter(pkg, pkgfile);
  13028. }
  13029. cb(null, pkg, dir);
  13030. });
  13031. });
  13032. }
  13033. function loadAsDirectory(x, loadAsDirectoryPackage, callback) {
  13034. var cb = callback;
  13035. var fpkg = loadAsDirectoryPackage;
  13036. if (typeof fpkg === 'function') {
  13037. cb = fpkg;
  13038. fpkg = opts.package;
  13039. }
  13040. var pkgfile = path$2.join(x, 'package.json');
  13041. isFile(pkgfile, function (err, ex) {
  13042. if (err) return cb(err);
  13043. if (!ex) return loadAsFile(path$2.join(x, 'index'), fpkg, cb);
  13044. readFile(pkgfile, function (err, body) {
  13045. if (err) return cb(err);
  13046. try {
  13047. var pkg = JSON.parse(body);
  13048. } catch (jsonErr) {}
  13049. if (opts.packageFilter) {
  13050. pkg = opts.packageFilter(pkg, pkgfile);
  13051. }
  13052. if (pkg.main) {
  13053. if (typeof pkg.main !== 'string') {
  13054. var mainError = new TypeError('package “' + pkg.name + '” `main` must be a string');
  13055. mainError.code = 'INVALID_PACKAGE_MAIN';
  13056. return cb(mainError);
  13057. }
  13058. if (pkg.main === '.' || pkg.main === './') {
  13059. pkg.main = 'index';
  13060. }
  13061. loadAsFile(path$2.resolve(x, pkg.main), pkg, function (err, m, pkg) {
  13062. if (err) return cb(err);
  13063. if (m) return cb(null, m, pkg);
  13064. if (!pkg) return loadAsFile(path$2.join(x, 'index'), pkg, cb);
  13065. var dir = path$2.resolve(x, pkg.main);
  13066. loadAsDirectory(dir, pkg, function (err, n, pkg) {
  13067. if (err) return cb(err);
  13068. if (n) return cb(null, n, pkg);
  13069. loadAsFile(path$2.join(x, 'index'), pkg, cb);
  13070. });
  13071. });
  13072. return;
  13073. }
  13074. loadAsFile(path$2.join(x, '/index'), pkg, cb);
  13075. });
  13076. });
  13077. }
  13078. function processDirs(cb, dirs) {
  13079. if (dirs.length === 0) return cb(null, undefined);
  13080. var dir = dirs[0];
  13081. isDirectory(dir, isdir);
  13082. function isdir(err, isdir) {
  13083. if (err) return cb(err);
  13084. if (!isdir) return processDirs(cb, dirs.slice(1));
  13085. var file = path$2.join(dir, x);
  13086. loadAsFile(file, opts.package, onfile);
  13087. }
  13088. function onfile(err, m, pkg) {
  13089. if (err) return cb(err);
  13090. if (m) return cb(null, m, pkg);
  13091. loadAsDirectory(path$2.join(dir, x), opts.package, ondir);
  13092. }
  13093. function ondir(err, n, pkg) {
  13094. if (err) return cb(err);
  13095. if (n) return cb(null, n, pkg);
  13096. processDirs(cb, dirs.slice(1));
  13097. }
  13098. }
  13099. function loadNodeModules(x, start, cb) {
  13100. processDirs(cb, nodeModulesPaths(start, opts, x));
  13101. }
  13102. };
  13103. var defaultIsFile$1 = function isFile(file) {
  13104. try {
  13105. var stat = fs$1.statSync(file);
  13106. } catch (e) {
  13107. if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
  13108. throw e;
  13109. }
  13110. return stat.isFile() || stat.isFIFO();
  13111. };
  13112. var defaultIsDir$1 = function isDirectory(dir) {
  13113. try {
  13114. var stat = fs$1.statSync(dir);
  13115. } catch (e) {
  13116. if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
  13117. throw e;
  13118. }
  13119. return stat.isDirectory();
  13120. };
  13121. var maybeUnwrapSymlink$1 = function maybeUnwrapSymlink(x, opts) {
  13122. if (opts && opts.preserveSymlinks === false) {
  13123. try {
  13124. return fs$1.realpathSync(x);
  13125. } catch (realPathErr) {
  13126. if (realPathErr.code !== 'ENOENT') {
  13127. throw realPathErr;
  13128. }
  13129. }
  13130. }
  13131. return x;
  13132. };
  13133. var sync = function sync(x, options) {
  13134. if (typeof x !== 'string') {
  13135. throw new TypeError('Path must be a string.');
  13136. }
  13137. var opts = normalizeOptions$2(x, options);
  13138. var isFile = opts.isFile || defaultIsFile$1;
  13139. var readFileSync = opts.readFileSync || fs$1.readFileSync;
  13140. var isDirectory = opts.isDirectory || defaultIsDir$1;
  13141. var extensions = opts.extensions || ['.js'];
  13142. var basedir = opts.basedir || path$2.dirname(caller());
  13143. var parent = opts.filename || basedir;
  13144. opts.paths = opts.paths || []; // ensure that `basedir` is an absolute path at this point, resolving against the process' current working directory
  13145. var absoluteStart = maybeUnwrapSymlink$1(path$2.resolve(basedir), opts);
  13146. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  13147. var res = path$2.resolve(absoluteStart, x);
  13148. if (x === '..' || x.slice(-1) === '/') res += '/';
  13149. var m = loadAsFileSync(res) || loadAsDirectorySync(res);
  13150. if (m) return maybeUnwrapSymlink$1(m, opts);
  13151. } else if (core_1[x]) {
  13152. return x;
  13153. } else {
  13154. var n = loadNodeModulesSync(x, absoluteStart);
  13155. if (n) return maybeUnwrapSymlink$1(n, opts);
  13156. }
  13157. if (core_1[x]) return x;
  13158. var err = new Error("Cannot find module '" + x + "' from '" + parent + "'");
  13159. err.code = 'MODULE_NOT_FOUND';
  13160. throw err;
  13161. function loadAsFileSync(x) {
  13162. var pkg = loadpkg(path$2.dirname(x));
  13163. if (pkg && pkg.dir && pkg.pkg && opts.pathFilter) {
  13164. var rfile = path$2.relative(pkg.dir, x);
  13165. var r = opts.pathFilter(pkg.pkg, x, rfile);
  13166. if (r) {
  13167. x = path$2.resolve(pkg.dir, r); // eslint-disable-line no-param-reassign
  13168. }
  13169. }
  13170. if (isFile(x)) {
  13171. return x;
  13172. }
  13173. for (var i = 0; i < extensions.length; i++) {
  13174. var file = x + extensions[i];
  13175. if (isFile(file)) {
  13176. return file;
  13177. }
  13178. }
  13179. }
  13180. function loadpkg(dir) {
  13181. if (dir === '' || dir === '/') return;
  13182. if (process.platform === 'win32' && /^\w:[/\\]*$/.test(dir)) {
  13183. return;
  13184. }
  13185. if (/[/\\]node_modules[/\\]*$/.test(dir)) return;
  13186. var pkgfile = path$2.join(dir, 'package.json');
  13187. if (!isFile(pkgfile)) {
  13188. return loadpkg(path$2.dirname(dir));
  13189. }
  13190. var body = readFileSync(pkgfile);
  13191. try {
  13192. var pkg = JSON.parse(body);
  13193. } catch (jsonErr) {}
  13194. if (pkg && opts.packageFilter) {
  13195. pkg = opts.packageFilter(pkg, dir);
  13196. }
  13197. return {
  13198. pkg: pkg,
  13199. dir: dir
  13200. };
  13201. }
  13202. function loadAsDirectorySync(x) {
  13203. var pkgfile = path$2.join(x, '/package.json');
  13204. if (isFile(pkgfile)) {
  13205. try {
  13206. var body = readFileSync(pkgfile, 'UTF8');
  13207. var pkg = JSON.parse(body);
  13208. } catch (e) {}
  13209. if (opts.packageFilter) {
  13210. pkg = opts.packageFilter(pkg, x);
  13211. }
  13212. if (pkg.main) {
  13213. if (typeof pkg.main !== 'string') {
  13214. var mainError = new TypeError('package “' + pkg.name + '” `main` must be a string');
  13215. mainError.code = 'INVALID_PACKAGE_MAIN';
  13216. throw mainError;
  13217. }
  13218. if (pkg.main === '.' || pkg.main === './') {
  13219. pkg.main = 'index';
  13220. }
  13221. try {
  13222. var m = loadAsFileSync(path$2.resolve(x, pkg.main));
  13223. if (m) return m;
  13224. var n = loadAsDirectorySync(path$2.resolve(x, pkg.main));
  13225. if (n) return n;
  13226. } catch (e) {}
  13227. }
  13228. }
  13229. return loadAsFileSync(path$2.join(x, '/index'));
  13230. }
  13231. function loadNodeModulesSync(x, start) {
  13232. var dirs = nodeModulesPaths(start, opts, x);
  13233. for (var i = 0; i < dirs.length; i++) {
  13234. var dir = dirs[i];
  13235. if (isDirectory(dir)) {
  13236. var m = loadAsFileSync(path$2.join(dir, '/', x));
  13237. if (m) return m;
  13238. var n = loadAsDirectorySync(path$2.join(dir, '/', x));
  13239. if (n) return n;
  13240. }
  13241. }
  13242. }
  13243. };
  13244. var resolve = createCommonjsModule(function (module, exports) {
  13245. async.core = core_1;
  13246. async.isCore = function isCore(x) {
  13247. return core_1[x];
  13248. };
  13249. async.sync = sync;
  13250. module.exports = async;
  13251. });
  13252. var mimicFn = function mimicFn(to, from) {
  13253. var _iteratorNormalCompletion = true;
  13254. var _didIteratorError = false;
  13255. var _iteratorError = undefined;
  13256. try {
  13257. for (var _iterator = Reflect.ownKeys(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  13258. var prop = _step.value;
  13259. Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
  13260. }
  13261. } catch (err) {
  13262. _didIteratorError = true;
  13263. _iteratorError = err;
  13264. } finally {
  13265. try {
  13266. if (!_iteratorNormalCompletion && _iterator.return != null) {
  13267. _iterator.return();
  13268. }
  13269. } finally {
  13270. if (_didIteratorError) {
  13271. throw _iteratorError;
  13272. }
  13273. }
  13274. }
  13275. return to;
  13276. };
  13277. var mimicFn_1 = mimicFn; // TODO: Remove this for the next major release
  13278. var default_1$4 = mimicFn;
  13279. mimicFn_1.default = default_1$4;
  13280. var isPromise = function isPromise(input) {
  13281. return input instanceof Promise || input !== null && typeof input === 'object' && typeof input.then === 'function' && typeof input.catch === 'function';
  13282. };
  13283. var pIsPromise = isPromise; // TODO: Remove this for the next major release
  13284. var default_1$5 = isPromise;
  13285. pIsPromise.default = default_1$5;
  13286. var pDefer = function pDefer() {
  13287. var ret = {};
  13288. ret.promise = new Promise(function (resolve, reject) {
  13289. ret.resolve = resolve;
  13290. ret.reject = reject;
  13291. });
  13292. return ret;
  13293. };
  13294. var dist = createCommonjsModule(function (module, exports) {
  13295. var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
  13296. return new (P || (P = Promise))(function (resolve, reject) {
  13297. function fulfilled(value) {
  13298. try {
  13299. step(generator.next(value));
  13300. } catch (e) {
  13301. reject(e);
  13302. }
  13303. }
  13304. function rejected(value) {
  13305. try {
  13306. step(generator["throw"](value));
  13307. } catch (e) {
  13308. reject(e);
  13309. }
  13310. }
  13311. function step(result) {
  13312. result.done ? resolve(result.value) : new P(function (resolve) {
  13313. resolve(result.value);
  13314. }).then(fulfilled, rejected);
  13315. }
  13316. step((generator = generator.apply(thisArg, _arguments || [])).next());
  13317. });
  13318. };
  13319. var __importDefault = this && this.__importDefault || function (mod) {
  13320. return mod && mod.__esModule ? mod : {
  13321. "default": mod
  13322. };
  13323. };
  13324. Object.defineProperty(exports, "__esModule", {
  13325. value: true
  13326. });
  13327. var p_defer_1 = __importDefault(pDefer);
  13328. function mapAgeCleaner(map) {
  13329. var _this = this;
  13330. var property = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'maxAge';
  13331. var processingKey;
  13332. var processingTimer;
  13333. var processingDeferred;
  13334. var cleanup = function cleanup() {
  13335. return __awaiter(_this, void 0, void 0,
  13336. /*#__PURE__*/
  13337. regeneratorRuntime.mark(function _callee2() {
  13338. var _this2 = this;
  13339. var setupTimer, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, entry;
  13340. return regeneratorRuntime.wrap(function _callee2$(_context2) {
  13341. while (1) {
  13342. switch (_context2.prev = _context2.next) {
  13343. case 0:
  13344. if (!(processingKey !== undefined)) {
  13345. _context2.next = 2;
  13346. break;
  13347. }
  13348. return _context2.abrupt("return");
  13349. case 2:
  13350. setupTimer = function setupTimer(item) {
  13351. return __awaiter(_this2, void 0, void 0,
  13352. /*#__PURE__*/
  13353. regeneratorRuntime.mark(function _callee() {
  13354. var delay;
  13355. return regeneratorRuntime.wrap(function _callee$(_context) {
  13356. while (1) {
  13357. switch (_context.prev = _context.next) {
  13358. case 0:
  13359. processingDeferred = p_defer_1.default();
  13360. delay = item[1][property] - Date.now();
  13361. if (!(delay <= 0)) {
  13362. _context.next = 6;
  13363. break;
  13364. }
  13365. // Remove the item immediately if the delay is equal to or below 0
  13366. map.delete(item[0]);
  13367. processingDeferred.resolve();
  13368. return _context.abrupt("return");
  13369. case 6:
  13370. // Keep track of the current processed key
  13371. processingKey = item[0];
  13372. processingTimer = setTimeout(function () {
  13373. // Remove the item when the timeout fires
  13374. map.delete(item[0]);
  13375. if (processingDeferred) {
  13376. processingDeferred.resolve();
  13377. }
  13378. }, delay); // tslint:disable-next-line:strict-type-predicates
  13379. if (typeof processingTimer.unref === 'function') {
  13380. // Don't hold up the process from exiting
  13381. processingTimer.unref();
  13382. }
  13383. return _context.abrupt("return", processingDeferred.promise);
  13384. case 10:
  13385. case "end":
  13386. return _context.stop();
  13387. }
  13388. }
  13389. }, _callee);
  13390. }));
  13391. };
  13392. _context2.prev = 3;
  13393. _iteratorNormalCompletion = true;
  13394. _didIteratorError = false;
  13395. _iteratorError = undefined;
  13396. _context2.prev = 7;
  13397. _iterator = map[Symbol.iterator]();
  13398. case 9:
  13399. if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
  13400. _context2.next = 16;
  13401. break;
  13402. }
  13403. entry = _step.value;
  13404. _context2.next = 13;
  13405. return setupTimer(entry);
  13406. case 13:
  13407. _iteratorNormalCompletion = true;
  13408. _context2.next = 9;
  13409. break;
  13410. case 16:
  13411. _context2.next = 22;
  13412. break;
  13413. case 18:
  13414. _context2.prev = 18;
  13415. _context2.t0 = _context2["catch"](7);
  13416. _didIteratorError = true;
  13417. _iteratorError = _context2.t0;
  13418. case 22:
  13419. _context2.prev = 22;
  13420. _context2.prev = 23;
  13421. if (!_iteratorNormalCompletion && _iterator.return != null) {
  13422. _iterator.return();
  13423. }
  13424. case 25:
  13425. _context2.prev = 25;
  13426. if (!_didIteratorError) {
  13427. _context2.next = 28;
  13428. break;
  13429. }
  13430. throw _iteratorError;
  13431. case 28:
  13432. return _context2.finish(25);
  13433. case 29:
  13434. return _context2.finish(22);
  13435. case 30:
  13436. _context2.next = 34;
  13437. break;
  13438. case 32:
  13439. _context2.prev = 32;
  13440. _context2.t1 = _context2["catch"](3);
  13441. case 34:
  13442. processingKey = undefined;
  13443. case 35:
  13444. case "end":
  13445. return _context2.stop();
  13446. }
  13447. }
  13448. }, _callee2, null, [[3, 32], [7, 18, 22, 30], [23,, 25, 29]]);
  13449. }));
  13450. };
  13451. var reset = function reset() {
  13452. processingKey = undefined;
  13453. if (processingTimer !== undefined) {
  13454. clearTimeout(processingTimer);
  13455. processingTimer = undefined;
  13456. }
  13457. if (processingDeferred !== undefined) {
  13458. // tslint:disable-line:early-exit
  13459. processingDeferred.reject(undefined);
  13460. processingDeferred = undefined;
  13461. }
  13462. };
  13463. var originalSet = map.set.bind(map);
  13464. map.set = function (key, value) {
  13465. if (map.has(key)) {
  13466. // If the key already exist, remove it so we can add it back at the end of the map.
  13467. map.delete(key);
  13468. } // Call the original `map.set`
  13469. var result = originalSet(key, value); // If we are already processing a key and the key added is the current processed key, stop processing it
  13470. if (processingKey && processingKey === key) {
  13471. reset();
  13472. } // Always run the cleanup method in case it wasn't started yet
  13473. cleanup(); // tslint:disable-line:no-floating-promises
  13474. return result;
  13475. };
  13476. cleanup(); // tslint:disable-line:no-floating-promises
  13477. return map;
  13478. }
  13479. exports.default = mapAgeCleaner; // Add support for CJS
  13480. module.exports = mapAgeCleaner;
  13481. module.exports.default = mapAgeCleaner;
  13482. });
  13483. unwrapExports(dist);
  13484. var cacheStore = new WeakMap();
  13485. var defaultCacheKey = function defaultCacheKey() {
  13486. for (var _len = arguments.length, arguments_ = new Array(_len), _key = 0; _key < _len; _key++) {
  13487. arguments_[_key] = arguments[_key];
  13488. }
  13489. if (arguments_.length === 0) {
  13490. return '__defaultKey';
  13491. }
  13492. if (arguments_.length === 1) {
  13493. var firstArgument = arguments_[0];
  13494. var isObject = typeof firstArgument === 'object' && firstArgument !== null;
  13495. var isPrimitive = !isObject;
  13496. if (isPrimitive) {
  13497. return firstArgument;
  13498. }
  13499. }
  13500. return JSON.stringify(arguments_);
  13501. };
  13502. var mem = function mem(fn) {
  13503. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  13504. _ref$cacheKey = _ref.cacheKey,
  13505. cacheKey = _ref$cacheKey === void 0 ? defaultCacheKey : _ref$cacheKey,
  13506. _ref$cache = _ref.cache,
  13507. cache = _ref$cache === void 0 ? new Map() : _ref$cache,
  13508. _ref$cachePromiseReje = _ref.cachePromiseRejection,
  13509. cachePromiseRejection = _ref$cachePromiseReje === void 0 ? true : _ref$cachePromiseReje,
  13510. maxAge = _ref.maxAge;
  13511. if (typeof maxAge === 'number') {
  13512. dist(cache);
  13513. }
  13514. var memoized = function memoized() {
  13515. for (var _len2 = arguments.length, arguments_ = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  13516. arguments_[_key2] = arguments[_key2];
  13517. }
  13518. var key = cacheKey.apply(void 0, arguments_);
  13519. if (cache.has(key)) {
  13520. return cache.get(key).data;
  13521. }
  13522. var cacheItem = fn.apply(this, arguments_);
  13523. cache.set(key, {
  13524. data: cacheItem,
  13525. maxAge: maxAge ? Date.now() + maxAge : Infinity
  13526. });
  13527. if (pIsPromise(cacheItem) && cachePromiseRejection === false) {
  13528. cacheItem.catch(function () {
  13529. return cache.delete(key);
  13530. });
  13531. }
  13532. return cacheItem;
  13533. };
  13534. try {
  13535. // The below call will throw in some host environments
  13536. // See https://github.com/sindresorhus/mimic-fn/issues/10
  13537. mimicFn_1(memoized, fn);
  13538. } catch (_) {}
  13539. cacheStore.set(memoized, cache);
  13540. return memoized;
  13541. };
  13542. var mem_1 = mem;
  13543. var clear = function clear(fn) {
  13544. var cache = cacheStore.get(fn);
  13545. if (cache && typeof cache.clear === 'function') {
  13546. cache.clear();
  13547. }
  13548. };
  13549. mem_1.clear = clear;
  13550. var semver$1 = createCommonjsModule(function (module, exports) {
  13551. exports = module.exports = SemVer; // The debug function is excluded entirely from the minified version.
  13552. /* nomin */
  13553. var debug;
  13554. /* nomin */
  13555. if (typeof process === 'object' &&
  13556. /* nomin */
  13557. process.env &&
  13558. /* nomin */
  13559. process.env.NODE_DEBUG &&
  13560. /* nomin */
  13561. /\bsemver\b/i.test(process.env.NODE_DEBUG))
  13562. /* nomin */
  13563. debug = function debug() {
  13564. /* nomin */
  13565. var args = Array.prototype.slice.call(arguments, 0);
  13566. /* nomin */
  13567. args.unshift('SEMVER');
  13568. /* nomin */
  13569. console.log.apply(console, args);
  13570. /* nomin */
  13571. };
  13572. /* nomin */
  13573. else
  13574. /* nomin */
  13575. debug = function debug() {}; // Note: this is the semver.org version of the spec that it implements
  13576. // Not necessarily the package version of this code.
  13577. exports.SEMVER_SPEC_VERSION = '2.0.0';
  13578. var MAX_LENGTH = 256;
  13579. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // Max safe segment length for coercion.
  13580. var MAX_SAFE_COMPONENT_LENGTH = 16; // The actual regexps go on exports.re
  13581. var re = exports.re = [];
  13582. var src = exports.src = [];
  13583. var R = 0; // The following Regular Expressions can be used for tokenizing,
  13584. // validating, and parsing SemVer version strings.
  13585. // ## Numeric Identifier
  13586. // A single `0`, or a non-zero digit followed by zero or more digits.
  13587. var NUMERICIDENTIFIER = R++;
  13588. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  13589. var NUMERICIDENTIFIERLOOSE = R++;
  13590. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
  13591. // Zero or more digits, followed by a letter or hyphen, and then zero or
  13592. // more letters, digits, or hyphens.
  13593. var NONNUMERICIDENTIFIER = R++;
  13594. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
  13595. // Three dot-separated numeric identifiers.
  13596. var MAINVERSION = R++;
  13597. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')';
  13598. var MAINVERSIONLOOSE = R++;
  13599. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
  13600. // A numeric identifier, or a non-numeric identifier.
  13601. var PRERELEASEIDENTIFIER = R++;
  13602. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + '|' + src[NONNUMERICIDENTIFIER] + ')';
  13603. var PRERELEASEIDENTIFIERLOOSE = R++;
  13604. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + '|' + src[NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
  13605. // Hyphen, followed by one or more dot-separated pre-release version
  13606. // identifiers.
  13607. var PRERELEASE = R++;
  13608. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  13609. var PRERELEASELOOSE = R++;
  13610. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
  13611. // Any combination of digits, letters, or hyphens.
  13612. var BUILDIDENTIFIER = R++;
  13613. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
  13614. // Plus sign, followed by one or more period-separated build metadata
  13615. // identifiers.
  13616. var BUILD = R++;
  13617. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'; // ## Full Version String
  13618. // A main version, followed optionally by a pre-release version and
  13619. // build metadata.
  13620. // Note that the only major, minor, patch, and pre-release sections of
  13621. // the version string are capturing groups. The build metadata is not a
  13622. // capturing group, because it should not ever be used in version
  13623. // comparison.
  13624. var FULL = R++;
  13625. var FULLPLAIN = 'v?' + src[MAINVERSION] + src[PRERELEASE] + '?' + src[BUILD] + '?';
  13626. src[FULL] = '^' + FULLPLAIN + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  13627. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  13628. // common in the npm registry.
  13629. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + src[PRERELEASELOOSE] + '?' + src[BUILD] + '?';
  13630. var LOOSE = R++;
  13631. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  13632. var GTLT = R++;
  13633. src[GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
  13634. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  13635. // Only the first item is strictly required.
  13636. var XRANGEIDENTIFIERLOOSE = R++;
  13637. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  13638. var XRANGEIDENTIFIER = R++;
  13639. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  13640. var XRANGEPLAIN = R++;
  13641. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:' + src[PRERELEASE] + ')?' + src[BUILD] + '?' + ')?)?';
  13642. var XRANGEPLAINLOOSE = R++;
  13643. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[PRERELEASELOOSE] + ')?' + src[BUILD] + '?' + ')?)?';
  13644. var XRANGE = R++;
  13645. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  13646. var XRANGELOOSE = R++;
  13647. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'; // Coercion.
  13648. // Extract anything that could conceivably be a part of a valid semver
  13649. var COERCE = R++;
  13650. src[COERCE] = '(?:^|[^\\d])' + '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:$|[^\\d])'; // Tilde ranges.
  13651. // Meaning is "reasonably at or greater than"
  13652. var LONETILDE = R++;
  13653. src[LONETILDE] = '(?:~>?)';
  13654. var TILDETRIM = R++;
  13655. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  13656. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  13657. var tildeTrimReplace = '$1~';
  13658. var TILDE = R++;
  13659. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  13660. var TILDELOOSE = R++;
  13661. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'; // Caret ranges.
  13662. // Meaning is "at least and backwards compatible with"
  13663. var LONECARET = R++;
  13664. src[LONECARET] = '(?:\\^)';
  13665. var CARETTRIM = R++;
  13666. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  13667. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  13668. var caretTrimReplace = '$1^';
  13669. var CARET = R++;
  13670. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  13671. var CARETLOOSE = R++;
  13672. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
  13673. var COMPARATORLOOSE = R++;
  13674. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  13675. var COMPARATOR = R++;
  13676. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
  13677. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  13678. var COMPARATORTRIM = R++;
  13679. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'; // this one has to use the /g flag
  13680. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  13681. var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  13682. // Note that these all use the loose form, because they'll be
  13683. // checked against either the strict or loose comparator form
  13684. // later.
  13685. var HYPHENRANGE = R++;
  13686. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAIN] + ')' + '\\s*$';
  13687. var HYPHENRANGELOOSE = R++;
  13688. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
  13689. var STAR = R++;
  13690. src[STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
  13691. // All are flag-free, unless they were created above with a flag.
  13692. for (var i = 0; i < R; i++) {
  13693. debug(i, src[i]);
  13694. if (!re[i]) re[i] = new RegExp(src[i]);
  13695. }
  13696. exports.parse = parse;
  13697. function parse(version, options) {
  13698. if (!options || typeof options !== 'object') options = {
  13699. loose: !!options,
  13700. includePrerelease: false
  13701. };
  13702. if (version instanceof SemVer) return version;
  13703. if (typeof version !== 'string') return null;
  13704. if (version.length > MAX_LENGTH) return null;
  13705. var r = options.loose ? re[LOOSE] : re[FULL];
  13706. if (!r.test(version)) return null;
  13707. try {
  13708. return new SemVer(version, options);
  13709. } catch (er) {
  13710. return null;
  13711. }
  13712. }
  13713. exports.valid = valid;
  13714. function valid(version, options) {
  13715. var v = parse(version, options);
  13716. return v ? v.version : null;
  13717. }
  13718. exports.clean = clean;
  13719. function clean(version, options) {
  13720. var s = parse(version.trim().replace(/^[=v]+/, ''), options);
  13721. return s ? s.version : null;
  13722. }
  13723. exports.SemVer = SemVer;
  13724. function SemVer(version, options) {
  13725. if (!options || typeof options !== 'object') options = {
  13726. loose: !!options,
  13727. includePrerelease: false
  13728. };
  13729. if (version instanceof SemVer) {
  13730. if (version.loose === options.loose) return version;else version = version.version;
  13731. } else if (typeof version !== 'string') {
  13732. throw new TypeError('Invalid Version: ' + version);
  13733. }
  13734. if (version.length > MAX_LENGTH) throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
  13735. if (!(this instanceof SemVer)) return new SemVer(version, options);
  13736. debug('SemVer', version, options);
  13737. this.options = options;
  13738. this.loose = !!options.loose;
  13739. var m = version.trim().match(options.loose ? re[LOOSE] : re[FULL]);
  13740. if (!m) throw new TypeError('Invalid Version: ' + version);
  13741. this.raw = version; // these are actually numbers
  13742. this.major = +m[1];
  13743. this.minor = +m[2];
  13744. this.patch = +m[3];
  13745. if (this.major > MAX_SAFE_INTEGER || this.major < 0) throw new TypeError('Invalid major version');
  13746. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) throw new TypeError('Invalid minor version');
  13747. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) throw new TypeError('Invalid patch version'); // numberify any prerelease numeric ids
  13748. if (!m[4]) this.prerelease = [];else this.prerelease = m[4].split('.').map(function (id) {
  13749. if (/^[0-9]+$/.test(id)) {
  13750. var num = +id;
  13751. if (num >= 0 && num < MAX_SAFE_INTEGER) return num;
  13752. }
  13753. return id;
  13754. });
  13755. this.build = m[5] ? m[5].split('.') : [];
  13756. this.format();
  13757. }
  13758. SemVer.prototype.format = function () {
  13759. this.version = this.major + '.' + this.minor + '.' + this.patch;
  13760. if (this.prerelease.length) this.version += '-' + this.prerelease.join('.');
  13761. return this.version;
  13762. };
  13763. SemVer.prototype.toString = function () {
  13764. return this.version;
  13765. };
  13766. SemVer.prototype.compare = function (other) {
  13767. debug('SemVer.compare', this.version, this.options, other);
  13768. if (!(other instanceof SemVer)) other = new SemVer(other, this.options);
  13769. return this.compareMain(other) || this.comparePre(other);
  13770. };
  13771. SemVer.prototype.compareMain = function (other) {
  13772. if (!(other instanceof SemVer)) other = new SemVer(other, this.options);
  13773. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  13774. };
  13775. SemVer.prototype.comparePre = function (other) {
  13776. if (!(other instanceof SemVer)) other = new SemVer(other, this.options); // NOT having a prerelease is > having one
  13777. if (this.prerelease.length && !other.prerelease.length) return -1;else if (!this.prerelease.length && other.prerelease.length) return 1;else if (!this.prerelease.length && !other.prerelease.length) return 0;
  13778. var i = 0;
  13779. do {
  13780. var a = this.prerelease[i];
  13781. var b = other.prerelease[i];
  13782. debug('prerelease compare', i, a, b);
  13783. if (a === undefined && b === undefined) return 0;else if (b === undefined) return 1;else if (a === undefined) return -1;else if (a === b) continue;else return compareIdentifiers(a, b);
  13784. } while (++i);
  13785. }; // preminor will bump the version up to the next minor release, and immediately
  13786. // down to pre-release. premajor and prepatch work the same way.
  13787. SemVer.prototype.inc = function (release, identifier) {
  13788. switch (release) {
  13789. case 'premajor':
  13790. this.prerelease.length = 0;
  13791. this.patch = 0;
  13792. this.minor = 0;
  13793. this.major++;
  13794. this.inc('pre', identifier);
  13795. break;
  13796. case 'preminor':
  13797. this.prerelease.length = 0;
  13798. this.patch = 0;
  13799. this.minor++;
  13800. this.inc('pre', identifier);
  13801. break;
  13802. case 'prepatch':
  13803. // If this is already a prerelease, it will bump to the next version
  13804. // drop any prereleases that might already exist, since they are not
  13805. // relevant at this point.
  13806. this.prerelease.length = 0;
  13807. this.inc('patch', identifier);
  13808. this.inc('pre', identifier);
  13809. break;
  13810. // If the input is a non-prerelease version, this acts the same as
  13811. // prepatch.
  13812. case 'prerelease':
  13813. if (this.prerelease.length === 0) this.inc('patch', identifier);
  13814. this.inc('pre', identifier);
  13815. break;
  13816. case 'major':
  13817. // If this is a pre-major version, bump up to the same major version.
  13818. // Otherwise increment major.
  13819. // 1.0.0-5 bumps to 1.0.0
  13820. // 1.1.0 bumps to 2.0.0
  13821. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) this.major++;
  13822. this.minor = 0;
  13823. this.patch = 0;
  13824. this.prerelease = [];
  13825. break;
  13826. case 'minor':
  13827. // If this is a pre-minor version, bump up to the same minor version.
  13828. // Otherwise increment minor.
  13829. // 1.2.0-5 bumps to 1.2.0
  13830. // 1.2.1 bumps to 1.3.0
  13831. if (this.patch !== 0 || this.prerelease.length === 0) this.minor++;
  13832. this.patch = 0;
  13833. this.prerelease = [];
  13834. break;
  13835. case 'patch':
  13836. // If this is not a pre-release version, it will increment the patch.
  13837. // If it is a pre-release it will bump up to the same patch version.
  13838. // 1.2.0-5 patches to 1.2.0
  13839. // 1.2.0 patches to 1.2.1
  13840. if (this.prerelease.length === 0) this.patch++;
  13841. this.prerelease = [];
  13842. break;
  13843. // This probably shouldn't be used publicly.
  13844. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  13845. case 'pre':
  13846. if (this.prerelease.length === 0) this.prerelease = [0];else {
  13847. var i = this.prerelease.length;
  13848. while (--i >= 0) {
  13849. if (typeof this.prerelease[i] === 'number') {
  13850. this.prerelease[i]++;
  13851. i = -2;
  13852. }
  13853. }
  13854. if (i === -1) // didn't increment anything
  13855. this.prerelease.push(0);
  13856. }
  13857. if (identifier) {
  13858. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  13859. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  13860. if (this.prerelease[0] === identifier) {
  13861. if (isNaN(this.prerelease[1])) this.prerelease = [identifier, 0];
  13862. } else this.prerelease = [identifier, 0];
  13863. }
  13864. break;
  13865. default:
  13866. throw new Error('invalid increment argument: ' + release);
  13867. }
  13868. this.format();
  13869. this.raw = this.version;
  13870. return this;
  13871. };
  13872. exports.inc = inc;
  13873. function inc(version, release, loose, identifier) {
  13874. if (typeof loose === 'string') {
  13875. identifier = loose;
  13876. loose = undefined;
  13877. }
  13878. try {
  13879. return new SemVer(version, loose).inc(release, identifier).version;
  13880. } catch (er) {
  13881. return null;
  13882. }
  13883. }
  13884. exports.diff = diff;
  13885. function diff(version1, version2) {
  13886. if (eq(version1, version2)) {
  13887. return null;
  13888. } else {
  13889. var v1 = parse(version1);
  13890. var v2 = parse(version2);
  13891. if (v1.prerelease.length || v2.prerelease.length) {
  13892. for (var key in v1) {
  13893. if (key === 'major' || key === 'minor' || key === 'patch') {
  13894. if (v1[key] !== v2[key]) {
  13895. return 'pre' + key;
  13896. }
  13897. }
  13898. }
  13899. return 'prerelease';
  13900. }
  13901. for (var key in v1) {
  13902. if (key === 'major' || key === 'minor' || key === 'patch') {
  13903. if (v1[key] !== v2[key]) {
  13904. return key;
  13905. }
  13906. }
  13907. }
  13908. }
  13909. }
  13910. exports.compareIdentifiers = compareIdentifiers;
  13911. var numeric = /^[0-9]+$/;
  13912. function compareIdentifiers(a, b) {
  13913. var anum = numeric.test(a);
  13914. var bnum = numeric.test(b);
  13915. if (anum && bnum) {
  13916. a = +a;
  13917. b = +b;
  13918. }
  13919. return anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : a > b ? 1 : 0;
  13920. }
  13921. exports.rcompareIdentifiers = rcompareIdentifiers;
  13922. function rcompareIdentifiers(a, b) {
  13923. return compareIdentifiers(b, a);
  13924. }
  13925. exports.major = major;
  13926. function major(a, loose) {
  13927. return new SemVer(a, loose).major;
  13928. }
  13929. exports.minor = minor;
  13930. function minor(a, loose) {
  13931. return new SemVer(a, loose).minor;
  13932. }
  13933. exports.patch = patch;
  13934. function patch(a, loose) {
  13935. return new SemVer(a, loose).patch;
  13936. }
  13937. exports.compare = compare;
  13938. function compare(a, b, loose) {
  13939. return new SemVer(a, loose).compare(new SemVer(b, loose));
  13940. }
  13941. exports.compareLoose = compareLoose;
  13942. function compareLoose(a, b) {
  13943. return compare(a, b, true);
  13944. }
  13945. exports.rcompare = rcompare;
  13946. function rcompare(a, b, loose) {
  13947. return compare(b, a, loose);
  13948. }
  13949. exports.sort = sort;
  13950. function sort(list, loose) {
  13951. return list.sort(function (a, b) {
  13952. return exports.compare(a, b, loose);
  13953. });
  13954. }
  13955. exports.rsort = rsort;
  13956. function rsort(list, loose) {
  13957. return list.sort(function (a, b) {
  13958. return exports.rcompare(a, b, loose);
  13959. });
  13960. }
  13961. exports.gt = gt;
  13962. function gt(a, b, loose) {
  13963. return compare(a, b, loose) > 0;
  13964. }
  13965. exports.lt = lt;
  13966. function lt(a, b, loose) {
  13967. return compare(a, b, loose) < 0;
  13968. }
  13969. exports.eq = eq;
  13970. function eq(a, b, loose) {
  13971. return compare(a, b, loose) === 0;
  13972. }
  13973. exports.neq = neq;
  13974. function neq(a, b, loose) {
  13975. return compare(a, b, loose) !== 0;
  13976. }
  13977. exports.gte = gte;
  13978. function gte(a, b, loose) {
  13979. return compare(a, b, loose) >= 0;
  13980. }
  13981. exports.lte = lte;
  13982. function lte(a, b, loose) {
  13983. return compare(a, b, loose) <= 0;
  13984. }
  13985. exports.cmp = cmp;
  13986. function cmp(a, op, b, loose) {
  13987. var ret;
  13988. switch (op) {
  13989. case '===':
  13990. if (typeof a === 'object') a = a.version;
  13991. if (typeof b === 'object') b = b.version;
  13992. ret = a === b;
  13993. break;
  13994. case '!==':
  13995. if (typeof a === 'object') a = a.version;
  13996. if (typeof b === 'object') b = b.version;
  13997. ret = a !== b;
  13998. break;
  13999. case '':
  14000. case '=':
  14001. case '==':
  14002. ret = eq(a, b, loose);
  14003. break;
  14004. case '!=':
  14005. ret = neq(a, b, loose);
  14006. break;
  14007. case '>':
  14008. ret = gt(a, b, loose);
  14009. break;
  14010. case '>=':
  14011. ret = gte(a, b, loose);
  14012. break;
  14013. case '<':
  14014. ret = lt(a, b, loose);
  14015. break;
  14016. case '<=':
  14017. ret = lte(a, b, loose);
  14018. break;
  14019. default:
  14020. throw new TypeError('Invalid operator: ' + op);
  14021. }
  14022. return ret;
  14023. }
  14024. exports.Comparator = Comparator;
  14025. function Comparator(comp, options) {
  14026. if (!options || typeof options !== 'object') options = {
  14027. loose: !!options,
  14028. includePrerelease: false
  14029. };
  14030. if (comp instanceof Comparator) {
  14031. if (comp.loose === !!options.loose) return comp;else comp = comp.value;
  14032. }
  14033. if (!(this instanceof Comparator)) return new Comparator(comp, options);
  14034. debug('comparator', comp, options);
  14035. this.options = options;
  14036. this.loose = !!options.loose;
  14037. this.parse(comp);
  14038. if (this.semver === ANY) this.value = '';else this.value = this.operator + this.semver.version;
  14039. debug('comp', this);
  14040. }
  14041. var ANY = {};
  14042. Comparator.prototype.parse = function (comp) {
  14043. var r = this.options.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  14044. var m = comp.match(r);
  14045. if (!m) throw new TypeError('Invalid comparator: ' + comp);
  14046. this.operator = m[1];
  14047. if (this.operator === '=') this.operator = ''; // if it literally is just '>' or '' then allow anything.
  14048. if (!m[2]) this.semver = ANY;else this.semver = new SemVer(m[2], this.options.loose);
  14049. };
  14050. Comparator.prototype.toString = function () {
  14051. return this.value;
  14052. };
  14053. Comparator.prototype.test = function (version) {
  14054. debug('Comparator.test', version, this.options.loose);
  14055. if (this.semver === ANY) return true;
  14056. if (typeof version === 'string') version = new SemVer(version, this.options);
  14057. return cmp(version, this.operator, this.semver, this.options);
  14058. };
  14059. Comparator.prototype.intersects = function (comp, options) {
  14060. if (!(comp instanceof Comparator)) {
  14061. throw new TypeError('a Comparator is required');
  14062. }
  14063. if (!options || typeof options !== 'object') options = {
  14064. loose: !!options,
  14065. includePrerelease: false
  14066. };
  14067. var rangeTmp;
  14068. if (this.operator === '') {
  14069. rangeTmp = new Range(comp.value, options);
  14070. return satisfies(this.value, rangeTmp, options);
  14071. } else if (comp.operator === '') {
  14072. rangeTmp = new Range(this.value, options);
  14073. return satisfies(comp.semver, rangeTmp, options);
  14074. }
  14075. var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
  14076. var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
  14077. var sameSemVer = this.semver.version === comp.semver.version;
  14078. var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
  14079. var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, options) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
  14080. var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, options) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
  14081. return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  14082. };
  14083. exports.Range = Range;
  14084. function Range(range, options) {
  14085. if (!options || typeof options !== 'object') options = {
  14086. loose: !!options,
  14087. includePrerelease: false
  14088. };
  14089. if (range instanceof Range) {
  14090. if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) {
  14091. return range;
  14092. } else {
  14093. return new Range(range.raw, options);
  14094. }
  14095. }
  14096. if (range instanceof Comparator) {
  14097. return new Range(range.value, options);
  14098. }
  14099. if (!(this instanceof Range)) return new Range(range, options);
  14100. this.options = options;
  14101. this.loose = !!options.loose;
  14102. this.includePrerelease = !!options.includePrerelease; // First, split based on boolean or ||
  14103. this.raw = range;
  14104. this.set = range.split(/\s*\|\|\s*/).map(function (range) {
  14105. return this.parseRange(range.trim());
  14106. }, this).filter(function (c) {
  14107. // throw out any that are not relevant for whatever reason
  14108. return c.length;
  14109. });
  14110. if (!this.set.length) {
  14111. throw new TypeError('Invalid SemVer Range: ' + range);
  14112. }
  14113. this.format();
  14114. }
  14115. Range.prototype.format = function () {
  14116. this.range = this.set.map(function (comps) {
  14117. return comps.join(' ').trim();
  14118. }).join('||').trim();
  14119. return this.range;
  14120. };
  14121. Range.prototype.toString = function () {
  14122. return this.range;
  14123. };
  14124. Range.prototype.parseRange = function (range) {
  14125. var loose = this.options.loose;
  14126. range = range.trim(); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  14127. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  14128. range = range.replace(hr, hyphenReplace);
  14129. debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  14130. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  14131. debug('comparator trim', range, re[COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
  14132. range = range.replace(re[TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
  14133. range = range.replace(re[CARETTRIM], caretTrimReplace); // normalize spaces
  14134. range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
  14135. // ready to be split into comparators.
  14136. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  14137. var set = range.split(' ').map(function (comp) {
  14138. return parseComparator(comp, this.options);
  14139. }, this).join(' ').split(/\s+/);
  14140. if (this.options.loose) {
  14141. // in loose mode, throw out any that are not valid comparators
  14142. set = set.filter(function (comp) {
  14143. return !!comp.match(compRe);
  14144. });
  14145. }
  14146. set = set.map(function (comp) {
  14147. return new Comparator(comp, this.options);
  14148. }, this);
  14149. return set;
  14150. };
  14151. Range.prototype.intersects = function (range, options) {
  14152. if (!(range instanceof Range)) {
  14153. throw new TypeError('a Range is required');
  14154. }
  14155. return this.set.some(function (thisComparators) {
  14156. return thisComparators.every(function (thisComparator) {
  14157. return range.set.some(function (rangeComparators) {
  14158. return rangeComparators.every(function (rangeComparator) {
  14159. return thisComparator.intersects(rangeComparator, options);
  14160. });
  14161. });
  14162. });
  14163. });
  14164. }; // Mostly just for testing and legacy API reasons
  14165. exports.toComparators = toComparators;
  14166. function toComparators(range, options) {
  14167. return new Range(range, options).set.map(function (comp) {
  14168. return comp.map(function (c) {
  14169. return c.value;
  14170. }).join(' ').trim().split(' ');
  14171. });
  14172. } // comprised of xranges, tildes, stars, and gtlt's at this point.
  14173. // already replaced the hyphen ranges
  14174. // turn into a set of JUST comparators.
  14175. function parseComparator(comp, options) {
  14176. debug('comp', comp, options);
  14177. comp = replaceCarets(comp, options);
  14178. debug('caret', comp);
  14179. comp = replaceTildes(comp, options);
  14180. debug('tildes', comp);
  14181. comp = replaceXRanges(comp, options);
  14182. debug('xrange', comp);
  14183. comp = replaceStars(comp, options);
  14184. debug('stars', comp);
  14185. return comp;
  14186. }
  14187. function isX(id) {
  14188. return !id || id.toLowerCase() === 'x' || id === '*';
  14189. } // ~, ~> --> * (any, kinda silly)
  14190. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  14191. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  14192. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  14193. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  14194. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  14195. function replaceTildes(comp, options) {
  14196. return comp.trim().split(/\s+/).map(function (comp) {
  14197. return replaceTilde(comp, options);
  14198. }).join(' ');
  14199. }
  14200. function replaceTilde(comp, options) {
  14201. if (!options || typeof options !== 'object') options = {
  14202. loose: !!options,
  14203. includePrerelease: false
  14204. };
  14205. var r = options.loose ? re[TILDELOOSE] : re[TILDE];
  14206. return comp.replace(r, function (_, M, m, p, pr) {
  14207. debug('tilde', comp, _, M, m, p, pr);
  14208. var ret;
  14209. if (isX(M)) ret = '';else if (isX(m)) ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';else if (isX(p)) // ~1.2 == >=1.2.0 <1.3.0
  14210. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else if (pr) {
  14211. debug('replaceTilde pr', pr);
  14212. if (pr.charAt(0) !== '-') pr = '-' + pr;
  14213. ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  14214. } else // ~1.2.3 == >=1.2.3 <1.3.0
  14215. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  14216. debug('tilde return', ret);
  14217. return ret;
  14218. });
  14219. } // ^ --> * (any, kinda silly)
  14220. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  14221. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  14222. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  14223. // ^1.2.3 --> >=1.2.3 <2.0.0
  14224. // ^1.2.0 --> >=1.2.0 <2.0.0
  14225. function replaceCarets(comp, options) {
  14226. return comp.trim().split(/\s+/).map(function (comp) {
  14227. return replaceCaret(comp, options);
  14228. }).join(' ');
  14229. }
  14230. function replaceCaret(comp, options) {
  14231. debug('caret', comp, options);
  14232. if (!options || typeof options !== 'object') options = {
  14233. loose: !!options,
  14234. includePrerelease: false
  14235. };
  14236. var r = options.loose ? re[CARETLOOSE] : re[CARET];
  14237. return comp.replace(r, function (_, M, m, p, pr) {
  14238. debug('caret', comp, _, M, m, p, pr);
  14239. var ret;
  14240. if (isX(M)) ret = '';else if (isX(m)) ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';else if (isX(p)) {
  14241. if (M === '0') ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  14242. } else if (pr) {
  14243. debug('replaceCaret pr', pr);
  14244. if (pr.charAt(0) !== '-') pr = '-' + pr;
  14245. if (M === '0') {
  14246. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  14247. } else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + (+M + 1) + '.0.0';
  14248. } else {
  14249. debug('no pr');
  14250. if (M === '0') {
  14251. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  14252. } else ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
  14253. }
  14254. debug('caret return', ret);
  14255. return ret;
  14256. });
  14257. }
  14258. function replaceXRanges(comp, options) {
  14259. debug('replaceXRanges', comp, options);
  14260. return comp.split(/\s+/).map(function (comp) {
  14261. return replaceXRange(comp, options);
  14262. }).join(' ');
  14263. }
  14264. function replaceXRange(comp, options) {
  14265. comp = comp.trim();
  14266. if (!options || typeof options !== 'object') options = {
  14267. loose: !!options,
  14268. includePrerelease: false
  14269. };
  14270. var r = options.loose ? re[XRANGELOOSE] : re[XRANGE];
  14271. return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
  14272. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  14273. var xM = isX(M);
  14274. var xm = xM || isX(m);
  14275. var xp = xm || isX(p);
  14276. var anyX = xp;
  14277. if (gtlt === '=' && anyX) gtlt = '';
  14278. if (xM) {
  14279. if (gtlt === '>' || gtlt === '<') {
  14280. // nothing is allowed
  14281. ret = '<0.0.0';
  14282. } else {
  14283. // nothing is forbidden
  14284. ret = '*';
  14285. }
  14286. } else if (gtlt && anyX) {
  14287. // replace X with 0
  14288. if (xm) m = 0;
  14289. if (xp) p = 0;
  14290. if (gtlt === '>') {
  14291. // >1 => >=2.0.0
  14292. // >1.2 => >=1.3.0
  14293. // >1.2.3 => >= 1.2.4
  14294. gtlt = '>=';
  14295. if (xm) {
  14296. M = +M + 1;
  14297. m = 0;
  14298. p = 0;
  14299. } else if (xp) {
  14300. m = +m + 1;
  14301. p = 0;
  14302. }
  14303. } else if (gtlt === '<=') {
  14304. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  14305. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  14306. gtlt = '<';
  14307. if (xm) M = +M + 1;else m = +m + 1;
  14308. }
  14309. ret = gtlt + M + '.' + m + '.' + p;
  14310. } else if (xm) {
  14311. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  14312. } else if (xp) {
  14313. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  14314. }
  14315. debug('xRange return', ret);
  14316. return ret;
  14317. });
  14318. } // Because * is AND-ed with everything else in the comparator,
  14319. // and '' means "any version", just remove the *s entirely.
  14320. function replaceStars(comp, options) {
  14321. debug('replaceStars', comp, options); // Looseness is ignored here. star is always as loose as it gets!
  14322. return comp.trim().replace(re[STAR], '');
  14323. } // This function is passed to string.replace(re[HYPHENRANGE])
  14324. // M, m, patch, prerelease, build
  14325. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  14326. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  14327. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  14328. function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
  14329. if (isX(fM)) from = '';else if (isX(fm)) from = '>=' + fM + '.0.0';else if (isX(fp)) from = '>=' + fM + '.' + fm + '.0';else from = '>=' + from;
  14330. if (isX(tM)) to = '';else if (isX(tm)) to = '<' + (+tM + 1) + '.0.0';else if (isX(tp)) to = '<' + tM + '.' + (+tm + 1) + '.0';else if (tpr) to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;else to = '<=' + to;
  14331. return (from + ' ' + to).trim();
  14332. } // if ANY of the sets match ALL of its comparators, then pass
  14333. Range.prototype.test = function (version) {
  14334. if (!version) return false;
  14335. if (typeof version === 'string') version = new SemVer(version, this.options);
  14336. for (var i = 0; i < this.set.length; i++) {
  14337. if (testSet(this.set[i], version, this.options)) return true;
  14338. }
  14339. return false;
  14340. };
  14341. function testSet(set, version, options) {
  14342. for (var i = 0; i < set.length; i++) {
  14343. if (!set[i].test(version)) return false;
  14344. }
  14345. if (!options) options = {};
  14346. if (version.prerelease.length && !options.includePrerelease) {
  14347. // Find the set of versions that are allowed to have prereleases
  14348. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  14349. // That should allow `1.2.3-pr.2` to pass.
  14350. // However, `1.2.4-alpha.notready` should NOT be allowed,
  14351. // even though it's within the range set by the comparators.
  14352. for (var i = 0; i < set.length; i++) {
  14353. debug(set[i].semver);
  14354. if (set[i].semver === ANY) continue;
  14355. if (set[i].semver.prerelease.length > 0) {
  14356. var allowed = set[i].semver;
  14357. if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) return true;
  14358. }
  14359. } // Version has a -pre, but it's not one of the ones we like.
  14360. return false;
  14361. }
  14362. return true;
  14363. }
  14364. exports.satisfies = satisfies;
  14365. function satisfies(version, range, options) {
  14366. try {
  14367. range = new Range(range, options);
  14368. } catch (er) {
  14369. return false;
  14370. }
  14371. return range.test(version);
  14372. }
  14373. exports.maxSatisfying = maxSatisfying;
  14374. function maxSatisfying(versions, range, options) {
  14375. var max = null;
  14376. var maxSV = null;
  14377. try {
  14378. var rangeObj = new Range(range, options);
  14379. } catch (er) {
  14380. return null;
  14381. }
  14382. versions.forEach(function (v) {
  14383. if (rangeObj.test(v)) {
  14384. // satisfies(v, range, options)
  14385. if (!max || maxSV.compare(v) === -1) {
  14386. // compare(max, v, true)
  14387. max = v;
  14388. maxSV = new SemVer(max, options);
  14389. }
  14390. }
  14391. });
  14392. return max;
  14393. }
  14394. exports.minSatisfying = minSatisfying;
  14395. function minSatisfying(versions, range, options) {
  14396. var min = null;
  14397. var minSV = null;
  14398. try {
  14399. var rangeObj = new Range(range, options);
  14400. } catch (er) {
  14401. return null;
  14402. }
  14403. versions.forEach(function (v) {
  14404. if (rangeObj.test(v)) {
  14405. // satisfies(v, range, options)
  14406. if (!min || minSV.compare(v) === 1) {
  14407. // compare(min, v, true)
  14408. min = v;
  14409. minSV = new SemVer(min, options);
  14410. }
  14411. }
  14412. });
  14413. return min;
  14414. }
  14415. exports.validRange = validRange;
  14416. function validRange(range, options) {
  14417. try {
  14418. // Return '*' instead of '' so that truthiness works.
  14419. // This will throw if it's invalid anyway
  14420. return new Range(range, options).range || '*';
  14421. } catch (er) {
  14422. return null;
  14423. }
  14424. } // Determine if version is less than all the versions possible in the range
  14425. exports.ltr = ltr;
  14426. function ltr(version, range, options) {
  14427. return outside(version, range, '<', options);
  14428. } // Determine if version is greater than all the versions possible in the range.
  14429. exports.gtr = gtr;
  14430. function gtr(version, range, options) {
  14431. return outside(version, range, '>', options);
  14432. }
  14433. exports.outside = outside;
  14434. function outside(version, range, hilo, options) {
  14435. version = new SemVer(version, options);
  14436. range = new Range(range, options);
  14437. var gtfn, ltefn, ltfn, comp, ecomp;
  14438. switch (hilo) {
  14439. case '>':
  14440. gtfn = gt;
  14441. ltefn = lte;
  14442. ltfn = lt;
  14443. comp = '>';
  14444. ecomp = '>=';
  14445. break;
  14446. case '<':
  14447. gtfn = lt;
  14448. ltefn = gte;
  14449. ltfn = gt;
  14450. comp = '<';
  14451. ecomp = '<=';
  14452. break;
  14453. default:
  14454. throw new TypeError('Must provide a hilo val of "<" or ">"');
  14455. } // If it satisifes the range it is not outside
  14456. if (satisfies(version, range, options)) {
  14457. return false;
  14458. } // From now on, variable terms are as if we're in "gtr" mode.
  14459. // but note that everything is flipped for the "ltr" function.
  14460. for (var i = 0; i < range.set.length; ++i) {
  14461. var comparators = range.set[i];
  14462. var high = null;
  14463. var low = null;
  14464. comparators.forEach(function (comparator) {
  14465. if (comparator.semver === ANY) {
  14466. comparator = new Comparator('>=0.0.0');
  14467. }
  14468. high = high || comparator;
  14469. low = low || comparator;
  14470. if (gtfn(comparator.semver, high.semver, options)) {
  14471. high = comparator;
  14472. } else if (ltfn(comparator.semver, low.semver, options)) {
  14473. low = comparator;
  14474. }
  14475. }); // If the edge version comparator has a operator then our version
  14476. // isn't outside it
  14477. if (high.operator === comp || high.operator === ecomp) {
  14478. return false;
  14479. } // If the lowest version comparator has an operator and our version
  14480. // is less than it then it isn't higher than the range
  14481. if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
  14482. return false;
  14483. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  14484. return false;
  14485. }
  14486. }
  14487. return true;
  14488. }
  14489. exports.prerelease = prerelease;
  14490. function prerelease(version, options) {
  14491. var parsed = parse(version, options);
  14492. return parsed && parsed.prerelease.length ? parsed.prerelease : null;
  14493. }
  14494. exports.intersects = intersects;
  14495. function intersects(r1, r2, options) {
  14496. r1 = new Range(r1, options);
  14497. r2 = new Range(r2, options);
  14498. return r1.intersects(r2);
  14499. }
  14500. exports.coerce = coerce;
  14501. function coerce(version) {
  14502. if (version instanceof SemVer) return version;
  14503. if (typeof version !== 'string') return null;
  14504. var match = version.match(re[COERCE]);
  14505. if (match == null) return null;
  14506. return parse((match[1] || '0') + '.' + (match[2] || '0') + '.' + (match[3] || '0'));
  14507. }
  14508. });
  14509. var semver_1$1 = semver$1.SEMVER_SPEC_VERSION;
  14510. var semver_2$1 = semver$1.re;
  14511. var semver_3$1 = semver$1.src;
  14512. var semver_4$1 = semver$1.parse;
  14513. var semver_5$1 = semver$1.valid;
  14514. var semver_6$1 = semver$1.clean;
  14515. var semver_7$1 = semver$1.SemVer;
  14516. var semver_8$1 = semver$1.inc;
  14517. var semver_9$1 = semver$1.diff;
  14518. var semver_10$1 = semver$1.compareIdentifiers;
  14519. var semver_11$1 = semver$1.rcompareIdentifiers;
  14520. var semver_12$1 = semver$1.major;
  14521. var semver_13$1 = semver$1.minor;
  14522. var semver_14$1 = semver$1.patch;
  14523. var semver_15$1 = semver$1.compare;
  14524. var semver_16$1 = semver$1.compareLoose;
  14525. var semver_17$1 = semver$1.rcompare;
  14526. var semver_18$1 = semver$1.sort;
  14527. var semver_19$1 = semver$1.rsort;
  14528. var semver_20$1 = semver$1.gt;
  14529. var semver_21$1 = semver$1.lt;
  14530. var semver_22$1 = semver$1.eq;
  14531. var semver_23$1 = semver$1.neq;
  14532. var semver_24$1 = semver$1.gte;
  14533. var semver_25$1 = semver$1.lte;
  14534. var semver_26$1 = semver$1.cmp;
  14535. var semver_27$1 = semver$1.Comparator;
  14536. var semver_28$1 = semver$1.Range;
  14537. var semver_29$1 = semver$1.toComparators;
  14538. var semver_30$1 = semver$1.satisfies;
  14539. var semver_31$1 = semver$1.maxSatisfying;
  14540. var semver_32$1 = semver$1.minSatisfying;
  14541. var semver_33$1 = semver$1.validRange;
  14542. var semver_34$1 = semver$1.ltr;
  14543. var semver_35$1 = semver$1.gtr;
  14544. var semver_36$1 = semver$1.outside;
  14545. var semver_37$1 = semver$1.prerelease;
  14546. var semver_38$1 = semver$1.intersects;
  14547. var semver_39$1 = semver$1.coerce;
  14548. var hasOwnProperty = Object.prototype.hasOwnProperty;
  14549. var pseudomap = PseudoMap;
  14550. function PseudoMap(set) {
  14551. if (!(this instanceof PseudoMap)) // whyyyyyyy
  14552. throw new TypeError("Constructor PseudoMap requires 'new'");
  14553. this.clear();
  14554. if (set) {
  14555. if (set instanceof PseudoMap || typeof Map === 'function' && set instanceof Map) set.forEach(function (value, key) {
  14556. this.set(key, value);
  14557. }, this);else if (Array.isArray(set)) set.forEach(function (kv) {
  14558. this.set(kv[0], kv[1]);
  14559. }, this);else throw new TypeError('invalid argument');
  14560. }
  14561. }
  14562. PseudoMap.prototype.forEach = function (fn, thisp) {
  14563. thisp = thisp || this;
  14564. Object.keys(this._data).forEach(function (k) {
  14565. if (k !== 'size') fn.call(thisp, this._data[k].value, this._data[k].key);
  14566. }, this);
  14567. };
  14568. PseudoMap.prototype.has = function (k) {
  14569. return !!find(this._data, k);
  14570. };
  14571. PseudoMap.prototype.get = function (k) {
  14572. var res = find(this._data, k);
  14573. return res && res.value;
  14574. };
  14575. PseudoMap.prototype.set = function (k, v) {
  14576. set(this._data, k, v);
  14577. };
  14578. PseudoMap.prototype.delete = function (k) {
  14579. var res = find(this._data, k);
  14580. if (res) {
  14581. delete this._data[res._index];
  14582. this._data.size--;
  14583. }
  14584. };
  14585. PseudoMap.prototype.clear = function () {
  14586. var data = Object.create(null);
  14587. data.size = 0;
  14588. Object.defineProperty(this, '_data', {
  14589. value: data,
  14590. enumerable: false,
  14591. configurable: true,
  14592. writable: false
  14593. });
  14594. };
  14595. Object.defineProperty(PseudoMap.prototype, 'size', {
  14596. get: function get() {
  14597. return this._data.size;
  14598. },
  14599. set: function set(n) {},
  14600. enumerable: true,
  14601. configurable: true
  14602. });
  14603. PseudoMap.prototype.values = PseudoMap.prototype.keys = PseudoMap.prototype.entries = function () {
  14604. throw new Error('iterators are not implemented in this version');
  14605. }; // Either identical, or both NaN
  14606. function same(a, b) {
  14607. return a === b || a !== a && b !== b;
  14608. }
  14609. function Entry(k, v, i) {
  14610. this.key = k;
  14611. this.value = v;
  14612. this._index = i;
  14613. }
  14614. function find(data, k) {
  14615. for (var i = 0, s = '_' + k, key = s; hasOwnProperty.call(data, key); key = s + i++) {
  14616. if (same(data[key].key, k)) return data[key];
  14617. }
  14618. }
  14619. function set(data, k, v) {
  14620. for (var i = 0, s = '_' + k, key = s; hasOwnProperty.call(data, key); key = s + i++) {
  14621. if (same(data[key].key, k)) {
  14622. data[key].value = v;
  14623. return;
  14624. }
  14625. }
  14626. data.size++;
  14627. data[key] = new Entry(k, v, key);
  14628. }
  14629. var map = createCommonjsModule(function (module) {
  14630. if (process.env.npm_package_name === 'pseudomap' && process.env.npm_lifecycle_script === 'test') process.env.TEST_PSEUDOMAP = 'true';
  14631. if (typeof Map === 'function' && !process.env.TEST_PSEUDOMAP) {
  14632. module.exports = Map;
  14633. } else {
  14634. module.exports = pseudomap;
  14635. }
  14636. });
  14637. var yallist = Yallist;
  14638. Yallist.Node = Node;
  14639. Yallist.create = Yallist;
  14640. function Yallist(list) {
  14641. var self = this;
  14642. if (!(self instanceof Yallist)) {
  14643. self = new Yallist();
  14644. }
  14645. self.tail = null;
  14646. self.head = null;
  14647. self.length = 0;
  14648. if (list && typeof list.forEach === 'function') {
  14649. list.forEach(function (item) {
  14650. self.push(item);
  14651. });
  14652. } else if (arguments.length > 0) {
  14653. for (var i = 0, l = arguments.length; i < l; i++) {
  14654. self.push(arguments[i]);
  14655. }
  14656. }
  14657. return self;
  14658. }
  14659. Yallist.prototype.removeNode = function (node) {
  14660. if (node.list !== this) {
  14661. throw new Error('removing node which does not belong to this list');
  14662. }
  14663. var next = node.next;
  14664. var prev = node.prev;
  14665. if (next) {
  14666. next.prev = prev;
  14667. }
  14668. if (prev) {
  14669. prev.next = next;
  14670. }
  14671. if (node === this.head) {
  14672. this.head = next;
  14673. }
  14674. if (node === this.tail) {
  14675. this.tail = prev;
  14676. }
  14677. node.list.length--;
  14678. node.next = null;
  14679. node.prev = null;
  14680. node.list = null;
  14681. };
  14682. Yallist.prototype.unshiftNode = function (node) {
  14683. if (node === this.head) {
  14684. return;
  14685. }
  14686. if (node.list) {
  14687. node.list.removeNode(node);
  14688. }
  14689. var head = this.head;
  14690. node.list = this;
  14691. node.next = head;
  14692. if (head) {
  14693. head.prev = node;
  14694. }
  14695. this.head = node;
  14696. if (!this.tail) {
  14697. this.tail = node;
  14698. }
  14699. this.length++;
  14700. };
  14701. Yallist.prototype.pushNode = function (node) {
  14702. if (node === this.tail) {
  14703. return;
  14704. }
  14705. if (node.list) {
  14706. node.list.removeNode(node);
  14707. }
  14708. var tail = this.tail;
  14709. node.list = this;
  14710. node.prev = tail;
  14711. if (tail) {
  14712. tail.next = node;
  14713. }
  14714. this.tail = node;
  14715. if (!this.head) {
  14716. this.head = node;
  14717. }
  14718. this.length++;
  14719. };
  14720. Yallist.prototype.push = function () {
  14721. for (var i = 0, l = arguments.length; i < l; i++) {
  14722. push(this, arguments[i]);
  14723. }
  14724. return this.length;
  14725. };
  14726. Yallist.prototype.unshift = function () {
  14727. for (var i = 0, l = arguments.length; i < l; i++) {
  14728. unshift(this, arguments[i]);
  14729. }
  14730. return this.length;
  14731. };
  14732. Yallist.prototype.pop = function () {
  14733. if (!this.tail) {
  14734. return undefined;
  14735. }
  14736. var res = this.tail.value;
  14737. this.tail = this.tail.prev;
  14738. if (this.tail) {
  14739. this.tail.next = null;
  14740. } else {
  14741. this.head = null;
  14742. }
  14743. this.length--;
  14744. return res;
  14745. };
  14746. Yallist.prototype.shift = function () {
  14747. if (!this.head) {
  14748. return undefined;
  14749. }
  14750. var res = this.head.value;
  14751. this.head = this.head.next;
  14752. if (this.head) {
  14753. this.head.prev = null;
  14754. } else {
  14755. this.tail = null;
  14756. }
  14757. this.length--;
  14758. return res;
  14759. };
  14760. Yallist.prototype.forEach = function (fn, thisp) {
  14761. thisp = thisp || this;
  14762. for (var walker = this.head, i = 0; walker !== null; i++) {
  14763. fn.call(thisp, walker.value, i, this);
  14764. walker = walker.next;
  14765. }
  14766. };
  14767. Yallist.prototype.forEachReverse = function (fn, thisp) {
  14768. thisp = thisp || this;
  14769. for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
  14770. fn.call(thisp, walker.value, i, this);
  14771. walker = walker.prev;
  14772. }
  14773. };
  14774. Yallist.prototype.get = function (n) {
  14775. for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
  14776. // abort out of the list early if we hit a cycle
  14777. walker = walker.next;
  14778. }
  14779. if (i === n && walker !== null) {
  14780. return walker.value;
  14781. }
  14782. };
  14783. Yallist.prototype.getReverse = function (n) {
  14784. for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
  14785. // abort out of the list early if we hit a cycle
  14786. walker = walker.prev;
  14787. }
  14788. if (i === n && walker !== null) {
  14789. return walker.value;
  14790. }
  14791. };
  14792. Yallist.prototype.map = function (fn, thisp) {
  14793. thisp = thisp || this;
  14794. var res = new Yallist();
  14795. for (var walker = this.head; walker !== null;) {
  14796. res.push(fn.call(thisp, walker.value, this));
  14797. walker = walker.next;
  14798. }
  14799. return res;
  14800. };
  14801. Yallist.prototype.mapReverse = function (fn, thisp) {
  14802. thisp = thisp || this;
  14803. var res = new Yallist();
  14804. for (var walker = this.tail; walker !== null;) {
  14805. res.push(fn.call(thisp, walker.value, this));
  14806. walker = walker.prev;
  14807. }
  14808. return res;
  14809. };
  14810. Yallist.prototype.reduce = function (fn, initial) {
  14811. var acc;
  14812. var walker = this.head;
  14813. if (arguments.length > 1) {
  14814. acc = initial;
  14815. } else if (this.head) {
  14816. walker = this.head.next;
  14817. acc = this.head.value;
  14818. } else {
  14819. throw new TypeError('Reduce of empty list with no initial value');
  14820. }
  14821. for (var i = 0; walker !== null; i++) {
  14822. acc = fn(acc, walker.value, i);
  14823. walker = walker.next;
  14824. }
  14825. return acc;
  14826. };
  14827. Yallist.prototype.reduceReverse = function (fn, initial) {
  14828. var acc;
  14829. var walker = this.tail;
  14830. if (arguments.length > 1) {
  14831. acc = initial;
  14832. } else if (this.tail) {
  14833. walker = this.tail.prev;
  14834. acc = this.tail.value;
  14835. } else {
  14836. throw new TypeError('Reduce of empty list with no initial value');
  14837. }
  14838. for (var i = this.length - 1; walker !== null; i--) {
  14839. acc = fn(acc, walker.value, i);
  14840. walker = walker.prev;
  14841. }
  14842. return acc;
  14843. };
  14844. Yallist.prototype.toArray = function () {
  14845. var arr = new Array(this.length);
  14846. for (var i = 0, walker = this.head; walker !== null; i++) {
  14847. arr[i] = walker.value;
  14848. walker = walker.next;
  14849. }
  14850. return arr;
  14851. };
  14852. Yallist.prototype.toArrayReverse = function () {
  14853. var arr = new Array(this.length);
  14854. for (var i = 0, walker = this.tail; walker !== null; i++) {
  14855. arr[i] = walker.value;
  14856. walker = walker.prev;
  14857. }
  14858. return arr;
  14859. };
  14860. Yallist.prototype.slice = function (from, to) {
  14861. to = to || this.length;
  14862. if (to < 0) {
  14863. to += this.length;
  14864. }
  14865. from = from || 0;
  14866. if (from < 0) {
  14867. from += this.length;
  14868. }
  14869. var ret = new Yallist();
  14870. if (to < from || to < 0) {
  14871. return ret;
  14872. }
  14873. if (from < 0) {
  14874. from = 0;
  14875. }
  14876. if (to > this.length) {
  14877. to = this.length;
  14878. }
  14879. for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
  14880. walker = walker.next;
  14881. }
  14882. for (; walker !== null && i < to; i++, walker = walker.next) {
  14883. ret.push(walker.value);
  14884. }
  14885. return ret;
  14886. };
  14887. Yallist.prototype.sliceReverse = function (from, to) {
  14888. to = to || this.length;
  14889. if (to < 0) {
  14890. to += this.length;
  14891. }
  14892. from = from || 0;
  14893. if (from < 0) {
  14894. from += this.length;
  14895. }
  14896. var ret = new Yallist();
  14897. if (to < from || to < 0) {
  14898. return ret;
  14899. }
  14900. if (from < 0) {
  14901. from = 0;
  14902. }
  14903. if (to > this.length) {
  14904. to = this.length;
  14905. }
  14906. for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
  14907. walker = walker.prev;
  14908. }
  14909. for (; walker !== null && i > from; i--, walker = walker.prev) {
  14910. ret.push(walker.value);
  14911. }
  14912. return ret;
  14913. };
  14914. Yallist.prototype.reverse = function () {
  14915. var head = this.head;
  14916. var tail = this.tail;
  14917. for (var walker = head; walker !== null; walker = walker.prev) {
  14918. var p = walker.prev;
  14919. walker.prev = walker.next;
  14920. walker.next = p;
  14921. }
  14922. this.head = tail;
  14923. this.tail = head;
  14924. return this;
  14925. };
  14926. function push(self, item) {
  14927. self.tail = new Node(item, self.tail, null, self);
  14928. if (!self.head) {
  14929. self.head = self.tail;
  14930. }
  14931. self.length++;
  14932. }
  14933. function unshift(self, item) {
  14934. self.head = new Node(item, null, self.head, self);
  14935. if (!self.tail) {
  14936. self.tail = self.head;
  14937. }
  14938. self.length++;
  14939. }
  14940. function Node(value, prev, next, list) {
  14941. if (!(this instanceof Node)) {
  14942. return new Node(value, prev, next, list);
  14943. }
  14944. this.list = list;
  14945. this.value = value;
  14946. if (prev) {
  14947. prev.next = this;
  14948. this.prev = prev;
  14949. } else {
  14950. this.prev = null;
  14951. }
  14952. if (next) {
  14953. next.prev = this;
  14954. this.next = next;
  14955. } else {
  14956. this.next = null;
  14957. }
  14958. }
  14959. var lruCache = LRUCache; // This will be a proper iterable 'Map' in engines that support it,
  14960. // or a fakey-fake PseudoMap in older versions.
  14961. // A linked list to keep track of recently-used-ness
  14962. // use symbols if possible, otherwise just _props
  14963. var hasSymbol = typeof Symbol === 'function' && process.env._nodeLRUCacheForceNoSymbol !== '1';
  14964. var makeSymbol;
  14965. if (hasSymbol) {
  14966. makeSymbol = function makeSymbol(key) {
  14967. return Symbol(key);
  14968. };
  14969. } else {
  14970. makeSymbol = function makeSymbol(key) {
  14971. return '_' + key;
  14972. };
  14973. }
  14974. var MAX = makeSymbol('max');
  14975. var LENGTH = makeSymbol('length');
  14976. var LENGTH_CALCULATOR = makeSymbol('lengthCalculator');
  14977. var ALLOW_STALE = makeSymbol('allowStale');
  14978. var MAX_AGE = makeSymbol('maxAge');
  14979. var DISPOSE = makeSymbol('dispose');
  14980. var NO_DISPOSE_ON_SET = makeSymbol('noDisposeOnSet');
  14981. var LRU_LIST = makeSymbol('lruList');
  14982. var CACHE = makeSymbol('cache');
  14983. function naiveLength() {
  14984. return 1;
  14985. } // lruList is a yallist where the head is the youngest
  14986. // item, and the tail is the oldest. the list contains the Hit
  14987. // objects as the entries.
  14988. // Each Hit object has a reference to its Yallist.Node. This
  14989. // never changes.
  14990. //
  14991. // cache is a Map (or PseudoMap) that matches the keys to
  14992. // the Yallist.Node object.
  14993. function LRUCache(options) {
  14994. if (!(this instanceof LRUCache)) {
  14995. return new LRUCache(options);
  14996. }
  14997. if (typeof options === 'number') {
  14998. options = {
  14999. max: options
  15000. };
  15001. }
  15002. if (!options) {
  15003. options = {};
  15004. }
  15005. var max = this[MAX] = options.max; // Kind of weird to have a default max of Infinity, but oh well.
  15006. if (!max || !(typeof max === 'number') || max <= 0) {
  15007. this[MAX] = Infinity;
  15008. }
  15009. var lc = options.length || naiveLength;
  15010. if (typeof lc !== 'function') {
  15011. lc = naiveLength;
  15012. }
  15013. this[LENGTH_CALCULATOR] = lc;
  15014. this[ALLOW_STALE] = options.stale || false;
  15015. this[MAX_AGE] = options.maxAge || 0;
  15016. this[DISPOSE] = options.dispose;
  15017. this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
  15018. this.reset();
  15019. } // resize the cache when the max changes.
  15020. Object.defineProperty(LRUCache.prototype, 'max', {
  15021. set: function set(mL) {
  15022. if (!mL || !(typeof mL === 'number') || mL <= 0) {
  15023. mL = Infinity;
  15024. }
  15025. this[MAX] = mL;
  15026. trim$2(this);
  15027. },
  15028. get: function get() {
  15029. return this[MAX];
  15030. },
  15031. enumerable: true
  15032. });
  15033. Object.defineProperty(LRUCache.prototype, 'allowStale', {
  15034. set: function set(allowStale) {
  15035. this[ALLOW_STALE] = !!allowStale;
  15036. },
  15037. get: function get() {
  15038. return this[ALLOW_STALE];
  15039. },
  15040. enumerable: true
  15041. });
  15042. Object.defineProperty(LRUCache.prototype, 'maxAge', {
  15043. set: function set(mA) {
  15044. if (!mA || !(typeof mA === 'number') || mA < 0) {
  15045. mA = 0;
  15046. }
  15047. this[MAX_AGE] = mA;
  15048. trim$2(this);
  15049. },
  15050. get: function get() {
  15051. return this[MAX_AGE];
  15052. },
  15053. enumerable: true
  15054. }); // resize the cache when the lengthCalculator changes.
  15055. Object.defineProperty(LRUCache.prototype, 'lengthCalculator', {
  15056. set: function set(lC) {
  15057. if (typeof lC !== 'function') {
  15058. lC = naiveLength;
  15059. }
  15060. if (lC !== this[LENGTH_CALCULATOR]) {
  15061. this[LENGTH_CALCULATOR] = lC;
  15062. this[LENGTH] = 0;
  15063. this[LRU_LIST].forEach(function (hit) {
  15064. hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
  15065. this[LENGTH] += hit.length;
  15066. }, this);
  15067. }
  15068. trim$2(this);
  15069. },
  15070. get: function get() {
  15071. return this[LENGTH_CALCULATOR];
  15072. },
  15073. enumerable: true
  15074. });
  15075. Object.defineProperty(LRUCache.prototype, 'length', {
  15076. get: function get() {
  15077. return this[LENGTH];
  15078. },
  15079. enumerable: true
  15080. });
  15081. Object.defineProperty(LRUCache.prototype, 'itemCount', {
  15082. get: function get() {
  15083. return this[LRU_LIST].length;
  15084. },
  15085. enumerable: true
  15086. });
  15087. LRUCache.prototype.rforEach = function (fn, thisp) {
  15088. thisp = thisp || this;
  15089. for (var walker = this[LRU_LIST].tail; walker !== null;) {
  15090. var prev = walker.prev;
  15091. forEachStep(this, fn, walker, thisp);
  15092. walker = prev;
  15093. }
  15094. };
  15095. function forEachStep(self, fn, node, thisp) {
  15096. var hit = node.value;
  15097. if (isStale(self, hit)) {
  15098. del(self, node);
  15099. if (!self[ALLOW_STALE]) {
  15100. hit = undefined;
  15101. }
  15102. }
  15103. if (hit) {
  15104. fn.call(thisp, hit.value, hit.key, self);
  15105. }
  15106. }
  15107. LRUCache.prototype.forEach = function (fn, thisp) {
  15108. thisp = thisp || this;
  15109. for (var walker = this[LRU_LIST].head; walker !== null;) {
  15110. var next = walker.next;
  15111. forEachStep(this, fn, walker, thisp);
  15112. walker = next;
  15113. }
  15114. };
  15115. LRUCache.prototype.keys = function () {
  15116. return this[LRU_LIST].toArray().map(function (k) {
  15117. return k.key;
  15118. }, this);
  15119. };
  15120. LRUCache.prototype.values = function () {
  15121. return this[LRU_LIST].toArray().map(function (k) {
  15122. return k.value;
  15123. }, this);
  15124. };
  15125. LRUCache.prototype.reset = function () {
  15126. if (this[DISPOSE] && this[LRU_LIST] && this[LRU_LIST].length) {
  15127. this[LRU_LIST].forEach(function (hit) {
  15128. this[DISPOSE](hit.key, hit.value);
  15129. }, this);
  15130. }
  15131. this[CACHE] = new map(); // hash of items by key
  15132. this[LRU_LIST] = new yallist(); // list of items in order of use recency
  15133. this[LENGTH] = 0; // length of items in the list
  15134. };
  15135. LRUCache.prototype.dump = function () {
  15136. return this[LRU_LIST].map(function (hit) {
  15137. if (!isStale(this, hit)) {
  15138. return {
  15139. k: hit.key,
  15140. v: hit.value,
  15141. e: hit.now + (hit.maxAge || 0)
  15142. };
  15143. }
  15144. }, this).toArray().filter(function (h) {
  15145. return h;
  15146. });
  15147. };
  15148. LRUCache.prototype.dumpLru = function () {
  15149. return this[LRU_LIST];
  15150. };
  15151. /* istanbul ignore next */
  15152. LRUCache.prototype.inspect = function (n, opts) {
  15153. var str = 'LRUCache {';
  15154. var extras = false;
  15155. var as = this[ALLOW_STALE];
  15156. if (as) {
  15157. str += '\n allowStale: true';
  15158. extras = true;
  15159. }
  15160. var max = this[MAX];
  15161. if (max && max !== Infinity) {
  15162. if (extras) {
  15163. str += ',';
  15164. }
  15165. str += '\n max: ' + util$2.inspect(max, opts);
  15166. extras = true;
  15167. }
  15168. var maxAge = this[MAX_AGE];
  15169. if (maxAge) {
  15170. if (extras) {
  15171. str += ',';
  15172. }
  15173. str += '\n maxAge: ' + util$2.inspect(maxAge, opts);
  15174. extras = true;
  15175. }
  15176. var lc = this[LENGTH_CALCULATOR];
  15177. if (lc && lc !== naiveLength) {
  15178. if (extras) {
  15179. str += ',';
  15180. }
  15181. str += '\n length: ' + util$2.inspect(this[LENGTH], opts);
  15182. extras = true;
  15183. }
  15184. var didFirst = false;
  15185. this[LRU_LIST].forEach(function (item) {
  15186. if (didFirst) {
  15187. str += ',\n ';
  15188. } else {
  15189. if (extras) {
  15190. str += ',\n';
  15191. }
  15192. didFirst = true;
  15193. str += '\n ';
  15194. }
  15195. var key = util$2.inspect(item.key).split('\n').join('\n ');
  15196. var val = {
  15197. value: item.value
  15198. };
  15199. if (item.maxAge !== maxAge) {
  15200. val.maxAge = item.maxAge;
  15201. }
  15202. if (lc !== naiveLength) {
  15203. val.length = item.length;
  15204. }
  15205. if (isStale(this, item)) {
  15206. val.stale = true;
  15207. }
  15208. val = util$2.inspect(val, opts).split('\n').join('\n ');
  15209. str += key + ' => ' + val;
  15210. });
  15211. if (didFirst || extras) {
  15212. str += '\n';
  15213. }
  15214. str += '}';
  15215. return str;
  15216. };
  15217. LRUCache.prototype.set = function (key, value, maxAge) {
  15218. maxAge = maxAge || this[MAX_AGE];
  15219. var now = maxAge ? Date.now() : 0;
  15220. var len = this[LENGTH_CALCULATOR](value, key);
  15221. if (this[CACHE].has(key)) {
  15222. if (len > this[MAX]) {
  15223. del(this, this[CACHE].get(key));
  15224. return false;
  15225. }
  15226. var node = this[CACHE].get(key);
  15227. var item = node.value; // dispose of the old one before overwriting
  15228. // split out into 2 ifs for better coverage tracking
  15229. if (this[DISPOSE]) {
  15230. if (!this[NO_DISPOSE_ON_SET]) {
  15231. this[DISPOSE](key, item.value);
  15232. }
  15233. }
  15234. item.now = now;
  15235. item.maxAge = maxAge;
  15236. item.value = value;
  15237. this[LENGTH] += len - item.length;
  15238. item.length = len;
  15239. this.get(key);
  15240. trim$2(this);
  15241. return true;
  15242. }
  15243. var hit = new Entry$1(key, value, len, now, maxAge); // oversized objects fall out of cache automatically.
  15244. if (hit.length > this[MAX]) {
  15245. if (this[DISPOSE]) {
  15246. this[DISPOSE](key, value);
  15247. }
  15248. return false;
  15249. }
  15250. this[LENGTH] += hit.length;
  15251. this[LRU_LIST].unshift(hit);
  15252. this[CACHE].set(key, this[LRU_LIST].head);
  15253. trim$2(this);
  15254. return true;
  15255. };
  15256. LRUCache.prototype.has = function (key) {
  15257. if (!this[CACHE].has(key)) return false;
  15258. var hit = this[CACHE].get(key).value;
  15259. if (isStale(this, hit)) {
  15260. return false;
  15261. }
  15262. return true;
  15263. };
  15264. LRUCache.prototype.get = function (key) {
  15265. return get(this, key, true);
  15266. };
  15267. LRUCache.prototype.peek = function (key) {
  15268. return get(this, key, false);
  15269. };
  15270. LRUCache.prototype.pop = function () {
  15271. var node = this[LRU_LIST].tail;
  15272. if (!node) return null;
  15273. del(this, node);
  15274. return node.value;
  15275. };
  15276. LRUCache.prototype.del = function (key) {
  15277. del(this, this[CACHE].get(key));
  15278. };
  15279. LRUCache.prototype.load = function (arr) {
  15280. // reset the cache
  15281. this.reset();
  15282. var now = Date.now(); // A previous serialized cache has the most recent items first
  15283. for (var l = arr.length - 1; l >= 0; l--) {
  15284. var hit = arr[l];
  15285. var expiresAt = hit.e || 0;
  15286. if (expiresAt === 0) {
  15287. // the item was created without expiration in a non aged cache
  15288. this.set(hit.k, hit.v);
  15289. } else {
  15290. var maxAge = expiresAt - now; // dont add already expired items
  15291. if (maxAge > 0) {
  15292. this.set(hit.k, hit.v, maxAge);
  15293. }
  15294. }
  15295. }
  15296. };
  15297. LRUCache.prototype.prune = function () {
  15298. var self = this;
  15299. this[CACHE].forEach(function (value, key) {
  15300. get(self, key, false);
  15301. });
  15302. };
  15303. function get(self, key, doUse) {
  15304. var node = self[CACHE].get(key);
  15305. if (node) {
  15306. var hit = node.value;
  15307. if (isStale(self, hit)) {
  15308. del(self, node);
  15309. if (!self[ALLOW_STALE]) hit = undefined;
  15310. } else {
  15311. if (doUse) {
  15312. self[LRU_LIST].unshiftNode(node);
  15313. }
  15314. }
  15315. if (hit) hit = hit.value;
  15316. }
  15317. return hit;
  15318. }
  15319. function isStale(self, hit) {
  15320. if (!hit || !hit.maxAge && !self[MAX_AGE]) {
  15321. return false;
  15322. }
  15323. var stale = false;
  15324. var diff = Date.now() - hit.now;
  15325. if (hit.maxAge) {
  15326. stale = diff > hit.maxAge;
  15327. } else {
  15328. stale = self[MAX_AGE] && diff > self[MAX_AGE];
  15329. }
  15330. return stale;
  15331. }
  15332. function trim$2(self) {
  15333. if (self[LENGTH] > self[MAX]) {
  15334. for (var walker = self[LRU_LIST].tail; self[LENGTH] > self[MAX] && walker !== null;) {
  15335. // We know that we're about to delete this one, and also
  15336. // what the next least recently used key will be, so just
  15337. // go ahead and set it now.
  15338. var prev = walker.prev;
  15339. del(self, walker);
  15340. walker = prev;
  15341. }
  15342. }
  15343. }
  15344. function del(self, node) {
  15345. if (node) {
  15346. var hit = node.value;
  15347. if (self[DISPOSE]) {
  15348. self[DISPOSE](hit.key, hit.value);
  15349. }
  15350. self[LENGTH] -= hit.length;
  15351. self[CACHE].delete(hit.key);
  15352. self[LRU_LIST].removeNode(node);
  15353. }
  15354. } // classy, since V8 prefers predictable objects.
  15355. function Entry$1(key, value, length, now, maxAge) {
  15356. this.key = key;
  15357. this.value = value;
  15358. this.length = length;
  15359. this.now = now;
  15360. this.maxAge = maxAge || 0;
  15361. }
  15362. var sigmund_1 = sigmund;
  15363. function sigmund(subject, maxSessions) {
  15364. maxSessions = maxSessions || 10;
  15365. var notes = [];
  15366. var analysis = '';
  15367. var RE = RegExp;
  15368. function psychoAnalyze(subject, session) {
  15369. if (session > maxSessions) return;
  15370. if (typeof subject === 'function' || typeof subject === 'undefined') {
  15371. return;
  15372. }
  15373. if (typeof subject !== 'object' || !subject || subject instanceof RE) {
  15374. analysis += subject;
  15375. return;
  15376. }
  15377. if (notes.indexOf(subject) !== -1 || session === maxSessions) return;
  15378. notes.push(subject);
  15379. analysis += '{';
  15380. Object.keys(subject).forEach(function (issue, _, __) {
  15381. // pseudo-private values. skip those.
  15382. if (issue.charAt(0) === '_') return;
  15383. var to = typeof subject[issue];
  15384. if (to === 'function' || to === 'undefined') return;
  15385. analysis += issue;
  15386. psychoAnalyze(subject[issue], session + 1);
  15387. });
  15388. }
  15389. psychoAnalyze(subject, 0);
  15390. return analysis;
  15391. } // vim: set softtabstop=4 shiftwidth=4:
  15392. var fnmatch = createCommonjsModule(function (module, exports) {
  15393. // Based on minimatch.js by isaacs <https://npmjs.org/package/minimatch>
  15394. var platform = typeof process === "object" ? process.platform : "win32";
  15395. if (module) module.exports = minimatch;else exports.minimatch = minimatch;
  15396. minimatch.Minimatch = Minimatch;
  15397. var cache = minimatch.cache = new lruCache({
  15398. max: 100
  15399. }),
  15400. GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
  15401. var qmark = "[^/]" // * => any number of characters
  15402. ,
  15403. star = qmark + "*?" // ** when dots are allowed. Anything goes, except .. and .
  15404. // not (^ or / followed by one or two dots followed by $ or /),
  15405. // followed by anything, any number of times.
  15406. ,
  15407. twoStarDot = "(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?" // not a ^ or / followed by a dot,
  15408. // followed by anything, any number of times.
  15409. ,
  15410. twoStarNoDot = "(?:(?!(?:\\\/|^)\\.).)*?" // characters that need to be escaped in RegExp.
  15411. ,
  15412. reSpecials = charSet("().*{}+?[]^$\\!"); // "abc" -> { a:true, b:true, c:true }
  15413. function charSet(s) {
  15414. return s.split("").reduce(function (set, c) {
  15415. set[c] = true;
  15416. return set;
  15417. }, {});
  15418. } // normalizes slashes.
  15419. var slashSplit = /\/+/;
  15420. minimatch.monkeyPatch = monkeyPatch;
  15421. function monkeyPatch() {
  15422. var desc = Object.getOwnPropertyDescriptor(String.prototype, "match");
  15423. var orig = desc.value;
  15424. desc.value = function (p) {
  15425. if (p instanceof Minimatch) return p.match(this);
  15426. return orig.call(this, p);
  15427. };
  15428. Object.defineProperty(String.prototype, desc);
  15429. }
  15430. minimatch.filter = filter;
  15431. function filter(pattern, options) {
  15432. options = options || {};
  15433. return function (p, i, list) {
  15434. return minimatch(p, pattern, options);
  15435. };
  15436. }
  15437. function ext(a, b) {
  15438. a = a || {};
  15439. b = b || {};
  15440. var t = {};
  15441. Object.keys(b).forEach(function (k) {
  15442. t[k] = b[k];
  15443. });
  15444. Object.keys(a).forEach(function (k) {
  15445. t[k] = a[k];
  15446. });
  15447. return t;
  15448. }
  15449. minimatch.defaults = function (def) {
  15450. if (!def || !Object.keys(def).length) return minimatch;
  15451. var orig = minimatch;
  15452. var m = function minimatch(p, pattern, options) {
  15453. return orig.minimatch(p, pattern, ext(def, options));
  15454. };
  15455. m.Minimatch = function Minimatch(pattern, options) {
  15456. return new orig.Minimatch(pattern, ext(def, options));
  15457. };
  15458. return m;
  15459. };
  15460. Minimatch.defaults = function (def) {
  15461. if (!def || !Object.keys(def).length) return Minimatch;
  15462. return minimatch.defaults(def).Minimatch;
  15463. };
  15464. function minimatch(p, pattern, options) {
  15465. if (typeof pattern !== "string") {
  15466. throw new TypeError("glob pattern string required");
  15467. }
  15468. if (!options) options = {}; // shortcut: comments match nothing.
  15469. if (!options.nocomment && pattern.charAt(0) === "#") {
  15470. return false;
  15471. } // "" only matches ""
  15472. if (pattern.trim() === "") return p === "";
  15473. return new Minimatch(pattern, options).match(p);
  15474. }
  15475. function Minimatch(pattern, options) {
  15476. if (!(this instanceof Minimatch)) {
  15477. return new Minimatch(pattern, options, cache);
  15478. }
  15479. if (typeof pattern !== "string") {
  15480. throw new TypeError("glob pattern string required");
  15481. }
  15482. if (!options) options = {}; // windows: need to use /, not \
  15483. // On other platforms, \ is a valid (albeit bad) filename char.
  15484. if (platform === "win32") {
  15485. pattern = pattern.split("\\").join("/");
  15486. } // lru storage.
  15487. // these things aren't particularly big, but walking down the string
  15488. // and turning it into a regexp can get pretty costly.
  15489. var cacheKey = pattern + "\n" + sigmund_1(options);
  15490. var cached = minimatch.cache.get(cacheKey);
  15491. if (cached) return cached;
  15492. minimatch.cache.set(cacheKey, this);
  15493. this.options = options;
  15494. this.set = [];
  15495. this.pattern = pattern;
  15496. this.regexp = null;
  15497. this.negate = false;
  15498. this.comment = false;
  15499. this.empty = false; // make the set of regexps etc.
  15500. this.make();
  15501. }
  15502. Minimatch.prototype.make = make;
  15503. function make() {
  15504. // don't do it more than once.
  15505. if (this._made) return;
  15506. var pattern = this.pattern;
  15507. var options = this.options; // empty patterns and comments match nothing.
  15508. if (!options.nocomment && pattern.charAt(0) === "#") {
  15509. this.comment = true;
  15510. return;
  15511. }
  15512. if (!pattern) {
  15513. this.empty = true;
  15514. return;
  15515. } // step 1: figure out negation, etc.
  15516. this.parseNegate(); // step 2: expand braces
  15517. var set = this.globSet = this.braceExpand();
  15518. 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
  15519. // matching patterns.
  15520. // These will be regexps, except in the case of "**", which is
  15521. // set to the GLOBSTAR object for globstar behavior,
  15522. // and will not contain any / characters
  15523. set = this.globParts = set.map(function (s) {
  15524. return s.split(slashSplit);
  15525. });
  15526. if (options.debug) console.error(this.pattern, set); // glob --> regexps
  15527. set = set.map(function (s, si, set) {
  15528. return s.map(this.parse, this);
  15529. }, this);
  15530. if (options.debug) console.error(this.pattern, set); // filter out everything that didn't compile properly.
  15531. set = set.filter(function (s) {
  15532. return -1 === s.indexOf(false);
  15533. });
  15534. if (options.debug) console.error(this.pattern, set);
  15535. this.set = set;
  15536. }
  15537. Minimatch.prototype.parseNegate = parseNegate;
  15538. function parseNegate() {
  15539. var pattern = this.pattern,
  15540. negate = false,
  15541. options = this.options,
  15542. negateOffset = 0;
  15543. if (options.nonegate) return;
  15544. for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === "!"; i++) {
  15545. negate = !negate;
  15546. negateOffset++;
  15547. }
  15548. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  15549. this.negate = negate;
  15550. } // Brace expansion:
  15551. // a{b,c}d -> abd acd
  15552. // a{b,}c -> abc ac
  15553. // a{0..3}d -> a0d a1d a2d a3d
  15554. // a{b,c{d,e}f}g -> abg acdfg acefg
  15555. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  15556. //
  15557. // Invalid sets are not expanded.
  15558. // a{2..}b -> a{2..}b
  15559. // a{b}c -> a{b}c
  15560. minimatch.braceExpand = function (pattern, options) {
  15561. return new Minimatch(pattern, options).braceExpand();
  15562. };
  15563. Minimatch.prototype.braceExpand = braceExpand;
  15564. function braceExpand(pattern, options) {
  15565. options = options || this.options;
  15566. pattern = typeof pattern === "undefined" ? this.pattern : pattern;
  15567. if (typeof pattern === "undefined") {
  15568. throw new Error("undefined pattern");
  15569. }
  15570. if (options.nobrace || !pattern.match(/\{.*\}/)) {
  15571. // shortcut. no need to expand.
  15572. return [pattern];
  15573. }
  15574. var escaping = false; // examples and comments refer to this crazy pattern:
  15575. // a{b,c{d,e},{f,g}h}x{y,z}
  15576. // expected:
  15577. // abxy
  15578. // abxz
  15579. // acdxy
  15580. // acdxz
  15581. // acexy
  15582. // acexz
  15583. // afhxy
  15584. // afhxz
  15585. // aghxy
  15586. // aghxz
  15587. // everything before the first \{ is just a prefix.
  15588. // So, we pluck that off, and work with the rest,
  15589. // and then prepend it to everything we find.
  15590. if (pattern.charAt(0) !== "{") {
  15591. // console.error(pattern)
  15592. var prefix = null;
  15593. for (var i = 0, l = pattern.length; i < l; i++) {
  15594. var c = pattern.charAt(i); // console.error(i, c)
  15595. if (c === "\\") {
  15596. escaping = !escaping;
  15597. } else if (c === "{" && !escaping) {
  15598. prefix = pattern.substr(0, i);
  15599. break;
  15600. }
  15601. } // actually no sets, all { were escaped.
  15602. if (prefix === null) {
  15603. // console.error("no sets")
  15604. return [pattern];
  15605. }
  15606. var tail = braceExpand(pattern.substr(i), options);
  15607. return tail.map(function (t) {
  15608. return prefix + t;
  15609. });
  15610. } // now we have something like:
  15611. // {b,c{d,e},{f,g}h}x{y,z}
  15612. // walk through the set, expanding each part, until
  15613. // the set ends. then, we'll expand the suffix.
  15614. // If the set only has a single member, then'll put the {} back
  15615. // first, handle numeric sets, since they're easier
  15616. var numset = pattern.match(/^\{(-?[0-9]+)\.\.(-?[0-9]+)\}/);
  15617. if (numset) {
  15618. // console.error("numset", numset[1], numset[2])
  15619. var suf = braceExpand(pattern.substr(numset[0].length), options),
  15620. start = +numset[1],
  15621. end = +numset[2],
  15622. inc = start > end ? -1 : 1,
  15623. set = [];
  15624. for (var i = start; i != end + inc; i += inc) {
  15625. // append all the suffixes
  15626. for (var ii = 0, ll = suf.length; ii < ll; ii++) {
  15627. set.push(i + suf[ii]);
  15628. }
  15629. }
  15630. return set;
  15631. } // ok, walk through the set
  15632. // We hope, somewhat optimistically, that there
  15633. // will be a } at the end.
  15634. // If the closing brace isn't found, then the pattern is
  15635. // interpreted as braceExpand("\\" + pattern) so that
  15636. // the leading \{ will be interpreted literally.
  15637. var i = 1 // skip the \{
  15638. ,
  15639. depth = 1,
  15640. set = [],
  15641. member = "",
  15642. escaping = false;
  15643. function addMember() {
  15644. set.push(member);
  15645. member = "";
  15646. } // console.error("Entering for")
  15647. FOR: for (i = 1, l = pattern.length; i < l; i++) {
  15648. var c = pattern.charAt(i); // console.error("", i, c)
  15649. if (escaping) {
  15650. escaping = false;
  15651. member += "\\" + c;
  15652. } else {
  15653. switch (c) {
  15654. case "\\":
  15655. escaping = true;
  15656. continue;
  15657. case "{":
  15658. depth++;
  15659. member += "{";
  15660. continue;
  15661. case "}":
  15662. depth--; // if this closes the actual set, then we're done
  15663. if (depth === 0) {
  15664. addMember(); // pluck off the close-brace
  15665. i++;
  15666. break FOR;
  15667. } else {
  15668. member += c;
  15669. continue;
  15670. }
  15671. case ",":
  15672. if (depth === 1) {
  15673. addMember();
  15674. } else {
  15675. member += c;
  15676. }
  15677. continue;
  15678. default:
  15679. member += c;
  15680. continue;
  15681. } // switch
  15682. } // else
  15683. } // for
  15684. // now we've either finished the set, and the suffix is
  15685. // pattern.substr(i), or we have *not* closed the set,
  15686. // and need to escape the leading brace
  15687. if (depth !== 0) {
  15688. // console.error("didn't close", pattern)
  15689. return braceExpand("\\" + pattern, options);
  15690. } // x{y,z} -> ["xy", "xz"]
  15691. // console.error("set", set)
  15692. // console.error("suffix", pattern.substr(i))
  15693. var suf = braceExpand(pattern.substr(i), options); // ["b", "c{d,e}","{f,g}h"] ->
  15694. // [["b"], ["cd", "ce"], ["fh", "gh"]]
  15695. var addBraces = set.length === 1; // console.error("set pre-expanded", set)
  15696. set = set.map(function (p) {
  15697. return braceExpand(p, options);
  15698. }); // console.error("set expanded", set)
  15699. // [["b"], ["cd", "ce"], ["fh", "gh"]] ->
  15700. // ["b", "cd", "ce", "fh", "gh"]
  15701. set = set.reduce(function (l, r) {
  15702. return l.concat(r);
  15703. });
  15704. if (addBraces) {
  15705. set = set.map(function (s) {
  15706. return "{" + s + "}";
  15707. });
  15708. } // now attach the suffixes.
  15709. var ret = [];
  15710. for (var i = 0, l = set.length; i < l; i++) {
  15711. for (var ii = 0, ll = suf.length; ii < ll; ii++) {
  15712. ret.push(set[i] + suf[ii]);
  15713. }
  15714. }
  15715. return ret;
  15716. } // parse a component of the expanded set.
  15717. // At this point, no pattern may contain "/" in it
  15718. // so we're going to return a 2d array, where each entry is the full
  15719. // pattern, split on '/', and then turned into a regular expression.
  15720. // A regexp is made at the end which joins each array with an
  15721. // escaped /, and another full one which joins each regexp with |.
  15722. //
  15723. // Following the lead of Bash 4.1, note that "**" only has special meaning
  15724. // when it is the *only* thing in a path portion. Otherwise, any series
  15725. // of * is equivalent to a single *. Globstar behavior is enabled by
  15726. // default, and can be disabled by setting options.noglobstar.
  15727. Minimatch.prototype.parse = parse;
  15728. var SUBPARSE = {};
  15729. function parse(pattern, isSub) {
  15730. var options = this.options; // shortcuts
  15731. if (!options.noglobstar && pattern === "**") return GLOBSTAR;
  15732. if (pattern === "") return "";
  15733. var re = "",
  15734. hasMagic = !!options.nocase,
  15735. escaping = false // ? => one single character
  15736. ,
  15737. patternListStack = [],
  15738. plType,
  15739. stateChar,
  15740. inClass = false,
  15741. reClassStart = -1,
  15742. classStart = -1 // . and .. never match anything that doesn't start with .,
  15743. // even when options.dot is set.
  15744. ,
  15745. patternStart = pattern.charAt(0) === "." ? "" // anything
  15746. // not (start or / followed by . or .. followed by / or end)
  15747. : options.dot ? "(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))" : "(?!\\.)";
  15748. function clearStateChar() {
  15749. if (stateChar) {
  15750. // we had some state-tracking character
  15751. // that wasn't consumed by this pass.
  15752. switch (stateChar) {
  15753. case "*":
  15754. re += star;
  15755. hasMagic = true;
  15756. break;
  15757. case "?":
  15758. re += qmark;
  15759. hasMagic = true;
  15760. break;
  15761. default:
  15762. re += "\\" + stateChar;
  15763. break;
  15764. }
  15765. stateChar = false;
  15766. }
  15767. }
  15768. for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
  15769. if (options.debug) {
  15770. console.error("%s\t%s %s %j", pattern, i, re, c);
  15771. } // skip over any that are escaped.
  15772. if (escaping && reSpecials[c]) {
  15773. re += "\\" + c;
  15774. escaping = false;
  15775. continue;
  15776. }
  15777. switch (c) {
  15778. case "/":
  15779. // completely not allowed, even escaped.
  15780. // Should already be path-split by now.
  15781. return false;
  15782. case "\\":
  15783. clearStateChar();
  15784. escaping = true;
  15785. continue;
  15786. // the various stateChar values
  15787. // for the "extglob" stuff.
  15788. case "?":
  15789. case "*":
  15790. case "+":
  15791. case "@":
  15792. case "!":
  15793. if (options.debug) {
  15794. console.error("%s\t%s %s %j <-- stateChar", pattern, i, re, c);
  15795. } // all of those are literals inside a class, except that
  15796. // the glob [!a] means [^a] in regexp
  15797. if (inClass) {
  15798. if (c === "!" && i === classStart + 1) c = "^";
  15799. re += c;
  15800. continue;
  15801. } // if we already have a stateChar, then it means
  15802. // that there was something like ** or +? in there.
  15803. // Handle the stateChar, then proceed with this one.
  15804. clearStateChar();
  15805. stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
  15806. // just clear the statechar *now*, rather than even diving into
  15807. // the patternList stuff.
  15808. if (options.noext) clearStateChar();
  15809. continue;
  15810. case "(":
  15811. if (inClass) {
  15812. re += "(";
  15813. continue;
  15814. }
  15815. if (!stateChar) {
  15816. re += "\\(";
  15817. continue;
  15818. }
  15819. plType = stateChar;
  15820. patternListStack.push({
  15821. type: plType,
  15822. start: i - 1,
  15823. reStart: re.length
  15824. }); // negation is (?:(?!js)[^/]*)
  15825. re += stateChar === "!" ? "(?:(?!" : "(?:";
  15826. stateChar = false;
  15827. continue;
  15828. case ")":
  15829. if (inClass || !patternListStack.length) {
  15830. re += "\\)";
  15831. continue;
  15832. }
  15833. hasMagic = true;
  15834. re += ")";
  15835. plType = patternListStack.pop().type; // negation is (?:(?!js)[^/]*)
  15836. // The others are (?:<pattern>)<type>
  15837. switch (plType) {
  15838. case "!":
  15839. re += "[^/]*?)";
  15840. break;
  15841. case "?":
  15842. case "+":
  15843. case "*":
  15844. re += plType;
  15845. // the default anyway
  15846. }
  15847. continue;
  15848. case "|":
  15849. if (inClass || !patternListStack.length || escaping) {
  15850. re += "\\|";
  15851. escaping = false;
  15852. continue;
  15853. }
  15854. re += "|";
  15855. continue;
  15856. // these are mostly the same in regexp and glob
  15857. case "[":
  15858. // swallow any state-tracking char before the [
  15859. clearStateChar();
  15860. if (inClass) {
  15861. re += "\\" + c;
  15862. continue;
  15863. }
  15864. inClass = true;
  15865. classStart = i;
  15866. reClassStart = re.length;
  15867. re += c;
  15868. continue;
  15869. case "]":
  15870. // a right bracket shall lose its special
  15871. // meaning and represent itself in
  15872. // a bracket expression if it occurs
  15873. // first in the list. -- POSIX.2 2.8.3.2
  15874. if (i === classStart + 1 || !inClass) {
  15875. re += "\\" + c;
  15876. escaping = false;
  15877. continue;
  15878. } // finish up the class.
  15879. hasMagic = true;
  15880. inClass = false;
  15881. re += c;
  15882. continue;
  15883. default:
  15884. // swallow any state char that wasn't consumed
  15885. clearStateChar();
  15886. if (escaping) {
  15887. // no need
  15888. escaping = false;
  15889. } else if (reSpecials[c] && !(c === "^" && inClass)) {
  15890. re += "\\";
  15891. }
  15892. re += c;
  15893. } // switch
  15894. } // for
  15895. // handle the case where we left a class open.
  15896. // "[abc" is valid, equivalent to "\[abc"
  15897. if (inClass) {
  15898. // split where the last [ was, and escape it
  15899. // this is a huge pita. We now have to re-walk
  15900. // the contents of the would-be class to re-translate
  15901. // any characters that were passed through as-is
  15902. var cs = pattern.substr(classStart + 1),
  15903. sp = this.parse(cs, SUBPARSE);
  15904. re = re.substr(0, reClassStart) + "\\[" + sp[0];
  15905. hasMagic = hasMagic || sp[1];
  15906. } // handle the case where we had a +( thing at the *end*
  15907. // of the pattern.
  15908. // each pattern list stack adds 3 chars, and we need to go through
  15909. // and escape any | chars that were passed through as-is for the regexp.
  15910. // Go through and escape them, taking care not to double-escape any
  15911. // | chars that were already escaped.
  15912. var pl;
  15913. while (pl = patternListStack.pop()) {
  15914. var tail = re.slice(pl.reStart + 3); // maybe some even number of \, then maybe 1 \, followed by a |
  15915. tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
  15916. if (!$2) {
  15917. // the | isn't already escaped, so escape it.
  15918. $2 = "\\";
  15919. } // need to escape all those slashes *again*, without escaping the
  15920. // one that we need for escaping the | character. As it works out,
  15921. // escaping an even number of slashes can be done by simply repeating
  15922. // it exactly after itself. That's why this trick works.
  15923. //
  15924. // I am sorry that you have to see this.
  15925. return $1 + $1 + $2 + "|";
  15926. }); // console.error("tail=%j\n %s", tail, tail)
  15927. var t = pl.type === "*" ? star : pl.type === "?" ? qmark : "\\" + pl.type;
  15928. hasMagic = true;
  15929. re = re.slice(0, pl.reStart) + t + "\\(" + tail;
  15930. } // handle trailing things that only matter at the very end.
  15931. clearStateChar();
  15932. if (escaping) {
  15933. // trailing \\
  15934. re += "\\\\";
  15935. } // only need to apply the nodot start if the re starts with
  15936. // something that could conceivably capture a dot
  15937. var addPatternStart = false;
  15938. switch (re.charAt(0)) {
  15939. case ".":
  15940. case "[":
  15941. case "(":
  15942. addPatternStart = true;
  15943. } // if the re is not "" at this point, then we need to make sure
  15944. // it doesn't match against an empty path part.
  15945. // Otherwise a/* will match a/, which it should not.
  15946. if (re !== "" && hasMagic) re = "(?=.)" + re;
  15947. if (addPatternStart) re = patternStart + re; // parsing just a piece of a larger pattern.
  15948. if (isSub === SUBPARSE) {
  15949. return [re, hasMagic];
  15950. } // skip the regexp for non-magical patterns
  15951. // unescape anything in it, though, so that it'll be
  15952. // an exact match against a file etc.
  15953. if (!hasMagic) {
  15954. return globUnescape(pattern);
  15955. }
  15956. var flags = options.nocase ? "i" : "",
  15957. regExp = new RegExp("^" + re + "$", flags);
  15958. regExp._glob = pattern;
  15959. regExp._src = re;
  15960. return regExp;
  15961. }
  15962. minimatch.makeRe = function (pattern, options) {
  15963. return new Minimatch(pattern, options || {}).makeRe();
  15964. };
  15965. Minimatch.prototype.makeRe = makeRe;
  15966. function makeRe() {
  15967. if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
  15968. // pattern strings, or "**".
  15969. //
  15970. // It's better to use .match(). This function shouldn't
  15971. // be used, really, but it's pretty convenient sometimes,
  15972. // when you just want to work with a regex.
  15973. var set = this.set;
  15974. if (!set.length) return this.regexp = false;
  15975. var options = this.options;
  15976. var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot,
  15977. flags = options.nocase ? "i" : "";
  15978. var re = set.map(function (pattern) {
  15979. return pattern.map(function (p) {
  15980. return p === GLOBSTAR ? twoStar : typeof p === "string" ? regExpEscape(p) : p._src;
  15981. }).join("\\\/");
  15982. }).join("|"); // must match entire pattern
  15983. // ending in a * or ** will make it less strict.
  15984. re = "^(?:" + re + ")$"; // can match anything, as long as it's not this.
  15985. if (this.negate) re = "^(?!" + re + ").*$";
  15986. try {
  15987. return this.regexp = new RegExp(re, flags);
  15988. } catch (ex) {
  15989. return this.regexp = false;
  15990. }
  15991. }
  15992. minimatch.match = function (list, pattern, options) {
  15993. var mm = new Minimatch(pattern, options);
  15994. list = list.filter(function (f) {
  15995. return mm.match(f);
  15996. });
  15997. if (options.nonull && !list.length) {
  15998. list.push(pattern);
  15999. }
  16000. return list;
  16001. };
  16002. Minimatch.prototype.match = match;
  16003. function match(f, partial) {
  16004. // console.error("match", f, this.pattern)
  16005. // short-circuit in the case of busted things.
  16006. // comments, etc.
  16007. if (this.comment) return false;
  16008. if (this.empty) return f === "";
  16009. if (f === "/" && partial) return true;
  16010. var options = this.options; // windows: need to use /, not \
  16011. // On other platforms, \ is a valid (albeit bad) filename char.
  16012. if (platform === "win32") {
  16013. f = f.split("\\").join("/");
  16014. } // treat the test path as a set of pathparts.
  16015. f = f.split(slashSplit);
  16016. if (options.debug) {
  16017. console.error(this.pattern, "split", f);
  16018. } // just ONE of the pattern sets in this.set needs to match
  16019. // in order for it to be valid. If negating, then just one
  16020. // match means that we have failed.
  16021. // Either way, return on the first hit.
  16022. var set = this.set; // console.error(this.pattern, "set", set)
  16023. for (var i = 0, l = set.length; i < l; i++) {
  16024. var pattern = set[i];
  16025. var hit = this.matchOne(f, pattern, partial);
  16026. if (hit) {
  16027. if (options.flipNegate) return true;
  16028. return !this.negate;
  16029. }
  16030. } // didn't get any hits. this is success if it's a negative
  16031. // pattern, failure otherwise.
  16032. if (options.flipNegate) return false;
  16033. return this.negate;
  16034. } // set partial to true to test if, for example,
  16035. // "/a/b" matches the start of "/*/b/*/d"
  16036. // Partial means, if you run out of file before you run
  16037. // out of pattern, then that's fine, as long as all
  16038. // the parts match.
  16039. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  16040. var options = this.options;
  16041. if (options.debug) {
  16042. console.error("matchOne", {
  16043. "this": this,
  16044. file: file,
  16045. pattern: pattern
  16046. });
  16047. }
  16048. if (options.matchBase && pattern.length === 1) {
  16049. file = path$2.basename(file.join("/")).split("/");
  16050. }
  16051. if (options.debug) {
  16052. console.error("matchOne", file.length, pattern.length);
  16053. }
  16054. for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
  16055. if (options.debug) {
  16056. console.error("matchOne loop");
  16057. }
  16058. var p = pattern[pi],
  16059. f = file[fi];
  16060. if (options.debug) {
  16061. console.error(pattern, p, f);
  16062. } // should be impossible.
  16063. // some invalid regexp stuff in the set.
  16064. if (p === false) return false;
  16065. if (p === GLOBSTAR) {
  16066. if (options.debug) console.error('GLOBSTAR', [pattern, p, f]); // "**"
  16067. // a/**/b/**/c would match the following:
  16068. // a/b/x/y/z/c
  16069. // a/x/y/z/b/c
  16070. // a/b/x/b/x/c
  16071. // a/b/c
  16072. // To do this, take the rest of the pattern after
  16073. // the **, and see if it would match the file remainder.
  16074. // If so, return success.
  16075. // If not, the ** "swallows" a segment, and try again.
  16076. // This is recursively awful.
  16077. //
  16078. // a/**/b/**/c matching a/b/x/y/z/c
  16079. // - a matches a
  16080. // - doublestar
  16081. // - matchOne(b/x/y/z/c, b/**/c)
  16082. // - b matches b
  16083. // - doublestar
  16084. // - matchOne(x/y/z/c, c) -> no
  16085. // - matchOne(y/z/c, c) -> no
  16086. // - matchOne(z/c, c) -> no
  16087. // - matchOne(c, c) yes, hit
  16088. var fr = fi,
  16089. pr = pi + 1;
  16090. if (pr === pl) {
  16091. if (options.debug) console.error('** at the end'); // a ** at the end will just swallow the rest.
  16092. // We have found a match.
  16093. // however, it will not swallow /.x, unless
  16094. // options.dot is set.
  16095. // . and .. are *never* matched by **, for explosively
  16096. // exponential reasons.
  16097. for (; fi < fl; fi++) {
  16098. if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".") return false;
  16099. }
  16100. return true;
  16101. } // ok, let's see if we can swallow whatever we can.
  16102. WHILE: while (fr < fl) {
  16103. var swallowee = file[fr];
  16104. if (options.debug) {
  16105. console.error('\nglobstar while', file, fr, pattern, pr, swallowee);
  16106. } // XXX remove this slice. Just pass the start index.
  16107. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  16108. if (options.debug) console.error('globstar found match!', fr, fl, swallowee); // found a match.
  16109. return true;
  16110. } else {
  16111. // can't swallow "." or ".." ever.
  16112. // can only swallow ".foo" when explicitly asked.
  16113. if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
  16114. if (options.debug) console.error("dot detected!", file, fr, pattern, pr);
  16115. break WHILE;
  16116. } // ** swallows a segment, and continue.
  16117. if (options.debug) console.error('globstar swallow a segment, and continue');
  16118. fr++;
  16119. }
  16120. } // no match was found.
  16121. // However, in partial mode, we can't say this is necessarily over.
  16122. // If there's more *pattern* left, then
  16123. if (partial) {
  16124. // ran out of file
  16125. // console.error("\n>>> no match, partial?", file, fr, pattern, pr)
  16126. if (fr === fl) return true;
  16127. }
  16128. return false;
  16129. } // something other than **
  16130. // non-magic patterns just have to match exactly
  16131. // patterns with magic have been turned into regexps.
  16132. var hit;
  16133. if (typeof p === "string") {
  16134. if (options.nocase) {
  16135. hit = f.toLowerCase() === p.toLowerCase();
  16136. } else {
  16137. hit = f === p;
  16138. }
  16139. if (options.debug) {
  16140. console.error("string match", p, f, hit);
  16141. }
  16142. } else {
  16143. hit = f.match(p);
  16144. if (options.debug) {
  16145. console.error("pattern match", p, f, hit);
  16146. }
  16147. }
  16148. if (!hit) return false;
  16149. } // Note: ending in / means that we'll get a final ""
  16150. // at the end of the pattern. This can only match a
  16151. // corresponding "" at the end of the file.
  16152. // If the file ends in /, then it can only match a
  16153. // a pattern that ends in /, unless the pattern just
  16154. // doesn't have any more for it. But, a/b/ should *not*
  16155. // match "a/b/*", even though "" matches against the
  16156. // [^/]*? pattern, except in partial mode, where it might
  16157. // simply not be reached yet.
  16158. // However, a/b/ should still satisfy a/*
  16159. // now either we fell off the end of the pattern, or we're done.
  16160. if (fi === fl && pi === pl) {
  16161. // ran out of pattern and filename at the same time.
  16162. // an exact hit!
  16163. return true;
  16164. } else if (fi === fl) {
  16165. // ran out of file, but still had pattern left.
  16166. // this is ok if we're doing the match as part of
  16167. // a glob fs traversal.
  16168. return partial;
  16169. } else if (pi === pl) {
  16170. // ran out of pattern, still have file left.
  16171. // this is only acceptable if we're on the very last
  16172. // empty segment of a file with a trailing slash.
  16173. // a/* should match a/b/
  16174. var emptyFileEnd = fi === fl - 1 && file[fi] === "";
  16175. return emptyFileEnd;
  16176. } // should be unreachable.
  16177. throw new Error("wtf?");
  16178. }; // replace stuff like \* with *
  16179. function globUnescape(s) {
  16180. return s.replace(/\\(.)/g, "$1");
  16181. }
  16182. function regExpEscape(s) {
  16183. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
  16184. }
  16185. });
  16186. var fnmatch_1 = fnmatch.minimatch;
  16187. var ini = createCommonjsModule(function (module, exports) {
  16188. var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
  16189. return new (P || (P = Promise))(function (resolve, reject) {
  16190. function fulfilled(value) {
  16191. try {
  16192. step(generator.next(value));
  16193. } catch (e) {
  16194. reject(e);
  16195. }
  16196. }
  16197. function rejected(value) {
  16198. try {
  16199. step(generator["throw"](value));
  16200. } catch (e) {
  16201. reject(e);
  16202. }
  16203. }
  16204. function step(result) {
  16205. result.done ? resolve(result.value) : new P(function (resolve) {
  16206. resolve(result.value);
  16207. }).then(fulfilled, rejected);
  16208. }
  16209. step((generator = generator.apply(thisArg, _arguments || [])).next());
  16210. });
  16211. };
  16212. var __generator = this && this.__generator || function (thisArg, body) {
  16213. var _ = {
  16214. label: 0,
  16215. sent: function sent() {
  16216. if (t[0] & 1) throw t[1];
  16217. return t[1];
  16218. },
  16219. trys: [],
  16220. ops: []
  16221. },
  16222. f,
  16223. y,
  16224. t,
  16225. g;
  16226. return g = {
  16227. next: verb(0),
  16228. "throw": verb(1),
  16229. "return": verb(2)
  16230. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  16231. return this;
  16232. }), g;
  16233. function verb(n) {
  16234. return function (v) {
  16235. return step([n, v]);
  16236. };
  16237. }
  16238. function step(op) {
  16239. if (f) throw new TypeError("Generator is already executing.");
  16240. while (_) {
  16241. try {
  16242. 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;
  16243. if (y = 0, t) op = [op[0] & 2, t.value];
  16244. switch (op[0]) {
  16245. case 0:
  16246. case 1:
  16247. t = op;
  16248. break;
  16249. case 4:
  16250. _.label++;
  16251. return {
  16252. value: op[1],
  16253. done: false
  16254. };
  16255. case 5:
  16256. _.label++;
  16257. y = op[1];
  16258. op = [0];
  16259. continue;
  16260. case 7:
  16261. op = _.ops.pop();
  16262. _.trys.pop();
  16263. continue;
  16264. default:
  16265. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  16266. _ = 0;
  16267. continue;
  16268. }
  16269. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  16270. _.label = op[1];
  16271. break;
  16272. }
  16273. if (op[0] === 6 && _.label < t[1]) {
  16274. _.label = t[1];
  16275. t = op;
  16276. break;
  16277. }
  16278. if (t && _.label < t[2]) {
  16279. _.label = t[2];
  16280. _.ops.push(op);
  16281. break;
  16282. }
  16283. if (t[2]) _.ops.pop();
  16284. _.trys.pop();
  16285. continue;
  16286. }
  16287. op = body.call(thisArg, _);
  16288. } catch (e) {
  16289. op = [6, e];
  16290. y = 0;
  16291. } finally {
  16292. f = t = 0;
  16293. }
  16294. }
  16295. if (op[0] & 5) throw op[1];
  16296. return {
  16297. value: op[0] ? op[1] : void 0,
  16298. done: true
  16299. };
  16300. }
  16301. };
  16302. var __importStar = this && this.__importStar || function (mod) {
  16303. if (mod && mod.__esModule) return mod;
  16304. var result = {};
  16305. if (mod != null) for (var k in mod) {
  16306. if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  16307. }
  16308. result["default"] = mod;
  16309. return result;
  16310. };
  16311. Object.defineProperty(exports, "__esModule", {
  16312. value: true
  16313. });
  16314. var fs = __importStar(fs$1);
  16315. /**
  16316. * define the possible values:
  16317. * section: [section]
  16318. * param: key=value
  16319. * comment: ;this is a comment
  16320. */
  16321. var regex = {
  16322. section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
  16323. param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
  16324. comment: /^\s*[#;].*$/
  16325. };
  16326. /**
  16327. * Parses an .ini file
  16328. * @param file The location of the .ini file
  16329. */
  16330. function parse(file) {
  16331. return __awaiter(this, void 0, void 0, function () {
  16332. return __generator(this, function (_a) {
  16333. return [2
  16334. /*return*/
  16335. , new Promise(function (resolve, reject) {
  16336. fs.readFile(file, 'utf8', function (err, data) {
  16337. if (err) {
  16338. reject(err);
  16339. return;
  16340. }
  16341. resolve(parseString(data));
  16342. });
  16343. })];
  16344. });
  16345. });
  16346. }
  16347. exports.parse = parse;
  16348. function parseSync(file) {
  16349. return parseString(fs.readFileSync(file, 'utf8'));
  16350. }
  16351. exports.parseSync = parseSync;
  16352. function parseString(data) {
  16353. var sectionBody = {};
  16354. var sectionName = null;
  16355. var value = [[sectionName, sectionBody]];
  16356. var lines = data.split(/\r\n|\r|\n/);
  16357. lines.forEach(function (line) {
  16358. var match;
  16359. if (regex.comment.test(line)) {
  16360. return;
  16361. }
  16362. if (regex.param.test(line)) {
  16363. match = line.match(regex.param);
  16364. sectionBody[match[1]] = match[2];
  16365. } else if (regex.section.test(line)) {
  16366. match = line.match(regex.section);
  16367. sectionName = match[1];
  16368. sectionBody = {};
  16369. value.push([sectionName, sectionBody]);
  16370. }
  16371. });
  16372. return value;
  16373. }
  16374. exports.parseString = parseString;
  16375. });
  16376. unwrapExports(ini);
  16377. var ini_1 = ini.parse;
  16378. var ini_2 = ini.parseSync;
  16379. var ini_3 = ini.parseString;
  16380. var name$1 = "editorconfig";
  16381. var version$1 = "0.15.3";
  16382. var description$1 = "EditorConfig File Locator and Interpreter for Node.js";
  16383. var keywords = [
  16384. "editorconfig",
  16385. "core"
  16386. ];
  16387. var main$1 = "src/index.js";
  16388. var contributors = [
  16389. "Hong Xu (topbug.net)",
  16390. "Jed Mao (https://github.com/jedmao/)",
  16391. "Trey Hunner (http://treyhunner.com)"
  16392. ];
  16393. var directories = {
  16394. bin: "./bin",
  16395. lib: "./lib"
  16396. };
  16397. var scripts$1 = {
  16398. clean: "rimraf dist",
  16399. prebuild: "npm run clean",
  16400. build: "tsc",
  16401. pretest: "npm run lint && npm run build && npm run copy && cmake .",
  16402. test: "ctest .",
  16403. "pretest:ci": "npm run pretest",
  16404. "test:ci": "ctest -VV --output-on-failure .",
  16405. lint: "npm run eclint && npm run tslint",
  16406. eclint: "eclint check --indent_size ignore \"src/**\"",
  16407. tslint: "tslint --project tsconfig.json --exclude package.json",
  16408. copy: "cpy .npmignore LICENSE README.md CHANGELOG.md dist && cpy bin/* dist/bin && cpy src/lib/fnmatch*.* dist/src/lib",
  16409. prepub: "npm run lint && npm run build && npm run copy",
  16410. pub: "npm publish ./dist"
  16411. };
  16412. var repository$1 = {
  16413. type: "git",
  16414. url: "git://github.com/editorconfig/editorconfig-core-js.git"
  16415. };
  16416. var bugs = "https://github.com/editorconfig/editorconfig-core-js/issues";
  16417. var author$1 = "EditorConfig Team";
  16418. var license$1 = "MIT";
  16419. var dependencies$1 = {
  16420. commander: "^2.19.0",
  16421. "lru-cache": "^4.1.5",
  16422. semver: "^5.6.0",
  16423. sigmund: "^1.0.1"
  16424. };
  16425. var devDependencies$1 = {
  16426. "@types/mocha": "^5.2.6",
  16427. "@types/node": "^10.12.29",
  16428. "@types/semver": "^5.5.0",
  16429. "cpy-cli": "^2.0.0",
  16430. eclint: "^2.8.1",
  16431. mocha: "^5.2.0",
  16432. rimraf: "^2.6.3",
  16433. should: "^13.2.3",
  16434. tslint: "^5.13.1",
  16435. typescript: "^3.3.3333"
  16436. };
  16437. var _package$2 = {
  16438. name: name$1,
  16439. version: version$1,
  16440. description: description$1,
  16441. keywords: keywords,
  16442. main: main$1,
  16443. contributors: contributors,
  16444. directories: directories,
  16445. scripts: scripts$1,
  16446. repository: repository$1,
  16447. bugs: bugs,
  16448. author: author$1,
  16449. license: license$1,
  16450. dependencies: dependencies$1,
  16451. devDependencies: devDependencies$1
  16452. };
  16453. var _package$3 = /*#__PURE__*/Object.freeze({
  16454. __proto__: null,
  16455. name: name$1,
  16456. version: version$1,
  16457. description: description$1,
  16458. keywords: keywords,
  16459. main: main$1,
  16460. contributors: contributors,
  16461. directories: directories,
  16462. scripts: scripts$1,
  16463. repository: repository$1,
  16464. bugs: bugs,
  16465. author: author$1,
  16466. license: license$1,
  16467. dependencies: dependencies$1,
  16468. devDependencies: devDependencies$1,
  16469. 'default': _package$2
  16470. });
  16471. var require$$4 = getCjsExportFromNamespace(_package$3);
  16472. var src = createCommonjsModule(function (module, exports) {
  16473. var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
  16474. return new (P || (P = Promise))(function (resolve, reject) {
  16475. function fulfilled(value) {
  16476. try {
  16477. step(generator.next(value));
  16478. } catch (e) {
  16479. reject(e);
  16480. }
  16481. }
  16482. function rejected(value) {
  16483. try {
  16484. step(generator["throw"](value));
  16485. } catch (e) {
  16486. reject(e);
  16487. }
  16488. }
  16489. function step(result) {
  16490. result.done ? resolve(result.value) : new P(function (resolve) {
  16491. resolve(result.value);
  16492. }).then(fulfilled, rejected);
  16493. }
  16494. step((generator = generator.apply(thisArg, _arguments || [])).next());
  16495. });
  16496. };
  16497. var __generator = this && this.__generator || function (thisArg, body) {
  16498. var _ = {
  16499. label: 0,
  16500. sent: function sent() {
  16501. if (t[0] & 1) throw t[1];
  16502. return t[1];
  16503. },
  16504. trys: [],
  16505. ops: []
  16506. },
  16507. f,
  16508. y,
  16509. t,
  16510. g;
  16511. return g = {
  16512. next: verb(0),
  16513. "throw": verb(1),
  16514. "return": verb(2)
  16515. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  16516. return this;
  16517. }), g;
  16518. function verb(n) {
  16519. return function (v) {
  16520. return step([n, v]);
  16521. };
  16522. }
  16523. function step(op) {
  16524. if (f) throw new TypeError("Generator is already executing.");
  16525. while (_) {
  16526. try {
  16527. 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;
  16528. if (y = 0, t) op = [op[0] & 2, t.value];
  16529. switch (op[0]) {
  16530. case 0:
  16531. case 1:
  16532. t = op;
  16533. break;
  16534. case 4:
  16535. _.label++;
  16536. return {
  16537. value: op[1],
  16538. done: false
  16539. };
  16540. case 5:
  16541. _.label++;
  16542. y = op[1];
  16543. op = [0];
  16544. continue;
  16545. case 7:
  16546. op = _.ops.pop();
  16547. _.trys.pop();
  16548. continue;
  16549. default:
  16550. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  16551. _ = 0;
  16552. continue;
  16553. }
  16554. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  16555. _.label = op[1];
  16556. break;
  16557. }
  16558. if (op[0] === 6 && _.label < t[1]) {
  16559. _.label = t[1];
  16560. t = op;
  16561. break;
  16562. }
  16563. if (t && _.label < t[2]) {
  16564. _.label = t[2];
  16565. _.ops.push(op);
  16566. break;
  16567. }
  16568. if (t[2]) _.ops.pop();
  16569. _.trys.pop();
  16570. continue;
  16571. }
  16572. op = body.call(thisArg, _);
  16573. } catch (e) {
  16574. op = [6, e];
  16575. y = 0;
  16576. } finally {
  16577. f = t = 0;
  16578. }
  16579. }
  16580. if (op[0] & 5) throw op[1];
  16581. return {
  16582. value: op[0] ? op[1] : void 0,
  16583. done: true
  16584. };
  16585. }
  16586. };
  16587. var __importStar = this && this.__importStar || function (mod) {
  16588. if (mod && mod.__esModule) return mod;
  16589. var result = {};
  16590. if (mod != null) for (var k in mod) {
  16591. if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  16592. }
  16593. result["default"] = mod;
  16594. return result;
  16595. };
  16596. var __importDefault = this && this.__importDefault || function (mod) {
  16597. return mod && mod.__esModule ? mod : {
  16598. "default": mod
  16599. };
  16600. };
  16601. Object.defineProperty(exports, "__esModule", {
  16602. value: true
  16603. });
  16604. var fs = __importStar(fs$1);
  16605. var path = __importStar(path$2);
  16606. var semver = __importStar(semver$1);
  16607. var fnmatch_1 = __importDefault(fnmatch);
  16608. exports.parseString = ini.parseString;
  16609. var package_json_1 = __importDefault(require$$4);
  16610. var knownProps = {
  16611. end_of_line: true,
  16612. indent_style: true,
  16613. indent_size: true,
  16614. insert_final_newline: true,
  16615. trim_trailing_whitespace: true,
  16616. charset: true
  16617. };
  16618. function fnmatch$1(filepath, glob) {
  16619. var matchOptions = {
  16620. matchBase: true,
  16621. dot: true,
  16622. noext: true
  16623. };
  16624. glob = glob.replace(/\*\*/g, '{*,**/**/**}');
  16625. return fnmatch_1.default(filepath, glob, matchOptions);
  16626. }
  16627. function getConfigFileNames(filepath, options) {
  16628. var paths = [];
  16629. do {
  16630. filepath = path.dirname(filepath);
  16631. paths.push(path.join(filepath, options.config));
  16632. } while (filepath !== options.root);
  16633. return paths;
  16634. }
  16635. function processMatches(matches, version) {
  16636. // Set indent_size to 'tab' if indent_size is unspecified and
  16637. // indent_style is set to 'tab'.
  16638. if ('indent_style' in matches && matches.indent_style === 'tab' && !('indent_size' in matches) && semver.gte(version, '0.10.0')) {
  16639. matches.indent_size = 'tab';
  16640. } // Set tab_width to indent_size if indent_size is specified and
  16641. // tab_width is unspecified
  16642. if ('indent_size' in matches && !('tab_width' in matches) && matches.indent_size !== 'tab') {
  16643. matches.tab_width = matches.indent_size;
  16644. } // Set indent_size to tab_width if indent_size is 'tab'
  16645. if ('indent_size' in matches && 'tab_width' in matches && matches.indent_size === 'tab') {
  16646. matches.indent_size = matches.tab_width;
  16647. }
  16648. return matches;
  16649. }
  16650. function processOptions(options, filepath) {
  16651. if (options === void 0) {
  16652. options = {};
  16653. }
  16654. return {
  16655. config: options.config || '.editorconfig',
  16656. version: options.version || package_json_1.default.version,
  16657. root: path.resolve(options.root || path.parse(filepath).root)
  16658. };
  16659. }
  16660. function buildFullGlob(pathPrefix, glob) {
  16661. switch (glob.indexOf('/')) {
  16662. case -1:
  16663. glob = '**/' + glob;
  16664. break;
  16665. case 0:
  16666. glob = glob.substring(1);
  16667. break;
  16668. }
  16669. return path.join(pathPrefix, glob);
  16670. }
  16671. function extendProps(props, options) {
  16672. if (props === void 0) {
  16673. props = {};
  16674. }
  16675. if (options === void 0) {
  16676. options = {};
  16677. }
  16678. for (var key in options) {
  16679. if (options.hasOwnProperty(key)) {
  16680. var value = options[key];
  16681. var key2 = key.toLowerCase();
  16682. var value2 = value;
  16683. if (knownProps[key2]) {
  16684. value2 = value.toLowerCase();
  16685. }
  16686. try {
  16687. value2 = JSON.parse(value);
  16688. } catch (e) {}
  16689. if (typeof value === 'undefined' || value === null) {
  16690. // null and undefined are values specific to JSON (no special meaning
  16691. // in editorconfig) & should just be returned as regular strings.
  16692. value2 = String(value);
  16693. }
  16694. props[key2] = value2;
  16695. }
  16696. }
  16697. return props;
  16698. }
  16699. function parseFromConfigs(configs, filepath, options) {
  16700. return processMatches(configs.reverse().reduce(function (matches, file) {
  16701. var pathPrefix = path.dirname(file.name);
  16702. file.contents.forEach(function (section) {
  16703. var glob = section[0];
  16704. var options2 = section[1];
  16705. if (!glob) {
  16706. return;
  16707. }
  16708. var fullGlob = buildFullGlob(pathPrefix, glob);
  16709. if (!fnmatch$1(filepath, fullGlob)) {
  16710. return;
  16711. }
  16712. matches = extendProps(matches, options2);
  16713. });
  16714. return matches;
  16715. }, {}), options.version);
  16716. }
  16717. function getConfigsForFiles(files) {
  16718. var configs = [];
  16719. for (var i in files) {
  16720. if (files.hasOwnProperty(i)) {
  16721. var file = files[i];
  16722. var contents = ini.parseString(file.contents);
  16723. configs.push({
  16724. name: file.name,
  16725. contents: contents
  16726. });
  16727. if ((contents[0][1].root || '').toLowerCase() === 'true') {
  16728. break;
  16729. }
  16730. }
  16731. }
  16732. return configs;
  16733. }
  16734. function readConfigFiles(filepaths) {
  16735. return __awaiter(this, void 0, void 0, function () {
  16736. return __generator(this, function (_a) {
  16737. return [2
  16738. /*return*/
  16739. , Promise.all(filepaths.map(function (name) {
  16740. return new Promise(function (resolve) {
  16741. fs.readFile(name, 'utf8', function (err, data) {
  16742. resolve({
  16743. name: name,
  16744. contents: err ? '' : data
  16745. });
  16746. });
  16747. });
  16748. }))];
  16749. });
  16750. });
  16751. }
  16752. function readConfigFilesSync(filepaths) {
  16753. var files = [];
  16754. var file;
  16755. filepaths.forEach(function (filepath) {
  16756. try {
  16757. file = fs.readFileSync(filepath, 'utf8');
  16758. } catch (e) {
  16759. file = '';
  16760. }
  16761. files.push({
  16762. name: filepath,
  16763. contents: file
  16764. });
  16765. });
  16766. return files;
  16767. }
  16768. function opts(filepath, options) {
  16769. if (options === void 0) {
  16770. options = {};
  16771. }
  16772. var resolvedFilePath = path.resolve(filepath);
  16773. return [resolvedFilePath, processOptions(options, resolvedFilePath)];
  16774. }
  16775. function parseFromFiles(filepath, files, options) {
  16776. if (options === void 0) {
  16777. options = {};
  16778. }
  16779. return __awaiter(this, void 0, void 0, function () {
  16780. var _a, resolvedFilePath, processedOptions;
  16781. return __generator(this, function (_b) {
  16782. _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
  16783. return [2
  16784. /*return*/
  16785. , files.then(getConfigsForFiles).then(function (configs) {
  16786. return parseFromConfigs(configs, resolvedFilePath, processedOptions);
  16787. })];
  16788. });
  16789. });
  16790. }
  16791. exports.parseFromFiles = parseFromFiles;
  16792. function parseFromFilesSync(filepath, files, options) {
  16793. if (options === void 0) {
  16794. options = {};
  16795. }
  16796. var _a = opts(filepath, options),
  16797. resolvedFilePath = _a[0],
  16798. processedOptions = _a[1];
  16799. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  16800. }
  16801. exports.parseFromFilesSync = parseFromFilesSync;
  16802. function parse(_filepath, _options) {
  16803. if (_options === void 0) {
  16804. _options = {};
  16805. }
  16806. return __awaiter(this, void 0, void 0, function () {
  16807. var _a, resolvedFilePath, processedOptions, filepaths;
  16808. return __generator(this, function (_b) {
  16809. _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
  16810. filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  16811. return [2
  16812. /*return*/
  16813. , readConfigFiles(filepaths).then(getConfigsForFiles).then(function (configs) {
  16814. return parseFromConfigs(configs, resolvedFilePath, processedOptions);
  16815. })];
  16816. });
  16817. });
  16818. }
  16819. exports.parse = parse;
  16820. function parseSync(_filepath, _options) {
  16821. if (_options === void 0) {
  16822. _options = {};
  16823. }
  16824. var _a = opts(_filepath, _options),
  16825. resolvedFilePath = _a[0],
  16826. processedOptions = _a[1];
  16827. var filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  16828. var files = readConfigFilesSync(filepaths);
  16829. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  16830. }
  16831. exports.parseSync = parseSync;
  16832. });
  16833. unwrapExports(src);
  16834. var src_1 = src.parseString;
  16835. var src_2 = src.parseFromFiles;
  16836. var src_3 = src.parseFromFilesSync;
  16837. var src_4 = src.parse;
  16838. var src_5 = src.parseSync;
  16839. var editorconfigToPrettier = editorConfigToPrettier;
  16840. function removeUnset(editorConfig) {
  16841. var result = {};
  16842. var keys = Object.keys(editorConfig);
  16843. for (var i = 0; i < keys.length; i++) {
  16844. var key = keys[i];
  16845. if (editorConfig[key] === "unset") {
  16846. continue;
  16847. }
  16848. result[key] = editorConfig[key];
  16849. }
  16850. return result;
  16851. }
  16852. function editorConfigToPrettier(editorConfig) {
  16853. if (!editorConfig) {
  16854. return null;
  16855. }
  16856. editorConfig = removeUnset(editorConfig);
  16857. if (Object.keys(editorConfig).length === 0) {
  16858. return null;
  16859. }
  16860. var result = {};
  16861. if (editorConfig.indent_style) {
  16862. result.useTabs = editorConfig.indent_style === "tab";
  16863. }
  16864. if (editorConfig.indent_size === "tab") {
  16865. result.useTabs = true;
  16866. }
  16867. if (result.useTabs && editorConfig.tab_width) {
  16868. result.tabWidth = editorConfig.tab_width;
  16869. } else if (editorConfig.indent_style === "space" && editorConfig.indent_size && editorConfig.indent_size !== "tab") {
  16870. result.tabWidth = editorConfig.indent_size;
  16871. } else if (editorConfig.tab_width !== undefined) {
  16872. result.tabWidth = editorConfig.tab_width;
  16873. }
  16874. if (editorConfig.max_line_length && editorConfig.max_line_length !== "off") {
  16875. result.printWidth = editorConfig.max_line_length;
  16876. }
  16877. if (editorConfig.quote_type === "single") {
  16878. result.singleQuote = true;
  16879. } else if (editorConfig.quote_type === "double") {
  16880. result.singleQuote = false;
  16881. }
  16882. if (["cr", "crlf", "lf"].indexOf(editorConfig.end_of_line) !== -1) {
  16883. result.endOfLine = editorConfig.end_of_line;
  16884. }
  16885. return result;
  16886. }
  16887. function markerExists(files, markers) {
  16888. return markers.some(function (marker) {
  16889. return files.some(function (file) {
  16890. return file === marker;
  16891. });
  16892. });
  16893. }
  16894. function traverseFolder(directory, levels, markers) {
  16895. var files = fs$1.readdirSync(directory);
  16896. if (levels === 0) {
  16897. return null;
  16898. } else if (markerExists(files, markers)) {
  16899. return directory;
  16900. } else {
  16901. return traverseFolder(path$2.resolve(directory, '..'), levels - 1, markers);
  16902. }
  16903. }
  16904. var findProjectRoot = function findRoot(dir, opts) {
  16905. if (!dir) throw new Error("Directory not defined");
  16906. opts = opts || {};
  16907. var levels = opts.maxDepth || findRoot.MAX_DEPTH;
  16908. var markers = opts.markers || findRoot.MARKERS;
  16909. return traverseFolder(dir, levels, markers);
  16910. };
  16911. var MAX_DEPTH = 9;
  16912. var MARKERS = ['.git', '.hg'];
  16913. findProjectRoot.MAX_DEPTH = MAX_DEPTH;
  16914. findProjectRoot.MARKERS = MARKERS;
  16915. var maybeParse = function maybeParse(filePath, config, parse) {
  16916. // findProjectRoot will throw an error if we pass a nonexistent directory to
  16917. // it, which is possible, for example, when the path is given via
  16918. // --stdin-filepath. So, first, traverse up until we find an existing
  16919. // directory.
  16920. var dirPath = path$2.dirname(path$2.resolve(filePath));
  16921. var fsRoot = path$2.parse(dirPath).root;
  16922. while (dirPath !== fsRoot && !fs$1.existsSync(dirPath)) {
  16923. dirPath = path$2.dirname(dirPath);
  16924. }
  16925. var root = findProjectRoot(dirPath);
  16926. return filePath && parse(filePath, {
  16927. root
  16928. });
  16929. };
  16930. var editorconfigAsyncNoCache = function editorconfigAsyncNoCache(filePath, config) {
  16931. return Promise.resolve(maybeParse(filePath, config, src.parse)).then(editorconfigToPrettier);
  16932. };
  16933. var editorconfigAsyncWithCache = mem_1(editorconfigAsyncNoCache);
  16934. var editorconfigSyncNoCache = function editorconfigSyncNoCache(filePath, config) {
  16935. return editorconfigToPrettier(maybeParse(filePath, config, src.parseSync));
  16936. };
  16937. var editorconfigSyncWithCache = mem_1(editorconfigSyncNoCache);
  16938. function getLoadFunction(opts) {
  16939. if (!opts.editorconfig) {
  16940. return function () {
  16941. return null;
  16942. };
  16943. }
  16944. if (opts.sync) {
  16945. return opts.cache ? editorconfigSyncWithCache : editorconfigSyncNoCache;
  16946. }
  16947. return opts.cache ? editorconfigAsyncWithCache : editorconfigAsyncNoCache;
  16948. }
  16949. function clearCache() {
  16950. mem_1.clear(editorconfigSyncWithCache);
  16951. mem_1.clear(editorconfigAsyncWithCache);
  16952. }
  16953. var resolveConfigEditorconfig = {
  16954. getLoadFunction,
  16955. clearCache
  16956. };
  16957. var ParserEND = 0x110000;
  16958. var ParserError =
  16959. /*#__PURE__*/
  16960. function (_Error) {
  16961. _inherits(ParserError, _Error);
  16962. /* istanbul ignore next */
  16963. function ParserError(msg, filename, linenumber) {
  16964. var _this;
  16965. _classCallCheck(this, ParserError);
  16966. _this = _possibleConstructorReturn(this, _getPrototypeOf(ParserError).call(this, '[ParserError] ' + msg, filename, linenumber));
  16967. _this.name = 'ParserError';
  16968. _this.code = 'ParserError';
  16969. if (Error.captureStackTrace) Error.captureStackTrace(_assertThisInitialized(_this), ParserError);
  16970. return _this;
  16971. }
  16972. return ParserError;
  16973. }(_wrapNativeSuper(Error));
  16974. var State = function State(parser) {
  16975. _classCallCheck(this, State);
  16976. this.parser = parser;
  16977. this.buf = '';
  16978. this.returned = null;
  16979. this.result = null;
  16980. this.resultTable = null;
  16981. this.resultArr = null;
  16982. };
  16983. var Parser =
  16984. /*#__PURE__*/
  16985. function () {
  16986. function Parser() {
  16987. _classCallCheck(this, Parser);
  16988. this.pos = 0;
  16989. this.col = 0;
  16990. this.line = 0;
  16991. this.obj = {};
  16992. this.ctx = this.obj;
  16993. this.stack = [];
  16994. this._buf = '';
  16995. this.char = null;
  16996. this.ii = 0;
  16997. this.state = new State(this.parseStart);
  16998. }
  16999. _createClass(Parser, [{
  17000. key: "parse",
  17001. value: function parse(str) {
  17002. /* istanbul ignore next */
  17003. if (str.length === 0 || str.length == null) return;
  17004. this._buf = String(str);
  17005. this.ii = -1;
  17006. this.char = -1;
  17007. var getNext;
  17008. while (getNext === false || this.nextChar()) {
  17009. getNext = this.runOne();
  17010. }
  17011. this._buf = null;
  17012. }
  17013. }, {
  17014. key: "nextChar",
  17015. value: function nextChar() {
  17016. if (this.char === 0x0A) {
  17017. ++this.line;
  17018. this.col = -1;
  17019. }
  17020. ++this.ii;
  17021. this.char = this._buf.codePointAt(this.ii);
  17022. ++this.pos;
  17023. ++this.col;
  17024. return this.haveBuffer();
  17025. }
  17026. }, {
  17027. key: "haveBuffer",
  17028. value: function haveBuffer() {
  17029. return this.ii < this._buf.length;
  17030. }
  17031. }, {
  17032. key: "runOne",
  17033. value: function runOne() {
  17034. return this.state.parser.call(this, this.state.returned);
  17035. }
  17036. }, {
  17037. key: "finish",
  17038. value: function finish() {
  17039. this.char = ParserEND;
  17040. var last;
  17041. do {
  17042. last = this.state.parser;
  17043. this.runOne();
  17044. } while (this.state.parser !== last);
  17045. this.ctx = null;
  17046. this.state = null;
  17047. this._buf = null;
  17048. return this.obj;
  17049. }
  17050. }, {
  17051. key: "next",
  17052. value: function next(fn) {
  17053. /* istanbul ignore next */
  17054. if (typeof fn !== 'function') throw new ParserError('Tried to set state to non-existent state: ' + JSON.stringify(fn));
  17055. this.state.parser = fn;
  17056. }
  17057. }, {
  17058. key: "goto",
  17059. value: function goto(fn) {
  17060. this.next(fn);
  17061. return this.runOne();
  17062. }
  17063. }, {
  17064. key: "call",
  17065. value: function call(fn, returnWith) {
  17066. if (returnWith) this.next(returnWith);
  17067. this.stack.push(this.state);
  17068. this.state = new State(fn);
  17069. }
  17070. }, {
  17071. key: "callNow",
  17072. value: function callNow(fn, returnWith) {
  17073. this.call(fn, returnWith);
  17074. return this.runOne();
  17075. }
  17076. }, {
  17077. key: "return",
  17078. value: function _return(value) {
  17079. /* istanbul ignore next */
  17080. if (this.stack.length === 0) throw this.error(new ParserError('Stack underflow'));
  17081. if (value === undefined) value = this.state.buf;
  17082. this.state = this.stack.pop();
  17083. this.state.returned = value;
  17084. }
  17085. }, {
  17086. key: "returnNow",
  17087. value: function returnNow(value) {
  17088. this.return(value);
  17089. return this.runOne();
  17090. }
  17091. }, {
  17092. key: "consume",
  17093. value: function consume() {
  17094. /* istanbul ignore next */
  17095. if (this.char === ParserEND) throw this.error(new ParserError('Unexpected end-of-buffer'));
  17096. this.state.buf += this._buf[this.ii];
  17097. }
  17098. }, {
  17099. key: "error",
  17100. value: function error(err) {
  17101. err.line = this.line;
  17102. err.col = this.col;
  17103. err.pos = this.pos;
  17104. return err;
  17105. }
  17106. /* istanbul ignore next */
  17107. }, {
  17108. key: "parseStart",
  17109. value: function parseStart() {
  17110. throw new ParserError('Must declare a parseStart method');
  17111. }
  17112. }]);
  17113. return Parser;
  17114. }();
  17115. Parser.END = ParserEND;
  17116. Parser.Error = ParserError;
  17117. var parser$1 = Parser;
  17118. var createDatetime = function createDatetime(value) {
  17119. var date = new Date(value);
  17120. /* istanbul ignore if */
  17121. if (isNaN(date)) {
  17122. throw new TypeError('Invalid Datetime');
  17123. } else {
  17124. return date;
  17125. }
  17126. };
  17127. var formatNum = function formatNum(d, num) {
  17128. num = String(num);
  17129. while (num.length < d) {
  17130. num = '0' + num;
  17131. }
  17132. return num;
  17133. };
  17134. var FloatingDateTime =
  17135. /*#__PURE__*/
  17136. function (_Date) {
  17137. _inherits(FloatingDateTime, _Date);
  17138. function FloatingDateTime(value) {
  17139. var _this;
  17140. _classCallCheck(this, FloatingDateTime);
  17141. _this = _possibleConstructorReturn(this, _getPrototypeOf(FloatingDateTime).call(this, value + 'Z'));
  17142. _this.isFloating = true;
  17143. return _this;
  17144. }
  17145. _createClass(FloatingDateTime, [{
  17146. key: "toISOString",
  17147. value: function toISOString() {
  17148. var date = `${this.getUTCFullYear()}-${formatNum(2, this.getUTCMonth() + 1)}-${formatNum(2, this.getUTCDate())}`;
  17149. var time = `${formatNum(2, this.getUTCHours())}:${formatNum(2, this.getUTCMinutes())}:${formatNum(2, this.getUTCSeconds())}.${formatNum(3, this.getUTCMilliseconds())}`;
  17150. return `${date}T${time}`;
  17151. }
  17152. }]);
  17153. return FloatingDateTime;
  17154. }(_wrapNativeSuper(Date));
  17155. var createDatetimeFloat = function createDatetimeFloat(value) {
  17156. var date = new FloatingDateTime(value);
  17157. /* istanbul ignore if */
  17158. if (isNaN(date)) {
  17159. throw new TypeError('Invalid Datetime');
  17160. } else {
  17161. return date;
  17162. }
  17163. };
  17164. var DateTime = global.Date;
  17165. var Date$1 =
  17166. /*#__PURE__*/
  17167. function (_DateTime) {
  17168. _inherits(Date, _DateTime);
  17169. function Date(value) {
  17170. var _this;
  17171. _classCallCheck(this, Date);
  17172. _this = _possibleConstructorReturn(this, _getPrototypeOf(Date).call(this, value));
  17173. _this.isDate = true;
  17174. return _this;
  17175. }
  17176. _createClass(Date, [{
  17177. key: "toISOString",
  17178. value: function toISOString() {
  17179. return `${this.getUTCFullYear()}-${formatNum(2, this.getUTCMonth() + 1)}-${formatNum(2, this.getUTCDate())}`;
  17180. }
  17181. }]);
  17182. return Date;
  17183. }(DateTime);
  17184. var createDate = function createDate(value) {
  17185. var date = new Date$1(value);
  17186. /* istanbul ignore if */
  17187. if (isNaN(date)) {
  17188. throw new TypeError('Invalid Datetime');
  17189. } else {
  17190. return date;
  17191. }
  17192. };
  17193. var Time =
  17194. /*#__PURE__*/
  17195. function (_Date) {
  17196. _inherits(Time, _Date);
  17197. function Time(value) {
  17198. var _this;
  17199. _classCallCheck(this, Time);
  17200. _this = _possibleConstructorReturn(this, _getPrototypeOf(Time).call(this, `0000-01-01T${value}Z`));
  17201. _this.isTime = true;
  17202. return _this;
  17203. }
  17204. _createClass(Time, [{
  17205. key: "toISOString",
  17206. value: function toISOString() {
  17207. return `${formatNum(2, this.getUTCHours())}:${formatNum(2, this.getUTCMinutes())}:${formatNum(2, this.getUTCSeconds())}.${formatNum(3, this.getUTCMilliseconds())}`;
  17208. }
  17209. }]);
  17210. return Time;
  17211. }(_wrapNativeSuper(Date));
  17212. var createTime = function createTime(value) {
  17213. var date = new Time(value);
  17214. /* istanbul ignore if */
  17215. if (isNaN(date)) {
  17216. throw new TypeError('Invalid Datetime');
  17217. } else {
  17218. return date;
  17219. }
  17220. };
  17221. /* eslint-disable no-new-wrappers, no-eval, camelcase, operator-linebreak */
  17222. var tomlParser = makeParserClass(parser$1);
  17223. var makeParserClass_1 = makeParserClass;
  17224. var TomlError =
  17225. /*#__PURE__*/
  17226. function (_Error) {
  17227. _inherits(TomlError, _Error);
  17228. function TomlError(msg) {
  17229. var _this;
  17230. _classCallCheck(this, TomlError);
  17231. _this = _possibleConstructorReturn(this, _getPrototypeOf(TomlError).call(this, msg));
  17232. _this.name = 'TomlError';
  17233. /* istanbul ignore next */
  17234. if (Error.captureStackTrace) Error.captureStackTrace(_assertThisInitialized(_this), TomlError);
  17235. _this.fromTOML = true;
  17236. _this.wrapped = null;
  17237. return _this;
  17238. }
  17239. return TomlError;
  17240. }(_wrapNativeSuper(Error));
  17241. TomlError.wrap = function (err) {
  17242. var terr = new TomlError(err.message);
  17243. terr.code = err.code;
  17244. terr.wrapped = err;
  17245. return terr;
  17246. };
  17247. var TomlError_1 = TomlError;
  17248. var CTRL_I = 0x09;
  17249. var CTRL_J = 0x0A;
  17250. var CTRL_M = 0x0D;
  17251. var CTRL_CHAR_BOUNDARY = 0x1F; // the last non-character in the latin1 region of unicode, except DEL
  17252. var CHAR_SP = 0x20;
  17253. var CHAR_QUOT = 0x22;
  17254. var CHAR_NUM = 0x23;
  17255. var CHAR_APOS = 0x27;
  17256. var CHAR_PLUS = 0x2B;
  17257. var CHAR_COMMA = 0x2C;
  17258. var CHAR_HYPHEN = 0x2D;
  17259. var CHAR_PERIOD = 0x2E;
  17260. var CHAR_0 = 0x30;
  17261. var CHAR_1 = 0x31;
  17262. var CHAR_7 = 0x37;
  17263. var CHAR_9 = 0x39;
  17264. var CHAR_COLON = 0x3A;
  17265. var CHAR_EQUALS = 0x3D;
  17266. var CHAR_A = 0x41;
  17267. var CHAR_E = 0x45;
  17268. var CHAR_F = 0x46;
  17269. var CHAR_T = 0x54;
  17270. var CHAR_U = 0x55;
  17271. var CHAR_Z = 0x5A;
  17272. var CHAR_LOWBAR = 0x5F;
  17273. var CHAR_a = 0x61;
  17274. var CHAR_b = 0x62;
  17275. var CHAR_e = 0x65;
  17276. var CHAR_f = 0x66;
  17277. var CHAR_i = 0x69;
  17278. var CHAR_l = 0x6C;
  17279. var CHAR_n = 0x6E;
  17280. var CHAR_o = 0x6F;
  17281. var CHAR_r = 0x72;
  17282. var CHAR_s = 0x73;
  17283. var CHAR_t = 0x74;
  17284. var CHAR_u = 0x75;
  17285. var CHAR_x = 0x78;
  17286. var CHAR_z = 0x7A;
  17287. var CHAR_LCUB = 0x7B;
  17288. var CHAR_RCUB = 0x7D;
  17289. var CHAR_LSQB = 0x5B;
  17290. var CHAR_BSOL = 0x5C;
  17291. var CHAR_RSQB = 0x5D;
  17292. var CHAR_DEL = 0x7F;
  17293. var SURROGATE_FIRST = 0xD800;
  17294. var SURROGATE_LAST = 0xDFFF;
  17295. var escapes = {
  17296. [CHAR_b]: '\u0008',
  17297. [CHAR_t]: '\u0009',
  17298. [CHAR_n]: '\u000A',
  17299. [CHAR_f]: '\u000C',
  17300. [CHAR_r]: '\u000D',
  17301. [CHAR_QUOT]: '\u0022',
  17302. [CHAR_BSOL]: '\u005C'
  17303. };
  17304. function isDigit(cp) {
  17305. return cp >= CHAR_0 && cp <= CHAR_9;
  17306. }
  17307. function isHexit(cp) {
  17308. return cp >= CHAR_A && cp <= CHAR_F || cp >= CHAR_a && cp <= CHAR_f || cp >= CHAR_0 && cp <= CHAR_9;
  17309. }
  17310. function isBit(cp) {
  17311. return cp === CHAR_1 || cp === CHAR_0;
  17312. }
  17313. function isOctit(cp) {
  17314. return cp >= CHAR_0 && cp <= CHAR_7;
  17315. }
  17316. function isAlphaNumQuoteHyphen(cp) {
  17317. 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;
  17318. }
  17319. function isAlphaNumHyphen(cp) {
  17320. 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;
  17321. }
  17322. var _type = Symbol('type');
  17323. var _declared = Symbol('declared');
  17324. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  17325. var defineProperty = Object.defineProperty;
  17326. var descriptor = {
  17327. configurable: true,
  17328. enumerable: true,
  17329. writable: true,
  17330. value: undefined
  17331. };
  17332. function hasKey(obj, key) {
  17333. if (hasOwnProperty$1.call(obj, key)) return true;
  17334. if (key === '__proto__') defineProperty(obj, '__proto__', descriptor);
  17335. return false;
  17336. }
  17337. var INLINE_TABLE = Symbol('inline-table');
  17338. function InlineTable() {
  17339. return Object.defineProperties({}, {
  17340. [_type]: {
  17341. value: INLINE_TABLE
  17342. }
  17343. });
  17344. }
  17345. function isInlineTable(obj) {
  17346. if (obj === null || typeof obj !== 'object') return false;
  17347. return obj[_type] === INLINE_TABLE;
  17348. }
  17349. var TABLE = Symbol('table');
  17350. function Table() {
  17351. return Object.defineProperties({}, {
  17352. [_type]: {
  17353. value: TABLE
  17354. },
  17355. [_declared]: {
  17356. value: false,
  17357. writable: true
  17358. }
  17359. });
  17360. }
  17361. function isTable(obj) {
  17362. if (obj === null || typeof obj !== 'object') return false;
  17363. return obj[_type] === TABLE;
  17364. }
  17365. var _contentType = Symbol('content-type');
  17366. var INLINE_LIST = Symbol('inline-list');
  17367. function InlineList(type) {
  17368. return Object.defineProperties([], {
  17369. [_type]: {
  17370. value: INLINE_LIST
  17371. },
  17372. [_contentType]: {
  17373. value: type
  17374. }
  17375. });
  17376. }
  17377. function isInlineList(obj) {
  17378. if (obj === null || typeof obj !== 'object') return false;
  17379. return obj[_type] === INLINE_LIST;
  17380. }
  17381. var LIST = Symbol('list');
  17382. function List() {
  17383. return Object.defineProperties([], {
  17384. [_type]: {
  17385. value: LIST
  17386. }
  17387. });
  17388. }
  17389. function isList(obj) {
  17390. if (obj === null || typeof obj !== 'object') return false;
  17391. return obj[_type] === LIST;
  17392. } // in an eval, to let bundlers not slurp in a util proxy
  17393. var _custom;
  17394. try {
  17395. var utilInspect = util$2.inspect;
  17396. _custom = utilInspect.custom;
  17397. } catch (_) {}
  17398. /* eval require not available in transpiled bundle */
  17399. /* istanbul ignore next */
  17400. var _inspect = _custom || 'inspect';
  17401. var BoxedBigInt =
  17402. /*#__PURE__*/
  17403. function () {
  17404. function BoxedBigInt(value) {
  17405. _classCallCheck(this, BoxedBigInt);
  17406. try {
  17407. this.value = global.BigInt.asIntN(64, value);
  17408. } catch (_) {
  17409. /* istanbul ignore next */
  17410. this.value = null;
  17411. }
  17412. Object.defineProperty(this, _type, {
  17413. value: INTEGER
  17414. });
  17415. }
  17416. _createClass(BoxedBigInt, [{
  17417. key: "isNaN",
  17418. value: function isNaN() {
  17419. return this.value === null;
  17420. }
  17421. /* istanbul ignore next */
  17422. }, {
  17423. key: "toString",
  17424. value: function toString() {
  17425. return String(this.value);
  17426. }
  17427. /* istanbul ignore next */
  17428. }, {
  17429. key: _inspect,
  17430. value: function value() {
  17431. return `[BigInt: ${this.toString()}]}`;
  17432. }
  17433. }, {
  17434. key: "valueOf",
  17435. value: function valueOf() {
  17436. return this.value;
  17437. }
  17438. }]);
  17439. return BoxedBigInt;
  17440. }();
  17441. var INTEGER = Symbol('integer');
  17442. function Integer(_value) {
  17443. var num = Number(_value); // -0 is a float thing, not an int thing
  17444. if (Object.is(num, -0)) num = 0;
  17445. /* istanbul ignore else */
  17446. if (global.BigInt && !Number.isSafeInteger(num)) {
  17447. return new BoxedBigInt(_value);
  17448. } else {
  17449. /* istanbul ignore next */
  17450. return Object.defineProperties(new Number(num), {
  17451. isNaN: {
  17452. value: function value() {
  17453. return isNaN(this);
  17454. }
  17455. },
  17456. [_type]: {
  17457. value: INTEGER
  17458. },
  17459. [_inspect]: {
  17460. value: function value() {
  17461. return `[Integer: ${_value}]`;
  17462. }
  17463. }
  17464. });
  17465. }
  17466. }
  17467. function isInteger(obj) {
  17468. if (obj === null || typeof obj !== 'object') return false;
  17469. return obj[_type] === INTEGER;
  17470. }
  17471. var FLOAT = Symbol('float');
  17472. function Float(_value2) {
  17473. /* istanbul ignore next */
  17474. return Object.defineProperties(new Number(_value2), {
  17475. [_type]: {
  17476. value: FLOAT
  17477. },
  17478. [_inspect]: {
  17479. value: function value() {
  17480. return `[Float: ${_value2}]`;
  17481. }
  17482. }
  17483. });
  17484. }
  17485. function isFloat(obj) {
  17486. if (obj === null || typeof obj !== 'object') return false;
  17487. return obj[_type] === FLOAT;
  17488. }
  17489. function tomlType(value) {
  17490. var type = typeof value;
  17491. if (type === 'object') {
  17492. /* istanbul ignore if */
  17493. if (value === null) return 'null';
  17494. if (value instanceof Date) return 'datetime';
  17495. /* istanbul ignore else */
  17496. if (_type in value) {
  17497. switch (value[_type]) {
  17498. case INLINE_TABLE:
  17499. return 'inline-table';
  17500. case INLINE_LIST:
  17501. return 'inline-list';
  17502. /* istanbul ignore next */
  17503. case TABLE:
  17504. return 'table';
  17505. /* istanbul ignore next */
  17506. case LIST:
  17507. return 'list';
  17508. case FLOAT:
  17509. return 'float';
  17510. case INTEGER:
  17511. return 'integer';
  17512. }
  17513. }
  17514. }
  17515. return type;
  17516. }
  17517. function makeParserClass(Parser) {
  17518. var TOMLParser =
  17519. /*#__PURE__*/
  17520. function (_Parser) {
  17521. _inherits(TOMLParser, _Parser);
  17522. function TOMLParser() {
  17523. var _this2;
  17524. _classCallCheck(this, TOMLParser);
  17525. _this2 = _possibleConstructorReturn(this, _getPrototypeOf(TOMLParser).call(this));
  17526. _this2.ctx = _this2.obj = Table();
  17527. return _this2;
  17528. }
  17529. /* MATCH HELPER */
  17530. _createClass(TOMLParser, [{
  17531. key: "atEndOfWord",
  17532. value: function atEndOfWord() {
  17533. return this.char === CHAR_NUM || this.char === CTRL_I || this.char === CHAR_SP || this.atEndOfLine();
  17534. }
  17535. }, {
  17536. key: "atEndOfLine",
  17537. value: function atEndOfLine() {
  17538. return this.char === Parser.END || this.char === CTRL_J || this.char === CTRL_M;
  17539. }
  17540. }, {
  17541. key: "parseStart",
  17542. value: function parseStart() {
  17543. if (this.char === Parser.END) {
  17544. return null;
  17545. } else if (this.char === CHAR_LSQB) {
  17546. return this.call(this.parseTableOrList);
  17547. } else if (this.char === CHAR_NUM) {
  17548. return this.call(this.parseComment);
  17549. } else if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
  17550. return null;
  17551. } else if (isAlphaNumQuoteHyphen(this.char)) {
  17552. return this.callNow(this.parseAssignStatement);
  17553. } else {
  17554. throw this.error(new TomlError(`Unknown character "${this.char}"`));
  17555. }
  17556. } // HELPER, this strips any whitespace and comments to the end of the line
  17557. // then RETURNS. Last state in a production.
  17558. }, {
  17559. key: "parseWhitespaceToEOL",
  17560. value: function parseWhitespaceToEOL() {
  17561. if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
  17562. return null;
  17563. } else if (this.char === CHAR_NUM) {
  17564. return this.goto(this.parseComment);
  17565. } else if (this.char === Parser.END || this.char === CTRL_J) {
  17566. return this.return();
  17567. } else {
  17568. throw this.error(new TomlError('Unexpected character, expected only whitespace or comments till end of line'));
  17569. }
  17570. }
  17571. /* ASSIGNMENT: key = value */
  17572. }, {
  17573. key: "parseAssignStatement",
  17574. value: function parseAssignStatement() {
  17575. return this.callNow(this.parseAssign, this.recordAssignStatement);
  17576. }
  17577. }, {
  17578. key: "recordAssignStatement",
  17579. value: function recordAssignStatement(kv) {
  17580. var target = this.ctx;
  17581. var finalKey = kv.key.pop();
  17582. var _iteratorNormalCompletion = true;
  17583. var _didIteratorError = false;
  17584. var _iteratorError = undefined;
  17585. try {
  17586. for (var _iterator = kv.key[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  17587. var kw = _step.value;
  17588. if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
  17589. throw this.error(new TomlError("Can't redefine existing key"));
  17590. }
  17591. target = target[kw] = target[kw] || Table();
  17592. }
  17593. } catch (err) {
  17594. _didIteratorError = true;
  17595. _iteratorError = err;
  17596. } finally {
  17597. try {
  17598. if (!_iteratorNormalCompletion && _iterator.return != null) {
  17599. _iterator.return();
  17600. }
  17601. } finally {
  17602. if (_didIteratorError) {
  17603. throw _iteratorError;
  17604. }
  17605. }
  17606. }
  17607. if (hasKey(target, finalKey)) {
  17608. throw this.error(new TomlError("Can't redefine existing key"));
  17609. } // unbox our numbers
  17610. if (isInteger(kv.value) || isFloat(kv.value)) {
  17611. target[finalKey] = kv.value.valueOf();
  17612. } else {
  17613. target[finalKey] = kv.value;
  17614. }
  17615. return this.goto(this.parseWhitespaceToEOL);
  17616. }
  17617. /* ASSSIGNMENT expression, key = value possibly inside an inline table */
  17618. }, {
  17619. key: "parseAssign",
  17620. value: function parseAssign() {
  17621. return this.callNow(this.parseKeyword, this.recordAssignKeyword);
  17622. }
  17623. }, {
  17624. key: "recordAssignKeyword",
  17625. value: function recordAssignKeyword(key) {
  17626. if (this.state.resultTable) {
  17627. this.state.resultTable.push(key);
  17628. } else {
  17629. this.state.resultTable = [key];
  17630. }
  17631. return this.goto(this.parseAssignKeywordPreDot);
  17632. }
  17633. }, {
  17634. key: "parseAssignKeywordPreDot",
  17635. value: function parseAssignKeywordPreDot() {
  17636. if (this.char === CHAR_PERIOD) {
  17637. return this.next(this.parseAssignKeywordPostDot);
  17638. } else if (this.char !== CHAR_SP && this.char !== CTRL_I) {
  17639. return this.goto(this.parseAssignEqual);
  17640. }
  17641. }
  17642. }, {
  17643. key: "parseAssignKeywordPostDot",
  17644. value: function parseAssignKeywordPostDot() {
  17645. if (this.char !== CHAR_SP && this.char !== CTRL_I) {
  17646. return this.callNow(this.parseKeyword, this.recordAssignKeyword);
  17647. }
  17648. }
  17649. }, {
  17650. key: "parseAssignEqual",
  17651. value: function parseAssignEqual() {
  17652. if (this.char === CHAR_EQUALS) {
  17653. return this.next(this.parseAssignPreValue);
  17654. } else {
  17655. throw this.error(new TomlError('Invalid character, expected "="'));
  17656. }
  17657. }
  17658. }, {
  17659. key: "parseAssignPreValue",
  17660. value: function parseAssignPreValue() {
  17661. if (this.char === CHAR_SP || this.char === CTRL_I) {
  17662. return null;
  17663. } else {
  17664. return this.callNow(this.parseValue, this.recordAssignValue);
  17665. }
  17666. }
  17667. }, {
  17668. key: "recordAssignValue",
  17669. value: function recordAssignValue(value) {
  17670. return this.returnNow({
  17671. key: this.state.resultTable,
  17672. value: value
  17673. });
  17674. }
  17675. /* COMMENTS: #...eol */
  17676. }, {
  17677. key: "parseComment",
  17678. value: function parseComment() {
  17679. do {
  17680. if (this.char === Parser.END || this.char === CTRL_J) {
  17681. return this.return();
  17682. }
  17683. } while (this.nextChar());
  17684. }
  17685. /* TABLES AND LISTS, [foo] and [[foo]] */
  17686. }, {
  17687. key: "parseTableOrList",
  17688. value: function parseTableOrList() {
  17689. if (this.char === CHAR_LSQB) {
  17690. this.next(this.parseList);
  17691. } else {
  17692. return this.goto(this.parseTable);
  17693. }
  17694. }
  17695. /* TABLE [foo.bar.baz] */
  17696. }, {
  17697. key: "parseTable",
  17698. value: function parseTable() {
  17699. this.ctx = this.obj;
  17700. return this.goto(this.parseTableNext);
  17701. }
  17702. }, {
  17703. key: "parseTableNext",
  17704. value: function parseTableNext() {
  17705. if (this.char === CHAR_SP || this.char === CTRL_I) {
  17706. return null;
  17707. } else {
  17708. return this.callNow(this.parseKeyword, this.parseTableMore);
  17709. }
  17710. }
  17711. }, {
  17712. key: "parseTableMore",
  17713. value: function parseTableMore(keyword) {
  17714. if (this.char === CHAR_SP || this.char === CTRL_I) {
  17715. return null;
  17716. } else if (this.char === CHAR_RSQB) {
  17717. if (hasKey(this.ctx, keyword) && (!isTable(this.ctx[keyword]) || this.ctx[keyword][_declared])) {
  17718. throw this.error(new TomlError("Can't redefine existing key"));
  17719. } else {
  17720. this.ctx = this.ctx[keyword] = this.ctx[keyword] || Table();
  17721. this.ctx[_declared] = true;
  17722. }
  17723. return this.next(this.parseWhitespaceToEOL);
  17724. } else if (this.char === CHAR_PERIOD) {
  17725. if (!hasKey(this.ctx, keyword)) {
  17726. this.ctx = this.ctx[keyword] = Table();
  17727. } else if (isTable(this.ctx[keyword])) {
  17728. this.ctx = this.ctx[keyword];
  17729. } else if (isList(this.ctx[keyword])) {
  17730. this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
  17731. } else {
  17732. throw this.error(new TomlError("Can't redefine existing key"));
  17733. }
  17734. return this.next(this.parseTableNext);
  17735. } else {
  17736. throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'));
  17737. }
  17738. }
  17739. /* LIST [[a.b.c]] */
  17740. }, {
  17741. key: "parseList",
  17742. value: function parseList() {
  17743. this.ctx = this.obj;
  17744. return this.goto(this.parseListNext);
  17745. }
  17746. }, {
  17747. key: "parseListNext",
  17748. value: function parseListNext() {
  17749. if (this.char === CHAR_SP || this.char === CTRL_I) {
  17750. return null;
  17751. } else {
  17752. return this.callNow(this.parseKeyword, this.parseListMore);
  17753. }
  17754. }
  17755. }, {
  17756. key: "parseListMore",
  17757. value: function parseListMore(keyword) {
  17758. if (this.char === CHAR_SP || this.char === CTRL_I) {
  17759. return null;
  17760. } else if (this.char === CHAR_RSQB) {
  17761. if (!hasKey(this.ctx, keyword)) {
  17762. this.ctx[keyword] = List();
  17763. }
  17764. if (isInlineList(this.ctx[keyword])) {
  17765. throw this.error(new TomlError("Can't extend an inline array"));
  17766. } else if (isList(this.ctx[keyword])) {
  17767. var next = Table();
  17768. this.ctx[keyword].push(next);
  17769. this.ctx = next;
  17770. } else {
  17771. throw this.error(new TomlError("Can't redefine an existing key"));
  17772. }
  17773. return this.next(this.parseListEnd);
  17774. } else if (this.char === CHAR_PERIOD) {
  17775. if (!hasKey(this.ctx, keyword)) {
  17776. this.ctx = this.ctx[keyword] = Table();
  17777. } else if (isInlineList(this.ctx[keyword])) {
  17778. throw this.error(new TomlError("Can't extend an inline array"));
  17779. } else if (isInlineTable(this.ctx[keyword])) {
  17780. throw this.error(new TomlError("Can't extend an inline table"));
  17781. } else if (isList(this.ctx[keyword])) {
  17782. this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
  17783. } else if (isTable(this.ctx[keyword])) {
  17784. this.ctx = this.ctx[keyword];
  17785. } else {
  17786. throw this.error(new TomlError("Can't redefine an existing key"));
  17787. }
  17788. return this.next(this.parseListNext);
  17789. } else {
  17790. throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'));
  17791. }
  17792. }
  17793. }, {
  17794. key: "parseListEnd",
  17795. value: function parseListEnd(keyword) {
  17796. if (this.char === CHAR_RSQB) {
  17797. return this.next(this.parseWhitespaceToEOL);
  17798. } else {
  17799. throw this.error(new TomlError('Unexpected character, expected whitespace, . or ]'));
  17800. }
  17801. }
  17802. /* VALUE string, number, boolean, inline list, inline object */
  17803. }, {
  17804. key: "parseValue",
  17805. value: function parseValue() {
  17806. if (this.char === Parser.END) {
  17807. throw this.error(new TomlError('Key without value'));
  17808. } else if (this.char === CHAR_QUOT) {
  17809. return this.next(this.parseDoubleString);
  17810. }
  17811. if (this.char === CHAR_APOS) {
  17812. return this.next(this.parseSingleString);
  17813. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  17814. return this.goto(this.parseNumberSign);
  17815. } else if (this.char === CHAR_i) {
  17816. return this.next(this.parseInf);
  17817. } else if (this.char === CHAR_n) {
  17818. return this.next(this.parseNan);
  17819. } else if (isDigit(this.char)) {
  17820. return this.goto(this.parseNumberOrDateTime);
  17821. } else if (this.char === CHAR_t || this.char === CHAR_f) {
  17822. return this.goto(this.parseBoolean);
  17823. } else if (this.char === CHAR_LSQB) {
  17824. return this.call(this.parseInlineList, this.recordValue);
  17825. } else if (this.char === CHAR_LCUB) {
  17826. return this.call(this.parseInlineTable, this.recordValue);
  17827. } else {
  17828. throw this.error(new TomlError('Unexpected character, expecting string, number, datetime, boolean, inline array or inline table'));
  17829. }
  17830. }
  17831. }, {
  17832. key: "recordValue",
  17833. value: function recordValue(value) {
  17834. return this.returnNow(value);
  17835. }
  17836. }, {
  17837. key: "parseInf",
  17838. value: function parseInf() {
  17839. if (this.char === CHAR_n) {
  17840. return this.next(this.parseInf2);
  17841. } else {
  17842. throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'));
  17843. }
  17844. }
  17845. }, {
  17846. key: "parseInf2",
  17847. value: function parseInf2() {
  17848. if (this.char === CHAR_f) {
  17849. if (this.state.buf === '-') {
  17850. return this.return(-Infinity);
  17851. } else {
  17852. return this.return(Infinity);
  17853. }
  17854. } else {
  17855. throw this.error(new TomlError('Unexpected character, expected "inf", "+inf" or "-inf"'));
  17856. }
  17857. }
  17858. }, {
  17859. key: "parseNan",
  17860. value: function parseNan() {
  17861. if (this.char === CHAR_a) {
  17862. return this.next(this.parseNan2);
  17863. } else {
  17864. throw this.error(new TomlError('Unexpected character, expected "nan"'));
  17865. }
  17866. }
  17867. }, {
  17868. key: "parseNan2",
  17869. value: function parseNan2() {
  17870. if (this.char === CHAR_n) {
  17871. return this.return(NaN);
  17872. } else {
  17873. throw this.error(new TomlError('Unexpected character, expected "nan"'));
  17874. }
  17875. }
  17876. /* KEYS, barewords or basic, literal, or dotted */
  17877. }, {
  17878. key: "parseKeyword",
  17879. value: function parseKeyword() {
  17880. if (this.char === CHAR_QUOT) {
  17881. return this.next(this.parseBasicString);
  17882. } else if (this.char === CHAR_APOS) {
  17883. return this.next(this.parseLiteralString);
  17884. } else {
  17885. return this.goto(this.parseBareKey);
  17886. }
  17887. }
  17888. /* KEYS: barewords */
  17889. }, {
  17890. key: "parseBareKey",
  17891. value: function parseBareKey() {
  17892. do {
  17893. if (this.char === Parser.END) {
  17894. throw this.error(new TomlError('Key ended without value'));
  17895. } else if (isAlphaNumHyphen(this.char)) {
  17896. this.consume();
  17897. } else if (this.state.buf.length === 0) {
  17898. throw this.error(new TomlError('Empty bare keys are not allowed'));
  17899. } else {
  17900. return this.returnNow();
  17901. }
  17902. } while (this.nextChar());
  17903. }
  17904. /* STRINGS, single quoted (literal) */
  17905. }, {
  17906. key: "parseSingleString",
  17907. value: function parseSingleString() {
  17908. if (this.char === CHAR_APOS) {
  17909. return this.next(this.parseLiteralMultiStringMaybe);
  17910. } else {
  17911. return this.goto(this.parseLiteralString);
  17912. }
  17913. }
  17914. }, {
  17915. key: "parseLiteralString",
  17916. value: function parseLiteralString() {
  17917. do {
  17918. if (this.char === CHAR_APOS) {
  17919. return this.return();
  17920. } else if (this.atEndOfLine()) {
  17921. throw this.error(new TomlError('Unterminated string'));
  17922. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I) {
  17923. throw this.errorControlCharInString();
  17924. } else {
  17925. this.consume();
  17926. }
  17927. } while (this.nextChar());
  17928. }
  17929. }, {
  17930. key: "parseLiteralMultiStringMaybe",
  17931. value: function parseLiteralMultiStringMaybe() {
  17932. if (this.char === CHAR_APOS) {
  17933. return this.next(this.parseLiteralMultiString);
  17934. } else {
  17935. return this.returnNow();
  17936. }
  17937. }
  17938. }, {
  17939. key: "parseLiteralMultiString",
  17940. value: function parseLiteralMultiString() {
  17941. if (this.char === CTRL_M) {
  17942. return null;
  17943. } else if (this.char === CTRL_J) {
  17944. return this.next(this.parseLiteralMultiStringContent);
  17945. } else {
  17946. return this.goto(this.parseLiteralMultiStringContent);
  17947. }
  17948. }
  17949. }, {
  17950. key: "parseLiteralMultiStringContent",
  17951. value: function parseLiteralMultiStringContent() {
  17952. do {
  17953. if (this.char === CHAR_APOS) {
  17954. return this.next(this.parseLiteralMultiEnd);
  17955. } else if (this.char === Parser.END) {
  17956. throw this.error(new TomlError('Unterminated multi-line string'));
  17957. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) {
  17958. throw this.errorControlCharInString();
  17959. } else {
  17960. this.consume();
  17961. }
  17962. } while (this.nextChar());
  17963. }
  17964. }, {
  17965. key: "parseLiteralMultiEnd",
  17966. value: function parseLiteralMultiEnd() {
  17967. if (this.char === CHAR_APOS) {
  17968. return this.next(this.parseLiteralMultiEnd2);
  17969. } else {
  17970. this.state.buf += "'";
  17971. return this.goto(this.parseLiteralMultiStringContent);
  17972. }
  17973. }
  17974. }, {
  17975. key: "parseLiteralMultiEnd2",
  17976. value: function parseLiteralMultiEnd2() {
  17977. if (this.char === CHAR_APOS) {
  17978. return this.return();
  17979. } else {
  17980. this.state.buf += "''";
  17981. return this.goto(this.parseLiteralMultiStringContent);
  17982. }
  17983. }
  17984. /* STRINGS double quoted */
  17985. }, {
  17986. key: "parseDoubleString",
  17987. value: function parseDoubleString() {
  17988. if (this.char === CHAR_QUOT) {
  17989. return this.next(this.parseMultiStringMaybe);
  17990. } else {
  17991. return this.goto(this.parseBasicString);
  17992. }
  17993. }
  17994. }, {
  17995. key: "parseBasicString",
  17996. value: function parseBasicString() {
  17997. do {
  17998. if (this.char === CHAR_BSOL) {
  17999. return this.call(this.parseEscape, this.recordEscapeReplacement);
  18000. } else if (this.char === CHAR_QUOT) {
  18001. return this.return();
  18002. } else if (this.atEndOfLine()) {
  18003. throw this.error(new TomlError('Unterminated string'));
  18004. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I) {
  18005. throw this.errorControlCharInString();
  18006. } else {
  18007. this.consume();
  18008. }
  18009. } while (this.nextChar());
  18010. }
  18011. }, {
  18012. key: "recordEscapeReplacement",
  18013. value: function recordEscapeReplacement(replacement) {
  18014. this.state.buf += replacement;
  18015. return this.goto(this.parseBasicString);
  18016. }
  18017. }, {
  18018. key: "parseMultiStringMaybe",
  18019. value: function parseMultiStringMaybe() {
  18020. if (this.char === CHAR_QUOT) {
  18021. return this.next(this.parseMultiString);
  18022. } else {
  18023. return this.returnNow();
  18024. }
  18025. }
  18026. }, {
  18027. key: "parseMultiString",
  18028. value: function parseMultiString() {
  18029. if (this.char === CTRL_M) {
  18030. return null;
  18031. } else if (this.char === CTRL_J) {
  18032. return this.next(this.parseMultiStringContent);
  18033. } else {
  18034. return this.goto(this.parseMultiStringContent);
  18035. }
  18036. }
  18037. }, {
  18038. key: "parseMultiStringContent",
  18039. value: function parseMultiStringContent() {
  18040. do {
  18041. if (this.char === CHAR_BSOL) {
  18042. return this.call(this.parseMultiEscape, this.recordMultiEscapeReplacement);
  18043. } else if (this.char === CHAR_QUOT) {
  18044. return this.next(this.parseMultiEnd);
  18045. } else if (this.char === Parser.END) {
  18046. throw this.error(new TomlError('Unterminated multi-line string'));
  18047. } else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) {
  18048. throw this.errorControlCharInString();
  18049. } else {
  18050. this.consume();
  18051. }
  18052. } while (this.nextChar());
  18053. }
  18054. }, {
  18055. key: "errorControlCharInString",
  18056. value: function errorControlCharInString() {
  18057. var displayCode = '\\u00';
  18058. if (this.char < 16) {
  18059. displayCode += '0';
  18060. }
  18061. displayCode += this.char.toString(16);
  18062. return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in strings, use ${displayCode} instead`));
  18063. }
  18064. }, {
  18065. key: "recordMultiEscapeReplacement",
  18066. value: function recordMultiEscapeReplacement(replacement) {
  18067. this.state.buf += replacement;
  18068. return this.goto(this.parseMultiStringContent);
  18069. }
  18070. }, {
  18071. key: "parseMultiEnd",
  18072. value: function parseMultiEnd() {
  18073. if (this.char === CHAR_QUOT) {
  18074. return this.next(this.parseMultiEnd2);
  18075. } else {
  18076. this.state.buf += '"';
  18077. return this.goto(this.parseMultiStringContent);
  18078. }
  18079. }
  18080. }, {
  18081. key: "parseMultiEnd2",
  18082. value: function parseMultiEnd2() {
  18083. if (this.char === CHAR_QUOT) {
  18084. return this.return();
  18085. } else {
  18086. this.state.buf += '""';
  18087. return this.goto(this.parseMultiStringContent);
  18088. }
  18089. }
  18090. }, {
  18091. key: "parseMultiEscape",
  18092. value: function parseMultiEscape() {
  18093. if (this.char === CTRL_M || this.char === CTRL_J) {
  18094. return this.next(this.parseMultiTrim);
  18095. } else if (this.char === CHAR_SP || this.char === CTRL_I) {
  18096. return this.next(this.parsePreMultiTrim);
  18097. } else {
  18098. return this.goto(this.parseEscape);
  18099. }
  18100. }
  18101. }, {
  18102. key: "parsePreMultiTrim",
  18103. value: function parsePreMultiTrim() {
  18104. if (this.char === CHAR_SP || this.char === CTRL_I) {
  18105. return null;
  18106. } else if (this.char === CTRL_M || this.char === CTRL_J) {
  18107. return this.next(this.parseMultiTrim);
  18108. } else {
  18109. throw this.error(new TomlError("Can't escape whitespace"));
  18110. }
  18111. }
  18112. }, {
  18113. key: "parseMultiTrim",
  18114. value: function parseMultiTrim() {
  18115. // explicitly whitespace here, END should follow the same path as chars
  18116. if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) {
  18117. return null;
  18118. } else {
  18119. return this.returnNow();
  18120. }
  18121. }
  18122. }, {
  18123. key: "parseEscape",
  18124. value: function parseEscape() {
  18125. if (this.char in escapes) {
  18126. return this.return(escapes[this.char]);
  18127. } else if (this.char === CHAR_u) {
  18128. return this.call(this.parseSmallUnicode, this.parseUnicodeReturn);
  18129. } else if (this.char === CHAR_U) {
  18130. return this.call(this.parseLargeUnicode, this.parseUnicodeReturn);
  18131. } else {
  18132. throw this.error(new TomlError('Unknown escape character: ' + this.char));
  18133. }
  18134. }
  18135. }, {
  18136. key: "parseUnicodeReturn",
  18137. value: function parseUnicodeReturn(char) {
  18138. try {
  18139. var codePoint = parseInt(char, 16);
  18140. if (codePoint >= SURROGATE_FIRST && codePoint <= SURROGATE_LAST) {
  18141. throw this.error(new TomlError('Invalid unicode, character in range 0xD800 - 0xDFFF is reserved'));
  18142. }
  18143. return this.returnNow(String.fromCodePoint(codePoint));
  18144. } catch (err) {
  18145. throw this.error(TomlError.wrap(err));
  18146. }
  18147. }
  18148. }, {
  18149. key: "parseSmallUnicode",
  18150. value: function parseSmallUnicode() {
  18151. if (!isHexit(this.char)) {
  18152. throw this.error(new TomlError('Invalid character in unicode sequence, expected hex'));
  18153. } else {
  18154. this.consume();
  18155. if (this.state.buf.length >= 4) return this.return();
  18156. }
  18157. }
  18158. }, {
  18159. key: "parseLargeUnicode",
  18160. value: function parseLargeUnicode() {
  18161. if (!isHexit(this.char)) {
  18162. throw this.error(new TomlError('Invalid character in unicode sequence, expected hex'));
  18163. } else {
  18164. this.consume();
  18165. if (this.state.buf.length >= 8) return this.return();
  18166. }
  18167. }
  18168. /* NUMBERS */
  18169. }, {
  18170. key: "parseNumberSign",
  18171. value: function parseNumberSign() {
  18172. this.consume();
  18173. return this.next(this.parseMaybeSignedInfOrNan);
  18174. }
  18175. }, {
  18176. key: "parseMaybeSignedInfOrNan",
  18177. value: function parseMaybeSignedInfOrNan() {
  18178. if (this.char === CHAR_i) {
  18179. return this.next(this.parseInf);
  18180. } else if (this.char === CHAR_n) {
  18181. return this.next(this.parseNan);
  18182. } else {
  18183. return this.callNow(this.parseNoUnder, this.parseNumberIntegerStart);
  18184. }
  18185. }
  18186. }, {
  18187. key: "parseNumberIntegerStart",
  18188. value: function parseNumberIntegerStart() {
  18189. if (this.char === CHAR_0) {
  18190. this.consume();
  18191. return this.next(this.parseNumberIntegerExponentOrDecimal);
  18192. } else {
  18193. return this.goto(this.parseNumberInteger);
  18194. }
  18195. }
  18196. }, {
  18197. key: "parseNumberIntegerExponentOrDecimal",
  18198. value: function parseNumberIntegerExponentOrDecimal() {
  18199. if (this.char === CHAR_PERIOD) {
  18200. this.consume();
  18201. return this.call(this.parseNoUnder, this.parseNumberFloat);
  18202. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  18203. this.consume();
  18204. return this.next(this.parseNumberExponentSign);
  18205. } else {
  18206. return this.returnNow(Integer(this.state.buf));
  18207. }
  18208. }
  18209. }, {
  18210. key: "parseNumberInteger",
  18211. value: function parseNumberInteger() {
  18212. if (isDigit(this.char)) {
  18213. this.consume();
  18214. } else if (this.char === CHAR_LOWBAR) {
  18215. return this.call(this.parseNoUnder);
  18216. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  18217. this.consume();
  18218. return this.next(this.parseNumberExponentSign);
  18219. } else if (this.char === CHAR_PERIOD) {
  18220. this.consume();
  18221. return this.call(this.parseNoUnder, this.parseNumberFloat);
  18222. } else {
  18223. var result = Integer(this.state.buf);
  18224. /* istanbul ignore if */
  18225. if (result.isNaN()) {
  18226. throw this.error(new TomlError('Invalid number'));
  18227. } else {
  18228. return this.returnNow(result);
  18229. }
  18230. }
  18231. }
  18232. }, {
  18233. key: "parseNoUnder",
  18234. value: function parseNoUnder() {
  18235. if (this.char === CHAR_LOWBAR || this.char === CHAR_PERIOD || this.char === CHAR_E || this.char === CHAR_e) {
  18236. throw this.error(new TomlError('Unexpected character, expected digit'));
  18237. } else if (this.atEndOfWord()) {
  18238. throw this.error(new TomlError('Incomplete number'));
  18239. }
  18240. return this.returnNow();
  18241. }
  18242. }, {
  18243. key: "parseNumberFloat",
  18244. value: function parseNumberFloat() {
  18245. if (this.char === CHAR_LOWBAR) {
  18246. return this.call(this.parseNoUnder, this.parseNumberFloat);
  18247. } else if (isDigit(this.char)) {
  18248. this.consume();
  18249. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  18250. this.consume();
  18251. return this.next(this.parseNumberExponentSign);
  18252. } else {
  18253. return this.returnNow(Float(this.state.buf));
  18254. }
  18255. }
  18256. }, {
  18257. key: "parseNumberExponentSign",
  18258. value: function parseNumberExponentSign() {
  18259. if (isDigit(this.char)) {
  18260. return this.goto(this.parseNumberExponent);
  18261. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  18262. this.consume();
  18263. this.call(this.parseNoUnder, this.parseNumberExponent);
  18264. } else {
  18265. throw this.error(new TomlError('Unexpected character, expected -, + or digit'));
  18266. }
  18267. }
  18268. }, {
  18269. key: "parseNumberExponent",
  18270. value: function parseNumberExponent() {
  18271. if (isDigit(this.char)) {
  18272. this.consume();
  18273. } else if (this.char === CHAR_LOWBAR) {
  18274. return this.call(this.parseNoUnder);
  18275. } else {
  18276. return this.returnNow(Float(this.state.buf));
  18277. }
  18278. }
  18279. /* NUMBERS or DATETIMES */
  18280. }, {
  18281. key: "parseNumberOrDateTime",
  18282. value: function parseNumberOrDateTime() {
  18283. if (this.char === CHAR_0) {
  18284. this.consume();
  18285. return this.next(this.parseNumberBaseOrDateTime);
  18286. } else {
  18287. return this.goto(this.parseNumberOrDateTimeOnly);
  18288. }
  18289. }
  18290. }, {
  18291. key: "parseNumberOrDateTimeOnly",
  18292. value: function parseNumberOrDateTimeOnly() {
  18293. // note, if two zeros are in a row then it MUST be a date
  18294. if (this.char === CHAR_LOWBAR) {
  18295. return this.call(this.parseNoUnder, this.parseNumberInteger);
  18296. } else if (isDigit(this.char)) {
  18297. this.consume();
  18298. if (this.state.buf.length > 4) this.next(this.parseNumberInteger);
  18299. } else if (this.char === CHAR_E || this.char === CHAR_e) {
  18300. this.consume();
  18301. return this.next(this.parseNumberExponentSign);
  18302. } else if (this.char === CHAR_PERIOD) {
  18303. this.consume();
  18304. return this.call(this.parseNoUnder, this.parseNumberFloat);
  18305. } else if (this.char === CHAR_HYPHEN) {
  18306. return this.goto(this.parseDateTime);
  18307. } else if (this.char === CHAR_COLON) {
  18308. return this.goto(this.parseOnlyTimeHour);
  18309. } else {
  18310. return this.returnNow(Integer(this.state.buf));
  18311. }
  18312. }
  18313. }, {
  18314. key: "parseDateTimeOnly",
  18315. value: function parseDateTimeOnly() {
  18316. if (this.state.buf.length < 4) {
  18317. if (isDigit(this.char)) {
  18318. return this.consume();
  18319. } else if (this.char === CHAR_COLON) {
  18320. return this.goto(this.parseOnlyTimeHour);
  18321. } else {
  18322. throw this.error(new TomlError('Expected digit while parsing year part of a date'));
  18323. }
  18324. } else {
  18325. if (this.char === CHAR_HYPHEN) {
  18326. return this.goto(this.parseDateTime);
  18327. } else {
  18328. throw this.error(new TomlError('Expected hyphen (-) while parsing year part of date'));
  18329. }
  18330. }
  18331. }
  18332. }, {
  18333. key: "parseNumberBaseOrDateTime",
  18334. value: function parseNumberBaseOrDateTime() {
  18335. if (this.char === CHAR_b) {
  18336. this.consume();
  18337. return this.call(this.parseNoUnder, this.parseIntegerBin);
  18338. } else if (this.char === CHAR_o) {
  18339. this.consume();
  18340. return this.call(this.parseNoUnder, this.parseIntegerOct);
  18341. } else if (this.char === CHAR_x) {
  18342. this.consume();
  18343. return this.call(this.parseNoUnder, this.parseIntegerHex);
  18344. } else if (this.char === CHAR_PERIOD) {
  18345. return this.goto(this.parseNumberInteger);
  18346. } else if (isDigit(this.char)) {
  18347. return this.goto(this.parseDateTimeOnly);
  18348. } else {
  18349. return this.returnNow(Integer(this.state.buf));
  18350. }
  18351. }
  18352. }, {
  18353. key: "parseIntegerHex",
  18354. value: function parseIntegerHex() {
  18355. if (isHexit(this.char)) {
  18356. this.consume();
  18357. } else if (this.char === CHAR_LOWBAR) {
  18358. return this.call(this.parseNoUnder);
  18359. } else {
  18360. var result = Integer(this.state.buf);
  18361. /* istanbul ignore if */
  18362. if (result.isNaN()) {
  18363. throw this.error(new TomlError('Invalid number'));
  18364. } else {
  18365. return this.returnNow(result);
  18366. }
  18367. }
  18368. }
  18369. }, {
  18370. key: "parseIntegerOct",
  18371. value: function parseIntegerOct() {
  18372. if (isOctit(this.char)) {
  18373. this.consume();
  18374. } else if (this.char === CHAR_LOWBAR) {
  18375. return this.call(this.parseNoUnder);
  18376. } else {
  18377. var result = Integer(this.state.buf);
  18378. /* istanbul ignore if */
  18379. if (result.isNaN()) {
  18380. throw this.error(new TomlError('Invalid number'));
  18381. } else {
  18382. return this.returnNow(result);
  18383. }
  18384. }
  18385. }
  18386. }, {
  18387. key: "parseIntegerBin",
  18388. value: function parseIntegerBin() {
  18389. if (isBit(this.char)) {
  18390. this.consume();
  18391. } else if (this.char === CHAR_LOWBAR) {
  18392. return this.call(this.parseNoUnder);
  18393. } else {
  18394. var result = Integer(this.state.buf);
  18395. /* istanbul ignore if */
  18396. if (result.isNaN()) {
  18397. throw this.error(new TomlError('Invalid number'));
  18398. } else {
  18399. return this.returnNow(result);
  18400. }
  18401. }
  18402. }
  18403. /* DATETIME */
  18404. }, {
  18405. key: "parseDateTime",
  18406. value: function parseDateTime() {
  18407. // we enter here having just consumed the year and about to consume the hyphen
  18408. if (this.state.buf.length < 4) {
  18409. throw this.error(new TomlError('Years less than 1000 must be zero padded to four characters'));
  18410. }
  18411. this.state.result = this.state.buf;
  18412. this.state.buf = '';
  18413. return this.next(this.parseDateMonth);
  18414. }
  18415. }, {
  18416. key: "parseDateMonth",
  18417. value: function parseDateMonth() {
  18418. if (this.char === CHAR_HYPHEN) {
  18419. if (this.state.buf.length < 2) {
  18420. throw this.error(new TomlError('Months less than 10 must be zero padded to two characters'));
  18421. }
  18422. this.state.result += '-' + this.state.buf;
  18423. this.state.buf = '';
  18424. return this.next(this.parseDateDay);
  18425. } else if (isDigit(this.char)) {
  18426. this.consume();
  18427. } else {
  18428. throw this.error(new TomlError('Incomplete datetime'));
  18429. }
  18430. }
  18431. }, {
  18432. key: "parseDateDay",
  18433. value: function parseDateDay() {
  18434. if (this.char === CHAR_T || this.char === CHAR_SP) {
  18435. if (this.state.buf.length < 2) {
  18436. throw this.error(new TomlError('Days less than 10 must be zero padded to two characters'));
  18437. }
  18438. this.state.result += '-' + this.state.buf;
  18439. this.state.buf = '';
  18440. return this.next(this.parseStartTimeHour);
  18441. } else if (this.atEndOfWord()) {
  18442. return this.return(createDate(this.state.result + '-' + this.state.buf));
  18443. } else if (isDigit(this.char)) {
  18444. this.consume();
  18445. } else {
  18446. throw this.error(new TomlError('Incomplete datetime'));
  18447. }
  18448. }
  18449. }, {
  18450. key: "parseStartTimeHour",
  18451. value: function parseStartTimeHour() {
  18452. if (this.atEndOfWord()) {
  18453. return this.returnNow(createDate(this.state.result));
  18454. } else {
  18455. return this.goto(this.parseTimeHour);
  18456. }
  18457. }
  18458. }, {
  18459. key: "parseTimeHour",
  18460. value: function parseTimeHour() {
  18461. if (this.char === CHAR_COLON) {
  18462. if (this.state.buf.length < 2) {
  18463. throw this.error(new TomlError('Hours less than 10 must be zero padded to two characters'));
  18464. }
  18465. this.state.result += 'T' + this.state.buf;
  18466. this.state.buf = '';
  18467. return this.next(this.parseTimeMin);
  18468. } else if (isDigit(this.char)) {
  18469. this.consume();
  18470. } else {
  18471. throw this.error(new TomlError('Incomplete datetime'));
  18472. }
  18473. }
  18474. }, {
  18475. key: "parseTimeMin",
  18476. value: function parseTimeMin() {
  18477. if (this.state.buf.length < 2 && isDigit(this.char)) {
  18478. this.consume();
  18479. } else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
  18480. this.state.result += ':' + this.state.buf;
  18481. this.state.buf = '';
  18482. return this.next(this.parseTimeSec);
  18483. } else {
  18484. throw this.error(new TomlError('Incomplete datetime'));
  18485. }
  18486. }
  18487. }, {
  18488. key: "parseTimeSec",
  18489. value: function parseTimeSec() {
  18490. if (isDigit(this.char)) {
  18491. this.consume();
  18492. if (this.state.buf.length === 2) {
  18493. this.state.result += ':' + this.state.buf;
  18494. this.state.buf = '';
  18495. return this.next(this.parseTimeZoneOrFraction);
  18496. }
  18497. } else {
  18498. throw this.error(new TomlError('Incomplete datetime'));
  18499. }
  18500. }
  18501. }, {
  18502. key: "parseOnlyTimeHour",
  18503. value: function parseOnlyTimeHour() {
  18504. /* istanbul ignore else */
  18505. if (this.char === CHAR_COLON) {
  18506. if (this.state.buf.length < 2) {
  18507. throw this.error(new TomlError('Hours less than 10 must be zero padded to two characters'));
  18508. }
  18509. this.state.result = this.state.buf;
  18510. this.state.buf = '';
  18511. return this.next(this.parseOnlyTimeMin);
  18512. } else {
  18513. throw this.error(new TomlError('Incomplete time'));
  18514. }
  18515. }
  18516. }, {
  18517. key: "parseOnlyTimeMin",
  18518. value: function parseOnlyTimeMin() {
  18519. if (this.state.buf.length < 2 && isDigit(this.char)) {
  18520. this.consume();
  18521. } else if (this.state.buf.length === 2 && this.char === CHAR_COLON) {
  18522. this.state.result += ':' + this.state.buf;
  18523. this.state.buf = '';
  18524. return this.next(this.parseOnlyTimeSec);
  18525. } else {
  18526. throw this.error(new TomlError('Incomplete time'));
  18527. }
  18528. }
  18529. }, {
  18530. key: "parseOnlyTimeSec",
  18531. value: function parseOnlyTimeSec() {
  18532. if (isDigit(this.char)) {
  18533. this.consume();
  18534. if (this.state.buf.length === 2) {
  18535. return this.next(this.parseOnlyTimeFractionMaybe);
  18536. }
  18537. } else {
  18538. throw this.error(new TomlError('Incomplete time'));
  18539. }
  18540. }
  18541. }, {
  18542. key: "parseOnlyTimeFractionMaybe",
  18543. value: function parseOnlyTimeFractionMaybe() {
  18544. this.state.result += ':' + this.state.buf;
  18545. if (this.char === CHAR_PERIOD) {
  18546. this.state.buf = '';
  18547. this.next(this.parseOnlyTimeFraction);
  18548. } else {
  18549. return this.return(createTime(this.state.result));
  18550. }
  18551. }
  18552. }, {
  18553. key: "parseOnlyTimeFraction",
  18554. value: function parseOnlyTimeFraction() {
  18555. if (isDigit(this.char)) {
  18556. this.consume();
  18557. } else if (this.atEndOfWord()) {
  18558. if (this.state.buf.length === 0) throw this.error(new TomlError('Expected digit in milliseconds'));
  18559. return this.returnNow(createTime(this.state.result + '.' + this.state.buf));
  18560. } else {
  18561. throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'));
  18562. }
  18563. }
  18564. }, {
  18565. key: "parseTimeZoneOrFraction",
  18566. value: function parseTimeZoneOrFraction() {
  18567. if (this.char === CHAR_PERIOD) {
  18568. this.consume();
  18569. this.next(this.parseDateTimeFraction);
  18570. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  18571. this.consume();
  18572. this.next(this.parseTimeZoneHour);
  18573. } else if (this.char === CHAR_Z) {
  18574. this.consume();
  18575. return this.return(createDatetime(this.state.result + this.state.buf));
  18576. } else if (this.atEndOfWord()) {
  18577. return this.returnNow(createDatetimeFloat(this.state.result + this.state.buf));
  18578. } else {
  18579. throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'));
  18580. }
  18581. }
  18582. }, {
  18583. key: "parseDateTimeFraction",
  18584. value: function parseDateTimeFraction() {
  18585. if (isDigit(this.char)) {
  18586. this.consume();
  18587. } else if (this.state.buf.length === 1) {
  18588. throw this.error(new TomlError('Expected digit in milliseconds'));
  18589. } else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) {
  18590. this.consume();
  18591. this.next(this.parseTimeZoneHour);
  18592. } else if (this.char === CHAR_Z) {
  18593. this.consume();
  18594. return this.return(createDatetime(this.state.result + this.state.buf));
  18595. } else if (this.atEndOfWord()) {
  18596. return this.returnNow(createDatetimeFloat(this.state.result + this.state.buf));
  18597. } else {
  18598. throw this.error(new TomlError('Unexpected character in datetime, expected period (.), minus (-), plus (+) or Z'));
  18599. }
  18600. }
  18601. }, {
  18602. key: "parseTimeZoneHour",
  18603. value: function parseTimeZoneHour() {
  18604. if (isDigit(this.char)) {
  18605. this.consume(); // FIXME: No more regexps
  18606. if (/\d\d$/.test(this.state.buf)) return this.next(this.parseTimeZoneSep);
  18607. } else {
  18608. throw this.error(new TomlError('Unexpected character in datetime, expected digit'));
  18609. }
  18610. }
  18611. }, {
  18612. key: "parseTimeZoneSep",
  18613. value: function parseTimeZoneSep() {
  18614. if (this.char === CHAR_COLON) {
  18615. this.consume();
  18616. this.next(this.parseTimeZoneMin);
  18617. } else {
  18618. throw this.error(new TomlError('Unexpected character in datetime, expected colon'));
  18619. }
  18620. }
  18621. }, {
  18622. key: "parseTimeZoneMin",
  18623. value: function parseTimeZoneMin() {
  18624. if (isDigit(this.char)) {
  18625. this.consume();
  18626. if (/\d\d$/.test(this.state.buf)) return this.return(createDatetime(this.state.result + this.state.buf));
  18627. } else {
  18628. throw this.error(new TomlError('Unexpected character in datetime, expected digit'));
  18629. }
  18630. }
  18631. /* BOOLEAN */
  18632. }, {
  18633. key: "parseBoolean",
  18634. value: function parseBoolean() {
  18635. /* istanbul ignore else */
  18636. if (this.char === CHAR_t) {
  18637. this.consume();
  18638. return this.next(this.parseTrue_r);
  18639. } else if (this.char === CHAR_f) {
  18640. this.consume();
  18641. return this.next(this.parseFalse_a);
  18642. }
  18643. }
  18644. }, {
  18645. key: "parseTrue_r",
  18646. value: function parseTrue_r() {
  18647. if (this.char === CHAR_r) {
  18648. this.consume();
  18649. return this.next(this.parseTrue_u);
  18650. } else {
  18651. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  18652. }
  18653. }
  18654. }, {
  18655. key: "parseTrue_u",
  18656. value: function parseTrue_u() {
  18657. if (this.char === CHAR_u) {
  18658. this.consume();
  18659. return this.next(this.parseTrue_e);
  18660. } else {
  18661. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  18662. }
  18663. }
  18664. }, {
  18665. key: "parseTrue_e",
  18666. value: function parseTrue_e() {
  18667. if (this.char === CHAR_e) {
  18668. return this.return(true);
  18669. } else {
  18670. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  18671. }
  18672. }
  18673. }, {
  18674. key: "parseFalse_a",
  18675. value: function parseFalse_a() {
  18676. if (this.char === CHAR_a) {
  18677. this.consume();
  18678. return this.next(this.parseFalse_l);
  18679. } else {
  18680. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  18681. }
  18682. }
  18683. }, {
  18684. key: "parseFalse_l",
  18685. value: function parseFalse_l() {
  18686. if (this.char === CHAR_l) {
  18687. this.consume();
  18688. return this.next(this.parseFalse_s);
  18689. } else {
  18690. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  18691. }
  18692. }
  18693. }, {
  18694. key: "parseFalse_s",
  18695. value: function parseFalse_s() {
  18696. if (this.char === CHAR_s) {
  18697. this.consume();
  18698. return this.next(this.parseFalse_e);
  18699. } else {
  18700. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  18701. }
  18702. }
  18703. }, {
  18704. key: "parseFalse_e",
  18705. value: function parseFalse_e() {
  18706. if (this.char === CHAR_e) {
  18707. return this.return(false);
  18708. } else {
  18709. throw this.error(new TomlError('Invalid boolean, expected true or false'));
  18710. }
  18711. }
  18712. /* INLINE LISTS */
  18713. }, {
  18714. key: "parseInlineList",
  18715. value: function parseInlineList() {
  18716. if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) {
  18717. return null;
  18718. } else if (this.char === Parser.END) {
  18719. throw this.error(new TomlError('Unterminated inline array'));
  18720. } else if (this.char === CHAR_NUM) {
  18721. return this.call(this.parseComment);
  18722. } else if (this.char === CHAR_RSQB) {
  18723. return this.return(this.state.resultArr || InlineList());
  18724. } else {
  18725. return this.callNow(this.parseValue, this.recordInlineListValue);
  18726. }
  18727. }
  18728. }, {
  18729. key: "recordInlineListValue",
  18730. value: function recordInlineListValue(value) {
  18731. if (this.state.resultArr) {
  18732. var listType = this.state.resultArr[_contentType];
  18733. var valueType = tomlType(value);
  18734. if (listType !== valueType) {
  18735. throw this.error(new TomlError(`Inline lists must be a single type, not a mix of ${listType} and ${valueType}`));
  18736. }
  18737. } else {
  18738. this.state.resultArr = InlineList(tomlType(value));
  18739. }
  18740. if (isFloat(value) || isInteger(value)) {
  18741. // unbox now that we've verified they're ok
  18742. this.state.resultArr.push(value.valueOf());
  18743. } else {
  18744. this.state.resultArr.push(value);
  18745. }
  18746. return this.goto(this.parseInlineListNext);
  18747. }
  18748. }, {
  18749. key: "parseInlineListNext",
  18750. value: function parseInlineListNext() {
  18751. if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) {
  18752. return null;
  18753. } else if (this.char === CHAR_NUM) {
  18754. return this.call(this.parseComment);
  18755. } else if (this.char === CHAR_COMMA) {
  18756. return this.next(this.parseInlineList);
  18757. } else if (this.char === CHAR_RSQB) {
  18758. return this.goto(this.parseInlineList);
  18759. } else {
  18760. throw this.error(new TomlError('Invalid character, expected whitespace, comma (,) or close bracket (])'));
  18761. }
  18762. }
  18763. /* INLINE TABLE */
  18764. }, {
  18765. key: "parseInlineTable",
  18766. value: function parseInlineTable() {
  18767. if (this.char === CHAR_SP || this.char === CTRL_I) {
  18768. return null;
  18769. } else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
  18770. throw this.error(new TomlError('Unterminated inline array'));
  18771. } else if (this.char === CHAR_RCUB) {
  18772. return this.return(this.state.resultTable || InlineTable());
  18773. } else {
  18774. if (!this.state.resultTable) this.state.resultTable = InlineTable();
  18775. return this.callNow(this.parseAssign, this.recordInlineTableValue);
  18776. }
  18777. }
  18778. }, {
  18779. key: "recordInlineTableValue",
  18780. value: function recordInlineTableValue(kv) {
  18781. var target = this.state.resultTable;
  18782. var finalKey = kv.key.pop();
  18783. var _iteratorNormalCompletion2 = true;
  18784. var _didIteratorError2 = false;
  18785. var _iteratorError2 = undefined;
  18786. try {
  18787. for (var _iterator2 = kv.key[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  18788. var kw = _step2.value;
  18789. if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
  18790. throw this.error(new TomlError("Can't redefine existing key"));
  18791. }
  18792. target = target[kw] = target[kw] || Table();
  18793. }
  18794. } catch (err) {
  18795. _didIteratorError2 = true;
  18796. _iteratorError2 = err;
  18797. } finally {
  18798. try {
  18799. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  18800. _iterator2.return();
  18801. }
  18802. } finally {
  18803. if (_didIteratorError2) {
  18804. throw _iteratorError2;
  18805. }
  18806. }
  18807. }
  18808. if (hasKey(target, finalKey)) {
  18809. throw this.error(new TomlError("Can't redefine existing key"));
  18810. }
  18811. if (isInteger(kv.value) || isFloat(kv.value)) {
  18812. target[finalKey] = kv.value.valueOf();
  18813. } else {
  18814. target[finalKey] = kv.value;
  18815. }
  18816. return this.goto(this.parseInlineTableNext);
  18817. }
  18818. }, {
  18819. key: "parseInlineTableNext",
  18820. value: function parseInlineTableNext() {
  18821. if (this.char === CHAR_SP || this.char === CTRL_I) {
  18822. return null;
  18823. } else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
  18824. throw this.error(new TomlError('Unterminated inline array'));
  18825. } else if (this.char === CHAR_COMMA) {
  18826. return this.next(this.parseInlineTable);
  18827. } else if (this.char === CHAR_RCUB) {
  18828. return this.goto(this.parseInlineTable);
  18829. } else {
  18830. throw this.error(new TomlError('Invalid character, expected whitespace, comma (,) or close bracket (])'));
  18831. }
  18832. }
  18833. }]);
  18834. return TOMLParser;
  18835. }(Parser);
  18836. return TOMLParser;
  18837. }
  18838. tomlParser.makeParserClass = makeParserClass_1;
  18839. tomlParser.TomlError = TomlError_1;
  18840. var parsePrettyError = prettyError;
  18841. function prettyError(err, buf) {
  18842. /* istanbul ignore if */
  18843. if (err.pos == null || err.line == null) return err;
  18844. var msg = err.message;
  18845. msg += ` at row ${err.line + 1}, col ${err.col + 1}, pos ${err.pos}:\n`;
  18846. /* istanbul ignore else */
  18847. if (buf && buf.split) {
  18848. var lines = buf.split(/\n/);
  18849. var lineNumWidth = String(Math.min(lines.length, err.line + 3)).length;
  18850. var linePadding = ' ';
  18851. while (linePadding.length < lineNumWidth) {
  18852. linePadding += ' ';
  18853. }
  18854. for (var ii = Math.max(0, err.line - 1); ii < Math.min(lines.length, err.line + 2); ++ii) {
  18855. var lineNum = String(ii + 1);
  18856. if (lineNum.length < lineNumWidth) lineNum = ' ' + lineNum;
  18857. if (err.line === ii) {
  18858. msg += lineNum + '> ' + lines[ii] + '\n';
  18859. msg += linePadding + ' ';
  18860. for (var hh = 0; hh < err.col; ++hh) {
  18861. msg += ' ';
  18862. }
  18863. msg += '^\n';
  18864. } else {
  18865. msg += lineNum + ': ' + lines[ii] + '\n';
  18866. }
  18867. }
  18868. }
  18869. err.message = msg + '\n';
  18870. return err;
  18871. }
  18872. var parseString_1 = parseString;
  18873. function parseString(str) {
  18874. if (global.Buffer && global.Buffer.isBuffer(str)) {
  18875. str = str.toString('utf8');
  18876. }
  18877. var parser = new tomlParser();
  18878. try {
  18879. parser.parse(str);
  18880. return parser.finish();
  18881. } catch (err) {
  18882. throw parsePrettyError(err, str);
  18883. }
  18884. }
  18885. var loadToml = function loadToml(filePath, content) {
  18886. try {
  18887. return parseString_1(content);
  18888. } catch (error) {
  18889. error.message = `TOML Error in ${filePath}:\n${error.message}`;
  18890. throw error;
  18891. }
  18892. };
  18893. var getExplorerMemoized = mem_1(function (opts) {
  18894. var explorer = thirdParty.cosmiconfig("prettier", {
  18895. cache: opts.cache,
  18896. transform: function transform(result) {
  18897. if (result && result.config) {
  18898. if (typeof result.config === "string") {
  18899. var modulePath = resolve.sync(result.config, {
  18900. basedir: path$2.dirname(result.filepath)
  18901. });
  18902. result.config = require(modulePath);
  18903. }
  18904. if (typeof result.config !== "object") {
  18905. throw new Error(`Config is only allowed to be an object, ` + `but received ${typeof result.config} in "${result.filepath}"`);
  18906. }
  18907. delete result.config.$schema;
  18908. }
  18909. return result;
  18910. },
  18911. searchPlaces: ["package.json", ".prettierrc", ".prettierrc.json", ".prettierrc.yaml", ".prettierrc.yml", ".prettierrc.js", "prettier.config.js", ".prettierrc.toml"],
  18912. loaders: {
  18913. ".toml": loadToml
  18914. }
  18915. });
  18916. var _load = opts.sync ? explorer.loadSync : explorer.load;
  18917. var search = opts.sync ? explorer.searchSync : explorer.search;
  18918. return {
  18919. // cosmiconfig v4 interface
  18920. load: function load(searchPath, configPath) {
  18921. return configPath ? _load(configPath) : search(searchPath);
  18922. }
  18923. };
  18924. });
  18925. /** @param {{ cache: boolean, sync: boolean }} opts */
  18926. function getLoadFunction$1(opts) {
  18927. // Normalize opts before passing to a memoized function
  18928. opts = Object.assign({
  18929. sync: false,
  18930. cache: false
  18931. }, opts);
  18932. return getExplorerMemoized(opts).load;
  18933. }
  18934. function _resolveConfig(filePath, opts, sync) {
  18935. opts = Object.assign({
  18936. useCache: true
  18937. }, opts);
  18938. var loadOpts = {
  18939. cache: !!opts.useCache,
  18940. sync: !!sync,
  18941. editorconfig: !!opts.editorconfig
  18942. };
  18943. var load = getLoadFunction$1(loadOpts);
  18944. var loadEditorConfig = resolveConfigEditorconfig.getLoadFunction(loadOpts);
  18945. var arr = [load, loadEditorConfig].map(function (l) {
  18946. return l(filePath, opts.config);
  18947. });
  18948. var unwrapAndMerge = function unwrapAndMerge(arr) {
  18949. var result = arr[0];
  18950. var editorConfigured = arr[1];
  18951. var merged = Object.assign({}, editorConfigured, mergeOverrides(Object.assign({}, result), filePath));
  18952. ["plugins", "pluginSearchDirs"].forEach(function (optionName) {
  18953. if (Array.isArray(merged[optionName])) {
  18954. merged[optionName] = merged[optionName].map(function (value) {
  18955. return typeof value === "string" && value.startsWith(".") // relative path
  18956. ? path$2.resolve(path$2.dirname(result.filepath), value) : value;
  18957. });
  18958. }
  18959. });
  18960. if (!result && !editorConfigured) {
  18961. return null;
  18962. }
  18963. return merged;
  18964. };
  18965. if (loadOpts.sync) {
  18966. return unwrapAndMerge(arr);
  18967. }
  18968. return Promise.all(arr).then(unwrapAndMerge);
  18969. }
  18970. var resolveConfig = function resolveConfig(filePath, opts) {
  18971. return _resolveConfig(filePath, opts, false);
  18972. };
  18973. resolveConfig.sync = function (filePath, opts) {
  18974. return _resolveConfig(filePath, opts, true);
  18975. };
  18976. function clearCache$1() {
  18977. mem_1.clear(getExplorerMemoized);
  18978. resolveConfigEditorconfig.clearCache();
  18979. }
  18980. function resolveConfigFile(filePath) {
  18981. var load = getLoadFunction$1({
  18982. sync: false
  18983. });
  18984. return load(filePath).then(function (result) {
  18985. return result ? result.filepath : null;
  18986. });
  18987. }
  18988. resolveConfigFile.sync = function (filePath) {
  18989. var load = getLoadFunction$1({
  18990. sync: true
  18991. });
  18992. var result = load(filePath);
  18993. return result ? result.filepath : null;
  18994. };
  18995. function mergeOverrides(configResult, filePath) {
  18996. var options = Object.assign({}, configResult.config);
  18997. if (filePath && options.overrides) {
  18998. var relativeFilePath = path$2.relative(path$2.dirname(configResult.filepath), filePath);
  18999. var _iteratorNormalCompletion = true;
  19000. var _didIteratorError = false;
  19001. var _iteratorError = undefined;
  19002. try {
  19003. for (var _iterator = options.overrides[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  19004. var override = _step.value;
  19005. if (pathMatchesGlobs(relativeFilePath, override.files, override.excludeFiles)) {
  19006. Object.assign(options, override.options);
  19007. }
  19008. }
  19009. } catch (err) {
  19010. _didIteratorError = true;
  19011. _iteratorError = err;
  19012. } finally {
  19013. try {
  19014. if (!_iteratorNormalCompletion && _iterator.return != null) {
  19015. _iterator.return();
  19016. }
  19017. } finally {
  19018. if (_didIteratorError) {
  19019. throw _iteratorError;
  19020. }
  19021. }
  19022. }
  19023. }
  19024. delete options.overrides;
  19025. return options;
  19026. } // Based on eslint: https://github.com/eslint/eslint/blob/master/lib/config/config-ops.js
  19027. function pathMatchesGlobs(filePath, patterns, excludedPatterns) {
  19028. var patternList = [].concat(patterns);
  19029. var excludedPatternList = [].concat(excludedPatterns || []);
  19030. var opts = {
  19031. matchBase: true,
  19032. dot: true
  19033. };
  19034. return patternList.some(function (pattern) {
  19035. return minimatch_1(filePath, pattern, opts);
  19036. }) && !excludedPatternList.some(function (excludedPattern) {
  19037. return minimatch_1(filePath, excludedPattern, opts);
  19038. });
  19039. }
  19040. var resolveConfig_1 = {
  19041. resolveConfig,
  19042. resolveConfigFile,
  19043. clearCache: clearCache$1
  19044. };
  19045. /**
  19046. * @typedef {{ ignorePath?: string, withNodeModules?: boolean, plugins: object }} FileInfoOptions
  19047. * @typedef {{ ignored: boolean, inferredParser: string | null }} FileInfoResult
  19048. */
  19049. /**
  19050. * @param {string} filePath
  19051. * @param {FileInfoOptions} opts
  19052. * @returns {Promise<FileInfoResult>}
  19053. *
  19054. * Please note that prettier.getFileInfo() expects opts.plugins to be an array of paths,
  19055. * not an object. A transformation from this array to an object is automatically done
  19056. * internally by the method wrapper. See withPlugins() in index.js.
  19057. */
  19058. function getFileInfo(filePath, opts) {
  19059. if (typeof filePath !== "string") {
  19060. return Promise.reject(new TypeError(`expect \`filePath\` to be a string, got \`${typeof filePath}\``));
  19061. }
  19062. return createIgnorer_1(opts.ignorePath, opts.withNodeModules).then(function (ignorer) {
  19063. return _getFileInfo({
  19064. ignorer,
  19065. filePath: normalizeFilePath(filePath, opts.ignorePath),
  19066. plugins: opts.plugins,
  19067. resolveConfig: opts.resolveConfig,
  19068. sync: false
  19069. });
  19070. });
  19071. }
  19072. /**
  19073. * @param {string} filePath
  19074. * @param {FileInfoOptions} opts
  19075. * @returns {FileInfoResult}
  19076. */
  19077. getFileInfo.sync = function (filePath, opts) {
  19078. if (typeof filePath !== "string") {
  19079. throw new TypeError(`expect \`filePath\` to be a string, got \`${typeof filePath}\``);
  19080. }
  19081. var ignorer = createIgnorer_1.sync(opts.ignorePath, opts.withNodeModules);
  19082. return _getFileInfo({
  19083. ignorer,
  19084. filePath: normalizeFilePath(filePath, opts.ignorePath),
  19085. plugins: opts.plugins,
  19086. resolveConfig: opts.resolveConfig,
  19087. sync: true
  19088. });
  19089. };
  19090. function _getFileInfo(_ref) {
  19091. var ignorer = _ref.ignorer,
  19092. filePath = _ref.filePath,
  19093. plugins = _ref.plugins,
  19094. _ref$resolveConfig = _ref.resolveConfig,
  19095. resolveConfig = _ref$resolveConfig === void 0 ? false : _ref$resolveConfig,
  19096. _ref$sync = _ref.sync,
  19097. sync = _ref$sync === void 0 ? false : _ref$sync;
  19098. var fileInfo = {
  19099. ignored: ignorer.ignores(filePath),
  19100. inferredParser: options$1.inferParser(filePath, plugins) || null
  19101. };
  19102. if (!fileInfo.inferredParser && resolveConfig) {
  19103. if (!sync) {
  19104. return resolveConfig_1.resolveConfig(filePath).then(function (resolvedConfig) {
  19105. if (resolvedConfig && resolvedConfig.parser) {
  19106. fileInfo.inferredParser = resolvedConfig.parser;
  19107. }
  19108. return fileInfo;
  19109. });
  19110. }
  19111. var resolvedConfig = resolveConfig_1.resolveConfig.sync(filePath);
  19112. if (resolvedConfig && resolvedConfig.parser) {
  19113. fileInfo.inferredParser = resolvedConfig.parser;
  19114. }
  19115. }
  19116. return fileInfo;
  19117. }
  19118. function normalizeFilePath(filePath, ignorePath) {
  19119. return ignorePath ? path$2.relative(path$2.dirname(ignorePath), filePath) : filePath;
  19120. }
  19121. var getFileInfo_1 = getFileInfo;
  19122. var lodash_uniqby = createCommonjsModule(function (module, exports) {
  19123. /**
  19124. * lodash (Custom Build) <https://lodash.com/>
  19125. * Build: `lodash modularize exports="npm" -o ./`
  19126. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  19127. * Released under MIT license <https://lodash.com/license>
  19128. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  19129. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  19130. */
  19131. /** Used as the size to enable large array optimizations. */
  19132. var LARGE_ARRAY_SIZE = 200;
  19133. /** Used as the `TypeError` message for "Functions" methods. */
  19134. var FUNC_ERROR_TEXT = 'Expected a function';
  19135. /** Used to stand-in for `undefined` hash values. */
  19136. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  19137. /** Used to compose bitmasks for comparison styles. */
  19138. var UNORDERED_COMPARE_FLAG = 1,
  19139. PARTIAL_COMPARE_FLAG = 2;
  19140. /** Used as references for various `Number` constants. */
  19141. var INFINITY = 1 / 0,
  19142. MAX_SAFE_INTEGER = 9007199254740991;
  19143. /** `Object#toString` result references. */
  19144. var argsTag = '[object Arguments]',
  19145. arrayTag = '[object Array]',
  19146. boolTag = '[object Boolean]',
  19147. dateTag = '[object Date]',
  19148. errorTag = '[object Error]',
  19149. funcTag = '[object Function]',
  19150. genTag = '[object GeneratorFunction]',
  19151. mapTag = '[object Map]',
  19152. numberTag = '[object Number]',
  19153. objectTag = '[object Object]',
  19154. promiseTag = '[object Promise]',
  19155. regexpTag = '[object RegExp]',
  19156. setTag = '[object Set]',
  19157. stringTag = '[object String]',
  19158. symbolTag = '[object Symbol]',
  19159. weakMapTag = '[object WeakMap]';
  19160. var arrayBufferTag = '[object ArrayBuffer]',
  19161. dataViewTag = '[object DataView]',
  19162. float32Tag = '[object Float32Array]',
  19163. float64Tag = '[object Float64Array]',
  19164. int8Tag = '[object Int8Array]',
  19165. int16Tag = '[object Int16Array]',
  19166. int32Tag = '[object Int32Array]',
  19167. uint8Tag = '[object Uint8Array]',
  19168. uint8ClampedTag = '[object Uint8ClampedArray]',
  19169. uint16Tag = '[object Uint16Array]',
  19170. uint32Tag = '[object Uint32Array]';
  19171. /** Used to match property names within property paths. */
  19172. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  19173. reIsPlainProp = /^\w*$/,
  19174. reLeadingDot = /^\./,
  19175. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  19176. /**
  19177. * Used to match `RegExp`
  19178. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  19179. */
  19180. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  19181. /** Used to match backslashes in property paths. */
  19182. var reEscapeChar = /\\(\\)?/g;
  19183. /** Used to detect host constructors (Safari). */
  19184. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  19185. /** Used to detect unsigned integer values. */
  19186. var reIsUint = /^(?:0|[1-9]\d*)$/;
  19187. /** Used to identify `toStringTag` values of typed arrays. */
  19188. var typedArrayTags = {};
  19189. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  19190. typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag] = typedArrayTags[mapTag] = typedArrayTags[numberTag] = typedArrayTags[objectTag] = typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  19191. /** Detect free variable `global` from Node.js. */
  19192. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  19193. /** Detect free variable `self`. */
  19194. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  19195. /** Used as a reference to the global object. */
  19196. var root = freeGlobal || freeSelf || Function('return this')();
  19197. /** Detect free variable `exports`. */
  19198. var freeExports = exports && !exports.nodeType && exports;
  19199. /** Detect free variable `module`. */
  19200. var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
  19201. /** Detect the popular CommonJS extension `module.exports`. */
  19202. var moduleExports = freeModule && freeModule.exports === freeExports;
  19203. /** Detect free variable `process` from Node.js. */
  19204. var freeProcess = moduleExports && freeGlobal.process;
  19205. /** Used to access faster Node.js helpers. */
  19206. var nodeUtil = function () {
  19207. try {
  19208. return freeProcess && freeProcess.binding('util');
  19209. } catch (e) {}
  19210. }();
  19211. /* Node.js helper references. */
  19212. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  19213. /**
  19214. * A specialized version of `_.includes` for arrays without support for
  19215. * specifying an index to search from.
  19216. *
  19217. * @private
  19218. * @param {Array} [array] The array to inspect.
  19219. * @param {*} target The value to search for.
  19220. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  19221. */
  19222. function arrayIncludes(array, value) {
  19223. var length = array ? array.length : 0;
  19224. return !!length && baseIndexOf(array, value, 0) > -1;
  19225. }
  19226. /**
  19227. * This function is like `arrayIncludes` except that it accepts a comparator.
  19228. *
  19229. * @private
  19230. * @param {Array} [array] The array to inspect.
  19231. * @param {*} target The value to search for.
  19232. * @param {Function} comparator The comparator invoked per element.
  19233. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  19234. */
  19235. function arrayIncludesWith(array, value, comparator) {
  19236. var index = -1,
  19237. length = array ? array.length : 0;
  19238. while (++index < length) {
  19239. if (comparator(value, array[index])) {
  19240. return true;
  19241. }
  19242. }
  19243. return false;
  19244. }
  19245. /**
  19246. * A specialized version of `_.some` for arrays without support for iteratee
  19247. * shorthands.
  19248. *
  19249. * @private
  19250. * @param {Array} [array] The array to iterate over.
  19251. * @param {Function} predicate The function invoked per iteration.
  19252. * @returns {boolean} Returns `true` if any element passes the predicate check,
  19253. * else `false`.
  19254. */
  19255. function arraySome(array, predicate) {
  19256. var index = -1,
  19257. length = array ? array.length : 0;
  19258. while (++index < length) {
  19259. if (predicate(array[index], index, array)) {
  19260. return true;
  19261. }
  19262. }
  19263. return false;
  19264. }
  19265. /**
  19266. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  19267. * support for iteratee shorthands.
  19268. *
  19269. * @private
  19270. * @param {Array} array The array to inspect.
  19271. * @param {Function} predicate The function invoked per iteration.
  19272. * @param {number} fromIndex The index to search from.
  19273. * @param {boolean} [fromRight] Specify iterating from right to left.
  19274. * @returns {number} Returns the index of the matched value, else `-1`.
  19275. */
  19276. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  19277. var length = array.length,
  19278. index = fromIndex + (fromRight ? 1 : -1);
  19279. while (fromRight ? index-- : ++index < length) {
  19280. if (predicate(array[index], index, array)) {
  19281. return index;
  19282. }
  19283. }
  19284. return -1;
  19285. }
  19286. /**
  19287. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  19288. *
  19289. * @private
  19290. * @param {Array} array The array to inspect.
  19291. * @param {*} value The value to search for.
  19292. * @param {number} fromIndex The index to search from.
  19293. * @returns {number} Returns the index of the matched value, else `-1`.
  19294. */
  19295. function baseIndexOf(array, value, fromIndex) {
  19296. if (value !== value) {
  19297. return baseFindIndex(array, baseIsNaN, fromIndex);
  19298. }
  19299. var index = fromIndex - 1,
  19300. length = array.length;
  19301. while (++index < length) {
  19302. if (array[index] === value) {
  19303. return index;
  19304. }
  19305. }
  19306. return -1;
  19307. }
  19308. /**
  19309. * The base implementation of `_.isNaN` without support for number objects.
  19310. *
  19311. * @private
  19312. * @param {*} value The value to check.
  19313. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  19314. */
  19315. function baseIsNaN(value) {
  19316. return value !== value;
  19317. }
  19318. /**
  19319. * The base implementation of `_.property` without support for deep paths.
  19320. *
  19321. * @private
  19322. * @param {string} key The key of the property to get.
  19323. * @returns {Function} Returns the new accessor function.
  19324. */
  19325. function baseProperty(key) {
  19326. return function (object) {
  19327. return object == null ? undefined : object[key];
  19328. };
  19329. }
  19330. /**
  19331. * The base implementation of `_.times` without support for iteratee shorthands
  19332. * or max array length checks.
  19333. *
  19334. * @private
  19335. * @param {number} n The number of times to invoke `iteratee`.
  19336. * @param {Function} iteratee The function invoked per iteration.
  19337. * @returns {Array} Returns the array of results.
  19338. */
  19339. function baseTimes(n, iteratee) {
  19340. var index = -1,
  19341. result = Array(n);
  19342. while (++index < n) {
  19343. result[index] = iteratee(index);
  19344. }
  19345. return result;
  19346. }
  19347. /**
  19348. * The base implementation of `_.unary` without support for storing metadata.
  19349. *
  19350. * @private
  19351. * @param {Function} func The function to cap arguments for.
  19352. * @returns {Function} Returns the new capped function.
  19353. */
  19354. function baseUnary(func) {
  19355. return function (value) {
  19356. return func(value);
  19357. };
  19358. }
  19359. /**
  19360. * Checks if a cache value for `key` exists.
  19361. *
  19362. * @private
  19363. * @param {Object} cache The cache to query.
  19364. * @param {string} key The key of the entry to check.
  19365. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  19366. */
  19367. function cacheHas(cache, key) {
  19368. return cache.has(key);
  19369. }
  19370. /**
  19371. * Gets the value at `key` of `object`.
  19372. *
  19373. * @private
  19374. * @param {Object} [object] The object to query.
  19375. * @param {string} key The key of the property to get.
  19376. * @returns {*} Returns the property value.
  19377. */
  19378. function getValue(object, key) {
  19379. return object == null ? undefined : object[key];
  19380. }
  19381. /**
  19382. * Checks if `value` is a host object in IE < 9.
  19383. *
  19384. * @private
  19385. * @param {*} value The value to check.
  19386. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  19387. */
  19388. function isHostObject(value) {
  19389. // Many host objects are `Object` objects that can coerce to strings
  19390. // despite having improperly defined `toString` methods.
  19391. var result = false;
  19392. if (value != null && typeof value.toString != 'function') {
  19393. try {
  19394. result = !!(value + '');
  19395. } catch (e) {}
  19396. }
  19397. return result;
  19398. }
  19399. /**
  19400. * Converts `map` to its key-value pairs.
  19401. *
  19402. * @private
  19403. * @param {Object} map The map to convert.
  19404. * @returns {Array} Returns the key-value pairs.
  19405. */
  19406. function mapToArray(map) {
  19407. var index = -1,
  19408. result = Array(map.size);
  19409. map.forEach(function (value, key) {
  19410. result[++index] = [key, value];
  19411. });
  19412. return result;
  19413. }
  19414. /**
  19415. * Creates a unary function that invokes `func` with its argument transformed.
  19416. *
  19417. * @private
  19418. * @param {Function} func The function to wrap.
  19419. * @param {Function} transform The argument transform.
  19420. * @returns {Function} Returns the new function.
  19421. */
  19422. function overArg(func, transform) {
  19423. return function (arg) {
  19424. return func(transform(arg));
  19425. };
  19426. }
  19427. /**
  19428. * Converts `set` to an array of its values.
  19429. *
  19430. * @private
  19431. * @param {Object} set The set to convert.
  19432. * @returns {Array} Returns the values.
  19433. */
  19434. function setToArray(set) {
  19435. var index = -1,
  19436. result = Array(set.size);
  19437. set.forEach(function (value) {
  19438. result[++index] = value;
  19439. });
  19440. return result;
  19441. }
  19442. /** Used for built-in method references. */
  19443. var arrayProto = Array.prototype,
  19444. funcProto = Function.prototype,
  19445. objectProto = Object.prototype;
  19446. /** Used to detect overreaching core-js shims. */
  19447. var coreJsData = root['__core-js_shared__'];
  19448. /** Used to detect methods masquerading as native. */
  19449. var maskSrcKey = function () {
  19450. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  19451. return uid ? 'Symbol(src)_1.' + uid : '';
  19452. }();
  19453. /** Used to resolve the decompiled source of functions. */
  19454. var funcToString = funcProto.toString;
  19455. /** Used to check objects for own properties. */
  19456. var hasOwnProperty = objectProto.hasOwnProperty;
  19457. /**
  19458. * Used to resolve the
  19459. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  19460. * of values.
  19461. */
  19462. var objectToString = objectProto.toString;
  19463. /** Used to detect if a method is native. */
  19464. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  19465. /** Built-in value references. */
  19466. var Symbol = root.Symbol,
  19467. Uint8Array = root.Uint8Array,
  19468. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  19469. splice = arrayProto.splice;
  19470. /* Built-in method references for those with the same name as other `lodash` methods. */
  19471. var nativeKeys = overArg(Object.keys, Object);
  19472. /* Built-in method references that are verified to be native. */
  19473. var DataView = getNative(root, 'DataView'),
  19474. Map = getNative(root, 'Map'),
  19475. Promise = getNative(root, 'Promise'),
  19476. Set = getNative(root, 'Set'),
  19477. WeakMap = getNative(root, 'WeakMap'),
  19478. nativeCreate = getNative(Object, 'create');
  19479. /** Used to detect maps, sets, and weakmaps. */
  19480. var dataViewCtorString = toSource(DataView),
  19481. mapCtorString = toSource(Map),
  19482. promiseCtorString = toSource(Promise),
  19483. setCtorString = toSource(Set),
  19484. weakMapCtorString = toSource(WeakMap);
  19485. /** Used to convert symbols to primitives and strings. */
  19486. var symbolProto = Symbol ? Symbol.prototype : undefined,
  19487. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  19488. symbolToString = symbolProto ? symbolProto.toString : undefined;
  19489. /**
  19490. * Creates a hash object.
  19491. *
  19492. * @private
  19493. * @constructor
  19494. * @param {Array} [entries] The key-value pairs to cache.
  19495. */
  19496. function Hash(entries) {
  19497. var index = -1,
  19498. length = entries ? entries.length : 0;
  19499. this.clear();
  19500. while (++index < length) {
  19501. var entry = entries[index];
  19502. this.set(entry[0], entry[1]);
  19503. }
  19504. }
  19505. /**
  19506. * Removes all key-value entries from the hash.
  19507. *
  19508. * @private
  19509. * @name clear
  19510. * @memberOf Hash
  19511. */
  19512. function hashClear() {
  19513. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  19514. }
  19515. /**
  19516. * Removes `key` and its value from the hash.
  19517. *
  19518. * @private
  19519. * @name delete
  19520. * @memberOf Hash
  19521. * @param {Object} hash The hash to modify.
  19522. * @param {string} key The key of the value to remove.
  19523. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  19524. */
  19525. function hashDelete(key) {
  19526. return this.has(key) && delete this.__data__[key];
  19527. }
  19528. /**
  19529. * Gets the hash value for `key`.
  19530. *
  19531. * @private
  19532. * @name get
  19533. * @memberOf Hash
  19534. * @param {string} key The key of the value to get.
  19535. * @returns {*} Returns the entry value.
  19536. */
  19537. function hashGet(key) {
  19538. var data = this.__data__;
  19539. if (nativeCreate) {
  19540. var result = data[key];
  19541. return result === HASH_UNDEFINED ? undefined : result;
  19542. }
  19543. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  19544. }
  19545. /**
  19546. * Checks if a hash value for `key` exists.
  19547. *
  19548. * @private
  19549. * @name has
  19550. * @memberOf Hash
  19551. * @param {string} key The key of the entry to check.
  19552. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  19553. */
  19554. function hashHas(key) {
  19555. var data = this.__data__;
  19556. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  19557. }
  19558. /**
  19559. * Sets the hash `key` to `value`.
  19560. *
  19561. * @private
  19562. * @name set
  19563. * @memberOf Hash
  19564. * @param {string} key The key of the value to set.
  19565. * @param {*} value The value to set.
  19566. * @returns {Object} Returns the hash instance.
  19567. */
  19568. function hashSet(key, value) {
  19569. var data = this.__data__;
  19570. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  19571. return this;
  19572. } // Add methods to `Hash`.
  19573. Hash.prototype.clear = hashClear;
  19574. Hash.prototype['delete'] = hashDelete;
  19575. Hash.prototype.get = hashGet;
  19576. Hash.prototype.has = hashHas;
  19577. Hash.prototype.set = hashSet;
  19578. /**
  19579. * Creates an list cache object.
  19580. *
  19581. * @private
  19582. * @constructor
  19583. * @param {Array} [entries] The key-value pairs to cache.
  19584. */
  19585. function ListCache(entries) {
  19586. var index = -1,
  19587. length = entries ? entries.length : 0;
  19588. this.clear();
  19589. while (++index < length) {
  19590. var entry = entries[index];
  19591. this.set(entry[0], entry[1]);
  19592. }
  19593. }
  19594. /**
  19595. * Removes all key-value entries from the list cache.
  19596. *
  19597. * @private
  19598. * @name clear
  19599. * @memberOf ListCache
  19600. */
  19601. function listCacheClear() {
  19602. this.__data__ = [];
  19603. }
  19604. /**
  19605. * Removes `key` and its value from the list cache.
  19606. *
  19607. * @private
  19608. * @name delete
  19609. * @memberOf ListCache
  19610. * @param {string} key The key of the value to remove.
  19611. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  19612. */
  19613. function listCacheDelete(key) {
  19614. var data = this.__data__,
  19615. index = assocIndexOf(data, key);
  19616. if (index < 0) {
  19617. return false;
  19618. }
  19619. var lastIndex = data.length - 1;
  19620. if (index == lastIndex) {
  19621. data.pop();
  19622. } else {
  19623. splice.call(data, index, 1);
  19624. }
  19625. return true;
  19626. }
  19627. /**
  19628. * Gets the list cache value for `key`.
  19629. *
  19630. * @private
  19631. * @name get
  19632. * @memberOf ListCache
  19633. * @param {string} key The key of the value to get.
  19634. * @returns {*} Returns the entry value.
  19635. */
  19636. function listCacheGet(key) {
  19637. var data = this.__data__,
  19638. index = assocIndexOf(data, key);
  19639. return index < 0 ? undefined : data[index][1];
  19640. }
  19641. /**
  19642. * Checks if a list cache value for `key` exists.
  19643. *
  19644. * @private
  19645. * @name has
  19646. * @memberOf ListCache
  19647. * @param {string} key The key of the entry to check.
  19648. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  19649. */
  19650. function listCacheHas(key) {
  19651. return assocIndexOf(this.__data__, key) > -1;
  19652. }
  19653. /**
  19654. * Sets the list cache `key` to `value`.
  19655. *
  19656. * @private
  19657. * @name set
  19658. * @memberOf ListCache
  19659. * @param {string} key The key of the value to set.
  19660. * @param {*} value The value to set.
  19661. * @returns {Object} Returns the list cache instance.
  19662. */
  19663. function listCacheSet(key, value) {
  19664. var data = this.__data__,
  19665. index = assocIndexOf(data, key);
  19666. if (index < 0) {
  19667. data.push([key, value]);
  19668. } else {
  19669. data[index][1] = value;
  19670. }
  19671. return this;
  19672. } // Add methods to `ListCache`.
  19673. ListCache.prototype.clear = listCacheClear;
  19674. ListCache.prototype['delete'] = listCacheDelete;
  19675. ListCache.prototype.get = listCacheGet;
  19676. ListCache.prototype.has = listCacheHas;
  19677. ListCache.prototype.set = listCacheSet;
  19678. /**
  19679. * Creates a map cache object to store key-value pairs.
  19680. *
  19681. * @private
  19682. * @constructor
  19683. * @param {Array} [entries] The key-value pairs to cache.
  19684. */
  19685. function MapCache(entries) {
  19686. var index = -1,
  19687. length = entries ? entries.length : 0;
  19688. this.clear();
  19689. while (++index < length) {
  19690. var entry = entries[index];
  19691. this.set(entry[0], entry[1]);
  19692. }
  19693. }
  19694. /**
  19695. * Removes all key-value entries from the map.
  19696. *
  19697. * @private
  19698. * @name clear
  19699. * @memberOf MapCache
  19700. */
  19701. function mapCacheClear() {
  19702. this.__data__ = {
  19703. 'hash': new Hash(),
  19704. 'map': new (Map || ListCache)(),
  19705. 'string': new Hash()
  19706. };
  19707. }
  19708. /**
  19709. * Removes `key` and its value from the map.
  19710. *
  19711. * @private
  19712. * @name delete
  19713. * @memberOf MapCache
  19714. * @param {string} key The key of the value to remove.
  19715. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  19716. */
  19717. function mapCacheDelete(key) {
  19718. return getMapData(this, key)['delete'](key);
  19719. }
  19720. /**
  19721. * Gets the map value for `key`.
  19722. *
  19723. * @private
  19724. * @name get
  19725. * @memberOf MapCache
  19726. * @param {string} key The key of the value to get.
  19727. * @returns {*} Returns the entry value.
  19728. */
  19729. function mapCacheGet(key) {
  19730. return getMapData(this, key).get(key);
  19731. }
  19732. /**
  19733. * Checks if a map value for `key` exists.
  19734. *
  19735. * @private
  19736. * @name has
  19737. * @memberOf MapCache
  19738. * @param {string} key The key of the entry to check.
  19739. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  19740. */
  19741. function mapCacheHas(key) {
  19742. return getMapData(this, key).has(key);
  19743. }
  19744. /**
  19745. * Sets the map `key` to `value`.
  19746. *
  19747. * @private
  19748. * @name set
  19749. * @memberOf MapCache
  19750. * @param {string} key The key of the value to set.
  19751. * @param {*} value The value to set.
  19752. * @returns {Object} Returns the map cache instance.
  19753. */
  19754. function mapCacheSet(key, value) {
  19755. getMapData(this, key).set(key, value);
  19756. return this;
  19757. } // Add methods to `MapCache`.
  19758. MapCache.prototype.clear = mapCacheClear;
  19759. MapCache.prototype['delete'] = mapCacheDelete;
  19760. MapCache.prototype.get = mapCacheGet;
  19761. MapCache.prototype.has = mapCacheHas;
  19762. MapCache.prototype.set = mapCacheSet;
  19763. /**
  19764. *
  19765. * Creates an array cache object to store unique values.
  19766. *
  19767. * @private
  19768. * @constructor
  19769. * @param {Array} [values] The values to cache.
  19770. */
  19771. function SetCache(values) {
  19772. var index = -1,
  19773. length = values ? values.length : 0;
  19774. this.__data__ = new MapCache();
  19775. while (++index < length) {
  19776. this.add(values[index]);
  19777. }
  19778. }
  19779. /**
  19780. * Adds `value` to the array cache.
  19781. *
  19782. * @private
  19783. * @name add
  19784. * @memberOf SetCache
  19785. * @alias push
  19786. * @param {*} value The value to cache.
  19787. * @returns {Object} Returns the cache instance.
  19788. */
  19789. function setCacheAdd(value) {
  19790. this.__data__.set(value, HASH_UNDEFINED);
  19791. return this;
  19792. }
  19793. /**
  19794. * Checks if `value` is in the array cache.
  19795. *
  19796. * @private
  19797. * @name has
  19798. * @memberOf SetCache
  19799. * @param {*} value The value to search for.
  19800. * @returns {number} Returns `true` if `value` is found, else `false`.
  19801. */
  19802. function setCacheHas(value) {
  19803. return this.__data__.has(value);
  19804. } // Add methods to `SetCache`.
  19805. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  19806. SetCache.prototype.has = setCacheHas;
  19807. /**
  19808. * Creates a stack cache object to store key-value pairs.
  19809. *
  19810. * @private
  19811. * @constructor
  19812. * @param {Array} [entries] The key-value pairs to cache.
  19813. */
  19814. function Stack(entries) {
  19815. this.__data__ = new ListCache(entries);
  19816. }
  19817. /**
  19818. * Removes all key-value entries from the stack.
  19819. *
  19820. * @private
  19821. * @name clear
  19822. * @memberOf Stack
  19823. */
  19824. function stackClear() {
  19825. this.__data__ = new ListCache();
  19826. }
  19827. /**
  19828. * Removes `key` and its value from the stack.
  19829. *
  19830. * @private
  19831. * @name delete
  19832. * @memberOf Stack
  19833. * @param {string} key The key of the value to remove.
  19834. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  19835. */
  19836. function stackDelete(key) {
  19837. return this.__data__['delete'](key);
  19838. }
  19839. /**
  19840. * Gets the stack value for `key`.
  19841. *
  19842. * @private
  19843. * @name get
  19844. * @memberOf Stack
  19845. * @param {string} key The key of the value to get.
  19846. * @returns {*} Returns the entry value.
  19847. */
  19848. function stackGet(key) {
  19849. return this.__data__.get(key);
  19850. }
  19851. /**
  19852. * Checks if a stack value for `key` exists.
  19853. *
  19854. * @private
  19855. * @name has
  19856. * @memberOf Stack
  19857. * @param {string} key The key of the entry to check.
  19858. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  19859. */
  19860. function stackHas(key) {
  19861. return this.__data__.has(key);
  19862. }
  19863. /**
  19864. * Sets the stack `key` to `value`.
  19865. *
  19866. * @private
  19867. * @name set
  19868. * @memberOf Stack
  19869. * @param {string} key The key of the value to set.
  19870. * @param {*} value The value to set.
  19871. * @returns {Object} Returns the stack cache instance.
  19872. */
  19873. function stackSet(key, value) {
  19874. var cache = this.__data__;
  19875. if (cache instanceof ListCache) {
  19876. var pairs = cache.__data__;
  19877. if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  19878. pairs.push([key, value]);
  19879. return this;
  19880. }
  19881. cache = this.__data__ = new MapCache(pairs);
  19882. }
  19883. cache.set(key, value);
  19884. return this;
  19885. } // Add methods to `Stack`.
  19886. Stack.prototype.clear = stackClear;
  19887. Stack.prototype['delete'] = stackDelete;
  19888. Stack.prototype.get = stackGet;
  19889. Stack.prototype.has = stackHas;
  19890. Stack.prototype.set = stackSet;
  19891. /**
  19892. * Creates an array of the enumerable property names of the array-like `value`.
  19893. *
  19894. * @private
  19895. * @param {*} value The value to query.
  19896. * @param {boolean} inherited Specify returning inherited property names.
  19897. * @returns {Array} Returns the array of property names.
  19898. */
  19899. function arrayLikeKeys(value, inherited) {
  19900. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  19901. // Safari 9 makes `arguments.length` enumerable in strict mode.
  19902. var result = isArray(value) || isArguments(value) ? baseTimes(value.length, String) : [];
  19903. var length = result.length,
  19904. skipIndexes = !!length;
  19905. for (var key in value) {
  19906. if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  19907. result.push(key);
  19908. }
  19909. }
  19910. return result;
  19911. }
  19912. /**
  19913. * Gets the index at which the `key` is found in `array` of key-value pairs.
  19914. *
  19915. * @private
  19916. * @param {Array} array The array to inspect.
  19917. * @param {*} key The key to search for.
  19918. * @returns {number} Returns the index of the matched value, else `-1`.
  19919. */
  19920. function assocIndexOf(array, key) {
  19921. var length = array.length;
  19922. while (length--) {
  19923. if (eq(array[length][0], key)) {
  19924. return length;
  19925. }
  19926. }
  19927. return -1;
  19928. }
  19929. /**
  19930. * The base implementation of `_.get` without support for default values.
  19931. *
  19932. * @private
  19933. * @param {Object} object The object to query.
  19934. * @param {Array|string} path The path of the property to get.
  19935. * @returns {*} Returns the resolved value.
  19936. */
  19937. function baseGet(object, path) {
  19938. path = isKey(path, object) ? [path] : castPath(path);
  19939. var index = 0,
  19940. length = path.length;
  19941. while (object != null && index < length) {
  19942. object = object[toKey(path[index++])];
  19943. }
  19944. return index && index == length ? object : undefined;
  19945. }
  19946. /**
  19947. * The base implementation of `getTag`.
  19948. *
  19949. * @private
  19950. * @param {*} value The value to query.
  19951. * @returns {string} Returns the `toStringTag`.
  19952. */
  19953. function baseGetTag(value) {
  19954. return objectToString.call(value);
  19955. }
  19956. /**
  19957. * The base implementation of `_.hasIn` without support for deep paths.
  19958. *
  19959. * @private
  19960. * @param {Object} [object] The object to query.
  19961. * @param {Array|string} key The key to check.
  19962. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  19963. */
  19964. function baseHasIn(object, key) {
  19965. return object != null && key in Object(object);
  19966. }
  19967. /**
  19968. * The base implementation of `_.isEqual` which supports partial comparisons
  19969. * and tracks traversed objects.
  19970. *
  19971. * @private
  19972. * @param {*} value The value to compare.
  19973. * @param {*} other The other value to compare.
  19974. * @param {Function} [customizer] The function to customize comparisons.
  19975. * @param {boolean} [bitmask] The bitmask of comparison flags.
  19976. * The bitmask may be composed of the following flags:
  19977. * 1 - Unordered comparison
  19978. * 2 - Partial comparison
  19979. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  19980. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  19981. */
  19982. function baseIsEqual(value, other, customizer, bitmask, stack) {
  19983. if (value === other) {
  19984. return true;
  19985. }
  19986. if (value == null || other == null || !isObject(value) && !isObjectLike(other)) {
  19987. return value !== value && other !== other;
  19988. }
  19989. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  19990. }
  19991. /**
  19992. * A specialized version of `baseIsEqual` for arrays and objects which performs
  19993. * deep comparisons and tracks traversed objects enabling objects with circular
  19994. * references to be compared.
  19995. *
  19996. * @private
  19997. * @param {Object} object The object to compare.
  19998. * @param {Object} other The other object to compare.
  19999. * @param {Function} equalFunc The function to determine equivalents of values.
  20000. * @param {Function} [customizer] The function to customize comparisons.
  20001. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  20002. * for more details.
  20003. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  20004. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  20005. */
  20006. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  20007. var objIsArr = isArray(object),
  20008. othIsArr = isArray(other),
  20009. objTag = arrayTag,
  20010. othTag = arrayTag;
  20011. if (!objIsArr) {
  20012. objTag = getTag(object);
  20013. objTag = objTag == argsTag ? objectTag : objTag;
  20014. }
  20015. if (!othIsArr) {
  20016. othTag = getTag(other);
  20017. othTag = othTag == argsTag ? objectTag : othTag;
  20018. }
  20019. var objIsObj = objTag == objectTag && !isHostObject(object),
  20020. othIsObj = othTag == objectTag && !isHostObject(other),
  20021. isSameTag = objTag == othTag;
  20022. if (isSameTag && !objIsObj) {
  20023. stack || (stack = new Stack());
  20024. return objIsArr || isTypedArray(object) ? equalArrays(object, other, equalFunc, customizer, bitmask, stack) : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  20025. }
  20026. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  20027. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  20028. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  20029. if (objIsWrapped || othIsWrapped) {
  20030. var objUnwrapped = objIsWrapped ? object.value() : object,
  20031. othUnwrapped = othIsWrapped ? other.value() : other;
  20032. stack || (stack = new Stack());
  20033. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  20034. }
  20035. }
  20036. if (!isSameTag) {
  20037. return false;
  20038. }
  20039. stack || (stack = new Stack());
  20040. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  20041. }
  20042. /**
  20043. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  20044. *
  20045. * @private
  20046. * @param {Object} object The object to inspect.
  20047. * @param {Object} source The object of property values to match.
  20048. * @param {Array} matchData The property names, values, and compare flags to match.
  20049. * @param {Function} [customizer] The function to customize comparisons.
  20050. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  20051. */
  20052. function baseIsMatch(object, source, matchData, customizer) {
  20053. var index = matchData.length,
  20054. length = index,
  20055. noCustomizer = !customizer;
  20056. if (object == null) {
  20057. return !length;
  20058. }
  20059. object = Object(object);
  20060. while (index--) {
  20061. var data = matchData[index];
  20062. if (noCustomizer && data[2] ? data[1] !== object[data[0]] : !(data[0] in object)) {
  20063. return false;
  20064. }
  20065. }
  20066. while (++index < length) {
  20067. data = matchData[index];
  20068. var key = data[0],
  20069. objValue = object[key],
  20070. srcValue = data[1];
  20071. if (noCustomizer && data[2]) {
  20072. if (objValue === undefined && !(key in object)) {
  20073. return false;
  20074. }
  20075. } else {
  20076. var stack = new Stack();
  20077. if (customizer) {
  20078. var result = customizer(objValue, srcValue, key, object, source, stack);
  20079. }
  20080. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) : result)) {
  20081. return false;
  20082. }
  20083. }
  20084. }
  20085. return true;
  20086. }
  20087. /**
  20088. * The base implementation of `_.isNative` without bad shim checks.
  20089. *
  20090. * @private
  20091. * @param {*} value The value to check.
  20092. * @returns {boolean} Returns `true` if `value` is a native function,
  20093. * else `false`.
  20094. */
  20095. function baseIsNative(value) {
  20096. if (!isObject(value) || isMasked(value)) {
  20097. return false;
  20098. }
  20099. var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
  20100. return pattern.test(toSource(value));
  20101. }
  20102. /**
  20103. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  20104. *
  20105. * @private
  20106. * @param {*} value The value to check.
  20107. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  20108. */
  20109. function baseIsTypedArray(value) {
  20110. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  20111. }
  20112. /**
  20113. * The base implementation of `_.iteratee`.
  20114. *
  20115. * @private
  20116. * @param {*} [value=_.identity] The value to convert to an iteratee.
  20117. * @returns {Function} Returns the iteratee.
  20118. */
  20119. function baseIteratee(value) {
  20120. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  20121. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  20122. if (typeof value == 'function') {
  20123. return value;
  20124. }
  20125. if (value == null) {
  20126. return identity;
  20127. }
  20128. if (typeof value == 'object') {
  20129. return isArray(value) ? baseMatchesProperty(value[0], value[1]) : baseMatches(value);
  20130. }
  20131. return property(value);
  20132. }
  20133. /**
  20134. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  20135. *
  20136. * @private
  20137. * @param {Object} object The object to query.
  20138. * @returns {Array} Returns the array of property names.
  20139. */
  20140. function baseKeys(object) {
  20141. if (!isPrototype(object)) {
  20142. return nativeKeys(object);
  20143. }
  20144. var result = [];
  20145. for (var key in Object(object)) {
  20146. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  20147. result.push(key);
  20148. }
  20149. }
  20150. return result;
  20151. }
  20152. /**
  20153. * The base implementation of `_.matches` which doesn't clone `source`.
  20154. *
  20155. * @private
  20156. * @param {Object} source The object of property values to match.
  20157. * @returns {Function} Returns the new spec function.
  20158. */
  20159. function baseMatches(source) {
  20160. var matchData = getMatchData(source);
  20161. if (matchData.length == 1 && matchData[0][2]) {
  20162. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  20163. }
  20164. return function (object) {
  20165. return object === source || baseIsMatch(object, source, matchData);
  20166. };
  20167. }
  20168. /**
  20169. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  20170. *
  20171. * @private
  20172. * @param {string} path The path of the property to get.
  20173. * @param {*} srcValue The value to match.
  20174. * @returns {Function} Returns the new spec function.
  20175. */
  20176. function baseMatchesProperty(path, srcValue) {
  20177. if (isKey(path) && isStrictComparable(srcValue)) {
  20178. return matchesStrictComparable(toKey(path), srcValue);
  20179. }
  20180. return function (object) {
  20181. var objValue = get(object, path);
  20182. return objValue === undefined && objValue === srcValue ? hasIn(object, path) : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  20183. };
  20184. }
  20185. /**
  20186. * A specialized version of `baseProperty` which supports deep paths.
  20187. *
  20188. * @private
  20189. * @param {Array|string} path The path of the property to get.
  20190. * @returns {Function} Returns the new accessor function.
  20191. */
  20192. function basePropertyDeep(path) {
  20193. return function (object) {
  20194. return baseGet(object, path);
  20195. };
  20196. }
  20197. /**
  20198. * The base implementation of `_.toString` which doesn't convert nullish
  20199. * values to empty strings.
  20200. *
  20201. * @private
  20202. * @param {*} value The value to process.
  20203. * @returns {string} Returns the string.
  20204. */
  20205. function baseToString(value) {
  20206. // Exit early for strings to avoid a performance hit in some environments.
  20207. if (typeof value == 'string') {
  20208. return value;
  20209. }
  20210. if (isSymbol(value)) {
  20211. return symbolToString ? symbolToString.call(value) : '';
  20212. }
  20213. var result = value + '';
  20214. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  20215. }
  20216. /**
  20217. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  20218. *
  20219. * @private
  20220. * @param {Array} array The array to inspect.
  20221. * @param {Function} [iteratee] The iteratee invoked per element.
  20222. * @param {Function} [comparator] The comparator invoked per element.
  20223. * @returns {Array} Returns the new duplicate free array.
  20224. */
  20225. function baseUniq(array, iteratee, comparator) {
  20226. var index = -1,
  20227. includes = arrayIncludes,
  20228. length = array.length,
  20229. isCommon = true,
  20230. result = [],
  20231. seen = result;
  20232. if (comparator) {
  20233. isCommon = false;
  20234. includes = arrayIncludesWith;
  20235. } else if (length >= LARGE_ARRAY_SIZE) {
  20236. var set = iteratee ? null : createSet(array);
  20237. if (set) {
  20238. return setToArray(set);
  20239. }
  20240. isCommon = false;
  20241. includes = cacheHas;
  20242. seen = new SetCache();
  20243. } else {
  20244. seen = iteratee ? [] : result;
  20245. }
  20246. outer: while (++index < length) {
  20247. var value = array[index],
  20248. computed = iteratee ? iteratee(value) : value;
  20249. value = comparator || value !== 0 ? value : 0;
  20250. if (isCommon && computed === computed) {
  20251. var seenIndex = seen.length;
  20252. while (seenIndex--) {
  20253. if (seen[seenIndex] === computed) {
  20254. continue outer;
  20255. }
  20256. }
  20257. if (iteratee) {
  20258. seen.push(computed);
  20259. }
  20260. result.push(value);
  20261. } else if (!includes(seen, computed, comparator)) {
  20262. if (seen !== result) {
  20263. seen.push(computed);
  20264. }
  20265. result.push(value);
  20266. }
  20267. }
  20268. return result;
  20269. }
  20270. /**
  20271. * Casts `value` to a path array if it's not one.
  20272. *
  20273. * @private
  20274. * @param {*} value The value to inspect.
  20275. * @returns {Array} Returns the cast property path array.
  20276. */
  20277. function castPath(value) {
  20278. return isArray(value) ? value : stringToPath(value);
  20279. }
  20280. /**
  20281. * Creates a set object of `values`.
  20282. *
  20283. * @private
  20284. * @param {Array} values The values to add to the set.
  20285. * @returns {Object} Returns the new set.
  20286. */
  20287. var createSet = !(Set && 1 / setToArray(new Set([, -0]))[1] == INFINITY) ? noop : function (values) {
  20288. return new Set(values);
  20289. };
  20290. /**
  20291. * A specialized version of `baseIsEqualDeep` for arrays with support for
  20292. * partial deep comparisons.
  20293. *
  20294. * @private
  20295. * @param {Array} array The array to compare.
  20296. * @param {Array} other The other array to compare.
  20297. * @param {Function} equalFunc The function to determine equivalents of values.
  20298. * @param {Function} customizer The function to customize comparisons.
  20299. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  20300. * for more details.
  20301. * @param {Object} stack Tracks traversed `array` and `other` objects.
  20302. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  20303. */
  20304. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  20305. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  20306. arrLength = array.length,
  20307. othLength = other.length;
  20308. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  20309. return false;
  20310. } // Assume cyclic values are equal.
  20311. var stacked = stack.get(array);
  20312. if (stacked && stack.get(other)) {
  20313. return stacked == other;
  20314. }
  20315. var index = -1,
  20316. result = true,
  20317. seen = bitmask & UNORDERED_COMPARE_FLAG ? new SetCache() : undefined;
  20318. stack.set(array, other);
  20319. stack.set(other, array); // Ignore non-index properties.
  20320. while (++index < arrLength) {
  20321. var arrValue = array[index],
  20322. othValue = other[index];
  20323. if (customizer) {
  20324. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  20325. }
  20326. if (compared !== undefined) {
  20327. if (compared) {
  20328. continue;
  20329. }
  20330. result = false;
  20331. break;
  20332. } // Recursively compare arrays (susceptible to call stack limits).
  20333. if (seen) {
  20334. if (!arraySome(other, function (othValue, othIndex) {
  20335. if (!seen.has(othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  20336. return seen.add(othIndex);
  20337. }
  20338. })) {
  20339. result = false;
  20340. break;
  20341. }
  20342. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  20343. result = false;
  20344. break;
  20345. }
  20346. }
  20347. stack['delete'](array);
  20348. stack['delete'](other);
  20349. return result;
  20350. }
  20351. /**
  20352. * A specialized version of `baseIsEqualDeep` for comparing objects of
  20353. * the same `toStringTag`.
  20354. *
  20355. * **Note:** This function only supports comparing values with tags of
  20356. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  20357. *
  20358. * @private
  20359. * @param {Object} object The object to compare.
  20360. * @param {Object} other The other object to compare.
  20361. * @param {string} tag The `toStringTag` of the objects to compare.
  20362. * @param {Function} equalFunc The function to determine equivalents of values.
  20363. * @param {Function} customizer The function to customize comparisons.
  20364. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  20365. * for more details.
  20366. * @param {Object} stack Tracks traversed `object` and `other` objects.
  20367. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  20368. */
  20369. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  20370. switch (tag) {
  20371. case dataViewTag:
  20372. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  20373. return false;
  20374. }
  20375. object = object.buffer;
  20376. other = other.buffer;
  20377. case arrayBufferTag:
  20378. if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  20379. return false;
  20380. }
  20381. return true;
  20382. case boolTag:
  20383. case dateTag:
  20384. case numberTag:
  20385. // Coerce booleans to `1` or `0` and dates to milliseconds.
  20386. // Invalid dates are coerced to `NaN`.
  20387. return eq(+object, +other);
  20388. case errorTag:
  20389. return object.name == other.name && object.message == other.message;
  20390. case regexpTag:
  20391. case stringTag:
  20392. // Coerce regexes to strings and treat strings, primitives and objects,
  20393. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  20394. // for more details.
  20395. return object == other + '';
  20396. case mapTag:
  20397. var convert = mapToArray;
  20398. case setTag:
  20399. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  20400. convert || (convert = setToArray);
  20401. if (object.size != other.size && !isPartial) {
  20402. return false;
  20403. } // Assume cyclic values are equal.
  20404. var stacked = stack.get(object);
  20405. if (stacked) {
  20406. return stacked == other;
  20407. }
  20408. bitmask |= UNORDERED_COMPARE_FLAG; // Recursively compare objects (susceptible to call stack limits).
  20409. stack.set(object, other);
  20410. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  20411. stack['delete'](object);
  20412. return result;
  20413. case symbolTag:
  20414. if (symbolValueOf) {
  20415. return symbolValueOf.call(object) == symbolValueOf.call(other);
  20416. }
  20417. }
  20418. return false;
  20419. }
  20420. /**
  20421. * A specialized version of `baseIsEqualDeep` for objects with support for
  20422. * partial deep comparisons.
  20423. *
  20424. * @private
  20425. * @param {Object} object The object to compare.
  20426. * @param {Object} other The other object to compare.
  20427. * @param {Function} equalFunc The function to determine equivalents of values.
  20428. * @param {Function} customizer The function to customize comparisons.
  20429. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  20430. * for more details.
  20431. * @param {Object} stack Tracks traversed `object` and `other` objects.
  20432. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  20433. */
  20434. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  20435. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  20436. objProps = keys(object),
  20437. objLength = objProps.length,
  20438. othProps = keys(other),
  20439. othLength = othProps.length;
  20440. if (objLength != othLength && !isPartial) {
  20441. return false;
  20442. }
  20443. var index = objLength;
  20444. while (index--) {
  20445. var key = objProps[index];
  20446. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  20447. return false;
  20448. }
  20449. } // Assume cyclic values are equal.
  20450. var stacked = stack.get(object);
  20451. if (stacked && stack.get(other)) {
  20452. return stacked == other;
  20453. }
  20454. var result = true;
  20455. stack.set(object, other);
  20456. stack.set(other, object);
  20457. var skipCtor = isPartial;
  20458. while (++index < objLength) {
  20459. key = objProps[index];
  20460. var objValue = object[key],
  20461. othValue = other[key];
  20462. if (customizer) {
  20463. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  20464. } // Recursively compare objects (susceptible to call stack limits).
  20465. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack) : compared)) {
  20466. result = false;
  20467. break;
  20468. }
  20469. skipCtor || (skipCtor = key == 'constructor');
  20470. }
  20471. if (result && !skipCtor) {
  20472. var objCtor = object.constructor,
  20473. othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal.
  20474. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  20475. result = false;
  20476. }
  20477. }
  20478. stack['delete'](object);
  20479. stack['delete'](other);
  20480. return result;
  20481. }
  20482. /**
  20483. * Gets the data for `map`.
  20484. *
  20485. * @private
  20486. * @param {Object} map The map to query.
  20487. * @param {string} key The reference key.
  20488. * @returns {*} Returns the map data.
  20489. */
  20490. function getMapData(map, key) {
  20491. var data = map.__data__;
  20492. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  20493. }
  20494. /**
  20495. * Gets the property names, values, and compare flags of `object`.
  20496. *
  20497. * @private
  20498. * @param {Object} object The object to query.
  20499. * @returns {Array} Returns the match data of `object`.
  20500. */
  20501. function getMatchData(object) {
  20502. var result = keys(object),
  20503. length = result.length;
  20504. while (length--) {
  20505. var key = result[length],
  20506. value = object[key];
  20507. result[length] = [key, value, isStrictComparable(value)];
  20508. }
  20509. return result;
  20510. }
  20511. /**
  20512. * Gets the native function at `key` of `object`.
  20513. *
  20514. * @private
  20515. * @param {Object} object The object to query.
  20516. * @param {string} key The key of the method to get.
  20517. * @returns {*} Returns the function if it's native, else `undefined`.
  20518. */
  20519. function getNative(object, key) {
  20520. var value = getValue(object, key);
  20521. return baseIsNative(value) ? value : undefined;
  20522. }
  20523. /**
  20524. * Gets the `toStringTag` of `value`.
  20525. *
  20526. * @private
  20527. * @param {*} value The value to query.
  20528. * @returns {string} Returns the `toStringTag`.
  20529. */
  20530. var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11,
  20531. // for data views in Edge < 14, and promises in Node.js.
  20532. if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map && getTag(new Map()) != mapTag || Promise && getTag(Promise.resolve()) != promiseTag || Set && getTag(new Set()) != setTag || WeakMap && getTag(new WeakMap()) != weakMapTag) {
  20533. getTag = function getTag(value) {
  20534. var result = objectToString.call(value),
  20535. Ctor = result == objectTag ? value.constructor : undefined,
  20536. ctorString = Ctor ? toSource(Ctor) : undefined;
  20537. if (ctorString) {
  20538. switch (ctorString) {
  20539. case dataViewCtorString:
  20540. return dataViewTag;
  20541. case mapCtorString:
  20542. return mapTag;
  20543. case promiseCtorString:
  20544. return promiseTag;
  20545. case setCtorString:
  20546. return setTag;
  20547. case weakMapCtorString:
  20548. return weakMapTag;
  20549. }
  20550. }
  20551. return result;
  20552. };
  20553. }
  20554. /**
  20555. * Checks if `path` exists on `object`.
  20556. *
  20557. * @private
  20558. * @param {Object} object The object to query.
  20559. * @param {Array|string} path The path to check.
  20560. * @param {Function} hasFunc The function to check properties.
  20561. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  20562. */
  20563. function hasPath(object, path, hasFunc) {
  20564. path = isKey(path, object) ? [path] : castPath(path);
  20565. var result,
  20566. index = -1,
  20567. length = path.length;
  20568. while (++index < length) {
  20569. var key = toKey(path[index]);
  20570. if (!(result = object != null && hasFunc(object, key))) {
  20571. break;
  20572. }
  20573. object = object[key];
  20574. }
  20575. if (result) {
  20576. return result;
  20577. }
  20578. var length = object ? object.length : 0;
  20579. return !!length && isLength(length) && isIndex(key, length) && (isArray(object) || isArguments(object));
  20580. }
  20581. /**
  20582. * Checks if `value` is a valid array-like index.
  20583. *
  20584. * @private
  20585. * @param {*} value The value to check.
  20586. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  20587. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  20588. */
  20589. function isIndex(value, length) {
  20590. length = length == null ? MAX_SAFE_INTEGER : length;
  20591. return !!length && (typeof value == 'number' || reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  20592. }
  20593. /**
  20594. * Checks if `value` is a property name and not a property path.
  20595. *
  20596. * @private
  20597. * @param {*} value The value to check.
  20598. * @param {Object} [object] The object to query keys on.
  20599. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  20600. */
  20601. function isKey(value, object) {
  20602. if (isArray(value)) {
  20603. return false;
  20604. }
  20605. var type = typeof value;
  20606. if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol(value)) {
  20607. return true;
  20608. }
  20609. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
  20610. }
  20611. /**
  20612. * Checks if `value` is suitable for use as unique object key.
  20613. *
  20614. * @private
  20615. * @param {*} value The value to check.
  20616. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  20617. */
  20618. function isKeyable(value) {
  20619. var type = typeof value;
  20620. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  20621. }
  20622. /**
  20623. * Checks if `func` has its source masked.
  20624. *
  20625. * @private
  20626. * @param {Function} func The function to check.
  20627. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  20628. */
  20629. function isMasked(func) {
  20630. return !!maskSrcKey && maskSrcKey in func;
  20631. }
  20632. /**
  20633. * Checks if `value` is likely a prototype object.
  20634. *
  20635. * @private
  20636. * @param {*} value The value to check.
  20637. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  20638. */
  20639. function isPrototype(value) {
  20640. var Ctor = value && value.constructor,
  20641. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto;
  20642. return value === proto;
  20643. }
  20644. /**
  20645. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  20646. *
  20647. * @private
  20648. * @param {*} value The value to check.
  20649. * @returns {boolean} Returns `true` if `value` if suitable for strict
  20650. * equality comparisons, else `false`.
  20651. */
  20652. function isStrictComparable(value) {
  20653. return value === value && !isObject(value);
  20654. }
  20655. /**
  20656. * A specialized version of `matchesProperty` for source values suitable
  20657. * for strict equality comparisons, i.e. `===`.
  20658. *
  20659. * @private
  20660. * @param {string} key The key of the property to get.
  20661. * @param {*} srcValue The value to match.
  20662. * @returns {Function} Returns the new spec function.
  20663. */
  20664. function matchesStrictComparable(key, srcValue) {
  20665. return function (object) {
  20666. if (object == null) {
  20667. return false;
  20668. }
  20669. return object[key] === srcValue && (srcValue !== undefined || key in Object(object));
  20670. };
  20671. }
  20672. /**
  20673. * Converts `string` to a property path array.
  20674. *
  20675. * @private
  20676. * @param {string} string The string to convert.
  20677. * @returns {Array} Returns the property path array.
  20678. */
  20679. var stringToPath = memoize(function (string) {
  20680. string = toString(string);
  20681. var result = [];
  20682. if (reLeadingDot.test(string)) {
  20683. result.push('');
  20684. }
  20685. string.replace(rePropName, function (match, number, quote, string) {
  20686. result.push(quote ? string.replace(reEscapeChar, '$1') : number || match);
  20687. });
  20688. return result;
  20689. });
  20690. /**
  20691. * Converts `value` to a string key if it's not a string or symbol.
  20692. *
  20693. * @private
  20694. * @param {*} value The value to inspect.
  20695. * @returns {string|symbol} Returns the key.
  20696. */
  20697. function toKey(value) {
  20698. if (typeof value == 'string' || isSymbol(value)) {
  20699. return value;
  20700. }
  20701. var result = value + '';
  20702. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  20703. }
  20704. /**
  20705. * Converts `func` to its source code.
  20706. *
  20707. * @private
  20708. * @param {Function} func The function to process.
  20709. * @returns {string} Returns the source code.
  20710. */
  20711. function toSource(func) {
  20712. if (func != null) {
  20713. try {
  20714. return funcToString.call(func);
  20715. } catch (e) {}
  20716. try {
  20717. return func + '';
  20718. } catch (e) {}
  20719. }
  20720. return '';
  20721. }
  20722. /**
  20723. * This method is like `_.uniq` except that it accepts `iteratee` which is
  20724. * invoked for each element in `array` to generate the criterion by which
  20725. * uniqueness is computed. The iteratee is invoked with one argument: (value).
  20726. *
  20727. * @static
  20728. * @memberOf _
  20729. * @since 4.0.0
  20730. * @category Array
  20731. * @param {Array} array The array to inspect.
  20732. * @param {Function} [iteratee=_.identity]
  20733. * The iteratee invoked per element.
  20734. * @returns {Array} Returns the new duplicate free array.
  20735. * @example
  20736. *
  20737. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  20738. * // => [2.1, 1.2]
  20739. *
  20740. * // The `_.property` iteratee shorthand.
  20741. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  20742. * // => [{ 'x': 1 }, { 'x': 2 }]
  20743. */
  20744. function uniqBy(array, iteratee) {
  20745. return array && array.length ? baseUniq(array, baseIteratee(iteratee)) : [];
  20746. }
  20747. /**
  20748. * Creates a function that memoizes the result of `func`. If `resolver` is
  20749. * provided, it determines the cache key for storing the result based on the
  20750. * arguments provided to the memoized function. By default, the first argument
  20751. * provided to the memoized function is used as the map cache key. The `func`
  20752. * is invoked with the `this` binding of the memoized function.
  20753. *
  20754. * **Note:** The cache is exposed as the `cache` property on the memoized
  20755. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  20756. * constructor with one whose instances implement the
  20757. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  20758. * method interface of `delete`, `get`, `has`, and `set`.
  20759. *
  20760. * @static
  20761. * @memberOf _
  20762. * @since 0.1.0
  20763. * @category Function
  20764. * @param {Function} func The function to have its output memoized.
  20765. * @param {Function} [resolver] The function to resolve the cache key.
  20766. * @returns {Function} Returns the new memoized function.
  20767. * @example
  20768. *
  20769. * var object = { 'a': 1, 'b': 2 };
  20770. * var other = { 'c': 3, 'd': 4 };
  20771. *
  20772. * var values = _.memoize(_.values);
  20773. * values(object);
  20774. * // => [1, 2]
  20775. *
  20776. * values(other);
  20777. * // => [3, 4]
  20778. *
  20779. * object.a = 2;
  20780. * values(object);
  20781. * // => [1, 2]
  20782. *
  20783. * // Modify the result cache.
  20784. * values.cache.set(object, ['a', 'b']);
  20785. * values(object);
  20786. * // => ['a', 'b']
  20787. *
  20788. * // Replace `_.memoize.Cache`.
  20789. * _.memoize.Cache = WeakMap;
  20790. */
  20791. function memoize(func, resolver) {
  20792. if (typeof func != 'function' || resolver && typeof resolver != 'function') {
  20793. throw new TypeError(FUNC_ERROR_TEXT);
  20794. }
  20795. var memoized = function memoized() {
  20796. var args = arguments,
  20797. key = resolver ? resolver.apply(this, args) : args[0],
  20798. cache = memoized.cache;
  20799. if (cache.has(key)) {
  20800. return cache.get(key);
  20801. }
  20802. var result = func.apply(this, args);
  20803. memoized.cache = cache.set(key, result);
  20804. return result;
  20805. };
  20806. memoized.cache = new (memoize.Cache || MapCache)();
  20807. return memoized;
  20808. } // Assign cache to `_.memoize`.
  20809. memoize.Cache = MapCache;
  20810. /**
  20811. * Performs a
  20812. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  20813. * comparison between two values to determine if they are equivalent.
  20814. *
  20815. * @static
  20816. * @memberOf _
  20817. * @since 4.0.0
  20818. * @category Lang
  20819. * @param {*} value The value to compare.
  20820. * @param {*} other The other value to compare.
  20821. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  20822. * @example
  20823. *
  20824. * var object = { 'a': 1 };
  20825. * var other = { 'a': 1 };
  20826. *
  20827. * _.eq(object, object);
  20828. * // => true
  20829. *
  20830. * _.eq(object, other);
  20831. * // => false
  20832. *
  20833. * _.eq('a', 'a');
  20834. * // => true
  20835. *
  20836. * _.eq('a', Object('a'));
  20837. * // => false
  20838. *
  20839. * _.eq(NaN, NaN);
  20840. * // => true
  20841. */
  20842. function eq(value, other) {
  20843. return value === other || value !== value && other !== other;
  20844. }
  20845. /**
  20846. * Checks if `value` is likely an `arguments` object.
  20847. *
  20848. * @static
  20849. * @memberOf _
  20850. * @since 0.1.0
  20851. * @category Lang
  20852. * @param {*} value The value to check.
  20853. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  20854. * else `false`.
  20855. * @example
  20856. *
  20857. * _.isArguments(function() { return arguments; }());
  20858. * // => true
  20859. *
  20860. * _.isArguments([1, 2, 3]);
  20861. * // => false
  20862. */
  20863. function isArguments(value) {
  20864. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  20865. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  20866. }
  20867. /**
  20868. * Checks if `value` is classified as an `Array` object.
  20869. *
  20870. * @static
  20871. * @memberOf _
  20872. * @since 0.1.0
  20873. * @category Lang
  20874. * @param {*} value The value to check.
  20875. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  20876. * @example
  20877. *
  20878. * _.isArray([1, 2, 3]);
  20879. * // => true
  20880. *
  20881. * _.isArray(document.body.children);
  20882. * // => false
  20883. *
  20884. * _.isArray('abc');
  20885. * // => false
  20886. *
  20887. * _.isArray(_.noop);
  20888. * // => false
  20889. */
  20890. var isArray = Array.isArray;
  20891. /**
  20892. * Checks if `value` is array-like. A value is considered array-like if it's
  20893. * not a function and has a `value.length` that's an integer greater than or
  20894. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  20895. *
  20896. * @static
  20897. * @memberOf _
  20898. * @since 4.0.0
  20899. * @category Lang
  20900. * @param {*} value The value to check.
  20901. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  20902. * @example
  20903. *
  20904. * _.isArrayLike([1, 2, 3]);
  20905. * // => true
  20906. *
  20907. * _.isArrayLike(document.body.children);
  20908. * // => true
  20909. *
  20910. * _.isArrayLike('abc');
  20911. * // => true
  20912. *
  20913. * _.isArrayLike(_.noop);
  20914. * // => false
  20915. */
  20916. function isArrayLike(value) {
  20917. return value != null && isLength(value.length) && !isFunction(value);
  20918. }
  20919. /**
  20920. * This method is like `_.isArrayLike` except that it also checks if `value`
  20921. * is an object.
  20922. *
  20923. * @static
  20924. * @memberOf _
  20925. * @since 4.0.0
  20926. * @category Lang
  20927. * @param {*} value The value to check.
  20928. * @returns {boolean} Returns `true` if `value` is an array-like object,
  20929. * else `false`.
  20930. * @example
  20931. *
  20932. * _.isArrayLikeObject([1, 2, 3]);
  20933. * // => true
  20934. *
  20935. * _.isArrayLikeObject(document.body.children);
  20936. * // => true
  20937. *
  20938. * _.isArrayLikeObject('abc');
  20939. * // => false
  20940. *
  20941. * _.isArrayLikeObject(_.noop);
  20942. * // => false
  20943. */
  20944. function isArrayLikeObject(value) {
  20945. return isObjectLike(value) && isArrayLike(value);
  20946. }
  20947. /**
  20948. * Checks if `value` is classified as a `Function` object.
  20949. *
  20950. * @static
  20951. * @memberOf _
  20952. * @since 0.1.0
  20953. * @category Lang
  20954. * @param {*} value The value to check.
  20955. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  20956. * @example
  20957. *
  20958. * _.isFunction(_);
  20959. * // => true
  20960. *
  20961. * _.isFunction(/abc/);
  20962. * // => false
  20963. */
  20964. function isFunction(value) {
  20965. // The use of `Object#toString` avoids issues with the `typeof` operator
  20966. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  20967. var tag = isObject(value) ? objectToString.call(value) : '';
  20968. return tag == funcTag || tag == genTag;
  20969. }
  20970. /**
  20971. * Checks if `value` is a valid array-like length.
  20972. *
  20973. * **Note:** This method is loosely based on
  20974. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  20975. *
  20976. * @static
  20977. * @memberOf _
  20978. * @since 4.0.0
  20979. * @category Lang
  20980. * @param {*} value The value to check.
  20981. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  20982. * @example
  20983. *
  20984. * _.isLength(3);
  20985. * // => true
  20986. *
  20987. * _.isLength(Number.MIN_VALUE);
  20988. * // => false
  20989. *
  20990. * _.isLength(Infinity);
  20991. * // => false
  20992. *
  20993. * _.isLength('3');
  20994. * // => false
  20995. */
  20996. function isLength(value) {
  20997. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  20998. }
  20999. /**
  21000. * Checks if `value` is the
  21001. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  21002. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  21003. *
  21004. * @static
  21005. * @memberOf _
  21006. * @since 0.1.0
  21007. * @category Lang
  21008. * @param {*} value The value to check.
  21009. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  21010. * @example
  21011. *
  21012. * _.isObject({});
  21013. * // => true
  21014. *
  21015. * _.isObject([1, 2, 3]);
  21016. * // => true
  21017. *
  21018. * _.isObject(_.noop);
  21019. * // => true
  21020. *
  21021. * _.isObject(null);
  21022. * // => false
  21023. */
  21024. function isObject(value) {
  21025. var type = typeof value;
  21026. return !!value && (type == 'object' || type == 'function');
  21027. }
  21028. /**
  21029. * Checks if `value` is object-like. A value is object-like if it's not `null`
  21030. * and has a `typeof` result of "object".
  21031. *
  21032. * @static
  21033. * @memberOf _
  21034. * @since 4.0.0
  21035. * @category Lang
  21036. * @param {*} value The value to check.
  21037. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  21038. * @example
  21039. *
  21040. * _.isObjectLike({});
  21041. * // => true
  21042. *
  21043. * _.isObjectLike([1, 2, 3]);
  21044. * // => true
  21045. *
  21046. * _.isObjectLike(_.noop);
  21047. * // => false
  21048. *
  21049. * _.isObjectLike(null);
  21050. * // => false
  21051. */
  21052. function isObjectLike(value) {
  21053. return !!value && typeof value == 'object';
  21054. }
  21055. /**
  21056. * Checks if `value` is classified as a `Symbol` primitive or object.
  21057. *
  21058. * @static
  21059. * @memberOf _
  21060. * @since 4.0.0
  21061. * @category Lang
  21062. * @param {*} value The value to check.
  21063. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  21064. * @example
  21065. *
  21066. * _.isSymbol(Symbol.iterator);
  21067. * // => true
  21068. *
  21069. * _.isSymbol('abc');
  21070. * // => false
  21071. */
  21072. function isSymbol(value) {
  21073. return typeof value == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;
  21074. }
  21075. /**
  21076. * Checks if `value` is classified as a typed array.
  21077. *
  21078. * @static
  21079. * @memberOf _
  21080. * @since 3.0.0
  21081. * @category Lang
  21082. * @param {*} value The value to check.
  21083. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  21084. * @example
  21085. *
  21086. * _.isTypedArray(new Uint8Array);
  21087. * // => true
  21088. *
  21089. * _.isTypedArray([]);
  21090. * // => false
  21091. */
  21092. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  21093. /**
  21094. * Converts `value` to a string. An empty string is returned for `null`
  21095. * and `undefined` values. The sign of `-0` is preserved.
  21096. *
  21097. * @static
  21098. * @memberOf _
  21099. * @since 4.0.0
  21100. * @category Lang
  21101. * @param {*} value The value to process.
  21102. * @returns {string} Returns the string.
  21103. * @example
  21104. *
  21105. * _.toString(null);
  21106. * // => ''
  21107. *
  21108. * _.toString(-0);
  21109. * // => '-0'
  21110. *
  21111. * _.toString([1, 2, 3]);
  21112. * // => '1,2,3'
  21113. */
  21114. function toString(value) {
  21115. return value == null ? '' : baseToString(value);
  21116. }
  21117. /**
  21118. * Gets the value at `path` of `object`. If the resolved value is
  21119. * `undefined`, the `defaultValue` is returned in its place.
  21120. *
  21121. * @static
  21122. * @memberOf _
  21123. * @since 3.7.0
  21124. * @category Object
  21125. * @param {Object} object The object to query.
  21126. * @param {Array|string} path The path of the property to get.
  21127. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  21128. * @returns {*} Returns the resolved value.
  21129. * @example
  21130. *
  21131. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  21132. *
  21133. * _.get(object, 'a[0].b.c');
  21134. * // => 3
  21135. *
  21136. * _.get(object, ['a', '0', 'b', 'c']);
  21137. * // => 3
  21138. *
  21139. * _.get(object, 'a.b.c', 'default');
  21140. * // => 'default'
  21141. */
  21142. function get(object, path, defaultValue) {
  21143. var result = object == null ? undefined : baseGet(object, path);
  21144. return result === undefined ? defaultValue : result;
  21145. }
  21146. /**
  21147. * Checks if `path` is a direct or inherited property of `object`.
  21148. *
  21149. * @static
  21150. * @memberOf _
  21151. * @since 4.0.0
  21152. * @category Object
  21153. * @param {Object} object The object to query.
  21154. * @param {Array|string} path The path to check.
  21155. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  21156. * @example
  21157. *
  21158. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  21159. *
  21160. * _.hasIn(object, 'a');
  21161. * // => true
  21162. *
  21163. * _.hasIn(object, 'a.b');
  21164. * // => true
  21165. *
  21166. * _.hasIn(object, ['a', 'b']);
  21167. * // => true
  21168. *
  21169. * _.hasIn(object, 'b');
  21170. * // => false
  21171. */
  21172. function hasIn(object, path) {
  21173. return object != null && hasPath(object, path, baseHasIn);
  21174. }
  21175. /**
  21176. * Creates an array of the own enumerable property names of `object`.
  21177. *
  21178. * **Note:** Non-object values are coerced to objects. See the
  21179. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  21180. * for more details.
  21181. *
  21182. * @static
  21183. * @since 0.1.0
  21184. * @memberOf _
  21185. * @category Object
  21186. * @param {Object} object The object to query.
  21187. * @returns {Array} Returns the array of property names.
  21188. * @example
  21189. *
  21190. * function Foo() {
  21191. * this.a = 1;
  21192. * this.b = 2;
  21193. * }
  21194. *
  21195. * Foo.prototype.c = 3;
  21196. *
  21197. * _.keys(new Foo);
  21198. * // => ['a', 'b'] (iteration order is not guaranteed)
  21199. *
  21200. * _.keys('hi');
  21201. * // => ['0', '1']
  21202. */
  21203. function keys(object) {
  21204. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  21205. }
  21206. /**
  21207. * This method returns the first argument it receives.
  21208. *
  21209. * @static
  21210. * @since 0.1.0
  21211. * @memberOf _
  21212. * @category Util
  21213. * @param {*} value Any value.
  21214. * @returns {*} Returns `value`.
  21215. * @example
  21216. *
  21217. * var object = { 'a': 1 };
  21218. *
  21219. * console.log(_.identity(object) === object);
  21220. * // => true
  21221. */
  21222. function identity(value) {
  21223. return value;
  21224. }
  21225. /**
  21226. * This method returns `undefined`.
  21227. *
  21228. * @static
  21229. * @memberOf _
  21230. * @since 2.3.0
  21231. * @category Util
  21232. * @example
  21233. *
  21234. * _.times(2, _.noop);
  21235. * // => [undefined, undefined]
  21236. */
  21237. function noop() {} // No operation performed.
  21238. /**
  21239. * Creates a function that returns the value at `path` of a given object.
  21240. *
  21241. * @static
  21242. * @memberOf _
  21243. * @since 2.4.0
  21244. * @category Util
  21245. * @param {Array|string} path The path of the property to get.
  21246. * @returns {Function} Returns the new accessor function.
  21247. * @example
  21248. *
  21249. * var objects = [
  21250. * { 'a': { 'b': 2 } },
  21251. * { 'a': { 'b': 1 } }
  21252. * ];
  21253. *
  21254. * _.map(objects, _.property('a.b'));
  21255. * // => [2, 1]
  21256. *
  21257. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  21258. * // => [1, 2]
  21259. */
  21260. function property(path) {
  21261. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  21262. }
  21263. module.exports = uniqBy;
  21264. });
  21265. var PENDING = 'pending';
  21266. var SETTLED = 'settled';
  21267. var FULFILLED = 'fulfilled';
  21268. var REJECTED = 'rejected';
  21269. var NOOP = function NOOP() {};
  21270. var isNode = typeof global !== 'undefined' && typeof global.process !== 'undefined' && typeof global.process.emit === 'function';
  21271. var asyncSetTimer = typeof setImmediate === 'undefined' ? setTimeout : setImmediate;
  21272. var asyncQueue = [];
  21273. var asyncTimer;
  21274. function asyncFlush() {
  21275. // run promise callbacks
  21276. for (var i = 0; i < asyncQueue.length; i++) {
  21277. asyncQueue[i][0](asyncQueue[i][1]);
  21278. } // reset async asyncQueue
  21279. asyncQueue = [];
  21280. asyncTimer = false;
  21281. }
  21282. function asyncCall(callback, arg) {
  21283. asyncQueue.push([callback, arg]);
  21284. if (!asyncTimer) {
  21285. asyncTimer = true;
  21286. asyncSetTimer(asyncFlush, 0);
  21287. }
  21288. }
  21289. function invokeResolver(resolver, promise) {
  21290. function resolvePromise(value) {
  21291. resolve$1(promise, value);
  21292. }
  21293. function rejectPromise(reason) {
  21294. reject(promise, reason);
  21295. }
  21296. try {
  21297. resolver(resolvePromise, rejectPromise);
  21298. } catch (e) {
  21299. rejectPromise(e);
  21300. }
  21301. }
  21302. function invokeCallback(subscriber) {
  21303. var owner = subscriber.owner;
  21304. var settled = owner._state;
  21305. var value = owner._data;
  21306. var callback = subscriber[settled];
  21307. var promise = subscriber.then;
  21308. if (typeof callback === 'function') {
  21309. settled = FULFILLED;
  21310. try {
  21311. value = callback(value);
  21312. } catch (e) {
  21313. reject(promise, e);
  21314. }
  21315. }
  21316. if (!handleThenable(promise, value)) {
  21317. if (settled === FULFILLED) {
  21318. resolve$1(promise, value);
  21319. }
  21320. if (settled === REJECTED) {
  21321. reject(promise, value);
  21322. }
  21323. }
  21324. }
  21325. function handleThenable(promise, value) {
  21326. var resolved;
  21327. try {
  21328. if (promise === value) {
  21329. throw new TypeError('A promises callback cannot return that same promise.');
  21330. }
  21331. if (value && (typeof value === 'function' || typeof value === 'object')) {
  21332. // then should be retrieved only once
  21333. var then = value.then;
  21334. if (typeof then === 'function') {
  21335. then.call(value, function (val) {
  21336. if (!resolved) {
  21337. resolved = true;
  21338. if (value === val) {
  21339. fulfill(promise, val);
  21340. } else {
  21341. resolve$1(promise, val);
  21342. }
  21343. }
  21344. }, function (reason) {
  21345. if (!resolved) {
  21346. resolved = true;
  21347. reject(promise, reason);
  21348. }
  21349. });
  21350. return true;
  21351. }
  21352. }
  21353. } catch (e) {
  21354. if (!resolved) {
  21355. reject(promise, e);
  21356. }
  21357. return true;
  21358. }
  21359. return false;
  21360. }
  21361. function resolve$1(promise, value) {
  21362. if (promise === value || !handleThenable(promise, value)) {
  21363. fulfill(promise, value);
  21364. }
  21365. }
  21366. function fulfill(promise, value) {
  21367. if (promise._state === PENDING) {
  21368. promise._state = SETTLED;
  21369. promise._data = value;
  21370. asyncCall(publishFulfillment, promise);
  21371. }
  21372. }
  21373. function reject(promise, reason) {
  21374. if (promise._state === PENDING) {
  21375. promise._state = SETTLED;
  21376. promise._data = reason;
  21377. asyncCall(publishRejection, promise);
  21378. }
  21379. }
  21380. function publish(promise) {
  21381. promise._then = promise._then.forEach(invokeCallback);
  21382. }
  21383. function publishFulfillment(promise) {
  21384. promise._state = FULFILLED;
  21385. publish(promise);
  21386. }
  21387. function publishRejection(promise) {
  21388. promise._state = REJECTED;
  21389. publish(promise);
  21390. if (!promise._handled && isNode) {
  21391. global.process.emit('unhandledRejection', promise._data, promise);
  21392. }
  21393. }
  21394. function notifyRejectionHandled(promise) {
  21395. global.process.emit('rejectionHandled', promise);
  21396. }
  21397. /**
  21398. * @class
  21399. */
  21400. function Promise$1(resolver) {
  21401. if (typeof resolver !== 'function') {
  21402. throw new TypeError('Promise resolver ' + resolver + ' is not a function');
  21403. }
  21404. if (this instanceof Promise$1 === false) {
  21405. throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object constructor cannot be called as a function.');
  21406. }
  21407. this._then = [];
  21408. invokeResolver(resolver, this);
  21409. }
  21410. Promise$1.prototype = {
  21411. constructor: Promise$1,
  21412. _state: PENDING,
  21413. _then: null,
  21414. _data: undefined,
  21415. _handled: false,
  21416. then: function then(onFulfillment, onRejection) {
  21417. var subscriber = {
  21418. owner: this,
  21419. then: new this.constructor(NOOP),
  21420. fulfilled: onFulfillment,
  21421. rejected: onRejection
  21422. };
  21423. if ((onRejection || onFulfillment) && !this._handled) {
  21424. this._handled = true;
  21425. if (this._state === REJECTED && isNode) {
  21426. asyncCall(notifyRejectionHandled, this);
  21427. }
  21428. }
  21429. if (this._state === FULFILLED || this._state === REJECTED) {
  21430. // already resolved, call callback async
  21431. asyncCall(invokeCallback, subscriber);
  21432. } else {
  21433. // subscribe
  21434. this._then.push(subscriber);
  21435. }
  21436. return subscriber.then;
  21437. },
  21438. catch: function _catch(onRejection) {
  21439. return this.then(null, onRejection);
  21440. }
  21441. };
  21442. Promise$1.all = function (promises) {
  21443. if (!Array.isArray(promises)) {
  21444. throw new TypeError('You must pass an array to Promise.all().');
  21445. }
  21446. return new Promise$1(function (resolve, reject) {
  21447. var results = [];
  21448. var remaining = 0;
  21449. function resolver(index) {
  21450. remaining++;
  21451. return function (value) {
  21452. results[index] = value;
  21453. if (! --remaining) {
  21454. resolve(results);
  21455. }
  21456. };
  21457. }
  21458. for (var i = 0, promise; i < promises.length; i++) {
  21459. promise = promises[i];
  21460. if (promise && typeof promise.then === 'function') {
  21461. promise.then(resolver(i), reject);
  21462. } else {
  21463. results[i] = promise;
  21464. }
  21465. }
  21466. if (!remaining) {
  21467. resolve(results);
  21468. }
  21469. });
  21470. };
  21471. Promise$1.race = function (promises) {
  21472. if (!Array.isArray(promises)) {
  21473. throw new TypeError('You must pass an array to Promise.race().');
  21474. }
  21475. return new Promise$1(function (resolve, reject) {
  21476. for (var i = 0, promise; i < promises.length; i++) {
  21477. promise = promises[i];
  21478. if (promise && typeof promise.then === 'function') {
  21479. promise.then(resolve, reject);
  21480. } else {
  21481. resolve(promise);
  21482. }
  21483. }
  21484. });
  21485. };
  21486. Promise$1.resolve = function (value) {
  21487. if (value && typeof value === 'object' && value.constructor === Promise$1) {
  21488. return value;
  21489. }
  21490. return new Promise$1(function (resolve) {
  21491. resolve(value);
  21492. });
  21493. };
  21494. Promise$1.reject = function (reason) {
  21495. return new Promise$1(function (resolve, reject) {
  21496. reject(reason);
  21497. });
  21498. };
  21499. var pinkie = Promise$1;
  21500. var pinkiePromise = typeof Promise === 'function' ? Promise : pinkie;
  21501. var arrayUniq = createCommonjsModule(function (module) {
  21502. // 1 - no Set type is defined
  21503. function uniqNoSet(arr) {
  21504. var ret = [];
  21505. for (var i = 0; i < arr.length; i++) {
  21506. if (ret.indexOf(arr[i]) === -1) {
  21507. ret.push(arr[i]);
  21508. }
  21509. }
  21510. return ret;
  21511. } // 2 - a simple Set type is defined
  21512. function uniqSet(arr) {
  21513. var seen = new Set();
  21514. return arr.filter(function (el) {
  21515. if (!seen.has(el)) {
  21516. seen.add(el);
  21517. return true;
  21518. }
  21519. return false;
  21520. });
  21521. } // 3 - a standard Set type is defined and it has a forEach method
  21522. function uniqSetWithForEach(arr) {
  21523. var ret = [];
  21524. new Set(arr).forEach(function (el) {
  21525. ret.push(el);
  21526. });
  21527. return ret;
  21528. } // V8 currently has a broken implementation
  21529. // https://github.com/joyent/node/issues/8449
  21530. function doesForEachActuallyWork() {
  21531. var ret = false;
  21532. new Set([true]).forEach(function (el) {
  21533. ret = el;
  21534. });
  21535. return ret === true;
  21536. }
  21537. if ('Set' in global) {
  21538. if (typeof Set.prototype.forEach === 'function' && doesForEachActuallyWork()) {
  21539. module.exports = uniqSetWithForEach;
  21540. } else {
  21541. module.exports = uniqSet;
  21542. }
  21543. } else {
  21544. module.exports = uniqNoSet;
  21545. }
  21546. });
  21547. var arrayUnion = function arrayUnion() {
  21548. return arrayUniq([].concat.apply([], arguments));
  21549. };
  21550. /*
  21551. object-assign
  21552. (c) Sindre Sorhus
  21553. @license MIT
  21554. */
  21555. /* eslint-disable no-unused-vars */
  21556. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  21557. var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  21558. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  21559. function toObject(val) {
  21560. if (val === null || val === undefined) {
  21561. throw new TypeError('Object.assign cannot be called with null or undefined');
  21562. }
  21563. return Object(val);
  21564. }
  21565. function shouldUseNative() {
  21566. try {
  21567. if (!Object.assign) {
  21568. return false;
  21569. } // Detect buggy property enumeration order in older V8 versions.
  21570. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  21571. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  21572. test1[5] = 'de';
  21573. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  21574. return false;
  21575. } // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  21576. var test2 = {};
  21577. for (var i = 0; i < 10; i++) {
  21578. test2['_' + String.fromCharCode(i)] = i;
  21579. }
  21580. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  21581. return test2[n];
  21582. });
  21583. if (order2.join('') !== '0123456789') {
  21584. return false;
  21585. } // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  21586. var test3 = {};
  21587. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  21588. test3[letter] = letter;
  21589. });
  21590. if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') {
  21591. return false;
  21592. }
  21593. return true;
  21594. } catch (err) {
  21595. // We don't expect any of the above to throw, but better to be safe.
  21596. return false;
  21597. }
  21598. }
  21599. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  21600. var from;
  21601. var to = toObject(target);
  21602. var symbols;
  21603. for (var s = 1; s < arguments.length; s++) {
  21604. from = Object(arguments[s]);
  21605. for (var key in from) {
  21606. if (hasOwnProperty$2.call(from, key)) {
  21607. to[key] = from[key];
  21608. }
  21609. }
  21610. if (getOwnPropertySymbols) {
  21611. symbols = getOwnPropertySymbols(from);
  21612. for (var i = 0; i < symbols.length; i++) {
  21613. if (propIsEnumerable.call(from, symbols[i])) {
  21614. to[symbols[i]] = from[symbols[i]];
  21615. }
  21616. }
  21617. }
  21618. }
  21619. return to;
  21620. };
  21621. //
  21622. // Permission is hereby granted, free of charge, to any person obtaining a
  21623. // copy of this software and associated documentation files (the
  21624. // "Software"), to deal in the Software without restriction, including
  21625. // without limitation the rights to use, copy, modify, merge, publish,
  21626. // distribute, sublicense, and/or sell copies of the Software, and to permit
  21627. // persons to whom the Software is furnished to do so, subject to the
  21628. // following conditions:
  21629. //
  21630. // The above copyright notice and this permission notice shall be included
  21631. // in all copies or substantial portions of the Software.
  21632. //
  21633. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21634. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21635. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  21636. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  21637. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21638. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  21639. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  21640. var isWindows = process.platform === 'win32'; // JavaScript implementation of realpath, ported from node pre-v6
  21641. var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
  21642. function rethrow() {
  21643. // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
  21644. // is fairly slow to generate.
  21645. var callback;
  21646. if (DEBUG) {
  21647. var backtrace = new Error();
  21648. callback = debugCallback;
  21649. } else callback = missingCallback;
  21650. return callback;
  21651. function debugCallback(err) {
  21652. if (err) {
  21653. backtrace.message = err.message;
  21654. err = backtrace;
  21655. missingCallback(err);
  21656. }
  21657. }
  21658. function missingCallback(err) {
  21659. if (err) {
  21660. if (process.throwDeprecation) throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
  21661. else if (!process.noDeprecation) {
  21662. var msg = 'fs: missing callback ' + (err.stack || err.message);
  21663. if (process.traceDeprecation) console.trace(msg);else console.error(msg);
  21664. }
  21665. }
  21666. }
  21667. }
  21668. function maybeCallback(cb) {
  21669. return typeof cb === 'function' ? cb : rethrow();
  21670. }
  21671. var normalize$3 = path$2.normalize; // Regexp that finds the next partion of a (partial) path
  21672. // result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
  21673. if (isWindows) {
  21674. var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
  21675. } else {
  21676. var nextPartRe = /(.*?)(?:[\/]+|$)/g;
  21677. } // Regex to find the device root, including trailing slash. E.g. 'c:\\'.
  21678. if (isWindows) {
  21679. var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
  21680. } else {
  21681. var splitRootRe = /^[\/]*/;
  21682. }
  21683. var realpathSync = function realpathSync(p, cache) {
  21684. // make p is absolute
  21685. p = path$2.resolve(p);
  21686. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  21687. return cache[p];
  21688. }
  21689. var original = p,
  21690. seenLinks = {},
  21691. knownHard = {}; // current character position in p
  21692. var pos; // the partial path so far, including a trailing slash if any
  21693. var current; // the partial path without a trailing slash (except when pointing at a root)
  21694. var base; // the partial path scanned in the previous round, with slash
  21695. var previous;
  21696. start();
  21697. function start() {
  21698. // Skip over roots
  21699. var m = splitRootRe.exec(p);
  21700. pos = m[0].length;
  21701. current = m[0];
  21702. base = m[0];
  21703. previous = ''; // On windows, check that the root exists. On unix there is no need.
  21704. if (isWindows && !knownHard[base]) {
  21705. fs$1.lstatSync(base);
  21706. knownHard[base] = true;
  21707. }
  21708. } // walk down the path, swapping out linked pathparts for their real
  21709. // values
  21710. // NB: p.length changes.
  21711. while (pos < p.length) {
  21712. // find the next part
  21713. nextPartRe.lastIndex = pos;
  21714. var result = nextPartRe.exec(p);
  21715. previous = current;
  21716. current += result[0];
  21717. base = previous + result[1];
  21718. pos = nextPartRe.lastIndex; // continue if not a symlink
  21719. if (knownHard[base] || cache && cache[base] === base) {
  21720. continue;
  21721. }
  21722. var resolvedLink;
  21723. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  21724. // some known symbolic link. no need to stat again.
  21725. resolvedLink = cache[base];
  21726. } else {
  21727. var stat = fs$1.lstatSync(base);
  21728. if (!stat.isSymbolicLink()) {
  21729. knownHard[base] = true;
  21730. if (cache) cache[base] = base;
  21731. continue;
  21732. } // read the link if it wasn't read before
  21733. // dev/ino always return 0 on windows, so skip the check.
  21734. var linkTarget = null;
  21735. if (!isWindows) {
  21736. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  21737. if (seenLinks.hasOwnProperty(id)) {
  21738. linkTarget = seenLinks[id];
  21739. }
  21740. }
  21741. if (linkTarget === null) {
  21742. fs$1.statSync(base);
  21743. linkTarget = fs$1.readlinkSync(base);
  21744. }
  21745. resolvedLink = path$2.resolve(previous, linkTarget); // track this, if given a cache.
  21746. if (cache) cache[base] = resolvedLink;
  21747. if (!isWindows) seenLinks[id] = linkTarget;
  21748. } // resolve the link, then start over
  21749. p = path$2.resolve(resolvedLink, p.slice(pos));
  21750. start();
  21751. }
  21752. if (cache) cache[original] = p;
  21753. return p;
  21754. };
  21755. var realpath = function realpath(p, cache, cb) {
  21756. if (typeof cb !== 'function') {
  21757. cb = maybeCallback(cache);
  21758. cache = null;
  21759. } // make p is absolute
  21760. p = path$2.resolve(p);
  21761. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  21762. return process.nextTick(cb.bind(null, null, cache[p]));
  21763. }
  21764. var original = p,
  21765. seenLinks = {},
  21766. knownHard = {}; // current character position in p
  21767. var pos; // the partial path so far, including a trailing slash if any
  21768. var current; // the partial path without a trailing slash (except when pointing at a root)
  21769. var base; // the partial path scanned in the previous round, with slash
  21770. var previous;
  21771. start();
  21772. function start() {
  21773. // Skip over roots
  21774. var m = splitRootRe.exec(p);
  21775. pos = m[0].length;
  21776. current = m[0];
  21777. base = m[0];
  21778. previous = ''; // On windows, check that the root exists. On unix there is no need.
  21779. if (isWindows && !knownHard[base]) {
  21780. fs$1.lstat(base, function (err) {
  21781. if (err) return cb(err);
  21782. knownHard[base] = true;
  21783. LOOP();
  21784. });
  21785. } else {
  21786. process.nextTick(LOOP);
  21787. }
  21788. } // walk down the path, swapping out linked pathparts for their real
  21789. // values
  21790. function LOOP() {
  21791. // stop if scanned past end of path
  21792. if (pos >= p.length) {
  21793. if (cache) cache[original] = p;
  21794. return cb(null, p);
  21795. } // find the next part
  21796. nextPartRe.lastIndex = pos;
  21797. var result = nextPartRe.exec(p);
  21798. previous = current;
  21799. current += result[0];
  21800. base = previous + result[1];
  21801. pos = nextPartRe.lastIndex; // continue if not a symlink
  21802. if (knownHard[base] || cache && cache[base] === base) {
  21803. return process.nextTick(LOOP);
  21804. }
  21805. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  21806. // known symbolic link. no need to stat again.
  21807. return gotResolvedLink(cache[base]);
  21808. }
  21809. return fs$1.lstat(base, gotStat);
  21810. }
  21811. function gotStat(err, stat) {
  21812. if (err) return cb(err); // if not a symlink, skip to the next path part
  21813. if (!stat.isSymbolicLink()) {
  21814. knownHard[base] = true;
  21815. if (cache) cache[base] = base;
  21816. return process.nextTick(LOOP);
  21817. } // stat & read the link if not read before
  21818. // call gotTarget as soon as the link target is known
  21819. // dev/ino always return 0 on windows, so skip the check.
  21820. if (!isWindows) {
  21821. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  21822. if (seenLinks.hasOwnProperty(id)) {
  21823. return gotTarget(null, seenLinks[id], base);
  21824. }
  21825. }
  21826. fs$1.stat(base, function (err) {
  21827. if (err) return cb(err);
  21828. fs$1.readlink(base, function (err, target) {
  21829. if (!isWindows) seenLinks[id] = target;
  21830. gotTarget(err, target);
  21831. });
  21832. });
  21833. }
  21834. function gotTarget(err, target, base) {
  21835. if (err) return cb(err);
  21836. var resolvedLink = path$2.resolve(previous, target);
  21837. if (cache) cache[base] = resolvedLink;
  21838. gotResolvedLink(resolvedLink);
  21839. }
  21840. function gotResolvedLink(resolvedLink) {
  21841. // resolve the link, then start over
  21842. p = path$2.resolve(resolvedLink, p.slice(pos));
  21843. start();
  21844. }
  21845. };
  21846. var old = {
  21847. realpathSync: realpathSync,
  21848. realpath: realpath
  21849. };
  21850. var fs_realpath = realpath$1;
  21851. realpath$1.realpath = realpath$1;
  21852. realpath$1.sync = realpathSync$1;
  21853. realpath$1.realpathSync = realpathSync$1;
  21854. realpath$1.monkeypatch = monkeypatch;
  21855. realpath$1.unmonkeypatch = unmonkeypatch;
  21856. var origRealpath = fs$1.realpath;
  21857. var origRealpathSync = fs$1.realpathSync;
  21858. var version$2 = process.version;
  21859. var ok = /^v[0-5]\./.test(version$2);
  21860. function newError(er) {
  21861. return er && er.syscall === 'realpath' && (er.code === 'ELOOP' || er.code === 'ENOMEM' || er.code === 'ENAMETOOLONG');
  21862. }
  21863. function realpath$1(p, cache, cb) {
  21864. if (ok) {
  21865. return origRealpath(p, cache, cb);
  21866. }
  21867. if (typeof cache === 'function') {
  21868. cb = cache;
  21869. cache = null;
  21870. }
  21871. origRealpath(p, cache, function (er, result) {
  21872. if (newError(er)) {
  21873. old.realpath(p, cache, cb);
  21874. } else {
  21875. cb(er, result);
  21876. }
  21877. });
  21878. }
  21879. function realpathSync$1(p, cache) {
  21880. if (ok) {
  21881. return origRealpathSync(p, cache);
  21882. }
  21883. try {
  21884. return origRealpathSync(p, cache);
  21885. } catch (er) {
  21886. if (newError(er)) {
  21887. return old.realpathSync(p, cache);
  21888. } else {
  21889. throw er;
  21890. }
  21891. }
  21892. }
  21893. function monkeypatch() {
  21894. fs$1.realpath = realpath$1;
  21895. fs$1.realpathSync = realpathSync$1;
  21896. }
  21897. function unmonkeypatch() {
  21898. fs$1.realpath = origRealpath;
  21899. fs$1.realpathSync = origRealpathSync;
  21900. }
  21901. var inherits_browser = createCommonjsModule(function (module) {
  21902. if (typeof Object.create === 'function') {
  21903. // implementation from standard node.js 'util' module
  21904. module.exports = function inherits(ctor, superCtor) {
  21905. if (superCtor) {
  21906. ctor.super_ = superCtor;
  21907. ctor.prototype = Object.create(superCtor.prototype, {
  21908. constructor: {
  21909. value: ctor,
  21910. enumerable: false,
  21911. writable: true,
  21912. configurable: true
  21913. }
  21914. });
  21915. }
  21916. };
  21917. } else {
  21918. // old school shim for old browsers
  21919. module.exports = function inherits(ctor, superCtor) {
  21920. if (superCtor) {
  21921. ctor.super_ = superCtor;
  21922. var TempCtor = function TempCtor() {};
  21923. TempCtor.prototype = superCtor.prototype;
  21924. ctor.prototype = new TempCtor();
  21925. ctor.prototype.constructor = ctor;
  21926. }
  21927. };
  21928. }
  21929. });
  21930. var inherits = createCommonjsModule(function (module) {
  21931. try {
  21932. var util = util$2;
  21933. /* istanbul ignore next */
  21934. if (typeof util.inherits !== 'function') throw '';
  21935. module.exports = util.inherits;
  21936. } catch (e) {
  21937. /* istanbul ignore next */
  21938. module.exports = inherits_browser;
  21939. }
  21940. });
  21941. function posix(path) {
  21942. return path.charAt(0) === '/';
  21943. }
  21944. function win32(path) {
  21945. // https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
  21946. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
  21947. var result = splitDeviceRe.exec(path);
  21948. var device = result[1] || '';
  21949. var isUnc = Boolean(device && device.charAt(1) !== ':'); // UNC paths are always absolute
  21950. return Boolean(result[2] || isUnc);
  21951. }
  21952. var pathIsAbsolute = process.platform === 'win32' ? win32 : posix;
  21953. var posix_1 = posix;
  21954. var win32_1 = win32;
  21955. pathIsAbsolute.posix = posix_1;
  21956. pathIsAbsolute.win32 = win32_1;
  21957. var alphasort_1 = alphasort;
  21958. var alphasorti_1 = alphasorti;
  21959. var setopts_1 = setopts;
  21960. var ownProp_1 = ownProp;
  21961. var makeAbs_1 = makeAbs;
  21962. var finish_1 = finish;
  21963. var mark_1 = mark;
  21964. var isIgnored_1 = isIgnored;
  21965. var childrenIgnored_1 = childrenIgnored;
  21966. function ownProp(obj, field) {
  21967. return Object.prototype.hasOwnProperty.call(obj, field);
  21968. }
  21969. var Minimatch$1 = minimatch_1.Minimatch;
  21970. function alphasorti(a, b) {
  21971. return a.toLowerCase().localeCompare(b.toLowerCase());
  21972. }
  21973. function alphasort(a, b) {
  21974. return a.localeCompare(b);
  21975. }
  21976. function setupIgnores(self, options) {
  21977. self.ignore = options.ignore || [];
  21978. if (!Array.isArray(self.ignore)) self.ignore = [self.ignore];
  21979. if (self.ignore.length) {
  21980. self.ignore = self.ignore.map(ignoreMap);
  21981. }
  21982. } // ignore patterns are always in dot:true mode.
  21983. function ignoreMap(pattern) {
  21984. var gmatcher = null;
  21985. if (pattern.slice(-3) === '/**') {
  21986. var gpattern = pattern.replace(/(\/\*\*)+$/, '');
  21987. gmatcher = new Minimatch$1(gpattern, {
  21988. dot: true
  21989. });
  21990. }
  21991. return {
  21992. matcher: new Minimatch$1(pattern, {
  21993. dot: true
  21994. }),
  21995. gmatcher: gmatcher
  21996. };
  21997. }
  21998. function setopts(self, pattern, options) {
  21999. if (!options) options = {}; // base-matching: just use globstar for that.
  22000. if (options.matchBase && -1 === pattern.indexOf("/")) {
  22001. if (options.noglobstar) {
  22002. throw new Error("base matching requires globstar");
  22003. }
  22004. pattern = "**/" + pattern;
  22005. }
  22006. self.silent = !!options.silent;
  22007. self.pattern = pattern;
  22008. self.strict = options.strict !== false;
  22009. self.realpath = !!options.realpath;
  22010. self.realpathCache = options.realpathCache || Object.create(null);
  22011. self.follow = !!options.follow;
  22012. self.dot = !!options.dot;
  22013. self.mark = !!options.mark;
  22014. self.nodir = !!options.nodir;
  22015. if (self.nodir) self.mark = true;
  22016. self.sync = !!options.sync;
  22017. self.nounique = !!options.nounique;
  22018. self.nonull = !!options.nonull;
  22019. self.nosort = !!options.nosort;
  22020. self.nocase = !!options.nocase;
  22021. self.stat = !!options.stat;
  22022. self.noprocess = !!options.noprocess;
  22023. self.absolute = !!options.absolute;
  22024. self.maxLength = options.maxLength || Infinity;
  22025. self.cache = options.cache || Object.create(null);
  22026. self.statCache = options.statCache || Object.create(null);
  22027. self.symlinks = options.symlinks || Object.create(null);
  22028. setupIgnores(self, options);
  22029. self.changedCwd = false;
  22030. var cwd = process.cwd();
  22031. if (!ownProp(options, "cwd")) self.cwd = cwd;else {
  22032. self.cwd = path$2.resolve(options.cwd);
  22033. self.changedCwd = self.cwd !== cwd;
  22034. }
  22035. self.root = options.root || path$2.resolve(self.cwd, "/");
  22036. self.root = path$2.resolve(self.root);
  22037. if (process.platform === "win32") self.root = self.root.replace(/\\/g, "/"); // TODO: is an absolute `cwd` supposed to be resolved against `root`?
  22038. // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
  22039. self.cwdAbs = pathIsAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
  22040. if (process.platform === "win32") self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
  22041. self.nomount = !!options.nomount; // disable comments and negation in Minimatch.
  22042. // Note that they are not supported in Glob itself anyway.
  22043. options.nonegate = true;
  22044. options.nocomment = true;
  22045. self.minimatch = new Minimatch$1(pattern, options);
  22046. self.options = self.minimatch.options;
  22047. }
  22048. function finish(self) {
  22049. var nou = self.nounique;
  22050. var all = nou ? [] : Object.create(null);
  22051. for (var i = 0, l = self.matches.length; i < l; i++) {
  22052. var matches = self.matches[i];
  22053. if (!matches || Object.keys(matches).length === 0) {
  22054. if (self.nonull) {
  22055. // do like the shell, and spit out the literal glob
  22056. var literal = self.minimatch.globSet[i];
  22057. if (nou) all.push(literal);else all[literal] = true;
  22058. }
  22059. } else {
  22060. // had matches
  22061. var m = Object.keys(matches);
  22062. if (nou) all.push.apply(all, m);else m.forEach(function (m) {
  22063. all[m] = true;
  22064. });
  22065. }
  22066. }
  22067. if (!nou) all = Object.keys(all);
  22068. if (!self.nosort) all = all.sort(self.nocase ? alphasorti : alphasort); // at *some* point we statted all of these
  22069. if (self.mark) {
  22070. for (var i = 0; i < all.length; i++) {
  22071. all[i] = self._mark(all[i]);
  22072. }
  22073. if (self.nodir) {
  22074. all = all.filter(function (e) {
  22075. var notDir = !/\/$/.test(e);
  22076. var c = self.cache[e] || self.cache[makeAbs(self, e)];
  22077. if (notDir && c) notDir = c !== 'DIR' && !Array.isArray(c);
  22078. return notDir;
  22079. });
  22080. }
  22081. }
  22082. if (self.ignore.length) all = all.filter(function (m) {
  22083. return !isIgnored(self, m);
  22084. });
  22085. self.found = all;
  22086. }
  22087. function mark(self, p) {
  22088. var abs = makeAbs(self, p);
  22089. var c = self.cache[abs];
  22090. var m = p;
  22091. if (c) {
  22092. var isDir = c === 'DIR' || Array.isArray(c);
  22093. var slash = p.slice(-1) === '/';
  22094. if (isDir && !slash) m += '/';else if (!isDir && slash) m = m.slice(0, -1);
  22095. if (m !== p) {
  22096. var mabs = makeAbs(self, m);
  22097. self.statCache[mabs] = self.statCache[abs];
  22098. self.cache[mabs] = self.cache[abs];
  22099. }
  22100. }
  22101. return m;
  22102. } // lotta situps...
  22103. function makeAbs(self, f) {
  22104. var abs = f;
  22105. if (f.charAt(0) === '/') {
  22106. abs = path$2.join(self.root, f);
  22107. } else if (pathIsAbsolute(f) || f === '') {
  22108. abs = f;
  22109. } else if (self.changedCwd) {
  22110. abs = path$2.resolve(self.cwd, f);
  22111. } else {
  22112. abs = path$2.resolve(f);
  22113. }
  22114. if (process.platform === 'win32') abs = abs.replace(/\\/g, '/');
  22115. return abs;
  22116. } // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
  22117. // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
  22118. function isIgnored(self, path) {
  22119. if (!self.ignore.length) return false;
  22120. return self.ignore.some(function (item) {
  22121. return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path));
  22122. });
  22123. }
  22124. function childrenIgnored(self, path) {
  22125. if (!self.ignore.length) return false;
  22126. return self.ignore.some(function (item) {
  22127. return !!(item.gmatcher && item.gmatcher.match(path));
  22128. });
  22129. }
  22130. var common$2 = {
  22131. alphasort: alphasort_1,
  22132. alphasorti: alphasorti_1,
  22133. setopts: setopts_1,
  22134. ownProp: ownProp_1,
  22135. makeAbs: makeAbs_1,
  22136. finish: finish_1,
  22137. mark: mark_1,
  22138. isIgnored: isIgnored_1,
  22139. childrenIgnored: childrenIgnored_1
  22140. };
  22141. var sync$1 = globSync;
  22142. globSync.GlobSync = GlobSync;
  22143. var setopts$1 = common$2.setopts;
  22144. var ownProp$1 = common$2.ownProp;
  22145. var childrenIgnored$1 = common$2.childrenIgnored;
  22146. var isIgnored$1 = common$2.isIgnored;
  22147. function globSync(pattern, options) {
  22148. if (typeof options === 'function' || arguments.length === 3) throw new TypeError('callback provided to sync glob\n' + 'See: https://github.com/isaacs/node-glob/issues/167');
  22149. return new GlobSync(pattern, options).found;
  22150. }
  22151. function GlobSync(pattern, options) {
  22152. if (!pattern) throw new Error('must provide pattern');
  22153. if (typeof options === 'function' || arguments.length === 3) throw new TypeError('callback provided to sync glob\n' + 'See: https://github.com/isaacs/node-glob/issues/167');
  22154. if (!(this instanceof GlobSync)) return new GlobSync(pattern, options);
  22155. setopts$1(this, pattern, options);
  22156. if (this.noprocess) return this;
  22157. var n = this.minimatch.set.length;
  22158. this.matches = new Array(n);
  22159. for (var i = 0; i < n; i++) {
  22160. this._process(this.minimatch.set[i], i, false);
  22161. }
  22162. this._finish();
  22163. }
  22164. GlobSync.prototype._finish = function () {
  22165. assert$1(this instanceof GlobSync);
  22166. if (this.realpath) {
  22167. var self = this;
  22168. this.matches.forEach(function (matchset, index) {
  22169. var set = self.matches[index] = Object.create(null);
  22170. for (var p in matchset) {
  22171. try {
  22172. p = self._makeAbs(p);
  22173. var real = fs_realpath.realpathSync(p, self.realpathCache);
  22174. set[real] = true;
  22175. } catch (er) {
  22176. if (er.syscall === 'stat') set[self._makeAbs(p)] = true;else throw er;
  22177. }
  22178. }
  22179. });
  22180. }
  22181. common$2.finish(this);
  22182. };
  22183. GlobSync.prototype._process = function (pattern, index, inGlobStar) {
  22184. assert$1(this instanceof GlobSync); // Get the first [n] parts of pattern that are all strings.
  22185. var n = 0;
  22186. while (typeof pattern[n] === 'string') {
  22187. n++;
  22188. } // now n is the index of the first one that is *not* a string.
  22189. // See if there's anything else
  22190. var prefix;
  22191. switch (n) {
  22192. // if not, then this is rather simple
  22193. case pattern.length:
  22194. this._processSimple(pattern.join('/'), index);
  22195. return;
  22196. case 0:
  22197. // pattern *starts* with some non-trivial item.
  22198. // going to readdir(cwd), but not include the prefix in matches.
  22199. prefix = null;
  22200. break;
  22201. default:
  22202. // pattern has some string bits in the front.
  22203. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  22204. // or 'relative' like '../baz'
  22205. prefix = pattern.slice(0, n).join('/');
  22206. break;
  22207. }
  22208. var remain = pattern.slice(n); // get the list of entries.
  22209. var read;
  22210. if (prefix === null) read = '.';else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  22211. if (!prefix || !pathIsAbsolute(prefix)) prefix = '/' + prefix;
  22212. read = prefix;
  22213. } else read = prefix;
  22214. var abs = this._makeAbs(read); //if ignored, skip processing
  22215. if (childrenIgnored$1(this, read)) return;
  22216. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  22217. if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar);
  22218. };
  22219. GlobSync.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
  22220. var entries = this._readdir(abs, inGlobStar); // if the abs isn't a dir, then nothing can match!
  22221. if (!entries) return; // It will only match dot entries if it starts with a dot, or if
  22222. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  22223. var pn = remain[0];
  22224. var negate = !!this.minimatch.negate;
  22225. var rawGlob = pn._glob;
  22226. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  22227. var matchedEntries = [];
  22228. for (var i = 0; i < entries.length; i++) {
  22229. var e = entries[i];
  22230. if (e.charAt(0) !== '.' || dotOk) {
  22231. var m;
  22232. if (negate && !prefix) {
  22233. m = !e.match(pn);
  22234. } else {
  22235. m = e.match(pn);
  22236. }
  22237. if (m) matchedEntries.push(e);
  22238. }
  22239. }
  22240. var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
  22241. if (len === 0) return; // if this is the last remaining pattern bit, then no need for
  22242. // an additional stat *unless* the user has specified mark or
  22243. // stat explicitly. We know they exist, since readdir returned
  22244. // them.
  22245. if (remain.length === 1 && !this.mark && !this.stat) {
  22246. if (!this.matches[index]) this.matches[index] = Object.create(null);
  22247. for (var i = 0; i < len; i++) {
  22248. var e = matchedEntries[i];
  22249. if (prefix) {
  22250. if (prefix.slice(-1) !== '/') e = prefix + '/' + e;else e = prefix + e;
  22251. }
  22252. if (e.charAt(0) === '/' && !this.nomount) {
  22253. e = path$2.join(this.root, e);
  22254. }
  22255. this._emitMatch(index, e);
  22256. } // This was the last one, and no stats were needed
  22257. return;
  22258. } // now test all matched entries as stand-ins for that part
  22259. // of the pattern.
  22260. remain.shift();
  22261. for (var i = 0; i < len; i++) {
  22262. var e = matchedEntries[i];
  22263. var newPattern;
  22264. if (prefix) newPattern = [prefix, e];else newPattern = [e];
  22265. this._process(newPattern.concat(remain), index, inGlobStar);
  22266. }
  22267. };
  22268. GlobSync.prototype._emitMatch = function (index, e) {
  22269. if (isIgnored$1(this, e)) return;
  22270. var abs = this._makeAbs(e);
  22271. if (this.mark) e = this._mark(e);
  22272. if (this.absolute) {
  22273. e = abs;
  22274. }
  22275. if (this.matches[index][e]) return;
  22276. if (this.nodir) {
  22277. var c = this.cache[abs];
  22278. if (c === 'DIR' || Array.isArray(c)) return;
  22279. }
  22280. this.matches[index][e] = true;
  22281. if (this.stat) this._stat(e);
  22282. };
  22283. GlobSync.prototype._readdirInGlobStar = function (abs) {
  22284. // follow all symlinked directories forever
  22285. // just proceed as if this is a non-globstar situation
  22286. if (this.follow) return this._readdir(abs, false);
  22287. var entries;
  22288. var lstat;
  22289. try {
  22290. lstat = fs$1.lstatSync(abs);
  22291. } catch (er) {
  22292. if (er.code === 'ENOENT') {
  22293. // lstat failed, doesn't exist
  22294. return null;
  22295. }
  22296. }
  22297. var isSym = lstat && lstat.isSymbolicLink();
  22298. this.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
  22299. // don't bother doing a readdir in that case.
  22300. if (!isSym && lstat && !lstat.isDirectory()) this.cache[abs] = 'FILE';else entries = this._readdir(abs, false);
  22301. return entries;
  22302. };
  22303. GlobSync.prototype._readdir = function (abs, inGlobStar) {
  22304. if (inGlobStar && !ownProp$1(this.symlinks, abs)) return this._readdirInGlobStar(abs);
  22305. if (ownProp$1(this.cache, abs)) {
  22306. var c = this.cache[abs];
  22307. if (!c || c === 'FILE') return null;
  22308. if (Array.isArray(c)) return c;
  22309. }
  22310. try {
  22311. return this._readdirEntries(abs, fs$1.readdirSync(abs));
  22312. } catch (er) {
  22313. this._readdirError(abs, er);
  22314. return null;
  22315. }
  22316. };
  22317. GlobSync.prototype._readdirEntries = function (abs, entries) {
  22318. // if we haven't asked to stat everything, then just
  22319. // assume that everything in there exists, so we can avoid
  22320. // having to stat it a second time.
  22321. if (!this.mark && !this.stat) {
  22322. for (var i = 0; i < entries.length; i++) {
  22323. var e = entries[i];
  22324. if (abs === '/') e = abs + e;else e = abs + '/' + e;
  22325. this.cache[e] = true;
  22326. }
  22327. }
  22328. this.cache[abs] = entries; // mark and cache dir-ness
  22329. return entries;
  22330. };
  22331. GlobSync.prototype._readdirError = function (f, er) {
  22332. // handle errors, and cache the information
  22333. switch (er.code) {
  22334. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  22335. case 'ENOTDIR':
  22336. // totally normal. means it *does* exist.
  22337. var abs = this._makeAbs(f);
  22338. this.cache[abs] = 'FILE';
  22339. if (abs === this.cwdAbs) {
  22340. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  22341. error.path = this.cwd;
  22342. error.code = er.code;
  22343. throw error;
  22344. }
  22345. break;
  22346. case 'ENOENT': // not terribly unusual
  22347. case 'ELOOP':
  22348. case 'ENAMETOOLONG':
  22349. case 'UNKNOWN':
  22350. this.cache[this._makeAbs(f)] = false;
  22351. break;
  22352. default:
  22353. // some unusual error. Treat as failure.
  22354. this.cache[this._makeAbs(f)] = false;
  22355. if (this.strict) throw er;
  22356. if (!this.silent) console.error('glob error', er);
  22357. break;
  22358. }
  22359. };
  22360. GlobSync.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
  22361. var entries = this._readdir(abs, inGlobStar); // no entries means not a dir, so it can never have matches
  22362. // foo.txt/** doesn't match foo.txt
  22363. if (!entries) return; // test without the globstar, and with every child both below
  22364. // and replacing the globstar.
  22365. var remainWithoutGlobStar = remain.slice(1);
  22366. var gspref = prefix ? [prefix] : [];
  22367. var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
  22368. this._process(noGlobStar, index, false);
  22369. var len = entries.length;
  22370. var isSym = this.symlinks[abs]; // If it's a symlink, and we're in a globstar, then stop
  22371. if (isSym && inGlobStar) return;
  22372. for (var i = 0; i < len; i++) {
  22373. var e = entries[i];
  22374. if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
  22375. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  22376. this._process(instead, index, true);
  22377. var below = gspref.concat(entries[i], remain);
  22378. this._process(below, index, true);
  22379. }
  22380. };
  22381. GlobSync.prototype._processSimple = function (prefix, index) {
  22382. // XXX review this. Shouldn't it be doing the mounting etc
  22383. // before doing stat? kinda weird?
  22384. var exists = this._stat(prefix);
  22385. if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
  22386. if (!exists) return;
  22387. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  22388. var trail = /[\/\\]$/.test(prefix);
  22389. if (prefix.charAt(0) === '/') {
  22390. prefix = path$2.join(this.root, prefix);
  22391. } else {
  22392. prefix = path$2.resolve(this.root, prefix);
  22393. if (trail) prefix += '/';
  22394. }
  22395. }
  22396. if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
  22397. this._emitMatch(index, prefix);
  22398. }; // Returns either 'DIR', 'FILE', or false
  22399. GlobSync.prototype._stat = function (f) {
  22400. var abs = this._makeAbs(f);
  22401. var needDir = f.slice(-1) === '/';
  22402. if (f.length > this.maxLength) return false;
  22403. if (!this.stat && ownProp$1(this.cache, abs)) {
  22404. var c = this.cache[abs];
  22405. if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
  22406. if (!needDir || c === 'DIR') return c;
  22407. if (needDir && c === 'FILE') return false; // otherwise we have to stat, because maybe c=true
  22408. // if we know it exists, but not what it is.
  22409. }
  22410. var stat = this.statCache[abs];
  22411. if (!stat) {
  22412. var lstat;
  22413. try {
  22414. lstat = fs$1.lstatSync(abs);
  22415. } catch (er) {
  22416. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  22417. this.statCache[abs] = false;
  22418. return false;
  22419. }
  22420. }
  22421. if (lstat && lstat.isSymbolicLink()) {
  22422. try {
  22423. stat = fs$1.statSync(abs);
  22424. } catch (er) {
  22425. stat = lstat;
  22426. }
  22427. } else {
  22428. stat = lstat;
  22429. }
  22430. }
  22431. this.statCache[abs] = stat;
  22432. var c = true;
  22433. if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
  22434. this.cache[abs] = this.cache[abs] || c;
  22435. if (needDir && c === 'FILE') return false;
  22436. return c;
  22437. };
  22438. GlobSync.prototype._mark = function (p) {
  22439. return common$2.mark(this, p);
  22440. };
  22441. GlobSync.prototype._makeAbs = function (f) {
  22442. return common$2.makeAbs(this, f);
  22443. };
  22444. // Returns a wrapper function that returns a wrapped callback
  22445. // The wrapper function should do some stuff, and return a
  22446. // presumably different callback function.
  22447. // This makes sure that own properties are retained, so that
  22448. // decorations and such are not lost along the way.
  22449. var wrappy_1 = wrappy;
  22450. function wrappy(fn, cb) {
  22451. if (fn && cb) return wrappy(fn)(cb);
  22452. if (typeof fn !== 'function') throw new TypeError('need wrapper function');
  22453. Object.keys(fn).forEach(function (k) {
  22454. wrapper[k] = fn[k];
  22455. });
  22456. return wrapper;
  22457. function wrapper() {
  22458. var args = new Array(arguments.length);
  22459. for (var i = 0; i < args.length; i++) {
  22460. args[i] = arguments[i];
  22461. }
  22462. var ret = fn.apply(this, args);
  22463. var cb = args[args.length - 1];
  22464. if (typeof ret === 'function' && ret !== cb) {
  22465. Object.keys(cb).forEach(function (k) {
  22466. ret[k] = cb[k];
  22467. });
  22468. }
  22469. return ret;
  22470. }
  22471. }
  22472. var once_1 = wrappy_1(once);
  22473. var strict = wrappy_1(onceStrict);
  22474. once.proto = once(function () {
  22475. Object.defineProperty(Function.prototype, 'once', {
  22476. value: function value() {
  22477. return once(this);
  22478. },
  22479. configurable: true
  22480. });
  22481. Object.defineProperty(Function.prototype, 'onceStrict', {
  22482. value: function value() {
  22483. return onceStrict(this);
  22484. },
  22485. configurable: true
  22486. });
  22487. });
  22488. function once(fn) {
  22489. var f = function f() {
  22490. if (f.called) return f.value;
  22491. f.called = true;
  22492. return f.value = fn.apply(this, arguments);
  22493. };
  22494. f.called = false;
  22495. return f;
  22496. }
  22497. function onceStrict(fn) {
  22498. var f = function f() {
  22499. if (f.called) throw new Error(f.onceError);
  22500. f.called = true;
  22501. return f.value = fn.apply(this, arguments);
  22502. };
  22503. var name = fn.name || 'Function wrapped with `once`';
  22504. f.onceError = name + " shouldn't be called more than once";
  22505. f.called = false;
  22506. return f;
  22507. }
  22508. once_1.strict = strict;
  22509. var reqs = Object.create(null);
  22510. var inflight_1 = wrappy_1(inflight);
  22511. function inflight(key, cb) {
  22512. if (reqs[key]) {
  22513. reqs[key].push(cb);
  22514. return null;
  22515. } else {
  22516. reqs[key] = [cb];
  22517. return makeres(key);
  22518. }
  22519. }
  22520. function makeres(key) {
  22521. return once_1(function RES() {
  22522. var cbs = reqs[key];
  22523. var len = cbs.length;
  22524. var args = slice(arguments); // XXX It's somewhat ambiguous whether a new callback added in this
  22525. // pass should be queued for later execution if something in the
  22526. // list of callbacks throws, or if it should just be discarded.
  22527. // However, it's such an edge case that it hardly matters, and either
  22528. // choice is likely as surprising as the other.
  22529. // As it happens, we do go ahead and schedule it for later execution.
  22530. try {
  22531. for (var i = 0; i < len; i++) {
  22532. cbs[i].apply(null, args);
  22533. }
  22534. } finally {
  22535. if (cbs.length > len) {
  22536. // added more in the interim.
  22537. // de-zalgo, just in case, but don't call again.
  22538. cbs.splice(0, len);
  22539. process.nextTick(function () {
  22540. RES.apply(null, args);
  22541. });
  22542. } else {
  22543. delete reqs[key];
  22544. }
  22545. }
  22546. });
  22547. }
  22548. function slice(args) {
  22549. var length = args.length;
  22550. var array = [];
  22551. for (var i = 0; i < length; i++) {
  22552. array[i] = args[i];
  22553. }
  22554. return array;
  22555. }
  22556. //
  22557. // 1. Get the minimatch set
  22558. // 2. For each pattern in the set, PROCESS(pattern, false)
  22559. // 3. Store matches per-set, then uniq them
  22560. //
  22561. // PROCESS(pattern, inGlobStar)
  22562. // Get the first [n] items from pattern that are all strings
  22563. // Join these together. This is PREFIX.
  22564. // If there is no more remaining, then stat(PREFIX) and
  22565. // add to matches if it succeeds. END.
  22566. //
  22567. // If inGlobStar and PREFIX is symlink and points to dir
  22568. // set ENTRIES = []
  22569. // else readdir(PREFIX) as ENTRIES
  22570. // If fail, END
  22571. //
  22572. // with ENTRIES
  22573. // If pattern[n] is GLOBSTAR
  22574. // // handle the case where the globstar match is empty
  22575. // // by pruning it out, and testing the resulting pattern
  22576. // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
  22577. // // handle other cases.
  22578. // for ENTRY in ENTRIES (not dotfiles)
  22579. // // attach globstar + tail onto the entry
  22580. // // Mark that this entry is a globstar match
  22581. // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
  22582. //
  22583. // else // not globstar
  22584. // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
  22585. // Test ENTRY against pattern[n]
  22586. // If fails, continue
  22587. // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
  22588. //
  22589. // Caveat:
  22590. // Cache all stats and readdirs results to minimize syscall. Since all
  22591. // we ever care about is existence and directory-ness, we can just keep
  22592. // `true` for files, and [children,...] for directories, or `false` for
  22593. // things that don't exist.
  22594. var glob_1 = glob;
  22595. var EE = events$1.EventEmitter;
  22596. var setopts$2 = common$2.setopts;
  22597. var ownProp$2 = common$2.ownProp;
  22598. var childrenIgnored$2 = common$2.childrenIgnored;
  22599. var isIgnored$2 = common$2.isIgnored;
  22600. function glob(pattern, options, cb) {
  22601. if (typeof options === 'function') cb = options, options = {};
  22602. if (!options) options = {};
  22603. if (options.sync) {
  22604. if (cb) throw new TypeError('callback provided to sync glob');
  22605. return sync$1(pattern, options);
  22606. }
  22607. return new Glob(pattern, options, cb);
  22608. }
  22609. glob.sync = sync$1;
  22610. var GlobSync$1 = glob.GlobSync = sync$1.GlobSync; // old api surface
  22611. glob.glob = glob;
  22612. function extend(origin, add) {
  22613. if (add === null || typeof add !== 'object') {
  22614. return origin;
  22615. }
  22616. var keys = Object.keys(add);
  22617. var i = keys.length;
  22618. while (i--) {
  22619. origin[keys[i]] = add[keys[i]];
  22620. }
  22621. return origin;
  22622. }
  22623. glob.hasMagic = function (pattern, options_) {
  22624. var options = extend({}, options_);
  22625. options.noprocess = true;
  22626. var g = new Glob(pattern, options);
  22627. var set = g.minimatch.set;
  22628. if (!pattern) return false;
  22629. if (set.length > 1) return true;
  22630. for (var j = 0; j < set[0].length; j++) {
  22631. if (typeof set[0][j] !== 'string') return true;
  22632. }
  22633. return false;
  22634. };
  22635. glob.Glob = Glob;
  22636. inherits(Glob, EE);
  22637. function Glob(pattern, options, cb) {
  22638. if (typeof options === 'function') {
  22639. cb = options;
  22640. options = null;
  22641. }
  22642. if (options && options.sync) {
  22643. if (cb) throw new TypeError('callback provided to sync glob');
  22644. return new GlobSync$1(pattern, options);
  22645. }
  22646. if (!(this instanceof Glob)) return new Glob(pattern, options, cb);
  22647. setopts$2(this, pattern, options);
  22648. this._didRealPath = false; // process each pattern in the minimatch set
  22649. var n = this.minimatch.set.length; // The matches are stored as {<filename>: true,...} so that
  22650. // duplicates are automagically pruned.
  22651. // Later, we do an Object.keys() on these.
  22652. // Keep them as a list so we can fill in when nonull is set.
  22653. this.matches = new Array(n);
  22654. if (typeof cb === 'function') {
  22655. cb = once_1(cb);
  22656. this.on('error', cb);
  22657. this.on('end', function (matches) {
  22658. cb(null, matches);
  22659. });
  22660. }
  22661. var self = this;
  22662. this._processing = 0;
  22663. this._emitQueue = [];
  22664. this._processQueue = [];
  22665. this.paused = false;
  22666. if (this.noprocess) return this;
  22667. if (n === 0) return done();
  22668. var sync = true;
  22669. for (var i = 0; i < n; i++) {
  22670. this._process(this.minimatch.set[i], i, false, done);
  22671. }
  22672. sync = false;
  22673. function done() {
  22674. --self._processing;
  22675. if (self._processing <= 0) {
  22676. if (sync) {
  22677. process.nextTick(function () {
  22678. self._finish();
  22679. });
  22680. } else {
  22681. self._finish();
  22682. }
  22683. }
  22684. }
  22685. }
  22686. Glob.prototype._finish = function () {
  22687. assert$1(this instanceof Glob);
  22688. if (this.aborted) return;
  22689. if (this.realpath && !this._didRealpath) return this._realpath();
  22690. common$2.finish(this);
  22691. this.emit('end', this.found);
  22692. };
  22693. Glob.prototype._realpath = function () {
  22694. if (this._didRealpath) return;
  22695. this._didRealpath = true;
  22696. var n = this.matches.length;
  22697. if (n === 0) return this._finish();
  22698. var self = this;
  22699. for (var i = 0; i < this.matches.length; i++) {
  22700. this._realpathSet(i, next);
  22701. }
  22702. function next() {
  22703. if (--n === 0) self._finish();
  22704. }
  22705. };
  22706. Glob.prototype._realpathSet = function (index, cb) {
  22707. var matchset = this.matches[index];
  22708. if (!matchset) return cb();
  22709. var found = Object.keys(matchset);
  22710. var self = this;
  22711. var n = found.length;
  22712. if (n === 0) return cb();
  22713. var set = this.matches[index] = Object.create(null);
  22714. found.forEach(function (p, i) {
  22715. // If there's a problem with the stat, then it means that
  22716. // one or more of the links in the realpath couldn't be
  22717. // resolved. just return the abs value in that case.
  22718. p = self._makeAbs(p);
  22719. fs_realpath.realpath(p, self.realpathCache, function (er, real) {
  22720. if (!er) set[real] = true;else if (er.syscall === 'stat') set[p] = true;else self.emit('error', er); // srsly wtf right here
  22721. if (--n === 0) {
  22722. self.matches[index] = set;
  22723. cb();
  22724. }
  22725. });
  22726. });
  22727. };
  22728. Glob.prototype._mark = function (p) {
  22729. return common$2.mark(this, p);
  22730. };
  22731. Glob.prototype._makeAbs = function (f) {
  22732. return common$2.makeAbs(this, f);
  22733. };
  22734. Glob.prototype.abort = function () {
  22735. this.aborted = true;
  22736. this.emit('abort');
  22737. };
  22738. Glob.prototype.pause = function () {
  22739. if (!this.paused) {
  22740. this.paused = true;
  22741. this.emit('pause');
  22742. }
  22743. };
  22744. Glob.prototype.resume = function () {
  22745. if (this.paused) {
  22746. this.emit('resume');
  22747. this.paused = false;
  22748. if (this._emitQueue.length) {
  22749. var eq = this._emitQueue.slice(0);
  22750. this._emitQueue.length = 0;
  22751. for (var i = 0; i < eq.length; i++) {
  22752. var e = eq[i];
  22753. this._emitMatch(e[0], e[1]);
  22754. }
  22755. }
  22756. if (this._processQueue.length) {
  22757. var pq = this._processQueue.slice(0);
  22758. this._processQueue.length = 0;
  22759. for (var i = 0; i < pq.length; i++) {
  22760. var p = pq[i];
  22761. this._processing--;
  22762. this._process(p[0], p[1], p[2], p[3]);
  22763. }
  22764. }
  22765. }
  22766. };
  22767. Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
  22768. assert$1(this instanceof Glob);
  22769. assert$1(typeof cb === 'function');
  22770. if (this.aborted) return;
  22771. this._processing++;
  22772. if (this.paused) {
  22773. this._processQueue.push([pattern, index, inGlobStar, cb]);
  22774. return;
  22775. } //console.error('PROCESS %d', this._processing, pattern)
  22776. // Get the first [n] parts of pattern that are all strings.
  22777. var n = 0;
  22778. while (typeof pattern[n] === 'string') {
  22779. n++;
  22780. } // now n is the index of the first one that is *not* a string.
  22781. // see if there's anything else
  22782. var prefix;
  22783. switch (n) {
  22784. // if not, then this is rather simple
  22785. case pattern.length:
  22786. this._processSimple(pattern.join('/'), index, cb);
  22787. return;
  22788. case 0:
  22789. // pattern *starts* with some non-trivial item.
  22790. // going to readdir(cwd), but not include the prefix in matches.
  22791. prefix = null;
  22792. break;
  22793. default:
  22794. // pattern has some string bits in the front.
  22795. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  22796. // or 'relative' like '../baz'
  22797. prefix = pattern.slice(0, n).join('/');
  22798. break;
  22799. }
  22800. var remain = pattern.slice(n); // get the list of entries.
  22801. var read;
  22802. if (prefix === null) read = '.';else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  22803. if (!prefix || !pathIsAbsolute(prefix)) prefix = '/' + prefix;
  22804. read = prefix;
  22805. } else read = prefix;
  22806. var abs = this._makeAbs(read); //if ignored, skip _processing
  22807. if (childrenIgnored$2(this, read)) return cb();
  22808. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  22809. if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb);
  22810. };
  22811. Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  22812. var self = this;
  22813. this._readdir(abs, inGlobStar, function (er, entries) {
  22814. return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
  22815. });
  22816. };
  22817. Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  22818. // if the abs isn't a dir, then nothing can match!
  22819. if (!entries) return cb(); // It will only match dot entries if it starts with a dot, or if
  22820. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  22821. var pn = remain[0];
  22822. var negate = !!this.minimatch.negate;
  22823. var rawGlob = pn._glob;
  22824. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  22825. var matchedEntries = [];
  22826. for (var i = 0; i < entries.length; i++) {
  22827. var e = entries[i];
  22828. if (e.charAt(0) !== '.' || dotOk) {
  22829. var m;
  22830. if (negate && !prefix) {
  22831. m = !e.match(pn);
  22832. } else {
  22833. m = e.match(pn);
  22834. }
  22835. if (m) matchedEntries.push(e);
  22836. }
  22837. } //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
  22838. var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
  22839. if (len === 0) return cb(); // if this is the last remaining pattern bit, then no need for
  22840. // an additional stat *unless* the user has specified mark or
  22841. // stat explicitly. We know they exist, since readdir returned
  22842. // them.
  22843. if (remain.length === 1 && !this.mark && !this.stat) {
  22844. if (!this.matches[index]) this.matches[index] = Object.create(null);
  22845. for (var i = 0; i < len; i++) {
  22846. var e = matchedEntries[i];
  22847. if (prefix) {
  22848. if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
  22849. }
  22850. if (e.charAt(0) === '/' && !this.nomount) {
  22851. e = path$2.join(this.root, e);
  22852. }
  22853. this._emitMatch(index, e);
  22854. } // This was the last one, and no stats were needed
  22855. return cb();
  22856. } // now test all matched entries as stand-ins for that part
  22857. // of the pattern.
  22858. remain.shift();
  22859. for (var i = 0; i < len; i++) {
  22860. var e = matchedEntries[i];
  22861. if (prefix) {
  22862. if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
  22863. }
  22864. this._process([e].concat(remain), index, inGlobStar, cb);
  22865. }
  22866. cb();
  22867. };
  22868. Glob.prototype._emitMatch = function (index, e) {
  22869. if (this.aborted) return;
  22870. if (isIgnored$2(this, e)) return;
  22871. if (this.paused) {
  22872. this._emitQueue.push([index, e]);
  22873. return;
  22874. }
  22875. var abs = pathIsAbsolute(e) ? e : this._makeAbs(e);
  22876. if (this.mark) e = this._mark(e);
  22877. if (this.absolute) e = abs;
  22878. if (this.matches[index][e]) return;
  22879. if (this.nodir) {
  22880. var c = this.cache[abs];
  22881. if (c === 'DIR' || Array.isArray(c)) return;
  22882. }
  22883. this.matches[index][e] = true;
  22884. var st = this.statCache[abs];
  22885. if (st) this.emit('stat', e, st);
  22886. this.emit('match', e);
  22887. };
  22888. Glob.prototype._readdirInGlobStar = function (abs, cb) {
  22889. if (this.aborted) return; // follow all symlinked directories forever
  22890. // just proceed as if this is a non-globstar situation
  22891. if (this.follow) return this._readdir(abs, false, cb);
  22892. var lstatkey = 'lstat\0' + abs;
  22893. var self = this;
  22894. var lstatcb = inflight_1(lstatkey, lstatcb_);
  22895. if (lstatcb) fs$1.lstat(abs, lstatcb);
  22896. function lstatcb_(er, lstat) {
  22897. if (er && er.code === 'ENOENT') return cb();
  22898. var isSym = lstat && lstat.isSymbolicLink();
  22899. self.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
  22900. // don't bother doing a readdir in that case.
  22901. if (!isSym && lstat && !lstat.isDirectory()) {
  22902. self.cache[abs] = 'FILE';
  22903. cb();
  22904. } else self._readdir(abs, false, cb);
  22905. }
  22906. };
  22907. Glob.prototype._readdir = function (abs, inGlobStar, cb) {
  22908. if (this.aborted) return;
  22909. cb = inflight_1('readdir\0' + abs + '\0' + inGlobStar, cb);
  22910. if (!cb) return; //console.error('RD %j %j', +inGlobStar, abs)
  22911. if (inGlobStar && !ownProp$2(this.symlinks, abs)) return this._readdirInGlobStar(abs, cb);
  22912. if (ownProp$2(this.cache, abs)) {
  22913. var c = this.cache[abs];
  22914. if (!c || c === 'FILE') return cb();
  22915. if (Array.isArray(c)) return cb(null, c);
  22916. }
  22917. fs$1.readdir(abs, readdirCb(this, abs, cb));
  22918. };
  22919. function readdirCb(self, abs, cb) {
  22920. return function (er, entries) {
  22921. if (er) self._readdirError(abs, er, cb);else self._readdirEntries(abs, entries, cb);
  22922. };
  22923. }
  22924. Glob.prototype._readdirEntries = function (abs, entries, cb) {
  22925. if (this.aborted) return; // if we haven't asked to stat everything, then just
  22926. // assume that everything in there exists, so we can avoid
  22927. // having to stat it a second time.
  22928. if (!this.mark && !this.stat) {
  22929. for (var i = 0; i < entries.length; i++) {
  22930. var e = entries[i];
  22931. if (abs === '/') e = abs + e;else e = abs + '/' + e;
  22932. this.cache[e] = true;
  22933. }
  22934. }
  22935. this.cache[abs] = entries;
  22936. return cb(null, entries);
  22937. };
  22938. Glob.prototype._readdirError = function (f, er, cb) {
  22939. if (this.aborted) return; // handle errors, and cache the information
  22940. switch (er.code) {
  22941. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  22942. case 'ENOTDIR':
  22943. // totally normal. means it *does* exist.
  22944. var abs = this._makeAbs(f);
  22945. this.cache[abs] = 'FILE';
  22946. if (abs === this.cwdAbs) {
  22947. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  22948. error.path = this.cwd;
  22949. error.code = er.code;
  22950. this.emit('error', error);
  22951. this.abort();
  22952. }
  22953. break;
  22954. case 'ENOENT': // not terribly unusual
  22955. case 'ELOOP':
  22956. case 'ENAMETOOLONG':
  22957. case 'UNKNOWN':
  22958. this.cache[this._makeAbs(f)] = false;
  22959. break;
  22960. default:
  22961. // some unusual error. Treat as failure.
  22962. this.cache[this._makeAbs(f)] = false;
  22963. if (this.strict) {
  22964. this.emit('error', er); // If the error is handled, then we abort
  22965. // if not, we threw out of here
  22966. this.abort();
  22967. }
  22968. if (!this.silent) console.error('glob error', er);
  22969. break;
  22970. }
  22971. return cb();
  22972. };
  22973. Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  22974. var self = this;
  22975. this._readdir(abs, inGlobStar, function (er, entries) {
  22976. self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
  22977. });
  22978. };
  22979. Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  22980. //console.error('pgs2', prefix, remain[0], entries)
  22981. // no entries means not a dir, so it can never have matches
  22982. // foo.txt/** doesn't match foo.txt
  22983. if (!entries) return cb(); // test without the globstar, and with every child both below
  22984. // and replacing the globstar.
  22985. var remainWithoutGlobStar = remain.slice(1);
  22986. var gspref = prefix ? [prefix] : [];
  22987. var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
  22988. this._process(noGlobStar, index, false, cb);
  22989. var isSym = this.symlinks[abs];
  22990. var len = entries.length; // If it's a symlink, and we're in a globstar, then stop
  22991. if (isSym && inGlobStar) return cb();
  22992. for (var i = 0; i < len; i++) {
  22993. var e = entries[i];
  22994. if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
  22995. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  22996. this._process(instead, index, true, cb);
  22997. var below = gspref.concat(entries[i], remain);
  22998. this._process(below, index, true, cb);
  22999. }
  23000. cb();
  23001. };
  23002. Glob.prototype._processSimple = function (prefix, index, cb) {
  23003. // XXX review this. Shouldn't it be doing the mounting etc
  23004. // before doing stat? kinda weird?
  23005. var self = this;
  23006. this._stat(prefix, function (er, exists) {
  23007. self._processSimple2(prefix, index, er, exists, cb);
  23008. });
  23009. };
  23010. Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
  23011. //console.error('ps2', prefix, exists)
  23012. if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
  23013. if (!exists) return cb();
  23014. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  23015. var trail = /[\/\\]$/.test(prefix);
  23016. if (prefix.charAt(0) === '/') {
  23017. prefix = path$2.join(this.root, prefix);
  23018. } else {
  23019. prefix = path$2.resolve(this.root, prefix);
  23020. if (trail) prefix += '/';
  23021. }
  23022. }
  23023. if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
  23024. this._emitMatch(index, prefix);
  23025. cb();
  23026. }; // Returns either 'DIR', 'FILE', or false
  23027. Glob.prototype._stat = function (f, cb) {
  23028. var abs = this._makeAbs(f);
  23029. var needDir = f.slice(-1) === '/';
  23030. if (f.length > this.maxLength) return cb();
  23031. if (!this.stat && ownProp$2(this.cache, abs)) {
  23032. var c = this.cache[abs];
  23033. if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
  23034. if (!needDir || c === 'DIR') return cb(null, c);
  23035. if (needDir && c === 'FILE') return cb(); // otherwise we have to stat, because maybe c=true
  23036. // if we know it exists, but not what it is.
  23037. }
  23038. var stat = this.statCache[abs];
  23039. if (stat !== undefined) {
  23040. if (stat === false) return cb(null, stat);else {
  23041. var type = stat.isDirectory() ? 'DIR' : 'FILE';
  23042. if (needDir && type === 'FILE') return cb();else return cb(null, type, stat);
  23043. }
  23044. }
  23045. var self = this;
  23046. var statcb = inflight_1('stat\0' + abs, lstatcb_);
  23047. if (statcb) fs$1.lstat(abs, statcb);
  23048. function lstatcb_(er, lstat) {
  23049. if (lstat && lstat.isSymbolicLink()) {
  23050. // If it's a symlink, then treat it as the target, unless
  23051. // the target does not exist, then treat it as a file.
  23052. return fs$1.stat(abs, function (er, stat) {
  23053. if (er) self._stat2(f, abs, null, lstat, cb);else self._stat2(f, abs, er, stat, cb);
  23054. });
  23055. } else {
  23056. self._stat2(f, abs, er, lstat, cb);
  23057. }
  23058. }
  23059. };
  23060. Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
  23061. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  23062. this.statCache[abs] = false;
  23063. return cb();
  23064. }
  23065. var needDir = f.slice(-1) === '/';
  23066. this.statCache[abs] = stat;
  23067. if (abs.slice(-1) === '/' && stat && !stat.isDirectory()) return cb(null, false, stat);
  23068. var c = true;
  23069. if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
  23070. this.cache[abs] = this.cache[abs] || c;
  23071. if (needDir && c === 'FILE') return cb();
  23072. return cb(null, c, stat);
  23073. };
  23074. var pify_1 = createCommonjsModule(function (module) {
  23075. var processFn = function processFn(fn, P, opts) {
  23076. return function () {
  23077. var that = this;
  23078. var args = new Array(arguments.length);
  23079. for (var i = 0; i < arguments.length; i++) {
  23080. args[i] = arguments[i];
  23081. }
  23082. return new P(function (resolve, reject) {
  23083. args.push(function (err, result) {
  23084. if (err) {
  23085. reject(err);
  23086. } else if (opts.multiArgs) {
  23087. var results = new Array(arguments.length - 1);
  23088. for (var i = 1; i < arguments.length; i++) {
  23089. results[i - 1] = arguments[i];
  23090. }
  23091. resolve(results);
  23092. } else {
  23093. resolve(result);
  23094. }
  23095. });
  23096. fn.apply(that, args);
  23097. });
  23098. };
  23099. };
  23100. var pify = module.exports = function (obj, P, opts) {
  23101. if (typeof P !== 'function') {
  23102. opts = P;
  23103. P = Promise;
  23104. }
  23105. opts = opts || {};
  23106. opts.exclude = opts.exclude || [/.+Sync$/];
  23107. var filter = function filter(key) {
  23108. var match = function match(pattern) {
  23109. return typeof pattern === 'string' ? key === pattern : pattern.test(key);
  23110. };
  23111. return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
  23112. };
  23113. var ret = typeof obj === 'function' ? function () {
  23114. if (opts.excludeMain) {
  23115. return obj.apply(this, arguments);
  23116. }
  23117. return processFn(obj, P, opts).apply(this, arguments);
  23118. } : {};
  23119. return Object.keys(obj).reduce(function (ret, key) {
  23120. var x = obj[key];
  23121. ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x;
  23122. return ret;
  23123. }, ret);
  23124. };
  23125. pify.all = pify;
  23126. });
  23127. var globP = pify_1(glob_1, pinkiePromise).bind(glob_1);
  23128. function isNegative(pattern) {
  23129. return pattern[0] === '!';
  23130. }
  23131. function isString(value) {
  23132. return typeof value === 'string';
  23133. }
  23134. function assertPatternsInput(patterns) {
  23135. if (!patterns.every(isString)) {
  23136. throw new TypeError('patterns must be a string or an array of strings');
  23137. }
  23138. }
  23139. function generateGlobTasks(patterns, opts) {
  23140. patterns = [].concat(patterns);
  23141. assertPatternsInput(patterns);
  23142. var globTasks = [];
  23143. opts = objectAssign({
  23144. cache: Object.create(null),
  23145. statCache: Object.create(null),
  23146. realpathCache: Object.create(null),
  23147. symlinks: Object.create(null),
  23148. ignore: []
  23149. }, opts);
  23150. patterns.forEach(function (pattern, i) {
  23151. if (isNegative(pattern)) {
  23152. return;
  23153. }
  23154. var ignore = patterns.slice(i).filter(isNegative).map(function (pattern) {
  23155. return pattern.slice(1);
  23156. });
  23157. globTasks.push({
  23158. pattern: pattern,
  23159. opts: objectAssign({}, opts, {
  23160. ignore: opts.ignore.concat(ignore)
  23161. })
  23162. });
  23163. });
  23164. return globTasks;
  23165. }
  23166. var globby = function globby(patterns, opts) {
  23167. var globTasks;
  23168. try {
  23169. globTasks = generateGlobTasks(patterns, opts);
  23170. } catch (err) {
  23171. return pinkiePromise.reject(err);
  23172. }
  23173. return pinkiePromise.all(globTasks.map(function (task) {
  23174. return globP(task.pattern, task.opts);
  23175. })).then(function (paths) {
  23176. return arrayUnion.apply(null, paths);
  23177. });
  23178. };
  23179. var sync$2 = function sync(patterns, opts) {
  23180. var globTasks = generateGlobTasks(patterns, opts);
  23181. return globTasks.reduce(function (matches, task) {
  23182. return arrayUnion(matches, glob_1.sync(task.pattern, task.opts));
  23183. }, []);
  23184. };
  23185. var generateGlobTasks_1 = generateGlobTasks;
  23186. var hasMagic = function hasMagic(patterns, opts) {
  23187. return [].concat(patterns).some(function (pattern) {
  23188. return glob_1.hasMagic(pattern, opts);
  23189. });
  23190. };
  23191. globby.sync = sync$2;
  23192. globby.generateGlobTasks = generateGlobTasks_1;
  23193. globby.hasMagic = hasMagic;
  23194. var addLeadingComment$2 = utilShared.addLeadingComment,
  23195. addTrailingComment$2 = utilShared.addTrailingComment,
  23196. addDanglingComment$2 = utilShared.addDanglingComment;
  23197. function handleOwnLineComment(comment, text, options, ast, isLastComment) {
  23198. var precedingNode = comment.precedingNode,
  23199. enclosingNode = comment.enclosingNode,
  23200. followingNode = comment.followingNode;
  23201. if (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)) {
  23202. return true;
  23203. }
  23204. return false;
  23205. }
  23206. function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
  23207. var precedingNode = comment.precedingNode,
  23208. enclosingNode = comment.enclosingNode,
  23209. followingNode = comment.followingNode;
  23210. if (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)) {
  23211. return true;
  23212. }
  23213. return false;
  23214. }
  23215. function handleRemainingComment(comment, text, options, ast, isLastComment) {
  23216. var precedingNode = comment.precedingNode,
  23217. enclosingNode = comment.enclosingNode,
  23218. followingNode = comment.followingNode;
  23219. 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)) {
  23220. return true;
  23221. }
  23222. return false;
  23223. }
  23224. function addBlockStatementFirstComment(node, comment) {
  23225. var body = node.body.filter(function (n) {
  23226. return n.type !== "EmptyStatement";
  23227. });
  23228. if (body.length === 0) {
  23229. addDanglingComment$2(node, comment);
  23230. } else {
  23231. addLeadingComment$2(body[0], comment);
  23232. }
  23233. }
  23234. function addBlockOrNotComment(node, comment) {
  23235. if (node.type === "BlockStatement") {
  23236. addBlockStatementFirstComment(node, comment);
  23237. } else {
  23238. addLeadingComment$2(node, comment);
  23239. }
  23240. } // There are often comments before the else clause of if statements like
  23241. //
  23242. // if (1) { ... }
  23243. // // comment
  23244. // else { ... }
  23245. //
  23246. // They are being attached as leading comments of the BlockExpression which
  23247. // is not well printed. What we want is to instead move the comment inside
  23248. // of the block and make it leadingComment of the first element of the block
  23249. // or dangling comment of the block if there is nothing inside
  23250. //
  23251. // if (1) { ... }
  23252. // else {
  23253. // // comment
  23254. // ...
  23255. // }
  23256. function handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  23257. if (!enclosingNode || enclosingNode.type !== "IfStatement" || !followingNode) {
  23258. return false;
  23259. } // We unfortunately have no way using the AST or location of nodes to know
  23260. // if the comment is positioned before the condition parenthesis:
  23261. // if (a /* comment */) {}
  23262. // The only workaround I found is to look at the next character to see if
  23263. // it is a ).
  23264. var nextCharacter = util.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd);
  23265. if (nextCharacter === ")") {
  23266. addTrailingComment$2(precedingNode, comment);
  23267. return true;
  23268. } // Comments before `else`:
  23269. // - treat as trailing comments of the consequent, if it's a BlockStatement
  23270. // - treat as a dangling comment otherwise
  23271. if (precedingNode === enclosingNode.consequent && followingNode === enclosingNode.alternate) {
  23272. if (precedingNode.type === "BlockStatement") {
  23273. addTrailingComment$2(precedingNode, comment);
  23274. } else {
  23275. addDanglingComment$2(enclosingNode, comment);
  23276. }
  23277. return true;
  23278. }
  23279. if (followingNode.type === "BlockStatement") {
  23280. addBlockStatementFirstComment(followingNode, comment);
  23281. return true;
  23282. }
  23283. if (followingNode.type === "IfStatement") {
  23284. addBlockOrNotComment(followingNode.consequent, comment);
  23285. return true;
  23286. } // For comments positioned after the condition parenthesis in an if statement
  23287. // before the consequent without brackets on, such as
  23288. // if (a) /* comment */ true,
  23289. // we look at the next character to see if the following node
  23290. // is the consequent for the if statement
  23291. if (enclosingNode.consequent === followingNode) {
  23292. addLeadingComment$2(followingNode, comment);
  23293. return true;
  23294. }
  23295. return false;
  23296. }
  23297. function handleWhileComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  23298. if (!enclosingNode || enclosingNode.type !== "WhileStatement" || !followingNode) {
  23299. return false;
  23300. } // We unfortunately have no way using the AST or location of nodes to know
  23301. // if the comment is positioned before the condition parenthesis:
  23302. // while (a /* comment */) {}
  23303. // The only workaround I found is to look at the next character to see if
  23304. // it is a ).
  23305. var nextCharacter = util.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd);
  23306. if (nextCharacter === ")") {
  23307. addTrailingComment$2(precedingNode, comment);
  23308. return true;
  23309. }
  23310. if (followingNode.type === "BlockStatement") {
  23311. addBlockStatementFirstComment(followingNode, comment);
  23312. return true;
  23313. }
  23314. return false;
  23315. } // Same as IfStatement but for TryStatement
  23316. function handleTryStatementComments(enclosingNode, precedingNode, followingNode, comment) {
  23317. if (!enclosingNode || enclosingNode.type !== "TryStatement" && enclosingNode.type !== "CatchClause" || !followingNode) {
  23318. return false;
  23319. }
  23320. if (enclosingNode.type === "CatchClause" && precedingNode) {
  23321. addTrailingComment$2(precedingNode, comment);
  23322. return true;
  23323. }
  23324. if (followingNode.type === "BlockStatement") {
  23325. addBlockStatementFirstComment(followingNode, comment);
  23326. return true;
  23327. }
  23328. if (followingNode.type === "TryStatement") {
  23329. addBlockOrNotComment(followingNode.finalizer, comment);
  23330. return true;
  23331. }
  23332. if (followingNode.type === "CatchClause") {
  23333. addBlockOrNotComment(followingNode.body, comment);
  23334. return true;
  23335. }
  23336. return false;
  23337. }
  23338. function handleMemberExpressionComments(enclosingNode, followingNode, comment) {
  23339. if (enclosingNode && (enclosingNode.type === "MemberExpression" || enclosingNode.type === "OptionalMemberExpression") && followingNode && followingNode.type === "Identifier") {
  23340. addLeadingComment$2(enclosingNode, comment);
  23341. return true;
  23342. }
  23343. return false;
  23344. }
  23345. function handleConditionalExpressionComments(enclosingNode, precedingNode, followingNode, comment, text, options) {
  23346. var isSameLineAsPrecedingNode = precedingNode && !util.hasNewlineInRange(text, options.locEnd(precedingNode), options.locStart(comment));
  23347. if ((!precedingNode || !isSameLineAsPrecedingNode) && enclosingNode && enclosingNode.type === "ConditionalExpression" && followingNode) {
  23348. addLeadingComment$2(followingNode, comment);
  23349. return true;
  23350. }
  23351. return false;
  23352. }
  23353. function handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) {
  23354. if (enclosingNode && (enclosingNode.type === "ObjectProperty" || enclosingNode.type === "Property") && enclosingNode.shorthand && enclosingNode.key === precedingNode && enclosingNode.value.type === "AssignmentPattern") {
  23355. addTrailingComment$2(enclosingNode.value.left, comment);
  23356. return true;
  23357. }
  23358. return false;
  23359. }
  23360. function handleClassComments(enclosingNode, precedingNode, followingNode, comment) {
  23361. if (enclosingNode && (enclosingNode.type === "ClassDeclaration" || enclosingNode.type === "ClassExpression") && enclosingNode.decorators && enclosingNode.decorators.length > 0 && !(followingNode && followingNode.type === "Decorator")) {
  23362. if (!enclosingNode.decorators || enclosingNode.decorators.length === 0) {
  23363. addLeadingComment$2(enclosingNode, comment);
  23364. } else {
  23365. addTrailingComment$2(enclosingNode.decorators[enclosingNode.decorators.length - 1], comment);
  23366. }
  23367. return true;
  23368. }
  23369. return false;
  23370. }
  23371. function handleMethodNameComments(text, enclosingNode, precedingNode, comment, options) {
  23372. // This is only needed for estree parsers (flow, typescript) to attach
  23373. // after a method name:
  23374. // obj = { fn /*comment*/() {} };
  23375. if (enclosingNode && precedingNode && (enclosingNode.type === "Property" || enclosingNode.type === "MethodDefinition") && precedingNode.type === "Identifier" && enclosingNode.key === precedingNode && // special Property case: { key: /*comment*/(value) };
  23376. // comment should be attached to value instead of key
  23377. util.getNextNonSpaceNonCommentCharacter(text, precedingNode, options.locEnd) !== ":") {
  23378. addTrailingComment$2(precedingNode, comment);
  23379. return true;
  23380. } // Print comments between decorators and class methods as a trailing comment
  23381. // on the decorator node instead of the method node
  23382. if (precedingNode && enclosingNode && precedingNode.type === "Decorator" && (enclosingNode.type === "ClassMethod" || enclosingNode.type === "ClassProperty" || enclosingNode.type === "TSAbstractClassProperty" || enclosingNode.type === "TSAbstractMethodDefinition" || enclosingNode.type === "MethodDefinition")) {
  23383. addTrailingComment$2(precedingNode, comment);
  23384. return true;
  23385. }
  23386. return false;
  23387. }
  23388. function handleFunctionNameComments(text, enclosingNode, precedingNode, comment, options) {
  23389. if (util.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) !== "(") {
  23390. return false;
  23391. }
  23392. if (precedingNode && enclosingNode && (enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ClassMethod" || enclosingNode.type === "MethodDefinition" || enclosingNode.type === "ObjectMethod")) {
  23393. addTrailingComment$2(precedingNode, comment);
  23394. return true;
  23395. }
  23396. return false;
  23397. }
  23398. function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
  23399. if (!(enclosingNode && enclosingNode.type === "ArrowFunctionExpression")) {
  23400. return false;
  23401. }
  23402. var index = utilShared.getNextNonSpaceNonCommentCharacterIndex(text, comment, options);
  23403. if (text.substr(index, 2) === "=>") {
  23404. addDanglingComment$2(enclosingNode, comment);
  23405. return true;
  23406. }
  23407. return false;
  23408. }
  23409. function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
  23410. if (util.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) !== ")") {
  23411. return false;
  23412. } // Only add dangling comments to fix the case when no params are present,
  23413. // i.e. a function without any argument.
  23414. if (enclosingNode && ((enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ArrowFunctionExpression" || enclosingNode.type === "ClassMethod" || enclosingNode.type === "ObjectMethod") && enclosingNode.params.length === 0 || (enclosingNode.type === "CallExpression" || enclosingNode.type === "OptionalCallExpression" || enclosingNode.type === "NewExpression") && enclosingNode.arguments.length === 0)) {
  23415. addDanglingComment$2(enclosingNode, comment);
  23416. return true;
  23417. }
  23418. if (enclosingNode && enclosingNode.type === "MethodDefinition" && enclosingNode.value.params.length === 0) {
  23419. addDanglingComment$2(enclosingNode.value, comment);
  23420. return true;
  23421. }
  23422. return false;
  23423. }
  23424. function handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  23425. // Type definitions functions
  23426. if (precedingNode && precedingNode.type === "FunctionTypeParam" && enclosingNode && enclosingNode.type === "FunctionTypeAnnotation" && followingNode && followingNode.type !== "FunctionTypeParam") {
  23427. addTrailingComment$2(precedingNode, comment);
  23428. return true;
  23429. } // Real functions
  23430. if (precedingNode && (precedingNode.type === "Identifier" || precedingNode.type === "AssignmentPattern") && enclosingNode && (enclosingNode.type === "ArrowFunctionExpression" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "ObjectMethod" || enclosingNode.type === "ClassMethod") && util.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) === ")") {
  23431. addTrailingComment$2(precedingNode, comment);
  23432. return true;
  23433. }
  23434. if (enclosingNode && enclosingNode.type === "FunctionDeclaration" && followingNode && followingNode.type === "BlockStatement") {
  23435. var functionParamRightParenIndex = function () {
  23436. if (enclosingNode.params.length !== 0) {
  23437. return util.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, options.locEnd(util.getLast(enclosingNode.params)));
  23438. }
  23439. var functionParamLeftParenIndex = util.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, options.locEnd(enclosingNode.id));
  23440. return util.getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, functionParamLeftParenIndex + 1);
  23441. }();
  23442. if (options.locStart(comment) > functionParamRightParenIndex) {
  23443. addBlockStatementFirstComment(followingNode, comment);
  23444. return true;
  23445. }
  23446. }
  23447. return false;
  23448. }
  23449. function handleImportSpecifierComments(enclosingNode, comment) {
  23450. if (enclosingNode && enclosingNode.type === "ImportSpecifier") {
  23451. addLeadingComment$2(enclosingNode, comment);
  23452. return true;
  23453. }
  23454. return false;
  23455. }
  23456. function handleLabeledStatementComments(enclosingNode, comment) {
  23457. if (enclosingNode && enclosingNode.type === "LabeledStatement") {
  23458. addLeadingComment$2(enclosingNode, comment);
  23459. return true;
  23460. }
  23461. return false;
  23462. }
  23463. function handleBreakAndContinueStatementComments(enclosingNode, comment) {
  23464. if (enclosingNode && (enclosingNode.type === "ContinueStatement" || enclosingNode.type === "BreakStatement") && !enclosingNode.label) {
  23465. addTrailingComment$2(enclosingNode, comment);
  23466. return true;
  23467. }
  23468. return false;
  23469. }
  23470. function handleCallExpressionComments(precedingNode, enclosingNode, comment) {
  23471. if (enclosingNode && (enclosingNode.type === "CallExpression" || enclosingNode.type === "OptionalCallExpression") && precedingNode && enclosingNode.callee === precedingNode && enclosingNode.arguments.length > 0) {
  23472. addLeadingComment$2(enclosingNode.arguments[0], comment);
  23473. return true;
  23474. }
  23475. return false;
  23476. }
  23477. function handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) {
  23478. if (enclosingNode && (enclosingNode.type === "UnionTypeAnnotation" || enclosingNode.type === "TSUnionType")) {
  23479. addTrailingComment$2(precedingNode, comment);
  23480. return true;
  23481. }
  23482. return false;
  23483. }
  23484. function handlePropertyComments(enclosingNode, comment) {
  23485. if (enclosingNode && (enclosingNode.type === "Property" || enclosingNode.type === "ObjectProperty")) {
  23486. addLeadingComment$2(enclosingNode, comment);
  23487. return true;
  23488. }
  23489. return false;
  23490. }
  23491. function handleOnlyComments(enclosingNode, ast, comment, isLastComment) {
  23492. // With Flow the enclosingNode is undefined so use the AST instead.
  23493. if (ast && ast.body && ast.body.length === 0) {
  23494. if (isLastComment) {
  23495. addDanglingComment$2(ast, comment);
  23496. } else {
  23497. addLeadingComment$2(ast, comment);
  23498. }
  23499. return true;
  23500. } else if (enclosingNode && enclosingNode.type === "Program" && enclosingNode.body.length === 0 && enclosingNode.directives && enclosingNode.directives.length === 0) {
  23501. if (isLastComment) {
  23502. addDanglingComment$2(enclosingNode, comment);
  23503. } else {
  23504. addLeadingComment$2(enclosingNode, comment);
  23505. }
  23506. return true;
  23507. }
  23508. return false;
  23509. }
  23510. function handleForComments(enclosingNode, precedingNode, comment) {
  23511. if (enclosingNode && (enclosingNode.type === "ForInStatement" || enclosingNode.type === "ForOfStatement")) {
  23512. addLeadingComment$2(enclosingNode, comment);
  23513. return true;
  23514. }
  23515. return false;
  23516. }
  23517. function handleImportDeclarationComments(text, enclosingNode, precedingNode, comment, options) {
  23518. if (precedingNode && precedingNode.type === "ImportSpecifier" && enclosingNode && enclosingNode.type === "ImportDeclaration" && util.hasNewline(text, options.locEnd(comment))) {
  23519. addTrailingComment$2(precedingNode, comment);
  23520. return true;
  23521. }
  23522. return false;
  23523. }
  23524. function handleAssignmentPatternComments(enclosingNode, comment) {
  23525. if (enclosingNode && enclosingNode.type === "AssignmentPattern") {
  23526. addLeadingComment$2(enclosingNode, comment);
  23527. return true;
  23528. }
  23529. return false;
  23530. }
  23531. function handleTypeAliasComments(enclosingNode, followingNode, comment) {
  23532. if (enclosingNode && enclosingNode.type === "TypeAlias") {
  23533. addLeadingComment$2(enclosingNode, comment);
  23534. return true;
  23535. }
  23536. return false;
  23537. }
  23538. function handleVariableDeclaratorComments(enclosingNode, followingNode, comment) {
  23539. if (enclosingNode && (enclosingNode.type === "VariableDeclarator" || enclosingNode.type === "AssignmentExpression") && followingNode && (followingNode.type === "ObjectExpression" || followingNode.type === "ArrayExpression" || followingNode.type === "TemplateLiteral" || followingNode.type === "TaggedTemplateExpression")) {
  23540. addLeadingComment$2(followingNode, comment);
  23541. return true;
  23542. }
  23543. return false;
  23544. }
  23545. function handleTSMappedTypeComments(text, enclosingNode, precedingNode, followingNode, comment) {
  23546. if (!enclosingNode || enclosingNode.type !== "TSMappedType") {
  23547. return false;
  23548. }
  23549. if (followingNode && followingNode.type === "TSTypeParameter" && followingNode.name) {
  23550. addLeadingComment$2(followingNode.name, comment);
  23551. return true;
  23552. }
  23553. if (precedingNode && precedingNode.type === "TSTypeParameter" && precedingNode.constraint) {
  23554. addTrailingComment$2(precedingNode.constraint, comment);
  23555. return true;
  23556. }
  23557. return false;
  23558. }
  23559. function isBlockComment(comment) {
  23560. return comment.type === "Block" || comment.type === "CommentBlock";
  23561. }
  23562. function hasLeadingComment(node) {
  23563. var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
  23564. return true;
  23565. };
  23566. if (node.leadingComments) {
  23567. return node.leadingComments.some(fn);
  23568. }
  23569. if (node.comments) {
  23570. return node.comments.some(function (comment) {
  23571. return comment.leading && fn(comment);
  23572. });
  23573. }
  23574. return false;
  23575. }
  23576. var comments$1 = {
  23577. handleOwnLineComment,
  23578. handleEndOfLineComment,
  23579. handleRemainingComment,
  23580. hasLeadingComment,
  23581. isBlockComment
  23582. };
  23583. var isBlockComment$1 = comments$1.isBlockComment,
  23584. hasLeadingComment$1 = comments$1.hasLeadingComment;
  23585. var _require$$1$builders = doc.builders,
  23586. indent$2 = _require$$1$builders.indent,
  23587. join$2 = _require$$1$builders.join,
  23588. hardline$3 = _require$$1$builders.hardline,
  23589. softline$1 = _require$$1$builders.softline,
  23590. literalline$1 = _require$$1$builders.literalline,
  23591. concat$4 = _require$$1$builders.concat,
  23592. group$1 = _require$$1$builders.group,
  23593. dedentToRoot$1 = _require$$1$builders.dedentToRoot,
  23594. _require$$1$utils = doc.utils,
  23595. mapDoc$3 = _require$$1$utils.mapDoc,
  23596. stripTrailingHardline$1 = _require$$1$utils.stripTrailingHardline;
  23597. function embed(path, print, textToDoc, options) {
  23598. var node = path.getValue();
  23599. var parent = path.getParentNode();
  23600. var parentParent = path.getParentNode(1);
  23601. switch (node.type) {
  23602. case "TemplateLiteral":
  23603. {
  23604. var isCss = [isStyledJsx, isStyledComponents, isCssProp, isAngularComponentStyles].some(function (isIt) {
  23605. return isIt(path);
  23606. });
  23607. if (isCss) {
  23608. // Get full template literal with expressions replaced by placeholders
  23609. var rawQuasis = node.quasis.map(function (q) {
  23610. return q.value.raw;
  23611. });
  23612. var placeholderID = 0;
  23613. var text = rawQuasis.reduce(function (prevVal, currVal, idx) {
  23614. return idx == 0 ? currVal : prevVal + "@prettier-placeholder-" + placeholderID++ + "-id" + currVal;
  23615. }, "");
  23616. var doc = textToDoc(text, {
  23617. parser: "css"
  23618. });
  23619. return transformCssDoc(doc, path, print);
  23620. }
  23621. /*
  23622. * react-relay and graphql-tag
  23623. * graphql`...`
  23624. * graphql.experimental`...`
  23625. * gql`...`
  23626. *
  23627. * This intentionally excludes Relay Classic tags, as Prettier does not
  23628. * support Relay Classic formatting.
  23629. */
  23630. if (isGraphQL(path)) {
  23631. var expressionDocs = node.expressions ? path.map(print, "expressions") : [];
  23632. var numQuasis = node.quasis.length;
  23633. if (numQuasis === 1 && node.quasis[0].value.raw.trim() === "") {
  23634. return "``";
  23635. }
  23636. var parts = [];
  23637. for (var i = 0; i < numQuasis; i++) {
  23638. var templateElement = node.quasis[i];
  23639. var isFirst = i === 0;
  23640. var isLast = i === numQuasis - 1;
  23641. var _text = templateElement.value.cooked; // Bail out if any of the quasis have an invalid escape sequence
  23642. // (which would make the `cooked` value be `null` or `undefined`)
  23643. if (typeof _text !== "string") {
  23644. return null;
  23645. }
  23646. var lines = _text.split("\n");
  23647. var numLines = lines.length;
  23648. var expressionDoc = expressionDocs[i];
  23649. var startsWithBlankLine = numLines > 2 && lines[0].trim() === "" && lines[1].trim() === "";
  23650. var endsWithBlankLine = numLines > 2 && lines[numLines - 1].trim() === "" && lines[numLines - 2].trim() === "";
  23651. var commentsAndWhitespaceOnly = lines.every(function (line) {
  23652. return /^\s*(?:#[^\r\n]*)?$/.test(line);
  23653. }); // Bail out if an interpolation occurs within a comment.
  23654. if (!isLast && /#[^\r\n]*$/.test(lines[numLines - 1])) {
  23655. return null;
  23656. }
  23657. var _doc = null;
  23658. if (commentsAndWhitespaceOnly) {
  23659. _doc = printGraphqlComments(lines);
  23660. } else {
  23661. _doc = stripTrailingHardline$1(textToDoc(_text, {
  23662. parser: "graphql"
  23663. }));
  23664. }
  23665. if (_doc) {
  23666. _doc = escapeTemplateCharacters(_doc, false);
  23667. if (!isFirst && startsWithBlankLine) {
  23668. parts.push("");
  23669. }
  23670. parts.push(_doc);
  23671. if (!isLast && endsWithBlankLine) {
  23672. parts.push("");
  23673. }
  23674. } else if (!isFirst && !isLast && startsWithBlankLine) {
  23675. parts.push("");
  23676. }
  23677. if (expressionDoc) {
  23678. parts.push(concat$4(["${", expressionDoc, "}"]));
  23679. }
  23680. }
  23681. return concat$4(["`", indent$2(concat$4([hardline$3, join$2(hardline$3, parts)])), hardline$3, "`"]);
  23682. }
  23683. var htmlParser = isHtml(path) ? "html" : isAngularComponentTemplate(path) ? "angular" : undefined;
  23684. if (htmlParser) {
  23685. return printHtmlTemplateLiteral(path, print, textToDoc, htmlParser, options.embeddedInHtml);
  23686. }
  23687. break;
  23688. }
  23689. case "TemplateElement":
  23690. {
  23691. /**
  23692. * md`...`
  23693. * markdown`...`
  23694. */
  23695. if (parentParent && parentParent.type === "TaggedTemplateExpression" && parent.quasis.length === 1 && parentParent.tag.type === "Identifier" && (parentParent.tag.name === "md" || parentParent.tag.name === "markdown")) {
  23696. var _text2 = parent.quasis[0].value.raw.replace(/((?:\\\\)*)\\`/g, function (_, backslashes) {
  23697. return "\\".repeat(backslashes.length / 2) + "`";
  23698. });
  23699. var indentation = getIndentation(_text2);
  23700. var hasIndent = indentation !== "";
  23701. return concat$4([hasIndent ? indent$2(concat$4([softline$1, printMarkdown(_text2.replace(new RegExp(`^${indentation}`, "gm"), ""))])) : concat$4([literalline$1, dedentToRoot$1(printMarkdown(_text2))]), softline$1]);
  23702. }
  23703. break;
  23704. }
  23705. }
  23706. function printMarkdown(text) {
  23707. var doc = textToDoc(text, {
  23708. parser: "markdown",
  23709. __inJsTemplate: true
  23710. });
  23711. return stripTrailingHardline$1(escapeTemplateCharacters(doc, true));
  23712. }
  23713. }
  23714. function getIndentation(str) {
  23715. var firstMatchedIndent = str.match(/^([^\S\n]*)\S/m);
  23716. return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
  23717. }
  23718. function uncook(cookedValue) {
  23719. return cookedValue.replace(/([\\`]|\$\{)/g, "\\$1");
  23720. }
  23721. function escapeTemplateCharacters(doc, raw) {
  23722. return mapDoc$3(doc, function (currentDoc) {
  23723. if (!currentDoc.parts) {
  23724. return currentDoc;
  23725. }
  23726. var parts = [];
  23727. currentDoc.parts.forEach(function (part) {
  23728. if (typeof part === "string") {
  23729. parts.push(raw ? part.replace(/(\\*)`/g, "$1$1\\`") : uncook(part));
  23730. } else {
  23731. parts.push(part);
  23732. }
  23733. });
  23734. return Object.assign({}, currentDoc, {
  23735. parts
  23736. });
  23737. });
  23738. }
  23739. function transformCssDoc(quasisDoc, path, print) {
  23740. var parentNode = path.getValue();
  23741. var isEmpty = parentNode.quasis.length === 1 && !parentNode.quasis[0].value.raw.trim();
  23742. if (isEmpty) {
  23743. return "``";
  23744. }
  23745. var expressionDocs = parentNode.expressions ? path.map(print, "expressions") : [];
  23746. var newDoc = replacePlaceholders(quasisDoc, expressionDocs);
  23747. /* istanbul ignore if */
  23748. if (!newDoc) {
  23749. throw new Error("Couldn't insert all the expressions");
  23750. }
  23751. return concat$4(["`", indent$2(concat$4([hardline$3, stripTrailingHardline$1(newDoc)])), softline$1, "`"]);
  23752. } // Search all the placeholders in the quasisDoc tree
  23753. // and replace them with the expression docs one by one
  23754. // returns a new doc with all the placeholders replaced,
  23755. // or null if it couldn't replace any expression
  23756. function replacePlaceholders(quasisDoc, expressionDocs) {
  23757. if (!expressionDocs || !expressionDocs.length) {
  23758. return quasisDoc;
  23759. }
  23760. var expressions = expressionDocs.slice();
  23761. var replaceCounter = 0;
  23762. var newDoc = mapDoc$3(quasisDoc, function (doc) {
  23763. if (!doc || !doc.parts || !doc.parts.length) {
  23764. return doc;
  23765. }
  23766. var parts = doc.parts;
  23767. var atIndex = parts.indexOf("@");
  23768. var placeholderIndex = atIndex + 1;
  23769. if (atIndex > -1 && typeof parts[placeholderIndex] === "string" && parts[placeholderIndex].startsWith("prettier-placeholder")) {
  23770. // If placeholder is split, join it
  23771. var at = parts[atIndex];
  23772. var placeholder = parts[placeholderIndex];
  23773. var rest = parts.slice(placeholderIndex + 1);
  23774. parts = parts.slice(0, atIndex).concat([at + placeholder]).concat(rest);
  23775. }
  23776. var atPlaceholderIndex = parts.findIndex(function (part) {
  23777. return typeof part === "string" && part.startsWith("@prettier-placeholder");
  23778. });
  23779. if (atPlaceholderIndex > -1) {
  23780. var _placeholder = parts[atPlaceholderIndex];
  23781. var _rest = parts.slice(atPlaceholderIndex + 1);
  23782. var placeholderMatch = _placeholder.match(/@prettier-placeholder-(.+)-id([\s\S]*)/);
  23783. var placeholderID = placeholderMatch[1]; // When the expression has a suffix appended, like:
  23784. // animation: linear ${time}s ease-out;
  23785. var suffix = placeholderMatch[2];
  23786. var expression = expressions[placeholderID];
  23787. replaceCounter++;
  23788. parts = parts.slice(0, atPlaceholderIndex).concat(["${", expression, "}" + suffix]).concat(_rest);
  23789. }
  23790. return Object.assign({}, doc, {
  23791. parts: parts
  23792. });
  23793. });
  23794. return expressions.length === replaceCounter ? newDoc : null;
  23795. }
  23796. function printGraphqlComments(lines) {
  23797. var parts = [];
  23798. var seenComment = false;
  23799. lines.map(function (textLine) {
  23800. return textLine.trim();
  23801. }).forEach(function (textLine, i, array) {
  23802. // Lines are either whitespace only, or a comment (with potential whitespace
  23803. // around it). Drop whitespace-only lines.
  23804. if (textLine === "") {
  23805. return;
  23806. }
  23807. if (array[i - 1] === "" && seenComment) {
  23808. // If a non-first comment is preceded by a blank (whitespace only) line,
  23809. // add in a blank line.
  23810. parts.push(concat$4([hardline$3, textLine]));
  23811. } else {
  23812. parts.push(textLine);
  23813. }
  23814. seenComment = true;
  23815. }); // If `lines` was whitespace only, return `null`.
  23816. return parts.length === 0 ? null : join$2(hardline$3, parts);
  23817. }
  23818. /**
  23819. * Template literal in these contexts:
  23820. * <style jsx>{`div{color:red}`}</style>
  23821. * css``
  23822. * css.global``
  23823. * css.resolve``
  23824. */
  23825. function isStyledJsx(path) {
  23826. var node = path.getValue();
  23827. var parent = path.getParentNode();
  23828. var parentParent = path.getParentNode(1);
  23829. return parentParent && node.quasis && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXElement" && parentParent.openingElement.name.name === "style" && parentParent.openingElement.attributes.some(function (attribute) {
  23830. return attribute.name.name === "jsx";
  23831. }) || 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");
  23832. }
  23833. /**
  23834. * Angular Components can have:
  23835. * - Inline HTML template
  23836. * - Inline CSS styles
  23837. *
  23838. * ...which are both within template literals somewhere
  23839. * inside of the Component decorator factory.
  23840. *
  23841. * E.g.
  23842. * @Component({
  23843. * template: `<div>...</div>`,
  23844. * styles: [`h1 { color: blue; }`]
  23845. * })
  23846. */
  23847. function isAngularComponentStyles(path) {
  23848. return isPathMatch(path, [function (node) {
  23849. return node.type === "TemplateLiteral";
  23850. }, function (node, name) {
  23851. return node.type === "ArrayExpression" && name === "elements";
  23852. }, function (node, name) {
  23853. return node.type === "Property" && node.key.type === "Identifier" && node.key.name === "styles" && name === "value";
  23854. }].concat(getAngularComponentObjectExpressionPredicates()));
  23855. }
  23856. function isAngularComponentTemplate(path) {
  23857. return isPathMatch(path, [function (node) {
  23858. return node.type === "TemplateLiteral";
  23859. }, function (node, name) {
  23860. return node.type === "Property" && node.key.type === "Identifier" && node.key.name === "template" && name === "value";
  23861. }].concat(getAngularComponentObjectExpressionPredicates()));
  23862. }
  23863. function getAngularComponentObjectExpressionPredicates() {
  23864. return [function (node, name) {
  23865. return node.type === "ObjectExpression" && name === "properties";
  23866. }, function (node, name) {
  23867. return node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "Component" && name === "arguments";
  23868. }, function (node, name) {
  23869. return node.type === "Decorator" && name === "expression";
  23870. }];
  23871. }
  23872. /**
  23873. * styled-components template literals
  23874. */
  23875. function isStyledComponents(path) {
  23876. var parent = path.getParentNode();
  23877. if (!parent || parent.type !== "TaggedTemplateExpression") {
  23878. return false;
  23879. }
  23880. var tag = parent.tag;
  23881. switch (tag.type) {
  23882. case "MemberExpression":
  23883. return (// styled.foo``
  23884. isStyledIdentifier(tag.object) || // Component.extend``
  23885. isStyledExtend(tag)
  23886. );
  23887. case "CallExpression":
  23888. return (// styled(Component)``
  23889. isStyledIdentifier(tag.callee) || tag.callee.type === "MemberExpression" && (tag.callee.object.type === "MemberExpression" && ( // styled.foo.attrs({})``
  23890. isStyledIdentifier(tag.callee.object.object) || // Component.extend.attrs({})``
  23891. isStyledExtend(tag.callee.object)) || // styled(Component).attrs({})``
  23892. tag.callee.object.type === "CallExpression" && isStyledIdentifier(tag.callee.object.callee))
  23893. );
  23894. case "Identifier":
  23895. // css``
  23896. return tag.name === "css";
  23897. default:
  23898. return false;
  23899. }
  23900. }
  23901. /**
  23902. * JSX element with CSS prop
  23903. */
  23904. function isCssProp(path) {
  23905. var parent = path.getParentNode();
  23906. var parentParent = path.getParentNode(1);
  23907. return parentParent && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" && parentParent.name.type === "JSXIdentifier" && parentParent.name.name === "css";
  23908. }
  23909. function isStyledIdentifier(node) {
  23910. return node.type === "Identifier" && node.name === "styled";
  23911. }
  23912. function isStyledExtend(node) {
  23913. return /^[A-Z]/.test(node.object.name) && node.property.name === "extend";
  23914. }
  23915. /*
  23916. * react-relay and graphql-tag
  23917. * graphql`...`
  23918. * graphql.experimental`...`
  23919. * gql`...`
  23920. * GraphQL comment block
  23921. *
  23922. * This intentionally excludes Relay Classic tags, as Prettier does not
  23923. * support Relay Classic formatting.
  23924. */
  23925. function isGraphQL(path) {
  23926. var node = path.getValue();
  23927. var parent = path.getParentNode();
  23928. 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");
  23929. }
  23930. function hasLanguageComment(node, languageName) {
  23931. // This checks for a leading comment that is exactly `/* GraphQL */`
  23932. // In order to be in line with other implementations of this comment tag
  23933. // we will not trim the comment value and we will expect exactly one space on
  23934. // either side of the GraphQL string
  23935. // Also see ./clean.js
  23936. return hasLeadingComment$1(node, function (comment) {
  23937. return isBlockComment$1(comment) && comment.value === ` ${languageName} `;
  23938. });
  23939. }
  23940. function isPathMatch(path, predicateStack) {
  23941. var stack = path.stack.slice();
  23942. var name = null;
  23943. var node = stack.pop();
  23944. var _iteratorNormalCompletion = true;
  23945. var _didIteratorError = false;
  23946. var _iteratorError = undefined;
  23947. try {
  23948. for (var _iterator = predicateStack[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  23949. var predicate = _step.value;
  23950. if (node === undefined) {
  23951. return false;
  23952. } // skip index/array
  23953. if (typeof name === "number") {
  23954. name = stack.pop();
  23955. node = stack.pop();
  23956. }
  23957. if (!predicate(node, name)) {
  23958. return false;
  23959. }
  23960. name = stack.pop();
  23961. node = stack.pop();
  23962. }
  23963. } catch (err) {
  23964. _didIteratorError = true;
  23965. _iteratorError = err;
  23966. } finally {
  23967. try {
  23968. if (!_iteratorNormalCompletion && _iterator.return != null) {
  23969. _iterator.return();
  23970. }
  23971. } finally {
  23972. if (_didIteratorError) {
  23973. throw _iteratorError;
  23974. }
  23975. }
  23976. }
  23977. return true;
  23978. }
  23979. /**
  23980. * - html`...`
  23981. * - HTML comment block
  23982. */
  23983. function isHtml(path) {
  23984. var node = path.getValue();
  23985. return hasLanguageComment(node, "HTML") || isPathMatch(path, [function (node) {
  23986. return node.type === "TemplateLiteral";
  23987. }, function (node, name) {
  23988. return node.type === "TaggedTemplateExpression" && node.tag.type === "Identifier" && node.tag.name === "html" && name === "quasi";
  23989. }]);
  23990. } // The counter is needed to distinguish nested embeds.
  23991. var htmlTemplateLiteralCounter = 0;
  23992. function printHtmlTemplateLiteral(path, print, textToDoc, parser, escapeClosingScriptTag) {
  23993. var node = path.getValue();
  23994. var counter = htmlTemplateLiteralCounter;
  23995. htmlTemplateLiteralCounter = htmlTemplateLiteralCounter + 1 >>> 0;
  23996. var composePlaceholder = function composePlaceholder(index) {
  23997. return `PRETTIER_HTML_PLACEHOLDER_${index}_${counter}_IN_JS`;
  23998. };
  23999. var text = node.quasis.map(function (quasi, index, quasis) {
  24000. return index === quasis.length - 1 ? quasi.value.cooked : quasi.value.cooked + composePlaceholder(index);
  24001. }).join("");
  24002. var expressionDocs = path.map(print, "expressions");
  24003. if (expressionDocs.length === 0 && text.trim().length === 0) {
  24004. return "``";
  24005. }
  24006. var placeholderRegex = RegExp(composePlaceholder("(\\d+)"), "g");
  24007. var contentDoc = mapDoc$3(stripTrailingHardline$1(textToDoc(text, {
  24008. parser
  24009. })), function (doc) {
  24010. if (typeof doc !== "string") {
  24011. return doc;
  24012. }
  24013. var parts = [];
  24014. var components = doc.split(placeholderRegex);
  24015. for (var i = 0; i < components.length; i++) {
  24016. var component = components[i];
  24017. if (i % 2 === 0) {
  24018. if (component) {
  24019. component = uncook(component);
  24020. if (escapeClosingScriptTag) {
  24021. component = component.replace(/<\/(script)\b/gi, "<\\/$1");
  24022. }
  24023. parts.push(component);
  24024. }
  24025. continue;
  24026. }
  24027. var placeholderIndex = +component;
  24028. parts.push(concat$4(["${", group$1(expressionDocs[placeholderIndex]), "}"]));
  24029. }
  24030. return concat$4(parts);
  24031. });
  24032. return group$1(concat$4(["`", indent$2(concat$4([hardline$3, group$1(contentDoc)])), softline$1, "`"]));
  24033. }
  24034. var embed_1 = embed;
  24035. function clean(ast, newObj, parent) {
  24036. ["range", "raw", "comments", "leadingComments", "trailingComments", "extra", "start", "end", "flags", "errors"].forEach(function (name) {
  24037. delete newObj[name];
  24038. });
  24039. if (ast.type === "BigIntLiteral") {
  24040. newObj.value = newObj.value.toLowerCase();
  24041. } // We remove extra `;` and add them when needed
  24042. if (ast.type === "EmptyStatement") {
  24043. return null;
  24044. } // We move text around, including whitespaces and add {" "}
  24045. if (ast.type === "JSXText") {
  24046. return null;
  24047. }
  24048. if (ast.type === "JSXExpressionContainer" && ast.expression.type === "Literal" && ast.expression.value === " ") {
  24049. return null;
  24050. } // We remove unneeded parens around same-operator LogicalExpressions
  24051. if (isUnbalancedLogicalTree(newObj)) {
  24052. return rebalanceLogicalTree(newObj);
  24053. } // (TypeScript) Ignore `static` in `constructor(static p) {}`
  24054. // and `export` in `constructor(export p) {}`
  24055. if (ast.type === "TSParameterProperty" && ast.accessibility === null && !ast.readonly) {
  24056. return {
  24057. type: "Identifier",
  24058. name: ast.parameter.name,
  24059. typeAnnotation: newObj.parameter.typeAnnotation,
  24060. decorators: newObj.decorators
  24061. };
  24062. } // (TypeScript) ignore empty `specifiers` array
  24063. if (ast.type === "TSNamespaceExportDeclaration" && ast.specifiers && ast.specifiers.length === 0) {
  24064. delete newObj.specifiers;
  24065. } // We convert <div></div> to <div />
  24066. if (ast.type === "JSXOpeningElement") {
  24067. delete newObj.selfClosing;
  24068. }
  24069. if (ast.type === "JSXElement") {
  24070. delete newObj.closingElement;
  24071. } // We change {'key': value} into {key: value}
  24072. if ((ast.type === "Property" || ast.type === "ObjectProperty" || ast.type === "MethodDefinition" || ast.type === "ClassProperty" || ast.type === "TSPropertySignature" || ast.type === "ObjectTypeProperty") && typeof ast.key === "object" && ast.key && (ast.key.type === "Literal" || ast.key.type === "StringLiteral" || ast.key.type === "Identifier")) {
  24073. delete newObj.key;
  24074. }
  24075. if (ast.type === "OptionalMemberExpression" && ast.optional === false) {
  24076. newObj.type = "MemberExpression";
  24077. delete newObj.optional;
  24078. } // Remove raw and cooked values from TemplateElement when it's CSS
  24079. // styled-jsx
  24080. if (ast.type === "JSXElement" && ast.openingElement.name.name === "style" && ast.openingElement.attributes.some(function (attr) {
  24081. return attr.name.name === "jsx";
  24082. })) {
  24083. var templateLiterals = newObj.children.filter(function (child) {
  24084. return child.type === "JSXExpressionContainer" && child.expression.type === "TemplateLiteral";
  24085. }).map(function (container) {
  24086. return container.expression;
  24087. });
  24088. var quasis = templateLiterals.reduce(function (quasis, templateLiteral) {
  24089. return quasis.concat(templateLiteral.quasis);
  24090. }, []);
  24091. quasis.forEach(function (q) {
  24092. return delete q.value;
  24093. });
  24094. } // CSS template literals in css prop
  24095. if (ast.type === "JSXAttribute" && ast.name.name === "css" && ast.value.type === "JSXExpressionContainer" && ast.value.expression.type === "TemplateLiteral") {
  24096. newObj.value.expression.quasis.forEach(function (q) {
  24097. return delete q.value;
  24098. });
  24099. } // Angular Components: Inline HTML template and Inline CSS styles
  24100. var expression = ast.expression || ast.callee;
  24101. if (ast.type === "Decorator" && expression.type === "CallExpression" && expression.callee.name === "Component" && expression.arguments.length === 1) {
  24102. var astProps = ast.expression.arguments[0].properties;
  24103. newObj.expression.arguments[0].properties.forEach(function (prop, index) {
  24104. var templateLiteral = null;
  24105. switch (astProps[index].key.name) {
  24106. case "styles":
  24107. if (prop.value.type === "ArrayExpression") {
  24108. templateLiteral = prop.value.elements[0];
  24109. }
  24110. break;
  24111. case "template":
  24112. if (prop.value.type === "TemplateLiteral") {
  24113. templateLiteral = prop.value;
  24114. }
  24115. break;
  24116. }
  24117. if (templateLiteral) {
  24118. templateLiteral.quasis.forEach(function (q) {
  24119. return delete q.value;
  24120. });
  24121. }
  24122. });
  24123. } // styled-components, graphql, markdown
  24124. 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")) {
  24125. newObj.quasi.quasis.forEach(function (quasi) {
  24126. return delete quasi.value;
  24127. });
  24128. }
  24129. if (ast.type === "TemplateLiteral") {
  24130. // This checks for a leading comment that is exactly `/* GraphQL */`
  24131. // In order to be in line with other implementations of this comment tag
  24132. // we will not trim the comment value and we will expect exactly one space on
  24133. // either side of the GraphQL string
  24134. // Also see ./embed.js
  24135. var hasLanguageComment = ast.leadingComments && ast.leadingComments.some(function (comment) {
  24136. return comment.type === "CommentBlock" && ["GraphQL", "HTML"].some(function (languageName) {
  24137. return comment.value === ` ${languageName} `;
  24138. });
  24139. });
  24140. if (hasLanguageComment || parent.type === "CallExpression" && parent.callee.name === "graphql") {
  24141. newObj.quasis.forEach(function (quasi) {
  24142. return delete quasi.value;
  24143. });
  24144. }
  24145. }
  24146. }
  24147. function isUnbalancedLogicalTree(newObj) {
  24148. return newObj.type === "LogicalExpression" && newObj.right.type === "LogicalExpression" && newObj.operator === newObj.right.operator;
  24149. }
  24150. function rebalanceLogicalTree(newObj) {
  24151. if (isUnbalancedLogicalTree(newObj)) {
  24152. return rebalanceLogicalTree({
  24153. type: "LogicalExpression",
  24154. operator: newObj.operator,
  24155. left: rebalanceLogicalTree({
  24156. type: "LogicalExpression",
  24157. operator: newObj.operator,
  24158. left: newObj.left,
  24159. right: newObj.right.left,
  24160. loc: {}
  24161. }),
  24162. right: newObj.right.right,
  24163. loc: {}
  24164. });
  24165. }
  24166. return newObj;
  24167. }
  24168. var clean_1 = clean;
  24169. var detectNewline = createCommonjsModule(function (module) {
  24170. module.exports = function (str) {
  24171. if (typeof str !== 'string') {
  24172. throw new TypeError('Expected a string');
  24173. }
  24174. var newlines = str.match(/(?:\r?\n)/g) || [];
  24175. if (newlines.length === 0) {
  24176. return null;
  24177. }
  24178. var crlf = newlines.filter(function (el) {
  24179. return el === '\r\n';
  24180. }).length;
  24181. var lf = newlines.length - crlf;
  24182. return crlf > lf ? '\r\n' : '\n';
  24183. };
  24184. module.exports.graceful = function (str) {
  24185. return module.exports(str) || '\n';
  24186. };
  24187. });
  24188. var detectNewline_1 = detectNewline.graceful;
  24189. var build = createCommonjsModule(function (module, exports) {
  24190. Object.defineProperty(exports, '__esModule', {
  24191. value: true
  24192. });
  24193. exports.extract = extract;
  24194. exports.strip = strip;
  24195. exports.parse = parse;
  24196. exports.parseWithComments = parseWithComments;
  24197. exports.print = print;
  24198. function _os() {
  24199. var data = os$1;
  24200. _os = function _os() {
  24201. return data;
  24202. };
  24203. return data;
  24204. }
  24205. function _detectNewline() {
  24206. var data = _interopRequireDefault(detectNewline);
  24207. _detectNewline = function _detectNewline() {
  24208. return data;
  24209. };
  24210. return data;
  24211. }
  24212. function _interopRequireDefault(obj) {
  24213. return obj && obj.__esModule ? obj : {
  24214. default: obj
  24215. };
  24216. }
  24217. /**
  24218. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  24219. *
  24220. * This source code is licensed under the MIT license found in the
  24221. * LICENSE file in the root directory of this source tree.
  24222. */
  24223. var commentEndRe = /\*\/$/;
  24224. var commentStartRe = /^\/\*\*/;
  24225. var docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;
  24226. var lineCommentRe = /(^|\s+)\/\/([^\r\n]*)/g;
  24227. var ltrimNewlineRe = /^(\r?\n)+/;
  24228. var multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *(?![^@\r\n]*\/\/[^]*)([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
  24229. var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
  24230. var stringStartRe = /(\r?\n|^) *\* ?/g;
  24231. function extract(contents) {
  24232. var match = contents.match(docblockRe);
  24233. return match ? match[0].trimLeft() : '';
  24234. }
  24235. function strip(contents) {
  24236. var match = contents.match(docblockRe);
  24237. return match && match[0] ? contents.substring(match[0].length) : contents;
  24238. }
  24239. function parse(docblock) {
  24240. return parseWithComments(docblock).pragmas;
  24241. }
  24242. function parseWithComments(docblock) {
  24243. var line = (0, _detectNewline().default)(docblock) || _os().EOL;
  24244. docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replace(stringStartRe, '$1'); // Normalize multi-line directives
  24245. var prev = '';
  24246. while (prev !== docblock) {
  24247. prev = docblock;
  24248. docblock = docblock.replace(multilineRe, `${line}$1 $2${line}`);
  24249. }
  24250. docblock = docblock.replace(ltrimNewlineRe, '').trimRight();
  24251. var result = Object.create(null);
  24252. var comments = docblock.replace(propertyRe, '').replace(ltrimNewlineRe, '').trimRight();
  24253. var match;
  24254. while (match = propertyRe.exec(docblock)) {
  24255. // strip linecomments from pragmas
  24256. var nextPragma = match[2].replace(lineCommentRe, '');
  24257. if (typeof result[match[1]] === 'string' || Array.isArray(result[match[1]])) {
  24258. result[match[1]] = [].concat(result[match[1]], nextPragma);
  24259. } else {
  24260. result[match[1]] = nextPragma;
  24261. }
  24262. }
  24263. return {
  24264. comments,
  24265. pragmas: result
  24266. };
  24267. }
  24268. function print(_ref) {
  24269. var _ref$comments = _ref.comments,
  24270. comments = _ref$comments === void 0 ? '' : _ref$comments,
  24271. _ref$pragmas = _ref.pragmas,
  24272. pragmas = _ref$pragmas === void 0 ? {} : _ref$pragmas;
  24273. var line = (0, _detectNewline().default)(comments) || _os().EOL;
  24274. var head = '/**';
  24275. var start = ' *';
  24276. var tail = ' */';
  24277. var keys = Object.keys(pragmas);
  24278. var printedObject = keys.map(function (key) {
  24279. return printKeyValues(key, pragmas[key]);
  24280. }).reduce(function (arr, next) {
  24281. return arr.concat(next);
  24282. }, []).map(function (keyValue) {
  24283. return start + ' ' + keyValue + line;
  24284. }).join('');
  24285. if (!comments) {
  24286. if (keys.length === 0) {
  24287. return '';
  24288. }
  24289. if (keys.length === 1 && !Array.isArray(pragmas[keys[0]])) {
  24290. var value = pragmas[keys[0]];
  24291. return `${head} ${printKeyValues(keys[0], value)[0]}${tail}`;
  24292. }
  24293. }
  24294. var printedComments = comments.split(line).map(function (textLine) {
  24295. return `${start} ${textLine}`;
  24296. }).join(line) + line;
  24297. return head + line + (comments ? printedComments : '') + (comments && keys.length ? start + line : '') + printedObject + tail;
  24298. }
  24299. function printKeyValues(key, valueOrArray) {
  24300. return [].concat(valueOrArray).map(function (value) {
  24301. return `@${key} ${value}`.trim();
  24302. });
  24303. }
  24304. });
  24305. unwrapExports(build);
  24306. var build_1 = build.extract;
  24307. var build_2 = build.strip;
  24308. var build_3 = build.parse;
  24309. var build_4 = build.parseWithComments;
  24310. var build_5 = build.print;
  24311. function hasPragma(text) {
  24312. var pragmas = Object.keys(build.parse(build.extract(text)));
  24313. return pragmas.indexOf("prettier") !== -1 || pragmas.indexOf("format") !== -1;
  24314. }
  24315. function insertPragma(text) {
  24316. var parsedDocblock = build.parseWithComments(build.extract(text));
  24317. var pragmas = Object.assign({
  24318. format: ""
  24319. }, parsedDocblock.pragmas);
  24320. var newDocblock = build.print({
  24321. pragmas,
  24322. comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, "") // remove leading newlines
  24323. }).replace(/(\r\n|\r)/g, "\n"); // normalise newlines (mitigate use of os.EOL by jest-docblock)
  24324. var strippedText = build.strip(text);
  24325. var separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n";
  24326. return newDocblock + separatingNewlines + strippedText;
  24327. }
  24328. var pragma = {
  24329. hasPragma,
  24330. insertPragma
  24331. };
  24332. var getLast$1 = util.getLast,
  24333. hasNewline$2 = util.hasNewline,
  24334. hasNewlineInRange$1 = util.hasNewlineInRange,
  24335. hasIgnoreComment$1 = util.hasIgnoreComment,
  24336. hasNodeIgnoreComment$1 = util.hasNodeIgnoreComment,
  24337. skipWhitespace$1 = util.skipWhitespace;
  24338. var isIdentifierName = utils$1.keyword.isIdentifierNameES5; // We match any whitespace except line terminators because
  24339. // Flow annotation comments cannot be split across lines. For example:
  24340. //
  24341. // (this /*
  24342. // : any */).foo = 5;
  24343. //
  24344. // is not picked up by Flow (see https://github.com/facebook/flow/issues/7050), so
  24345. // removing the newline would create a type annotation that the user did not intend
  24346. // to create.
  24347. var NON_LINE_TERMINATING_WHITE_SPACE = "(?:(?=.)\\s)";
  24348. var FLOW_SHORTHAND_ANNOTATION = new RegExp(`^${NON_LINE_TERMINATING_WHITE_SPACE}*:`);
  24349. var FLOW_ANNOTATION = new RegExp(`^${NON_LINE_TERMINATING_WHITE_SPACE}*::`);
  24350. function hasFlowShorthandAnnotationComment(node) {
  24351. // https://flow.org/en/docs/types/comments/
  24352. // Syntax example: const r = new (window.Request /*: Class<Request> */)("");
  24353. return node.extra && node.extra.parenthesized && node.trailingComments && node.trailingComments[0].value.match(FLOW_SHORTHAND_ANNOTATION);
  24354. }
  24355. function hasFlowAnnotationComment(comments) {
  24356. return comments && comments[0].value.match(FLOW_ANNOTATION);
  24357. }
  24358. function hasNode(node, fn) {
  24359. if (!node || typeof node !== "object") {
  24360. return false;
  24361. }
  24362. if (Array.isArray(node)) {
  24363. return node.some(function (value) {
  24364. return hasNode(value, fn);
  24365. });
  24366. }
  24367. var result = fn(node);
  24368. return typeof result === "boolean" ? result : Object.keys(node).some(function (key) {
  24369. return hasNode(node[key], fn);
  24370. });
  24371. }
  24372. function hasNakedLeftSide(node) {
  24373. 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";
  24374. }
  24375. function getLeftSide(node) {
  24376. if (node.expressions) {
  24377. return node.expressions[0];
  24378. }
  24379. return node.left || node.test || node.callee || node.object || node.tag || node.argument || node.expression;
  24380. }
  24381. function getLeftSidePathName(path, node) {
  24382. if (node.expressions) {
  24383. return ["expressions", 0];
  24384. }
  24385. if (node.left) {
  24386. return ["left"];
  24387. }
  24388. if (node.test) {
  24389. return ["test"];
  24390. }
  24391. if (node.object) {
  24392. return ["object"];
  24393. }
  24394. if (node.callee) {
  24395. return ["callee"];
  24396. }
  24397. if (node.tag) {
  24398. return ["tag"];
  24399. }
  24400. if (node.argument) {
  24401. return ["argument"];
  24402. }
  24403. if (node.expression) {
  24404. return ["expression"];
  24405. }
  24406. throw new Error("Unexpected node has no left side", node);
  24407. }
  24408. function isLiteral(node) {
  24409. return node.type === "BooleanLiteral" || node.type === "DirectiveLiteral" || node.type === "Literal" || node.type === "NullLiteral" || node.type === "NumericLiteral" || node.type === "RegExpLiteral" || node.type === "StringLiteral" || node.type === "TemplateLiteral" || node.type === "TSTypeLiteral" || node.type === "JSXText";
  24410. }
  24411. function isNumericLiteral(node) {
  24412. return node.type === "NumericLiteral" || node.type === "Literal" && typeof node.value === "number";
  24413. }
  24414. function isStringLiteral(node) {
  24415. return node.type === "StringLiteral" || node.type === "Literal" && typeof node.value === "string";
  24416. }
  24417. function isObjectType(n) {
  24418. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral";
  24419. }
  24420. function isFunctionOrArrowExpression(node) {
  24421. return node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
  24422. }
  24423. function isFunctionOrArrowExpressionWithBody(node) {
  24424. return node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" && node.body.type === "BlockStatement";
  24425. }
  24426. function isTemplateLiteral(node) {
  24427. return node.type === "TemplateLiteral";
  24428. } // `inject` is used in AngularJS 1.x, `async` in Angular 2+
  24429. // example: https://docs.angularjs.org/guide/unit-testing#using-beforeall-
  24430. function isAngularTestWrapper(node) {
  24431. return (node.type === "CallExpression" || node.type === "OptionalCallExpression") && node.callee.type === "Identifier" && (node.callee.name === "async" || node.callee.name === "inject" || node.callee.name === "fakeAsync");
  24432. }
  24433. function isJSXNode(node) {
  24434. return node.type === "JSXElement" || node.type === "JSXFragment";
  24435. }
  24436. function isTheOnlyJSXElementInMarkdown(options, path) {
  24437. if (options.parentParser !== "markdown" && options.parentParser !== "mdx") {
  24438. return false;
  24439. }
  24440. var node = path.getNode();
  24441. if (!node.expression || !isJSXNode(node.expression)) {
  24442. return false;
  24443. }
  24444. var parent = path.getParentNode();
  24445. return parent.type === "Program" && parent.body.length == 1;
  24446. } // Detect an expression node representing `{" "}`
  24447. function isJSXWhitespaceExpression(node) {
  24448. return node.type === "JSXExpressionContainer" && isLiteral(node.expression) && node.expression.value === " " && !node.expression.comments;
  24449. }
  24450. function isMemberExpressionChain(node) {
  24451. if (node.type !== "MemberExpression" && node.type !== "OptionalMemberExpression") {
  24452. return false;
  24453. }
  24454. if (node.object.type === "Identifier") {
  24455. return true;
  24456. }
  24457. return isMemberExpressionChain(node.object);
  24458. }
  24459. function isGetterOrSetter(node) {
  24460. return node.kind === "get" || node.kind === "set";
  24461. }
  24462. function sameLocStart(nodeA, nodeB, options) {
  24463. return options.locStart(nodeA) === options.locStart(nodeB);
  24464. } // TODO: This is a bad hack and we need a better way to distinguish between
  24465. // arrow functions and otherwise
  24466. function isFunctionNotation(node, options) {
  24467. return isGetterOrSetter(node) || sameLocStart(node, node.value, options);
  24468. } // Hack to differentiate between the following two which have the same ast
  24469. // type T = { method: () => void };
  24470. // type T = { method(): void };
  24471. function isObjectTypePropertyAFunction(node, options) {
  24472. return (node.type === "ObjectTypeProperty" || node.type === "ObjectTypeInternalSlot") && node.value.type === "FunctionTypeAnnotation" && !node.static && !isFunctionNotation(node, options);
  24473. } // Hack to differentiate between the following two which have the same ast
  24474. // declare function f(a): void;
  24475. // var f: (a) => void;
  24476. function isTypeAnnotationAFunction(node, options) {
  24477. return (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") && node.typeAnnotation.type === "FunctionTypeAnnotation" && !node.static && !sameLocStart(node, node.typeAnnotation, options);
  24478. }
  24479. function isBinaryish(node) {
  24480. return node.type === "BinaryExpression" || node.type === "LogicalExpression" || node.type === "NGPipeExpression";
  24481. }
  24482. function isMemberish(node) {
  24483. return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "BindExpression" && node.object;
  24484. }
  24485. function isSimpleFlowType(node) {
  24486. var flowTypeAnnotations = ["AnyTypeAnnotation", "NullLiteralTypeAnnotation", "GenericTypeAnnotation", "ThisTypeAnnotation", "NumberTypeAnnotation", "VoidTypeAnnotation", "EmptyTypeAnnotation", "MixedTypeAnnotation", "BooleanTypeAnnotation", "BooleanLiteralTypeAnnotation", "StringTypeAnnotation"];
  24487. return node && flowTypeAnnotations.indexOf(node.type) !== -1 && !(node.type === "GenericTypeAnnotation" && node.typeParameters);
  24488. }
  24489. var unitTestRe = /^(skip|[fx]?(it|describe|test))$/;
  24490. function isSkipOrOnlyBlock(node) {
  24491. 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");
  24492. }
  24493. function isUnitTestSetUp(n) {
  24494. var unitTestSetUpRe = /^(before|after)(Each|All)$/;
  24495. return n.callee.type === "Identifier" && unitTestSetUpRe.test(n.callee.name) && n.arguments.length === 1;
  24496. } // eg; `describe("some string", (done) => {})`
  24497. function isTestCall(n, parent) {
  24498. if (n.type !== "CallExpression") {
  24499. return false;
  24500. }
  24501. if (n.arguments.length === 1) {
  24502. if (isAngularTestWrapper(n) && parent && isTestCall(parent)) {
  24503. return isFunctionOrArrowExpression(n.arguments[0]);
  24504. }
  24505. if (isUnitTestSetUp(n)) {
  24506. return isAngularTestWrapper(n.arguments[0]);
  24507. }
  24508. } else if (n.arguments.length === 2 || n.arguments.length === 3) {
  24509. if ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name) || isSkipOrOnlyBlock(n)) && (isTemplateLiteral(n.arguments[0]) || isStringLiteral(n.arguments[0]))) {
  24510. // it("name", () => { ... }, 2500)
  24511. if (n.arguments[2] && !isNumericLiteral(n.arguments[2])) {
  24512. return false;
  24513. }
  24514. return (n.arguments.length === 2 ? isFunctionOrArrowExpression(n.arguments[1]) : isFunctionOrArrowExpressionWithBody(n.arguments[1]) && n.arguments[1].params.length <= 1) || isAngularTestWrapper(n.arguments[1]);
  24515. }
  24516. }
  24517. return false;
  24518. }
  24519. function hasLeadingComment$2(node) {
  24520. return node.comments && node.comments.some(function (comment) {
  24521. return comment.leading;
  24522. });
  24523. }
  24524. function hasTrailingComment(node) {
  24525. return node.comments && node.comments.some(function (comment) {
  24526. return comment.trailing;
  24527. });
  24528. }
  24529. function isCallOrOptionalCallExpression(node) {
  24530. return node.type === "CallExpression" || node.type === "OptionalCallExpression";
  24531. }
  24532. function hasDanglingComments(node) {
  24533. return node.comments && node.comments.some(function (comment) {
  24534. return !comment.leading && !comment.trailing;
  24535. });
  24536. }
  24537. /** identify if an angular expression seems to have side effects */
  24538. function hasNgSideEffect(path) {
  24539. return hasNode(path.getValue(), function (node) {
  24540. switch (node.type) {
  24541. case undefined:
  24542. return false;
  24543. case "CallExpression":
  24544. case "OptionalCallExpression":
  24545. case "AssignmentExpression":
  24546. return true;
  24547. }
  24548. });
  24549. }
  24550. function isNgForOf(node, index, parentNode) {
  24551. return node.type === "NGMicrosyntaxKeyedExpression" && node.key.name === "of" && index === 1 && parentNode.body[0].type === "NGMicrosyntaxLet" && parentNode.body[0].value === null;
  24552. }
  24553. /** @param node {import("estree").TemplateLiteral} */
  24554. function isSimpleTemplateLiteral(node) {
  24555. if (node.expressions.length === 0) {
  24556. return false;
  24557. }
  24558. return node.expressions.every(function (expr) {
  24559. // Disallow comments since printDocToString can't print them here
  24560. if (expr.comments) {
  24561. return false;
  24562. } // Allow `x` and `this`
  24563. if (expr.type === "Identifier" || expr.type === "ThisExpression") {
  24564. return true;
  24565. } // Allow `a.b.c`, `a.b[c]`, and `this.x.y`
  24566. if (expr.type === "MemberExpression" || expr.type === "OptionalMemberExpression") {
  24567. var head = expr;
  24568. while (head.type === "MemberExpression" || head.type === "OptionalMemberExpression") {
  24569. if (head.property.type !== "Identifier" && head.property.type !== "Literal" && head.property.type !== "StringLiteral" && head.property.type !== "NumericLiteral") {
  24570. return false;
  24571. }
  24572. head = head.object;
  24573. if (head.comments) {
  24574. return false;
  24575. }
  24576. }
  24577. if (head.type === "Identifier" || head.type === "ThisExpression") {
  24578. return true;
  24579. }
  24580. return false;
  24581. }
  24582. return false;
  24583. });
  24584. }
  24585. function getFlowVariance(path) {
  24586. if (!path.variance) {
  24587. return null;
  24588. } // Babel 7.0 currently uses variance node type, and flow should
  24589. // follow suit soon:
  24590. // https://github.com/babel/babel/issues/4722
  24591. var variance = path.variance.kind || path.variance;
  24592. switch (variance) {
  24593. case "plus":
  24594. return "+";
  24595. case "minus":
  24596. return "-";
  24597. default:
  24598. /* istanbul ignore next */
  24599. return variance;
  24600. }
  24601. }
  24602. function classPropMayCauseASIProblems(path) {
  24603. var node = path.getNode();
  24604. if (node.type !== "ClassProperty") {
  24605. return false;
  24606. }
  24607. var name = node.key && node.key.name; // this isn't actually possible yet with most parsers available today
  24608. // so isn't properly tested yet.
  24609. if ((name === "static" || name === "get" || name === "set") && !node.value && !node.typeAnnotation) {
  24610. return true;
  24611. }
  24612. }
  24613. function classChildNeedsASIProtection(node) {
  24614. if (!node) {
  24615. return;
  24616. }
  24617. if (node.static || node.accessibility // TypeScript
  24618. ) {
  24619. return false;
  24620. }
  24621. if (!node.computed) {
  24622. var name = node.key && node.key.name;
  24623. if (name === "in" || name === "instanceof") {
  24624. return true;
  24625. }
  24626. }
  24627. switch (node.type) {
  24628. case "ClassProperty":
  24629. case "TSAbstractClassProperty":
  24630. return node.computed;
  24631. case "MethodDefinition": // Flow
  24632. case "TSAbstractMethodDefinition": // TypeScript
  24633. case "ClassMethod":
  24634. case "ClassPrivateMethod":
  24635. {
  24636. // Babel
  24637. var isAsync = node.value ? node.value.async : node.async;
  24638. var isGenerator = node.value ? node.value.generator : node.generator;
  24639. if (isAsync || node.kind === "get" || node.kind === "set") {
  24640. return false;
  24641. }
  24642. if (node.computed || isGenerator) {
  24643. return true;
  24644. }
  24645. return false;
  24646. }
  24647. case "TSIndexSignature":
  24648. return true;
  24649. default:
  24650. /* istanbul ignore next */
  24651. return false;
  24652. }
  24653. }
  24654. function getTypeScriptMappedTypeModifier(tokenNode, keyword) {
  24655. if (tokenNode === "+") {
  24656. return "+" + keyword;
  24657. } else if (tokenNode === "-") {
  24658. return "-" + keyword;
  24659. }
  24660. return keyword;
  24661. }
  24662. function hasNewlineBetweenOrAfterDecorators(node, options) {
  24663. return hasNewlineInRange$1(options.originalText, options.locStart(node.decorators[0]), options.locEnd(getLast$1(node.decorators))) || hasNewline$2(options.originalText, options.locEnd(getLast$1(node.decorators)));
  24664. } // Only space, newline, carriage return, and tab are treated as whitespace
  24665. // inside JSX.
  24666. var jsxWhitespaceChars = " \n\r\t";
  24667. var matchJsxWhitespaceRegex = new RegExp("([" + jsxWhitespaceChars + "]+)");
  24668. var containsNonJsxWhitespaceRegex = new RegExp("[^" + jsxWhitespaceChars + "]"); // Meaningful if it contains non-whitespace characters,
  24669. // or it contains whitespace without a new line.
  24670. function isMeaningfulJSXText(node) {
  24671. return isLiteral(node) && (containsNonJsxWhitespaceRegex.test(rawText(node)) || !/\n/.test(rawText(node)));
  24672. }
  24673. function hasJsxIgnoreComment(path) {
  24674. var node = path.getValue();
  24675. var parent = path.getParentNode();
  24676. if (!parent || !node || !isJSXNode(node) || !isJSXNode(parent)) {
  24677. return false;
  24678. } // Lookup the previous sibling, ignoring any empty JSXText elements
  24679. var index = parent.children.indexOf(node);
  24680. var prevSibling = null;
  24681. for (var i = index; i > 0; i--) {
  24682. var candidate = parent.children[i - 1];
  24683. if (candidate.type === "JSXText" && !isMeaningfulJSXText(candidate)) {
  24684. continue;
  24685. }
  24686. prevSibling = candidate;
  24687. break;
  24688. }
  24689. return prevSibling && prevSibling.type === "JSXExpressionContainer" && prevSibling.expression.type === "JSXEmptyExpression" && prevSibling.expression.comments && prevSibling.expression.comments.find(function (comment) {
  24690. return comment.value.trim() === "prettier-ignore";
  24691. });
  24692. }
  24693. function isEmptyJSXElement(node) {
  24694. if (node.children.length === 0) {
  24695. return true;
  24696. }
  24697. if (node.children.length > 1) {
  24698. return false;
  24699. } // if there is one text child and does not contain any meaningful text
  24700. // we can treat the element as empty.
  24701. var child = node.children[0];
  24702. return isLiteral(child) && !isMeaningfulJSXText(child);
  24703. }
  24704. function hasPrettierIgnore(path) {
  24705. return hasIgnoreComment$1(path) || hasJsxIgnoreComment(path);
  24706. }
  24707. function isLastStatement(path) {
  24708. var parent = path.getParentNode();
  24709. if (!parent) {
  24710. return true;
  24711. }
  24712. var node = path.getValue();
  24713. var body = (parent.body || parent.consequent).filter(function (stmt) {
  24714. return stmt.type !== "EmptyStatement";
  24715. });
  24716. return body && body[body.length - 1] === node;
  24717. }
  24718. function isFlowAnnotationComment(text, typeAnnotation, options) {
  24719. var start = options.locStart(typeAnnotation);
  24720. var end = skipWhitespace$1(text, options.locEnd(typeAnnotation));
  24721. return text.substr(start, 2) === "/*" && text.substr(end, 2) === "*/";
  24722. }
  24723. function hasLeadingOwnLineComment(text, node, options) {
  24724. if (isJSXNode(node)) {
  24725. return hasNodeIgnoreComment$1(node);
  24726. }
  24727. var res = node.comments && node.comments.some(function (comment) {
  24728. return comment.leading && hasNewline$2(text, options.locEnd(comment));
  24729. });
  24730. return res;
  24731. } // This recurses the return argument, looking for the first token
  24732. // (the leftmost leaf node) and, if it (or its parents) has any
  24733. // leadingComments, returns true (so it can be wrapped in parens).
  24734. function returnArgumentHasLeadingComment(options, argument) {
  24735. if (hasLeadingOwnLineComment(options.originalText, argument, options)) {
  24736. return true;
  24737. }
  24738. if (hasNakedLeftSide(argument)) {
  24739. var leftMost = argument;
  24740. var newLeftMost;
  24741. while (newLeftMost = getLeftSide(leftMost)) {
  24742. leftMost = newLeftMost;
  24743. if (hasLeadingOwnLineComment(options.originalText, leftMost, options)) {
  24744. return true;
  24745. }
  24746. }
  24747. }
  24748. return false;
  24749. }
  24750. function isStringPropSafeToCoerceToIdentifier(node, options) {
  24751. return isStringLiteral(node.key) && isIdentifierName(node.key.value) && options.parser !== "json" && !(options.parser === "typescript" && node.type === "ClassProperty");
  24752. }
  24753. function isJestEachTemplateLiteral(node, parentNode) {
  24754. /**
  24755. * describe.each`table`(name, fn)
  24756. * describe.only.each`table`(name, fn)
  24757. * describe.skip.each`table`(name, fn)
  24758. * test.each`table`(name, fn)
  24759. * test.only.each`table`(name, fn)
  24760. * test.skip.each`table`(name, fn)
  24761. *
  24762. * Ref: https://github.com/facebook/jest/pull/6102
  24763. */
  24764. var jestEachTriggerRegex = /^[xf]?(describe|it|test)$/;
  24765. 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));
  24766. }
  24767. function templateLiteralHasNewLines(template) {
  24768. return template.quasis.some(function (quasi) {
  24769. return quasi.value.raw.includes("\n");
  24770. });
  24771. }
  24772. function isTemplateOnItsOwnLine(n, text, options) {
  24773. return (n.type === "TemplateLiteral" && templateLiteralHasNewLines(n) || n.type === "TaggedTemplateExpression" && templateLiteralHasNewLines(n.quasi)) && !hasNewline$2(text, options.locStart(n), {
  24774. backwards: true
  24775. });
  24776. }
  24777. function needsHardlineAfterDanglingComment(node) {
  24778. if (!node.comments) {
  24779. return false;
  24780. }
  24781. var lastDanglingComment = getLast$1(node.comments.filter(function (comment) {
  24782. return !comment.leading && !comment.trailing;
  24783. }));
  24784. return lastDanglingComment && !comments$1.isBlockComment(lastDanglingComment);
  24785. } // If we have nested conditional expressions, we want to print them in JSX mode
  24786. // if there's at least one JSXElement somewhere in the tree.
  24787. //
  24788. // A conditional expression chain like this should be printed in normal mode,
  24789. // because there aren't JSXElements anywhere in it:
  24790. //
  24791. // isA ? "A" : isB ? "B" : isC ? "C" : "Unknown";
  24792. //
  24793. // But a conditional expression chain like this should be printed in JSX mode,
  24794. // because there is a JSXElement in the last ConditionalExpression:
  24795. //
  24796. // isA ? "A" : isB ? "B" : isC ? "C" : <span className="warning">Unknown</span>;
  24797. //
  24798. // This type of ConditionalExpression chain is structured like this in the AST:
  24799. //
  24800. // ConditionalExpression {
  24801. // test: ...,
  24802. // consequent: ...,
  24803. // alternate: ConditionalExpression {
  24804. // test: ...,
  24805. // consequent: ...,
  24806. // alternate: ConditionalExpression {
  24807. // test: ...,
  24808. // consequent: ...,
  24809. // alternate: ...,
  24810. // }
  24811. // }
  24812. // }
  24813. //
  24814. // We want to traverse over that shape and convert it into a flat structure so
  24815. // that we can find if there's a JSXElement somewhere inside.
  24816. function getConditionalChainContents(node) {
  24817. // Given this code:
  24818. //
  24819. // // Using a ConditionalExpression as the consequent is uncommon, but should
  24820. // // be handled.
  24821. // A ? B : C ? D : E ? F ? G : H : I
  24822. //
  24823. // which has this AST:
  24824. //
  24825. // ConditionalExpression {
  24826. // test: Identifier(A),
  24827. // consequent: Identifier(B),
  24828. // alternate: ConditionalExpression {
  24829. // test: Identifier(C),
  24830. // consequent: Identifier(D),
  24831. // alternate: ConditionalExpression {
  24832. // test: Identifier(E),
  24833. // consequent: ConditionalExpression {
  24834. // test: Identifier(F),
  24835. // consequent: Identifier(G),
  24836. // alternate: Identifier(H),
  24837. // },
  24838. // alternate: Identifier(I),
  24839. // }
  24840. // }
  24841. // }
  24842. //
  24843. // we should return this Array:
  24844. //
  24845. // [
  24846. // Identifier(A),
  24847. // Identifier(B),
  24848. // Identifier(C),
  24849. // Identifier(D),
  24850. // Identifier(E),
  24851. // Identifier(F),
  24852. // Identifier(G),
  24853. // Identifier(H),
  24854. // Identifier(I)
  24855. // ];
  24856. //
  24857. // This loses the information about whether each node was the test,
  24858. // consequent, or alternate, but we don't care about that here- we are only
  24859. // flattening this structure to find if there's any JSXElements inside.
  24860. var nonConditionalExpressions = [];
  24861. function recurse(node) {
  24862. if (node.type === "ConditionalExpression") {
  24863. recurse(node.test);
  24864. recurse(node.consequent);
  24865. recurse(node.alternate);
  24866. } else {
  24867. nonConditionalExpressions.push(node);
  24868. }
  24869. }
  24870. recurse(node);
  24871. return nonConditionalExpressions;
  24872. }
  24873. function conditionalExpressionChainContainsJSX(node) {
  24874. return Boolean(getConditionalChainContents(node).find(isJSXNode));
  24875. } // Logic to check for args with multiple anonymous functions. For instance,
  24876. // the following call should be split on multiple lines for readability:
  24877. // source.pipe(map((x) => x + x), filter((x) => x % 2 === 0))
  24878. function isFunctionCompositionArgs(args) {
  24879. if (args.length <= 1) {
  24880. return false;
  24881. }
  24882. var count = 0;
  24883. var _iteratorNormalCompletion = true;
  24884. var _didIteratorError = false;
  24885. var _iteratorError = undefined;
  24886. try {
  24887. for (var _iterator = args[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  24888. var arg = _step.value;
  24889. if (isFunctionOrArrowExpression(arg)) {
  24890. count += 1;
  24891. if (count > 1) {
  24892. return true;
  24893. }
  24894. } else if (isCallOrOptionalCallExpression(arg)) {
  24895. var _iteratorNormalCompletion2 = true;
  24896. var _didIteratorError2 = false;
  24897. var _iteratorError2 = undefined;
  24898. try {
  24899. for (var _iterator2 = arg.arguments[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  24900. var childArg = _step2.value;
  24901. if (isFunctionOrArrowExpression(childArg)) {
  24902. return true;
  24903. }
  24904. }
  24905. } catch (err) {
  24906. _didIteratorError2 = true;
  24907. _iteratorError2 = err;
  24908. } finally {
  24909. try {
  24910. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  24911. _iterator2.return();
  24912. }
  24913. } finally {
  24914. if (_didIteratorError2) {
  24915. throw _iteratorError2;
  24916. }
  24917. }
  24918. }
  24919. }
  24920. }
  24921. } catch (err) {
  24922. _didIteratorError = true;
  24923. _iteratorError = err;
  24924. } finally {
  24925. try {
  24926. if (!_iteratorNormalCompletion && _iterator.return != null) {
  24927. _iterator.return();
  24928. }
  24929. } finally {
  24930. if (_didIteratorError) {
  24931. throw _iteratorError;
  24932. }
  24933. }
  24934. }
  24935. return false;
  24936. } // Logic to determine if a call is a “long curried function call”.
  24937. // See https://github.com/prettier/prettier/issues/1420.
  24938. //
  24939. // `connect(a, b, c)(d)`
  24940. // In the above call expression, the second call is the parent node and the
  24941. // first call is the current node.
  24942. function isLongCurriedCallExpression(path) {
  24943. var node = path.getValue();
  24944. var parent = path.getParentNode();
  24945. return isCallOrOptionalCallExpression(node) && isCallOrOptionalCallExpression(parent) && parent.callee === node && node.arguments.length > parent.arguments.length && parent.arguments.length > 0;
  24946. }
  24947. function rawText(node) {
  24948. return node.extra ? node.extra.raw : node.raw;
  24949. }
  24950. function identity(x) {
  24951. return x;
  24952. }
  24953. function isTSXFile(options) {
  24954. return options.filepath && /\.tsx$/i.test(options.filepath);
  24955. }
  24956. var utils$2 = {
  24957. classChildNeedsASIProtection,
  24958. classPropMayCauseASIProblems,
  24959. conditionalExpressionChainContainsJSX,
  24960. getFlowVariance,
  24961. getLeftSidePathName,
  24962. getTypeScriptMappedTypeModifier,
  24963. hasDanglingComments,
  24964. hasFlowAnnotationComment,
  24965. hasFlowShorthandAnnotationComment,
  24966. hasLeadingComment: hasLeadingComment$2,
  24967. hasLeadingOwnLineComment,
  24968. hasNakedLeftSide,
  24969. hasNewlineBetweenOrAfterDecorators,
  24970. hasNgSideEffect,
  24971. hasNode,
  24972. hasPrettierIgnore,
  24973. hasTrailingComment,
  24974. identity,
  24975. isBinaryish,
  24976. isCallOrOptionalCallExpression,
  24977. isEmptyJSXElement,
  24978. isFlowAnnotationComment,
  24979. isFunctionCompositionArgs,
  24980. isFunctionNotation,
  24981. isFunctionOrArrowExpression,
  24982. isGetterOrSetter,
  24983. isJestEachTemplateLiteral,
  24984. isJSXNode,
  24985. isJSXWhitespaceExpression,
  24986. isLastStatement,
  24987. isLiteral,
  24988. isLongCurriedCallExpression,
  24989. isMeaningfulJSXText,
  24990. isMemberExpressionChain,
  24991. isMemberish,
  24992. isNgForOf,
  24993. isNumericLiteral,
  24994. isObjectType,
  24995. isObjectTypePropertyAFunction,
  24996. isSimpleFlowType,
  24997. isSimpleTemplateLiteral,
  24998. isStringLiteral,
  24999. isStringPropSafeToCoerceToIdentifier,
  25000. isTemplateOnItsOwnLine,
  25001. isTestCall,
  25002. isTheOnlyJSXElementInMarkdown,
  25003. isTSXFile,
  25004. isTypeAnnotationAFunction,
  25005. matchJsxWhitespaceRegex,
  25006. needsHardlineAfterDanglingComment,
  25007. rawText,
  25008. returnArgumentHasLeadingComment
  25009. };
  25010. var getLeftSidePathName$1 = utils$2.getLeftSidePathName,
  25011. hasFlowShorthandAnnotationComment$1 = utils$2.hasFlowShorthandAnnotationComment,
  25012. hasNakedLeftSide$1 = utils$2.hasNakedLeftSide,
  25013. hasNode$1 = utils$2.hasNode;
  25014. function hasClosureCompilerTypeCastComment(text, path) {
  25015. // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
  25016. // Syntax example: var x = /** @type {string} */ (fruit);
  25017. var n = path.getValue();
  25018. return isParenthesized(n) && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
  25019. function hasAncestorTypeCastComment(index) {
  25020. var ancestor = path.getParentNode(index);
  25021. return ancestor && !isParenthesized(ancestor) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
  25022. }
  25023. function hasTypeCastComment(node) {
  25024. return node.comments && node.comments.some(function (comment) {
  25025. return comment.leading && comments$1.isBlockComment(comment) && isTypeCastComment(comment.value);
  25026. });
  25027. }
  25028. function isParenthesized(node) {
  25029. // Closure typecast comments only really make sense when _not_ using
  25030. // typescript or flow parsers, so we take advantage of the babel parser's
  25031. // parenthesized expressions.
  25032. return node.extra && node.extra.parenthesized;
  25033. }
  25034. function isTypeCastComment(comment) {
  25035. var cleaned = comment.trim().split("\n").map(function (line) {
  25036. return line.replace(/^[\s*]+/, "");
  25037. }).join(" ").trim();
  25038. if (!/^@type\s*\{[^]+\}$/.test(cleaned)) {
  25039. return false;
  25040. }
  25041. var isCompletelyClosed = false;
  25042. var unpairedBracketCount = 0;
  25043. var _iteratorNormalCompletion = true;
  25044. var _didIteratorError = false;
  25045. var _iteratorError = undefined;
  25046. try {
  25047. for (var _iterator = cleaned[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  25048. var char = _step.value;
  25049. if (char === "{") {
  25050. if (isCompletelyClosed) {
  25051. return false;
  25052. }
  25053. unpairedBracketCount++;
  25054. } else if (char === "}") {
  25055. if (unpairedBracketCount === 0) {
  25056. return false;
  25057. }
  25058. unpairedBracketCount--;
  25059. if (unpairedBracketCount === 0) {
  25060. isCompletelyClosed = true;
  25061. }
  25062. }
  25063. }
  25064. } catch (err) {
  25065. _didIteratorError = true;
  25066. _iteratorError = err;
  25067. } finally {
  25068. try {
  25069. if (!_iteratorNormalCompletion && _iterator.return != null) {
  25070. _iterator.return();
  25071. }
  25072. } finally {
  25073. if (_didIteratorError) {
  25074. throw _iteratorError;
  25075. }
  25076. }
  25077. }
  25078. return unpairedBracketCount === 0;
  25079. }
  25080. }
  25081. function needsParens(path, options) {
  25082. var parent = path.getParentNode();
  25083. if (!parent) {
  25084. return false;
  25085. }
  25086. var name = path.getName();
  25087. var node = path.getNode(); // If the value of this path is some child of a Node and not a Node
  25088. // itself, then it doesn't need parentheses. Only Node objects (in
  25089. // fact, only Expression nodes) need parentheses.
  25090. if (path.getValue() !== node) {
  25091. return false;
  25092. } // to avoid unexpected `}}` in HTML interpolations
  25093. if (options.__isInHtmlInterpolation && !options.bracketSpacing && endsWithRightBracket(node) && isFollowedByRightBracket(path)) {
  25094. return true;
  25095. } // Only statements don't need parentheses.
  25096. if (isStatement(node)) {
  25097. return false;
  25098. } // Closure compiler requires that type casted expressions to be surrounded by
  25099. // parentheses.
  25100. if (hasClosureCompilerTypeCastComment(options.originalText, path)) {
  25101. return true;
  25102. }
  25103. if ( // Preserve parens if we have a Flow annotation comment, unless we're using the Flow
  25104. // parser. The Flow parser turns Flow comments into type annotation nodes in its
  25105. // AST, which we handle separately.
  25106. options.parser !== "flow" && hasFlowShorthandAnnotationComment$1(path.getValue())) {
  25107. return true;
  25108. } // Identifiers never need parentheses.
  25109. if (node.type === "Identifier") {
  25110. // ...unless those identifiers are embed placeholders. They might be substituted by complex
  25111. // expressions, so the parens around them should not be dropped. Example (JS-in-HTML-in-JS):
  25112. // let tpl = html`<script> f((${expr}) / 2); </script>`;
  25113. // If the inner JS formatter removes the parens, the expression might change its meaning:
  25114. // f((a + b) / 2) vs f(a + b / 2)
  25115. if (node.extra && node.extra.parenthesized && /^PRETTIER_HTML_PLACEHOLDER_\d+_\d+_IN_JS$/.test(node.name)) {
  25116. return true;
  25117. }
  25118. return false;
  25119. }
  25120. if (parent.type === "ParenthesizedExpression") {
  25121. return false;
  25122. } // Add parens around the extends clause of a class. It is needed for almost
  25123. // all expressions.
  25124. 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")) {
  25125. return true;
  25126. } // `export default function` or `export default class` can't be followed by
  25127. // anything after. So an expression like `export default (function(){}).toString()`
  25128. // needs to be followed by a parentheses
  25129. if (parent.type === "ExportDefaultDeclaration") {
  25130. return shouldWrapFunctionForExportDefault(path, options);
  25131. }
  25132. if (parent.type === "Decorator" && parent.expression === node) {
  25133. var hasCallExpression = false;
  25134. var hasMemberExpression = false;
  25135. var current = node;
  25136. while (current) {
  25137. switch (current.type) {
  25138. case "MemberExpression":
  25139. hasMemberExpression = true;
  25140. current = current.object;
  25141. break;
  25142. case "CallExpression":
  25143. if (
  25144. /** @(x().y) */
  25145. hasMemberExpression ||
  25146. /** @(x().y()) */
  25147. hasCallExpression) {
  25148. return true;
  25149. }
  25150. hasCallExpression = true;
  25151. current = current.callee;
  25152. break;
  25153. case "Identifier":
  25154. return false;
  25155. default:
  25156. return true;
  25157. }
  25158. }
  25159. return true;
  25160. }
  25161. if (parent.type === "ArrowFunctionExpression" && parent.body === node && node.type !== "SequenceExpression" && // these have parens added anyway
  25162. util.startsWithNoLookaheadToken(node,
  25163. /* forbidFunctionClassAndDoExpr */
  25164. false) || parent.type === "ExpressionStatement" && util.startsWithNoLookaheadToken(node,
  25165. /* forbidFunctionClassAndDoExpr */
  25166. true)) {
  25167. return true;
  25168. }
  25169. switch (node.type) {
  25170. case "SpreadElement":
  25171. case "SpreadProperty":
  25172. return parent.type === "MemberExpression" && name === "object" && parent.object === node;
  25173. case "UpdateExpression":
  25174. if (parent.type === "UnaryExpression") {
  25175. return node.prefix && (node.operator === "++" && parent.operator === "+" || node.operator === "--" && parent.operator === "-");
  25176. }
  25177. // else fallthrough
  25178. case "UnaryExpression":
  25179. switch (parent.type) {
  25180. case "UnaryExpression":
  25181. return node.operator === parent.operator && (node.operator === "+" || node.operator === "-");
  25182. case "BindExpression":
  25183. return true;
  25184. case "MemberExpression":
  25185. case "OptionalMemberExpression":
  25186. return name === "object";
  25187. case "TaggedTemplateExpression":
  25188. return true;
  25189. case "NewExpression":
  25190. case "CallExpression":
  25191. case "OptionalCallExpression":
  25192. return name === "callee";
  25193. case "BinaryExpression":
  25194. return parent.operator === "**" && name === "left";
  25195. case "TSNonNullExpression":
  25196. return true;
  25197. default:
  25198. return false;
  25199. }
  25200. case "BinaryExpression":
  25201. {
  25202. if (parent.type === "UpdateExpression") {
  25203. return true;
  25204. }
  25205. var isLeftOfAForStatement = function isLeftOfAForStatement(node) {
  25206. var i = 0;
  25207. while (node) {
  25208. var _parent = path.getParentNode(i++);
  25209. if (!_parent) {
  25210. return false;
  25211. }
  25212. if (_parent.type === "ForStatement" && _parent.init === node) {
  25213. return true;
  25214. }
  25215. node = _parent;
  25216. }
  25217. return false;
  25218. };
  25219. if (node.operator === "in" && isLeftOfAForStatement(node)) {
  25220. return true;
  25221. }
  25222. }
  25223. // fallthrough
  25224. case "TSTypeAssertion":
  25225. case "TSAsExpression":
  25226. case "LogicalExpression":
  25227. switch (parent.type) {
  25228. case "ConditionalExpression":
  25229. return node.type === "TSAsExpression";
  25230. case "CallExpression":
  25231. case "NewExpression":
  25232. case "OptionalCallExpression":
  25233. return name === "callee";
  25234. case "ClassExpression":
  25235. case "ClassDeclaration":
  25236. return name === "superClass" && parent.superClass === node;
  25237. case "TSTypeAssertion":
  25238. case "TaggedTemplateExpression":
  25239. case "UnaryExpression":
  25240. case "JSXSpreadAttribute":
  25241. case "SpreadElement":
  25242. case "SpreadProperty":
  25243. case "BindExpression":
  25244. case "AwaitExpression":
  25245. case "TSAsExpression":
  25246. case "TSNonNullExpression":
  25247. case "UpdateExpression":
  25248. return true;
  25249. case "MemberExpression":
  25250. case "OptionalMemberExpression":
  25251. return name === "object";
  25252. case "AssignmentExpression":
  25253. return parent.left === node && (node.type === "TSTypeAssertion" || node.type === "TSAsExpression");
  25254. case "LogicalExpression":
  25255. if (node.type === "LogicalExpression") {
  25256. return parent.operator !== node.operator;
  25257. }
  25258. // else fallthrough
  25259. case "BinaryExpression":
  25260. {
  25261. if (!node.operator && node.type !== "TSTypeAssertion") {
  25262. return true;
  25263. }
  25264. var po = parent.operator;
  25265. var pp = util.getPrecedence(po);
  25266. var no = node.operator;
  25267. var np = util.getPrecedence(no);
  25268. if (pp > np) {
  25269. return true;
  25270. }
  25271. if (pp === np && name === "right") {
  25272. assert$1.strictEqual(parent.right, node);
  25273. return true;
  25274. }
  25275. if (pp === np && !util.shouldFlatten(po, no)) {
  25276. return true;
  25277. }
  25278. if (pp < np && no === "%") {
  25279. return po === "+" || po === "-";
  25280. } // Add parenthesis when working with bitwise operators
  25281. // It's not strictly needed but helps with code understanding
  25282. if (util.isBitwiseOperator(po)) {
  25283. return true;
  25284. }
  25285. return false;
  25286. }
  25287. default:
  25288. return false;
  25289. }
  25290. case "SequenceExpression":
  25291. switch (parent.type) {
  25292. case "ReturnStatement":
  25293. return false;
  25294. case "ForStatement":
  25295. // Although parentheses wouldn't hurt around sequence
  25296. // expressions in the head of for loops, traditional style
  25297. // dictates that e.g. i++, j++ should not be wrapped with
  25298. // parentheses.
  25299. return false;
  25300. case "ExpressionStatement":
  25301. return name !== "expression";
  25302. case "ArrowFunctionExpression":
  25303. // We do need parentheses, but SequenceExpressions are handled
  25304. // specially when printing bodies of arrow functions.
  25305. return name !== "body";
  25306. default:
  25307. // Otherwise err on the side of overparenthesization, adding
  25308. // explicit exceptions above if this proves overzealous.
  25309. return true;
  25310. }
  25311. case "YieldExpression":
  25312. if (parent.type === "UnaryExpression" || parent.type === "AwaitExpression" || parent.type === "TSAsExpression" || parent.type === "TSNonNullExpression") {
  25313. return true;
  25314. }
  25315. // else fallthrough
  25316. case "AwaitExpression":
  25317. switch (parent.type) {
  25318. case "TaggedTemplateExpression":
  25319. case "UnaryExpression":
  25320. case "BinaryExpression":
  25321. case "LogicalExpression":
  25322. case "SpreadElement":
  25323. case "SpreadProperty":
  25324. case "TSAsExpression":
  25325. case "TSNonNullExpression":
  25326. case "BindExpression":
  25327. return true;
  25328. case "MemberExpression":
  25329. case "OptionalMemberExpression":
  25330. return name === "object";
  25331. case "NewExpression":
  25332. case "CallExpression":
  25333. case "OptionalCallExpression":
  25334. return name === "callee";
  25335. case "ConditionalExpression":
  25336. return parent.test === node;
  25337. default:
  25338. return false;
  25339. }
  25340. case "TSConditionalType":
  25341. if (parent.type === "TSConditionalType" && node === parent.extendsType) {
  25342. return true;
  25343. }
  25344. // fallthrough
  25345. case "TSFunctionType":
  25346. case "TSConstructorType":
  25347. if (parent.type === "TSConditionalType" && node === parent.checkType) {
  25348. return true;
  25349. }
  25350. // fallthrough
  25351. case "TSUnionType":
  25352. case "TSIntersectionType":
  25353. if (parent.type === "TSUnionType" || parent.type === "TSIntersectionType") {
  25354. return true;
  25355. }
  25356. // fallthrough
  25357. case "TSTypeOperator":
  25358. case "TSInferType":
  25359. return parent.type === "TSArrayType" || parent.type === "TSOptionalType" || parent.type === "TSRestType" || parent.type === "TSIndexedAccessType" && node === parent.objectType || parent.type === "TSTypeOperator";
  25360. case "ArrayTypeAnnotation":
  25361. return parent.type === "NullableTypeAnnotation";
  25362. case "IntersectionTypeAnnotation":
  25363. case "UnionTypeAnnotation":
  25364. return parent.type === "ArrayTypeAnnotation" || parent.type === "NullableTypeAnnotation" || parent.type === "IntersectionTypeAnnotation" || parent.type === "UnionTypeAnnotation";
  25365. case "NullableTypeAnnotation":
  25366. return parent.type === "ArrayTypeAnnotation";
  25367. case "FunctionTypeAnnotation":
  25368. {
  25369. var ancestor = parent.type === "NullableTypeAnnotation" ? path.getParentNode(1) : parent;
  25370. return ancestor.type === "UnionTypeAnnotation" || ancestor.type === "IntersectionTypeAnnotation" || ancestor.type === "ArrayTypeAnnotation" || // We should check ancestor's parent to know whether the parentheses
  25371. // are really needed, but since ??T doesn't make sense this check
  25372. // will almost never be true.
  25373. ancestor.type === "NullableTypeAnnotation";
  25374. }
  25375. case "StringLiteral":
  25376. case "NumericLiteral":
  25377. case "Literal":
  25378. if (typeof node.value === "string" && parent.type === "ExpressionStatement" && ( // TypeScript workaround for https://github.com/JamesHenry/typescript-estree/issues/2
  25379. // See corresponding workaround in printer.js case: "Literal"
  25380. options.parser !== "typescript" && !parent.directive || options.parser === "typescript" && options.originalText.substr(options.locStart(node) - 1, 1) === "(")) {
  25381. // To avoid becoming a directive
  25382. var grandParent = path.getParentNode(1);
  25383. return grandParent.type === "Program" || grandParent.type === "BlockStatement";
  25384. }
  25385. return parent.type === "MemberExpression" && typeof node.value === "number" && name === "object" && parent.object === node;
  25386. case "AssignmentExpression":
  25387. {
  25388. var _grandParent = path.getParentNode(1);
  25389. if (parent.type === "ArrowFunctionExpression" && parent.body === node) {
  25390. return true;
  25391. } else if (parent.type === "ClassProperty" && parent.key === node && parent.computed) {
  25392. return false;
  25393. } else if (parent.type === "TSPropertySignature" && parent.name === node) {
  25394. return false;
  25395. } else if (parent.type === "ForStatement" && (parent.init === node || parent.update === node)) {
  25396. return false;
  25397. } else if (parent.type === "ExpressionStatement") {
  25398. return node.left.type === "ObjectPattern";
  25399. } else if (parent.type === "TSPropertySignature" && parent.key === node) {
  25400. return false;
  25401. } else if (parent.type === "AssignmentExpression") {
  25402. return false;
  25403. } else if (parent.type === "SequenceExpression" && _grandParent && _grandParent.type === "ForStatement" && (_grandParent.init === parent || _grandParent.update === parent)) {
  25404. return false;
  25405. } else if (parent.type === "Property" && parent.value === node) {
  25406. return false;
  25407. } else if (parent.type === "NGChainedExpression") {
  25408. return false;
  25409. }
  25410. return true;
  25411. }
  25412. case "ConditionalExpression":
  25413. switch (parent.type) {
  25414. case "TaggedTemplateExpression":
  25415. case "UnaryExpression":
  25416. case "SpreadElement":
  25417. case "SpreadProperty":
  25418. case "BinaryExpression":
  25419. case "LogicalExpression":
  25420. case "NGPipeExpression":
  25421. case "ExportDefaultDeclaration":
  25422. case "AwaitExpression":
  25423. case "JSXSpreadAttribute":
  25424. case "TSTypeAssertion":
  25425. case "TypeCastExpression":
  25426. case "TSAsExpression":
  25427. case "TSNonNullExpression":
  25428. return true;
  25429. case "NewExpression":
  25430. case "CallExpression":
  25431. case "OptionalCallExpression":
  25432. return name === "callee";
  25433. case "ConditionalExpression":
  25434. return name === "test" && parent.test === node;
  25435. case "MemberExpression":
  25436. case "OptionalMemberExpression":
  25437. return name === "object";
  25438. default:
  25439. return false;
  25440. }
  25441. case "FunctionExpression":
  25442. switch (parent.type) {
  25443. case "NewExpression":
  25444. case "CallExpression":
  25445. case "OptionalCallExpression":
  25446. // Not always necessary, but it's clearer to the reader if IIFEs are wrapped in parentheses.
  25447. // Is necessary if it is `expression` of `ExpressionStatement`.
  25448. return name === "callee";
  25449. case "TaggedTemplateExpression":
  25450. return true;
  25451. // This is basically a kind of IIFE.
  25452. default:
  25453. return false;
  25454. }
  25455. case "ArrowFunctionExpression":
  25456. switch (parent.type) {
  25457. case "NewExpression":
  25458. case "CallExpression":
  25459. case "OptionalCallExpression":
  25460. return name === "callee";
  25461. case "MemberExpression":
  25462. case "OptionalMemberExpression":
  25463. return name === "object";
  25464. case "TSAsExpression":
  25465. case "BindExpression":
  25466. case "TaggedTemplateExpression":
  25467. case "UnaryExpression":
  25468. case "LogicalExpression":
  25469. case "BinaryExpression":
  25470. case "AwaitExpression":
  25471. case "TSTypeAssertion":
  25472. return true;
  25473. case "ConditionalExpression":
  25474. return name === "test";
  25475. default:
  25476. return false;
  25477. }
  25478. case "ClassExpression":
  25479. switch (parent.type) {
  25480. case "NewExpression":
  25481. return name === "callee" && parent.callee === node;
  25482. default:
  25483. return false;
  25484. }
  25485. case "OptionalMemberExpression":
  25486. case "OptionalCallExpression":
  25487. if ((parent.type === "MemberExpression" && name === "object" || parent.type === "CallExpression" && name === "callee") && // workaround for https://github.com/facebook/flow/issues/8159
  25488. !(options.parser === "flow" && parent.range[0] === node.range[0])) {
  25489. return true;
  25490. }
  25491. // fallthrough
  25492. case "CallExpression":
  25493. case "MemberExpression":
  25494. case "TaggedTemplateExpression":
  25495. case "TSNonNullExpression":
  25496. if ((parent.type === "BindExpression" || parent.type === "NewExpression") && name === "callee") {
  25497. var object = node;
  25498. while (object) {
  25499. switch (object.type) {
  25500. case "CallExpression":
  25501. case "OptionalCallExpression":
  25502. return true;
  25503. case "MemberExpression":
  25504. case "OptionalMemberExpression":
  25505. case "BindExpression":
  25506. object = object.object;
  25507. break;
  25508. // tagged templates are basically member expressions from a grammar perspective
  25509. // see https://tc39.github.io/ecma262/#prod-MemberExpression
  25510. case "TaggedTemplateExpression":
  25511. object = object.tag;
  25512. break;
  25513. case "TSNonNullExpression":
  25514. object = object.expression;
  25515. break;
  25516. default:
  25517. return false;
  25518. }
  25519. }
  25520. }
  25521. return false;
  25522. case "BindExpression":
  25523. return (parent.type === "BindExpression" || parent.type === "NewExpression") && name === "callee" || (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && name === "object";
  25524. case "NGPipeExpression":
  25525. if (parent.type === "NGRoot" || parent.type === "NGMicrosyntaxExpression" || parent.type === "ObjectProperty" || 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") {
  25526. return false;
  25527. }
  25528. return true;
  25529. case "JSXFragment":
  25530. case "JSXElement":
  25531. return name === "callee" || parent.type !== "ArrayExpression" && parent.type !== "ArrowFunctionExpression" && parent.type !== "AssignmentExpression" && parent.type !== "AssignmentPattern" && parent.type !== "BinaryExpression" && parent.type !== "CallExpression" && 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 !== "TypeCastExpression" && parent.type !== "VariableDeclarator";
  25532. case "TypeAnnotation":
  25533. return name === "returnType" && parent.type === "ArrowFunctionExpression" && includesFunctionTypeInObjectType(node);
  25534. }
  25535. return false;
  25536. }
  25537. function isStatement(node) {
  25538. 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 === "ForAwaitStatement" || 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";
  25539. }
  25540. function includesFunctionTypeInObjectType(node) {
  25541. return hasNode$1(node, function (n1) {
  25542. return n1.type === "ObjectTypeAnnotation" && hasNode$1(n1, function (n2) {
  25543. return n2.type === "FunctionTypeAnnotation" || undefined;
  25544. }) || undefined;
  25545. });
  25546. }
  25547. function endsWithRightBracket(node) {
  25548. switch (node.type) {
  25549. case "ObjectExpression":
  25550. return true;
  25551. default:
  25552. return false;
  25553. }
  25554. }
  25555. function isFollowedByRightBracket(path) {
  25556. var node = path.getValue();
  25557. var parent = path.getParentNode();
  25558. var name = path.getName();
  25559. switch (parent.type) {
  25560. case "NGPipeExpression":
  25561. if (typeof name === "number" && parent.arguments[name] === node && parent.arguments.length - 1 === name) {
  25562. return path.callParent(isFollowedByRightBracket);
  25563. }
  25564. break;
  25565. case "ObjectProperty":
  25566. if (name === "value") {
  25567. var parentParent = path.getParentNode(1);
  25568. return parentParent.properties[parentParent.properties.length - 1] === parent;
  25569. }
  25570. break;
  25571. case "BinaryExpression":
  25572. case "LogicalExpression":
  25573. if (name === "right") {
  25574. return path.callParent(isFollowedByRightBracket);
  25575. }
  25576. break;
  25577. case "ConditionalExpression":
  25578. if (name === "alternate") {
  25579. return path.callParent(isFollowedByRightBracket);
  25580. }
  25581. break;
  25582. case "UnaryExpression":
  25583. if (parent.prefix) {
  25584. return path.callParent(isFollowedByRightBracket);
  25585. }
  25586. break;
  25587. }
  25588. return false;
  25589. }
  25590. function shouldWrapFunctionForExportDefault(path, options) {
  25591. var node = path.getValue();
  25592. var parent = path.getParentNode();
  25593. if (node.type === "FunctionExpression" || node.type === "ClassExpression") {
  25594. return parent.type === "ExportDefaultDeclaration" || // in some cases the function is already wrapped
  25595. // (e.g. `export default (function() {})();`)
  25596. // in this case we don't need to add extra parens
  25597. !needsParens(path, options);
  25598. }
  25599. if (!hasNakedLeftSide$1(node) || parent.type !== "ExportDefaultDeclaration" && needsParens(path, options)) {
  25600. return false;
  25601. }
  25602. return path.call.apply(path, [function (childPath) {
  25603. return shouldWrapFunctionForExportDefault(childPath, options);
  25604. }].concat(getLeftSidePathName$1(path, node)));
  25605. }
  25606. var needsParens_1 = needsParens;
  25607. var _require$$0$builders$1 = doc.builders,
  25608. concat$5 = _require$$0$builders$1.concat,
  25609. join$3 = _require$$0$builders$1.join,
  25610. line$1 = _require$$0$builders$1.line;
  25611. function printHtmlBinding(path, options, print) {
  25612. var node = path.getValue();
  25613. if (options.__onHtmlBindingRoot && path.getName() === null) {
  25614. options.__onHtmlBindingRoot(node);
  25615. }
  25616. if (node.type !== "File") {
  25617. return;
  25618. }
  25619. if (options.__isVueForBindingLeft) {
  25620. return path.call(function (functionDeclarationPath) {
  25621. var _functionDeclarationP = functionDeclarationPath.getValue(),
  25622. params = _functionDeclarationP.params;
  25623. return concat$5([params.length > 1 ? "(" : "", join$3(concat$5([",", line$1]), functionDeclarationPath.map(print, "params")), params.length > 1 ? ")" : ""]);
  25624. }, "program", "body", 0);
  25625. }
  25626. if (options.__isVueSlotScope) {
  25627. return path.call(function (functionDeclarationPath) {
  25628. return join$3(concat$5([",", line$1]), functionDeclarationPath.map(print, "params"));
  25629. }, "program", "body", 0);
  25630. }
  25631. } // based on https://github.com/prettier/prettier/blob/master/src/language-html/syntax-vue.js isVueEventBindingExpression()
  25632. function isVueEventBindingExpression(node) {
  25633. switch (node.type) {
  25634. case "MemberExpression":
  25635. switch (node.property.type) {
  25636. case "Identifier":
  25637. case "NumericLiteral":
  25638. case "StringLiteral":
  25639. return isVueEventBindingExpression(node.object);
  25640. }
  25641. return false;
  25642. case "Identifier":
  25643. return true;
  25644. default:
  25645. return false;
  25646. }
  25647. }
  25648. var htmlBinding = {
  25649. isVueEventBindingExpression,
  25650. printHtmlBinding
  25651. };
  25652. function preprocess(ast, options) {
  25653. switch (options.parser) {
  25654. case "json":
  25655. case "json5":
  25656. case "json-stringify":
  25657. case "__js_expression":
  25658. case "__vue_expression":
  25659. return Object.assign({}, ast, {
  25660. type: options.parser.startsWith("__") ? "JsExpressionRoot" : "JsonRoot",
  25661. node: ast,
  25662. comments: []
  25663. });
  25664. default:
  25665. return ast;
  25666. }
  25667. }
  25668. var preprocess_1 = preprocess;
  25669. var getParentExportDeclaration$1 = util.getParentExportDeclaration,
  25670. isExportDeclaration$1 = util.isExportDeclaration,
  25671. shouldFlatten$1 = util.shouldFlatten,
  25672. getNextNonSpaceNonCommentCharacter$1 = util.getNextNonSpaceNonCommentCharacter,
  25673. hasNewline$3 = util.hasNewline,
  25674. hasNewlineInRange$2 = util.hasNewlineInRange,
  25675. getLast$2 = util.getLast,
  25676. getStringWidth$2 = util.getStringWidth,
  25677. printString$1 = util.printString,
  25678. printNumber$1 = util.printNumber,
  25679. hasIgnoreComment$2 = util.hasIgnoreComment,
  25680. hasNodeIgnoreComment$2 = util.hasNodeIgnoreComment,
  25681. getPenultimate$1 = util.getPenultimate,
  25682. startsWithNoLookaheadToken$1 = util.startsWithNoLookaheadToken,
  25683. getIndentSize$1 = util.getIndentSize,
  25684. matchAncestorTypes$1 = util.matchAncestorTypes,
  25685. getPreferredQuote$1 = util.getPreferredQuote;
  25686. var isNextLineEmpty$2 = utilShared.isNextLineEmpty,
  25687. isNextLineEmptyAfterIndex$1 = utilShared.isNextLineEmptyAfterIndex,
  25688. getNextNonSpaceNonCommentCharacterIndex$2 = utilShared.getNextNonSpaceNonCommentCharacterIndex;
  25689. var insertPragma$1 = pragma.insertPragma;
  25690. var printHtmlBinding$1 = htmlBinding.printHtmlBinding,
  25691. isVueEventBindingExpression$1 = htmlBinding.isVueEventBindingExpression;
  25692. var classChildNeedsASIProtection$1 = utils$2.classChildNeedsASIProtection,
  25693. classPropMayCauseASIProblems$1 = utils$2.classPropMayCauseASIProblems,
  25694. conditionalExpressionChainContainsJSX$1 = utils$2.conditionalExpressionChainContainsJSX,
  25695. getFlowVariance$1 = utils$2.getFlowVariance,
  25696. getLeftSidePathName$2 = utils$2.getLeftSidePathName,
  25697. getTypeScriptMappedTypeModifier$1 = utils$2.getTypeScriptMappedTypeModifier,
  25698. hasDanglingComments$1 = utils$2.hasDanglingComments,
  25699. hasFlowAnnotationComment$1 = utils$2.hasFlowAnnotationComment,
  25700. hasFlowShorthandAnnotationComment$2 = utils$2.hasFlowShorthandAnnotationComment,
  25701. hasLeadingComment$3 = utils$2.hasLeadingComment,
  25702. hasLeadingOwnLineComment$1 = utils$2.hasLeadingOwnLineComment,
  25703. hasNakedLeftSide$2 = utils$2.hasNakedLeftSide,
  25704. hasNewlineBetweenOrAfterDecorators$1 = utils$2.hasNewlineBetweenOrAfterDecorators,
  25705. hasNgSideEffect$1 = utils$2.hasNgSideEffect,
  25706. hasPrettierIgnore$1 = utils$2.hasPrettierIgnore,
  25707. hasTrailingComment$1 = utils$2.hasTrailingComment,
  25708. identity$1 = utils$2.identity,
  25709. isBinaryish$1 = utils$2.isBinaryish,
  25710. isCallOrOptionalCallExpression$1 = utils$2.isCallOrOptionalCallExpression,
  25711. isEmptyJSXElement$1 = utils$2.isEmptyJSXElement,
  25712. isFlowAnnotationComment$1 = utils$2.isFlowAnnotationComment,
  25713. isFunctionCompositionArgs$1 = utils$2.isFunctionCompositionArgs,
  25714. isFunctionNotation$1 = utils$2.isFunctionNotation,
  25715. isFunctionOrArrowExpression$1 = utils$2.isFunctionOrArrowExpression,
  25716. isGetterOrSetter$1 = utils$2.isGetterOrSetter,
  25717. isJestEachTemplateLiteral$1 = utils$2.isJestEachTemplateLiteral,
  25718. isJSXNode$1 = utils$2.isJSXNode,
  25719. isJSXWhitespaceExpression$1 = utils$2.isJSXWhitespaceExpression,
  25720. isLastStatement$1 = utils$2.isLastStatement,
  25721. isLiteral$1 = utils$2.isLiteral,
  25722. isLongCurriedCallExpression$1 = utils$2.isLongCurriedCallExpression,
  25723. isMeaningfulJSXText$1 = utils$2.isMeaningfulJSXText,
  25724. isMemberExpressionChain$1 = utils$2.isMemberExpressionChain,
  25725. isMemberish$1 = utils$2.isMemberish,
  25726. isNgForOf$1 = utils$2.isNgForOf,
  25727. isNumericLiteral$1 = utils$2.isNumericLiteral,
  25728. isObjectType$1 = utils$2.isObjectType,
  25729. isObjectTypePropertyAFunction$1 = utils$2.isObjectTypePropertyAFunction,
  25730. isSimpleFlowType$1 = utils$2.isSimpleFlowType,
  25731. isSimpleTemplateLiteral$1 = utils$2.isSimpleTemplateLiteral,
  25732. isStringLiteral$1 = utils$2.isStringLiteral,
  25733. isStringPropSafeToCoerceToIdentifier$1 = utils$2.isStringPropSafeToCoerceToIdentifier,
  25734. isTemplateOnItsOwnLine$1 = utils$2.isTemplateOnItsOwnLine,
  25735. isTestCall$1 = utils$2.isTestCall,
  25736. isTheOnlyJSXElementInMarkdown$1 = utils$2.isTheOnlyJSXElementInMarkdown,
  25737. isTSXFile$1 = utils$2.isTSXFile,
  25738. isTypeAnnotationAFunction$1 = utils$2.isTypeAnnotationAFunction,
  25739. matchJsxWhitespaceRegex$1 = utils$2.matchJsxWhitespaceRegex,
  25740. needsHardlineAfterDanglingComment$1 = utils$2.needsHardlineAfterDanglingComment,
  25741. rawText$1 = utils$2.rawText,
  25742. returnArgumentHasLeadingComment$1 = utils$2.returnArgumentHasLeadingComment;
  25743. var needsQuoteProps = new WeakMap();
  25744. var _require$$5$builders = doc.builders,
  25745. concat$6 = _require$$5$builders.concat,
  25746. join$4 = _require$$5$builders.join,
  25747. line$2 = _require$$5$builders.line,
  25748. hardline$4 = _require$$5$builders.hardline,
  25749. softline$2 = _require$$5$builders.softline,
  25750. literalline$2 = _require$$5$builders.literalline,
  25751. group$2 = _require$$5$builders.group,
  25752. indent$3 = _require$$5$builders.indent,
  25753. align$1 = _require$$5$builders.align,
  25754. conditionalGroup$1 = _require$$5$builders.conditionalGroup,
  25755. fill$2 = _require$$5$builders.fill,
  25756. ifBreak$1 = _require$$5$builders.ifBreak,
  25757. breakParent$2 = _require$$5$builders.breakParent,
  25758. lineSuffixBoundary$1 = _require$$5$builders.lineSuffixBoundary,
  25759. addAlignmentToDoc$2 = _require$$5$builders.addAlignmentToDoc,
  25760. dedent$1 = _require$$5$builders.dedent,
  25761. _require$$5$utils = doc.utils,
  25762. willBreak$1 = _require$$5$utils.willBreak,
  25763. isLineNext$1 = _require$$5$utils.isLineNext,
  25764. isEmpty$1 = _require$$5$utils.isEmpty,
  25765. removeLines$1 = _require$$5$utils.removeLines,
  25766. printDocToString$2 = doc.printer.printDocToString;
  25767. var uid = 0;
  25768. function shouldPrintComma(options, level) {
  25769. level = level || "es5";
  25770. switch (options.trailingComma) {
  25771. case "all":
  25772. if (level === "all") {
  25773. return true;
  25774. }
  25775. // fallthrough
  25776. case "es5":
  25777. if (level === "es5") {
  25778. return true;
  25779. }
  25780. // fallthrough
  25781. case "none":
  25782. default:
  25783. return false;
  25784. }
  25785. }
  25786. function genericPrint(path, options, printPath, args) {
  25787. var node = path.getValue();
  25788. var needsParens = false;
  25789. var linesWithoutParens = printPathNoParens(path, options, printPath, args);
  25790. if (!node || isEmpty$1(linesWithoutParens)) {
  25791. return linesWithoutParens;
  25792. }
  25793. var parentExportDecl = getParentExportDeclaration$1(path);
  25794. var decorators = [];
  25795. if (node.type === "ClassMethod" || node.type === "ClassPrivateMethod" || node.type === "ClassProperty" || node.type === "TSAbstractClassProperty" || node.type === "ClassPrivateProperty" || node.type === "MethodDefinition" || node.type === "TSAbstractMethodDefinition") ; else if (node.decorators && node.decorators.length > 0 && // If the parent node is an export declaration and the decorator
  25796. // was written before the export, the export will be responsible
  25797. // for printing the decorators.
  25798. !(parentExportDecl && options.locStart(parentExportDecl, {
  25799. ignoreDecorators: true
  25800. }) > options.locStart(node.decorators[0]))) {
  25801. var shouldBreak = node.type === "ClassExpression" || node.type === "ClassDeclaration" || hasNewlineBetweenOrAfterDecorators$1(node, options);
  25802. var separator = shouldBreak ? hardline$4 : line$2;
  25803. path.each(function (decoratorPath) {
  25804. var decorator = decoratorPath.getValue();
  25805. if (decorator.expression) {
  25806. decorator = decorator.expression;
  25807. } else {
  25808. decorator = decorator.callee;
  25809. }
  25810. decorators.push(printPath(decoratorPath), separator);
  25811. }, "decorators");
  25812. if (parentExportDecl) {
  25813. decorators.unshift(hardline$4);
  25814. }
  25815. } 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,
  25816. // otherwise they are printed by the node.declaration
  25817. options.locStart(node, {
  25818. ignoreDecorators: true
  25819. }) > options.locStart(node.declaration.decorators[0])) {
  25820. // Export declarations are responsible for printing any decorators
  25821. // that logically apply to node.declaration.
  25822. path.each(function (decoratorPath) {
  25823. var decorator = decoratorPath.getValue();
  25824. var prefix = decorator.type === "Decorator" ? "" : "@";
  25825. decorators.push(prefix, printPath(decoratorPath), hardline$4);
  25826. }, "declaration", "decorators");
  25827. } else {
  25828. // Nodes with decorators can't have parentheses, so we can avoid
  25829. // computing pathNeedsParens() except in this case.
  25830. needsParens = needsParens_1(path, options);
  25831. }
  25832. var parts = [];
  25833. if (needsParens) {
  25834. parts.unshift("(");
  25835. }
  25836. parts.push(linesWithoutParens);
  25837. if (needsParens) {
  25838. var _node = path.getValue();
  25839. if (hasFlowShorthandAnnotationComment$2(_node)) {
  25840. parts.push(" /*");
  25841. parts.push(_node.trailingComments[0].value.trimLeft());
  25842. parts.push("*/");
  25843. _node.trailingComments[0].printed = true;
  25844. }
  25845. parts.push(")");
  25846. }
  25847. if (decorators.length > 0) {
  25848. return group$2(concat$6(decorators.concat(parts)));
  25849. }
  25850. return concat$6(parts);
  25851. }
  25852. function printDecorators(path, options, print) {
  25853. var node = path.getValue();
  25854. return group$2(concat$6([join$4(line$2, path.map(print, "decorators")), hasNewlineBetweenOrAfterDecorators$1(node, options) ? hardline$4 : line$2]));
  25855. }
  25856. /**
  25857. * The following is the shared logic for
  25858. * ternary operators, namely ConditionalExpression
  25859. * and TSConditionalType
  25860. * @typedef {Object} OperatorOptions
  25861. * @property {() => Array<string | Doc>} beforeParts - Parts to print before the `?`.
  25862. * @property {(breakClosingParen: boolean) => Array<string | Doc>} afterParts - Parts to print after the conditional expression.
  25863. * @property {boolean} shouldCheckJsx - Whether to check for and print in JSX mode.
  25864. * @property {string} conditionalNodeType - The type of the conditional expression node, ie "ConditionalExpression" or "TSConditionalType".
  25865. * @property {string} consequentNodePropertyName - The property at which the consequent node can be found on the main node, eg "consequent".
  25866. * @property {string} alternateNodePropertyName - The property at which the alternate node can be found on the main node, eg "alternate".
  25867. * @property {string} testNodePropertyName - The property at which the test node can be found on the main node, eg "test".
  25868. * @property {boolean} breakNested - Whether to break all nested ternaries when one breaks.
  25869. * @param {FastPath} path - The path to the ConditionalExpression/TSConditionalType node.
  25870. * @param {Options} options - Prettier options
  25871. * @param {Function} print - Print function to call recursively
  25872. * @param {OperatorOptions} operatorOptions
  25873. * @returns Doc
  25874. */
  25875. function printTernaryOperator(path, options, print, operatorOptions) {
  25876. var node = path.getValue();
  25877. var testNode = node[operatorOptions.testNodePropertyName];
  25878. var consequentNode = node[operatorOptions.consequentNodePropertyName];
  25879. var alternateNode = node[operatorOptions.alternateNodePropertyName];
  25880. var parts = []; // We print a ConditionalExpression in either "JSX mode" or "normal mode".
  25881. // See tests/jsx/conditional-expression.js for more info.
  25882. var jsxMode = false;
  25883. var parent = path.getParentNode();
  25884. var forceNoIndent = parent.type === operatorOptions.conditionalNodeType; // Find the outermost non-ConditionalExpression parent, and the outermost
  25885. // ConditionalExpression parent. We'll use these to determine if we should
  25886. // print in JSX mode.
  25887. var currentParent;
  25888. var previousParent;
  25889. var i = 0;
  25890. do {
  25891. previousParent = currentParent || node;
  25892. currentParent = path.getParentNode(i);
  25893. i++;
  25894. } while (currentParent && currentParent.type === operatorOptions.conditionalNodeType);
  25895. var firstNonConditionalParent = currentParent || parent;
  25896. var lastConditionalParent = previousParent;
  25897. if (operatorOptions.shouldCheckJsx && (isJSXNode$1(testNode) || isJSXNode$1(consequentNode) || isJSXNode$1(alternateNode) || conditionalExpressionChainContainsJSX$1(lastConditionalParent))) {
  25898. jsxMode = true;
  25899. forceNoIndent = true; // Even though they don't need parens, we wrap (almost) everything in
  25900. // parens when using ?: within JSX, because the parens are analogous to
  25901. // curly braces in an if statement.
  25902. var wrap = function wrap(doc) {
  25903. return concat$6([ifBreak$1("(", ""), indent$3(concat$6([softline$2, doc])), softline$2, ifBreak$1(")", "")]);
  25904. }; // The only things we don't wrap are:
  25905. // * Nested conditional expressions in alternates
  25906. // * null
  25907. var isNull = function isNull(node) {
  25908. return node.type === "NullLiteral" || node.type === "Literal" && node.value === null;
  25909. };
  25910. parts.push(" ? ", isNull(consequentNode) ? path.call(print, operatorOptions.consequentNodePropertyName) : wrap(path.call(print, operatorOptions.consequentNodePropertyName)), " : ", alternateNode.type === operatorOptions.conditionalNodeType || isNull(alternateNode) ? path.call(print, operatorOptions.alternateNodePropertyName) : wrap(path.call(print, operatorOptions.alternateNodePropertyName)));
  25911. } else {
  25912. // normal mode
  25913. var part = concat$6([line$2, "? ", consequentNode.type === operatorOptions.conditionalNodeType ? ifBreak$1("", "(") : "", align$1(2, path.call(print, operatorOptions.consequentNodePropertyName)), consequentNode.type === operatorOptions.conditionalNodeType ? ifBreak$1("", ")") : "", line$2, ": ", alternateNode.type === operatorOptions.conditionalNodeType ? path.call(print, operatorOptions.alternateNodePropertyName) : align$1(2, path.call(print, operatorOptions.alternateNodePropertyName))]);
  25914. parts.push(parent.type !== operatorOptions.conditionalNodeType || parent[operatorOptions.alternateNodePropertyName] === node ? part : options.useTabs ? dedent$1(indent$3(part)) : align$1(Math.max(0, options.tabWidth - 2), part));
  25915. } // We want a whole chain of ConditionalExpressions to all
  25916. // break if any of them break. That means we should only group around the
  25917. // outer-most ConditionalExpression.
  25918. var maybeGroup = function maybeGroup(doc) {
  25919. return operatorOptions.breakNested ? parent === firstNonConditionalParent ? group$2(doc) : doc : group$2(doc);
  25920. }; // Break the closing paren to keep the chain right after it:
  25921. // (a
  25922. // ? b
  25923. // : c
  25924. // ).call()
  25925. var breakClosingParen = !jsxMode && (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression" || parent.type === "NGPipeExpression" && parent.left === node && operatorOptions.breakNested) && !parent.computed;
  25926. return maybeGroup(concat$6([].concat(function (testDoc) {
  25927. return (
  25928. /**
  25929. * a
  25930. * ? b
  25931. * : multiline
  25932. * test
  25933. * node
  25934. * ^^ align(2)
  25935. * ? d
  25936. * : e
  25937. */
  25938. parent.type === operatorOptions.conditionalNodeType && parent[operatorOptions.alternateNodePropertyName] === node ? align$1(2, testDoc) : testDoc
  25939. );
  25940. }(concat$6(operatorOptions.beforeParts())), forceNoIndent ? concat$6(parts) : indent$3(concat$6(parts)), operatorOptions.afterParts(breakClosingParen))));
  25941. }
  25942. function printPathNoParens(path, options, print, args) {
  25943. var n = path.getValue();
  25944. var semi = options.semi ? ";" : "";
  25945. if (!n) {
  25946. return "";
  25947. }
  25948. if (typeof n === "string") {
  25949. return n;
  25950. }
  25951. var htmlBinding = printHtmlBinding$1(path, options, print);
  25952. if (htmlBinding) {
  25953. return htmlBinding;
  25954. }
  25955. var parts = [];
  25956. switch (n.type) {
  25957. case "JsExpressionRoot":
  25958. return path.call(print, "node");
  25959. case "JsonRoot":
  25960. return concat$6([path.call(print, "node"), hardline$4]);
  25961. case "File":
  25962. // Print @babel/parser's InterpreterDirective here so that
  25963. // leading comments on the `Program` node get printed after the hashbang.
  25964. if (n.program && n.program.interpreter) {
  25965. parts.push(path.call(function (programPath) {
  25966. return programPath.call(print, "interpreter");
  25967. }, "program"));
  25968. }
  25969. parts.push(path.call(print, "program"));
  25970. return concat$6(parts);
  25971. case "Program":
  25972. // Babel 6
  25973. if (n.directives) {
  25974. path.each(function (childPath) {
  25975. parts.push(print(childPath), semi, hardline$4);
  25976. if (isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  25977. parts.push(hardline$4);
  25978. }
  25979. }, "directives");
  25980. }
  25981. parts.push(path.call(function (bodyPath) {
  25982. return printStatementSequence(bodyPath, options, print);
  25983. }, "body"));
  25984. parts.push(comments.printDanglingComments(path, options,
  25985. /* sameIndent */
  25986. true)); // Only force a trailing newline if there were any contents.
  25987. if (n.body.length || n.comments) {
  25988. parts.push(hardline$4);
  25989. }
  25990. return concat$6(parts);
  25991. // Babel extension.
  25992. case "EmptyStatement":
  25993. return "";
  25994. case "ExpressionStatement":
  25995. // Detect Flow-parsed directives
  25996. if (n.directive) {
  25997. return concat$6([nodeStr(n.expression, options, true), semi]);
  25998. }
  25999. if (options.parser === "__vue_event_binding") {
  26000. var parent = path.getParentNode();
  26001. if (parent.type === "Program" && parent.body.length === 1 && parent.body[0] === n) {
  26002. return concat$6([path.call(print, "expression"), isVueEventBindingExpression$1(n.expression) ? ";" : ""]);
  26003. }
  26004. } // Do not append semicolon after the only JSX element in a program
  26005. return concat$6([path.call(print, "expression"), isTheOnlyJSXElementInMarkdown$1(options, path) ? "" : semi]);
  26006. // Babel extension.
  26007. case "ParenthesizedExpression":
  26008. return concat$6(["(", path.call(print, "expression"), ")"]);
  26009. case "AssignmentExpression":
  26010. return printAssignment(n.left, path.call(print, "left"), concat$6([" ", n.operator]), n.right, path.call(print, "right"), options);
  26011. case "BinaryExpression":
  26012. case "LogicalExpression":
  26013. case "NGPipeExpression":
  26014. {
  26015. var _parent = path.getParentNode();
  26016. var parentParent = path.getParentNode(1);
  26017. var isInsideParenthesis = n !== _parent.body && (_parent.type === "IfStatement" || _parent.type === "WhileStatement" || _parent.type === "SwitchStatement" || _parent.type === "DoWhileStatement");
  26018. var _parts = printBinaryishExpressions(path, print, options,
  26019. /* isNested */
  26020. false, isInsideParenthesis); // if (
  26021. // this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft
  26022. // ) {
  26023. //
  26024. // looks super weird, we want to break the children if the parent breaks
  26025. //
  26026. // if (
  26027. // this.hasPlugin("dynamicImports") &&
  26028. // this.lookahead().type === tt.parenLeft
  26029. // ) {
  26030. if (isInsideParenthesis) {
  26031. return concat$6(_parts);
  26032. } // Break between the parens in
  26033. // unaries or in a member or specific call expression, i.e.
  26034. //
  26035. // (
  26036. // a &&
  26037. // b &&
  26038. // c
  26039. // ).call()
  26040. if ((_parent.type === "CallExpression" || _parent.type === "OptionalCallExpression") && _parent.callee === n || _parent.type === "UnaryExpression" || (_parent.type === "MemberExpression" || _parent.type === "OptionalMemberExpression") && !_parent.computed) {
  26041. return group$2(concat$6([indent$3(concat$6([softline$2, concat$6(_parts)])), softline$2]));
  26042. } // Avoid indenting sub-expressions in some cases where the first sub-expression is already
  26043. // indented accordingly. We should indent sub-expressions where the first case isn't indented.
  26044. var shouldNotIndent = _parent.type === "ReturnStatement" || _parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" || 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 !== "CallExpression" && parentParent.type !== "OptionalCallExpression";
  26045. var shouldIndentIfInlining = _parent.type === "AssignmentExpression" || _parent.type === "VariableDeclarator" || _parent.type === "ClassProperty" || _parent.type === "TSAbstractClassProperty" || _parent.type === "ClassPrivateProperty" || _parent.type === "ObjectProperty" || _parent.type === "Property";
  26046. var samePrecedenceSubExpression = isBinaryish$1(n.left) && shouldFlatten$1(n.operator, n.left.operator);
  26047. if (shouldNotIndent || shouldInlineLogicalExpression(n) && !samePrecedenceSubExpression || !shouldInlineLogicalExpression(n) && shouldIndentIfInlining) {
  26048. return group$2(concat$6(_parts));
  26049. }
  26050. if (_parts.length === 0) {
  26051. return "";
  26052. } // If the right part is a JSX node, we include it in a separate group to
  26053. // prevent it breaking the whole chain, so we can print the expression like:
  26054. //
  26055. // foo && bar && (
  26056. // <Foo>
  26057. // <Bar />
  26058. // </Foo>
  26059. // )
  26060. var hasJSX = isJSXNode$1(n.right);
  26061. var rest = concat$6(hasJSX ? _parts.slice(1, -1) : _parts.slice(1));
  26062. var groupId = Symbol("logicalChain-" + ++uid);
  26063. var chain = group$2(concat$6([// Don't include the initial expression in the indentation
  26064. // level. The first item is guaranteed to be the first
  26065. // left-most expression.
  26066. _parts.length > 0 ? _parts[0] : "", indent$3(rest)]), {
  26067. id: groupId
  26068. });
  26069. if (!hasJSX) {
  26070. return chain;
  26071. }
  26072. var jsxPart = getLast$2(_parts);
  26073. return group$2(concat$6([chain, ifBreak$1(indent$3(jsxPart), jsxPart, {
  26074. groupId
  26075. })]));
  26076. }
  26077. case "AssignmentPattern":
  26078. return concat$6([path.call(print, "left"), " = ", path.call(print, "right")]);
  26079. case "TSTypeAssertion":
  26080. {
  26081. var shouldBreakAfterCast = !(n.expression.type === "ArrayExpression" || n.expression.type === "ObjectExpression");
  26082. var castGroup = group$2(concat$6(["<", indent$3(concat$6([softline$2, path.call(print, "typeAnnotation")])), softline$2, ">"]));
  26083. var exprContents = concat$6([ifBreak$1("("), indent$3(concat$6([softline$2, path.call(print, "expression")])), softline$2, ifBreak$1(")")]);
  26084. if (shouldBreakAfterCast) {
  26085. return conditionalGroup$1([concat$6([castGroup, path.call(print, "expression")]), concat$6([castGroup, group$2(exprContents, {
  26086. shouldBreak: true
  26087. })]), concat$6([castGroup, path.call(print, "expression")])]);
  26088. }
  26089. return group$2(concat$6([castGroup, path.call(print, "expression")]));
  26090. }
  26091. case "OptionalMemberExpression":
  26092. case "MemberExpression":
  26093. {
  26094. var _parent2 = path.getParentNode();
  26095. var firstNonMemberParent;
  26096. var i = 0;
  26097. do {
  26098. firstNonMemberParent = path.getParentNode(i);
  26099. i++;
  26100. } while (firstNonMemberParent && (firstNonMemberParent.type === "MemberExpression" || firstNonMemberParent.type === "OptionalMemberExpression" || firstNonMemberParent.type === "TSNonNullExpression"));
  26101. var 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" && _parent2.type !== "MemberExpression" && _parent2.type !== "OptionalMemberExpression";
  26102. return concat$6([path.call(print, "object"), shouldInline ? printMemberLookup(path, options, print) : group$2(indent$3(concat$6([softline$2, printMemberLookup(path, options, print)])))]);
  26103. }
  26104. case "MetaProperty":
  26105. return concat$6([path.call(print, "meta"), ".", path.call(print, "property")]);
  26106. case "BindExpression":
  26107. if (n.object) {
  26108. parts.push(path.call(print, "object"));
  26109. }
  26110. parts.push(group$2(indent$3(concat$6([softline$2, printBindExpressionCallee(path, options, print)]))));
  26111. return concat$6(parts);
  26112. case "Identifier":
  26113. {
  26114. return concat$6([n.name, printOptionalToken(path), printTypeAnnotation(path, options, print)]);
  26115. }
  26116. case "V8IntrinsicIdentifier":
  26117. return concat$6(["%", n.name]);
  26118. case "SpreadElement":
  26119. case "SpreadElementPattern":
  26120. case "RestProperty":
  26121. case "SpreadProperty":
  26122. case "SpreadPropertyPattern":
  26123. case "RestElement":
  26124. case "ObjectTypeSpreadProperty":
  26125. return concat$6(["...", path.call(print, "argument"), printTypeAnnotation(path, options, print)]);
  26126. case "FunctionDeclaration":
  26127. case "FunctionExpression":
  26128. parts.push(printFunctionDeclaration(path, print, options));
  26129. if (!n.body) {
  26130. parts.push(semi);
  26131. }
  26132. return concat$6(parts);
  26133. case "ArrowFunctionExpression":
  26134. {
  26135. if (n.async) {
  26136. parts.push("async ");
  26137. }
  26138. if (shouldPrintParamsWithoutParens(path, options)) {
  26139. parts.push(path.call(print, "params", 0));
  26140. } else {
  26141. parts.push(group$2(concat$6([printFunctionParams(path, print, options,
  26142. /* expandLast */
  26143. args && (args.expandLastArg || args.expandFirstArg),
  26144. /* printTypeParams */
  26145. true), printReturnType(path, print, options)])));
  26146. }
  26147. var dangling = comments.printDanglingComments(path, options,
  26148. /* sameIndent */
  26149. true, function (comment) {
  26150. var nextCharacter = getNextNonSpaceNonCommentCharacterIndex$2(options.originalText, comment, options);
  26151. return options.originalText.substr(nextCharacter, 2) === "=>";
  26152. });
  26153. if (dangling) {
  26154. parts.push(" ", dangling);
  26155. }
  26156. parts.push(" =>");
  26157. var body = path.call(function (bodyPath) {
  26158. return print(bodyPath, args);
  26159. }, "body"); // We want to always keep these types of nodes on the same line
  26160. // as the arrow.
  26161. if (!hasLeadingOwnLineComment$1(options.originalText, n.body, options) && (n.body.type === "ArrayExpression" || n.body.type === "ObjectExpression" || n.body.type === "BlockStatement" || isJSXNode$1(n.body) || isTemplateOnItsOwnLine$1(n.body, options.originalText, options) || n.body.type === "ArrowFunctionExpression" || n.body.type === "DoExpression")) {
  26162. return group$2(concat$6([concat$6(parts), " ", body]));
  26163. } // We handle sequence expressions as the body of arrows specially,
  26164. // so that the required parentheses end up on their own lines.
  26165. if (n.body.type === "SequenceExpression") {
  26166. return group$2(concat$6([concat$6(parts), group$2(concat$6([" (", indent$3(concat$6([softline$2, body])), softline$2, ")"]))]));
  26167. } // if the arrow function is expanded as last argument, we are adding a
  26168. // level of indentation and need to add a softline to align the closing )
  26169. // with the opening (, or if it's inside a JSXExpression (e.g. an attribute)
  26170. // we should align the expression's closing } with the line with the opening {.
  26171. var shouldAddSoftLine = (args && args.expandLastArg || path.getParentNode().type === "JSXExpressionContainer") && !(n.comments && n.comments.length);
  26172. var printTrailingComma = args && args.expandLastArg && shouldPrintComma(options, "all"); // In order to avoid confusion between
  26173. // a => a ? a : a
  26174. // a <= a ? a : a
  26175. var shouldAddParens = n.body.type === "ConditionalExpression" && !startsWithNoLookaheadToken$1(n.body,
  26176. /* forbidFunctionAndClass */
  26177. false);
  26178. return group$2(concat$6([concat$6(parts), group$2(concat$6([indent$3(concat$6([line$2, shouldAddParens ? ifBreak$1("", "(") : "", body, shouldAddParens ? ifBreak$1("", ")") : ""])), shouldAddSoftLine ? concat$6([ifBreak$1(printTrailingComma ? "," : ""), softline$2]) : ""]))]));
  26179. }
  26180. case "YieldExpression":
  26181. parts.push("yield");
  26182. if (n.delegate) {
  26183. parts.push("*");
  26184. }
  26185. if (n.argument) {
  26186. parts.push(" ", path.call(print, "argument"));
  26187. }
  26188. return concat$6(parts);
  26189. case "AwaitExpression":
  26190. {
  26191. parts.push("await ", path.call(print, "argument"));
  26192. var _parent3 = path.getParentNode();
  26193. if ((_parent3.type === "CallExpression" || _parent3.type === "OptionalCallExpression") && _parent3.callee === n || (_parent3.type === "MemberExpression" || _parent3.type === "OptionalMemberExpression") && _parent3.object === n) {
  26194. return group$2(concat$6([indent$3(concat$6([softline$2, concat$6(parts)])), softline$2]));
  26195. }
  26196. return concat$6(parts);
  26197. }
  26198. case "ImportSpecifier":
  26199. if (n.importKind) {
  26200. parts.push(path.call(print, "importKind"), " ");
  26201. }
  26202. parts.push(path.call(print, "imported"));
  26203. if (n.local && n.local.name !== n.imported.name) {
  26204. parts.push(" as ", path.call(print, "local"));
  26205. }
  26206. return concat$6(parts);
  26207. case "ExportSpecifier":
  26208. parts.push(path.call(print, "local"));
  26209. if (n.exported && n.exported.name !== n.local.name) {
  26210. parts.push(" as ", path.call(print, "exported"));
  26211. }
  26212. return concat$6(parts);
  26213. case "ImportNamespaceSpecifier":
  26214. parts.push("* as ");
  26215. parts.push(path.call(print, "local"));
  26216. return concat$6(parts);
  26217. case "ImportDefaultSpecifier":
  26218. return path.call(print, "local");
  26219. case "TSExportAssignment":
  26220. return concat$6(["export = ", path.call(print, "expression"), semi]);
  26221. case "ExportDefaultDeclaration":
  26222. case "ExportNamedDeclaration":
  26223. return printExportDeclaration(path, options, print);
  26224. case "ExportAllDeclaration":
  26225. parts.push("export ");
  26226. if (n.exportKind === "type") {
  26227. parts.push("type ");
  26228. }
  26229. parts.push("* from ", path.call(print, "source"), semi);
  26230. return concat$6(parts);
  26231. case "ExportNamespaceSpecifier":
  26232. case "ExportDefaultSpecifier":
  26233. return path.call(print, "exported");
  26234. case "ImportDeclaration":
  26235. {
  26236. parts.push("import ");
  26237. if (n.importKind && n.importKind !== "value") {
  26238. parts.push(n.importKind + " ");
  26239. }
  26240. var standalones = [];
  26241. var grouped = [];
  26242. if (n.specifiers && n.specifiers.length > 0) {
  26243. path.each(function (specifierPath) {
  26244. var value = specifierPath.getValue();
  26245. if (value.type === "ImportDefaultSpecifier" || value.type === "ImportNamespaceSpecifier") {
  26246. standalones.push(print(specifierPath));
  26247. } else {
  26248. grouped.push(print(specifierPath));
  26249. }
  26250. }, "specifiers");
  26251. if (standalones.length > 0) {
  26252. parts.push(join$4(", ", standalones));
  26253. }
  26254. if (standalones.length > 0 && grouped.length > 0) {
  26255. parts.push(", ");
  26256. }
  26257. if (grouped.length === 1 && standalones.length === 0 && n.specifiers && !n.specifiers.some(function (node) {
  26258. return node.comments;
  26259. })) {
  26260. parts.push(concat$6(["{", options.bracketSpacing ? " " : "", concat$6(grouped), options.bracketSpacing ? " " : "", "}"]));
  26261. } else if (grouped.length >= 1) {
  26262. parts.push(group$2(concat$6(["{", indent$3(concat$6([options.bracketSpacing ? line$2 : softline$2, join$4(concat$6([",", line$2]), grouped)])), ifBreak$1(shouldPrintComma(options) ? "," : ""), options.bracketSpacing ? line$2 : softline$2, "}"])));
  26263. }
  26264. parts.push(" from ");
  26265. } else if (n.importKind && n.importKind === "type" || // import {} from 'x'
  26266. /{\s*}/.test(options.originalText.slice(options.locStart(n), options.locStart(n.source)))) {
  26267. parts.push("{} from ");
  26268. }
  26269. parts.push(path.call(print, "source"), semi);
  26270. return concat$6(parts);
  26271. }
  26272. case "Import":
  26273. return "import";
  26274. case "TSModuleBlock":
  26275. case "BlockStatement":
  26276. {
  26277. var naked = path.call(function (bodyPath) {
  26278. return printStatementSequence(bodyPath, options, print);
  26279. }, "body");
  26280. var hasContent = n.body.find(function (node) {
  26281. return node.type !== "EmptyStatement";
  26282. });
  26283. var hasDirectives = n.directives && n.directives.length > 0;
  26284. var _parent4 = path.getParentNode();
  26285. var _parentParent = path.getParentNode(1);
  26286. if (!hasContent && !hasDirectives && !hasDanglingComments$1(n) && (_parent4.type === "ArrowFunctionExpression" || _parent4.type === "FunctionExpression" || _parent4.type === "FunctionDeclaration" || _parent4.type === "ObjectMethod" || _parent4.type === "ClassMethod" || _parent4.type === "ClassPrivateMethod" || _parent4.type === "ForStatement" || _parent4.type === "WhileStatement" || _parent4.type === "DoWhileStatement" || _parent4.type === "DoExpression" || _parent4.type === "CatchClause" && !_parentParent.finalizer || _parent4.type === "TSModuleDeclaration")) {
  26287. return "{}";
  26288. }
  26289. parts.push("{"); // Babel 6
  26290. if (hasDirectives) {
  26291. path.each(function (childPath) {
  26292. parts.push(indent$3(concat$6([hardline$4, print(childPath), semi])));
  26293. if (isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  26294. parts.push(hardline$4);
  26295. }
  26296. }, "directives");
  26297. }
  26298. if (hasContent) {
  26299. parts.push(indent$3(concat$6([hardline$4, naked])));
  26300. }
  26301. parts.push(comments.printDanglingComments(path, options));
  26302. parts.push(hardline$4, "}");
  26303. return concat$6(parts);
  26304. }
  26305. case "ReturnStatement":
  26306. parts.push("return");
  26307. if (n.argument) {
  26308. if (returnArgumentHasLeadingComment$1(options, n.argument)) {
  26309. parts.push(concat$6([" (", indent$3(concat$6([hardline$4, path.call(print, "argument")])), hardline$4, ")"]));
  26310. } else if (n.argument.type === "LogicalExpression" || n.argument.type === "BinaryExpression" || n.argument.type === "SequenceExpression") {
  26311. parts.push(group$2(concat$6([ifBreak$1(" (", " "), indent$3(concat$6([softline$2, path.call(print, "argument")])), softline$2, ifBreak$1(")")])));
  26312. } else {
  26313. parts.push(" ", path.call(print, "argument"));
  26314. }
  26315. }
  26316. if (hasDanglingComments$1(n)) {
  26317. parts.push(" ", comments.printDanglingComments(path, options,
  26318. /* sameIndent */
  26319. true));
  26320. }
  26321. parts.push(semi);
  26322. return concat$6(parts);
  26323. case "NewExpression":
  26324. case "OptionalCallExpression":
  26325. case "CallExpression":
  26326. {
  26327. var isNew = n.type === "NewExpression";
  26328. var optional = printOptionalToken(path);
  26329. if ( // We want to keep CommonJS- and AMD-style require calls, and AMD-style
  26330. // define calls, as a unit.
  26331. // e.g. `define(["some/lib", (lib) => {`
  26332. !isNew && n.callee.type === "Identifier" && (n.callee.name === "require" || n.callee.name === "define") || // Template literals as single arguments
  26333. n.arguments.length === 1 && isTemplateOnItsOwnLine$1(n.arguments[0], options.originalText, options) || // Keep test declarations on a single line
  26334. // e.g. `it('long name', () => {`
  26335. !isNew && isTestCall$1(n, path.getParentNode())) {
  26336. return concat$6([isNew ? "new " : "", path.call(print, "callee"), optional, printFunctionTypeParameters(path, options, print), concat$6(["(", join$4(", ", path.map(print, "arguments")), ")"])]);
  26337. } // Inline Flow annotation comments following Identifiers in Call nodes need to
  26338. // stay with the Identifier. For example:
  26339. //
  26340. // foo /*:: <SomeGeneric> */(bar);
  26341. //
  26342. // Here, we ensure that such comments stay between the Identifier and the Callee.
  26343. var isIdentifierWithFlowAnnotation = n.callee.type === "Identifier" && hasFlowAnnotationComment$1(n.callee.trailingComments);
  26344. if (isIdentifierWithFlowAnnotation) {
  26345. n.callee.trailingComments[0].printed = true;
  26346. } // We detect calls on member lookups and possibly print them in a
  26347. // special chain format. See `printMemberChain` for more info.
  26348. if (!isNew && isMemberish$1(n.callee)) {
  26349. return printMemberChain(path, options, print);
  26350. }
  26351. var contents = concat$6([isNew ? "new " : "", path.call(print, "callee"), optional, isIdentifierWithFlowAnnotation ? `/*:: ${n.callee.trailingComments[0].value.substring(2).trim()} */` : "", printFunctionTypeParameters(path, options, print), printArgumentsList(path, options, print)]); // We group here when the callee is itself a call expression.
  26352. // See `isLongCurriedCallExpression` for more info.
  26353. if (isCallOrOptionalCallExpression$1(n.callee)) {
  26354. return group$2(contents);
  26355. }
  26356. return contents;
  26357. }
  26358. case "TSInterfaceDeclaration":
  26359. if (n.declare) {
  26360. parts.push("declare ");
  26361. }
  26362. parts.push(n.abstract ? "abstract " : "", printTypeScriptModifiers(path, options, print), "interface ", path.call(print, "id"), n.typeParameters ? path.call(print, "typeParameters") : "", " ");
  26363. if (n.extends && n.extends.length) {
  26364. parts.push(group$2(indent$3(concat$6([softline$2, "extends ", (n.extends.length === 1 ? identity$1 : indent$3)(join$4(concat$6([",", line$2]), path.map(print, "extends"))), " "]))));
  26365. }
  26366. parts.push(path.call(print, "body"));
  26367. return concat$6(parts);
  26368. case "ObjectTypeInternalSlot":
  26369. return concat$6([n.static ? "static " : "", "[[", path.call(print, "id"), "]]", printOptionalToken(path), n.method ? "" : ": ", path.call(print, "value")]);
  26370. case "ObjectExpression":
  26371. case "ObjectPattern":
  26372. case "ObjectTypeAnnotation":
  26373. case "TSInterfaceBody":
  26374. case "TSTypeLiteral":
  26375. {
  26376. var propertiesField;
  26377. if (n.type === "TSTypeLiteral") {
  26378. propertiesField = "members";
  26379. } else if (n.type === "TSInterfaceBody") {
  26380. propertiesField = "body";
  26381. } else {
  26382. propertiesField = "properties";
  26383. }
  26384. var isTypeAnnotation = n.type === "ObjectTypeAnnotation";
  26385. var fields = [];
  26386. if (isTypeAnnotation) {
  26387. fields.push("indexers", "callProperties", "internalSlots");
  26388. }
  26389. fields.push(propertiesField);
  26390. var firstProperty = fields.map(function (field) {
  26391. return n[field][0];
  26392. }).sort(function (a, b) {
  26393. return options.locStart(a) - options.locStart(b);
  26394. })[0];
  26395. var _parent5 = path.getParentNode(0);
  26396. var isFlowInterfaceLikeBody = isTypeAnnotation && _parent5 && (_parent5.type === "InterfaceDeclaration" || _parent5.type === "DeclareInterface" || _parent5.type === "DeclareClass") && path.getName() === "body";
  26397. var shouldBreak = n.type === "TSInterfaceBody" || isFlowInterfaceLikeBody || n.type === "ObjectPattern" && _parent5.type !== "FunctionDeclaration" && _parent5.type !== "FunctionExpression" && _parent5.type !== "ArrowFunctionExpression" && _parent5.type !== "ObjectMethod" && _parent5.type !== "ClassMethod" && _parent5.type !== "ClassPrivateMethod" && _parent5.type !== "AssignmentPattern" && _parent5.type !== "CatchClause" && n.properties.some(function (property) {
  26398. return property.value && (property.value.type === "ObjectPattern" || property.value.type === "ArrayPattern");
  26399. }) || n.type !== "ObjectPattern" && firstProperty && hasNewlineInRange$2(options.originalText, options.locStart(n), options.locStart(firstProperty));
  26400. var separator = isFlowInterfaceLikeBody ? ";" : n.type === "TSInterfaceBody" || n.type === "TSTypeLiteral" ? ifBreak$1(semi, ";") : ",";
  26401. var leftBrace = n.exact ? "{|" : "{";
  26402. var rightBrace = n.exact ? "|}" : "}"; // Unfortunately, things are grouped together in the ast can be
  26403. // interleaved in the source code. So we need to reorder them before
  26404. // printing them.
  26405. var propsAndLoc = [];
  26406. fields.forEach(function (field) {
  26407. path.each(function (childPath) {
  26408. var node = childPath.getValue();
  26409. propsAndLoc.push({
  26410. node: node,
  26411. printed: print(childPath),
  26412. loc: options.locStart(node)
  26413. });
  26414. }, field);
  26415. });
  26416. var separatorParts = [];
  26417. var props = propsAndLoc.sort(function (a, b) {
  26418. return a.loc - b.loc;
  26419. }).map(function (prop) {
  26420. var result = concat$6(separatorParts.concat(group$2(prop.printed)));
  26421. separatorParts = [separator, line$2];
  26422. if ((prop.node.type === "TSPropertySignature" || prop.node.type === "TSMethodSignature" || prop.node.type === "TSConstructSignatureDeclaration") && hasNodeIgnoreComment$2(prop.node)) {
  26423. separatorParts.shift();
  26424. }
  26425. if (isNextLineEmpty$2(options.originalText, prop.node, options)) {
  26426. separatorParts.push(hardline$4);
  26427. }
  26428. return result;
  26429. });
  26430. if (n.inexact) {
  26431. props.push(concat$6(separatorParts.concat(group$2("..."))));
  26432. }
  26433. var lastElem = getLast$2(n[propertiesField]);
  26434. var canHaveTrailingSeparator = !(lastElem && (lastElem.type === "RestProperty" || lastElem.type === "RestElement" || hasNodeIgnoreComment$2(lastElem) || n.inexact));
  26435. var content;
  26436. if (props.length === 0) {
  26437. if (!hasDanglingComments$1(n)) {
  26438. return concat$6([leftBrace, rightBrace, printTypeAnnotation(path, options, print)]);
  26439. }
  26440. content = group$2(concat$6([leftBrace, comments.printDanglingComments(path, options), softline$2, rightBrace, printOptionalToken(path), printTypeAnnotation(path, options, print)]));
  26441. } else {
  26442. content = concat$6([leftBrace, indent$3(concat$6([options.bracketSpacing ? line$2 : softline$2, concat$6(props)])), ifBreak$1(canHaveTrailingSeparator && (separator !== "," || shouldPrintComma(options)) ? separator : ""), concat$6([options.bracketSpacing ? line$2 : softline$2, rightBrace]), printOptionalToken(path), printTypeAnnotation(path, options, print)]);
  26443. } // If we inline the object as first argument of the parent, we don't want
  26444. // to create another group so that the object breaks before the return
  26445. // type
  26446. var parentParentParent = path.getParentNode(2);
  26447. if (n.type === "ObjectPattern" && _parent5 && shouldHugArguments(_parent5) && !n.decorators && _parent5.params[0] === n || shouldHugType(n) && parentParentParent && shouldHugArguments(parentParentParent) && parentParentParent.params[0].typeAnnotation && parentParentParent.params[0].typeAnnotation.typeAnnotation === n) {
  26448. return content;
  26449. }
  26450. return group$2(content, {
  26451. shouldBreak
  26452. });
  26453. }
  26454. // Babel 6
  26455. case "ObjectProperty": // Non-standard AST node type.
  26456. case "Property":
  26457. if (n.method || n.kind === "get" || n.kind === "set") {
  26458. return printMethod(path, options, print);
  26459. }
  26460. if (n.shorthand) {
  26461. parts.push(path.call(print, "value"));
  26462. } else {
  26463. parts.push(printAssignment(n.key, printPropertyKey(path, options, print), ":", n.value, path.call(print, "value"), options));
  26464. }
  26465. return concat$6(parts);
  26466. // Babel 6
  26467. case "ClassMethod":
  26468. case "ClassPrivateMethod":
  26469. case "MethodDefinition":
  26470. case "TSAbstractMethodDefinition":
  26471. if (n.decorators && n.decorators.length !== 0) {
  26472. parts.push(printDecorators(path, options, print));
  26473. }
  26474. if (n.accessibility) {
  26475. parts.push(n.accessibility + " ");
  26476. }
  26477. if (n.static) {
  26478. parts.push("static ");
  26479. }
  26480. if (n.type === "TSAbstractMethodDefinition") {
  26481. parts.push("abstract ");
  26482. }
  26483. parts.push(printMethod(path, options, print));
  26484. return concat$6(parts);
  26485. case "ObjectMethod":
  26486. return printMethod(path, options, print);
  26487. case "Decorator":
  26488. return concat$6(["@", path.call(print, "expression"), path.call(print, "callee")]);
  26489. case "ArrayExpression":
  26490. case "ArrayPattern":
  26491. if (n.elements.length === 0) {
  26492. if (!hasDanglingComments$1(n)) {
  26493. parts.push("[]");
  26494. } else {
  26495. parts.push(group$2(concat$6(["[", comments.printDanglingComments(path, options), softline$2, "]"])));
  26496. }
  26497. } else {
  26498. var _lastElem = getLast$2(n.elements);
  26499. var canHaveTrailingComma = !(_lastElem && _lastElem.type === "RestElement"); // JavaScript allows you to have empty elements in an array which
  26500. // changes its length based on the number of commas. The algorithm
  26501. // is that if the last argument is null, we need to force insert
  26502. // a comma to ensure JavaScript recognizes it.
  26503. // [,].length === 1
  26504. // [1,].length === 1
  26505. // [1,,].length === 2
  26506. //
  26507. // Note that getLast returns null if the array is empty, but
  26508. // we already check for an empty array just above so we are safe
  26509. var needsForcedTrailingComma = canHaveTrailingComma && _lastElem === null;
  26510. var _shouldBreak = n.elements.length > 1 && n.elements.every(function (element, i, elements) {
  26511. var elementType = element && element.type;
  26512. if (elementType !== "ArrayExpression" && elementType !== "ObjectExpression") {
  26513. return false;
  26514. }
  26515. var nextElement = elements[i + 1];
  26516. if (nextElement && elementType !== nextElement.type) {
  26517. return false;
  26518. }
  26519. var itemsKey = elementType === "ArrayExpression" ? "elements" : "properties";
  26520. return element[itemsKey] && element[itemsKey].length > 1;
  26521. });
  26522. parts.push(group$2(concat$6(["[", indent$3(concat$6([softline$2, printArrayItems(path, options, "elements", print)])), needsForcedTrailingComma ? "," : "", ifBreak$1(canHaveTrailingComma && !needsForcedTrailingComma && shouldPrintComma(options) ? "," : ""), comments.printDanglingComments(path, options,
  26523. /* sameIndent */
  26524. true), softline$2, "]"]), {
  26525. shouldBreak: _shouldBreak
  26526. }));
  26527. }
  26528. parts.push(printOptionalToken(path), printTypeAnnotation(path, options, print));
  26529. return concat$6(parts);
  26530. case "SequenceExpression":
  26531. {
  26532. var _parent6 = path.getParentNode(0);
  26533. if (_parent6.type === "ExpressionStatement" || _parent6.type === "ForStatement") {
  26534. // For ExpressionStatements and for-loop heads, which are among
  26535. // the few places a SequenceExpression appears unparenthesized, we want
  26536. // to indent expressions after the first.
  26537. var _parts2 = [];
  26538. path.each(function (p) {
  26539. if (p.getName() === 0) {
  26540. _parts2.push(print(p));
  26541. } else {
  26542. _parts2.push(",", indent$3(concat$6([line$2, print(p)])));
  26543. }
  26544. }, "expressions");
  26545. return group$2(concat$6(_parts2));
  26546. }
  26547. return group$2(concat$6([join$4(concat$6([",", line$2]), path.map(print, "expressions"))]));
  26548. }
  26549. case "ThisExpression":
  26550. return "this";
  26551. case "Super":
  26552. return "super";
  26553. case "NullLiteral":
  26554. // Babel 6 Literal split
  26555. return "null";
  26556. case "RegExpLiteral":
  26557. // Babel 6 Literal split
  26558. return printRegex(n);
  26559. case "NumericLiteral":
  26560. // Babel 6 Literal split
  26561. return printNumber$1(n.extra.raw);
  26562. case "BigIntLiteral":
  26563. // babel: n.extra.raw, typescript: n.raw, flow: n.bigint
  26564. return (n.bigint || (n.extra ? n.extra.raw : n.raw)).toLowerCase();
  26565. case "BooleanLiteral": // Babel 6 Literal split
  26566. case "StringLiteral": // Babel 6 Literal split
  26567. case "Literal":
  26568. {
  26569. if (n.regex) {
  26570. return printRegex(n.regex);
  26571. }
  26572. if (typeof n.value === "number") {
  26573. return printNumber$1(n.raw);
  26574. }
  26575. if (typeof n.value !== "string") {
  26576. return "" + n.value;
  26577. } // TypeScript workaround for https://github.com/JamesHenry/typescript-estree/issues/2
  26578. // See corresponding workaround in needs-parens.js
  26579. var grandParent = path.getParentNode(1);
  26580. var isTypeScriptDirective = options.parser === "typescript" && typeof n.value === "string" && grandParent && (grandParent.type === "Program" || grandParent.type === "BlockStatement");
  26581. return nodeStr(n, options, isTypeScriptDirective);
  26582. }
  26583. case "Directive":
  26584. return path.call(print, "value");
  26585. // Babel 6
  26586. case "DirectiveLiteral":
  26587. return nodeStr(n, options);
  26588. case "UnaryExpression":
  26589. parts.push(n.operator);
  26590. if (/[a-z]$/.test(n.operator)) {
  26591. parts.push(" ");
  26592. }
  26593. if (n.argument.comments && n.argument.comments.length > 0) {
  26594. parts.push(group$2(concat$6(["(", indent$3(concat$6([softline$2, path.call(print, "argument")])), softline$2, ")"])));
  26595. } else {
  26596. parts.push(path.call(print, "argument"));
  26597. }
  26598. return concat$6(parts);
  26599. case "UpdateExpression":
  26600. parts.push(path.call(print, "argument"), n.operator);
  26601. if (n.prefix) {
  26602. parts.reverse();
  26603. }
  26604. return concat$6(parts);
  26605. case "ConditionalExpression":
  26606. return printTernaryOperator(path, options, print, {
  26607. beforeParts: function beforeParts() {
  26608. return [path.call(print, "test")];
  26609. },
  26610. afterParts: function afterParts(breakClosingParen) {
  26611. return [breakClosingParen ? softline$2 : ""];
  26612. },
  26613. shouldCheckJsx: true,
  26614. conditionalNodeType: "ConditionalExpression",
  26615. consequentNodePropertyName: "consequent",
  26616. alternateNodePropertyName: "alternate",
  26617. testNodePropertyName: "test",
  26618. breakNested: true
  26619. });
  26620. case "VariableDeclaration":
  26621. {
  26622. var printed = path.map(function (childPath) {
  26623. return print(childPath);
  26624. }, "declarations"); // We generally want to terminate all variable declarations with a
  26625. // semicolon, except when they in the () part of for loops.
  26626. var parentNode = path.getParentNode();
  26627. var isParentForLoop = parentNode.type === "ForStatement" || parentNode.type === "ForInStatement" || parentNode.type === "ForOfStatement" || parentNode.type === "ForAwaitStatement";
  26628. var hasValue = n.declarations.some(function (decl) {
  26629. return decl.init;
  26630. });
  26631. var firstVariable;
  26632. if (printed.length === 1 && !n.declarations[0].comments) {
  26633. firstVariable = printed[0];
  26634. } else if (printed.length > 0) {
  26635. // Indent first var to comply with eslint one-var rule
  26636. firstVariable = indent$3(printed[0]);
  26637. }
  26638. parts = [n.declare ? "declare " : "", n.kind, firstVariable ? concat$6([" ", firstVariable]) : "", indent$3(concat$6(printed.slice(1).map(function (p) {
  26639. return concat$6([",", hasValue && !isParentForLoop ? hardline$4 : line$2, p]);
  26640. })))];
  26641. if (!(isParentForLoop && parentNode.body !== n)) {
  26642. parts.push(semi);
  26643. }
  26644. return group$2(concat$6(parts));
  26645. }
  26646. case "TSTypeAliasDeclaration":
  26647. {
  26648. if (n.declare) {
  26649. parts.push("declare ");
  26650. }
  26651. var _printed = printAssignmentRight(n.id, n.typeAnnotation, n.typeAnnotation && path.call(print, "typeAnnotation"), options);
  26652. parts.push("type ", path.call(print, "id"), path.call(print, "typeParameters"), " =", _printed, semi);
  26653. return group$2(concat$6(parts));
  26654. }
  26655. case "VariableDeclarator":
  26656. return printAssignment(n.id, path.call(print, "id"), " =", n.init, n.init && path.call(print, "init"), options);
  26657. case "WithStatement":
  26658. return group$2(concat$6(["with (", path.call(print, "object"), ")", adjustClause(n.body, path.call(print, "body"))]));
  26659. case "IfStatement":
  26660. {
  26661. var con = adjustClause(n.consequent, path.call(print, "consequent"));
  26662. var opening = group$2(concat$6(["if (", group$2(concat$6([indent$3(concat$6([softline$2, path.call(print, "test")])), softline$2])), ")", con]));
  26663. parts.push(opening);
  26664. if (n.alternate) {
  26665. var commentOnOwnLine = hasTrailingComment$1(n.consequent) && n.consequent.comments.some(function (comment) {
  26666. return comment.trailing && !comments$1.isBlockComment(comment);
  26667. }) || needsHardlineAfterDanglingComment$1(n);
  26668. var elseOnSameLine = n.consequent.type === "BlockStatement" && !commentOnOwnLine;
  26669. parts.push(elseOnSameLine ? " " : hardline$4);
  26670. if (hasDanglingComments$1(n)) {
  26671. parts.push(comments.printDanglingComments(path, options, true), commentOnOwnLine ? hardline$4 : " ");
  26672. }
  26673. parts.push("else", group$2(adjustClause(n.alternate, path.call(print, "alternate"), n.alternate.type === "IfStatement")));
  26674. }
  26675. return concat$6(parts);
  26676. }
  26677. case "ForStatement":
  26678. {
  26679. var _body = adjustClause(n.body, path.call(print, "body")); // We want to keep dangling comments above the loop to stay consistent.
  26680. // Any comment positioned between the for statement and the parentheses
  26681. // is going to be printed before the statement.
  26682. var _dangling = comments.printDanglingComments(path, options,
  26683. /* sameLine */
  26684. true);
  26685. var printedComments = _dangling ? concat$6([_dangling, softline$2]) : "";
  26686. if (!n.init && !n.test && !n.update) {
  26687. return concat$6([printedComments, group$2(concat$6(["for (;;)", _body]))]);
  26688. }
  26689. return concat$6([printedComments, group$2(concat$6(["for (", group$2(concat$6([indent$3(concat$6([softline$2, path.call(print, "init"), ";", line$2, path.call(print, "test"), ";", line$2, path.call(print, "update")])), softline$2])), ")", _body]))]);
  26690. }
  26691. case "WhileStatement":
  26692. return group$2(concat$6(["while (", group$2(concat$6([indent$3(concat$6([softline$2, path.call(print, "test")])), softline$2])), ")", adjustClause(n.body, path.call(print, "body"))]));
  26693. case "ForInStatement":
  26694. // Note: esprima can't actually parse "for each (".
  26695. return group$2(concat$6([n.each ? "for each (" : "for (", path.call(print, "left"), " in ", path.call(print, "right"), ")", adjustClause(n.body, path.call(print, "body"))]));
  26696. case "ForOfStatement":
  26697. case "ForAwaitStatement":
  26698. {
  26699. // Babel 7 removed ForAwaitStatement in favor of ForOfStatement
  26700. // with `"await": true`:
  26701. // https://github.com/estree/estree/pull/138
  26702. var isAwait = n.type === "ForAwaitStatement" || n.await;
  26703. return group$2(concat$6(["for", isAwait ? " await" : "", " (", path.call(print, "left"), " of ", path.call(print, "right"), ")", adjustClause(n.body, path.call(print, "body"))]));
  26704. }
  26705. case "DoWhileStatement":
  26706. {
  26707. var clause = adjustClause(n.body, path.call(print, "body"));
  26708. var doBody = group$2(concat$6(["do", clause]));
  26709. parts = [doBody];
  26710. if (n.body.type === "BlockStatement") {
  26711. parts.push(" ");
  26712. } else {
  26713. parts.push(hardline$4);
  26714. }
  26715. parts.push("while (");
  26716. parts.push(group$2(concat$6([indent$3(concat$6([softline$2, path.call(print, "test")])), softline$2])), ")", semi);
  26717. return concat$6(parts);
  26718. }
  26719. case "DoExpression":
  26720. return concat$6(["do ", path.call(print, "body")]);
  26721. case "BreakStatement":
  26722. parts.push("break");
  26723. if (n.label) {
  26724. parts.push(" ", path.call(print, "label"));
  26725. }
  26726. parts.push(semi);
  26727. return concat$6(parts);
  26728. case "ContinueStatement":
  26729. parts.push("continue");
  26730. if (n.label) {
  26731. parts.push(" ", path.call(print, "label"));
  26732. }
  26733. parts.push(semi);
  26734. return concat$6(parts);
  26735. case "LabeledStatement":
  26736. if (n.body.type === "EmptyStatement") {
  26737. return concat$6([path.call(print, "label"), ":;"]);
  26738. }
  26739. return concat$6([path.call(print, "label"), ": ", path.call(print, "body")]);
  26740. case "TryStatement":
  26741. return concat$6(["try ", path.call(print, "block"), n.handler ? concat$6([" ", path.call(print, "handler")]) : "", n.finalizer ? concat$6([" finally ", path.call(print, "finalizer")]) : ""]);
  26742. case "CatchClause":
  26743. if (n.param) {
  26744. var hasComments = n.param.comments && n.param.comments.some(function (comment) {
  26745. return !comments$1.isBlockComment(comment) || comment.leading && hasNewline$3(options.originalText, options.locEnd(comment)) || comment.trailing && hasNewline$3(options.originalText, options.locStart(comment), {
  26746. backwards: true
  26747. });
  26748. });
  26749. var param = path.call(print, "param");
  26750. return concat$6(["catch ", hasComments ? concat$6(["(", indent$3(concat$6([softline$2, param])), softline$2, ") "]) : concat$6(["(", param, ") "]), path.call(print, "body")]);
  26751. }
  26752. return concat$6(["catch ", path.call(print, "body")]);
  26753. case "ThrowStatement":
  26754. return concat$6(["throw ", path.call(print, "argument"), semi]);
  26755. // Note: ignoring n.lexical because it has no printing consequences.
  26756. case "SwitchStatement":
  26757. return concat$6([group$2(concat$6(["switch (", indent$3(concat$6([softline$2, path.call(print, "discriminant")])), softline$2, ")"])), " {", n.cases.length > 0 ? indent$3(concat$6([hardline$4, join$4(hardline$4, path.map(function (casePath) {
  26758. var caseNode = casePath.getValue();
  26759. return concat$6([casePath.call(print), n.cases.indexOf(caseNode) !== n.cases.length - 1 && isNextLineEmpty$2(options.originalText, caseNode, options) ? hardline$4 : ""]);
  26760. }, "cases"))])) : "", hardline$4, "}"]);
  26761. case "SwitchCase":
  26762. {
  26763. if (n.test) {
  26764. parts.push("case ", path.call(print, "test"), ":");
  26765. } else {
  26766. parts.push("default:");
  26767. }
  26768. var consequent = n.consequent.filter(function (node) {
  26769. return node.type !== "EmptyStatement";
  26770. });
  26771. if (consequent.length > 0) {
  26772. var cons = path.call(function (consequentPath) {
  26773. return printStatementSequence(consequentPath, options, print);
  26774. }, "consequent");
  26775. parts.push(consequent.length === 1 && consequent[0].type === "BlockStatement" ? concat$6([" ", cons]) : indent$3(concat$6([hardline$4, cons])));
  26776. }
  26777. return concat$6(parts);
  26778. }
  26779. // JSX extensions below.
  26780. case "DebuggerStatement":
  26781. return concat$6(["debugger", semi]);
  26782. case "JSXAttribute":
  26783. parts.push(path.call(print, "name"));
  26784. if (n.value) {
  26785. var res;
  26786. if (isStringLiteral$1(n.value)) {
  26787. var raw = rawText$1(n.value); // Unescape all quotes so we get an accurate preferred quote
  26788. var final = raw.replace(/&apos;/g, "'").replace(/&quot;/g, '"');
  26789. var quote = getPreferredQuote$1(final, options.jsxSingleQuote ? "'" : '"');
  26790. var _escape = quote === "'" ? "&apos;" : "&quot;";
  26791. final = final.slice(1, -1).replace(new RegExp(quote, "g"), _escape);
  26792. res = concat$6([quote, final, quote]);
  26793. } else {
  26794. res = path.call(print, "value");
  26795. }
  26796. parts.push("=", res);
  26797. }
  26798. return concat$6(parts);
  26799. case "JSXIdentifier":
  26800. return "" + n.name;
  26801. case "JSXNamespacedName":
  26802. return join$4(":", [path.call(print, "namespace"), path.call(print, "name")]);
  26803. case "JSXMemberExpression":
  26804. return join$4(".", [path.call(print, "object"), path.call(print, "property")]);
  26805. case "TSQualifiedName":
  26806. return join$4(".", [path.call(print, "left"), path.call(print, "right")]);
  26807. case "JSXSpreadAttribute":
  26808. case "JSXSpreadChild":
  26809. {
  26810. return concat$6(["{", path.call(function (p) {
  26811. var printed = concat$6(["...", print(p)]);
  26812. var n = p.getValue();
  26813. if (!n.comments || !n.comments.length) {
  26814. return printed;
  26815. }
  26816. return concat$6([indent$3(concat$6([softline$2, comments.printComments(p, function () {
  26817. return printed;
  26818. }, options)])), softline$2]);
  26819. }, n.type === "JSXSpreadAttribute" ? "argument" : "expression"), "}"]);
  26820. }
  26821. case "JSXExpressionContainer":
  26822. {
  26823. var _parent7 = path.getParentNode(0);
  26824. var preventInline = _parent7.type === "JSXAttribute" && n.expression.comments && n.expression.comments.length > 0;
  26825. var _shouldInline = !preventInline && (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 === "JSXEmptyExpression" || n.expression.type === "TemplateLiteral" || n.expression.type === "TaggedTemplateExpression" || n.expression.type === "DoExpression" || isJSXNode$1(_parent7) && (n.expression.type === "ConditionalExpression" || isBinaryish$1(n.expression)));
  26826. if (_shouldInline) {
  26827. return group$2(concat$6(["{", path.call(print, "expression"), lineSuffixBoundary$1, "}"]));
  26828. }
  26829. return group$2(concat$6(["{", indent$3(concat$6([softline$2, path.call(print, "expression")])), softline$2, lineSuffixBoundary$1, "}"]));
  26830. }
  26831. case "JSXFragment":
  26832. case "JSXElement":
  26833. {
  26834. var elem = comments.printComments(path, function () {
  26835. return printJSXElement(path, options, print);
  26836. }, options);
  26837. return maybeWrapJSXElementInParens(path, elem, options);
  26838. }
  26839. case "JSXOpeningElement":
  26840. {
  26841. var _n = path.getValue();
  26842. var 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
  26843. if (_n.selfClosing && !_n.attributes.length && !nameHasComments) {
  26844. return concat$6(["<", path.call(print, "name"), path.call(print, "typeParameters"), " />"]);
  26845. } // don't break up opening elements with a single long text attribute
  26846. 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:
  26847. // <div
  26848. // // comment
  26849. // attr="value"
  26850. // >
  26851. // <div
  26852. // attr="value"
  26853. // // comment
  26854. // >
  26855. !nameHasComments && (!_n.attributes[0].comments || !_n.attributes[0].comments.length)) {
  26856. return group$2(concat$6(["<", path.call(print, "name"), path.call(print, "typeParameters"), " ", concat$6(path.map(print, "attributes")), _n.selfClosing ? " />" : ">"]));
  26857. }
  26858. var lastAttrHasTrailingComments = _n.attributes.length && hasTrailingComment$1(getLast$2(_n.attributes));
  26859. var bracketSameLine = // Simple tags (no attributes and no comment in tag name) should be
  26860. // kept unbroken regardless of `jsxBracketSameLine`
  26861. !_n.attributes.length && !nameHasComments || options.jsxBracketSameLine && ( // We should print the bracket in a new line for the following cases:
  26862. // <div
  26863. // // comment
  26864. // >
  26865. // <div
  26866. // attr // comment
  26867. // >
  26868. !nameHasComments || _n.attributes.length) && !lastAttrHasTrailingComments; // We should print the opening element expanded if any prop value is a
  26869. // string literal with newlines
  26870. var _shouldBreak2 = _n.attributes && _n.attributes.some(function (attr) {
  26871. return attr.value && isStringLiteral$1(attr.value) && attr.value.value.includes("\n");
  26872. });
  26873. return group$2(concat$6(["<", path.call(print, "name"), path.call(print, "typeParameters"), concat$6([indent$3(concat$6(path.map(function (attr) {
  26874. return concat$6([line$2, print(attr)]);
  26875. }, "attributes"))), _n.selfClosing ? line$2 : bracketSameLine ? ">" : softline$2]), _n.selfClosing ? "/>" : bracketSameLine ? "" : ">"]), {
  26876. shouldBreak: _shouldBreak2
  26877. });
  26878. }
  26879. case "JSXClosingElement":
  26880. return concat$6(["</", path.call(print, "name"), ">"]);
  26881. case "JSXOpeningFragment":
  26882. case "JSXClosingFragment":
  26883. {
  26884. var hasComment = n.comments && n.comments.length;
  26885. var hasOwnLineComment = hasComment && !n.comments.every(comments$1.isBlockComment);
  26886. var isOpeningFragment = n.type === "JSXOpeningFragment";
  26887. return concat$6([isOpeningFragment ? "<" : "</", indent$3(concat$6([hasOwnLineComment ? hardline$4 : hasComment && !isOpeningFragment ? " " : "", comments.printDanglingComments(path, options, true)])), hasOwnLineComment ? hardline$4 : "", ">"]);
  26888. }
  26889. case "JSXText":
  26890. /* istanbul ignore next */
  26891. throw new Error("JSXTest should be handled by JSXElement");
  26892. case "JSXEmptyExpression":
  26893. {
  26894. var requiresHardline = n.comments && !n.comments.every(comments$1.isBlockComment);
  26895. return concat$6([comments.printDanglingComments(path, options,
  26896. /* sameIndent */
  26897. !requiresHardline), requiresHardline ? hardline$4 : ""]);
  26898. }
  26899. case "ClassBody":
  26900. if (!n.comments && n.body.length === 0) {
  26901. return "{}";
  26902. }
  26903. return concat$6(["{", n.body.length > 0 ? indent$3(concat$6([hardline$4, path.call(function (bodyPath) {
  26904. return printStatementSequence(bodyPath, options, print);
  26905. }, "body")])) : comments.printDanglingComments(path, options), hardline$4, "}"]);
  26906. case "ClassProperty":
  26907. case "TSAbstractClassProperty":
  26908. case "ClassPrivateProperty":
  26909. {
  26910. if (n.decorators && n.decorators.length !== 0) {
  26911. parts.push(printDecorators(path, options, print));
  26912. }
  26913. if (n.accessibility) {
  26914. parts.push(n.accessibility + " ");
  26915. }
  26916. if (n.declare) {
  26917. parts.push("declare ");
  26918. }
  26919. if (n.static) {
  26920. parts.push("static ");
  26921. }
  26922. if (n.type === "TSAbstractClassProperty") {
  26923. parts.push("abstract ");
  26924. }
  26925. if (n.readonly) {
  26926. parts.push("readonly ");
  26927. }
  26928. var variance = getFlowVariance$1(n);
  26929. if (variance) {
  26930. parts.push(variance);
  26931. }
  26932. parts.push(printPropertyKey(path, options, print), printOptionalToken(path), printTypeAnnotation(path, options, print));
  26933. if (n.value) {
  26934. parts.push(" =", printAssignmentRight(n.key, n.value, path.call(print, "value"), options));
  26935. }
  26936. parts.push(semi);
  26937. return group$2(concat$6(parts));
  26938. }
  26939. case "ClassDeclaration":
  26940. case "ClassExpression":
  26941. if (n.declare) {
  26942. parts.push("declare ");
  26943. }
  26944. parts.push(concat$6(printClass(path, options, print)));
  26945. return concat$6(parts);
  26946. case "TSInterfaceHeritage":
  26947. parts.push(path.call(print, "expression"));
  26948. if (n.typeParameters) {
  26949. parts.push(path.call(print, "typeParameters"));
  26950. }
  26951. return concat$6(parts);
  26952. case "TemplateElement":
  26953. return join$4(literalline$2, n.value.raw.split(/\r?\n/g));
  26954. case "TemplateLiteral":
  26955. {
  26956. var expressions = path.map(print, "expressions");
  26957. var _parentNode = path.getParentNode();
  26958. if (isJestEachTemplateLiteral$1(n, _parentNode)) {
  26959. var _printed2 = printJestEachTemplateLiteral(n, expressions, options);
  26960. if (_printed2) {
  26961. return _printed2;
  26962. }
  26963. }
  26964. var isSimple = isSimpleTemplateLiteral$1(n);
  26965. if (isSimple) {
  26966. expressions = expressions.map(function (doc) {
  26967. return printDocToString$2(doc, Object.assign({}, options, {
  26968. printWidth: Infinity
  26969. })).formatted;
  26970. });
  26971. }
  26972. parts.push(lineSuffixBoundary$1, "`");
  26973. path.each(function (childPath) {
  26974. var i = childPath.getName();
  26975. parts.push(print(childPath));
  26976. if (i < expressions.length) {
  26977. // For a template literal of the following form:
  26978. // `someQuery {
  26979. // ${call({
  26980. // a,
  26981. // b,
  26982. // })}
  26983. // }`
  26984. // the expression is on its own line (there is a \n in the previous
  26985. // quasi literal), therefore we want to indent the JavaScript
  26986. // expression inside at the beginning of ${ instead of the beginning
  26987. // of the `.
  26988. var tabWidth = options.tabWidth;
  26989. var quasi = childPath.getValue();
  26990. var indentSize = getIndentSize$1(quasi.value.raw, tabWidth);
  26991. var _printed3 = expressions[i];
  26992. if (!isSimple) {
  26993. // Breaks at the template element boundaries (${ and }) are preferred to breaking
  26994. // in the middle of a MemberExpression
  26995. 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") {
  26996. _printed3 = concat$6([indent$3(concat$6([softline$2, _printed3])), softline$2]);
  26997. }
  26998. }
  26999. var aligned = indentSize === 0 && quasi.value.raw.endsWith("\n") ? align$1(-Infinity, _printed3) : addAlignmentToDoc$2(_printed3, indentSize, tabWidth);
  27000. parts.push(group$2(concat$6(["${", aligned, lineSuffixBoundary$1, "}"])));
  27001. }
  27002. }, "quasis");
  27003. parts.push("`");
  27004. return concat$6(parts);
  27005. }
  27006. // These types are unprintable because they serve as abstract
  27007. // supertypes for other (printable) types.
  27008. case "TaggedTemplateExpression":
  27009. return concat$6([path.call(print, "tag"), path.call(print, "typeParameters"), path.call(print, "quasi")]);
  27010. case "Node":
  27011. case "Printable":
  27012. case "SourceLocation":
  27013. case "Position":
  27014. case "Statement":
  27015. case "Function":
  27016. case "Pattern":
  27017. case "Expression":
  27018. case "Declaration":
  27019. case "Specifier":
  27020. case "NamedSpecifier":
  27021. case "Comment":
  27022. case "MemberTypeAnnotation": // Flow
  27023. case "Type":
  27024. /* istanbul ignore next */
  27025. throw new Error("unprintable type: " + JSON.stringify(n.type));
  27026. // Type Annotations for Facebook Flow, typically stripped out or
  27027. // transformed away before printing.
  27028. case "TypeAnnotation":
  27029. case "TSTypeAnnotation":
  27030. if (n.typeAnnotation) {
  27031. return path.call(print, "typeAnnotation");
  27032. }
  27033. /* istanbul ignore next */
  27034. return "";
  27035. case "TSTupleType":
  27036. case "TupleTypeAnnotation":
  27037. {
  27038. var typesField = n.type === "TSTupleType" ? "elementTypes" : "types";
  27039. return group$2(concat$6(["[", indent$3(concat$6([softline$2, printArrayItems(path, options, typesField, print)])), ifBreak$1(shouldPrintComma(options, "all") ? "," : ""), comments.printDanglingComments(path, options,
  27040. /* sameIndent */
  27041. true), softline$2, "]"]));
  27042. }
  27043. case "ExistsTypeAnnotation":
  27044. return "*";
  27045. case "EmptyTypeAnnotation":
  27046. return "empty";
  27047. case "AnyTypeAnnotation":
  27048. return "any";
  27049. case "MixedTypeAnnotation":
  27050. return "mixed";
  27051. case "ArrayTypeAnnotation":
  27052. return concat$6([path.call(print, "elementType"), "[]"]);
  27053. case "BooleanTypeAnnotation":
  27054. return "boolean";
  27055. case "BooleanLiteralTypeAnnotation":
  27056. return "" + n.value;
  27057. case "DeclareClass":
  27058. return printFlowDeclaration(path, printClass(path, options, print));
  27059. case "TSDeclareFunction":
  27060. // For TypeScript the TSDeclareFunction node shares the AST
  27061. // structure with FunctionDeclaration
  27062. return concat$6([n.declare ? "declare " : "", printFunctionDeclaration(path, print, options), semi]);
  27063. case "DeclareFunction":
  27064. return printFlowDeclaration(path, ["function ", path.call(print, "id"), n.predicate ? " " : "", path.call(print, "predicate"), semi]);
  27065. case "DeclareModule":
  27066. return printFlowDeclaration(path, ["module ", path.call(print, "id"), " ", path.call(print, "body")]);
  27067. case "DeclareModuleExports":
  27068. return printFlowDeclaration(path, ["module.exports", ": ", path.call(print, "typeAnnotation"), semi]);
  27069. case "DeclareVariable":
  27070. return printFlowDeclaration(path, ["var ", path.call(print, "id"), semi]);
  27071. case "DeclareExportAllDeclaration":
  27072. return concat$6(["declare export * from ", path.call(print, "source")]);
  27073. case "DeclareExportDeclaration":
  27074. return concat$6(["declare ", printExportDeclaration(path, options, print)]);
  27075. case "DeclareOpaqueType":
  27076. case "OpaqueType":
  27077. {
  27078. parts.push("opaque type ", path.call(print, "id"), path.call(print, "typeParameters"));
  27079. if (n.supertype) {
  27080. parts.push(": ", path.call(print, "supertype"));
  27081. }
  27082. if (n.impltype) {
  27083. parts.push(" = ", path.call(print, "impltype"));
  27084. }
  27085. parts.push(semi);
  27086. if (n.type === "DeclareOpaqueType") {
  27087. return printFlowDeclaration(path, parts);
  27088. }
  27089. return concat$6(parts);
  27090. }
  27091. case "EnumDeclaration":
  27092. return concat$6(["enum ", path.call(print, "id"), " ", path.call(print, "body")]);
  27093. case "EnumBooleanBody":
  27094. case "EnumNumberBody":
  27095. case "EnumStringBody":
  27096. case "EnumSymbolBody":
  27097. {
  27098. if (n.type === "EnumSymbolBody" || n.explicitType) {
  27099. var type = null;
  27100. switch (n.type) {
  27101. case "EnumBooleanBody":
  27102. type = "boolean";
  27103. break;
  27104. case "EnumNumberBody":
  27105. type = "number";
  27106. break;
  27107. case "EnumStringBody":
  27108. type = "string";
  27109. break;
  27110. case "EnumSymbolBody":
  27111. type = "symbol";
  27112. break;
  27113. }
  27114. parts.push("of ", type, " ");
  27115. }
  27116. if (n.members.length === 0) {
  27117. parts.push(group$2(concat$6(["{", comments.printDanglingComments(path, options), softline$2, "}"])));
  27118. } else {
  27119. parts.push(group$2(concat$6(["{", indent$3(concat$6([hardline$4, printArrayItems(path, options, "members", print), shouldPrintComma(options) ? "," : ""])), comments.printDanglingComments(path, options,
  27120. /* sameIndent */
  27121. true), hardline$4, "}"])));
  27122. }
  27123. return concat$6(parts);
  27124. }
  27125. case "EnumBooleanMember":
  27126. case "EnumNumberMember":
  27127. case "EnumStringMember":
  27128. return concat$6([path.call(print, "id"), " = ", typeof n.init === "object" ? path.call(print, "init") : String(n.init)]);
  27129. case "EnumDefaultedMember":
  27130. return path.call(print, "id");
  27131. case "FunctionTypeAnnotation":
  27132. case "TSFunctionType":
  27133. {
  27134. // FunctionTypeAnnotation is ambiguous:
  27135. // declare function foo(a: B): void; OR
  27136. // var A: (a: B) => void;
  27137. var _parent8 = path.getParentNode(0);
  27138. var _parentParent2 = path.getParentNode(1);
  27139. var _parentParentParent = path.getParentNode(2);
  27140. var isArrowFunctionTypeAnnotation = n.type === "TSFunctionType" || !((_parent8.type === "ObjectTypeProperty" || _parent8.type === "ObjectTypeInternalSlot") && !getFlowVariance$1(_parent8) && !_parent8.optional && options.locStart(_parent8) === options.locStart(n) || _parent8.type === "ObjectTypeCallProperty" || _parentParentParent && _parentParentParent.type === "DeclareFunction");
  27141. var needsColon = isArrowFunctionTypeAnnotation && (_parent8.type === "TypeAnnotation" || _parent8.type === "TSTypeAnnotation"); // Sadly we can't put it inside of FastPath::needsColon because we are
  27142. // printing ":" as part of the expression and it would put parenthesis
  27143. // around :(
  27144. var needsParens = needsColon && isArrowFunctionTypeAnnotation && (_parent8.type === "TypeAnnotation" || _parent8.type === "TSTypeAnnotation") && _parentParent2.type === "ArrowFunctionExpression";
  27145. if (isObjectTypePropertyAFunction$1(_parent8, options)) {
  27146. isArrowFunctionTypeAnnotation = true;
  27147. needsColon = true;
  27148. }
  27149. if (needsParens) {
  27150. parts.push("(");
  27151. }
  27152. parts.push(printFunctionParams(path, print, options,
  27153. /* expandArg */
  27154. false,
  27155. /* printTypeParams */
  27156. true)); // The returnType is not wrapped in a TypeAnnotation, so the colon
  27157. // needs to be added separately.
  27158. if (n.returnType || n.predicate || n.typeAnnotation) {
  27159. parts.push(isArrowFunctionTypeAnnotation ? " => " : ": ", path.call(print, "returnType"), path.call(print, "predicate"), path.call(print, "typeAnnotation"));
  27160. }
  27161. if (needsParens) {
  27162. parts.push(")");
  27163. }
  27164. return group$2(concat$6(parts));
  27165. }
  27166. case "TSRestType":
  27167. return concat$6(["...", path.call(print, "typeAnnotation")]);
  27168. case "TSOptionalType":
  27169. return concat$6([path.call(print, "typeAnnotation"), "?"]);
  27170. case "FunctionTypeParam":
  27171. return concat$6([path.call(print, "name"), printOptionalToken(path), n.name ? ": " : "", path.call(print, "typeAnnotation")]);
  27172. case "GenericTypeAnnotation":
  27173. return concat$6([path.call(print, "id"), path.call(print, "typeParameters")]);
  27174. case "DeclareInterface":
  27175. case "InterfaceDeclaration":
  27176. case "InterfaceTypeAnnotation":
  27177. {
  27178. if (n.type === "DeclareInterface" || n.declare) {
  27179. parts.push("declare ");
  27180. }
  27181. parts.push("interface");
  27182. if (n.type === "DeclareInterface" || n.type === "InterfaceDeclaration") {
  27183. parts.push(" ", path.call(print, "id"), path.call(print, "typeParameters"));
  27184. }
  27185. if (n["extends"].length > 0) {
  27186. parts.push(group$2(indent$3(concat$6([line$2, "extends ", (n.extends.length === 1 ? identity$1 : indent$3)(join$4(concat$6([",", line$2]), path.map(print, "extends")))]))));
  27187. }
  27188. parts.push(" ", path.call(print, "body"));
  27189. return group$2(concat$6(parts));
  27190. }
  27191. case "ClassImplements":
  27192. case "InterfaceExtends":
  27193. return concat$6([path.call(print, "id"), path.call(print, "typeParameters")]);
  27194. case "TSClassImplements":
  27195. return concat$6([path.call(print, "expression"), path.call(print, "typeParameters")]);
  27196. case "TSIntersectionType":
  27197. case "IntersectionTypeAnnotation":
  27198. {
  27199. var types = path.map(print, "types");
  27200. var result = [];
  27201. var wasIndented = false;
  27202. for (var _i = 0; _i < types.length; ++_i) {
  27203. if (_i === 0) {
  27204. result.push(types[_i]);
  27205. } else if (isObjectType$1(n.types[_i - 1]) && isObjectType$1(n.types[_i])) {
  27206. // If both are objects, don't indent
  27207. result.push(concat$6([" & ", wasIndented ? indent$3(types[_i]) : types[_i]]));
  27208. } else if (!isObjectType$1(n.types[_i - 1]) && !isObjectType$1(n.types[_i])) {
  27209. // If no object is involved, go to the next line if it breaks
  27210. result.push(indent$3(concat$6([" &", line$2, types[_i]])));
  27211. } else {
  27212. // If you go from object to non-object or vis-versa, then inline it
  27213. if (_i > 1) {
  27214. wasIndented = true;
  27215. }
  27216. result.push(" & ", _i > 1 ? indent$3(types[_i]) : types[_i]);
  27217. }
  27218. }
  27219. return group$2(concat$6(result));
  27220. }
  27221. case "TSUnionType":
  27222. case "UnionTypeAnnotation":
  27223. {
  27224. // single-line variation
  27225. // A | B | C
  27226. // multi-line variation
  27227. // | A
  27228. // | B
  27229. // | C
  27230. var _parent9 = path.getParentNode(); // If there's a leading comment, the parent is doing the indentation
  27231. var shouldIndent = _parent9.type !== "TypeParameterInstantiation" && _parent9.type !== "TSTypeParameterInstantiation" && _parent9.type !== "GenericTypeAnnotation" && _parent9.type !== "TSTypeReference" && _parent9.type !== "TSTypeAssertion" && _parent9.type !== "TupleTypeAnnotation" && _parent9.type !== "TSTupleType" && !(_parent9.type === "FunctionTypeParam" && !_parent9.name) && !((_parent9.type === "TypeAlias" || _parent9.type === "VariableDeclarator" || _parent9.type === "TSTypeAliasDeclaration") && hasLeadingOwnLineComment$1(options.originalText, n, options)); // {
  27232. // a: string
  27233. // } | null | void
  27234. // should be inlined and not be printed in the multi-line variant
  27235. var shouldHug = shouldHugType(n); // We want to align the children but without its comment, so it looks like
  27236. // | child1
  27237. // // comment
  27238. // | child2
  27239. var _printed4 = path.map(function (typePath) {
  27240. var printedType = typePath.call(print);
  27241. if (!shouldHug) {
  27242. printedType = align$1(2, printedType);
  27243. }
  27244. return comments.printComments(typePath, function () {
  27245. return printedType;
  27246. }, options);
  27247. }, "types");
  27248. if (shouldHug) {
  27249. return join$4(" | ", _printed4);
  27250. }
  27251. var shouldAddStartLine = shouldIndent && !hasLeadingOwnLineComment$1(options.originalText, n, options);
  27252. var code = concat$6([ifBreak$1(concat$6([shouldAddStartLine ? line$2 : "", "| "])), join$4(concat$6([line$2, "| "]), _printed4)]);
  27253. if (needsParens_1(path, options)) {
  27254. return group$2(concat$6([indent$3(code), softline$2]));
  27255. }
  27256. if (_parent9.type === "TupleTypeAnnotation" && _parent9.types.length > 1 || _parent9.type === "TSTupleType" && _parent9.elementTypes.length > 1) {
  27257. return group$2(concat$6([indent$3(concat$6([ifBreak$1(concat$6(["(", softline$2])), code])), softline$2, ifBreak$1(")")]));
  27258. }
  27259. return group$2(shouldIndent ? indent$3(code) : code);
  27260. }
  27261. case "NullableTypeAnnotation":
  27262. return concat$6(["?", path.call(print, "typeAnnotation")]);
  27263. case "TSNullKeyword":
  27264. case "NullLiteralTypeAnnotation":
  27265. return "null";
  27266. case "ThisTypeAnnotation":
  27267. return "this";
  27268. case "NumberTypeAnnotation":
  27269. return "number";
  27270. case "ObjectTypeCallProperty":
  27271. if (n.static) {
  27272. parts.push("static ");
  27273. }
  27274. parts.push(path.call(print, "value"));
  27275. return concat$6(parts);
  27276. case "ObjectTypeIndexer":
  27277. {
  27278. var _variance = getFlowVariance$1(n);
  27279. return concat$6([_variance || "", "[", path.call(print, "id"), n.id ? ": " : "", path.call(print, "key"), "]: ", path.call(print, "value")]);
  27280. }
  27281. case "ObjectTypeProperty":
  27282. {
  27283. var _variance2 = getFlowVariance$1(n);
  27284. var modifier = "";
  27285. if (n.proto) {
  27286. modifier = "proto ";
  27287. } else if (n.static) {
  27288. modifier = "static ";
  27289. }
  27290. return concat$6([modifier, isGetterOrSetter$1(n) ? n.kind + " " : "", _variance2 || "", printPropertyKey(path, options, print), printOptionalToken(path), isFunctionNotation$1(n, options) ? "" : ": ", path.call(print, "value")]);
  27291. }
  27292. case "QualifiedTypeIdentifier":
  27293. return concat$6([path.call(print, "qualification"), ".", path.call(print, "id")]);
  27294. case "StringLiteralTypeAnnotation":
  27295. return nodeStr(n, options);
  27296. case "NumberLiteralTypeAnnotation":
  27297. assert$1.strictEqual(typeof n.value, "number");
  27298. if (n.extra != null) {
  27299. return printNumber$1(n.extra.raw);
  27300. }
  27301. return printNumber$1(n.raw);
  27302. case "StringTypeAnnotation":
  27303. return "string";
  27304. case "DeclareTypeAlias":
  27305. case "TypeAlias":
  27306. {
  27307. if (n.type === "DeclareTypeAlias" || n.declare) {
  27308. parts.push("declare ");
  27309. }
  27310. var _printed5 = printAssignmentRight(n.id, n.right, path.call(print, "right"), options);
  27311. parts.push("type ", path.call(print, "id"), path.call(print, "typeParameters"), " =", _printed5, semi);
  27312. return group$2(concat$6(parts));
  27313. }
  27314. case "TypeCastExpression":
  27315. {
  27316. var value = path.getValue(); // Flow supports a comment syntax for specifying type annotations: https://flow.org/en/docs/types/comments/.
  27317. // Unfortunately, its parser doesn't differentiate between comment annotations and regular
  27318. // annotations when producing an AST. So to preserve parentheses around type casts that use
  27319. // the comment syntax, we need to hackily read the source itself to see if the code contains
  27320. // a type annotation comment.
  27321. //
  27322. // Note that we're able to use the normal whitespace regex here because the Flow parser has
  27323. // already deemed this AST node to be a type cast. Only the Babel parser needs the
  27324. // non-line-break whitespace regex, which is why hasFlowShorthandAnnotationComment() is
  27325. // implemented differently.
  27326. var commentSyntax = value && value.typeAnnotation && value.typeAnnotation.range && options.originalText.substring(value.typeAnnotation.range[0]).match(/^\/\*\s*:/);
  27327. return concat$6(["(", path.call(print, "expression"), commentSyntax ? " /*" : "", ": ", path.call(print, "typeAnnotation"), commentSyntax ? " */" : "", ")"]);
  27328. }
  27329. case "TypeParameterDeclaration":
  27330. case "TypeParameterInstantiation":
  27331. {
  27332. var _value = path.getValue();
  27333. var commentStart = _value.range ? options.originalText.substring(0, _value.range[0]).lastIndexOf("/*") : -1; // As noted in the TypeCastExpression comments above, we're able to use a normal whitespace regex here
  27334. // because we know for sure that this is a type definition.
  27335. var _commentSyntax = commentStart >= 0 && options.originalText.substring(commentStart).match(/^\/\*\s*::/);
  27336. if (_commentSyntax) {
  27337. return concat$6(["/*:: ", printTypeParameters(path, options, print, "params"), " */"]);
  27338. }
  27339. return printTypeParameters(path, options, print, "params");
  27340. }
  27341. case "TSTypeParameterDeclaration":
  27342. case "TSTypeParameterInstantiation":
  27343. return printTypeParameters(path, options, print, "params");
  27344. case "TSTypeParameter":
  27345. case "TypeParameter":
  27346. {
  27347. var _parent10 = path.getParentNode();
  27348. if (_parent10.type === "TSMappedType") {
  27349. parts.push("[", path.call(print, "name"));
  27350. if (n.constraint) {
  27351. parts.push(" in ", path.call(print, "constraint"));
  27352. }
  27353. parts.push("]");
  27354. return concat$6(parts);
  27355. }
  27356. var _variance3 = getFlowVariance$1(n);
  27357. if (_variance3) {
  27358. parts.push(_variance3);
  27359. }
  27360. parts.push(path.call(print, "name"));
  27361. if (n.bound) {
  27362. parts.push(": ");
  27363. parts.push(path.call(print, "bound"));
  27364. }
  27365. if (n.constraint) {
  27366. parts.push(" extends ", path.call(print, "constraint"));
  27367. }
  27368. if (n["default"]) {
  27369. parts.push(" = ", path.call(print, "default"));
  27370. } // Keep comma if the file extension is .tsx and
  27371. // has one type parameter that isn't extend with any types.
  27372. // Because, otherwise formatted result will be invalid as tsx.
  27373. var _grandParent = path.getNode(2);
  27374. if (_parent10.params && _parent10.params.length === 1 && isTSXFile$1(options) && !n.constraint && _grandParent.type === "ArrowFunctionExpression") {
  27375. parts.push(",");
  27376. }
  27377. return concat$6(parts);
  27378. }
  27379. case "TypeofTypeAnnotation":
  27380. return concat$6(["typeof ", path.call(print, "argument")]);
  27381. case "VoidTypeAnnotation":
  27382. return "void";
  27383. case "InferredPredicate":
  27384. return "%checks";
  27385. // Unhandled types below. If encountered, nodes of these types should
  27386. // be either left alone or desugared into AST types that are fully
  27387. // supported by the pretty-printer.
  27388. case "DeclaredPredicate":
  27389. return concat$6(["%checks(", path.call(print, "value"), ")"]);
  27390. case "TSAbstractKeyword":
  27391. return "abstract";
  27392. case "TSAnyKeyword":
  27393. return "any";
  27394. case "TSAsyncKeyword":
  27395. return "async";
  27396. case "TSBooleanKeyword":
  27397. return "boolean";
  27398. case "TSBigIntKeyword":
  27399. return "bigint";
  27400. case "TSConstKeyword":
  27401. return "const";
  27402. case "TSDeclareKeyword":
  27403. return "declare";
  27404. case "TSExportKeyword":
  27405. return "export";
  27406. case "TSNeverKeyword":
  27407. return "never";
  27408. case "TSNumberKeyword":
  27409. return "number";
  27410. case "TSObjectKeyword":
  27411. return "object";
  27412. case "TSProtectedKeyword":
  27413. return "protected";
  27414. case "TSPrivateKeyword":
  27415. return "private";
  27416. case "TSPublicKeyword":
  27417. return "public";
  27418. case "TSReadonlyKeyword":
  27419. return "readonly";
  27420. case "TSSymbolKeyword":
  27421. return "symbol";
  27422. case "TSStaticKeyword":
  27423. return "static";
  27424. case "TSStringKeyword":
  27425. return "string";
  27426. case "TSUndefinedKeyword":
  27427. return "undefined";
  27428. case "TSUnknownKeyword":
  27429. return "unknown";
  27430. case "TSVoidKeyword":
  27431. return "void";
  27432. case "TSAsExpression":
  27433. return concat$6([path.call(print, "expression"), " as ", path.call(print, "typeAnnotation")]);
  27434. case "TSArrayType":
  27435. return concat$6([path.call(print, "elementType"), "[]"]);
  27436. case "TSPropertySignature":
  27437. {
  27438. if (n.export) {
  27439. parts.push("export ");
  27440. }
  27441. if (n.accessibility) {
  27442. parts.push(n.accessibility + " ");
  27443. }
  27444. if (n.static) {
  27445. parts.push("static ");
  27446. }
  27447. if (n.readonly) {
  27448. parts.push("readonly ");
  27449. }
  27450. parts.push(printPropertyKey(path, options, print), printOptionalToken(path));
  27451. if (n.typeAnnotation) {
  27452. parts.push(": ");
  27453. parts.push(path.call(print, "typeAnnotation"));
  27454. } // This isn't valid semantically, but it's in the AST so we can print it.
  27455. if (n.initializer) {
  27456. parts.push(" = ", path.call(print, "initializer"));
  27457. }
  27458. return concat$6(parts);
  27459. }
  27460. case "TSParameterProperty":
  27461. if (n.accessibility) {
  27462. parts.push(n.accessibility + " ");
  27463. }
  27464. if (n.export) {
  27465. parts.push("export ");
  27466. }
  27467. if (n.static) {
  27468. parts.push("static ");
  27469. }
  27470. if (n.readonly) {
  27471. parts.push("readonly ");
  27472. }
  27473. parts.push(path.call(print, "parameter"));
  27474. return concat$6(parts);
  27475. case "TSTypeReference":
  27476. return concat$6([path.call(print, "typeName"), printTypeParameters(path, options, print, "typeParameters")]);
  27477. case "TSTypeQuery":
  27478. return concat$6(["typeof ", path.call(print, "exprName")]);
  27479. case "TSIndexSignature":
  27480. {
  27481. var _parent11 = path.getParentNode();
  27482. return concat$6([n.export ? "export " : "", n.accessibility ? concat$6([n.accessibility, " "]) : "", n.static ? "static " : "", n.readonly ? "readonly " : "", "[", n.parameters ? concat$6(path.map(print, "parameters")) : "", "]: ", path.call(print, "typeAnnotation"), _parent11.type === "ClassBody" ? semi : ""]);
  27483. }
  27484. case "TSTypePredicate":
  27485. return concat$6([n.asserts ? "asserts " : "", path.call(print, "parameterName"), n.typeAnnotation ? concat$6([" is ", path.call(print, "typeAnnotation")]) : ""]);
  27486. case "TSNonNullExpression":
  27487. return concat$6([path.call(print, "expression"), "!"]);
  27488. case "TSThisType":
  27489. return "this";
  27490. case "TSImportType":
  27491. return concat$6([!n.isTypeOf ? "" : "typeof ", "import(", path.call(print, "parameter"), ")", !n.qualifier ? "" : concat$6([".", path.call(print, "qualifier")]), printTypeParameters(path, options, print, "typeParameters")]);
  27492. case "TSLiteralType":
  27493. return path.call(print, "literal");
  27494. case "TSIndexedAccessType":
  27495. return concat$6([path.call(print, "objectType"), "[", path.call(print, "indexType"), "]"]);
  27496. case "TSConstructSignatureDeclaration":
  27497. case "TSCallSignatureDeclaration":
  27498. case "TSConstructorType":
  27499. {
  27500. if (n.type !== "TSCallSignatureDeclaration") {
  27501. parts.push("new ");
  27502. }
  27503. parts.push(group$2(printFunctionParams(path, print, options,
  27504. /* expandArg */
  27505. false,
  27506. /* printTypeParams */
  27507. true)));
  27508. if (n.returnType) {
  27509. var isType = n.type === "TSConstructorType";
  27510. parts.push(isType ? " => " : ": ", path.call(print, "returnType"));
  27511. }
  27512. return concat$6(parts);
  27513. }
  27514. case "TSTypeOperator":
  27515. return concat$6([n.operator, " ", path.call(print, "typeAnnotation")]);
  27516. case "TSMappedType":
  27517. {
  27518. var _shouldBreak3 = hasNewlineInRange$2(options.originalText, options.locStart(n), options.locEnd(n));
  27519. return group$2(concat$6(["{", indent$3(concat$6([options.bracketSpacing ? line$2 : softline$2, n.readonly ? concat$6([getTypeScriptMappedTypeModifier$1(n.readonly, "readonly"), " "]) : "", printTypeScriptModifiers(path, options, print), path.call(print, "typeParameter"), n.optional ? getTypeScriptMappedTypeModifier$1(n.optional, "?") : "", ": ", path.call(print, "typeAnnotation"), ifBreak$1(semi, "")])), comments.printDanglingComments(path, options,
  27520. /* sameIndent */
  27521. true), options.bracketSpacing ? line$2 : softline$2, "}"]), {
  27522. shouldBreak: _shouldBreak3
  27523. });
  27524. }
  27525. case "TSMethodSignature":
  27526. parts.push(n.accessibility ? concat$6([n.accessibility, " "]) : "", n.export ? "export " : "", n.static ? "static " : "", n.readonly ? "readonly " : "", n.computed ? "[" : "", path.call(print, "key"), n.computed ? "]" : "", printOptionalToken(path), printFunctionParams(path, print, options,
  27527. /* expandArg */
  27528. false,
  27529. /* printTypeParams */
  27530. true));
  27531. if (n.returnType) {
  27532. parts.push(": ", path.call(print, "returnType"));
  27533. }
  27534. return group$2(concat$6(parts));
  27535. case "TSNamespaceExportDeclaration":
  27536. parts.push("export as namespace ", path.call(print, "id"));
  27537. if (options.semi) {
  27538. parts.push(";");
  27539. }
  27540. return group$2(concat$6(parts));
  27541. case "TSEnumDeclaration":
  27542. if (n.declare) {
  27543. parts.push("declare ");
  27544. }
  27545. if (n.modifiers) {
  27546. parts.push(printTypeScriptModifiers(path, options, print));
  27547. }
  27548. if (n.const) {
  27549. parts.push("const ");
  27550. }
  27551. parts.push("enum ", path.call(print, "id"), " ");
  27552. if (n.members.length === 0) {
  27553. parts.push(group$2(concat$6(["{", comments.printDanglingComments(path, options), softline$2, "}"])));
  27554. } else {
  27555. parts.push(group$2(concat$6(["{", indent$3(concat$6([hardline$4, printArrayItems(path, options, "members", print), shouldPrintComma(options, "es5") ? "," : ""])), comments.printDanglingComments(path, options,
  27556. /* sameIndent */
  27557. true), hardline$4, "}"])));
  27558. }
  27559. return concat$6(parts);
  27560. case "TSEnumMember":
  27561. parts.push(path.call(print, "id"));
  27562. if (n.initializer) {
  27563. parts.push(" = ", path.call(print, "initializer"));
  27564. }
  27565. return concat$6(parts);
  27566. case "TSImportEqualsDeclaration":
  27567. if (n.isExport) {
  27568. parts.push("export ");
  27569. }
  27570. parts.push("import ", path.call(print, "id"), " = ", path.call(print, "moduleReference"));
  27571. if (options.semi) {
  27572. parts.push(";");
  27573. }
  27574. return group$2(concat$6(parts));
  27575. case "TSExternalModuleReference":
  27576. return concat$6(["require(", path.call(print, "expression"), ")"]);
  27577. case "TSModuleDeclaration":
  27578. {
  27579. var _parent12 = path.getParentNode();
  27580. var isExternalModule = isLiteral$1(n.id);
  27581. var parentIsDeclaration = _parent12.type === "TSModuleDeclaration";
  27582. var bodyIsDeclaration = n.body && n.body.type === "TSModuleDeclaration";
  27583. if (parentIsDeclaration) {
  27584. parts.push(".");
  27585. } else {
  27586. if (n.declare) {
  27587. parts.push("declare ");
  27588. }
  27589. parts.push(printTypeScriptModifiers(path, options, print));
  27590. var textBetweenNodeAndItsId = options.originalText.slice(options.locStart(n), options.locStart(n.id)); // Global declaration looks like this:
  27591. // (declare)? global { ... }
  27592. var isGlobalDeclaration = n.id.type === "Identifier" && n.id.name === "global" && !/namespace|module/.test(textBetweenNodeAndItsId);
  27593. if (!isGlobalDeclaration) {
  27594. parts.push(isExternalModule || /(^|\s)module(\s|$)/.test(textBetweenNodeAndItsId) ? "module " : "namespace ");
  27595. }
  27596. }
  27597. parts.push(path.call(print, "id"));
  27598. if (bodyIsDeclaration) {
  27599. parts.push(path.call(print, "body"));
  27600. } else if (n.body) {
  27601. parts.push(" ", group$2(path.call(print, "body")));
  27602. } else {
  27603. parts.push(semi);
  27604. }
  27605. return concat$6(parts);
  27606. }
  27607. case "PrivateName":
  27608. return concat$6(["#", path.call(print, "id")]);
  27609. case "TSConditionalType":
  27610. return printTernaryOperator(path, options, print, {
  27611. beforeParts: function beforeParts() {
  27612. return [path.call(print, "checkType"), " ", "extends", " ", path.call(print, "extendsType")];
  27613. },
  27614. afterParts: function afterParts() {
  27615. return [];
  27616. },
  27617. shouldCheckJsx: false,
  27618. conditionalNodeType: "TSConditionalType",
  27619. consequentNodePropertyName: "trueType",
  27620. alternateNodePropertyName: "falseType",
  27621. testNodePropertyName: "checkType",
  27622. breakNested: true
  27623. });
  27624. case "TSInferType":
  27625. return concat$6(["infer", " ", path.call(print, "typeParameter")]);
  27626. case "InterpreterDirective":
  27627. parts.push("#!", n.value, hardline$4);
  27628. if (isNextLineEmpty$2(options.originalText, n, options)) {
  27629. parts.push(hardline$4);
  27630. }
  27631. return concat$6(parts);
  27632. case "NGRoot":
  27633. return concat$6([].concat(path.call(print, "node"), !n.node.comments || n.node.comments.length === 0 ? [] : concat$6([" //", n.node.comments[0].value.trimRight()])));
  27634. case "NGChainedExpression":
  27635. return group$2(join$4(concat$6([";", line$2]), path.map(function (childPath) {
  27636. return hasNgSideEffect$1(childPath) ? print(childPath) : concat$6(["(", print(childPath), ")"]);
  27637. }, "expressions")));
  27638. case "NGEmptyExpression":
  27639. return "";
  27640. case "NGQuotedExpression":
  27641. return concat$6([n.prefix, ":", n.value]);
  27642. case "NGMicrosyntax":
  27643. return concat$6(path.map(function (childPath, index) {
  27644. return concat$6([index === 0 ? "" : isNgForOf$1(childPath.getValue(), index, n) ? " " : concat$6([";", line$2]), print(childPath)]);
  27645. }, "body"));
  27646. case "NGMicrosyntaxKey":
  27647. return /^[a-z_$][a-z0-9_$]*(-[a-z_$][a-z0-9_$])*$/i.test(n.name) ? n.name : JSON.stringify(n.name);
  27648. case "NGMicrosyntaxExpression":
  27649. return concat$6([path.call(print, "expression"), n.alias === null ? "" : concat$6([" as ", path.call(print, "alias")])]);
  27650. case "NGMicrosyntaxKeyedExpression":
  27651. {
  27652. var index = path.getName();
  27653. var _parentNode2 = path.getParentNode();
  27654. var shouldNotPrintColon = isNgForOf$1(n, index, _parentNode2) || (index === 1 && (n.key.name === "then" || n.key.name === "else") || index === 2 && n.key.name === "else" && _parentNode2.body[index - 1].type === "NGMicrosyntaxKeyedExpression" && _parentNode2.body[index - 1].key.name === "then") && _parentNode2.body[0].type === "NGMicrosyntaxExpression";
  27655. return concat$6([path.call(print, "key"), shouldNotPrintColon ? " " : ": ", path.call(print, "expression")]);
  27656. }
  27657. case "NGMicrosyntaxLet":
  27658. return concat$6(["let ", path.call(print, "key"), n.value === null ? "" : concat$6([" = ", path.call(print, "value")])]);
  27659. case "NGMicrosyntaxAs":
  27660. return concat$6([path.call(print, "key"), " as ", path.call(print, "alias")]);
  27661. case "ArgumentPlaceholder":
  27662. return "?";
  27663. default:
  27664. /* istanbul ignore next */
  27665. throw new Error("unknown type: " + JSON.stringify(n.type));
  27666. }
  27667. }
  27668. function printStatementSequence(path, options, print) {
  27669. var printed = [];
  27670. var bodyNode = path.getNode();
  27671. var isClass = bodyNode.type === "ClassBody";
  27672. path.map(function (stmtPath, i) {
  27673. var stmt = stmtPath.getValue(); // Just in case the AST has been modified to contain falsy
  27674. // "statements," it's safer simply to skip them.
  27675. /* istanbul ignore if */
  27676. if (!stmt) {
  27677. return;
  27678. } // Skip printing EmptyStatement nodes to avoid leaving stray
  27679. // semicolons lying around.
  27680. if (stmt.type === "EmptyStatement") {
  27681. return;
  27682. }
  27683. var stmtPrinted = print(stmtPath);
  27684. var text = options.originalText;
  27685. var parts = []; // in no-semi mode, prepend statement with semicolon if it might break ASI
  27686. // don't prepend the only JSX element in a program with semicolon
  27687. if (!options.semi && !isClass && !isTheOnlyJSXElementInMarkdown$1(options, stmtPath) && stmtNeedsASIProtection(stmtPath, options)) {
  27688. if (stmt.comments && stmt.comments.some(function (comment) {
  27689. return comment.leading;
  27690. })) {
  27691. parts.push(print(stmtPath, {
  27692. needsSemi: true
  27693. }));
  27694. } else {
  27695. parts.push(";", stmtPrinted);
  27696. }
  27697. } else {
  27698. parts.push(stmtPrinted);
  27699. }
  27700. if (!options.semi && isClass) {
  27701. if (classPropMayCauseASIProblems$1(stmtPath)) {
  27702. parts.push(";");
  27703. } else if (stmt.type === "ClassProperty") {
  27704. var nextChild = bodyNode.body[i + 1];
  27705. if (classChildNeedsASIProtection$1(nextChild)) {
  27706. parts.push(";");
  27707. }
  27708. }
  27709. }
  27710. if (isNextLineEmpty$2(text, stmt, options) && !isLastStatement$1(stmtPath)) {
  27711. parts.push(hardline$4);
  27712. }
  27713. printed.push(concat$6(parts));
  27714. });
  27715. return join$4(hardline$4, printed);
  27716. }
  27717. function printPropertyKey(path, options, print) {
  27718. var node = path.getNode();
  27719. if (node.computed) {
  27720. return concat$6(["[", path.call(print, "key"), "]"]);
  27721. }
  27722. var parent = path.getParentNode();
  27723. var key = node.key;
  27724. if (options.quoteProps === "consistent" && !needsQuoteProps.has(parent)) {
  27725. var objectHasStringProp = (parent.properties || parent.body || parent.members).some(function (prop) {
  27726. return !prop.computed && prop.key && isStringLiteral$1(prop.key) && !isStringPropSafeToCoerceToIdentifier$1(prop, options);
  27727. });
  27728. needsQuoteProps.set(parent, objectHasStringProp);
  27729. }
  27730. if (key.type === "Identifier" && (options.parser === "json" || options.quoteProps === "consistent" && needsQuoteProps.get(parent))) {
  27731. // a -> "a"
  27732. var prop = printString$1(JSON.stringify(key.name), options);
  27733. return path.call(function (keyPath) {
  27734. return comments.printComments(keyPath, function () {
  27735. return prop;
  27736. }, options);
  27737. }, "key");
  27738. }
  27739. if (isStringPropSafeToCoerceToIdentifier$1(node, options) && (options.quoteProps === "as-needed" || options.quoteProps === "consistent" && !needsQuoteProps.get(parent))) {
  27740. // 'a' -> a
  27741. return path.call(function (keyPath) {
  27742. return comments.printComments(keyPath, function () {
  27743. return key.value;
  27744. }, options);
  27745. }, "key");
  27746. }
  27747. return path.call(print, "key");
  27748. }
  27749. function printMethod(path, options, print) {
  27750. var node = path.getNode();
  27751. var kind = node.kind;
  27752. var value = node.value || node;
  27753. var parts = [];
  27754. if (!kind || kind === "init" || kind === "method" || kind === "constructor") {
  27755. if (value.async) {
  27756. parts.push("async ");
  27757. }
  27758. if (value.generator) {
  27759. parts.push("*");
  27760. }
  27761. } else {
  27762. assert$1.ok(kind === "get" || kind === "set");
  27763. parts.push(kind, " ");
  27764. }
  27765. parts.push(printPropertyKey(path, options, print), node.optional || node.key.optional ? "?" : "", node === value ? printMethodInternal(path, options, print) : path.call(function (path) {
  27766. return printMethodInternal(path, options, print);
  27767. }, "value"));
  27768. return concat$6(parts);
  27769. }
  27770. function printMethodInternal(path, options, print) {
  27771. var parts = [printFunctionTypeParameters(path, options, print), group$2(concat$6([printFunctionParams(path, print, options), printReturnType(path, print, options)]))];
  27772. if (path.getNode().body) {
  27773. parts.push(" ", path.call(print, "body"));
  27774. } else {
  27775. parts.push(options.semi ? ";" : "");
  27776. }
  27777. return concat$6(parts);
  27778. }
  27779. function couldGroupArg(arg) {
  27780. 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
  27781. // https://github.com/prettier/prettier/issues/4070
  27782. // export class Thing implements OtherThing {
  27783. // do: (type: Type) => Provider<Prop> = memoize(
  27784. // (type: ObjectType): Provider<Opts> => {}
  27785. // );
  27786. // }
  27787. // https://github.com/prettier/prettier/issues/6099
  27788. // app.get("/", (req, res): void => {
  27789. // res.send("Hello World!");
  27790. // });
  27791. !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));
  27792. }
  27793. function shouldGroupLastArg(args) {
  27794. var lastArg = getLast$2(args);
  27795. var penultimateArg = getPenultimate$1(args);
  27796. return !hasLeadingComment$3(lastArg) && !hasTrailingComment$1(lastArg) && couldGroupArg(lastArg) && ( // If the last two arguments are of the same type,
  27797. // disable last element expansion.
  27798. !penultimateArg || penultimateArg.type !== lastArg.type);
  27799. }
  27800. function shouldGroupFirstArg(args) {
  27801. if (args.length !== 2) {
  27802. return false;
  27803. }
  27804. var firstArg = args[0];
  27805. var secondArg = args[1];
  27806. 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);
  27807. }
  27808. function printJestEachTemplateLiteral(node, expressions, options) {
  27809. /**
  27810. * a | b | expected
  27811. * ${1} | ${1} | ${2}
  27812. * ${1} | ${2} | ${3}
  27813. * ${2} | ${1} | ${3}
  27814. */
  27815. var headerNames = node.quasis[0].value.raw.trim().split(/\s*\|\s*/);
  27816. if (headerNames.length > 1 || headerNames.some(function (headerName) {
  27817. return headerName.length !== 0;
  27818. })) {
  27819. var parts = [];
  27820. var stringifiedExpressions = expressions.map(function (doc) {
  27821. return "${" + printDocToString$2(doc, Object.assign({}, options, {
  27822. printWidth: Infinity,
  27823. endOfLine: "lf"
  27824. })).formatted + "}";
  27825. });
  27826. var tableBody = [{
  27827. hasLineBreak: false,
  27828. cells: []
  27829. }];
  27830. for (var i = 1; i < node.quasis.length; i++) {
  27831. var row = tableBody[tableBody.length - 1];
  27832. var correspondingExpression = stringifiedExpressions[i - 1];
  27833. row.cells.push(correspondingExpression);
  27834. if (correspondingExpression.indexOf("\n") !== -1) {
  27835. row.hasLineBreak = true;
  27836. }
  27837. if (node.quasis[i].value.raw.indexOf("\n") !== -1) {
  27838. tableBody.push({
  27839. hasLineBreak: false,
  27840. cells: []
  27841. });
  27842. }
  27843. }
  27844. var maxColumnCount = tableBody.reduce(function (maxColumnCount, row) {
  27845. return Math.max(maxColumnCount, row.cells.length);
  27846. }, headerNames.length);
  27847. var maxColumnWidths = Array.from(new Array(maxColumnCount), function () {
  27848. return 0;
  27849. });
  27850. var table = [{
  27851. cells: headerNames
  27852. }].concat(tableBody.filter(function (row) {
  27853. return row.cells.length !== 0;
  27854. }));
  27855. table.filter(function (row) {
  27856. return !row.hasLineBreak;
  27857. }).forEach(function (row) {
  27858. row.cells.forEach(function (cell, index) {
  27859. maxColumnWidths[index] = Math.max(maxColumnWidths[index], getStringWidth$2(cell));
  27860. });
  27861. });
  27862. parts.push(lineSuffixBoundary$1, "`", indent$3(concat$6([hardline$4, join$4(hardline$4, table.map(function (row) {
  27863. return join$4(" | ", row.cells.map(function (cell, index) {
  27864. return row.hasLineBreak ? cell : cell + " ".repeat(maxColumnWidths[index] - getStringWidth$2(cell));
  27865. }));
  27866. }))])), hardline$4, "`");
  27867. return concat$6(parts);
  27868. }
  27869. }
  27870. function printArgumentsList(path, options, print) {
  27871. var node = path.getValue();
  27872. var args = node.arguments;
  27873. if (args.length === 0) {
  27874. return concat$6(["(", comments.printDanglingComments(path, options,
  27875. /* sameIndent */
  27876. true), ")"]);
  27877. } // useEffect(() => { ... }, [foo, bar, baz])
  27878. if (args.length === 2 && args[0].type === "ArrowFunctionExpression" && args[0].params.length === 0 && args[0].body.type === "BlockStatement" && args[1].type === "ArrayExpression" && !args.find(function (arg) {
  27879. return arg.comments;
  27880. })) {
  27881. return concat$6(["(", path.call(print, "arguments", 0), ", ", path.call(print, "arguments", 1), ")"]);
  27882. } // func(
  27883. // ({
  27884. // a,
  27885. // b
  27886. // }) => {}
  27887. // );
  27888. function shouldBreakForArrowFunctionInArguments(arg, argPath) {
  27889. if (!arg || arg.type !== "ArrowFunctionExpression" || !arg.body || arg.body.type !== "BlockStatement" || !arg.params || arg.params.length < 1) {
  27890. return false;
  27891. }
  27892. var shouldBreak = false;
  27893. argPath.each(function (paramPath) {
  27894. var printed = concat$6([print(paramPath)]);
  27895. shouldBreak = shouldBreak || willBreak$1(printed);
  27896. }, "params");
  27897. return shouldBreak;
  27898. }
  27899. var anyArgEmptyLine = false;
  27900. var shouldBreakForArrowFunction = false;
  27901. var hasEmptyLineFollowingFirstArg = false;
  27902. var lastArgIndex = args.length - 1;
  27903. var printedArguments = path.map(function (argPath, index) {
  27904. var arg = argPath.getNode();
  27905. var parts = [print(argPath)];
  27906. if (index === lastArgIndex) ; else if (isNextLineEmpty$2(options.originalText, arg, options)) {
  27907. if (index === 0) {
  27908. hasEmptyLineFollowingFirstArg = true;
  27909. }
  27910. anyArgEmptyLine = true;
  27911. parts.push(",", hardline$4, hardline$4);
  27912. } else {
  27913. parts.push(",", line$2);
  27914. }
  27915. shouldBreakForArrowFunction = shouldBreakForArrowFunctionInArguments(arg, argPath);
  27916. return concat$6(parts);
  27917. }, "arguments");
  27918. var maybeTrailingComma = // Dynamic imports cannot have trailing commas
  27919. !(node.callee && node.callee.type === "Import") && shouldPrintComma(options, "all") ? "," : "";
  27920. function allArgsBrokenOut() {
  27921. return group$2(concat$6(["(", indent$3(concat$6([line$2, concat$6(printedArguments)])), maybeTrailingComma, line$2, ")"]), {
  27922. shouldBreak: true
  27923. });
  27924. }
  27925. if (isFunctionCompositionArgs$1(args)) {
  27926. return allArgsBrokenOut();
  27927. }
  27928. var shouldGroupFirst = shouldGroupFirstArg(args);
  27929. var shouldGroupLast = shouldGroupLastArg(args);
  27930. if (shouldGroupFirst || shouldGroupLast) {
  27931. var 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
  27932. var printedExpanded;
  27933. var i = 0;
  27934. path.each(function (argPath) {
  27935. if (shouldGroupFirst && i === 0) {
  27936. printedExpanded = [concat$6([argPath.call(function (p) {
  27937. return print(p, {
  27938. expandFirstArg: true
  27939. });
  27940. }), printedArguments.length > 1 ? "," : "", hasEmptyLineFollowingFirstArg ? hardline$4 : line$2, hasEmptyLineFollowingFirstArg ? hardline$4 : ""])].concat(printedArguments.slice(1));
  27941. }
  27942. if (shouldGroupLast && i === args.length - 1) {
  27943. printedExpanded = printedArguments.slice(0, -1).concat(argPath.call(function (p) {
  27944. return print(p, {
  27945. expandLastArg: true
  27946. });
  27947. }));
  27948. }
  27949. i++;
  27950. }, "arguments");
  27951. var somePrintedArgumentsWillBreak = printedArguments.some(willBreak$1);
  27952. var simpleConcat = concat$6(["(", concat$6(printedExpanded), ")"]);
  27953. return concat$6([somePrintedArgumentsWillBreak ? breakParent$2 : "", conditionalGroup$1([!somePrintedArgumentsWillBreak && !node.typeArguments && !node.typeParameters ? simpleConcat : ifBreak$1(allArgsBrokenOut(), simpleConcat), shouldGroupFirst ? concat$6(["(", group$2(printedExpanded[0], {
  27954. shouldBreak: true
  27955. }), concat$6(printedExpanded.slice(1)), ")"]) : concat$6(["(", concat$6(printedArguments.slice(0, -1)), group$2(getLast$2(printedExpanded), {
  27956. shouldBreak: true
  27957. }), ")"]), allArgsBrokenOut()], {
  27958. shouldBreak
  27959. })]);
  27960. }
  27961. var contents = concat$6(["(", indent$3(concat$6([softline$2, concat$6(printedArguments)])), ifBreak$1(maybeTrailingComma), softline$2, ")"]);
  27962. if (isLongCurriedCallExpression$1(path)) {
  27963. // By not wrapping the arguments in a group, the printer prioritizes
  27964. // breaking up these arguments rather than the args of the parent call.
  27965. return contents;
  27966. }
  27967. return group$2(contents, {
  27968. shouldBreak: printedArguments.some(willBreak$1) || anyArgEmptyLine
  27969. });
  27970. }
  27971. function printTypeAnnotation(path, options, print) {
  27972. var node = path.getValue();
  27973. if (!node.typeAnnotation) {
  27974. return "";
  27975. }
  27976. var parentNode = path.getParentNode();
  27977. var isDefinite = node.definite || parentNode && parentNode.type === "VariableDeclarator" && parentNode.definite;
  27978. var isFunctionDeclarationIdentifier = parentNode.type === "DeclareFunction" && parentNode.id === node;
  27979. if (isFlowAnnotationComment$1(options.originalText, node.typeAnnotation, options)) {
  27980. return concat$6([" /*: ", path.call(print, "typeAnnotation"), " */"]);
  27981. }
  27982. return concat$6([isFunctionDeclarationIdentifier ? "" : isDefinite ? "!: " : ": ", path.call(print, "typeAnnotation")]);
  27983. }
  27984. function printFunctionTypeParameters(path, options, print) {
  27985. var fun = path.getValue();
  27986. if (fun.typeArguments) {
  27987. return path.call(print, "typeArguments");
  27988. }
  27989. if (fun.typeParameters) {
  27990. return path.call(print, "typeParameters");
  27991. }
  27992. return "";
  27993. }
  27994. function printFunctionParams(path, print, options, expandArg, printTypeParams) {
  27995. var fun = path.getValue();
  27996. var parent = path.getParentNode();
  27997. var paramsField = fun.parameters ? "parameters" : "params";
  27998. var isParametersInTestCall = isTestCall$1(parent);
  27999. var shouldHugParameters = shouldHugArguments(fun);
  28000. var shouldExpandParameters = expandArg && !(fun[paramsField] && fun[paramsField].some(function (n) {
  28001. return n.comments;
  28002. }));
  28003. var typeParams = printTypeParams ? printFunctionTypeParameters(path, options, print) : "";
  28004. var printed = [];
  28005. if (fun[paramsField]) {
  28006. var lastArgIndex = fun[paramsField].length - 1;
  28007. printed = path.map(function (childPath, index) {
  28008. var parts = [];
  28009. var param = childPath.getValue();
  28010. parts.push(print(childPath));
  28011. if (index === lastArgIndex) {
  28012. if (fun.rest) {
  28013. parts.push(",", line$2);
  28014. }
  28015. } else if (isParametersInTestCall || shouldHugParameters || shouldExpandParameters) {
  28016. parts.push(", ");
  28017. } else if (isNextLineEmpty$2(options.originalText, param, options)) {
  28018. parts.push(",", hardline$4, hardline$4);
  28019. } else {
  28020. parts.push(",", line$2);
  28021. }
  28022. return concat$6(parts);
  28023. }, paramsField);
  28024. }
  28025. if (fun.rest) {
  28026. printed.push(concat$6(["...", path.call(print, "rest")]));
  28027. }
  28028. if (printed.length === 0) {
  28029. return concat$6([typeParams, "(", comments.printDanglingComments(path, options,
  28030. /* sameIndent */
  28031. true, function (comment) {
  28032. return getNextNonSpaceNonCommentCharacter$1(options.originalText, comment, options.locEnd) === ")";
  28033. }), ")"]);
  28034. }
  28035. var lastParam = getLast$2(fun[paramsField]); // If the parent is a call with the first/last argument expansion and this is the
  28036. // params of the first/last argument, we don't want the arguments to break and instead
  28037. // want the whole expression to be on a new line.
  28038. //
  28039. // Good: Bad:
  28040. // verylongcall( verylongcall((
  28041. // (a, b) => { a,
  28042. // } b,
  28043. // }) ) => {
  28044. // })
  28045. if (shouldExpandParameters) {
  28046. return group$2(concat$6([removeLines$1(typeParams), "(", concat$6(printed.map(removeLines$1)), ")"]));
  28047. } // Single object destructuring should hug
  28048. //
  28049. // function({
  28050. // a,
  28051. // b,
  28052. // c
  28053. // }) {}
  28054. var hasNotParameterDecorator = fun[paramsField].every(function (param) {
  28055. return !param.decorators;
  28056. });
  28057. if (shouldHugParameters && hasNotParameterDecorator) {
  28058. return concat$6([typeParams, "(", concat$6(printed), ")"]);
  28059. } // don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})`
  28060. if (isParametersInTestCall) {
  28061. return concat$6([typeParams, "(", concat$6(printed), ")"]);
  28062. }
  28063. var 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;
  28064. if (isFlowShorthandWithOneArg) {
  28065. if (options.arrowParens === "always") {
  28066. return concat$6(["(", concat$6(printed), ")"]);
  28067. }
  28068. return concat$6(printed);
  28069. }
  28070. var canHaveTrailingComma = !(lastParam && lastParam.type === "RestElement") && !fun.rest;
  28071. return concat$6([typeParams, "(", indent$3(concat$6([softline$2, concat$6(printed)])), ifBreak$1(canHaveTrailingComma && shouldPrintComma(options, "all") ? "," : ""), softline$2, ")"]);
  28072. }
  28073. function shouldPrintParamsWithoutParens(path, options) {
  28074. if (options.arrowParens === "always") {
  28075. return false;
  28076. }
  28077. if (options.arrowParens === "avoid") {
  28078. var node = path.getValue();
  28079. return canPrintParamsWithoutParens(node);
  28080. } // Fallback default; should be unreachable
  28081. return false;
  28082. }
  28083. function canPrintParamsWithoutParens(node) {
  28084. 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;
  28085. }
  28086. function printFunctionDeclaration(path, print, options) {
  28087. var n = path.getValue();
  28088. var parts = [];
  28089. if (n.async) {
  28090. parts.push("async ");
  28091. }
  28092. parts.push("function");
  28093. if (n.generator) {
  28094. parts.push("*");
  28095. }
  28096. if (n.id) {
  28097. parts.push(" ", path.call(print, "id"));
  28098. }
  28099. parts.push(printFunctionTypeParameters(path, options, print), group$2(concat$6([printFunctionParams(path, print, options), printReturnType(path, print, options)])), n.body ? " " : "", path.call(print, "body"));
  28100. return concat$6(parts);
  28101. }
  28102. function printReturnType(path, print, options) {
  28103. var n = path.getValue();
  28104. var returnType = path.call(print, "returnType");
  28105. if (n.returnType && isFlowAnnotationComment$1(options.originalText, n.returnType, options)) {
  28106. return concat$6([" /*: ", returnType, " */"]);
  28107. }
  28108. var parts = [returnType]; // prepend colon to TypeScript type annotation
  28109. if (n.returnType && n.returnType.typeAnnotation) {
  28110. parts.unshift(": ");
  28111. }
  28112. if (n.predicate) {
  28113. // The return type will already add the colon, but otherwise we
  28114. // need to do it ourselves
  28115. parts.push(n.returnType ? " " : ": ", path.call(print, "predicate"));
  28116. }
  28117. return concat$6(parts);
  28118. }
  28119. function printExportDeclaration(path, options, print) {
  28120. var decl = path.getValue();
  28121. var semi = options.semi ? ";" : "";
  28122. var parts = ["export "];
  28123. var isDefault = decl["default"] || decl.type === "ExportDefaultDeclaration";
  28124. if (isDefault) {
  28125. parts.push("default ");
  28126. }
  28127. parts.push(comments.printDanglingComments(path, options,
  28128. /* sameIndent */
  28129. true));
  28130. if (needsHardlineAfterDanglingComment$1(decl)) {
  28131. parts.push(hardline$4);
  28132. }
  28133. if (decl.declaration) {
  28134. parts.push(path.call(print, "declaration"));
  28135. 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") {
  28136. parts.push(semi);
  28137. }
  28138. } else {
  28139. if (decl.specifiers && decl.specifiers.length > 0) {
  28140. var specifiers = [];
  28141. var defaultSpecifiers = [];
  28142. var namespaceSpecifiers = [];
  28143. path.each(function (specifierPath) {
  28144. var specifierType = path.getValue().type;
  28145. if (specifierType === "ExportSpecifier") {
  28146. specifiers.push(print(specifierPath));
  28147. } else if (specifierType === "ExportDefaultSpecifier") {
  28148. defaultSpecifiers.push(print(specifierPath));
  28149. } else if (specifierType === "ExportNamespaceSpecifier") {
  28150. namespaceSpecifiers.push(concat$6(["* as ", print(specifierPath)]));
  28151. }
  28152. }, "specifiers");
  28153. var isNamespaceFollowed = namespaceSpecifiers.length !== 0 && specifiers.length !== 0;
  28154. var isDefaultFollowed = defaultSpecifiers.length !== 0 && (namespaceSpecifiers.length !== 0 || specifiers.length !== 0);
  28155. var canBreak = specifiers.length > 1 || defaultSpecifiers.length > 0 || decl.specifiers && decl.specifiers.some(function (node) {
  28156. return node.comments;
  28157. });
  28158. var printed = "";
  28159. if (specifiers.length !== 0) {
  28160. if (canBreak) {
  28161. printed = group$2(concat$6(["{", indent$3(concat$6([options.bracketSpacing ? line$2 : softline$2, join$4(concat$6([",", line$2]), specifiers)])), ifBreak$1(shouldPrintComma(options) ? "," : ""), options.bracketSpacing ? line$2 : softline$2, "}"]));
  28162. } else {
  28163. printed = concat$6(["{", options.bracketSpacing ? " " : "", concat$6(specifiers), options.bracketSpacing ? " " : "", "}"]);
  28164. }
  28165. }
  28166. parts.push(decl.exportKind === "type" ? "type " : "", concat$6(defaultSpecifiers), concat$6([isDefaultFollowed ? ", " : ""]), concat$6(namespaceSpecifiers), concat$6([isNamespaceFollowed ? ", " : ""]), printed);
  28167. } else {
  28168. parts.push("{}");
  28169. }
  28170. if (decl.source) {
  28171. parts.push(" from ", path.call(print, "source"));
  28172. }
  28173. parts.push(semi);
  28174. }
  28175. return concat$6(parts);
  28176. }
  28177. function printFlowDeclaration(path, parts) {
  28178. var parentExportDecl = getParentExportDeclaration$1(path);
  28179. if (parentExportDecl) {
  28180. assert$1.strictEqual(parentExportDecl.type, "DeclareExportDeclaration");
  28181. } else {
  28182. // If the parent node has type DeclareExportDeclaration, then it
  28183. // will be responsible for printing the "declare" token. Otherwise
  28184. // it needs to be printed with this non-exported declaration node.
  28185. parts.unshift("declare ");
  28186. }
  28187. return concat$6(parts);
  28188. }
  28189. function printTypeScriptModifiers(path, options, print) {
  28190. var n = path.getValue();
  28191. if (!n.modifiers || !n.modifiers.length) {
  28192. return "";
  28193. }
  28194. return concat$6([join$4(" ", path.map(print, "modifiers")), " "]);
  28195. }
  28196. function printTypeParameters(path, options, print, paramsKey) {
  28197. var n = path.getValue();
  28198. if (!n[paramsKey]) {
  28199. return "";
  28200. } // for TypeParameterDeclaration typeParameters is a single node
  28201. if (!Array.isArray(n[paramsKey])) {
  28202. return path.call(print, paramsKey);
  28203. }
  28204. var grandparent = path.getNode(2);
  28205. var greatGreatGrandParent = path.getNode(4);
  28206. var isParameterInTestCall = grandparent != null && isTestCall$1(grandparent);
  28207. var 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.
  28208. greatGreatGrandParent && greatGreatGrandParent.type === "VariableDeclarator" && grandparent && grandparent.type === "TSTypeAnnotation" && n[paramsKey][0].type !== "TSUnionType" && n[paramsKey][0].type !== "UnionTypeAnnotation" && n[paramsKey][0].type !== "TSConditionalType" && n[paramsKey][0].type !== "TSMappedType");
  28209. if (shouldInline) {
  28210. return concat$6(["<", join$4(", ", path.map(print, paramsKey)), ">"]);
  28211. }
  28212. return group$2(concat$6(["<", indent$3(concat$6([softline$2, join$4(concat$6([",", line$2]), path.map(print, paramsKey))])), ifBreak$1(options.parser !== "typescript" && shouldPrintComma(options, "all") ? "," : ""), softline$2, ">"]));
  28213. }
  28214. function printClass(path, options, print) {
  28215. var n = path.getValue();
  28216. var parts = [];
  28217. if (n.abstract) {
  28218. parts.push("abstract ");
  28219. }
  28220. parts.push("class");
  28221. if (n.id) {
  28222. parts.push(" ", path.call(print, "id"));
  28223. }
  28224. parts.push(path.call(print, "typeParameters"));
  28225. var partsGroup = [];
  28226. if (n.superClass) {
  28227. var printed = concat$6(["extends ", path.call(print, "superClass"), path.call(print, "superTypeParameters")]); // Keep old behaviour of extends in same line
  28228. // If there is only on extends and there are not comments
  28229. if ((!n.implements || n.implements.length === 0) && (!n.superClass.comments || n.superClass.comments.length === 0)) {
  28230. parts.push(concat$6([" ", path.call(function (superClass) {
  28231. return comments.printComments(superClass, function () {
  28232. return printed;
  28233. }, options);
  28234. }, "superClass")]));
  28235. } else {
  28236. partsGroup.push(group$2(concat$6([line$2, path.call(function (superClass) {
  28237. return comments.printComments(superClass, function () {
  28238. return printed;
  28239. }, options);
  28240. }, "superClass")])));
  28241. }
  28242. } else if (n.extends && n.extends.length > 0) {
  28243. parts.push(" extends ", join$4(", ", path.map(print, "extends")));
  28244. }
  28245. if (n["mixins"] && n["mixins"].length > 0) {
  28246. partsGroup.push(line$2, "mixins ", group$2(indent$3(join$4(concat$6([",", line$2]), path.map(print, "mixins")))));
  28247. }
  28248. if (n["implements"] && n["implements"].length > 0) {
  28249. partsGroup.push(line$2, "implements", group$2(indent$3(concat$6([line$2, join$4(concat$6([",", line$2]), path.map(print, "implements"))]))));
  28250. }
  28251. if (partsGroup.length > 0) {
  28252. parts.push(group$2(indent$3(concat$6(partsGroup))));
  28253. }
  28254. if (n.body && n.body.comments && hasLeadingOwnLineComment$1(options.originalText, n.body, options)) {
  28255. parts.push(hardline$4);
  28256. } else {
  28257. parts.push(" ");
  28258. }
  28259. parts.push(path.call(print, "body"));
  28260. return parts;
  28261. }
  28262. function printOptionalToken(path) {
  28263. var node = path.getValue();
  28264. if (!node.optional || // It's an optional computed method parsed by typescript-estree.
  28265. // "?" is printed in `printMethod`.
  28266. node.type === "Identifier" && node === path.getParentNode().key) {
  28267. return "";
  28268. }
  28269. if (node.type === "OptionalCallExpression" || node.type === "OptionalMemberExpression" && node.computed) {
  28270. return "?.";
  28271. }
  28272. return "?";
  28273. }
  28274. function printMemberLookup(path, options, print) {
  28275. var property = path.call(print, "property");
  28276. var n = path.getValue();
  28277. var optional = printOptionalToken(path);
  28278. if (!n.computed) {
  28279. return concat$6([optional, ".", property]);
  28280. }
  28281. if (!n.property || isNumericLiteral$1(n.property)) {
  28282. return concat$6([optional, "[", property, "]"]);
  28283. }
  28284. return group$2(concat$6([optional, "[", indent$3(concat$6([softline$2, property])), softline$2, "]"]));
  28285. }
  28286. function printBindExpressionCallee(path, options, print) {
  28287. return concat$6(["::", path.call(print, "callee")]);
  28288. } // We detect calls on member expressions specially to format a
  28289. // common pattern better. The pattern we are looking for is this:
  28290. //
  28291. // arr
  28292. // .map(x => x + 1)
  28293. // .filter(x => x > 10)
  28294. // .some(x => x % 2)
  28295. //
  28296. // The way it is structured in the AST is via a nested sequence of
  28297. // MemberExpression and CallExpression. We need to traverse the AST
  28298. // and make groups out of it to print it in the desired way.
  28299. function printMemberChain(path, options, print) {
  28300. // The first phase is to linearize the AST by traversing it down.
  28301. //
  28302. // a().b()
  28303. // has the following AST structure:
  28304. // CallExpression(MemberExpression(CallExpression(Identifier)))
  28305. // and we transform it into
  28306. // [Identifier, CallExpression, MemberExpression, CallExpression]
  28307. var printedNodes = []; // Here we try to retain one typed empty line after each call expression or
  28308. // the first group whether it is in parentheses or not
  28309. function shouldInsertEmptyLineAfter(node) {
  28310. var originalText = options.originalText;
  28311. var nextCharIndex = getNextNonSpaceNonCommentCharacterIndex$2(originalText, node, options);
  28312. var nextChar = originalText.charAt(nextCharIndex); // if it is cut off by a parenthesis, we only account for one typed empty
  28313. // line after that parenthesis
  28314. if (nextChar == ")") {
  28315. return isNextLineEmptyAfterIndex$1(originalText, nextCharIndex + 1, options);
  28316. }
  28317. return isNextLineEmpty$2(originalText, node, options);
  28318. }
  28319. function rec(path) {
  28320. var node = path.getValue();
  28321. if ((node.type === "CallExpression" || node.type === "OptionalCallExpression") && (isMemberish$1(node.callee) || node.callee.type === "CallExpression" || node.callee.type === "OptionalCallExpression")) {
  28322. printedNodes.unshift({
  28323. node: node,
  28324. printed: concat$6([comments.printComments(path, function () {
  28325. return concat$6([printOptionalToken(path), printFunctionTypeParameters(path, options, print), printArgumentsList(path, options, print)]);
  28326. }, options), shouldInsertEmptyLineAfter(node) ? hardline$4 : ""])
  28327. });
  28328. path.call(function (callee) {
  28329. return rec(callee);
  28330. }, "callee");
  28331. } else if (isMemberish$1(node)) {
  28332. printedNodes.unshift({
  28333. node: node,
  28334. needsParens: needsParens_1(path, options),
  28335. printed: comments.printComments(path, function () {
  28336. return node.type === "OptionalMemberExpression" || node.type === "MemberExpression" ? printMemberLookup(path, options, print) : printBindExpressionCallee(path, options, print);
  28337. }, options)
  28338. });
  28339. path.call(function (object) {
  28340. return rec(object);
  28341. }, "object");
  28342. } else if (node.type === "TSNonNullExpression") {
  28343. printedNodes.unshift({
  28344. node: node,
  28345. printed: comments.printComments(path, function () {
  28346. return "!";
  28347. }, options)
  28348. });
  28349. path.call(function (expression) {
  28350. return rec(expression);
  28351. }, "expression");
  28352. } else {
  28353. printedNodes.unshift({
  28354. node: node,
  28355. printed: path.call(print)
  28356. });
  28357. }
  28358. } // Note: the comments of the root node have already been printed, so we
  28359. // need to extract this first call without printing them as they would
  28360. // if handled inside of the recursive call.
  28361. var node = path.getValue();
  28362. printedNodes.unshift({
  28363. node,
  28364. printed: concat$6([printOptionalToken(path), printFunctionTypeParameters(path, options, print), printArgumentsList(path, options, print)])
  28365. });
  28366. path.call(function (callee) {
  28367. return rec(callee);
  28368. }, "callee"); // Once we have a linear list of printed nodes, we want to create groups out
  28369. // of it.
  28370. //
  28371. // a().b.c().d().e
  28372. // will be grouped as
  28373. // [
  28374. // [Identifier, CallExpression],
  28375. // [MemberExpression, MemberExpression, CallExpression],
  28376. // [MemberExpression, CallExpression],
  28377. // [MemberExpression],
  28378. // ]
  28379. // so that we can print it as
  28380. // a()
  28381. // .b.c()
  28382. // .d()
  28383. // .e
  28384. // The first group is the first node followed by
  28385. // - as many CallExpression as possible
  28386. // < fn()()() >.something()
  28387. // - as many array accessors as possible
  28388. // < fn()[0][1][2] >.something()
  28389. // - then, as many MemberExpression as possible but the last one
  28390. // < this.items >.something()
  28391. var groups = [];
  28392. var currentGroup = [printedNodes[0]];
  28393. var i = 1;
  28394. for (; i < printedNodes.length; ++i) {
  28395. if (printedNodes[i].node.type === "TSNonNullExpression" || printedNodes[i].node.type === "OptionalCallExpression" || printedNodes[i].node.type === "CallExpression" || (printedNodes[i].node.type === "MemberExpression" || printedNodes[i].node.type === "OptionalMemberExpression") && printedNodes[i].node.computed && isNumericLiteral$1(printedNodes[i].node.property)) {
  28396. currentGroup.push(printedNodes[i]);
  28397. } else {
  28398. break;
  28399. }
  28400. }
  28401. if (printedNodes[0].node.type !== "CallExpression" && printedNodes[0].node.type !== "OptionalCallExpression") {
  28402. for (; i + 1 < printedNodes.length; ++i) {
  28403. if (isMemberish$1(printedNodes[i].node) && isMemberish$1(printedNodes[i + 1].node)) {
  28404. currentGroup.push(printedNodes[i]);
  28405. } else {
  28406. break;
  28407. }
  28408. }
  28409. }
  28410. groups.push(currentGroup);
  28411. currentGroup = []; // Then, each following group is a sequence of MemberExpression followed by
  28412. // a sequence of CallExpression. To compute it, we keep adding things to the
  28413. // group until we has seen a CallExpression in the past and reach a
  28414. // MemberExpression
  28415. var hasSeenCallExpression = false;
  28416. for (; i < printedNodes.length; ++i) {
  28417. if (hasSeenCallExpression && isMemberish$1(printedNodes[i].node)) {
  28418. // [0] should be appended at the end of the group instead of the
  28419. // beginning of the next one
  28420. if (printedNodes[i].node.computed && isNumericLiteral$1(printedNodes[i].node.property)) {
  28421. currentGroup.push(printedNodes[i]);
  28422. continue;
  28423. }
  28424. groups.push(currentGroup);
  28425. currentGroup = [];
  28426. hasSeenCallExpression = false;
  28427. }
  28428. if (printedNodes[i].node.type === "CallExpression" || printedNodes[i].node.type === "OptionalCallExpression") {
  28429. hasSeenCallExpression = true;
  28430. }
  28431. currentGroup.push(printedNodes[i]);
  28432. if (printedNodes[i].node.comments && printedNodes[i].node.comments.some(function (comment) {
  28433. return comment.trailing;
  28434. })) {
  28435. groups.push(currentGroup);
  28436. currentGroup = [];
  28437. hasSeenCallExpression = false;
  28438. }
  28439. }
  28440. if (currentGroup.length > 0) {
  28441. groups.push(currentGroup);
  28442. } // There are cases like Object.keys(), Observable.of(), _.values() where
  28443. // they are the subject of all the chained calls and therefore should
  28444. // be kept on the same line:
  28445. //
  28446. // Object.keys(items)
  28447. // .filter(x => x)
  28448. // .map(x => x)
  28449. //
  28450. // In order to detect those cases, we use an heuristic: if the first
  28451. // node is an identifier with the name starting with a capital
  28452. // letter or just a sequence of _$. The rationale is that they are
  28453. // likely to be factories.
  28454. function isFactory(name) {
  28455. return /^[A-Z]|^[_$]+$/.test(name);
  28456. } // In case the Identifier is shorter than tab width, we can keep the
  28457. // first call in a single line, if it's an ExpressionStatement.
  28458. //
  28459. // d3.scaleLinear()
  28460. // .domain([0, 100])
  28461. // .range([0, width]);
  28462. //
  28463. function isShort(name) {
  28464. return name.length <= options.tabWidth;
  28465. }
  28466. function shouldNotWrap(groups) {
  28467. var parent = path.getParentNode();
  28468. var isExpression = parent && parent.type === "ExpressionStatement";
  28469. var hasComputed = groups[1].length && groups[1][0].node.computed;
  28470. if (groups[0].length === 1) {
  28471. var firstNode = groups[0][0].node;
  28472. return firstNode.type === "ThisExpression" || firstNode.type === "Identifier" && (isFactory(firstNode.name) || isExpression && isShort(firstNode.name) || hasComputed);
  28473. }
  28474. var lastNode = getLast$2(groups[0]).node;
  28475. return (lastNode.type === "MemberExpression" || lastNode.type === "OptionalMemberExpression") && lastNode.property.type === "Identifier" && (isFactory(lastNode.property.name) || hasComputed);
  28476. }
  28477. var shouldMerge = groups.length >= 2 && !groups[1][0].node.comments && shouldNotWrap(groups);
  28478. function printGroup(printedGroup) {
  28479. var printed = printedGroup.map(function (tuple) {
  28480. return tuple.printed;
  28481. }); // Checks if the last node (i.e. the parent node) needs parens and print
  28482. // accordingly
  28483. if (printedGroup.length > 0 && printedGroup[printedGroup.length - 1].needsParens) {
  28484. return concat$6(["("].concat(_toConsumableArray$1(printed), [")"]));
  28485. }
  28486. return concat$6(printed);
  28487. }
  28488. function printIndentedGroup(groups) {
  28489. if (groups.length === 0) {
  28490. return "";
  28491. }
  28492. return indent$3(group$2(concat$6([hardline$4, join$4(hardline$4, groups.map(printGroup))])));
  28493. }
  28494. var printedGroups = groups.map(printGroup);
  28495. var oneLine = concat$6(printedGroups);
  28496. var cutoff = shouldMerge ? 3 : 2;
  28497. var flatGroups = groups.slice(0, cutoff).reduce(function (res, group) {
  28498. return res.concat(group);
  28499. }, []);
  28500. var hasComment = flatGroups.slice(1, -1).some(function (node) {
  28501. return hasLeadingComment$3(node.node);
  28502. }) || flatGroups.slice(0, -1).some(function (node) {
  28503. return hasTrailingComment$1(node.node);
  28504. }) || groups[cutoff] && hasLeadingComment$3(groups[cutoff][0].node); // If we only have a single `.`, we shouldn't do anything fancy and just
  28505. // render everything concatenated together.
  28506. if (groups.length <= cutoff && !hasComment) {
  28507. if (isLongCurriedCallExpression$1(path)) {
  28508. return oneLine;
  28509. }
  28510. return group$2(oneLine);
  28511. } // Find out the last node in the first group and check if it has an
  28512. // empty line after
  28513. var lastNodeBeforeIndent = getLast$2(shouldMerge ? groups.slice(1, 2)[0] : groups[0]).node;
  28514. var shouldHaveEmptyLineBeforeIndent = lastNodeBeforeIndent.type !== "CallExpression" && lastNodeBeforeIndent.type !== "OptionalCallExpression" && shouldInsertEmptyLineAfter(lastNodeBeforeIndent);
  28515. var expanded = concat$6([printGroup(groups[0]), shouldMerge ? concat$6(groups.slice(1, 2).map(printGroup)) : "", shouldHaveEmptyLineBeforeIndent ? hardline$4 : "", printIndentedGroup(groups.slice(shouldMerge ? 2 : 1))]);
  28516. var callExpressions = printedNodes.map(function (_ref) {
  28517. var node = _ref.node;
  28518. return node;
  28519. }).filter(isCallOrOptionalCallExpression$1); // We don't want to print in one line if there's:
  28520. // * A comment.
  28521. // * 3 or more chained calls.
  28522. // * Any group but the last one has a hard line.
  28523. // If the last group is a function it's okay to inline if it fits.
  28524. if (hasComment || callExpressions.length >= 3 || printedGroups.slice(0, -1).some(willBreak$1) ||
  28525. /**
  28526. * scopes.filter(scope => scope.value !== '').map((scope, i) => {
  28527. * // multi line content
  28528. * })
  28529. */
  28530. function (lastGroupDoc, lastGroupNode) {
  28531. return isCallOrOptionalCallExpression$1(lastGroupNode) && willBreak$1(lastGroupDoc);
  28532. }(getLast$2(printedGroups), getLast$2(getLast$2(groups)).node) && callExpressions.slice(0, -1).some(function (n) {
  28533. return n.arguments.some(isFunctionOrArrowExpression$1);
  28534. })) {
  28535. return group$2(expanded);
  28536. }
  28537. return concat$6([// We only need to check `oneLine` because if `expanded` is chosen
  28538. // that means that the parent group has already been broken
  28539. // naturally
  28540. willBreak$1(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent$2 : "", conditionalGroup$1([oneLine, expanded])]);
  28541. }
  28542. function separatorNoWhitespace(isFacebookTranslationTag, child, childNode, nextNode) {
  28543. if (isFacebookTranslationTag) {
  28544. return "";
  28545. }
  28546. if (childNode.type === "JSXElement" && !childNode.closingElement || nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement) {
  28547. return child.length === 1 ? softline$2 : hardline$4;
  28548. }
  28549. return softline$2;
  28550. }
  28551. function separatorWithWhitespace(isFacebookTranslationTag, child, childNode, nextNode) {
  28552. if (isFacebookTranslationTag) {
  28553. return hardline$4;
  28554. }
  28555. if (child.length === 1) {
  28556. return childNode.type === "JSXElement" && !childNode.closingElement || nextNode && nextNode.type === "JSXElement" && !nextNode.closingElement ? hardline$4 : softline$2;
  28557. }
  28558. return hardline$4;
  28559. } // JSX Children are strange, mostly for two reasons:
  28560. // 1. JSX reads newlines into string values, instead of skipping them like JS
  28561. // 2. up to one whitespace between elements within a line is significant,
  28562. // but not between lines.
  28563. //
  28564. // Leading, trailing, and lone whitespace all need to
  28565. // turn themselves into the rather ugly `{' '}` when breaking.
  28566. //
  28567. // We print JSX using the `fill` doc primitive.
  28568. // This requires that we give it an array of alternating
  28569. // content and whitespace elements.
  28570. // To ensure this we add dummy `""` content elements as needed.
  28571. function printJSXChildren(path, options, print, jsxWhitespace, isFacebookTranslationTag) {
  28572. var n = path.getValue();
  28573. var children = []; // using `map` instead of `each` because it provides `i`
  28574. path.map(function (childPath, i) {
  28575. var child = childPath.getValue();
  28576. if (isLiteral$1(child)) {
  28577. var text = rawText$1(child); // Contains a non-whitespace character
  28578. if (isMeaningfulJSXText$1(child)) {
  28579. var words = text.split(matchJsxWhitespaceRegex$1); // Starts with whitespace
  28580. if (words[0] === "") {
  28581. children.push("");
  28582. words.shift();
  28583. if (/\n/.test(words[0])) {
  28584. var next = n.children[i + 1];
  28585. children.push(separatorWithWhitespace(isFacebookTranslationTag, words[1], child, next));
  28586. } else {
  28587. children.push(jsxWhitespace);
  28588. }
  28589. words.shift();
  28590. }
  28591. var endWhitespace; // Ends with whitespace
  28592. if (getLast$2(words) === "") {
  28593. words.pop();
  28594. endWhitespace = words.pop();
  28595. } // This was whitespace only without a new line.
  28596. if (words.length === 0) {
  28597. return;
  28598. }
  28599. words.forEach(function (word, i) {
  28600. if (i % 2 === 1) {
  28601. children.push(line$2);
  28602. } else {
  28603. children.push(word);
  28604. }
  28605. });
  28606. if (endWhitespace !== undefined) {
  28607. if (/\n/.test(endWhitespace)) {
  28608. var _next = n.children[i + 1];
  28609. children.push(separatorWithWhitespace(isFacebookTranslationTag, getLast$2(children), child, _next));
  28610. } else {
  28611. children.push(jsxWhitespace);
  28612. }
  28613. } else {
  28614. var _next2 = n.children[i + 1];
  28615. children.push(separatorNoWhitespace(isFacebookTranslationTag, getLast$2(children), child, _next2));
  28616. }
  28617. } else if (/\n/.test(text)) {
  28618. // Keep (up to one) blank line between tags/expressions/text.
  28619. // Note: We don't keep blank lines between text elements.
  28620. if (text.match(/\n/g).length > 1) {
  28621. children.push("");
  28622. children.push(hardline$4);
  28623. }
  28624. } else {
  28625. children.push("");
  28626. children.push(jsxWhitespace);
  28627. }
  28628. } else {
  28629. var printedChild = print(childPath);
  28630. children.push(printedChild);
  28631. var _next3 = n.children[i + 1];
  28632. var directlyFollowedByMeaningfulText = _next3 && isMeaningfulJSXText$1(_next3);
  28633. if (directlyFollowedByMeaningfulText) {
  28634. var firstWord = rawText$1(_next3).trim().split(matchJsxWhitespaceRegex$1)[0];
  28635. children.push(separatorNoWhitespace(isFacebookTranslationTag, firstWord, child, _next3));
  28636. } else {
  28637. children.push(hardline$4);
  28638. }
  28639. }
  28640. }, "children");
  28641. return children;
  28642. } // JSX expands children from the inside-out, instead of the outside-in.
  28643. // This is both to break children before attributes,
  28644. // and to ensure that when children break, their parents do as well.
  28645. //
  28646. // Any element that is written without any newlines and fits on a single line
  28647. // is left that way.
  28648. // Not only that, any user-written-line containing multiple JSX siblings
  28649. // should also be kept on one line if possible,
  28650. // so each user-written-line is wrapped in its own group.
  28651. //
  28652. // Elements that contain newlines or don't fit on a single line (recursively)
  28653. // are fully-split, using hardline and shouldBreak: true.
  28654. //
  28655. // To support that case properly, all leading and trailing spaces
  28656. // are stripped from the list of children, and replaced with a single hardline.
  28657. function printJSXElement(path, options, print) {
  28658. var n = path.getValue();
  28659. if (n.type === "JSXElement" && isEmptyJSXElement$1(n)) {
  28660. return concat$6([path.call(print, "openingElement"), path.call(print, "closingElement")]);
  28661. }
  28662. var openingLines = n.type === "JSXElement" ? path.call(print, "openingElement") : path.call(print, "openingFragment");
  28663. var closingLines = n.type === "JSXElement" ? path.call(print, "closingElement") : path.call(print, "closingFragment");
  28664. if (n.children.length === 1 && n.children[0].type === "JSXExpressionContainer" && (n.children[0].expression.type === "TemplateLiteral" || n.children[0].expression.type === "TaggedTemplateExpression")) {
  28665. return concat$6([openingLines, concat$6(path.map(print, "children")), closingLines]);
  28666. } // Convert `{" "}` to text nodes containing a space.
  28667. // This makes it easy to turn them into `jsxWhitespace` which
  28668. // can then print as either a space or `{" "}` when breaking.
  28669. n.children = n.children.map(function (child) {
  28670. if (isJSXWhitespaceExpression$1(child)) {
  28671. return {
  28672. type: "JSXText",
  28673. value: " ",
  28674. raw: " "
  28675. };
  28676. }
  28677. return child;
  28678. });
  28679. var containsTag = n.children.filter(isJSXNode$1).length > 0;
  28680. var containsMultipleExpressions = n.children.filter(function (child) {
  28681. return child.type === "JSXExpressionContainer";
  28682. }).length > 1;
  28683. var containsMultipleAttributes = n.type === "JSXElement" && n.openingElement.attributes.length > 1; // Record any breaks. Should never go from true to false, only false to true.
  28684. var forcedBreak = willBreak$1(openingLines) || containsTag || containsMultipleAttributes || containsMultipleExpressions;
  28685. var rawJsxWhitespace = options.singleQuote ? "{' '}" : '{" "}';
  28686. var jsxWhitespace = ifBreak$1(concat$6([rawJsxWhitespace, softline$2]), " ");
  28687. var isFacebookTranslationTag = n.openingElement && n.openingElement.name && n.openingElement.name.name === "fbt";
  28688. var children = printJSXChildren(path, options, print, jsxWhitespace, isFacebookTranslationTag);
  28689. var containsText = n.children.filter(function (child) {
  28690. return isMeaningfulJSXText$1(child);
  28691. }).length > 0; // We can end up we multiple whitespace elements with empty string
  28692. // content between them.
  28693. // We need to remove empty whitespace and softlines before JSX whitespace
  28694. // to get the correct output.
  28695. for (var i = children.length - 2; i >= 0; i--) {
  28696. var isPairOfEmptyStrings = children[i] === "" && children[i + 1] === "";
  28697. var isPairOfHardlines = children[i] === hardline$4 && children[i + 1] === "" && children[i + 2] === hardline$4;
  28698. var isLineFollowedByJSXWhitespace = (children[i] === softline$2 || children[i] === hardline$4) && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  28699. var isJSXWhitespaceFollowedByLine = children[i] === jsxWhitespace && children[i + 1] === "" && (children[i + 2] === softline$2 || children[i + 2] === hardline$4);
  28700. var isDoubleJSXWhitespace = children[i] === jsxWhitespace && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  28701. var isPairOfHardOrSoftLines = children[i] === softline$2 && children[i + 1] === "" && children[i + 2] === hardline$4 || children[i] === hardline$4 && children[i + 1] === "" && children[i + 2] === softline$2;
  28702. if (isPairOfHardlines && containsText || isPairOfEmptyStrings || isLineFollowedByJSXWhitespace || isDoubleJSXWhitespace || isPairOfHardOrSoftLines) {
  28703. children.splice(i, 2);
  28704. } else if (isJSXWhitespaceFollowedByLine) {
  28705. children.splice(i + 1, 2);
  28706. }
  28707. } // Trim trailing lines (or empty strings)
  28708. while (children.length && (isLineNext$1(getLast$2(children)) || isEmpty$1(getLast$2(children)))) {
  28709. children.pop();
  28710. } // Trim leading lines (or empty strings)
  28711. while (children.length && (isLineNext$1(children[0]) || isEmpty$1(children[0])) && (isLineNext$1(children[1]) || isEmpty$1(children[1]))) {
  28712. children.shift();
  28713. children.shift();
  28714. } // Tweak how we format children if outputting this element over multiple lines.
  28715. // Also detect whether we will force this element to output over multiple lines.
  28716. var multilineChildren = [];
  28717. children.forEach(function (child, i) {
  28718. // There are a number of situations where we need to ensure we display
  28719. // whitespace as `{" "}` when outputting this element over multiple lines.
  28720. if (child === jsxWhitespace) {
  28721. if (i === 1 && children[i - 1] === "") {
  28722. if (children.length === 2) {
  28723. // Solitary whitespace
  28724. multilineChildren.push(rawJsxWhitespace);
  28725. return;
  28726. } // Leading whitespace
  28727. multilineChildren.push(concat$6([rawJsxWhitespace, hardline$4]));
  28728. return;
  28729. } else if (i === children.length - 1) {
  28730. // Trailing whitespace
  28731. multilineChildren.push(rawJsxWhitespace);
  28732. return;
  28733. } else if (children[i - 1] === "" && children[i - 2] === hardline$4) {
  28734. // Whitespace after line break
  28735. multilineChildren.push(rawJsxWhitespace);
  28736. return;
  28737. }
  28738. }
  28739. multilineChildren.push(child);
  28740. if (willBreak$1(child)) {
  28741. forcedBreak = true;
  28742. }
  28743. }); // If there is text we use `fill` to fit as much onto each line as possible.
  28744. // When there is no text (just tags and expressions) we use `group`
  28745. // to output each on a separate line.
  28746. var content = containsText ? fill$2(multilineChildren) : group$2(concat$6(multilineChildren), {
  28747. shouldBreak: true
  28748. });
  28749. var multiLineElem = group$2(concat$6([openingLines, indent$3(concat$6([hardline$4, content])), hardline$4, closingLines]));
  28750. if (forcedBreak) {
  28751. return multiLineElem;
  28752. }
  28753. return conditionalGroup$1([group$2(concat$6([openingLines, concat$6(children), closingLines])), multiLineElem]);
  28754. }
  28755. function maybeWrapJSXElementInParens(path, elem, options) {
  28756. var parent = path.getParentNode();
  28757. if (!parent) {
  28758. return elem;
  28759. }
  28760. var NO_WRAP_PARENTS = {
  28761. ArrayExpression: true,
  28762. JSXAttribute: true,
  28763. JSXElement: true,
  28764. JSXExpressionContainer: true,
  28765. JSXFragment: true,
  28766. ExpressionStatement: true,
  28767. CallExpression: true,
  28768. OptionalCallExpression: true,
  28769. ConditionalExpression: true,
  28770. JsExpressionRoot: true
  28771. };
  28772. if (NO_WRAP_PARENTS[parent.type]) {
  28773. return elem;
  28774. }
  28775. var shouldBreak = matchAncestorTypes$1(path, ["ArrowFunctionExpression", "CallExpression", "JSXExpressionContainer"]) || matchAncestorTypes$1(path, ["ArrowFunctionExpression", "OptionalCallExpression", "JSXExpressionContainer"]);
  28776. var needsParens = needsParens_1(path, options);
  28777. return group$2(concat$6([needsParens ? "" : ifBreak$1("("), indent$3(concat$6([softline$2, elem])), softline$2, needsParens ? "" : ifBreak$1(")")]), {
  28778. shouldBreak
  28779. });
  28780. }
  28781. function shouldInlineLogicalExpression(node) {
  28782. if (node.type !== "LogicalExpression") {
  28783. return false;
  28784. }
  28785. if (node.right.type === "ObjectExpression" && node.right.properties.length !== 0) {
  28786. return true;
  28787. }
  28788. if (node.right.type === "ArrayExpression" && node.right.elements.length !== 0) {
  28789. return true;
  28790. }
  28791. if (isJSXNode$1(node.right)) {
  28792. return true;
  28793. }
  28794. return false;
  28795. } // For binary expressions to be consistent, we need to group
  28796. // subsequent operators with the same precedence level under a single
  28797. // group. Otherwise they will be nested such that some of them break
  28798. // onto new lines but not all. Operators with the same precedence
  28799. // level should either all break or not. Because we group them by
  28800. // precedence level and the AST is structured based on precedence
  28801. // level, things are naturally broken up correctly, i.e. `&&` is
  28802. // broken before `+`.
  28803. function printBinaryishExpressions(path, print, options, isNested, isInsideParenthesis) {
  28804. var parts = [];
  28805. var node = path.getValue(); // We treat BinaryExpression and LogicalExpression nodes the same.
  28806. if (isBinaryish$1(node)) {
  28807. // Put all operators with the same precedence level in the same
  28808. // group. The reason we only need to do this with the `left`
  28809. // expression is because given an expression like `1 + 2 - 3`, it
  28810. // is always parsed like `((1 + 2) - 3)`, meaning the `left` side
  28811. // is where the rest of the expression will exist. Binary
  28812. // expressions on the right side mean they have a difference
  28813. // precedence level and should be treated as a separate group, so
  28814. // print them normally. (This doesn't hold for the `**` operator,
  28815. // which is unique in that it is right-associative.)
  28816. if (shouldFlatten$1(node.operator, node.left.operator)) {
  28817. // Flatten them out by recursively calling this function.
  28818. parts = parts.concat(path.call(function (left) {
  28819. return printBinaryishExpressions(left, print, options,
  28820. /* isNested */
  28821. true, isInsideParenthesis);
  28822. }, "left"));
  28823. } else {
  28824. parts.push(path.call(print, "left"));
  28825. }
  28826. var shouldInline = shouldInlineLogicalExpression(node);
  28827. var lineBeforeOperator = (node.operator === "|>" || node.type === "NGPipeExpression" || node.operator === "|" && options.parser === "__vue_expression") && !hasLeadingOwnLineComment$1(options.originalText, node.right, options);
  28828. var operator = node.type === "NGPipeExpression" ? "|" : node.operator;
  28829. var rightSuffix = node.type === "NGPipeExpression" && node.arguments.length !== 0 ? group$2(indent$3(concat$6([softline$2, ": ", join$4(concat$6([softline$2, ":", ifBreak$1(" ")]), path.map(print, "arguments").map(function (arg) {
  28830. return align$1(2, group$2(arg));
  28831. }))]))) : "";
  28832. var right = shouldInline ? concat$6([operator, " ", path.call(print, "right"), rightSuffix]) : concat$6([lineBeforeOperator ? softline$2 : "", operator, lineBeforeOperator ? " " : line$2, path.call(print, "right"), rightSuffix]); // If there's only a single binary expression, we want to create a group
  28833. // in order to avoid having a small right part like -1 be on its own line.
  28834. var parent = path.getParentNode();
  28835. var shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node.left.type !== node.type && node.right.type !== node.type;
  28836. parts.push(" ", shouldGroup ? group$2(right) : right); // The root comments are already printed, but we need to manually print
  28837. // the other ones since we don't call the normal print on BinaryExpression,
  28838. // only for the left and right parts
  28839. if (isNested && node.comments) {
  28840. parts = comments.printComments(path, function () {
  28841. return concat$6(parts);
  28842. }, options);
  28843. }
  28844. } else {
  28845. // Our stopping case. Simply print the node normally.
  28846. parts.push(path.call(print));
  28847. }
  28848. return parts;
  28849. }
  28850. function printAssignmentRight(leftNode, rightNode, printedRight, options) {
  28851. if (hasLeadingOwnLineComment$1(options.originalText, rightNode, options)) {
  28852. return indent$3(concat$6([hardline$4, printedRight]));
  28853. }
  28854. var 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
  28855. options.parser !== "json" && options.parser !== "json5" || rightNode.type === "SequenceExpression";
  28856. if (canBreak) {
  28857. return group$2(indent$3(concat$6([line$2, printedRight])));
  28858. }
  28859. return concat$6([" ", printedRight]);
  28860. }
  28861. function printAssignment(leftNode, printedLeft, operator, rightNode, printedRight, options) {
  28862. if (!rightNode) {
  28863. return printedLeft;
  28864. }
  28865. var printed = printAssignmentRight(leftNode, rightNode, printedRight, options);
  28866. return group$2(concat$6([printedLeft, operator, printed]));
  28867. }
  28868. function adjustClause(node, clause, forceSpace) {
  28869. if (node.type === "EmptyStatement") {
  28870. return ";";
  28871. }
  28872. if (node.type === "BlockStatement" || forceSpace) {
  28873. return concat$6([" ", clause]);
  28874. }
  28875. return indent$3(concat$6([line$2, clause]));
  28876. }
  28877. function nodeStr(node, options, isFlowOrTypeScriptDirectiveLiteral) {
  28878. var raw = rawText$1(node);
  28879. var isDirectiveLiteral = isFlowOrTypeScriptDirectiveLiteral || node.type === "DirectiveLiteral";
  28880. return printString$1(raw, options, isDirectiveLiteral);
  28881. }
  28882. function printRegex(node) {
  28883. var flags = node.flags.split("").sort().join("");
  28884. return `/${node.pattern}/${flags}`;
  28885. }
  28886. function exprNeedsASIProtection(path, options) {
  28887. var node = path.getValue();
  28888. var 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$1(node) || node.type === "BindExpression" && !node.object || node.type === "RegExpLiteral" || node.type === "Literal" && node.pattern || node.type === "Literal" && node.regex;
  28889. if (maybeASIProblem) {
  28890. return true;
  28891. }
  28892. if (!hasNakedLeftSide$2(node)) {
  28893. return false;
  28894. }
  28895. return path.call.apply(path, [function (childPath) {
  28896. return exprNeedsASIProtection(childPath, options);
  28897. }].concat(getLeftSidePathName$2(path, node)));
  28898. }
  28899. function stmtNeedsASIProtection(path, options) {
  28900. var node = path.getNode();
  28901. if (node.type !== "ExpressionStatement") {
  28902. return false;
  28903. }
  28904. return path.call(function (childPath) {
  28905. return exprNeedsASIProtection(childPath, options);
  28906. }, "expression");
  28907. }
  28908. function shouldHugType(node) {
  28909. if (isSimpleFlowType$1(node) || isObjectType$1(node)) {
  28910. return true;
  28911. }
  28912. if (node.type === "UnionTypeAnnotation" || node.type === "TSUnionType") {
  28913. var voidCount = node.types.filter(function (n) {
  28914. return n.type === "VoidTypeAnnotation" || n.type === "TSVoidKeyword" || n.type === "NullLiteralTypeAnnotation" || n.type === "TSNullKeyword";
  28915. }).length;
  28916. var objectCount = node.types.filter(function (n) {
  28917. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral" || // This is a bit aggressive but captures Array<{x}>
  28918. n.type === "GenericTypeAnnotation" || n.type === "TSTypeReference";
  28919. }).length;
  28920. if (node.types.length - 1 === voidCount && objectCount > 0) {
  28921. return true;
  28922. }
  28923. }
  28924. return false;
  28925. }
  28926. function shouldHugArguments(fun) {
  28927. return fun && fun.params && fun.params.length === 1 && !fun.params[0].comments && (fun.params[0].type === "ObjectPattern" || fun.params[0].type === "ArrayPattern" || fun.params[0].type === "Identifier" && fun.params[0].typeAnnotation && (fun.params[0].typeAnnotation.type === "TypeAnnotation" || fun.params[0].typeAnnotation.type === "TSTypeAnnotation") && isObjectType$1(fun.params[0].typeAnnotation.typeAnnotation) || fun.params[0].type === "FunctionTypeParam" && isObjectType$1(fun.params[0].typeAnnotation) || fun.params[0].type === "AssignmentPattern" && (fun.params[0].left.type === "ObjectPattern" || fun.params[0].left.type === "ArrayPattern") && (fun.params[0].right.type === "Identifier" || fun.params[0].right.type === "ObjectExpression" && fun.params[0].right.properties.length === 0 || fun.params[0].right.type === "ArrayExpression" && fun.params[0].right.elements.length === 0)) && !fun.rest;
  28928. }
  28929. function printArrayItems(path, options, printPath, print) {
  28930. var printedElements = [];
  28931. var separatorParts = [];
  28932. path.each(function (childPath) {
  28933. printedElements.push(concat$6(separatorParts));
  28934. printedElements.push(group$2(print(childPath)));
  28935. separatorParts = [",", line$2];
  28936. if (childPath.getValue() && isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  28937. separatorParts.push(softline$2);
  28938. }
  28939. }, printPath);
  28940. return concat$6(printedElements);
  28941. }
  28942. function willPrintOwnComments(path
  28943. /*, options */
  28944. ) {
  28945. var node = path.getValue();
  28946. var parent = path.getParentNode();
  28947. return (node && (isJSXNode$1(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);
  28948. }
  28949. function canAttachComment(node) {
  28950. return node.type && node.type !== "CommentBlock" && node.type !== "CommentLine" && node.type !== "Line" && node.type !== "Block" && node.type !== "EmptyStatement" && node.type !== "TemplateElement" && node.type !== "Import";
  28951. }
  28952. function printComment$1(commentPath, options) {
  28953. var comment = commentPath.getValue();
  28954. switch (comment.type) {
  28955. case "CommentBlock":
  28956. case "Block":
  28957. {
  28958. if (isIndentableBlockComment(comment)) {
  28959. var printed = printIndentableBlockComment(comment); // We need to prevent an edge case of a previous trailing comment
  28960. // printed as a `lineSuffix` which causes the comments to be
  28961. // interleaved. See https://github.com/prettier/prettier/issues/4412
  28962. if (comment.trailing && !hasNewline$3(options.originalText, options.locStart(comment), {
  28963. backwards: true
  28964. })) {
  28965. return concat$6([hardline$4, printed]);
  28966. }
  28967. return printed;
  28968. }
  28969. var isInsideFlowComment = options.originalText.substr(options.locEnd(comment) - 3, 3) === "*-/";
  28970. return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
  28971. }
  28972. case "CommentLine":
  28973. case "Line":
  28974. // Print shebangs with the proper comment characters
  28975. if (options.originalText.slice(options.locStart(comment)).startsWith("#!")) {
  28976. return "#!" + comment.value.trimRight();
  28977. }
  28978. return "//" + comment.value.trimRight();
  28979. default:
  28980. throw new Error("Not a comment: " + JSON.stringify(comment));
  28981. }
  28982. }
  28983. function isIndentableBlockComment(comment) {
  28984. // If the comment has multiple lines and every line starts with a star
  28985. // we can fix the indentation of each line. The stars in the `/*` and
  28986. // `*/` delimiters are not included in the comment value, so add them
  28987. // back first.
  28988. var lines = `*${comment.value}*`.split("\n");
  28989. return lines.length > 1 && lines.every(function (line) {
  28990. return line.trim()[0] === "*";
  28991. });
  28992. }
  28993. function printIndentableBlockComment(comment) {
  28994. var lines = comment.value.split("\n");
  28995. return concat$6(["/*", join$4(hardline$4, lines.map(function (line, index) {
  28996. return index === 0 ? line.trimRight() : " " + (index < lines.length - 1 ? line.trim() : line.trimLeft());
  28997. })), "*/"]);
  28998. }
  28999. var printerEstree = {
  29000. preprocess: preprocess_1,
  29001. print: genericPrint,
  29002. embed: embed_1,
  29003. insertPragma: insertPragma$1,
  29004. massageAstNode: clean_1,
  29005. hasPrettierIgnore: hasPrettierIgnore$1,
  29006. willPrintOwnComments,
  29007. canAttachComment,
  29008. printComment: printComment$1,
  29009. isBlockComment: comments$1.isBlockComment,
  29010. handleComments: {
  29011. ownLine: comments$1.handleOwnLineComment,
  29012. endOfLine: comments$1.handleEndOfLineComment,
  29013. remaining: comments$1.handleRemainingComment
  29014. }
  29015. };
  29016. var _require$$0$builders$2 = doc.builders,
  29017. concat$7 = _require$$0$builders$2.concat,
  29018. hardline$5 = _require$$0$builders$2.hardline,
  29019. indent$4 = _require$$0$builders$2.indent,
  29020. join$5 = _require$$0$builders$2.join;
  29021. function genericPrint$1(path, options, print) {
  29022. var node = path.getValue();
  29023. switch (node.type) {
  29024. case "JsonRoot":
  29025. return concat$7([path.call(print, "node"), hardline$5]);
  29026. case "ArrayExpression":
  29027. return node.elements.length === 0 ? "[]" : concat$7(["[", indent$4(concat$7([hardline$5, join$5(concat$7([",", hardline$5]), path.map(print, "elements"))])), hardline$5, "]"]);
  29028. case "ObjectExpression":
  29029. return node.properties.length === 0 ? "{}" : concat$7(["{", indent$4(concat$7([hardline$5, join$5(concat$7([",", hardline$5]), path.map(print, "properties"))])), hardline$5, "}"]);
  29030. case "ObjectProperty":
  29031. return concat$7([path.call(print, "key"), ": ", path.call(print, "value")]);
  29032. case "UnaryExpression":
  29033. return concat$7([node.operator === "+" ? "" : node.operator, path.call(print, "argument")]);
  29034. case "NullLiteral":
  29035. return "null";
  29036. case "BooleanLiteral":
  29037. return node.value ? "true" : "false";
  29038. case "StringLiteral":
  29039. case "NumericLiteral":
  29040. return JSON.stringify(node.value);
  29041. case "Identifier":
  29042. return JSON.stringify(node.name);
  29043. default:
  29044. /* istanbul ignore next */
  29045. throw new Error("unknown type: " + JSON.stringify(node.type));
  29046. }
  29047. }
  29048. function clean$1(node, newNode
  29049. /*, parent*/
  29050. ) {
  29051. delete newNode.start;
  29052. delete newNode.end;
  29053. delete newNode.extra;
  29054. delete newNode.loc;
  29055. delete newNode.comments;
  29056. delete newNode.errors;
  29057. if (node.type === "Identifier") {
  29058. return {
  29059. type: "StringLiteral",
  29060. value: node.name
  29061. };
  29062. }
  29063. if (node.type === "UnaryExpression" && node.operator === "+") {
  29064. return newNode.argument;
  29065. }
  29066. }
  29067. var printerEstreeJson = {
  29068. preprocess: preprocess_1,
  29069. print: genericPrint$1,
  29070. massageAstNode: clean$1
  29071. };
  29072. var CATEGORY_COMMON = "Common"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  29073. var commonOptions = {
  29074. bracketSpacing: {
  29075. since: "0.0.0",
  29076. category: CATEGORY_COMMON,
  29077. type: "boolean",
  29078. default: true,
  29079. description: "Print spaces between brackets.",
  29080. oppositeDescription: "Do not print spaces between brackets."
  29081. },
  29082. singleQuote: {
  29083. since: "0.0.0",
  29084. category: CATEGORY_COMMON,
  29085. type: "boolean",
  29086. default: false,
  29087. description: "Use single quotes instead of double quotes."
  29088. },
  29089. proseWrap: {
  29090. since: "1.8.2",
  29091. category: CATEGORY_COMMON,
  29092. type: "choice",
  29093. default: [{
  29094. since: "1.8.2",
  29095. value: true
  29096. }, {
  29097. since: "1.9.0",
  29098. value: "preserve"
  29099. }],
  29100. description: "How to wrap prose.",
  29101. choices: [{
  29102. since: "1.9.0",
  29103. value: "always",
  29104. description: "Wrap prose if it exceeds the print width."
  29105. }, {
  29106. since: "1.9.0",
  29107. value: "never",
  29108. description: "Do not wrap prose."
  29109. }, {
  29110. since: "1.9.0",
  29111. value: "preserve",
  29112. description: "Wrap prose as-is."
  29113. }, {
  29114. value: false,
  29115. deprecated: "1.9.0",
  29116. redirect: "never"
  29117. }, {
  29118. value: true,
  29119. deprecated: "1.9.0",
  29120. redirect: "always"
  29121. }]
  29122. }
  29123. };
  29124. var CATEGORY_JAVASCRIPT = "JavaScript"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  29125. var options$2 = {
  29126. arrowParens: {
  29127. since: "1.9.0",
  29128. category: CATEGORY_JAVASCRIPT,
  29129. type: "choice",
  29130. default: "avoid",
  29131. description: "Include parentheses around a sole arrow function parameter.",
  29132. choices: [{
  29133. value: "avoid",
  29134. description: "Omit parens when possible. Example: `x => x`"
  29135. }, {
  29136. value: "always",
  29137. description: "Always include parens. Example: `(x) => x`"
  29138. }]
  29139. },
  29140. bracketSpacing: commonOptions.bracketSpacing,
  29141. jsxBracketSameLine: {
  29142. since: "0.17.0",
  29143. category: CATEGORY_JAVASCRIPT,
  29144. type: "boolean",
  29145. default: false,
  29146. description: "Put > on the last line instead of at a new line."
  29147. },
  29148. semi: {
  29149. since: "1.0.0",
  29150. category: CATEGORY_JAVASCRIPT,
  29151. type: "boolean",
  29152. default: true,
  29153. description: "Print semicolons.",
  29154. oppositeDescription: "Do not print semicolons, except at the beginning of lines which may need them."
  29155. },
  29156. singleQuote: commonOptions.singleQuote,
  29157. jsxSingleQuote: {
  29158. since: "1.15.0",
  29159. category: CATEGORY_JAVASCRIPT,
  29160. type: "boolean",
  29161. default: false,
  29162. description: "Use single quotes in JSX."
  29163. },
  29164. quoteProps: {
  29165. since: "1.17.0",
  29166. category: CATEGORY_JAVASCRIPT,
  29167. type: "choice",
  29168. default: "as-needed",
  29169. description: "Change when properties in objects are quoted.",
  29170. choices: [{
  29171. value: "as-needed",
  29172. description: "Only add quotes around object properties where required."
  29173. }, {
  29174. value: "consistent",
  29175. description: "If at least one property in an object requires quotes, quote all properties."
  29176. }, {
  29177. value: "preserve",
  29178. description: "Respect the input use of quotes in object properties."
  29179. }]
  29180. },
  29181. trailingComma: {
  29182. since: "0.0.0",
  29183. category: CATEGORY_JAVASCRIPT,
  29184. type: "choice",
  29185. default: [{
  29186. since: "0.0.0",
  29187. value: false
  29188. }, {
  29189. since: "0.19.0",
  29190. value: "none"
  29191. }],
  29192. description: "Print trailing commas wherever possible when multi-line.",
  29193. choices: [{
  29194. value: "none",
  29195. description: "No trailing commas."
  29196. }, {
  29197. value: "es5",
  29198. description: "Trailing commas where valid in ES5 (objects, arrays, etc.)"
  29199. }, {
  29200. value: "all",
  29201. description: "Trailing commas wherever possible (including function arguments)."
  29202. }, {
  29203. value: true,
  29204. deprecated: "0.19.0",
  29205. redirect: "es5"
  29206. }, {
  29207. value: false,
  29208. deprecated: "0.19.0",
  29209. redirect: "none"
  29210. }]
  29211. }
  29212. };
  29213. var createLanguage = function createLanguage(linguistData, transform) {
  29214. var language = {};
  29215. for (var key in linguistData) {
  29216. var newKey = key === "languageId" ? "linguistLanguageId" : key;
  29217. language[newKey] = linguistData[key];
  29218. }
  29219. return transform(language);
  29220. };
  29221. var name$2 = "JavaScript";
  29222. var type = "programming";
  29223. var tmScope = "source.js";
  29224. var aceMode = "javascript";
  29225. var codemirrorMode = "javascript";
  29226. var codemirrorMimeType = "text/javascript";
  29227. var color = "#f1e05a";
  29228. var aliases = [
  29229. "js",
  29230. "node"
  29231. ];
  29232. var extensions = [
  29233. ".js",
  29234. "._js",
  29235. ".bones",
  29236. ".es",
  29237. ".es6",
  29238. ".frag",
  29239. ".gs",
  29240. ".jake",
  29241. ".jsb",
  29242. ".jscad",
  29243. ".jsfl",
  29244. ".jsm",
  29245. ".jss",
  29246. ".mjs",
  29247. ".njs",
  29248. ".pac",
  29249. ".sjs",
  29250. ".ssjs",
  29251. ".xsjs",
  29252. ".xsjslib"
  29253. ];
  29254. var filenames = [
  29255. "Jakefile"
  29256. ];
  29257. var interpreters = [
  29258. "chakra",
  29259. "d8",
  29260. "js",
  29261. "node",
  29262. "rhino",
  29263. "v8",
  29264. "v8-shell"
  29265. ];
  29266. var languageId = 183;
  29267. var JavaScript = {
  29268. name: name$2,
  29269. type: type,
  29270. tmScope: tmScope,
  29271. aceMode: aceMode,
  29272. codemirrorMode: codemirrorMode,
  29273. codemirrorMimeType: codemirrorMimeType,
  29274. color: color,
  29275. aliases: aliases,
  29276. extensions: extensions,
  29277. filenames: filenames,
  29278. interpreters: interpreters,
  29279. languageId: languageId
  29280. };
  29281. var JavaScript$1 = /*#__PURE__*/Object.freeze({
  29282. __proto__: null,
  29283. name: name$2,
  29284. type: type,
  29285. tmScope: tmScope,
  29286. aceMode: aceMode,
  29287. codemirrorMode: codemirrorMode,
  29288. codemirrorMimeType: codemirrorMimeType,
  29289. color: color,
  29290. aliases: aliases,
  29291. extensions: extensions,
  29292. filenames: filenames,
  29293. interpreters: interpreters,
  29294. languageId: languageId,
  29295. 'default': JavaScript
  29296. });
  29297. var name$3 = "JSX";
  29298. var type$1 = "programming";
  29299. var group$3 = "JavaScript";
  29300. var extensions$1 = [
  29301. ".jsx"
  29302. ];
  29303. var tmScope$1 = "source.js.jsx";
  29304. var aceMode$1 = "javascript";
  29305. var codemirrorMode$1 = "jsx";
  29306. var codemirrorMimeType$1 = "text/jsx";
  29307. var languageId$1 = 178;
  29308. var JSX = {
  29309. name: name$3,
  29310. type: type$1,
  29311. group: group$3,
  29312. extensions: extensions$1,
  29313. tmScope: tmScope$1,
  29314. aceMode: aceMode$1,
  29315. codemirrorMode: codemirrorMode$1,
  29316. codemirrorMimeType: codemirrorMimeType$1,
  29317. languageId: languageId$1
  29318. };
  29319. var JSX$1 = /*#__PURE__*/Object.freeze({
  29320. __proto__: null,
  29321. name: name$3,
  29322. type: type$1,
  29323. group: group$3,
  29324. extensions: extensions$1,
  29325. tmScope: tmScope$1,
  29326. aceMode: aceMode$1,
  29327. codemirrorMode: codemirrorMode$1,
  29328. codemirrorMimeType: codemirrorMimeType$1,
  29329. languageId: languageId$1,
  29330. 'default': JSX
  29331. });
  29332. var name$4 = "TypeScript";
  29333. var type$2 = "programming";
  29334. var color$1 = "#2b7489";
  29335. var aliases$1 = [
  29336. "ts"
  29337. ];
  29338. var interpreters$1 = [
  29339. "deno",
  29340. "ts-node"
  29341. ];
  29342. var extensions$2 = [
  29343. ".ts"
  29344. ];
  29345. var tmScope$2 = "source.ts";
  29346. var aceMode$2 = "typescript";
  29347. var codemirrorMode$2 = "javascript";
  29348. var codemirrorMimeType$2 = "application/typescript";
  29349. var languageId$2 = 378;
  29350. var TypeScript = {
  29351. name: name$4,
  29352. type: type$2,
  29353. color: color$1,
  29354. aliases: aliases$1,
  29355. interpreters: interpreters$1,
  29356. extensions: extensions$2,
  29357. tmScope: tmScope$2,
  29358. aceMode: aceMode$2,
  29359. codemirrorMode: codemirrorMode$2,
  29360. codemirrorMimeType: codemirrorMimeType$2,
  29361. languageId: languageId$2
  29362. };
  29363. var TypeScript$1 = /*#__PURE__*/Object.freeze({
  29364. __proto__: null,
  29365. name: name$4,
  29366. type: type$2,
  29367. color: color$1,
  29368. aliases: aliases$1,
  29369. interpreters: interpreters$1,
  29370. extensions: extensions$2,
  29371. tmScope: tmScope$2,
  29372. aceMode: aceMode$2,
  29373. codemirrorMode: codemirrorMode$2,
  29374. codemirrorMimeType: codemirrorMimeType$2,
  29375. languageId: languageId$2,
  29376. 'default': TypeScript
  29377. });
  29378. var name$5 = "TSX";
  29379. var type$3 = "programming";
  29380. var group$4 = "TypeScript";
  29381. var extensions$3 = [
  29382. ".tsx"
  29383. ];
  29384. var tmScope$3 = "source.tsx";
  29385. var aceMode$3 = "javascript";
  29386. var codemirrorMode$3 = "jsx";
  29387. var codemirrorMimeType$3 = "text/jsx";
  29388. var languageId$3 = 94901924;
  29389. var TSX = {
  29390. name: name$5,
  29391. type: type$3,
  29392. group: group$4,
  29393. extensions: extensions$3,
  29394. tmScope: tmScope$3,
  29395. aceMode: aceMode$3,
  29396. codemirrorMode: codemirrorMode$3,
  29397. codemirrorMimeType: codemirrorMimeType$3,
  29398. languageId: languageId$3
  29399. };
  29400. var TSX$1 = /*#__PURE__*/Object.freeze({
  29401. __proto__: null,
  29402. name: name$5,
  29403. type: type$3,
  29404. group: group$4,
  29405. extensions: extensions$3,
  29406. tmScope: tmScope$3,
  29407. aceMode: aceMode$3,
  29408. codemirrorMode: codemirrorMode$3,
  29409. codemirrorMimeType: codemirrorMimeType$3,
  29410. languageId: languageId$3,
  29411. 'default': TSX
  29412. });
  29413. var name$6 = "JSON";
  29414. var type$4 = "data";
  29415. var tmScope$4 = "source.json";
  29416. var aceMode$4 = "json";
  29417. var codemirrorMode$4 = "javascript";
  29418. var codemirrorMimeType$4 = "application/json";
  29419. var searchable = false;
  29420. var extensions$4 = [
  29421. ".json",
  29422. ".avsc",
  29423. ".geojson",
  29424. ".gltf",
  29425. ".har",
  29426. ".ice",
  29427. ".JSON-tmLanguage",
  29428. ".jsonl",
  29429. ".mcmeta",
  29430. ".tfstate",
  29431. ".tfstate.backup",
  29432. ".topojson",
  29433. ".webapp",
  29434. ".webmanifest",
  29435. ".yy",
  29436. ".yyp"
  29437. ];
  29438. var filenames$1 = [
  29439. ".arcconfig",
  29440. ".htmlhintrc",
  29441. ".tern-config",
  29442. ".tern-project",
  29443. ".watchmanconfig",
  29444. "composer.lock",
  29445. "mcmod.info"
  29446. ];
  29447. var languageId$4 = 174;
  29448. var _JSON = {
  29449. name: name$6,
  29450. type: type$4,
  29451. tmScope: tmScope$4,
  29452. aceMode: aceMode$4,
  29453. codemirrorMode: codemirrorMode$4,
  29454. codemirrorMimeType: codemirrorMimeType$4,
  29455. searchable: searchable,
  29456. extensions: extensions$4,
  29457. filenames: filenames$1,
  29458. languageId: languageId$4
  29459. };
  29460. var _JSON$1 = /*#__PURE__*/Object.freeze({
  29461. __proto__: null,
  29462. name: name$6,
  29463. type: type$4,
  29464. tmScope: tmScope$4,
  29465. aceMode: aceMode$4,
  29466. codemirrorMode: codemirrorMode$4,
  29467. codemirrorMimeType: codemirrorMimeType$4,
  29468. searchable: searchable,
  29469. extensions: extensions$4,
  29470. filenames: filenames$1,
  29471. languageId: languageId$4,
  29472. 'default': _JSON
  29473. });
  29474. var name$7 = "JSON with Comments";
  29475. var type$5 = "data";
  29476. var group$5 = "JSON";
  29477. var tmScope$5 = "source.js";
  29478. var aceMode$5 = "javascript";
  29479. var codemirrorMode$5 = "javascript";
  29480. var codemirrorMimeType$5 = "text/javascript";
  29481. var aliases$2 = [
  29482. "jsonc"
  29483. ];
  29484. var extensions$5 = [
  29485. ".sublime-build",
  29486. ".sublime-commands",
  29487. ".sublime-completions",
  29488. ".sublime-keymap",
  29489. ".sublime-macro",
  29490. ".sublime-menu",
  29491. ".sublime-mousemap",
  29492. ".sublime-project",
  29493. ".sublime-settings",
  29494. ".sublime-theme",
  29495. ".sublime-workspace",
  29496. ".sublime_metrics",
  29497. ".sublime_session"
  29498. ];
  29499. var filenames$2 = [
  29500. ".babelrc",
  29501. ".eslintrc.json",
  29502. ".jscsrc",
  29503. ".jshintrc",
  29504. ".jslintrc",
  29505. "jsconfig.json",
  29506. "language-configuration.json",
  29507. "tsconfig.json"
  29508. ];
  29509. var languageId$5 = 423;
  29510. var JSON_with_Comments = {
  29511. name: name$7,
  29512. type: type$5,
  29513. group: group$5,
  29514. tmScope: tmScope$5,
  29515. aceMode: aceMode$5,
  29516. codemirrorMode: codemirrorMode$5,
  29517. codemirrorMimeType: codemirrorMimeType$5,
  29518. aliases: aliases$2,
  29519. extensions: extensions$5,
  29520. filenames: filenames$2,
  29521. languageId: languageId$5
  29522. };
  29523. var JSON_with_Comments$1 = /*#__PURE__*/Object.freeze({
  29524. __proto__: null,
  29525. name: name$7,
  29526. type: type$5,
  29527. group: group$5,
  29528. tmScope: tmScope$5,
  29529. aceMode: aceMode$5,
  29530. codemirrorMode: codemirrorMode$5,
  29531. codemirrorMimeType: codemirrorMimeType$5,
  29532. aliases: aliases$2,
  29533. extensions: extensions$5,
  29534. filenames: filenames$2,
  29535. languageId: languageId$5,
  29536. 'default': JSON_with_Comments
  29537. });
  29538. var name$8 = "JSON5";
  29539. var type$6 = "data";
  29540. var extensions$6 = [
  29541. ".json5"
  29542. ];
  29543. var tmScope$6 = "source.js";
  29544. var aceMode$6 = "javascript";
  29545. var codemirrorMode$6 = "javascript";
  29546. var codemirrorMimeType$6 = "application/json";
  29547. var languageId$6 = 175;
  29548. var JSON5 = {
  29549. name: name$8,
  29550. type: type$6,
  29551. extensions: extensions$6,
  29552. tmScope: tmScope$6,
  29553. aceMode: aceMode$6,
  29554. codemirrorMode: codemirrorMode$6,
  29555. codemirrorMimeType: codemirrorMimeType$6,
  29556. languageId: languageId$6
  29557. };
  29558. var JSON5$1 = /*#__PURE__*/Object.freeze({
  29559. __proto__: null,
  29560. name: name$8,
  29561. type: type$6,
  29562. extensions: extensions$6,
  29563. tmScope: tmScope$6,
  29564. aceMode: aceMode$6,
  29565. codemirrorMode: codemirrorMode$6,
  29566. codemirrorMimeType: codemirrorMimeType$6,
  29567. languageId: languageId$6,
  29568. 'default': JSON5
  29569. });
  29570. var require$$0$1 = getCjsExportFromNamespace(JavaScript$1);
  29571. var require$$1 = getCjsExportFromNamespace(JSX$1);
  29572. var require$$2 = getCjsExportFromNamespace(TypeScript$1);
  29573. var require$$3 = getCjsExportFromNamespace(TSX$1);
  29574. var require$$4$1 = getCjsExportFromNamespace(_JSON$1);
  29575. var require$$5 = getCjsExportFromNamespace(JSON_with_Comments$1);
  29576. var require$$6 = getCjsExportFromNamespace(JSON5$1);
  29577. var languages = [createLanguage(require$$0$1, function (data) {
  29578. return Object.assign(data, {
  29579. since: "0.0.0",
  29580. parsers: ["babel", "flow"],
  29581. vscodeLanguageIds: ["javascript", "mongo"],
  29582. interpreters: data.interpreters.concat(["nodejs"])
  29583. });
  29584. }), createLanguage(require$$0$1, function (data) {
  29585. return Object.assign(data, {
  29586. name: "Flow",
  29587. since: "0.0.0",
  29588. parsers: ["babel", "flow"],
  29589. vscodeLanguageIds: ["javascript"],
  29590. aliases: [],
  29591. filenames: [],
  29592. extensions: [".js.flow"]
  29593. });
  29594. }), createLanguage(require$$1, function (data) {
  29595. return Object.assign(data, {
  29596. since: "0.0.0",
  29597. parsers: ["babel", "flow"],
  29598. vscodeLanguageIds: ["javascriptreact"]
  29599. });
  29600. }), createLanguage(require$$2, function (data) {
  29601. return Object.assign(data, {
  29602. since: "1.4.0",
  29603. parsers: ["typescript"],
  29604. vscodeLanguageIds: ["typescript"]
  29605. });
  29606. }), createLanguage(require$$3, function (data) {
  29607. return Object.assign(data, {
  29608. since: "1.4.0",
  29609. parsers: ["typescript"],
  29610. vscodeLanguageIds: ["typescriptreact"]
  29611. });
  29612. }), createLanguage(require$$4$1, function (data) {
  29613. return Object.assign(data, {
  29614. name: "JSON.stringify",
  29615. since: "1.13.0",
  29616. parsers: ["json-stringify"],
  29617. vscodeLanguageIds: ["json"],
  29618. extensions: [],
  29619. // .json file defaults to json instead of json-stringify
  29620. filenames: ["package.json", "package-lock.json", "composer.json"]
  29621. });
  29622. }), createLanguage(require$$4$1, function (data) {
  29623. return Object.assign(data, {
  29624. since: "1.5.0",
  29625. parsers: ["json"],
  29626. vscodeLanguageIds: ["json"],
  29627. filenames: data.filenames.concat([".prettierrc"])
  29628. });
  29629. }), createLanguage(require$$5, function (data) {
  29630. return Object.assign(data, {
  29631. since: "1.5.0",
  29632. parsers: ["json"],
  29633. vscodeLanguageIds: ["jsonc"],
  29634. filenames: data.filenames.concat([".eslintrc"])
  29635. });
  29636. }), createLanguage(require$$6, function (data) {
  29637. return Object.assign(data, {
  29638. since: "1.13.0",
  29639. parsers: ["json5"],
  29640. vscodeLanguageIds: ["json5"]
  29641. });
  29642. })];
  29643. var printers = {
  29644. estree: printerEstree,
  29645. "estree-json": printerEstreeJson
  29646. };
  29647. var languageJs = {
  29648. languages,
  29649. options: options$2,
  29650. printers
  29651. };
  29652. var index = [
  29653. "a",
  29654. "abbr",
  29655. "acronym",
  29656. "address",
  29657. "applet",
  29658. "area",
  29659. "article",
  29660. "aside",
  29661. "audio",
  29662. "b",
  29663. "base",
  29664. "basefont",
  29665. "bdi",
  29666. "bdo",
  29667. "bgsound",
  29668. "big",
  29669. "blink",
  29670. "blockquote",
  29671. "body",
  29672. "br",
  29673. "button",
  29674. "canvas",
  29675. "caption",
  29676. "center",
  29677. "cite",
  29678. "code",
  29679. "col",
  29680. "colgroup",
  29681. "command",
  29682. "content",
  29683. "data",
  29684. "datalist",
  29685. "dd",
  29686. "del",
  29687. "details",
  29688. "dfn",
  29689. "dialog",
  29690. "dir",
  29691. "div",
  29692. "dl",
  29693. "dt",
  29694. "element",
  29695. "em",
  29696. "embed",
  29697. "fieldset",
  29698. "figcaption",
  29699. "figure",
  29700. "font",
  29701. "footer",
  29702. "form",
  29703. "frame",
  29704. "frameset",
  29705. "h1",
  29706. "h2",
  29707. "h3",
  29708. "h4",
  29709. "h5",
  29710. "h6",
  29711. "head",
  29712. "header",
  29713. "hgroup",
  29714. "hr",
  29715. "html",
  29716. "i",
  29717. "iframe",
  29718. "image",
  29719. "img",
  29720. "input",
  29721. "ins",
  29722. "isindex",
  29723. "kbd",
  29724. "keygen",
  29725. "label",
  29726. "legend",
  29727. "li",
  29728. "link",
  29729. "listing",
  29730. "main",
  29731. "map",
  29732. "mark",
  29733. "marquee",
  29734. "math",
  29735. "menu",
  29736. "menuitem",
  29737. "meta",
  29738. "meter",
  29739. "multicol",
  29740. "nav",
  29741. "nextid",
  29742. "nobr",
  29743. "noembed",
  29744. "noframes",
  29745. "noscript",
  29746. "object",
  29747. "ol",
  29748. "optgroup",
  29749. "option",
  29750. "output",
  29751. "p",
  29752. "param",
  29753. "picture",
  29754. "plaintext",
  29755. "pre",
  29756. "progress",
  29757. "q",
  29758. "rb",
  29759. "rbc",
  29760. "rp",
  29761. "rt",
  29762. "rtc",
  29763. "ruby",
  29764. "s",
  29765. "samp",
  29766. "script",
  29767. "section",
  29768. "select",
  29769. "shadow",
  29770. "slot",
  29771. "small",
  29772. "source",
  29773. "spacer",
  29774. "span",
  29775. "strike",
  29776. "strong",
  29777. "style",
  29778. "sub",
  29779. "summary",
  29780. "sup",
  29781. "svg",
  29782. "table",
  29783. "tbody",
  29784. "td",
  29785. "template",
  29786. "textarea",
  29787. "tfoot",
  29788. "th",
  29789. "thead",
  29790. "time",
  29791. "title",
  29792. "tr",
  29793. "track",
  29794. "tt",
  29795. "u",
  29796. "ul",
  29797. "var",
  29798. "video",
  29799. "wbr",
  29800. "xmp"
  29801. ];
  29802. var htmlTagNames = /*#__PURE__*/Object.freeze({
  29803. __proto__: null,
  29804. 'default': index
  29805. });
  29806. var htmlTagNames$1 = getCjsExportFromNamespace(htmlTagNames);
  29807. function clean$2(ast, newObj, parent) {
  29808. ["raw", // front-matter
  29809. "raws", "sourceIndex", "source", "before", "after", "trailingComma"].forEach(function (name) {
  29810. delete newObj[name];
  29811. });
  29812. if (ast.type === "yaml") {
  29813. delete newObj.value;
  29814. } // --insert-pragma
  29815. if (ast.type === "css-comment" && parent.type === "css-root" && parent.nodes.length !== 0 && ( // first non-front-matter comment
  29816. parent.nodes[0] === ast || (parent.nodes[0].type === "yaml" || parent.nodes[0].type === "toml") && parent.nodes[1] === ast)) {
  29817. /**
  29818. * something
  29819. *
  29820. * @format
  29821. */
  29822. delete newObj.text; // standalone pragma
  29823. if (/^\*\s*@(format|prettier)\s*$/.test(ast.text)) {
  29824. return null;
  29825. }
  29826. }
  29827. if (ast.type === "media-query" || ast.type === "media-query-list" || ast.type === "media-feature-expression") {
  29828. delete newObj.value;
  29829. }
  29830. if (ast.type === "css-rule") {
  29831. delete newObj.params;
  29832. }
  29833. if (ast.type === "selector-combinator") {
  29834. newObj.value = newObj.value.replace(/\s+/g, " ");
  29835. }
  29836. if (ast.type === "media-feature") {
  29837. newObj.value = newObj.value.replace(/ /g, "");
  29838. }
  29839. if (ast.type === "value-word" && (ast.isColor && ast.isHex || ["initial", "inherit", "unset", "revert"].indexOf(newObj.value.replace().toLowerCase()) !== -1) || ast.type === "media-feature" || ast.type === "selector-root-invalid" || ast.type === "selector-pseudo") {
  29840. newObj.value = newObj.value.toLowerCase();
  29841. }
  29842. if (ast.type === "css-decl") {
  29843. newObj.prop = newObj.prop.toLowerCase();
  29844. }
  29845. if (ast.type === "css-atrule" || ast.type === "css-import") {
  29846. newObj.name = newObj.name.toLowerCase();
  29847. }
  29848. if (ast.type === "value-number") {
  29849. newObj.unit = newObj.unit.toLowerCase();
  29850. }
  29851. 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) {
  29852. newObj.value = cleanCSSStrings(newObj.value);
  29853. }
  29854. if (ast.type === "selector-attribute") {
  29855. newObj.attribute = newObj.attribute.trim();
  29856. if (newObj.namespace) {
  29857. if (typeof newObj.namespace === "string") {
  29858. newObj.namespace = newObj.namespace.trim();
  29859. if (newObj.namespace.length === 0) {
  29860. newObj.namespace = true;
  29861. }
  29862. }
  29863. }
  29864. if (newObj.value) {
  29865. newObj.value = newObj.value.trim().replace(/^['"]|['"]$/g, "");
  29866. delete newObj.quoted;
  29867. }
  29868. }
  29869. 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) {
  29870. newObj.value = newObj.value.replace(/([\d.eE+-]+)([a-zA-Z]*)/g, function (match, numStr, unit) {
  29871. var num = Number(numStr);
  29872. return isNaN(num) ? match : num + unit.toLowerCase();
  29873. });
  29874. }
  29875. if (ast.type === "selector-tag") {
  29876. var lowercasedValue = ast.value.toLowerCase();
  29877. if (htmlTagNames$1.indexOf(lowercasedValue) !== -1) {
  29878. newObj.value = lowercasedValue;
  29879. }
  29880. if (["from", "to"].indexOf(lowercasedValue) !== -1) {
  29881. newObj.value = lowercasedValue;
  29882. }
  29883. } // Workaround when `postcss-values-parser` parse `not`, `and` or `or` keywords as `value-func`
  29884. if (ast.type === "css-atrule" && ast.name.toLowerCase() === "supports") {
  29885. delete newObj.value;
  29886. } // Workaround for SCSS nested properties
  29887. if (ast.type === "selector-unknown") {
  29888. delete newObj.value;
  29889. }
  29890. }
  29891. function cleanCSSStrings(value) {
  29892. return value.replace(/'/g, '"').replace(/\\([^a-fA-F\d])/g, "$1");
  29893. }
  29894. var clean_1$1 = clean$2;
  29895. var _require$$0$builders$3 = doc.builders,
  29896. hardline$6 = _require$$0$builders$3.hardline,
  29897. literalline$3 = _require$$0$builders$3.literalline,
  29898. concat$8 = _require$$0$builders$3.concat,
  29899. markAsRoot$1 = _require$$0$builders$3.markAsRoot,
  29900. mapDoc$4 = doc.utils.mapDoc;
  29901. function embed$1(path, print, textToDoc
  29902. /*, options */
  29903. ) {
  29904. var node = path.getValue();
  29905. if (node.type === "yaml") {
  29906. return markAsRoot$1(concat$8(["---", hardline$6, node.value.trim() ? replaceNewlinesWithLiterallines(textToDoc(node.value, {
  29907. parser: "yaml"
  29908. })) : "", "---", hardline$6]));
  29909. }
  29910. return null;
  29911. function replaceNewlinesWithLiterallines(doc) {
  29912. return mapDoc$4(doc, function (currentDoc) {
  29913. return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$8(currentDoc.split(/(\n)/g).map(function (v, i) {
  29914. return i % 2 === 0 ? v : literalline$3;
  29915. })) : currentDoc;
  29916. });
  29917. }
  29918. }
  29919. var embed_1$1 = embed$1;
  29920. var DELIMITER_MAP = {
  29921. "---": "yaml",
  29922. "+++": "toml"
  29923. };
  29924. function parse$3(text) {
  29925. var delimiterRegex = Object.keys(DELIMITER_MAP).map(escapeStringRegexp).join("|");
  29926. var match = text.match( // trailing spaces after delimiters are allowed
  29927. new RegExp(`^(${delimiterRegex})[^\\n\\S]*\\n(?:([\\s\\S]*?)\\n)?\\1[^\\n\\S]*(\\n|$)`));
  29928. if (match === null) {
  29929. return {
  29930. frontMatter: null,
  29931. content: text
  29932. };
  29933. }
  29934. var raw = match[0].replace(/\n$/, "");
  29935. var delimiter = match[1];
  29936. var value = match[2];
  29937. return {
  29938. frontMatter: {
  29939. type: DELIMITER_MAP[delimiter],
  29940. value,
  29941. raw
  29942. },
  29943. content: match[0].replace(/[^\n]/g, " ") + text.slice(match[0].length)
  29944. };
  29945. }
  29946. var frontMatter = parse$3;
  29947. function hasPragma$1(text) {
  29948. return pragma.hasPragma(frontMatter(text).content);
  29949. }
  29950. function insertPragma$2(text) {
  29951. var _parseFrontMatter = frontMatter(text),
  29952. frontMatter$1 = _parseFrontMatter.frontMatter,
  29953. content = _parseFrontMatter.content;
  29954. return (frontMatter$1 ? frontMatter$1.raw + "\n\n" : "") + pragma.insertPragma(content);
  29955. }
  29956. var pragma$1 = {
  29957. hasPragma: hasPragma$1,
  29958. insertPragma: insertPragma$2
  29959. };
  29960. var colorAdjusterFunctions = ["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"];
  29961. function getAncestorCounter(path, typeOrTypes) {
  29962. var types = [].concat(typeOrTypes);
  29963. var counter = -1;
  29964. var ancestorNode;
  29965. while (ancestorNode = path.getParentNode(++counter)) {
  29966. if (types.indexOf(ancestorNode.type) !== -1) {
  29967. return counter;
  29968. }
  29969. }
  29970. return -1;
  29971. }
  29972. function getAncestorNode(path, typeOrTypes) {
  29973. var counter = getAncestorCounter(path, typeOrTypes);
  29974. return counter === -1 ? null : path.getParentNode(counter);
  29975. }
  29976. function getPropOfDeclNode(path) {
  29977. var declAncestorNode = getAncestorNode(path, "css-decl");
  29978. return declAncestorNode && declAncestorNode.prop && declAncestorNode.prop.toLowerCase();
  29979. }
  29980. function isSCSS(parser, text) {
  29981. var hasExplicitParserChoice = parser === "less" || parser === "scss";
  29982. var IS_POSSIBLY_SCSS = /(\w\s*: [^}:]+|#){|@import[^\n]+(url|,)/;
  29983. return hasExplicitParserChoice ? parser === "scss" : IS_POSSIBLY_SCSS.test(text);
  29984. }
  29985. function isWideKeywords(value) {
  29986. return ["initial", "inherit", "unset", "revert"].indexOf(value.toLowerCase()) !== -1;
  29987. }
  29988. function isKeyframeAtRuleKeywords(path, value) {
  29989. var atRuleAncestorNode = getAncestorNode(path, "css-atrule");
  29990. return atRuleAncestorNode && atRuleAncestorNode.name && atRuleAncestorNode.name.toLowerCase().endsWith("keyframes") && ["from", "to"].indexOf(value.toLowerCase()) !== -1;
  29991. }
  29992. function maybeToLowerCase(value) {
  29993. return value.includes("$") || value.includes("@") || value.includes("#") || value.startsWith("%") || value.startsWith("--") || value.startsWith(":--") || value.includes("(") && value.includes(")") ? value : value.toLowerCase();
  29994. }
  29995. function insideValueFunctionNode(path, functionName) {
  29996. var funcAncestorNode = getAncestorNode(path, "value-func");
  29997. return funcAncestorNode && funcAncestorNode.value && funcAncestorNode.value.toLowerCase() === functionName;
  29998. }
  29999. function insideICSSRuleNode(path) {
  30000. var ruleAncestorNode = getAncestorNode(path, "css-rule");
  30001. return ruleAncestorNode && ruleAncestorNode.raws && ruleAncestorNode.raws.selector && (ruleAncestorNode.raws.selector.startsWith(":import") || ruleAncestorNode.raws.selector.startsWith(":export"));
  30002. }
  30003. function insideAtRuleNode(path, atRuleNameOrAtRuleNames) {
  30004. var atRuleNames = [].concat(atRuleNameOrAtRuleNames);
  30005. var atRuleAncestorNode = getAncestorNode(path, "css-atrule");
  30006. return atRuleAncestorNode && atRuleNames.indexOf(atRuleAncestorNode.name.toLowerCase()) !== -1;
  30007. }
  30008. function insideURLFunctionInImportAtRuleNode(path) {
  30009. var node = path.getValue();
  30010. var atRuleAncestorNode = getAncestorNode(path, "css-atrule");
  30011. return atRuleAncestorNode && atRuleAncestorNode.name === "import" && node.groups[0].value === "url" && node.groups.length === 2;
  30012. }
  30013. function isURLFunctionNode(node) {
  30014. return node.type === "value-func" && node.value.toLowerCase() === "url";
  30015. }
  30016. function isLastNode(path, node) {
  30017. var parentNode = path.getParentNode();
  30018. if (!parentNode) {
  30019. return false;
  30020. }
  30021. var nodes = parentNode.nodes;
  30022. return nodes && nodes.indexOf(node) === nodes.length - 1;
  30023. }
  30024. function isHTMLTag(value) {
  30025. return htmlTagNames$1.indexOf(value.toLowerCase()) !== -1;
  30026. }
  30027. function isDetachedRulesetDeclarationNode(node) {
  30028. // If a Less file ends up being parsed with the SCSS parser, Less
  30029. // variable declarations will be parsed as atrules with names ending
  30030. // with a colon, so keep the original case then.
  30031. if (!node.selector) {
  30032. return false;
  30033. }
  30034. return typeof node.selector === "string" && /^@.+:.*$/.test(node.selector) || node.selector.value && /^@.+:.*$/.test(node.selector.value);
  30035. }
  30036. function isForKeywordNode(node) {
  30037. return node.type === "value-word" && ["from", "through", "end"].indexOf(node.value) !== -1;
  30038. }
  30039. function isIfElseKeywordNode(node) {
  30040. return node.type === "value-word" && ["and", "or", "not"].indexOf(node.value) !== -1;
  30041. }
  30042. function isEachKeywordNode(node) {
  30043. return node.type === "value-word" && node.value === "in";
  30044. }
  30045. function isMultiplicationNode(node) {
  30046. return node.type === "value-operator" && node.value === "*";
  30047. }
  30048. function isDivisionNode(node) {
  30049. return node.type === "value-operator" && node.value === "/";
  30050. }
  30051. function isAdditionNode(node) {
  30052. return node.type === "value-operator" && node.value === "+";
  30053. }
  30054. function isSubtractionNode(node) {
  30055. return node.type === "value-operator" && node.value === "-";
  30056. }
  30057. function isModuloNode(node) {
  30058. return node.type === "value-operator" && node.value === "%";
  30059. }
  30060. function isMathOperatorNode(node) {
  30061. return isMultiplicationNode(node) || isDivisionNode(node) || isAdditionNode(node) || isSubtractionNode(node) || isModuloNode(node);
  30062. }
  30063. function isEqualityOperatorNode(node) {
  30064. return node.type === "value-word" && ["==", "!="].indexOf(node.value) !== -1;
  30065. }
  30066. function isRelationalOperatorNode(node) {
  30067. return node.type === "value-word" && ["<", ">", "<=", ">="].indexOf(node.value) !== -1;
  30068. }
  30069. function isSCSSControlDirectiveNode(node) {
  30070. return node.type === "css-atrule" && ["if", "else", "for", "each", "while"].indexOf(node.name) !== -1;
  30071. }
  30072. function isSCSSNestedPropertyNode(node) {
  30073. if (!node.selector) {
  30074. return false;
  30075. }
  30076. return node.selector.replace(/\/\*.*?\*\//, "").replace(/\/\/.*?\n/, "").trim().endsWith(":");
  30077. }
  30078. function isDetachedRulesetCallNode(node) {
  30079. return node.raws && node.raws.params && /^\(\s*\)$/.test(node.raws.params);
  30080. }
  30081. function isTemplatePlaceholderNode(node) {
  30082. return node.name.startsWith("prettier-placeholder");
  30083. }
  30084. function isTemplatePropNode(node) {
  30085. return node.prop.startsWith("@prettier-placeholder");
  30086. }
  30087. function isPostcssSimpleVarNode(currentNode, nextNode) {
  30088. return currentNode.value === "$$" && currentNode.type === "value-func" && nextNode && nextNode.type === "value-word" && !nextNode.raws.before;
  30089. }
  30090. function hasComposesNode(node) {
  30091. return node.value && node.value.type === "value-root" && node.value.group && node.value.group.type === "value-value" && node.prop.toLowerCase() === "composes";
  30092. }
  30093. function hasParensAroundNode(node) {
  30094. 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;
  30095. }
  30096. function hasEmptyRawBefore(node) {
  30097. return node.raws && node.raws.before === "";
  30098. }
  30099. function isKeyValuePairNode(node) {
  30100. return node.type === "value-comma_group" && node.groups && node.groups[1] && node.groups[1].type === "value-colon";
  30101. }
  30102. function isKeyValuePairInParenGroupNode(node) {
  30103. return node.type === "value-paren_group" && node.groups && node.groups[0] && isKeyValuePairNode(node.groups[0]);
  30104. }
  30105. function isSCSSMapItemNode(path) {
  30106. var node = path.getValue(); // Ignore empty item (i.e. `$key: ()`)
  30107. if (node.groups.length === 0) {
  30108. return false;
  30109. }
  30110. var parentParentNode = path.getParentNode(1); // Check open parens contain key/value pair (i.e. `(key: value)` and `(key: (value, other-value)`)
  30111. if (!isKeyValuePairInParenGroupNode(node) && !(parentParentNode && isKeyValuePairInParenGroupNode(parentParentNode))) {
  30112. return false;
  30113. }
  30114. var declNode = getAncestorNode(path, "css-decl"); // SCSS map declaration (i.e. `$map: (key: value, other-key: other-value)`)
  30115. if (declNode && declNode.prop && declNode.prop.startsWith("$")) {
  30116. return true;
  30117. } // List as value of key inside SCSS map (i.e. `$map: (key: (value other-value other-other-value))`)
  30118. if (isKeyValuePairInParenGroupNode(parentParentNode)) {
  30119. return true;
  30120. } // SCSS Map is argument of function (i.e. `func((key: value, other-key: other-value))`)
  30121. if (parentParentNode.type === "value-func") {
  30122. return true;
  30123. }
  30124. return false;
  30125. }
  30126. function isInlineValueCommentNode(node) {
  30127. return node.type === "value-comment" && node.inline;
  30128. }
  30129. function isHashNode(node) {
  30130. return node.type === "value-word" && node.value === "#";
  30131. }
  30132. function isLeftCurlyBraceNode(node) {
  30133. return node.type === "value-word" && node.value === "{";
  30134. }
  30135. function isRightCurlyBraceNode(node) {
  30136. return node.type === "value-word" && node.value === "}";
  30137. }
  30138. function isWordNode(node) {
  30139. return ["value-word", "value-atword"].indexOf(node.type) !== -1;
  30140. }
  30141. function isColonNode(node) {
  30142. return node.type === "value-colon";
  30143. }
  30144. function isMediaAndSupportsKeywords(node) {
  30145. return node.value && ["not", "and", "or"].indexOf(node.value.toLowerCase()) !== -1;
  30146. }
  30147. function isColorAdjusterFuncNode(node) {
  30148. if (node.type !== "value-func") {
  30149. return false;
  30150. }
  30151. return colorAdjusterFunctions.indexOf(node.value.toLowerCase()) !== -1;
  30152. }
  30153. var utils$3 = {
  30154. getAncestorCounter,
  30155. getAncestorNode,
  30156. getPropOfDeclNode,
  30157. maybeToLowerCase,
  30158. insideValueFunctionNode,
  30159. insideICSSRuleNode,
  30160. insideAtRuleNode,
  30161. insideURLFunctionInImportAtRuleNode,
  30162. isKeyframeAtRuleKeywords,
  30163. isHTMLTag,
  30164. isWideKeywords,
  30165. isSCSS,
  30166. isLastNode,
  30167. isSCSSControlDirectiveNode,
  30168. isDetachedRulesetDeclarationNode,
  30169. isRelationalOperatorNode,
  30170. isEqualityOperatorNode,
  30171. isMultiplicationNode,
  30172. isDivisionNode,
  30173. isAdditionNode,
  30174. isSubtractionNode,
  30175. isModuloNode,
  30176. isMathOperatorNode,
  30177. isEachKeywordNode,
  30178. isForKeywordNode,
  30179. isURLFunctionNode,
  30180. isIfElseKeywordNode,
  30181. hasComposesNode,
  30182. hasParensAroundNode,
  30183. hasEmptyRawBefore,
  30184. isSCSSNestedPropertyNode,
  30185. isDetachedRulesetCallNode,
  30186. isTemplatePlaceholderNode,
  30187. isTemplatePropNode,
  30188. isPostcssSimpleVarNode,
  30189. isKeyValuePairNode,
  30190. isKeyValuePairInParenGroupNode,
  30191. isSCSSMapItemNode,
  30192. isInlineValueCommentNode,
  30193. isHashNode,
  30194. isLeftCurlyBraceNode,
  30195. isRightCurlyBraceNode,
  30196. isWordNode,
  30197. isColonNode,
  30198. isMediaAndSupportsKeywords,
  30199. isColorAdjusterFuncNode
  30200. };
  30201. var insertPragma$3 = pragma$1.insertPragma;
  30202. var printNumber$2 = util.printNumber,
  30203. printString$2 = util.printString,
  30204. hasIgnoreComment$3 = util.hasIgnoreComment,
  30205. hasNewline$4 = util.hasNewline;
  30206. var isNextLineEmpty$3 = utilShared.isNextLineEmpty;
  30207. var _require$$3$builders = doc.builders,
  30208. concat$9 = _require$$3$builders.concat,
  30209. join$6 = _require$$3$builders.join,
  30210. line$3 = _require$$3$builders.line,
  30211. hardline$7 = _require$$3$builders.hardline,
  30212. softline$3 = _require$$3$builders.softline,
  30213. group$6 = _require$$3$builders.group,
  30214. fill$3 = _require$$3$builders.fill,
  30215. indent$5 = _require$$3$builders.indent,
  30216. dedent$2 = _require$$3$builders.dedent,
  30217. ifBreak$2 = _require$$3$builders.ifBreak,
  30218. removeLines$2 = doc.utils.removeLines;
  30219. var getAncestorNode$1 = utils$3.getAncestorNode,
  30220. getPropOfDeclNode$1 = utils$3.getPropOfDeclNode,
  30221. maybeToLowerCase$1 = utils$3.maybeToLowerCase,
  30222. insideValueFunctionNode$1 = utils$3.insideValueFunctionNode,
  30223. insideICSSRuleNode$1 = utils$3.insideICSSRuleNode,
  30224. insideAtRuleNode$1 = utils$3.insideAtRuleNode,
  30225. insideURLFunctionInImportAtRuleNode$1 = utils$3.insideURLFunctionInImportAtRuleNode,
  30226. isKeyframeAtRuleKeywords$1 = utils$3.isKeyframeAtRuleKeywords,
  30227. isHTMLTag$1 = utils$3.isHTMLTag,
  30228. isWideKeywords$1 = utils$3.isWideKeywords,
  30229. isSCSS$1 = utils$3.isSCSS,
  30230. isLastNode$1 = utils$3.isLastNode,
  30231. isSCSSControlDirectiveNode$1 = utils$3.isSCSSControlDirectiveNode,
  30232. isDetachedRulesetDeclarationNode$1 = utils$3.isDetachedRulesetDeclarationNode,
  30233. isRelationalOperatorNode$1 = utils$3.isRelationalOperatorNode,
  30234. isEqualityOperatorNode$1 = utils$3.isEqualityOperatorNode,
  30235. isMultiplicationNode$1 = utils$3.isMultiplicationNode,
  30236. isDivisionNode$1 = utils$3.isDivisionNode,
  30237. isAdditionNode$1 = utils$3.isAdditionNode,
  30238. isSubtractionNode$1 = utils$3.isSubtractionNode,
  30239. isMathOperatorNode$1 = utils$3.isMathOperatorNode,
  30240. isEachKeywordNode$1 = utils$3.isEachKeywordNode,
  30241. isForKeywordNode$1 = utils$3.isForKeywordNode,
  30242. isURLFunctionNode$1 = utils$3.isURLFunctionNode,
  30243. isIfElseKeywordNode$1 = utils$3.isIfElseKeywordNode,
  30244. hasComposesNode$1 = utils$3.hasComposesNode,
  30245. hasParensAroundNode$1 = utils$3.hasParensAroundNode,
  30246. hasEmptyRawBefore$1 = utils$3.hasEmptyRawBefore,
  30247. isKeyValuePairNode$1 = utils$3.isKeyValuePairNode,
  30248. isDetachedRulesetCallNode$1 = utils$3.isDetachedRulesetCallNode,
  30249. isTemplatePlaceholderNode$1 = utils$3.isTemplatePlaceholderNode,
  30250. isTemplatePropNode$1 = utils$3.isTemplatePropNode,
  30251. isPostcssSimpleVarNode$1 = utils$3.isPostcssSimpleVarNode,
  30252. isSCSSMapItemNode$1 = utils$3.isSCSSMapItemNode,
  30253. isInlineValueCommentNode$1 = utils$3.isInlineValueCommentNode,
  30254. isHashNode$1 = utils$3.isHashNode,
  30255. isLeftCurlyBraceNode$1 = utils$3.isLeftCurlyBraceNode,
  30256. isRightCurlyBraceNode$1 = utils$3.isRightCurlyBraceNode,
  30257. isWordNode$1 = utils$3.isWordNode,
  30258. isColonNode$1 = utils$3.isColonNode,
  30259. isMediaAndSupportsKeywords$1 = utils$3.isMediaAndSupportsKeywords,
  30260. isColorAdjusterFuncNode$1 = utils$3.isColorAdjusterFuncNode;
  30261. function shouldPrintComma$1(options) {
  30262. switch (options.trailingComma) {
  30263. case "all":
  30264. case "es5":
  30265. return true;
  30266. case "none":
  30267. default:
  30268. return false;
  30269. }
  30270. }
  30271. function genericPrint$2(path, options, print) {
  30272. var node = path.getValue();
  30273. /* istanbul ignore if */
  30274. if (!node) {
  30275. return "";
  30276. }
  30277. if (typeof node === "string") {
  30278. return node;
  30279. }
  30280. switch (node.type) {
  30281. case "yaml":
  30282. case "toml":
  30283. return concat$9([node.raw, hardline$7]);
  30284. case "css-root":
  30285. {
  30286. var nodes = printNodeSequence(path, options, print);
  30287. if (nodes.parts.length) {
  30288. return concat$9([nodes, hardline$7]);
  30289. }
  30290. return nodes;
  30291. }
  30292. case "css-comment":
  30293. {
  30294. if (node.raws.content) {
  30295. return node.raws.content;
  30296. }
  30297. var text = options.originalText.slice(options.locStart(node), options.locEnd(node));
  30298. var rawText = node.raws.text || node.text; // Workaround a bug where the location is off.
  30299. // https://github.com/postcss/postcss-scss/issues/63
  30300. if (text.indexOf(rawText) === -1) {
  30301. if (node.raws.inline) {
  30302. return concat$9(["// ", rawText]);
  30303. }
  30304. return concat$9(["/* ", rawText, " */"]);
  30305. }
  30306. return text;
  30307. }
  30308. case "css-rule":
  30309. {
  30310. return concat$9([path.call(print, "selector"), node.important ? " !important" : "", node.nodes ? concat$9([" {", node.nodes.length > 0 ? indent$5(concat$9([hardline$7, printNodeSequence(path, options, print)])) : "", hardline$7, "}", isDetachedRulesetDeclarationNode$1(node) ? ";" : ""]) : ";"]);
  30311. }
  30312. case "css-decl":
  30313. {
  30314. var parentNode = path.getParentNode();
  30315. return concat$9([node.raws.before.replace(/[\s;]/g, ""), insideICSSRuleNode$1(path) ? node.prop : maybeToLowerCase$1(node.prop), node.raws.between.trim() === ":" ? ":" : node.raws.between.trim(), node.extend ? "" : " ", hasComposesNode$1(node) ? removeLines$2(path.call(print, "value")) : path.call(print, "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$9([" {", indent$5(concat$9([softline$3, printNodeSequence(path, options, print)])), softline$3, "}"]) : isTemplatePropNode$1(node) && !parentNode.raws.semicolon && options.originalText[options.locEnd(node) - 1] !== ";" ? "" : ";"]);
  30316. }
  30317. case "css-atrule":
  30318. {
  30319. var _parentNode = path.getParentNode();
  30320. return concat$9(["@", // If a Less file ends up being parsed with the SCSS parser, Less
  30321. // variable declarations will be parsed as at-rules with names ending
  30322. // with a colon, so keep the original case then.
  30323. isDetachedRulesetCallNode$1(node) || node.name.endsWith(":") ? node.name : maybeToLowerCase$1(node.name), node.params ? concat$9([isDetachedRulesetCallNode$1(node) ? "" : isTemplatePlaceholderNode$1(node) && /^\s*\n/.test(node.raws.afterName) ? /^\s*\n\s*\n/.test(node.raws.afterName) ? concat$9([hardline$7, hardline$7]) : hardline$7 : " ", path.call(print, "params")]) : "", node.selector ? indent$5(concat$9([" ", path.call(print, "selector")])) : "", node.value ? group$6(concat$9([" ", path.call(print, "value"), isSCSSControlDirectiveNode$1(node) ? hasParensAroundNode$1(node) ? " " : line$3 : ""])) : node.name === "else" ? " " : "", node.nodes ? concat$9([isSCSSControlDirectiveNode$1(node) ? "" : " ", "{", indent$5(concat$9([node.nodes.length > 0 ? softline$3 : "", printNodeSequence(path, options, print)])), softline$3, "}"]) : isTemplatePlaceholderNode$1(node) && !_parentNode.raws.semicolon && options.originalText[options.locEnd(node) - 1] !== ";" ? "" : ";"]);
  30324. }
  30325. // postcss-media-query-parser
  30326. case "media-query-list":
  30327. {
  30328. var parts = [];
  30329. path.each(function (childPath) {
  30330. var node = childPath.getValue();
  30331. if (node.type === "media-query" && node.value === "") {
  30332. return;
  30333. }
  30334. parts.push(childPath.call(print));
  30335. }, "nodes");
  30336. return group$6(indent$5(join$6(line$3, parts)));
  30337. }
  30338. case "media-query":
  30339. {
  30340. return concat$9([join$6(" ", path.map(print, "nodes")), isLastNode$1(path, node) ? "" : ","]);
  30341. }
  30342. case "media-type":
  30343. {
  30344. return adjustNumbers(adjustStrings(node.value, options));
  30345. }
  30346. case "media-feature-expression":
  30347. {
  30348. if (!node.nodes) {
  30349. return node.value;
  30350. }
  30351. return concat$9(["(", concat$9(path.map(print, "nodes")), ")"]);
  30352. }
  30353. case "media-feature":
  30354. {
  30355. return maybeToLowerCase$1(adjustStrings(node.value.replace(/ +/g, " "), options));
  30356. }
  30357. case "media-colon":
  30358. {
  30359. return concat$9([node.value, " "]);
  30360. }
  30361. case "media-value":
  30362. {
  30363. return adjustNumbers(adjustStrings(node.value, options));
  30364. }
  30365. case "media-keyword":
  30366. {
  30367. return adjustStrings(node.value, options);
  30368. }
  30369. case "media-url":
  30370. {
  30371. return adjustStrings(node.value.replace(/^url\(\s+/gi, "url(").replace(/\s+\)$/gi, ")"), options);
  30372. }
  30373. case "media-unknown":
  30374. {
  30375. return node.value;
  30376. }
  30377. // postcss-selector-parser
  30378. case "selector-root":
  30379. {
  30380. return group$6(concat$9([insideAtRuleNode$1(path, "custom-selector") ? concat$9([getAncestorNode$1(path, "css-atrule").customSelector, line$3]) : "", join$6(concat$9([",", insideAtRuleNode$1(path, ["extend", "custom-selector", "nest"]) ? line$3 : hardline$7]), path.map(print, "nodes"))]));
  30381. }
  30382. case "selector-selector":
  30383. {
  30384. return group$6(indent$5(concat$9(path.map(print, "nodes"))));
  30385. }
  30386. case "selector-comment":
  30387. {
  30388. return node.value;
  30389. }
  30390. case "selector-string":
  30391. {
  30392. return adjustStrings(node.value, options);
  30393. }
  30394. case "selector-tag":
  30395. {
  30396. var _parentNode2 = path.getParentNode();
  30397. var index = _parentNode2 && _parentNode2.nodes.indexOf(node);
  30398. var prevNode = index && _parentNode2.nodes[index - 1];
  30399. return concat$9([node.namespace ? concat$9([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", prevNode.type === "selector-nesting" ? node.value : adjustNumbers(isHTMLTag$1(node.value) || isKeyframeAtRuleKeywords$1(path, node.value) ? node.value.toLowerCase() : node.value)]);
  30400. }
  30401. case "selector-id":
  30402. {
  30403. return concat$9(["#", node.value]);
  30404. }
  30405. case "selector-class":
  30406. {
  30407. return concat$9([".", adjustNumbers(adjustStrings(node.value, options))]);
  30408. }
  30409. case "selector-attribute":
  30410. {
  30411. return concat$9(["[", node.namespace ? concat$9([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" : "", "]"]);
  30412. }
  30413. case "selector-combinator":
  30414. {
  30415. if (node.value === "+" || node.value === ">" || node.value === "~" || node.value === ">>>") {
  30416. var _parentNode3 = path.getParentNode();
  30417. var _leading = _parentNode3.type === "selector-selector" && _parentNode3.nodes[0] === node ? "" : line$3;
  30418. return concat$9([_leading, node.value, isLastNode$1(path, node) ? "" : " "]);
  30419. }
  30420. var leading = node.value.trim().startsWith("(") ? line$3 : "";
  30421. var value = adjustNumbers(adjustStrings(node.value.trim(), options)) || line$3;
  30422. return concat$9([leading, value]);
  30423. }
  30424. case "selector-universal":
  30425. {
  30426. return concat$9([node.namespace ? concat$9([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", node.value]);
  30427. }
  30428. case "selector-pseudo":
  30429. {
  30430. return concat$9([maybeToLowerCase$1(node.value), node.nodes && node.nodes.length > 0 ? concat$9(["(", join$6(", ", path.map(print, "nodes")), ")"]) : ""]);
  30431. }
  30432. case "selector-nesting":
  30433. {
  30434. return node.value;
  30435. }
  30436. case "selector-unknown":
  30437. {
  30438. var ruleAncestorNode = getAncestorNode$1(path, "css-rule"); // Nested SCSS property
  30439. if (ruleAncestorNode && ruleAncestorNode.isSCSSNesterProperty) {
  30440. return adjustNumbers(adjustStrings(maybeToLowerCase$1(node.value), options));
  30441. }
  30442. return node.value;
  30443. }
  30444. // postcss-values-parser
  30445. case "value-value":
  30446. case "value-root":
  30447. {
  30448. return path.call(print, "group");
  30449. }
  30450. case "value-comment":
  30451. {
  30452. return concat$9([node.inline ? "//" : "/*", node.value, node.inline ? "" : "*/"]);
  30453. }
  30454. case "value-comma_group":
  30455. {
  30456. var _parentNode4 = path.getParentNode();
  30457. var parentParentNode = path.getParentNode(1);
  30458. var declAncestorProp = getPropOfDeclNode$1(path);
  30459. var isGridValue = declAncestorProp && _parentNode4.type === "value-value" && (declAncestorProp === "grid" || declAncestorProp.startsWith("grid-template"));
  30460. var atRuleAncestorNode = getAncestorNode$1(path, "css-atrule");
  30461. var isControlDirective = atRuleAncestorNode && isSCSSControlDirectiveNode$1(atRuleAncestorNode);
  30462. var printed = path.map(print, "groups");
  30463. var _parts = [];
  30464. var insideURLFunction = insideValueFunctionNode$1(path, "url");
  30465. var insideSCSSInterpolationInString = false;
  30466. var didBreak = false;
  30467. for (var i = 0; i < node.groups.length; ++i) {
  30468. _parts.push(printed[i]); // Ignore value inside `url()`
  30469. if (insideURLFunction) {
  30470. continue;
  30471. }
  30472. var iPrevNode = node.groups[i - 1];
  30473. var iNode = node.groups[i];
  30474. var iNextNode = node.groups[i + 1];
  30475. var iNextNextNode = node.groups[i + 2]; // Ignore after latest node (i.e. before semicolon)
  30476. if (!iNextNode) {
  30477. continue;
  30478. } // Ignore spaces before/after string interpolation (i.e. `"#{my-fn("_")}"`)
  30479. var isStartSCSSInterpolationInString = iNode.type === "value-string" && iNode.value.startsWith("#{");
  30480. var isEndingSCSSInterpolationInString = insideSCSSInterpolationInString && iNextNode.type === "value-string" && iNextNode.value.endsWith("}");
  30481. if (isStartSCSSInterpolationInString || isEndingSCSSInterpolationInString) {
  30482. insideSCSSInterpolationInString = !insideSCSSInterpolationInString;
  30483. continue;
  30484. }
  30485. if (insideSCSSInterpolationInString) {
  30486. continue;
  30487. } // Ignore colon (i.e. `:`)
  30488. if (isColonNode$1(iNode) || isColonNode$1(iNextNode)) {
  30489. continue;
  30490. } // Ignore `@` in Less (i.e. `@@var;`)
  30491. if (iNode.type === "value-atword" && iNode.value === "") {
  30492. continue;
  30493. } // Ignore `~` in Less (i.e. `content: ~"^//* some horrible but needed css hack";`)
  30494. if (iNode.value === "~") {
  30495. continue;
  30496. } // Ignore escape `\`
  30497. if (iNode.value && iNode.value.indexOf("\\") !== -1 && iNextNode && iNextNode.type !== "value-comment") {
  30498. continue;
  30499. } // Ignore escaped `/`
  30500. if (iPrevNode && iPrevNode.value && iPrevNode.value.indexOf("\\") === iPrevNode.value.length - 1 && iNode.type === "value-operator" && iNode.value === "/") {
  30501. continue;
  30502. } // Ignore `\` (i.e. `$variable: \@small;`)
  30503. if (iNode.value === "\\") {
  30504. continue;
  30505. } // Ignore `$$` (i.e. `background-color: $$(style)Color;`)
  30506. if (isPostcssSimpleVarNode$1(iNode, iNextNode)) {
  30507. continue;
  30508. } // Ignore spaces after `#` and after `{` and before `}` in SCSS interpolation (i.e. `#{variable}`)
  30509. if (isHashNode$1(iNode) || isLeftCurlyBraceNode$1(iNode) || isRightCurlyBraceNode$1(iNextNode) || isLeftCurlyBraceNode$1(iNextNode) && hasEmptyRawBefore$1(iNextNode) || isRightCurlyBraceNode$1(iNode) && hasEmptyRawBefore$1(iNextNode)) {
  30510. continue;
  30511. } // Ignore css variables and interpolation in SCSS (i.e. `--#{$var}`)
  30512. if (iNode.value === "--" && isHashNode$1(iNextNode)) {
  30513. continue;
  30514. } // Formatting math operations
  30515. var isMathOperator = isMathOperatorNode$1(iNode);
  30516. var isNextMathOperator = isMathOperatorNode$1(iNextNode); // Print spaces before and after math operators beside SCSS interpolation as is
  30517. // (i.e. `#{$var}+5`, `#{$var} +5`, `#{$var}+ 5`, `#{$var} + 5`)
  30518. // (i.e. `5+#{$var}`, `5 +#{$var}`, `5+ #{$var}`, `5 + #{$var}`)
  30519. if ((isMathOperator && isHashNode$1(iNextNode) || isNextMathOperator && isRightCurlyBraceNode$1(iNode)) && hasEmptyRawBefore$1(iNextNode)) {
  30520. continue;
  30521. } // Print spaces before and after addition and subtraction math operators as is in `calc` function
  30522. // due to the fact that it is not valid syntax
  30523. // (i.e. `calc(1px+1px)`, `calc(1px+ 1px)`, `calc(1px +1px)`, `calc(1px + 1px)`)
  30524. if (insideValueFunctionNode$1(path, "calc") && (isAdditionNode$1(iNode) || isAdditionNode$1(iNextNode) || isSubtractionNode$1(iNode) || isSubtractionNode$1(iNextNode)) && hasEmptyRawBefore$1(iNextNode)) {
  30525. continue;
  30526. } // Print spaces after `+` and `-` in color adjuster functions as is (e.g. `color(red l(+ 20%))`)
  30527. // Adjusters with signed numbers (e.g. `color(red l(+20%))`) output as-is.
  30528. var isColorAdjusterNode = (isAdditionNode$1(iNode) || isSubtractionNode$1(iNode)) && i === 0 && (iNextNode.type === "value-number" || iNextNode.isHex) && parentParentNode && isColorAdjusterFuncNode$1(parentParentNode) && !hasEmptyRawBefore$1(iNextNode);
  30529. var requireSpaceBeforeOperator = iNextNextNode && iNextNextNode.type === "value-func" || iNextNextNode && isWordNode$1(iNextNextNode) || iNode.type === "value-func" || isWordNode$1(iNode);
  30530. var requireSpaceAfterOperator = iNextNode.type === "value-func" || isWordNode$1(iNextNode) || iPrevNode && iPrevNode.type === "value-func" || iPrevNode && isWordNode$1(iPrevNode); // Formatting `/`, `+`, `-` sign
  30531. 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)))) {
  30532. continue;
  30533. } // Add `hardline` after inline comment (i.e. `// comment\n foo: bar;`)
  30534. if (isInlineValueCommentNode$1(iNode)) {
  30535. _parts.push(hardline$7);
  30536. continue;
  30537. } // Handle keywords in SCSS control directive
  30538. if (isControlDirective && (isEqualityOperatorNode$1(iNextNode) || isRelationalOperatorNode$1(iNextNode) || isIfElseKeywordNode$1(iNextNode) || isEachKeywordNode$1(iNode) || isForKeywordNode$1(iNode))) {
  30539. _parts.push(" ");
  30540. continue;
  30541. } // At-rule `namespace` should be in one line
  30542. if (atRuleAncestorNode && atRuleAncestorNode.name.toLowerCase() === "namespace") {
  30543. _parts.push(" ");
  30544. continue;
  30545. } // Formatting `grid` property
  30546. if (isGridValue) {
  30547. if (iNode.source && iNextNode.source && iNode.source.start.line !== iNextNode.source.start.line) {
  30548. _parts.push(hardline$7);
  30549. didBreak = true;
  30550. } else {
  30551. _parts.push(" ");
  30552. }
  30553. continue;
  30554. } // Add `space` before next math operation
  30555. // Note: `grip` property have `/` delimiter and it is not math operation, so
  30556. // `grid` property handles above
  30557. if (isNextMathOperator) {
  30558. _parts.push(" ");
  30559. continue;
  30560. } // Be default all values go through `line`
  30561. _parts.push(line$3);
  30562. }
  30563. if (didBreak) {
  30564. _parts.unshift(hardline$7);
  30565. }
  30566. if (isControlDirective) {
  30567. return group$6(indent$5(concat$9(_parts)));
  30568. } // Indent is not needed for import url when url is very long
  30569. // and node has two groups
  30570. // when type is value-comma_group
  30571. // example @import url("verylongurl") projection,tv
  30572. if (insideURLFunctionInImportAtRuleNode$1(path)) {
  30573. return group$6(fill$3(_parts));
  30574. }
  30575. return group$6(indent$5(fill$3(_parts)));
  30576. }
  30577. case "value-paren_group":
  30578. {
  30579. var _parentNode5 = path.getParentNode();
  30580. if (_parentNode5 && isURLFunctionNode$1(_parentNode5) && (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:"))) {
  30581. return concat$9([node.open ? path.call(print, "open") : "", join$6(",", path.map(print, "groups")), node.close ? path.call(print, "close") : ""]);
  30582. }
  30583. if (!node.open) {
  30584. var _printed = path.map(print, "groups");
  30585. var res = [];
  30586. for (var _i = 0; _i < _printed.length; _i++) {
  30587. if (_i !== 0) {
  30588. res.push(concat$9([",", line$3]));
  30589. }
  30590. res.push(_printed[_i]);
  30591. }
  30592. return group$6(indent$5(fill$3(res)));
  30593. }
  30594. var isSCSSMapItem = isSCSSMapItemNode$1(path);
  30595. return group$6(concat$9([node.open ? path.call(print, "open") : "", indent$5(concat$9([softline$3, join$6(concat$9([",", line$3]), path.map(function (childPath) {
  30596. var node = childPath.getValue();
  30597. var printed = print(childPath); // Key/Value pair in open paren already indented
  30598. if (isKeyValuePairNode$1(node) && node.type === "value-comma_group" && node.groups && node.groups[2] && node.groups[2].type === "value-paren_group") {
  30599. printed.contents.contents.parts[1] = group$6(printed.contents.contents.parts[1]);
  30600. return group$6(dedent$2(printed));
  30601. }
  30602. return printed;
  30603. }, "groups"))])), ifBreak$2(isSCSS$1(options.parser, options.originalText) && isSCSSMapItem && shouldPrintComma$1(options) ? "," : ""), softline$3, node.close ? path.call(print, "close") : ""]), {
  30604. shouldBreak: isSCSSMapItem
  30605. });
  30606. }
  30607. case "value-func":
  30608. {
  30609. return concat$9([node.value, insideAtRuleNode$1(path, "supports") && isMediaAndSupportsKeywords$1(node) ? " " : "", path.call(print, "group")]);
  30610. }
  30611. case "value-paren":
  30612. {
  30613. return node.value;
  30614. }
  30615. case "value-number":
  30616. {
  30617. return concat$9([printCssNumber(node.value), maybeToLowerCase$1(node.unit)]);
  30618. }
  30619. case "value-operator":
  30620. {
  30621. return node.value;
  30622. }
  30623. case "value-word":
  30624. {
  30625. if (node.isColor && node.isHex || isWideKeywords$1(node.value)) {
  30626. return node.value.toLowerCase();
  30627. }
  30628. return node.value;
  30629. }
  30630. case "value-colon":
  30631. {
  30632. return concat$9([node.value, // Don't add spaces on `:` in `url` function (i.e. `url(fbglyph: cross-outline, fig-white)`)
  30633. insideValueFunctionNode$1(path, "url") ? "" : line$3]);
  30634. }
  30635. case "value-comma":
  30636. {
  30637. return concat$9([node.value, " "]);
  30638. }
  30639. case "value-string":
  30640. {
  30641. return printString$2(node.raws.quote + node.value + node.raws.quote, options);
  30642. }
  30643. case "value-atword":
  30644. {
  30645. return concat$9(["@", node.value]);
  30646. }
  30647. case "value-unicode-range":
  30648. {
  30649. return node.value;
  30650. }
  30651. case "value-unknown":
  30652. {
  30653. return node.value;
  30654. }
  30655. default:
  30656. /* istanbul ignore next */
  30657. throw new Error(`Unknown postcss type ${JSON.stringify(node.type)}`);
  30658. }
  30659. }
  30660. function printNodeSequence(path, options, print) {
  30661. var node = path.getValue();
  30662. var parts = [];
  30663. var i = 0;
  30664. path.map(function (pathChild) {
  30665. var prevNode = node.nodes[i - 1];
  30666. if (prevNode && prevNode.type === "css-comment" && prevNode.text.trim() === "prettier-ignore") {
  30667. var childNode = pathChild.getValue();
  30668. parts.push(options.originalText.slice(options.locStart(childNode), options.locEnd(childNode)));
  30669. } else {
  30670. parts.push(pathChild.call(print));
  30671. }
  30672. if (i !== node.nodes.length - 1) {
  30673. if (node.nodes[i + 1].type === "css-comment" && !hasNewline$4(options.originalText, options.locStart(node.nodes[i + 1]), {
  30674. backwards: true
  30675. }) && node.nodes[i].type !== "yaml" && node.nodes[i].type !== "toml" || node.nodes[i + 1].type === "css-atrule" && node.nodes[i + 1].name === "else" && node.nodes[i].type !== "css-comment") {
  30676. parts.push(" ");
  30677. } else {
  30678. parts.push(hardline$7);
  30679. if (isNextLineEmpty$3(options.originalText, pathChild.getValue(), options) && node.nodes[i].type !== "yaml" && node.nodes[i].type !== "toml") {
  30680. parts.push(hardline$7);
  30681. }
  30682. }
  30683. }
  30684. i++;
  30685. }, "nodes");
  30686. return concat$9(parts);
  30687. }
  30688. var STRING_REGEX$1 = /(['"])(?:(?!\1)[^\\]|\\[\s\S])*\1/g;
  30689. var NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g;
  30690. var STANDARD_UNIT_REGEX = /[a-zA-Z]+/g;
  30691. var WORD_PART_REGEX = /[$@]?[a-zA-Z_\u0080-\uFFFF][\w\-\u0080-\uFFFF]*/g;
  30692. var ADJUST_NUMBERS_REGEX = RegExp(STRING_REGEX$1.source + `|` + `(${WORD_PART_REGEX.source})?` + `(${NUMBER_REGEX.source})` + `(${STANDARD_UNIT_REGEX.source})?`, "g");
  30693. function adjustStrings(value, options) {
  30694. return value.replace(STRING_REGEX$1, function (match) {
  30695. return printString$2(match, options);
  30696. });
  30697. }
  30698. function quoteAttributeValue(value, options) {
  30699. var quote = options.singleQuote ? "'" : '"';
  30700. return value.includes('"') || value.includes("'") ? value : quote + value + quote;
  30701. }
  30702. function adjustNumbers(value) {
  30703. return value.replace(ADJUST_NUMBERS_REGEX, function (match, quote, wordPart, number, unit) {
  30704. return !wordPart && number ? (wordPart || "") + printCssNumber(number) + maybeToLowerCase$1(unit || "") : match;
  30705. });
  30706. }
  30707. function printCssNumber(rawNumber) {
  30708. return printNumber$2(rawNumber) // Remove trailing `.0`.
  30709. .replace(/\.0(?=$|e)/, "");
  30710. }
  30711. var printerPostcss = {
  30712. print: genericPrint$2,
  30713. embed: embed_1$1,
  30714. insertPragma: insertPragma$3,
  30715. hasPrettierIgnore: hasIgnoreComment$3,
  30716. massageAstNode: clean_1$1
  30717. };
  30718. var options$3 = {
  30719. singleQuote: commonOptions.singleQuote
  30720. };
  30721. var name$9 = "CSS";
  30722. var type$7 = "markup";
  30723. var tmScope$7 = "source.css";
  30724. var aceMode$7 = "css";
  30725. var codemirrorMode$7 = "css";
  30726. var codemirrorMimeType$7 = "text/css";
  30727. var color$2 = "#563d7c";
  30728. var extensions$7 = [
  30729. ".css"
  30730. ];
  30731. var languageId$7 = 50;
  30732. var CSS = {
  30733. name: name$9,
  30734. type: type$7,
  30735. tmScope: tmScope$7,
  30736. aceMode: aceMode$7,
  30737. codemirrorMode: codemirrorMode$7,
  30738. codemirrorMimeType: codemirrorMimeType$7,
  30739. color: color$2,
  30740. extensions: extensions$7,
  30741. languageId: languageId$7
  30742. };
  30743. var CSS$1 = /*#__PURE__*/Object.freeze({
  30744. __proto__: null,
  30745. name: name$9,
  30746. type: type$7,
  30747. tmScope: tmScope$7,
  30748. aceMode: aceMode$7,
  30749. codemirrorMode: codemirrorMode$7,
  30750. codemirrorMimeType: codemirrorMimeType$7,
  30751. color: color$2,
  30752. extensions: extensions$7,
  30753. languageId: languageId$7,
  30754. 'default': CSS
  30755. });
  30756. var name$a = "PostCSS";
  30757. var type$8 = "markup";
  30758. var tmScope$8 = "source.postcss";
  30759. var group$7 = "CSS";
  30760. var extensions$8 = [
  30761. ".pcss"
  30762. ];
  30763. var aceMode$8 = "text";
  30764. var languageId$8 = 262764437;
  30765. var PostCSS = {
  30766. name: name$a,
  30767. type: type$8,
  30768. tmScope: tmScope$8,
  30769. group: group$7,
  30770. extensions: extensions$8,
  30771. aceMode: aceMode$8,
  30772. languageId: languageId$8
  30773. };
  30774. var PostCSS$1 = /*#__PURE__*/Object.freeze({
  30775. __proto__: null,
  30776. name: name$a,
  30777. type: type$8,
  30778. tmScope: tmScope$8,
  30779. group: group$7,
  30780. extensions: extensions$8,
  30781. aceMode: aceMode$8,
  30782. languageId: languageId$8,
  30783. 'default': PostCSS
  30784. });
  30785. var name$b = "Less";
  30786. var type$9 = "markup";
  30787. var group$8 = "CSS";
  30788. var extensions$9 = [
  30789. ".less"
  30790. ];
  30791. var tmScope$9 = "source.css.less";
  30792. var aceMode$9 = "less";
  30793. var codemirrorMode$8 = "css";
  30794. var codemirrorMimeType$8 = "text/css";
  30795. var languageId$9 = 198;
  30796. var Less = {
  30797. name: name$b,
  30798. type: type$9,
  30799. group: group$8,
  30800. extensions: extensions$9,
  30801. tmScope: tmScope$9,
  30802. aceMode: aceMode$9,
  30803. codemirrorMode: codemirrorMode$8,
  30804. codemirrorMimeType: codemirrorMimeType$8,
  30805. languageId: languageId$9
  30806. };
  30807. var Less$1 = /*#__PURE__*/Object.freeze({
  30808. __proto__: null,
  30809. name: name$b,
  30810. type: type$9,
  30811. group: group$8,
  30812. extensions: extensions$9,
  30813. tmScope: tmScope$9,
  30814. aceMode: aceMode$9,
  30815. codemirrorMode: codemirrorMode$8,
  30816. codemirrorMimeType: codemirrorMimeType$8,
  30817. languageId: languageId$9,
  30818. 'default': Less
  30819. });
  30820. var name$c = "SCSS";
  30821. var type$a = "markup";
  30822. var tmScope$a = "source.css.scss";
  30823. var group$9 = "CSS";
  30824. var aceMode$a = "scss";
  30825. var codemirrorMode$9 = "css";
  30826. var codemirrorMimeType$9 = "text/x-scss";
  30827. var extensions$a = [
  30828. ".scss"
  30829. ];
  30830. var languageId$a = 329;
  30831. var SCSS = {
  30832. name: name$c,
  30833. type: type$a,
  30834. tmScope: tmScope$a,
  30835. group: group$9,
  30836. aceMode: aceMode$a,
  30837. codemirrorMode: codemirrorMode$9,
  30838. codemirrorMimeType: codemirrorMimeType$9,
  30839. extensions: extensions$a,
  30840. languageId: languageId$a
  30841. };
  30842. var SCSS$1 = /*#__PURE__*/Object.freeze({
  30843. __proto__: null,
  30844. name: name$c,
  30845. type: type$a,
  30846. tmScope: tmScope$a,
  30847. group: group$9,
  30848. aceMode: aceMode$a,
  30849. codemirrorMode: codemirrorMode$9,
  30850. codemirrorMimeType: codemirrorMimeType$9,
  30851. extensions: extensions$a,
  30852. languageId: languageId$a,
  30853. 'default': SCSS
  30854. });
  30855. var require$$0$2 = getCjsExportFromNamespace(CSS$1);
  30856. var require$$1$1 = getCjsExportFromNamespace(PostCSS$1);
  30857. var require$$2$1 = getCjsExportFromNamespace(Less$1);
  30858. var require$$3$1 = getCjsExportFromNamespace(SCSS$1);
  30859. var languages$1 = [createLanguage(require$$0$2, function (data) {
  30860. return Object.assign(data, {
  30861. since: "1.4.0",
  30862. parsers: ["css"],
  30863. vscodeLanguageIds: ["css"]
  30864. });
  30865. }), createLanguage(require$$1$1, function (data) {
  30866. return Object.assign(data, {
  30867. since: "1.4.0",
  30868. parsers: ["css"],
  30869. vscodeLanguageIds: ["postcss"],
  30870. extensions: data.extensions.concat(".postcss")
  30871. });
  30872. }), createLanguage(require$$2$1, function (data) {
  30873. return Object.assign(data, {
  30874. since: "1.4.0",
  30875. parsers: ["less"],
  30876. vscodeLanguageIds: ["less"]
  30877. });
  30878. }), createLanguage(require$$3$1, function (data) {
  30879. return Object.assign(data, {
  30880. since: "1.4.0",
  30881. parsers: ["scss"],
  30882. vscodeLanguageIds: ["scss"]
  30883. });
  30884. })];
  30885. var printers$1 = {
  30886. postcss: printerPostcss
  30887. };
  30888. var languageCss = {
  30889. languages: languages$1,
  30890. options: options$3,
  30891. printers: printers$1
  30892. };
  30893. var _require$$0$builders$4 = doc.builders,
  30894. concat$a = _require$$0$builders$4.concat,
  30895. join$7 = _require$$0$builders$4.join,
  30896. softline$4 = _require$$0$builders$4.softline,
  30897. hardline$8 = _require$$0$builders$4.hardline,
  30898. line$4 = _require$$0$builders$4.line,
  30899. group$a = _require$$0$builders$4.group,
  30900. indent$6 = _require$$0$builders$4.indent,
  30901. ifBreak$3 = _require$$0$builders$4.ifBreak; // http://w3c.github.io/html/single-page.html#void-elements
  30902. var voidTags = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]; // Formatter based on @glimmerjs/syntax's built-in test formatter:
  30903. // https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts
  30904. function printChildren(path, options, print) {
  30905. return concat$a(path.map(function (childPath, childIndex) {
  30906. var childNode = path.getValue();
  30907. var isFirstNode = childIndex === 0;
  30908. var isLastNode = childIndex == path.getParentNode(0).children.length - 1;
  30909. var isLastNodeInMultiNodeList = isLastNode && !isFirstNode;
  30910. var isWhitespace = isWhitespaceNode(childNode);
  30911. if (isWhitespace && isLastNodeInMultiNodeList) {
  30912. return print(childPath, options, print);
  30913. } else if (isFirstNode) {
  30914. return concat$a([softline$4, print(childPath, options, print)]);
  30915. }
  30916. return print(childPath, options, print);
  30917. }, "children"));
  30918. }
  30919. function print(path, options, print) {
  30920. var n = path.getValue();
  30921. /* istanbul ignore if*/
  30922. if (!n) {
  30923. return "";
  30924. }
  30925. switch (n.type) {
  30926. case "Block":
  30927. case "Program":
  30928. case "Template":
  30929. {
  30930. return group$a(concat$a(path.map(print, "body").filter(function (text) {
  30931. return text !== "";
  30932. })));
  30933. }
  30934. case "ElementNode":
  30935. {
  30936. var tagFirstChar = n.tag[0];
  30937. var isLocal = n.tag.indexOf(".") !== -1;
  30938. var isGlimmerComponent = tagFirstChar.toUpperCase() === tagFirstChar || isLocal;
  30939. var hasChildren = n.children.length > 0;
  30940. var hasNonWhitespaceChildren = n.children.some(function (n) {
  30941. return !isWhitespaceNode(n);
  30942. });
  30943. var isVoid = isGlimmerComponent && (!hasChildren || !hasNonWhitespaceChildren) || voidTags.indexOf(n.tag) !== -1;
  30944. var closeTagForNoBreak = isVoid ? concat$a([" />", softline$4]) : ">";
  30945. var closeTagForBreak = isVoid ? "/>" : ">";
  30946. var _getParams = function _getParams(path, print) {
  30947. return indent$6(concat$a([n.attributes.length ? line$4 : "", join$7(line$4, path.map(print, "attributes")), n.modifiers.length ? line$4 : "", join$7(line$4, path.map(print, "modifiers")), n.comments.length ? line$4 : "", join$7(line$4, path.map(print, "comments"))]));
  30948. };
  30949. var nextNode = getNextNode(path);
  30950. return concat$a([group$a(concat$a(["<", n.tag, _getParams(path, print), n.blockParams.length ? ` as |${n.blockParams.join(" ")}|` : "", ifBreak$3(softline$4, ""), ifBreak$3(closeTagForBreak, closeTagForNoBreak)])), !isVoid ? group$a(concat$a([hasNonWhitespaceChildren ? indent$6(printChildren(path, options, print)) : "", ifBreak$3(hasChildren ? hardline$8 : "", ""), concat$a(["</", n.tag, ">"])])) : "", nextNode && nextNode.type === "ElementNode" ? hardline$8 : ""]);
  30951. }
  30952. case "BlockStatement":
  30953. {
  30954. var pp = path.getParentNode(1);
  30955. var isElseIf = pp && pp.inverse && pp.inverse.body.length === 1 && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
  30956. var hasElseIf = n.inverse && n.inverse.body.length === 1 && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
  30957. var indentElse = hasElseIf ? function (a) {
  30958. return a;
  30959. } : indent$6;
  30960. if (n.inverse) {
  30961. return concat$a([isElseIf ? concat$a(["{{else ", printPathParams(path, print), "}}"]) : printOpenBlock(path, print), indent$6(concat$a([hardline$8, path.call(print, "program")])), n.inverse && !hasElseIf ? concat$a([hardline$8, "{{else}}"]) : "", n.inverse ? indentElse(concat$a([hardline$8, path.call(print, "inverse")])) : "", isElseIf ? "" : concat$a([hardline$8, printCloseBlock(path, print)])]);
  30962. } else if (isElseIf) {
  30963. return concat$a([concat$a(["{{else ", printPathParams(path, print), "}}"]), indent$6(concat$a([hardline$8, path.call(print, "program")]))]);
  30964. }
  30965. var _hasNonWhitespaceChildren = n.program.body.some(function (n) {
  30966. return !isWhitespaceNode(n);
  30967. });
  30968. return concat$a([printOpenBlock(path, print), group$a(concat$a([indent$6(concat$a([softline$4, path.call(print, "program")])), _hasNonWhitespaceChildren ? hardline$8 : softline$4, printCloseBlock(path, print)]))]);
  30969. }
  30970. case "ElementModifierStatement":
  30971. case "MustacheStatement":
  30972. {
  30973. var _pp = path.getParentNode(1);
  30974. var isConcat = _pp && _pp.type === "ConcatStatement";
  30975. return group$a(concat$a([n.escaped === false ? "{{{" : "{{", printPathParams(path, print, {
  30976. group: false
  30977. }), isConcat ? "" : softline$4, n.escaped === false ? "}}}" : "}}"]));
  30978. }
  30979. case "SubExpression":
  30980. {
  30981. var params = getParams(path, print);
  30982. var printedParams = params.length > 0 ? indent$6(concat$a([line$4, group$a(join$7(line$4, params))])) : "";
  30983. return group$a(concat$a(["(", printPath(path, print), printedParams, softline$4, ")"]));
  30984. }
  30985. case "AttrNode":
  30986. {
  30987. var isText = n.value.type === "TextNode";
  30988. if (isText && n.value.loc.start.column === n.value.loc.end.column) {
  30989. return concat$a([n.name]);
  30990. }
  30991. var value = path.call(print, "value");
  30992. var quotedValue = isText ? printStringLiteral(value.parts.join(), options) : value;
  30993. return concat$a([n.name, "=", quotedValue]);
  30994. }
  30995. case "ConcatStatement":
  30996. {
  30997. return concat$a(['"', group$a(indent$6(join$7(softline$4, path.map(function (partPath) {
  30998. return print(partPath);
  30999. }, "parts").filter(function (a) {
  31000. return a !== "";
  31001. })))), '"']);
  31002. }
  31003. case "Hash":
  31004. {
  31005. return concat$a([join$7(line$4, path.map(print, "pairs"))]);
  31006. }
  31007. case "HashPair":
  31008. {
  31009. return concat$a([n.key, "=", path.call(print, "value")]);
  31010. }
  31011. case "TextNode":
  31012. {
  31013. var maxLineBreaksToPreserve = 2;
  31014. var isFirstElement = !getPreviousNode(path);
  31015. var isLastElement = !getNextNode(path);
  31016. var isWhitespaceOnly = !/\S/.test(n.chars);
  31017. var lineBreaksCount = countNewLines(n.chars);
  31018. var hasBlockParent = path.getParentNode(0).type === "Block";
  31019. var hasElementParent = path.getParentNode(0).type === "ElementNode";
  31020. var hasTemplateParent = path.getParentNode(0).type === "Template";
  31021. var leadingLineBreaksCount = countLeadingNewLines(n.chars);
  31022. var trailingLineBreaksCount = countTrailingNewLines(n.chars);
  31023. if ((isFirstElement || isLastElement) && isWhitespaceOnly && (hasBlockParent || hasElementParent || hasTemplateParent)) {
  31024. return "";
  31025. }
  31026. if (isWhitespaceOnly && lineBreaksCount) {
  31027. leadingLineBreaksCount = Math.min(lineBreaksCount, maxLineBreaksToPreserve);
  31028. trailingLineBreaksCount = 0;
  31029. } else {
  31030. if (isNextNodeOfType(path, "ElementNode") || isNextNodeOfType(path, "BlockStatement")) {
  31031. trailingLineBreaksCount = Math.max(trailingLineBreaksCount, 1);
  31032. }
  31033. if (isPreviousNodeOfSomeType(path, ["ElementNode"]) || isPreviousNodeOfSomeType(path, ["BlockStatement"])) {
  31034. leadingLineBreaksCount = Math.max(leadingLineBreaksCount, 1);
  31035. }
  31036. }
  31037. var leadingSpace = "";
  31038. var trailingSpace = ""; // preserve a space inside of an attribute node where whitespace present,
  31039. // when next to mustache statement.
  31040. var inAttrNode = path.stack.indexOf("attributes") >= 0;
  31041. if (inAttrNode) {
  31042. var parentNode = path.getParentNode(0);
  31043. var _isConcat = parentNode.type === "ConcatStatement";
  31044. if (_isConcat) {
  31045. var parts = parentNode.parts;
  31046. var partIndex = parts.indexOf(n);
  31047. if (partIndex > 0) {
  31048. var partType = parts[partIndex - 1].type;
  31049. var isMustache = partType === "MustacheStatement";
  31050. if (isMustache) {
  31051. leadingSpace = " ";
  31052. }
  31053. }
  31054. if (partIndex < parts.length - 1) {
  31055. var _partType = parts[partIndex + 1].type;
  31056. var _isMustache = _partType === "MustacheStatement";
  31057. if (_isMustache) {
  31058. trailingSpace = " ";
  31059. }
  31060. }
  31061. }
  31062. } else {
  31063. if (trailingLineBreaksCount === 0 && isNextNodeOfType(path, "MustacheStatement")) {
  31064. trailingSpace = " ";
  31065. }
  31066. if (leadingLineBreaksCount === 0 && isPreviousNodeOfSomeType(path, ["MustacheStatement"])) {
  31067. leadingSpace = " ";
  31068. }
  31069. if (isFirstElement) {
  31070. leadingLineBreaksCount = 0;
  31071. leadingSpace = "";
  31072. }
  31073. if (isLastElement) {
  31074. trailingLineBreaksCount = 0;
  31075. trailingSpace = "";
  31076. }
  31077. }
  31078. return concat$a([].concat(_toConsumableArray$1(generateHardlines(leadingLineBreaksCount, maxLineBreaksToPreserve)), [n.chars.replace(/^[\s ]+/g, leadingSpace).replace(/[\s ]+$/, trailingSpace)], _toConsumableArray$1(generateHardlines(trailingLineBreaksCount, maxLineBreaksToPreserve))).filter(Boolean));
  31079. }
  31080. case "MustacheCommentStatement":
  31081. {
  31082. var dashes = n.value.indexOf("}}") > -1 ? "--" : "";
  31083. return concat$a(["{{!", dashes, n.value, dashes, "}}"]);
  31084. }
  31085. case "PathExpression":
  31086. {
  31087. return n.original;
  31088. }
  31089. case "BooleanLiteral":
  31090. {
  31091. return String(n.value);
  31092. }
  31093. case "CommentStatement":
  31094. {
  31095. return concat$a(["<!--", n.value, "-->"]);
  31096. }
  31097. case "StringLiteral":
  31098. {
  31099. return printStringLiteral(n.value, options);
  31100. }
  31101. case "NumberLiteral":
  31102. {
  31103. return String(n.value);
  31104. }
  31105. case "UndefinedLiteral":
  31106. {
  31107. return "undefined";
  31108. }
  31109. case "NullLiteral":
  31110. {
  31111. return "null";
  31112. }
  31113. /* istanbul ignore next */
  31114. default:
  31115. throw new Error("unknown glimmer type: " + JSON.stringify(n.type));
  31116. }
  31117. }
  31118. /**
  31119. * Prints a string literal with the correct surrounding quotes based on
  31120. * `options.singleQuote` and the number of escaped quotes contained in
  31121. * the string literal. This function is the glimmer equivalent of `printString`
  31122. * in `common/util`, but has differences because of the way escaped characters
  31123. * are treated in hbs string literals.
  31124. * @param {string} stringLiteral - the string literal value
  31125. * @param {object} options - the prettier options object
  31126. */
  31127. function printStringLiteral(stringLiteral, options) {
  31128. var double = {
  31129. quote: '"',
  31130. regex: /"/g
  31131. };
  31132. var single = {
  31133. quote: "'",
  31134. regex: /'/g
  31135. };
  31136. var preferred = options.singleQuote ? single : double;
  31137. var alternate = preferred === single ? double : single;
  31138. var shouldUseAlternateQuote = false; // If `stringLiteral` contains at least one of the quote preferred for
  31139. // enclosing the string, we might want to enclose with the alternate quote
  31140. // instead, to minimize the number of escaped quotes.
  31141. if (stringLiteral.includes(preferred.quote) || stringLiteral.includes(alternate.quote)) {
  31142. var numPreferredQuotes = (stringLiteral.match(preferred.regex) || []).length;
  31143. var numAlternateQuotes = (stringLiteral.match(alternate.regex) || []).length;
  31144. shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes;
  31145. }
  31146. var enclosingQuote = shouldUseAlternateQuote ? alternate : preferred;
  31147. var escapedStringLiteral = stringLiteral.replace(enclosingQuote.regex, `\\${enclosingQuote.quote}`);
  31148. return `${enclosingQuote.quote}${escapedStringLiteral}${enclosingQuote.quote}`;
  31149. }
  31150. function printPath(path, print) {
  31151. return path.call(print, "path");
  31152. }
  31153. function getParams(path, print) {
  31154. var node = path.getValue();
  31155. var parts = [];
  31156. if (node.params.length > 0) {
  31157. parts = parts.concat(path.map(print, "params"));
  31158. }
  31159. if (node.hash && node.hash.pairs.length > 0) {
  31160. parts.push(path.call(print, "hash"));
  31161. }
  31162. return parts;
  31163. }
  31164. function printPathParams(path, print, options) {
  31165. var parts = [];
  31166. options = Object.assign({
  31167. group: true
  31168. }, options || {});
  31169. parts.push(printPath(path, print));
  31170. parts = parts.concat(getParams(path, print));
  31171. if (!options.group) {
  31172. return indent$6(join$7(line$4, parts));
  31173. }
  31174. return indent$6(group$a(join$7(line$4, parts)));
  31175. }
  31176. function printBlockParams(path) {
  31177. var block = path.getValue();
  31178. if (!block.program || !block.program.blockParams.length) {
  31179. return "";
  31180. }
  31181. return concat$a([" as |", block.program.blockParams.join(" "), "|"]);
  31182. }
  31183. function printOpenBlock(path, print) {
  31184. return group$a(concat$a(["{{#", printPathParams(path, print), printBlockParams(path), softline$4, "}}"]));
  31185. }
  31186. function printCloseBlock(path, print) {
  31187. return concat$a(["{{/", path.call(print, "path"), "}}"]);
  31188. }
  31189. function isWhitespaceNode(node) {
  31190. return node.type === "TextNode" && !/\S/.test(node.chars);
  31191. }
  31192. function getPreviousNode(path) {
  31193. var node = path.getValue();
  31194. var parentNode = path.getParentNode(0);
  31195. var children = parentNode.children || parentNode.body;
  31196. if (children) {
  31197. var nodeIndex = children.indexOf(node);
  31198. if (nodeIndex > 0) {
  31199. var previousNode = children[nodeIndex - 1];
  31200. return previousNode;
  31201. }
  31202. }
  31203. }
  31204. function getNextNode(path) {
  31205. var node = path.getValue();
  31206. var parentNode = path.getParentNode(0);
  31207. var children = parentNode.children || parentNode.body;
  31208. if (children) {
  31209. var nodeIndex = children.indexOf(node);
  31210. if (nodeIndex < children.length) {
  31211. var nextNode = children[nodeIndex + 1];
  31212. return nextNode;
  31213. }
  31214. }
  31215. }
  31216. function isPreviousNodeOfSomeType(path, types) {
  31217. var previousNode = getPreviousNode(path);
  31218. if (previousNode) {
  31219. return types.some(function (type) {
  31220. return previousNode.type === type;
  31221. });
  31222. }
  31223. return false;
  31224. }
  31225. function isNextNodeOfType(path, type) {
  31226. var nextNode = getNextNode(path);
  31227. return nextNode && nextNode.type === type;
  31228. }
  31229. function clean$3(ast, newObj) {
  31230. delete newObj.loc;
  31231. delete newObj.selfClosing; // (Glimmer/HTML) ignore TextNode whitespace
  31232. if (ast.type === "TextNode") {
  31233. if (ast.chars.replace(/\s+/, "") === "") {
  31234. return null;
  31235. }
  31236. newObj.chars = ast.chars.replace(/^\s+/, "").replace(/\s+$/, "");
  31237. }
  31238. }
  31239. function countNewLines(string) {
  31240. /* istanbul ignore next */
  31241. string = typeof string === "string" ? string : "";
  31242. return string.split("\n").length - 1;
  31243. }
  31244. function countLeadingNewLines(string) {
  31245. /* istanbul ignore next */
  31246. string = typeof string === "string" ? string : "";
  31247. var newLines = (string.match(/^([^\S\r\n]*[\r\n])+/g) || [])[0] || "";
  31248. return countNewLines(newLines);
  31249. }
  31250. function countTrailingNewLines(string) {
  31251. /* istanbul ignore next */
  31252. string = typeof string === "string" ? string : "";
  31253. var newLines = (string.match(/([\r\n][^\S\r\n]*)+$/g) || [])[0] || "";
  31254. return countNewLines(newLines);
  31255. }
  31256. function generateHardlines() {
  31257. var number = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  31258. var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  31259. return new Array(Math.min(number, max)).fill(hardline$8);
  31260. }
  31261. var printerGlimmer = {
  31262. print,
  31263. massageAstNode: clean$3
  31264. };
  31265. var name$d = "Handlebars";
  31266. var type$b = "markup";
  31267. var group$b = "HTML";
  31268. var aliases$3 = [
  31269. "hbs",
  31270. "htmlbars"
  31271. ];
  31272. var extensions$b = [
  31273. ".handlebars",
  31274. ".hbs"
  31275. ];
  31276. var tmScope$b = "text.html.handlebars";
  31277. var aceMode$b = "handlebars";
  31278. var languageId$b = 155;
  31279. var Handlebars = {
  31280. name: name$d,
  31281. type: type$b,
  31282. group: group$b,
  31283. aliases: aliases$3,
  31284. extensions: extensions$b,
  31285. tmScope: tmScope$b,
  31286. aceMode: aceMode$b,
  31287. languageId: languageId$b
  31288. };
  31289. var Handlebars$1 = /*#__PURE__*/Object.freeze({
  31290. __proto__: null,
  31291. name: name$d,
  31292. type: type$b,
  31293. group: group$b,
  31294. aliases: aliases$3,
  31295. extensions: extensions$b,
  31296. tmScope: tmScope$b,
  31297. aceMode: aceMode$b,
  31298. languageId: languageId$b,
  31299. 'default': Handlebars
  31300. });
  31301. var require$$0$3 = getCjsExportFromNamespace(Handlebars$1);
  31302. var languages$2 = [createLanguage(require$$0$3, function (data) {
  31303. return Object.assign(data, {
  31304. since: null,
  31305. // unreleased
  31306. parsers: ["glimmer"],
  31307. vscodeLanguageIds: ["handlebars"]
  31308. });
  31309. })];
  31310. var printers$2 = {
  31311. glimmer: printerGlimmer
  31312. };
  31313. var languageHandlebars = {
  31314. languages: languages$2,
  31315. printers: printers$2
  31316. };
  31317. function hasPragma$2(text) {
  31318. return /^\s*#[^\n\S]*@(format|prettier)\s*(\n|$)/.test(text);
  31319. }
  31320. function insertPragma$4(text) {
  31321. return "# @format\n\n" + text;
  31322. }
  31323. var pragma$2 = {
  31324. hasPragma: hasPragma$2,
  31325. insertPragma: insertPragma$4
  31326. };
  31327. var _require$$0$builders$5 = doc.builders,
  31328. concat$b = _require$$0$builders$5.concat,
  31329. join$8 = _require$$0$builders$5.join,
  31330. hardline$9 = _require$$0$builders$5.hardline,
  31331. line$5 = _require$$0$builders$5.line,
  31332. softline$5 = _require$$0$builders$5.softline,
  31333. group$c = _require$$0$builders$5.group,
  31334. indent$7 = _require$$0$builders$5.indent,
  31335. ifBreak$4 = _require$$0$builders$5.ifBreak;
  31336. var hasIgnoreComment$4 = util.hasIgnoreComment;
  31337. var isNextLineEmpty$4 = utilShared.isNextLineEmpty;
  31338. var insertPragma$5 = pragma$2.insertPragma;
  31339. function genericPrint$3(path, options, print) {
  31340. var n = path.getValue();
  31341. if (!n) {
  31342. return "";
  31343. }
  31344. if (typeof n === "string") {
  31345. return n;
  31346. }
  31347. switch (n.kind) {
  31348. case "Document":
  31349. {
  31350. var parts = [];
  31351. path.map(function (pathChild, index) {
  31352. parts.push(concat$b([pathChild.call(print)]));
  31353. if (index !== n.definitions.length - 1) {
  31354. parts.push(hardline$9);
  31355. if (isNextLineEmpty$4(options.originalText, pathChild.getValue(), options)) {
  31356. parts.push(hardline$9);
  31357. }
  31358. }
  31359. }, "definitions");
  31360. return concat$b([concat$b(parts), hardline$9]);
  31361. }
  31362. case "OperationDefinition":
  31363. {
  31364. var hasOperation = options.originalText[options.locStart(n)] !== "{";
  31365. var hasName = !!n.name;
  31366. return concat$b([hasOperation ? n.operation : "", hasOperation && hasName ? concat$b([" ", path.call(print, "name")]) : "", n.variableDefinitions && n.variableDefinitions.length ? group$c(concat$b(["(", indent$7(concat$b([softline$5, join$8(concat$b([ifBreak$4("", ", "), softline$5]), path.map(print, "variableDefinitions"))])), softline$5, ")"])) : "", printDirectives(path, print, n), n.selectionSet ? !hasOperation && !hasName ? "" : " " : "", path.call(print, "selectionSet")]);
  31367. }
  31368. case "FragmentDefinition":
  31369. {
  31370. return concat$b(["fragment ", path.call(print, "name"), n.variableDefinitions && n.variableDefinitions.length ? group$c(concat$b(["(", indent$7(concat$b([softline$5, join$8(concat$b([ifBreak$4("", ", "), softline$5]), path.map(print, "variableDefinitions"))])), softline$5, ")"])) : "", " on ", path.call(print, "typeCondition"), printDirectives(path, print, n), " ", path.call(print, "selectionSet")]);
  31371. }
  31372. case "SelectionSet":
  31373. {
  31374. return concat$b(["{", indent$7(concat$b([hardline$9, join$8(hardline$9, path.call(function (selectionsPath) {
  31375. return printSequence(selectionsPath, options, print);
  31376. }, "selections"))])), hardline$9, "}"]);
  31377. }
  31378. case "Field":
  31379. {
  31380. return group$c(concat$b([n.alias ? concat$b([path.call(print, "alias"), ": "]) : "", path.call(print, "name"), n.arguments.length > 0 ? group$c(concat$b(["(", indent$7(concat$b([softline$5, join$8(concat$b([ifBreak$4("", ", "), softline$5]), path.call(function (argsPath) {
  31381. return printSequence(argsPath, options, print);
  31382. }, "arguments"))])), softline$5, ")"])) : "", printDirectives(path, print, n), n.selectionSet ? " " : "", path.call(print, "selectionSet")]));
  31383. }
  31384. case "Name":
  31385. {
  31386. return n.value;
  31387. }
  31388. case "StringValue":
  31389. {
  31390. if (n.block) {
  31391. return concat$b(['"""', hardline$9, join$8(hardline$9, n.value.replace(/"""/g, "\\$&").split("\n")), hardline$9, '"""']);
  31392. }
  31393. return concat$b(['"', n.value.replace(/["\\]/g, "\\$&").replace(/\n/g, "\\n"), '"']);
  31394. }
  31395. case "IntValue":
  31396. case "FloatValue":
  31397. case "EnumValue":
  31398. {
  31399. return n.value;
  31400. }
  31401. case "BooleanValue":
  31402. {
  31403. return n.value ? "true" : "false";
  31404. }
  31405. case "NullValue":
  31406. {
  31407. return "null";
  31408. }
  31409. case "Variable":
  31410. {
  31411. return concat$b(["$", path.call(print, "name")]);
  31412. }
  31413. case "ListValue":
  31414. {
  31415. return group$c(concat$b(["[", indent$7(concat$b([softline$5, join$8(concat$b([ifBreak$4("", ", "), softline$5]), path.map(print, "values"))])), softline$5, "]"]));
  31416. }
  31417. case "ObjectValue":
  31418. {
  31419. return group$c(concat$b(["{", options.bracketSpacing && n.fields.length > 0 ? " " : "", indent$7(concat$b([softline$5, join$8(concat$b([ifBreak$4("", ", "), softline$5]), path.map(print, "fields"))])), softline$5, ifBreak$4("", options.bracketSpacing && n.fields.length > 0 ? " " : ""), "}"]));
  31420. }
  31421. case "ObjectField":
  31422. case "Argument":
  31423. {
  31424. return concat$b([path.call(print, "name"), ": ", path.call(print, "value")]);
  31425. }
  31426. case "Directive":
  31427. {
  31428. return concat$b(["@", path.call(print, "name"), n.arguments.length > 0 ? group$c(concat$b(["(", indent$7(concat$b([softline$5, join$8(concat$b([ifBreak$4("", ", "), softline$5]), path.call(function (argsPath) {
  31429. return printSequence(argsPath, options, print);
  31430. }, "arguments"))])), softline$5, ")"])) : ""]);
  31431. }
  31432. case "NamedType":
  31433. {
  31434. return path.call(print, "name");
  31435. }
  31436. case "VariableDefinition":
  31437. {
  31438. return concat$b([path.call(print, "variable"), ": ", path.call(print, "type"), n.defaultValue ? concat$b([" = ", path.call(print, "defaultValue")]) : "", printDirectives(path, print, n)]);
  31439. }
  31440. case "TypeExtensionDefinition":
  31441. {
  31442. return concat$b(["extend ", path.call(print, "definition")]);
  31443. }
  31444. case "ObjectTypeExtension":
  31445. case "ObjectTypeDefinition":
  31446. {
  31447. return concat$b([path.call(print, "description"), n.description ? hardline$9 : "", n.kind === "ObjectTypeExtension" ? "extend " : "", "type ", path.call(print, "name"), n.interfaces.length > 0 ? concat$b([" implements ", join$8(determineInterfaceSeparator(options.originalText.substr(options.locStart(n), options.locEnd(n))), path.map(print, "interfaces"))]) : "", printDirectives(path, print, n), n.fields.length > 0 ? concat$b([" {", indent$7(concat$b([hardline$9, join$8(hardline$9, path.call(function (fieldsPath) {
  31448. return printSequence(fieldsPath, options, print);
  31449. }, "fields"))])), hardline$9, "}"]) : ""]);
  31450. }
  31451. case "FieldDefinition":
  31452. {
  31453. return concat$b([path.call(print, "description"), n.description ? hardline$9 : "", path.call(print, "name"), n.arguments.length > 0 ? group$c(concat$b(["(", indent$7(concat$b([softline$5, join$8(concat$b([ifBreak$4("", ", "), softline$5]), path.call(function (argsPath) {
  31454. return printSequence(argsPath, options, print);
  31455. }, "arguments"))])), softline$5, ")"])) : "", ": ", path.call(print, "type"), printDirectives(path, print, n)]);
  31456. }
  31457. case "DirectiveDefinition":
  31458. {
  31459. return concat$b([path.call(print, "description"), n.description ? hardline$9 : "", "directive ", "@", path.call(print, "name"), n.arguments.length > 0 ? group$c(concat$b(["(", indent$7(concat$b([softline$5, join$8(concat$b([ifBreak$4("", ", "), softline$5]), path.call(function (argsPath) {
  31460. return printSequence(argsPath, options, print);
  31461. }, "arguments"))])), softline$5, ")"])) : "", concat$b([" on ", join$8(" | ", path.map(print, "locations"))])]);
  31462. }
  31463. case "EnumTypeExtension":
  31464. case "EnumTypeDefinition":
  31465. {
  31466. return concat$b([path.call(print, "description"), n.description ? hardline$9 : "", n.kind === "EnumTypeExtension" ? "extend " : "", "enum ", path.call(print, "name"), printDirectives(path, print, n), n.values.length > 0 ? concat$b([" {", indent$7(concat$b([hardline$9, join$8(hardline$9, path.call(function (valuesPath) {
  31467. return printSequence(valuesPath, options, print);
  31468. }, "values"))])), hardline$9, "}"]) : ""]);
  31469. }
  31470. case "EnumValueDefinition":
  31471. {
  31472. return concat$b([path.call(print, "description"), n.description ? hardline$9 : "", path.call(print, "name"), printDirectives(path, print, n)]);
  31473. }
  31474. case "InputValueDefinition":
  31475. {
  31476. return concat$b([path.call(print, "description"), n.description ? n.description.block ? hardline$9 : line$5 : "", path.call(print, "name"), ": ", path.call(print, "type"), n.defaultValue ? concat$b([" = ", path.call(print, "defaultValue")]) : "", printDirectives(path, print, n)]);
  31477. }
  31478. case "InputObjectTypeExtension":
  31479. case "InputObjectTypeDefinition":
  31480. {
  31481. return concat$b([path.call(print, "description"), n.description ? hardline$9 : "", n.kind === "InputObjectTypeExtension" ? "extend " : "", "input ", path.call(print, "name"), printDirectives(path, print, n), n.fields.length > 0 ? concat$b([" {", indent$7(concat$b([hardline$9, join$8(hardline$9, path.call(function (fieldsPath) {
  31482. return printSequence(fieldsPath, options, print);
  31483. }, "fields"))])), hardline$9, "}"]) : ""]);
  31484. }
  31485. case "SchemaDefinition":
  31486. {
  31487. return concat$b(["schema", printDirectives(path, print, n), " {", n.operationTypes.length > 0 ? indent$7(concat$b([hardline$9, join$8(hardline$9, path.call(function (opsPath) {
  31488. return printSequence(opsPath, options, print);
  31489. }, "operationTypes"))])) : "", hardline$9, "}"]);
  31490. }
  31491. case "OperationTypeDefinition":
  31492. {
  31493. return concat$b([path.call(print, "operation"), ": ", path.call(print, "type")]);
  31494. }
  31495. case "InterfaceTypeExtension":
  31496. case "InterfaceTypeDefinition":
  31497. {
  31498. return concat$b([path.call(print, "description"), n.description ? hardline$9 : "", n.kind === "InterfaceTypeExtension" ? "extend " : "", "interface ", path.call(print, "name"), printDirectives(path, print, n), n.fields.length > 0 ? concat$b([" {", indent$7(concat$b([hardline$9, join$8(hardline$9, path.call(function (fieldsPath) {
  31499. return printSequence(fieldsPath, options, print);
  31500. }, "fields"))])), hardline$9, "}"]) : ""]);
  31501. }
  31502. case "FragmentSpread":
  31503. {
  31504. return concat$b(["...", path.call(print, "name"), printDirectives(path, print, n)]);
  31505. }
  31506. case "InlineFragment":
  31507. {
  31508. return concat$b(["...", n.typeCondition ? concat$b([" on ", path.call(print, "typeCondition")]) : "", printDirectives(path, print, n), " ", path.call(print, "selectionSet")]);
  31509. }
  31510. case "UnionTypeExtension":
  31511. case "UnionTypeDefinition":
  31512. {
  31513. return group$c(concat$b([path.call(print, "description"), n.description ? hardline$9 : "", group$c(concat$b([n.kind === "UnionTypeExtension" ? "extend " : "", "union ", path.call(print, "name"), printDirectives(path, print, n), n.types.length > 0 ? concat$b([" =", ifBreak$4("", " "), indent$7(concat$b([ifBreak$4(concat$b([line$5, " "])), join$8(concat$b([line$5, "| "]), path.map(print, "types"))]))]) : ""]))]));
  31514. }
  31515. case "ScalarTypeExtension":
  31516. case "ScalarTypeDefinition":
  31517. {
  31518. return concat$b([path.call(print, "description"), n.description ? hardline$9 : "", n.kind === "ScalarTypeExtension" ? "extend " : "", "scalar ", path.call(print, "name"), printDirectives(path, print, n)]);
  31519. }
  31520. case "NonNullType":
  31521. {
  31522. return concat$b([path.call(print, "type"), "!"]);
  31523. }
  31524. case "ListType":
  31525. {
  31526. return concat$b(["[", path.call(print, "type"), "]"]);
  31527. }
  31528. default:
  31529. /* istanbul ignore next */
  31530. throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
  31531. }
  31532. }
  31533. function printDirectives(path, print, n) {
  31534. if (n.directives.length === 0) {
  31535. return "";
  31536. }
  31537. return concat$b([" ", group$c(indent$7(concat$b([softline$5, join$8(concat$b([ifBreak$4("", " "), softline$5]), path.map(print, "directives"))])))]);
  31538. }
  31539. function printSequence(sequencePath, options, print) {
  31540. var count = sequencePath.getValue().length;
  31541. return sequencePath.map(function (path, i) {
  31542. var printed = print(path);
  31543. if (isNextLineEmpty$4(options.originalText, path.getValue(), options) && i < count - 1) {
  31544. return concat$b([printed, hardline$9]);
  31545. }
  31546. return printed;
  31547. });
  31548. }
  31549. function canAttachComment$1(node) {
  31550. return node.kind && node.kind !== "Comment";
  31551. }
  31552. function printComment$2(commentPath) {
  31553. var comment = commentPath.getValue();
  31554. if (comment.kind === "Comment") {
  31555. return "#" + comment.value.trimRight();
  31556. }
  31557. throw new Error("Not a comment: " + JSON.stringify(comment));
  31558. }
  31559. function determineInterfaceSeparator(originalSource) {
  31560. var start = originalSource.indexOf("implements");
  31561. if (start === -1) {
  31562. throw new Error("Must implement interfaces: " + originalSource);
  31563. }
  31564. var end = originalSource.indexOf("{");
  31565. if (end === -1) {
  31566. end = originalSource.length;
  31567. }
  31568. return originalSource.substr(start, end).includes("&") ? " & " : ", ";
  31569. }
  31570. function clean$4(node, newNode
  31571. /*, parent*/
  31572. ) {
  31573. delete newNode.loc;
  31574. delete newNode.comments;
  31575. }
  31576. var printerGraphql = {
  31577. print: genericPrint$3,
  31578. massageAstNode: clean$4,
  31579. hasPrettierIgnore: hasIgnoreComment$4,
  31580. insertPragma: insertPragma$5,
  31581. printComment: printComment$2,
  31582. canAttachComment: canAttachComment$1
  31583. };
  31584. var options$4 = {
  31585. bracketSpacing: commonOptions.bracketSpacing
  31586. };
  31587. var name$e = "GraphQL";
  31588. var type$c = "data";
  31589. var extensions$c = [
  31590. ".graphql",
  31591. ".gql",
  31592. ".graphqls"
  31593. ];
  31594. var tmScope$c = "source.graphql";
  31595. var aceMode$c = "text";
  31596. var languageId$c = 139;
  31597. var GraphQL = {
  31598. name: name$e,
  31599. type: type$c,
  31600. extensions: extensions$c,
  31601. tmScope: tmScope$c,
  31602. aceMode: aceMode$c,
  31603. languageId: languageId$c
  31604. };
  31605. var GraphQL$1 = /*#__PURE__*/Object.freeze({
  31606. __proto__: null,
  31607. name: name$e,
  31608. type: type$c,
  31609. extensions: extensions$c,
  31610. tmScope: tmScope$c,
  31611. aceMode: aceMode$c,
  31612. languageId: languageId$c,
  31613. 'default': GraphQL
  31614. });
  31615. var require$$0$4 = getCjsExportFromNamespace(GraphQL$1);
  31616. var languages$3 = [createLanguage(require$$0$4, function (data) {
  31617. return Object.assign(data, {
  31618. since: "1.5.0",
  31619. parsers: ["graphql"],
  31620. vscodeLanguageIds: ["graphql"]
  31621. });
  31622. })];
  31623. var printers$3 = {
  31624. graphql: printerGraphql
  31625. };
  31626. var languageGraphql = {
  31627. languages: languages$3,
  31628. options: options$4,
  31629. printers: printers$3
  31630. };
  31631. var json = {
  31632. "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]",
  31633. "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]",
  31634. "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]"
  31635. };
  31636. var cjkPattern = json.cjkPattern,
  31637. kPattern = json.kPattern,
  31638. punctuationPattern = json.punctuationPattern;
  31639. var getLast$3 = util.getLast;
  31640. var INLINE_NODE_TYPES = ["liquidNode", "inlineCode", "emphasis", "strong", "delete", "link", "linkReference", "image", "imageReference", "footnote", "footnoteReference", "sentence", "whitespace", "word", "break", "inlineMath"];
  31641. var INLINE_NODE_WRAPPER_TYPES = INLINE_NODE_TYPES.concat(["tableCell", "paragraph", "heading"]);
  31642. var kRegex = new RegExp(kPattern);
  31643. var punctuationRegex = new RegExp(punctuationPattern);
  31644. /**
  31645. * split text into whitespaces and words
  31646. * @param {string} text
  31647. * @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
  31648. */
  31649. function splitText(text, options) {
  31650. var KIND_NON_CJK = "non-cjk";
  31651. var KIND_CJ_LETTER = "cj-letter";
  31652. var KIND_K_LETTER = "k-letter";
  31653. var KIND_CJK_PUNCTUATION = "cjk-punctuation";
  31654. var nodes = [];
  31655. (options.proseWrap === "preserve" ? text : text.replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")).split(/([ \t\n]+)/).forEach(function (token, index, tokens) {
  31656. // whitespace
  31657. if (index % 2 === 1) {
  31658. nodes.push({
  31659. type: "whitespace",
  31660. value: /\n/.test(token) ? "\n" : " "
  31661. });
  31662. return;
  31663. } // word separated by whitespace
  31664. if ((index === 0 || index === tokens.length - 1) && token === "") {
  31665. return;
  31666. }
  31667. token.split(new RegExp(`(${cjkPattern})`)).forEach(function (innerToken, innerIndex, innerTokens) {
  31668. if ((innerIndex === 0 || innerIndex === innerTokens.length - 1) && innerToken === "") {
  31669. return;
  31670. } // non-CJK word
  31671. if (innerIndex % 2 === 0) {
  31672. if (innerToken !== "") {
  31673. appendNode({
  31674. type: "word",
  31675. value: innerToken,
  31676. kind: KIND_NON_CJK,
  31677. hasLeadingPunctuation: punctuationRegex.test(innerToken[0]),
  31678. hasTrailingPunctuation: punctuationRegex.test(getLast$3(innerToken))
  31679. });
  31680. }
  31681. return;
  31682. } // CJK character
  31683. appendNode(punctuationRegex.test(innerToken) ? {
  31684. type: "word",
  31685. value: innerToken,
  31686. kind: KIND_CJK_PUNCTUATION,
  31687. hasLeadingPunctuation: true,
  31688. hasTrailingPunctuation: true
  31689. } : {
  31690. type: "word",
  31691. value: innerToken,
  31692. kind: kRegex.test(innerToken) ? KIND_K_LETTER : KIND_CJ_LETTER,
  31693. hasLeadingPunctuation: false,
  31694. hasTrailingPunctuation: false
  31695. });
  31696. });
  31697. });
  31698. return nodes;
  31699. function appendNode(node) {
  31700. var lastNode = getLast$3(nodes);
  31701. if (lastNode && lastNode.type === "word") {
  31702. 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) {
  31703. nodes.push({
  31704. type: "whitespace",
  31705. value: " "
  31706. });
  31707. } else if (!isBetween(KIND_NON_CJK, KIND_CJK_PUNCTUATION) && // disallow leading/trailing full-width whitespace
  31708. ![lastNode.value, node.value].some(function (value) {
  31709. return /\u3000/.test(value);
  31710. })) {
  31711. nodes.push({
  31712. type: "whitespace",
  31713. value: ""
  31714. });
  31715. }
  31716. }
  31717. nodes.push(node);
  31718. function isBetween(kind1, kind2) {
  31719. return lastNode.kind === kind1 && node.kind === kind2 || lastNode.kind === kind2 && node.kind === kind1;
  31720. }
  31721. }
  31722. }
  31723. function getOrderedListItemInfo(orderListItem, originalText) {
  31724. var _originalText$slice$m = originalText.slice(orderListItem.position.start.offset, orderListItem.position.end.offset).match(/^\s*(\d+)(\.|\))(\s*)/),
  31725. _originalText$slice$m2 = _slicedToArray(_originalText$slice$m, 4),
  31726. numberText = _originalText$slice$m2[1],
  31727. marker = _originalText$slice$m2[2],
  31728. leadingSpaces = _originalText$slice$m2[3];
  31729. return {
  31730. numberText,
  31731. marker,
  31732. leadingSpaces
  31733. };
  31734. } // workaround for https://github.com/remarkjs/remark/issues/351
  31735. // leading and trailing newlines are stripped by remark
  31736. function getFencedCodeBlockValue(node, originalText) {
  31737. var text = originalText.slice(node.position.start.offset, node.position.end.offset);
  31738. var leadingSpaceCount = text.match(/^\s*/)[0].length;
  31739. var replaceRegex = new RegExp(`^\\s{0,${leadingSpaceCount}}`);
  31740. var lineContents = text.split("\n");
  31741. var markerStyle = text[leadingSpaceCount]; // ` or ~
  31742. var 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
  31743. // https://spec.commonmark.org/0.28/#example-93: The closing code fence must be at least as long as the opening fence
  31744. var hasEndMarker = new RegExp(`^\\s{0,3}${marker}`).test(lineContents[lineContents.length - 1].slice(getIndent(lineContents.length - 1)));
  31745. return lineContents.slice(1, hasEndMarker ? -1 : undefined).map(function (x, i) {
  31746. return x.slice(getIndent(i + 1)).replace(replaceRegex, "");
  31747. }).join("\n");
  31748. function getIndent(lineIndex) {
  31749. return node.position.indent[lineIndex - 1] - 1;
  31750. }
  31751. }
  31752. function mapAst(ast, handler) {
  31753. return function preorder(node, index, parentStack) {
  31754. parentStack = parentStack || [];
  31755. var newNode = handler(node, index, parentStack);
  31756. if (Array.isArray(newNode)) {
  31757. return newNode;
  31758. }
  31759. newNode = Object.assign({}, newNode);
  31760. if (newNode.children) {
  31761. newNode.children = newNode.children.reduce(function (nodes, child, index) {
  31762. var newNodes = preorder(child, index, [newNode].concat(parentStack));
  31763. if (!Array.isArray(newNodes)) {
  31764. newNodes = [newNodes];
  31765. }
  31766. nodes.push.apply(nodes, newNodes);
  31767. return nodes;
  31768. }, []);
  31769. }
  31770. return newNode;
  31771. }(ast, null, null);
  31772. }
  31773. var utils$4 = {
  31774. mapAst,
  31775. splitText,
  31776. punctuationPattern,
  31777. getFencedCodeBlockValue,
  31778. getOrderedListItemInfo,
  31779. INLINE_NODE_TYPES,
  31780. INLINE_NODE_WRAPPER_TYPES
  31781. };
  31782. var _require$$0$builders$6 = doc.builders,
  31783. hardline$a = _require$$0$builders$6.hardline,
  31784. literalline$4 = _require$$0$builders$6.literalline,
  31785. concat$c = _require$$0$builders$6.concat,
  31786. markAsRoot$2 = _require$$0$builders$6.markAsRoot,
  31787. mapDoc$5 = doc.utils.mapDoc;
  31788. var getFencedCodeBlockValue$1 = utils$4.getFencedCodeBlockValue;
  31789. function embed$2(path, print, textToDoc, options) {
  31790. var node = path.getValue();
  31791. if (node.type === "code" && node.lang !== null) {
  31792. // only look for the first string so as to support [markdown-preview-enhanced](https://shd101wyy.github.io/markdown-preview-enhanced/#/code-chunk)
  31793. var langMatch = node.lang.match(/^[A-Za-z0-9_-]+/);
  31794. var lang = langMatch ? langMatch[0] : "";
  31795. var parser = getParserName(lang);
  31796. if (parser) {
  31797. var styleUnit = options.__inJsTemplate ? "~" : "`";
  31798. var style = styleUnit.repeat(Math.max(3, util.getMaxContinuousCount(node.value, styleUnit) + 1));
  31799. var doc = textToDoc(getFencedCodeBlockValue$1(node, options.originalText), {
  31800. parser
  31801. });
  31802. return markAsRoot$2(concat$c([style, node.lang, hardline$a, replaceNewlinesWithLiterallines(doc), style]));
  31803. }
  31804. }
  31805. if (node.type === "yaml") {
  31806. return markAsRoot$2(concat$c(["---", hardline$a, node.value && node.value.trim() ? replaceNewlinesWithLiterallines(textToDoc(node.value, {
  31807. parser: "yaml"
  31808. })) : "", "---"]));
  31809. } // MDX
  31810. switch (node.type) {
  31811. case "importExport":
  31812. return textToDoc(node.value, {
  31813. parser: "babel"
  31814. });
  31815. case "jsx":
  31816. return textToDoc(node.value, {
  31817. parser: "__js_expression"
  31818. });
  31819. }
  31820. return null;
  31821. function getParserName(lang) {
  31822. var supportInfo = support.getSupportInfo(null, {
  31823. plugins: options.plugins
  31824. });
  31825. var language = supportInfo.languages.find(function (language) {
  31826. return language.name.toLowerCase() === lang || language.aliases && language.aliases.indexOf(lang) !== -1 || language.extensions && language.extensions.find(function (ext) {
  31827. return ext.substring(1) === lang;
  31828. });
  31829. });
  31830. if (language) {
  31831. return language.parsers[0];
  31832. }
  31833. return null;
  31834. }
  31835. function replaceNewlinesWithLiterallines(doc) {
  31836. return mapDoc$5(doc, function (currentDoc) {
  31837. return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$c(currentDoc.split(/(\n)/g).map(function (v, i) {
  31838. return i % 2 === 0 ? v : literalline$4;
  31839. })) : currentDoc;
  31840. });
  31841. }
  31842. }
  31843. var embed_1$2 = embed$2;
  31844. var pragmas = ["format", "prettier"];
  31845. function startWithPragma(text) {
  31846. var pragma = `@(${pragmas.join("|")})`;
  31847. var regex = new RegExp([`<!--\\s*${pragma}\\s*-->`, `<!--.*\r?\n[\\s\\S]*(^|\n)[^\\S\n]*${pragma}[^\\S\n]*($|\n)[\\s\\S]*\n.*-->`].join("|"), "m");
  31848. var matched = text.match(regex);
  31849. return matched && matched.index === 0;
  31850. }
  31851. var pragma$3 = {
  31852. startWithPragma,
  31853. hasPragma: function hasPragma(text) {
  31854. return startWithPragma(frontMatter(text).content.trimLeft());
  31855. },
  31856. insertPragma: function insertPragma(text) {
  31857. var extracted = frontMatter(text);
  31858. var pragma = `<!-- @${pragmas[0]} -->`;
  31859. return extracted.frontMatter ? `${extracted.frontMatter.raw}\n\n${pragma}\n\n${extracted.content}` : `${pragma}\n\n${extracted.content}`;
  31860. }
  31861. };
  31862. var getOrderedListItemInfo$1 = utils$4.getOrderedListItemInfo,
  31863. mapAst$1 = utils$4.mapAst,
  31864. splitText$1 = utils$4.splitText; // 0x0 ~ 0x10ffff
  31865. // eslint-disable-next-line no-control-regex
  31866. var isSingleCharRegex = /^([\u0000-\uffff]|[\ud800-\udbff][\udc00-\udfff])$/;
  31867. function preprocess$1(ast, options) {
  31868. ast = restoreUnescapedCharacter(ast, options);
  31869. ast = mergeContinuousTexts(ast);
  31870. ast = transformInlineCode(ast);
  31871. ast = transformIndentedCodeblockAndMarkItsParentList(ast, options);
  31872. ast = markAlignedList(ast, options);
  31873. ast = splitTextIntoSentences(ast, options);
  31874. ast = transformImportExport(ast);
  31875. ast = mergeContinuousImportExport(ast);
  31876. return ast;
  31877. }
  31878. function transformImportExport(ast) {
  31879. return mapAst$1(ast, function (node) {
  31880. if (node.type !== "import" && node.type !== "export") {
  31881. return node;
  31882. }
  31883. return Object.assign({}, node, {
  31884. type: "importExport"
  31885. });
  31886. });
  31887. }
  31888. function transformInlineCode(ast) {
  31889. return mapAst$1(ast, function (node) {
  31890. if (node.type !== "inlineCode") {
  31891. return node;
  31892. }
  31893. return Object.assign({}, node, {
  31894. value: node.value.replace(/\s+/g, " ")
  31895. });
  31896. });
  31897. }
  31898. function restoreUnescapedCharacter(ast, options) {
  31899. return mapAst$1(ast, function (node) {
  31900. return node.type !== "text" ? node : Object.assign({}, node, {
  31901. value: node.value !== "*" && node.value !== "_" && node.value !== "$" && // handle these cases in printer
  31902. 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
  31903. });
  31904. });
  31905. }
  31906. function mergeContinuousImportExport(ast) {
  31907. return mergeChildren(ast, function (prevNode, node) {
  31908. return prevNode.type === "importExport" && node.type === "importExport";
  31909. }, function (prevNode, node) {
  31910. return {
  31911. type: "importExport",
  31912. value: prevNode.value + "\n\n" + node.value,
  31913. position: {
  31914. start: prevNode.position.start,
  31915. end: node.position.end
  31916. }
  31917. };
  31918. });
  31919. }
  31920. function mergeChildren(ast, shouldMerge, mergeNode) {
  31921. return mapAst$1(ast, function (node) {
  31922. if (!node.children) {
  31923. return node;
  31924. }
  31925. var children = node.children.reduce(function (current, child) {
  31926. var lastChild = current[current.length - 1];
  31927. if (lastChild && shouldMerge(lastChild, child)) {
  31928. current.splice(-1, 1, mergeNode(lastChild, child));
  31929. } else {
  31930. current.push(child);
  31931. }
  31932. return current;
  31933. }, []);
  31934. return Object.assign({}, node, {
  31935. children
  31936. });
  31937. });
  31938. }
  31939. function mergeContinuousTexts(ast) {
  31940. return mergeChildren(ast, function (prevNode, node) {
  31941. return prevNode.type === "text" && node.type === "text";
  31942. }, function (prevNode, node) {
  31943. return {
  31944. type: "text",
  31945. value: prevNode.value + node.value,
  31946. position: {
  31947. start: prevNode.position.start,
  31948. end: node.position.end
  31949. }
  31950. };
  31951. });
  31952. }
  31953. function splitTextIntoSentences(ast, options) {
  31954. return mapAst$1(ast, function (node, index, _ref) {
  31955. var _ref2 = _slicedToArray(_ref, 1),
  31956. parentNode = _ref2[0];
  31957. if (node.type !== "text") {
  31958. return node;
  31959. }
  31960. var value = node.value;
  31961. if (parentNode.type === "paragraph") {
  31962. if (index === 0) {
  31963. value = value.trimLeft();
  31964. }
  31965. if (index === parentNode.children.length - 1) {
  31966. value = value.trimRight();
  31967. }
  31968. }
  31969. return {
  31970. type: "sentence",
  31971. position: node.position,
  31972. children: splitText$1(value, options)
  31973. };
  31974. });
  31975. }
  31976. function transformIndentedCodeblockAndMarkItsParentList(ast, options) {
  31977. return mapAst$1(ast, function (node, index, parentStack) {
  31978. if (node.type === "code") {
  31979. // the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it
  31980. var isIndented = /^\n?( {4,}|\t)/.test(options.originalText.slice(node.position.start.offset, node.position.end.offset));
  31981. node.isIndented = isIndented;
  31982. if (isIndented) {
  31983. for (var i = 0; i < parentStack.length; i++) {
  31984. var parent = parentStack[i]; // no need to check checked items
  31985. if (parent.hasIndentedCodeblock) {
  31986. break;
  31987. }
  31988. if (parent.type === "list") {
  31989. parent.hasIndentedCodeblock = true;
  31990. }
  31991. }
  31992. }
  31993. }
  31994. return node;
  31995. });
  31996. }
  31997. function markAlignedList(ast, options) {
  31998. return mapAst$1(ast, function (node, index, parentStack) {
  31999. if (node.type === "list" && node.children.length !== 0) {
  32000. // if one of its parents is not aligned, it's not possible to be aligned in sub-lists
  32001. for (var i = 0; i < parentStack.length; i++) {
  32002. var parent = parentStack[i];
  32003. if (parent.type === "list" && !parent.isAligned) {
  32004. node.isAligned = false;
  32005. return node;
  32006. }
  32007. }
  32008. node.isAligned = isAligned(node);
  32009. }
  32010. return node;
  32011. });
  32012. function getListItemStart(listItem) {
  32013. return listItem.children.length === 0 ? -1 : listItem.children[0].position.start.column - 1;
  32014. }
  32015. function isAligned(list) {
  32016. if (!list.ordered) {
  32017. /**
  32018. * - 123
  32019. * - 123
  32020. */
  32021. return true;
  32022. }
  32023. var _list$children = _slicedToArray(list.children, 2),
  32024. firstItem = _list$children[0],
  32025. secondItem = _list$children[1];
  32026. var firstInfo = getOrderedListItemInfo$1(firstItem, options.originalText);
  32027. if (firstInfo.leadingSpaces.length > 1) {
  32028. /**
  32029. * 1. 123
  32030. *
  32031. * 1. 123
  32032. * 1. 123
  32033. */
  32034. return true;
  32035. }
  32036. var firstStart = getListItemStart(firstItem);
  32037. if (firstStart === -1) {
  32038. /**
  32039. * 1.
  32040. *
  32041. * 1.
  32042. * 1.
  32043. */
  32044. return false;
  32045. }
  32046. if (list.children.length === 1) {
  32047. /**
  32048. * aligned:
  32049. *
  32050. * 11. 123
  32051. *
  32052. * not aligned:
  32053. *
  32054. * 1. 123
  32055. */
  32056. return firstStart % options.tabWidth === 0;
  32057. }
  32058. var secondStart = getListItemStart(secondItem);
  32059. if (firstStart !== secondStart) {
  32060. /**
  32061. * 11. 123
  32062. * 1. 123
  32063. *
  32064. * 1. 123
  32065. * 11. 123
  32066. */
  32067. return false;
  32068. }
  32069. if (firstStart % options.tabWidth === 0) {
  32070. /**
  32071. * 11. 123
  32072. * 12. 123
  32073. */
  32074. return true;
  32075. }
  32076. /**
  32077. * aligned:
  32078. *
  32079. * 11. 123
  32080. * 1. 123
  32081. *
  32082. * not aligned:
  32083. *
  32084. * 1. 123
  32085. * 2. 123
  32086. */
  32087. var secondInfo = getOrderedListItemInfo$1(secondItem, options.originalText);
  32088. return secondInfo.leadingSpaces.length > 1;
  32089. }
  32090. }
  32091. var preprocess_1$1 = preprocess$1;
  32092. var _require$$0$builders$7 = doc.builders,
  32093. breakParent$3 = _require$$0$builders$7.breakParent,
  32094. concat$d = _require$$0$builders$7.concat,
  32095. join$9 = _require$$0$builders$7.join,
  32096. line$6 = _require$$0$builders$7.line,
  32097. literalline$5 = _require$$0$builders$7.literalline,
  32098. markAsRoot$3 = _require$$0$builders$7.markAsRoot,
  32099. hardline$b = _require$$0$builders$7.hardline,
  32100. softline$6 = _require$$0$builders$7.softline,
  32101. ifBreak$5 = _require$$0$builders$7.ifBreak,
  32102. fill$4 = _require$$0$builders$7.fill,
  32103. align$2 = _require$$0$builders$7.align,
  32104. indent$8 = _require$$0$builders$7.indent,
  32105. group$d = _require$$0$builders$7.group,
  32106. mapDoc$6 = doc.utils.mapDoc,
  32107. printDocToString$3 = doc.printer.printDocToString;
  32108. var getFencedCodeBlockValue$2 = utils$4.getFencedCodeBlockValue,
  32109. getOrderedListItemInfo$2 = utils$4.getOrderedListItemInfo,
  32110. splitText$2 = utils$4.splitText,
  32111. punctuationPattern$1 = utils$4.punctuationPattern,
  32112. INLINE_NODE_TYPES$1 = utils$4.INLINE_NODE_TYPES,
  32113. INLINE_NODE_WRAPPER_TYPES$1 = utils$4.INLINE_NODE_WRAPPER_TYPES;
  32114. var replaceEndOfLineWith$1 = util.replaceEndOfLineWith;
  32115. var TRAILING_HARDLINE_NODES = ["importExport"];
  32116. var SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link"];
  32117. var SIBLING_NODE_TYPES = ["listItem", "definition", "footnoteDefinition", "jsx"];
  32118. function genericPrint$4(path, options, print) {
  32119. var node = path.getValue();
  32120. if (shouldRemainTheSameContent(path)) {
  32121. return concat$d(splitText$2(options.originalText.slice(node.position.start.offset, node.position.end.offset), options).map(function (node) {
  32122. return node.type === "word" ? node.value : node.value === "" ? "" : printLine(path, node.value, options);
  32123. }));
  32124. }
  32125. switch (node.type) {
  32126. case "root":
  32127. if (node.children.length === 0) {
  32128. return "";
  32129. }
  32130. return concat$d([normalizeDoc(printRoot(path, options, print)), TRAILING_HARDLINE_NODES.indexOf(getLastDescendantNode(node).type) === -1 ? hardline$b : ""]);
  32131. case "paragraph":
  32132. return printChildren$1(path, options, print, {
  32133. postprocessor: fill$4
  32134. });
  32135. case "sentence":
  32136. return printChildren$1(path, options, print);
  32137. case "word":
  32138. return node.value.replace(/[*$]/g, "\\$&") // escape all `*` and `$` (math)
  32139. .replace(new RegExp([`(^|${punctuationPattern$1})(_+)`, `(_+)(${punctuationPattern$1}|$)`].join("|"), "g"), function (_, text1, underscore1, underscore2, text2) {
  32140. return (underscore1 ? `${text1}${underscore1}` : `${underscore2}${text2}`).replace(/_/g, "\\_");
  32141. });
  32142. // escape all `_` except concating with non-punctuation, e.g. `1_2_3` is not considered emphasis
  32143. case "whitespace":
  32144. {
  32145. var parentNode = path.getParentNode();
  32146. var index = parentNode.children.indexOf(node);
  32147. var nextNode = parentNode.children[index + 1];
  32148. var proseWrap = // leading char that may cause different syntax
  32149. nextNode && /^>|^([-+*]|#{1,6}|[0-9]+[.)])$/.test(nextNode.value) ? "never" : options.proseWrap;
  32150. return printLine(path, node.value, {
  32151. proseWrap
  32152. });
  32153. }
  32154. case "emphasis":
  32155. {
  32156. var _parentNode = path.getParentNode();
  32157. var _index = _parentNode.children.indexOf(node);
  32158. var prevNode = _parentNode.children[_index - 1];
  32159. var _nextNode = _parentNode.children[_index + 1];
  32160. var hasPrevOrNextWord = // `1*2*3` is considered emphasis but `1_2_3` is not
  32161. prevNode && prevNode.type === "sentence" && prevNode.children.length > 0 && util.getLast(prevNode.children).type === "word" && !util.getLast(prevNode.children).hasTrailingPunctuation || _nextNode && _nextNode.type === "sentence" && _nextNode.children.length > 0 && _nextNode.children[0].type === "word" && !_nextNode.children[0].hasLeadingPunctuation;
  32162. var style = hasPrevOrNextWord || getAncestorNode$2(path, "emphasis") ? "*" : "_";
  32163. return concat$d([style, printChildren$1(path, options, print), style]);
  32164. }
  32165. case "strong":
  32166. return concat$d(["**", printChildren$1(path, options, print), "**"]);
  32167. case "delete":
  32168. return concat$d(["~~", printChildren$1(path, options, print), "~~"]);
  32169. case "inlineCode":
  32170. {
  32171. var backtickCount = util.getMinNotPresentContinuousCount(node.value, "`");
  32172. var _style = "`".repeat(backtickCount || 1);
  32173. var gap = backtickCount ? " " : "";
  32174. return concat$d([_style, gap, node.value, gap, _style]);
  32175. }
  32176. case "link":
  32177. switch (options.originalText[node.position.start.offset]) {
  32178. case "<":
  32179. {
  32180. var mailto = "mailto:";
  32181. var url = // <hello@example.com> is parsed as { url: "mailto:hello@example.com" }
  32182. 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;
  32183. return concat$d(["<", url, ">"]);
  32184. }
  32185. case "[":
  32186. return concat$d(["[", printChildren$1(path, options, print), "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  32187. default:
  32188. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  32189. }
  32190. case "image":
  32191. return concat$d(["![", node.alt || "", "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  32192. case "blockquote":
  32193. return concat$d(["> ", align$2("> ", printChildren$1(path, options, print))]);
  32194. case "heading":
  32195. return concat$d(["#".repeat(node.depth) + " ", printChildren$1(path, options, print)]);
  32196. case "code":
  32197. {
  32198. if (node.isIndented) {
  32199. // indented code block
  32200. var alignment = " ".repeat(4);
  32201. return align$2(alignment, concat$d([alignment, concat$d(replaceEndOfLineWith$1(node.value, hardline$b))]));
  32202. } // fenced code block
  32203. var styleUnit = options.__inJsTemplate ? "~" : "`";
  32204. var _style2 = styleUnit.repeat(Math.max(3, util.getMaxContinuousCount(node.value, styleUnit) + 1));
  32205. return concat$d([_style2, node.lang || "", hardline$b, concat$d(replaceEndOfLineWith$1(getFencedCodeBlockValue$2(node, options.originalText), hardline$b)), hardline$b, _style2]);
  32206. }
  32207. case "yaml":
  32208. case "toml":
  32209. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  32210. case "html":
  32211. {
  32212. var _parentNode2 = path.getParentNode();
  32213. var value = _parentNode2.type === "root" && util.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value;
  32214. var isHtmlComment = /^<!--[\s\S]*-->$/.test(value);
  32215. return concat$d(replaceEndOfLineWith$1(value, isHtmlComment ? hardline$b : markAsRoot$3(literalline$5)));
  32216. }
  32217. case "list":
  32218. {
  32219. var nthSiblingIndex = getNthListSiblingIndex(node, path.getParentNode());
  32220. var isGitDiffFriendlyOrderedList = node.ordered && node.children.length > 1 && +getOrderedListItemInfo$2(node.children[1], options.originalText).numberText === 1;
  32221. return printChildren$1(path, options, print, {
  32222. processor: function processor(childPath, index) {
  32223. var prefix = getPrefix();
  32224. return concat$d([prefix, align$2(" ".repeat(prefix.length), printListItem(childPath, options, print, prefix))]);
  32225. function getPrefix() {
  32226. var rawPrefix = node.ordered ? (index === 0 ? node.start : isGitDiffFriendlyOrderedList ? 1 : node.start + index) + (nthSiblingIndex % 2 === 0 ? ". " : ") ") : nthSiblingIndex % 2 === 0 ? "- " : "* ";
  32227. return node.isAligned ||
  32228. /* workaround for https://github.com/remarkjs/remark/issues/315 */
  32229. node.hasIndentedCodeblock ? alignListPrefix(rawPrefix, options) : rawPrefix;
  32230. }
  32231. }
  32232. });
  32233. }
  32234. case "thematicBreak":
  32235. {
  32236. var counter = getAncestorCounter$1(path, "list");
  32237. if (counter === -1) {
  32238. return "---";
  32239. }
  32240. var _nthSiblingIndex = getNthListSiblingIndex(path.getParentNode(counter), path.getParentNode(counter + 1));
  32241. return _nthSiblingIndex % 2 === 0 ? "***" : "---";
  32242. }
  32243. case "linkReference":
  32244. return concat$d(["[", printChildren$1(path, options, print), "]", node.referenceType === "full" ? concat$d(["[", node.identifier, "]"]) : node.referenceType === "collapsed" ? "[]" : ""]);
  32245. case "imageReference":
  32246. switch (node.referenceType) {
  32247. case "full":
  32248. return concat$d(["![", node.alt || "", "][", node.identifier, "]"]);
  32249. default:
  32250. return concat$d(["![", node.alt, "]", node.referenceType === "collapsed" ? "[]" : ""]);
  32251. }
  32252. case "definition":
  32253. {
  32254. var lineOrSpace = options.proseWrap === "always" ? line$6 : " ";
  32255. return group$d(concat$d([concat$d(["[", node.identifier, "]:"]), indent$8(concat$d([lineOrSpace, printUrl(node.url), node.title === null ? "" : concat$d([lineOrSpace, printTitle(node.title, options, false)])]))]));
  32256. }
  32257. case "footnote":
  32258. return concat$d(["[^", printChildren$1(path, options, print), "]"]);
  32259. case "footnoteReference":
  32260. return concat$d(["[^", node.identifier, "]"]);
  32261. case "footnoteDefinition":
  32262. {
  32263. var _nextNode2 = path.getParentNode().children[path.getName() + 1];
  32264. var 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);
  32265. return concat$d(["[^", node.identifier, "]: ", shouldInlineFootnote ? printChildren$1(path, options, print) : group$d(concat$d([align$2(" ".repeat(options.tabWidth), printChildren$1(path, options, print, {
  32266. processor: function processor(childPath, index) {
  32267. return index === 0 ? group$d(concat$d([softline$6, softline$6, childPath.call(print)])) : childPath.call(print);
  32268. }
  32269. })), _nextNode2 && _nextNode2.type === "footnoteDefinition" ? softline$6 : ""]))]);
  32270. }
  32271. case "table":
  32272. return printTable(path, options, print);
  32273. case "tableCell":
  32274. return printChildren$1(path, options, print);
  32275. case "break":
  32276. return /\s/.test(options.originalText[node.position.start.offset]) ? concat$d([" ", markAsRoot$3(literalline$5)]) : concat$d(["\\", hardline$b]);
  32277. case "liquidNode":
  32278. return concat$d(replaceEndOfLineWith$1(node.value, hardline$b));
  32279. // MDX
  32280. case "importExport":
  32281. case "jsx":
  32282. return node.value;
  32283. // fallback to the original text if multiparser failed
  32284. case "math":
  32285. return concat$d(["$$", hardline$b, node.value ? concat$d([concat$d(replaceEndOfLineWith$1(node.value, hardline$b)), hardline$b]) : "", "$$"]);
  32286. case "inlineMath":
  32287. {
  32288. // remark-math trims content but we don't want to remove whitespaces
  32289. // since it's very possible that it's recognized as math accidentally
  32290. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  32291. }
  32292. case "tableRow": // handled in "table"
  32293. case "listItem": // handled in "list"
  32294. default:
  32295. throw new Error(`Unknown markdown type ${JSON.stringify(node.type)}`);
  32296. }
  32297. }
  32298. function printListItem(path, options, print, listPrefix) {
  32299. var node = path.getValue();
  32300. var prefix = node.checked === null ? "" : node.checked ? "[x] " : "[ ] ";
  32301. return concat$d([prefix, printChildren$1(path, options, print, {
  32302. processor: function processor(childPath, index) {
  32303. if (index === 0 && childPath.getValue().type !== "list") {
  32304. return align$2(" ".repeat(prefix.length), childPath.call(print));
  32305. }
  32306. var alignment = " ".repeat(clamp(options.tabWidth - listPrefix.length, 0, 3) // 4+ will cause indented code block
  32307. );
  32308. return concat$d([alignment, align$2(alignment, childPath.call(print))]);
  32309. }
  32310. })]);
  32311. }
  32312. function alignListPrefix(prefix, options) {
  32313. var additionalSpaces = getAdditionalSpaces();
  32314. return prefix + " ".repeat(additionalSpaces >= 4 ? 0 : additionalSpaces // 4+ will cause indented code block
  32315. );
  32316. function getAdditionalSpaces() {
  32317. var restSpaces = prefix.length % options.tabWidth;
  32318. return restSpaces === 0 ? 0 : options.tabWidth - restSpaces;
  32319. }
  32320. }
  32321. function getNthListSiblingIndex(node, parentNode) {
  32322. return getNthSiblingIndex(node, parentNode, function (siblingNode) {
  32323. return siblingNode.ordered === node.ordered;
  32324. });
  32325. }
  32326. function getNthSiblingIndex(node, parentNode, condition) {
  32327. condition = condition || function () {
  32328. return true;
  32329. };
  32330. var index = -1;
  32331. var _iteratorNormalCompletion = true;
  32332. var _didIteratorError = false;
  32333. var _iteratorError = undefined;
  32334. try {
  32335. for (var _iterator = parentNode.children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  32336. var childNode = _step.value;
  32337. if (childNode.type === node.type && condition(childNode)) {
  32338. index++;
  32339. } else {
  32340. index = -1;
  32341. }
  32342. if (childNode === node) {
  32343. return index;
  32344. }
  32345. }
  32346. } catch (err) {
  32347. _didIteratorError = true;
  32348. _iteratorError = err;
  32349. } finally {
  32350. try {
  32351. if (!_iteratorNormalCompletion && _iterator.return != null) {
  32352. _iterator.return();
  32353. }
  32354. } finally {
  32355. if (_didIteratorError) {
  32356. throw _iteratorError;
  32357. }
  32358. }
  32359. }
  32360. }
  32361. function getAncestorCounter$1(path, typeOrTypes) {
  32362. var types = [].concat(typeOrTypes);
  32363. var counter = -1;
  32364. var ancestorNode;
  32365. while (ancestorNode = path.getParentNode(++counter)) {
  32366. if (types.indexOf(ancestorNode.type) !== -1) {
  32367. return counter;
  32368. }
  32369. }
  32370. return -1;
  32371. }
  32372. function getAncestorNode$2(path, typeOrTypes) {
  32373. var counter = getAncestorCounter$1(path, typeOrTypes);
  32374. return counter === -1 ? null : path.getParentNode(counter);
  32375. }
  32376. function printLine(path, value, options) {
  32377. if (options.proseWrap === "preserve" && value === "\n") {
  32378. return hardline$b;
  32379. }
  32380. var isBreakable = options.proseWrap === "always" && !getAncestorNode$2(path, SINGLE_LINE_NODE_TYPES);
  32381. return value !== "" ? isBreakable ? line$6 : " " : isBreakable ? softline$6 : "";
  32382. }
  32383. function printTable(path, options, print) {
  32384. var hardlineWithoutBreakParent = hardline$b.parts[0];
  32385. var node = path.getValue();
  32386. var contents = []; // { [rowIndex: number]: { [columnIndex: number]: string } }
  32387. path.map(function (rowPath) {
  32388. var rowContents = [];
  32389. rowPath.map(function (cellPath) {
  32390. rowContents.push(printDocToString$3(cellPath.call(print), options).formatted);
  32391. }, "children");
  32392. contents.push(rowContents);
  32393. }, "children"); // Get the width of each column
  32394. var columnMaxWidths = contents.reduce(function (currentWidths, rowContents) {
  32395. return currentWidths.map(function (width, columnIndex) {
  32396. return Math.max(width, util.getStringWidth(rowContents[columnIndex]));
  32397. });
  32398. }, contents[0].map(function () {
  32399. return 3;
  32400. }) // minimum width = 3 (---, :--, :-:, --:)
  32401. );
  32402. var alignedTable = join$9(hardlineWithoutBreakParent, [printRow(contents[0]), printSeparator(), join$9(hardlineWithoutBreakParent, contents.slice(1).map(function (rowContents) {
  32403. return printRow(rowContents);
  32404. }))]);
  32405. if (options.proseWrap !== "never") {
  32406. return concat$d([breakParent$3, alignedTable]);
  32407. } // Only if the --prose-wrap never is set and it exceeds the print width.
  32408. var compactTable = join$9(hardlineWithoutBreakParent, [printRow(contents[0],
  32409. /* isCompact */
  32410. true), printSeparator(
  32411. /* isCompact */
  32412. true), join$9(hardlineWithoutBreakParent, contents.slice(1).map(function (rowContents) {
  32413. return printRow(rowContents,
  32414. /* isCompact */
  32415. true);
  32416. }))]);
  32417. return concat$d([breakParent$3, group$d(ifBreak$5(compactTable, alignedTable))]);
  32418. function printSeparator(isCompact) {
  32419. return concat$d(["| ", join$9(" | ", columnMaxWidths.map(function (width, index) {
  32420. var spaces = isCompact ? 3 : width;
  32421. switch (node.align[index]) {
  32422. case "left":
  32423. return ":" + "-".repeat(spaces - 1);
  32424. case "right":
  32425. return "-".repeat(spaces - 1) + ":";
  32426. case "center":
  32427. return ":" + "-".repeat(spaces - 2) + ":";
  32428. default:
  32429. return "-".repeat(spaces);
  32430. }
  32431. })), " |"]);
  32432. }
  32433. function printRow(rowContents, isCompact) {
  32434. return concat$d(["| ", join$9(" | ", isCompact ? rowContents : rowContents.map(function (rowContent, columnIndex) {
  32435. switch (node.align[columnIndex]) {
  32436. case "right":
  32437. return alignRight(rowContent, columnMaxWidths[columnIndex]);
  32438. case "center":
  32439. return alignCenter(rowContent, columnMaxWidths[columnIndex]);
  32440. default:
  32441. return alignLeft(rowContent, columnMaxWidths[columnIndex]);
  32442. }
  32443. })), " |"]);
  32444. }
  32445. function alignLeft(text, width) {
  32446. var spaces = width - util.getStringWidth(text);
  32447. return concat$d([text, " ".repeat(spaces)]);
  32448. }
  32449. function alignRight(text, width) {
  32450. var spaces = width - util.getStringWidth(text);
  32451. return concat$d([" ".repeat(spaces), text]);
  32452. }
  32453. function alignCenter(text, width) {
  32454. var spaces = width - util.getStringWidth(text);
  32455. var left = Math.floor(spaces / 2);
  32456. var right = spaces - left;
  32457. return concat$d([" ".repeat(left), text, " ".repeat(right)]);
  32458. }
  32459. }
  32460. function printRoot(path, options, print) {
  32461. /** @typedef {{ index: number, offset: number }} IgnorePosition */
  32462. /** @type {Array<{start: IgnorePosition, end: IgnorePosition}>} */
  32463. var ignoreRanges = [];
  32464. /** @type {IgnorePosition | null} */
  32465. var ignoreStart = null;
  32466. var children = path.getValue().children;
  32467. children.forEach(function (childNode, index) {
  32468. switch (isPrettierIgnore(childNode)) {
  32469. case "start":
  32470. if (ignoreStart === null) {
  32471. ignoreStart = {
  32472. index,
  32473. offset: childNode.position.end.offset
  32474. };
  32475. }
  32476. break;
  32477. case "end":
  32478. if (ignoreStart !== null) {
  32479. ignoreRanges.push({
  32480. start: ignoreStart,
  32481. end: {
  32482. index,
  32483. offset: childNode.position.start.offset
  32484. }
  32485. });
  32486. ignoreStart = null;
  32487. }
  32488. break;
  32489. }
  32490. });
  32491. return printChildren$1(path, options, print, {
  32492. processor: function processor(childPath, index) {
  32493. if (ignoreRanges.length !== 0) {
  32494. var ignoreRange = ignoreRanges[0];
  32495. if (index === ignoreRange.start.index) {
  32496. return concat$d([children[ignoreRange.start.index].value, options.originalText.slice(ignoreRange.start.offset, ignoreRange.end.offset), children[ignoreRange.end.index].value]);
  32497. }
  32498. if (ignoreRange.start.index < index && index < ignoreRange.end.index) {
  32499. return false;
  32500. }
  32501. if (index === ignoreRange.end.index) {
  32502. ignoreRanges.shift();
  32503. return false;
  32504. }
  32505. }
  32506. return childPath.call(print);
  32507. }
  32508. });
  32509. }
  32510. function printChildren$1(path, options, print, events) {
  32511. events = events || {};
  32512. var postprocessor = events.postprocessor || concat$d;
  32513. var processor = events.processor || function (childPath) {
  32514. return childPath.call(print);
  32515. };
  32516. var node = path.getValue();
  32517. var parts = [];
  32518. var lastChildNode;
  32519. path.map(function (childPath, index) {
  32520. var childNode = childPath.getValue();
  32521. var result = processor(childPath, index);
  32522. if (result !== false) {
  32523. var data = {
  32524. parts,
  32525. prevNode: lastChildNode,
  32526. parentNode: node,
  32527. options
  32528. };
  32529. if (!shouldNotPrePrintHardline(childNode, data)) {
  32530. parts.push(hardline$b);
  32531. if (lastChildNode && TRAILING_HARDLINE_NODES.indexOf(lastChildNode.type) !== -1) {
  32532. if (shouldPrePrintTripleHardline(childNode, data)) {
  32533. parts.push(hardline$b);
  32534. }
  32535. } else {
  32536. if (shouldPrePrintDoubleHardline(childNode, data) || shouldPrePrintTripleHardline(childNode, data)) {
  32537. parts.push(hardline$b);
  32538. }
  32539. if (shouldPrePrintTripleHardline(childNode, data)) {
  32540. parts.push(hardline$b);
  32541. }
  32542. }
  32543. }
  32544. parts.push(result);
  32545. lastChildNode = childNode;
  32546. }
  32547. }, "children");
  32548. return postprocessor(parts);
  32549. }
  32550. function getLastDescendantNode(node) {
  32551. var current = node;
  32552. while (current.children && current.children.length !== 0) {
  32553. current = current.children[current.children.length - 1];
  32554. }
  32555. return current;
  32556. }
  32557. /** @return {false | 'next' | 'start' | 'end'} */
  32558. function isPrettierIgnore(node) {
  32559. if (node.type !== "html") {
  32560. return false;
  32561. }
  32562. var match = node.value.match(/^<!--\s*prettier-ignore(?:-(start|end))?\s*-->$/);
  32563. return match === null ? false : match[1] ? match[1] : "next";
  32564. }
  32565. function isInlineNode(node) {
  32566. return node && INLINE_NODE_TYPES$1.indexOf(node.type) !== -1;
  32567. }
  32568. function isEndsWithHardLine(node) {
  32569. return node && /\n+$/.test(node.value);
  32570. }
  32571. function last(nodes) {
  32572. return nodes && nodes[nodes.length - 1];
  32573. }
  32574. function shouldNotPrePrintHardline(node, _ref) {
  32575. var parentNode = _ref.parentNode,
  32576. parts = _ref.parts,
  32577. prevNode = _ref.prevNode;
  32578. var isFirstNode = parts.length === 0;
  32579. var isInlineHTML = node.type === "html" && INLINE_NODE_WRAPPER_TYPES$1.indexOf(parentNode.type) !== -1;
  32580. var isAfterHardlineNode = prevNode && (isEndsWithHardLine(prevNode) || isEndsWithHardLine(last(prevNode.children)));
  32581. return isFirstNode || isInlineNode(node) || isInlineHTML || isAfterHardlineNode;
  32582. }
  32583. function shouldPrePrintDoubleHardline(node, _ref2) {
  32584. var parentNode = _ref2.parentNode,
  32585. prevNode = _ref2.prevNode;
  32586. var prevNodeType = prevNode && prevNode.type;
  32587. var nodeType = node.type;
  32588. var isSequence = prevNodeType === nodeType;
  32589. var isSiblingNode = isSequence && SIBLING_NODE_TYPES.indexOf(nodeType) !== -1;
  32590. var isInTightListItem = parentNode.type === "listItem" && !parentNode.loose;
  32591. var isPrevNodeLooseListItem = prevNodeType === "listItem" && prevNode.loose;
  32592. var isPrevNodePrettierIgnore = isPrettierIgnore(prevNode) === "next";
  32593. var isBlockHtmlWithoutBlankLineBetweenPrevHtml = nodeType === "html" && prevNodeType === "html" && prevNode.position.end.line + 1 === node.position.start.line;
  32594. var isJsxInlineSibling = prevNodeType === "jsx" && isInlineNode(node) || nodeType === "jsx" && isInlineNode(prevNode);
  32595. return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore || isBlockHtmlWithoutBlankLineBetweenPrevHtml || isJsxInlineSibling);
  32596. }
  32597. function shouldPrePrintTripleHardline(node, data) {
  32598. var isPrevNodeList = data.prevNode && data.prevNode.type === "list";
  32599. var isIndentedCode = node.type === "code" && node.isIndented;
  32600. return isPrevNodeList && isIndentedCode;
  32601. }
  32602. function shouldRemainTheSameContent(path) {
  32603. var ancestorNode = getAncestorNode$2(path, ["linkReference", "imageReference"]);
  32604. return ancestorNode && (ancestorNode.type !== "linkReference" || ancestorNode.referenceType !== "full");
  32605. }
  32606. function normalizeDoc(doc) {
  32607. return mapDoc$6(doc, function (currentDoc) {
  32608. if (!currentDoc.parts) {
  32609. return currentDoc;
  32610. }
  32611. if (currentDoc.type === "concat" && currentDoc.parts.length === 1) {
  32612. return currentDoc.parts[0];
  32613. }
  32614. var parts = [];
  32615. currentDoc.parts.forEach(function (part) {
  32616. if (part.type === "concat") {
  32617. parts.push.apply(parts, part.parts);
  32618. } else if (part !== "") {
  32619. parts.push(part);
  32620. }
  32621. });
  32622. return Object.assign({}, currentDoc, {
  32623. parts: normalizeParts(parts)
  32624. });
  32625. });
  32626. }
  32627. function printUrl(url, dangerousCharOrChars) {
  32628. var dangerousChars = [" "].concat(dangerousCharOrChars || []);
  32629. return new RegExp(dangerousChars.map(function (x) {
  32630. return `\\${x}`;
  32631. }).join("|")).test(url) ? `<${url}>` : url;
  32632. }
  32633. function printTitle(title, options, printSpace) {
  32634. if (printSpace == null) {
  32635. printSpace = true;
  32636. }
  32637. if (!title) {
  32638. return "";
  32639. }
  32640. if (printSpace) {
  32641. return " " + printTitle(title, options, false);
  32642. }
  32643. if (title.includes('"') && title.includes("'") && !title.includes(")")) {
  32644. return `(${title})`; // avoid escaped quotes
  32645. } // faster than using RegExps: https://jsperf.com/performance-of-match-vs-split
  32646. var singleCount = title.split("'").length - 1;
  32647. var doubleCount = title.split('"').length - 1;
  32648. var quote = singleCount > doubleCount ? '"' : doubleCount > singleCount ? "'" : options.singleQuote ? "'" : '"';
  32649. title = title.replace(new RegExp(`(${quote})`, "g"), "\\$1");
  32650. return `${quote}${title}${quote}`;
  32651. }
  32652. function normalizeParts(parts) {
  32653. return parts.reduce(function (current, part) {
  32654. var lastPart = util.getLast(current);
  32655. if (typeof lastPart === "string" && typeof part === "string") {
  32656. current.splice(-1, 1, lastPart + part);
  32657. } else {
  32658. current.push(part);
  32659. }
  32660. return current;
  32661. }, []);
  32662. }
  32663. function clamp(value, min, max) {
  32664. return value < min ? min : value > max ? max : value;
  32665. }
  32666. function clean$5(ast, newObj, parent) {
  32667. delete newObj.position;
  32668. delete newObj.raw; // front-matter
  32669. // for codeblock
  32670. if (ast.type === "code" || ast.type === "yaml" || ast.type === "import" || ast.type === "export" || ast.type === "jsx") {
  32671. delete newObj.value;
  32672. }
  32673. if (ast.type === "list") {
  32674. delete newObj.isAligned;
  32675. } // texts can be splitted or merged
  32676. if (ast.type === "text") {
  32677. return null;
  32678. }
  32679. if (ast.type === "inlineCode") {
  32680. newObj.value = ast.value.replace(/[ \t\n]+/g, " ");
  32681. } // for insert pragma
  32682. if (parent && parent.type === "root" && parent.children.length > 0 && (parent.children[0] === ast || (parent.children[0].type === "yaml" || parent.children[0].type === "toml") && parent.children[1] === ast) && ast.type === "html" && pragma$3.startWithPragma(ast.value)) {
  32683. return null;
  32684. }
  32685. }
  32686. function hasPrettierIgnore$2(path) {
  32687. var index = +path.getName();
  32688. if (index === 0) {
  32689. return false;
  32690. }
  32691. var prevNode = path.getParentNode().children[index - 1];
  32692. return isPrettierIgnore(prevNode) === "next";
  32693. }
  32694. var printerMarkdown = {
  32695. preprocess: preprocess_1$1,
  32696. print: genericPrint$4,
  32697. embed: embed_1$2,
  32698. massageAstNode: clean$5,
  32699. hasPrettierIgnore: hasPrettierIgnore$2,
  32700. insertPragma: pragma$3.insertPragma
  32701. };
  32702. var options$5 = {
  32703. proseWrap: commonOptions.proseWrap,
  32704. singleQuote: commonOptions.singleQuote
  32705. };
  32706. var name$f = "Markdown";
  32707. var type$d = "prose";
  32708. var aliases$4 = [
  32709. "pandoc"
  32710. ];
  32711. var aceMode$d = "markdown";
  32712. var codemirrorMode$a = "gfm";
  32713. var codemirrorMimeType$a = "text/x-gfm";
  32714. var wrap = true;
  32715. var extensions$d = [
  32716. ".md",
  32717. ".markdown",
  32718. ".mdown",
  32719. ".mdwn",
  32720. ".mdx",
  32721. ".mkd",
  32722. ".mkdn",
  32723. ".mkdown",
  32724. ".ronn",
  32725. ".workbook"
  32726. ];
  32727. var filenames$3 = [
  32728. "contents.lr"
  32729. ];
  32730. var tmScope$d = "source.gfm";
  32731. var languageId$d = 222;
  32732. var Markdown = {
  32733. name: name$f,
  32734. type: type$d,
  32735. aliases: aliases$4,
  32736. aceMode: aceMode$d,
  32737. codemirrorMode: codemirrorMode$a,
  32738. codemirrorMimeType: codemirrorMimeType$a,
  32739. wrap: wrap,
  32740. extensions: extensions$d,
  32741. filenames: filenames$3,
  32742. tmScope: tmScope$d,
  32743. languageId: languageId$d
  32744. };
  32745. var Markdown$1 = /*#__PURE__*/Object.freeze({
  32746. __proto__: null,
  32747. name: name$f,
  32748. type: type$d,
  32749. aliases: aliases$4,
  32750. aceMode: aceMode$d,
  32751. codemirrorMode: codemirrorMode$a,
  32752. codemirrorMimeType: codemirrorMimeType$a,
  32753. wrap: wrap,
  32754. extensions: extensions$d,
  32755. filenames: filenames$3,
  32756. tmScope: tmScope$d,
  32757. languageId: languageId$d,
  32758. 'default': Markdown
  32759. });
  32760. var require$$0$5 = getCjsExportFromNamespace(Markdown$1);
  32761. var languages$4 = [createLanguage(require$$0$5, function (data) {
  32762. return Object.assign(data, {
  32763. since: "1.8.0",
  32764. parsers: ["remark"],
  32765. vscodeLanguageIds: ["markdown"],
  32766. filenames: data.filenames.concat(["README"]),
  32767. extensions: data.extensions.filter(function (extension) {
  32768. return extension !== ".mdx";
  32769. })
  32770. });
  32771. }), createLanguage(require$$0$5, function (data) {
  32772. return Object.assign(data, {
  32773. name: "MDX",
  32774. since: "1.15.0",
  32775. parsers: ["mdx"],
  32776. vscodeLanguageIds: ["mdx"],
  32777. filenames: [],
  32778. extensions: [".mdx"]
  32779. });
  32780. })];
  32781. var printers$4 = {
  32782. mdast: printerMarkdown
  32783. };
  32784. var languageMarkdown = {
  32785. languages: languages$4,
  32786. options: options$5,
  32787. printers: printers$4
  32788. };
  32789. var clean$6 = function clean(ast, newNode) {
  32790. delete newNode.sourceSpan;
  32791. delete newNode.startSourceSpan;
  32792. delete newNode.endSourceSpan;
  32793. delete newNode.nameSpan;
  32794. delete newNode.valueSpan;
  32795. if (ast.type === "text" || ast.type === "comment") {
  32796. return null;
  32797. } // may be formatted by multiparser
  32798. if (ast.type === "yaml" || ast.type === "toml") {
  32799. return null;
  32800. }
  32801. if (ast.type === "attribute") {
  32802. delete newNode.value;
  32803. }
  32804. if (ast.type === "docType") {
  32805. delete newNode.value;
  32806. }
  32807. };
  32808. var json$1 = {
  32809. "CSS_DISPLAY_TAGS": {
  32810. "area": "none",
  32811. "base": "none",
  32812. "basefont": "none",
  32813. "datalist": "none",
  32814. "head": "none",
  32815. "link": "none",
  32816. "meta": "none",
  32817. "noembed": "none",
  32818. "noframes": "none",
  32819. "param": "none",
  32820. "rp": "none",
  32821. "script": "block",
  32822. "source": "block",
  32823. "style": "none",
  32824. "template": "inline",
  32825. "track": "block",
  32826. "title": "none",
  32827. "html": "block",
  32828. "body": "block",
  32829. "address": "block",
  32830. "blockquote": "block",
  32831. "center": "block",
  32832. "div": "block",
  32833. "figure": "block",
  32834. "figcaption": "block",
  32835. "footer": "block",
  32836. "form": "block",
  32837. "header": "block",
  32838. "hr": "block",
  32839. "legend": "block",
  32840. "listing": "block",
  32841. "main": "block",
  32842. "p": "block",
  32843. "plaintext": "block",
  32844. "pre": "block",
  32845. "xmp": "block",
  32846. "slot": "contents",
  32847. "ruby": "ruby",
  32848. "rt": "ruby-text",
  32849. "article": "block",
  32850. "aside": "block",
  32851. "h1": "block",
  32852. "h2": "block",
  32853. "h3": "block",
  32854. "h4": "block",
  32855. "h5": "block",
  32856. "h6": "block",
  32857. "hgroup": "block",
  32858. "nav": "block",
  32859. "section": "block",
  32860. "dir": "block",
  32861. "dd": "block",
  32862. "dl": "block",
  32863. "dt": "block",
  32864. "ol": "block",
  32865. "ul": "block",
  32866. "li": "list-item",
  32867. "table": "table",
  32868. "caption": "table-caption",
  32869. "colgroup": "table-column-group",
  32870. "col": "table-column",
  32871. "thead": "table-header-group",
  32872. "tbody": "table-row-group",
  32873. "tfoot": "table-footer-group",
  32874. "tr": "table-row",
  32875. "td": "table-cell",
  32876. "th": "table-cell",
  32877. "fieldset": "block",
  32878. "button": "inline-block",
  32879. "video": "inline-block",
  32880. "audio": "inline-block"
  32881. },
  32882. "CSS_DISPLAY_DEFAULT": "inline",
  32883. "CSS_WHITE_SPACE_TAGS": {
  32884. "listing": "pre",
  32885. "plaintext": "pre",
  32886. "pre": "pre",
  32887. "xmp": "pre",
  32888. "nobr": "nowrap",
  32889. "table": "initial",
  32890. "textarea": "pre-wrap"
  32891. },
  32892. "CSS_WHITE_SPACE_DEFAULT": "normal"
  32893. };
  32894. var a = [
  32895. "accesskey",
  32896. "charset",
  32897. "coords",
  32898. "download",
  32899. "href",
  32900. "hreflang",
  32901. "name",
  32902. "ping",
  32903. "referrerpolicy",
  32904. "rel",
  32905. "rev",
  32906. "shape",
  32907. "tabindex",
  32908. "target",
  32909. "type"
  32910. ];
  32911. var abbr = [
  32912. "title"
  32913. ];
  32914. var applet = [
  32915. "align",
  32916. "alt",
  32917. "archive",
  32918. "code",
  32919. "codebase",
  32920. "height",
  32921. "hspace",
  32922. "name",
  32923. "object",
  32924. "vspace",
  32925. "width"
  32926. ];
  32927. var area = [
  32928. "accesskey",
  32929. "alt",
  32930. "coords",
  32931. "download",
  32932. "href",
  32933. "hreflang",
  32934. "nohref",
  32935. "ping",
  32936. "referrerpolicy",
  32937. "rel",
  32938. "shape",
  32939. "tabindex",
  32940. "target",
  32941. "type"
  32942. ];
  32943. var audio = [
  32944. "autoplay",
  32945. "controls",
  32946. "crossorigin",
  32947. "loop",
  32948. "muted",
  32949. "preload",
  32950. "src"
  32951. ];
  32952. var base = [
  32953. "href",
  32954. "target"
  32955. ];
  32956. var basefont = [
  32957. "color",
  32958. "face",
  32959. "size"
  32960. ];
  32961. var bdo = [
  32962. "dir"
  32963. ];
  32964. var blockquote = [
  32965. "cite"
  32966. ];
  32967. var body = [
  32968. "alink",
  32969. "background",
  32970. "bgcolor",
  32971. "link",
  32972. "text",
  32973. "vlink"
  32974. ];
  32975. var br = [
  32976. "clear"
  32977. ];
  32978. var button = [
  32979. "accesskey",
  32980. "autofocus",
  32981. "disabled",
  32982. "form",
  32983. "formaction",
  32984. "formenctype",
  32985. "formmethod",
  32986. "formnovalidate",
  32987. "formtarget",
  32988. "name",
  32989. "tabindex",
  32990. "type",
  32991. "value"
  32992. ];
  32993. var canvas = [
  32994. "height",
  32995. "width"
  32996. ];
  32997. var caption = [
  32998. "align"
  32999. ];
  33000. var col = [
  33001. "align",
  33002. "char",
  33003. "charoff",
  33004. "span",
  33005. "valign",
  33006. "width"
  33007. ];
  33008. var colgroup = [
  33009. "align",
  33010. "char",
  33011. "charoff",
  33012. "span",
  33013. "valign",
  33014. "width"
  33015. ];
  33016. var data$1 = [
  33017. "value"
  33018. ];
  33019. var del$1 = [
  33020. "cite",
  33021. "datetime"
  33022. ];
  33023. var details = [
  33024. "open"
  33025. ];
  33026. var dfn = [
  33027. "title"
  33028. ];
  33029. var dialog = [
  33030. "open"
  33031. ];
  33032. var dir = [
  33033. "compact"
  33034. ];
  33035. var div = [
  33036. "align"
  33037. ];
  33038. var dl = [
  33039. "compact"
  33040. ];
  33041. var embed$3 = [
  33042. "height",
  33043. "src",
  33044. "type",
  33045. "width"
  33046. ];
  33047. var fieldset = [
  33048. "disabled",
  33049. "form",
  33050. "name"
  33051. ];
  33052. var font = [
  33053. "color",
  33054. "face",
  33055. "size"
  33056. ];
  33057. var form = [
  33058. "accept",
  33059. "accept-charset",
  33060. "action",
  33061. "autocomplete",
  33062. "enctype",
  33063. "method",
  33064. "name",
  33065. "novalidate",
  33066. "target"
  33067. ];
  33068. var frame = [
  33069. "frameborder",
  33070. "longdesc",
  33071. "marginheight",
  33072. "marginwidth",
  33073. "name",
  33074. "noresize",
  33075. "scrolling",
  33076. "src"
  33077. ];
  33078. var frameset = [
  33079. "cols",
  33080. "rows"
  33081. ];
  33082. var h1 = [
  33083. "align"
  33084. ];
  33085. var h2 = [
  33086. "align"
  33087. ];
  33088. var h3 = [
  33089. "align"
  33090. ];
  33091. var h4 = [
  33092. "align"
  33093. ];
  33094. var h5 = [
  33095. "align"
  33096. ];
  33097. var h6 = [
  33098. "align"
  33099. ];
  33100. var head = [
  33101. "profile"
  33102. ];
  33103. var hr = [
  33104. "align",
  33105. "noshade",
  33106. "size",
  33107. "width"
  33108. ];
  33109. var html = [
  33110. "manifest",
  33111. "version"
  33112. ];
  33113. var iframe = [
  33114. "align",
  33115. "allow",
  33116. "allowfullscreen",
  33117. "allowpaymentrequest",
  33118. "allowusermedia",
  33119. "frameborder",
  33120. "height",
  33121. "longdesc",
  33122. "marginheight",
  33123. "marginwidth",
  33124. "name",
  33125. "referrerpolicy",
  33126. "sandbox",
  33127. "scrolling",
  33128. "src",
  33129. "srcdoc",
  33130. "width"
  33131. ];
  33132. var img = [
  33133. "align",
  33134. "alt",
  33135. "border",
  33136. "crossorigin",
  33137. "decoding",
  33138. "height",
  33139. "hspace",
  33140. "ismap",
  33141. "longdesc",
  33142. "name",
  33143. "referrerpolicy",
  33144. "sizes",
  33145. "src",
  33146. "srcset",
  33147. "usemap",
  33148. "vspace",
  33149. "width"
  33150. ];
  33151. var input = [
  33152. "accept",
  33153. "accesskey",
  33154. "align",
  33155. "alt",
  33156. "autocomplete",
  33157. "autofocus",
  33158. "checked",
  33159. "dirname",
  33160. "disabled",
  33161. "form",
  33162. "formaction",
  33163. "formenctype",
  33164. "formmethod",
  33165. "formnovalidate",
  33166. "formtarget",
  33167. "height",
  33168. "ismap",
  33169. "list",
  33170. "max",
  33171. "maxlength",
  33172. "min",
  33173. "minlength",
  33174. "multiple",
  33175. "name",
  33176. "pattern",
  33177. "placeholder",
  33178. "readonly",
  33179. "required",
  33180. "size",
  33181. "src",
  33182. "step",
  33183. "tabindex",
  33184. "title",
  33185. "type",
  33186. "usemap",
  33187. "value",
  33188. "width"
  33189. ];
  33190. var ins = [
  33191. "cite",
  33192. "datetime"
  33193. ];
  33194. var isindex = [
  33195. "prompt"
  33196. ];
  33197. var label = [
  33198. "accesskey",
  33199. "for",
  33200. "form"
  33201. ];
  33202. var legend = [
  33203. "accesskey",
  33204. "align"
  33205. ];
  33206. var li = [
  33207. "type",
  33208. "value"
  33209. ];
  33210. var link$1 = [
  33211. "as",
  33212. "charset",
  33213. "color",
  33214. "crossorigin",
  33215. "href",
  33216. "hreflang",
  33217. "imagesizes",
  33218. "imagesrcset",
  33219. "integrity",
  33220. "media",
  33221. "nonce",
  33222. "referrerpolicy",
  33223. "rel",
  33224. "rev",
  33225. "sizes",
  33226. "target",
  33227. "title",
  33228. "type"
  33229. ];
  33230. var map$1 = [
  33231. "name"
  33232. ];
  33233. var menu = [
  33234. "compact"
  33235. ];
  33236. var meta = [
  33237. "charset",
  33238. "content",
  33239. "http-equiv",
  33240. "name",
  33241. "scheme"
  33242. ];
  33243. var meter = [
  33244. "high",
  33245. "low",
  33246. "max",
  33247. "min",
  33248. "optimum",
  33249. "value"
  33250. ];
  33251. var object = [
  33252. "align",
  33253. "archive",
  33254. "border",
  33255. "classid",
  33256. "codebase",
  33257. "codetype",
  33258. "data",
  33259. "declare",
  33260. "form",
  33261. "height",
  33262. "hspace",
  33263. "name",
  33264. "standby",
  33265. "tabindex",
  33266. "type",
  33267. "typemustmatch",
  33268. "usemap",
  33269. "vspace",
  33270. "width"
  33271. ];
  33272. var ol = [
  33273. "compact",
  33274. "reversed",
  33275. "start",
  33276. "type"
  33277. ];
  33278. var optgroup = [
  33279. "disabled",
  33280. "label"
  33281. ];
  33282. var option = [
  33283. "disabled",
  33284. "label",
  33285. "selected",
  33286. "value"
  33287. ];
  33288. var output = [
  33289. "for",
  33290. "form",
  33291. "name"
  33292. ];
  33293. var p = [
  33294. "align"
  33295. ];
  33296. var param = [
  33297. "name",
  33298. "type",
  33299. "value",
  33300. "valuetype"
  33301. ];
  33302. var pre = [
  33303. "width"
  33304. ];
  33305. var progress = [
  33306. "max",
  33307. "value"
  33308. ];
  33309. var q = [
  33310. "cite"
  33311. ];
  33312. var script = [
  33313. "async",
  33314. "charset",
  33315. "crossorigin",
  33316. "defer",
  33317. "integrity",
  33318. "language",
  33319. "nomodule",
  33320. "nonce",
  33321. "referrerpolicy",
  33322. "src",
  33323. "type"
  33324. ];
  33325. var select = [
  33326. "autocomplete",
  33327. "autofocus",
  33328. "disabled",
  33329. "form",
  33330. "multiple",
  33331. "name",
  33332. "required",
  33333. "size",
  33334. "tabindex"
  33335. ];
  33336. var slot = [
  33337. "name"
  33338. ];
  33339. var source = [
  33340. "media",
  33341. "sizes",
  33342. "src",
  33343. "srcset",
  33344. "type"
  33345. ];
  33346. var style = [
  33347. "media",
  33348. "nonce",
  33349. "title",
  33350. "type"
  33351. ];
  33352. var table = [
  33353. "align",
  33354. "bgcolor",
  33355. "border",
  33356. "cellpadding",
  33357. "cellspacing",
  33358. "frame",
  33359. "rules",
  33360. "summary",
  33361. "width"
  33362. ];
  33363. var tbody = [
  33364. "align",
  33365. "char",
  33366. "charoff",
  33367. "valign"
  33368. ];
  33369. var td = [
  33370. "abbr",
  33371. "align",
  33372. "axis",
  33373. "bgcolor",
  33374. "char",
  33375. "charoff",
  33376. "colspan",
  33377. "headers",
  33378. "height",
  33379. "nowrap",
  33380. "rowspan",
  33381. "scope",
  33382. "valign",
  33383. "width"
  33384. ];
  33385. var textarea = [
  33386. "accesskey",
  33387. "autocomplete",
  33388. "autofocus",
  33389. "cols",
  33390. "dirname",
  33391. "disabled",
  33392. "form",
  33393. "maxlength",
  33394. "minlength",
  33395. "name",
  33396. "placeholder",
  33397. "readonly",
  33398. "required",
  33399. "rows",
  33400. "tabindex",
  33401. "wrap"
  33402. ];
  33403. var tfoot = [
  33404. "align",
  33405. "char",
  33406. "charoff",
  33407. "valign"
  33408. ];
  33409. var th = [
  33410. "abbr",
  33411. "align",
  33412. "axis",
  33413. "bgcolor",
  33414. "char",
  33415. "charoff",
  33416. "colspan",
  33417. "headers",
  33418. "height",
  33419. "nowrap",
  33420. "rowspan",
  33421. "scope",
  33422. "valign",
  33423. "width"
  33424. ];
  33425. var thead = [
  33426. "align",
  33427. "char",
  33428. "charoff",
  33429. "valign"
  33430. ];
  33431. var time = [
  33432. "datetime"
  33433. ];
  33434. var tr = [
  33435. "align",
  33436. "bgcolor",
  33437. "char",
  33438. "charoff",
  33439. "valign"
  33440. ];
  33441. var track = [
  33442. "default",
  33443. "kind",
  33444. "label",
  33445. "src",
  33446. "srclang"
  33447. ];
  33448. var ul = [
  33449. "compact",
  33450. "type"
  33451. ];
  33452. var video = [
  33453. "autoplay",
  33454. "controls",
  33455. "crossorigin",
  33456. "height",
  33457. "loop",
  33458. "muted",
  33459. "playsinline",
  33460. "poster",
  33461. "preload",
  33462. "src",
  33463. "width"
  33464. ];
  33465. var index$1 = {
  33466. "*": [
  33467. "accesskey",
  33468. "autocapitalize",
  33469. "autofocus",
  33470. "class",
  33471. "contenteditable",
  33472. "dir",
  33473. "draggable",
  33474. "enterkeyhint",
  33475. "hidden",
  33476. "id",
  33477. "inputmode",
  33478. "is",
  33479. "itemid",
  33480. "itemprop",
  33481. "itemref",
  33482. "itemscope",
  33483. "itemtype",
  33484. "lang",
  33485. "nonce",
  33486. "slot",
  33487. "spellcheck",
  33488. "style",
  33489. "tabindex",
  33490. "title",
  33491. "translate"
  33492. ],
  33493. a: a,
  33494. abbr: abbr,
  33495. applet: applet,
  33496. area: area,
  33497. audio: audio,
  33498. base: base,
  33499. basefont: basefont,
  33500. bdo: bdo,
  33501. blockquote: blockquote,
  33502. body: body,
  33503. br: br,
  33504. button: button,
  33505. canvas: canvas,
  33506. caption: caption,
  33507. col: col,
  33508. colgroup: colgroup,
  33509. data: data$1,
  33510. del: del$1,
  33511. details: details,
  33512. dfn: dfn,
  33513. dialog: dialog,
  33514. dir: dir,
  33515. div: div,
  33516. dl: dl,
  33517. embed: embed$3,
  33518. fieldset: fieldset,
  33519. font: font,
  33520. form: form,
  33521. frame: frame,
  33522. frameset: frameset,
  33523. h1: h1,
  33524. h2: h2,
  33525. h3: h3,
  33526. h4: h4,
  33527. h5: h5,
  33528. h6: h6,
  33529. head: head,
  33530. hr: hr,
  33531. html: html,
  33532. iframe: iframe,
  33533. img: img,
  33534. input: input,
  33535. ins: ins,
  33536. isindex: isindex,
  33537. label: label,
  33538. legend: legend,
  33539. li: li,
  33540. link: link$1,
  33541. map: map$1,
  33542. menu: menu,
  33543. meta: meta,
  33544. meter: meter,
  33545. object: object,
  33546. ol: ol,
  33547. optgroup: optgroup,
  33548. option: option,
  33549. output: output,
  33550. p: p,
  33551. param: param,
  33552. pre: pre,
  33553. progress: progress,
  33554. q: q,
  33555. script: script,
  33556. select: select,
  33557. slot: slot,
  33558. source: source,
  33559. style: style,
  33560. table: table,
  33561. tbody: tbody,
  33562. td: td,
  33563. textarea: textarea,
  33564. tfoot: tfoot,
  33565. th: th,
  33566. thead: thead,
  33567. time: time,
  33568. tr: tr,
  33569. track: track,
  33570. ul: ul,
  33571. video: video
  33572. };
  33573. var htmlElementAttributes = /*#__PURE__*/Object.freeze({
  33574. __proto__: null,
  33575. a: a,
  33576. abbr: abbr,
  33577. applet: applet,
  33578. area: area,
  33579. audio: audio,
  33580. base: base,
  33581. basefont: basefont,
  33582. bdo: bdo,
  33583. blockquote: blockquote,
  33584. body: body,
  33585. br: br,
  33586. button: button,
  33587. canvas: canvas,
  33588. caption: caption,
  33589. col: col,
  33590. colgroup: colgroup,
  33591. data: data$1,
  33592. del: del$1,
  33593. details: details,
  33594. dfn: dfn,
  33595. dialog: dialog,
  33596. dir: dir,
  33597. div: div,
  33598. dl: dl,
  33599. embed: embed$3,
  33600. fieldset: fieldset,
  33601. font: font,
  33602. form: form,
  33603. frame: frame,
  33604. frameset: frameset,
  33605. h1: h1,
  33606. h2: h2,
  33607. h3: h3,
  33608. h4: h4,
  33609. h5: h5,
  33610. h6: h6,
  33611. head: head,
  33612. hr: hr,
  33613. html: html,
  33614. iframe: iframe,
  33615. img: img,
  33616. input: input,
  33617. ins: ins,
  33618. isindex: isindex,
  33619. label: label,
  33620. legend: legend,
  33621. li: li,
  33622. link: link$1,
  33623. map: map$1,
  33624. menu: menu,
  33625. meta: meta,
  33626. meter: meter,
  33627. object: object,
  33628. ol: ol,
  33629. optgroup: optgroup,
  33630. option: option,
  33631. output: output,
  33632. p: p,
  33633. param: param,
  33634. pre: pre,
  33635. progress: progress,
  33636. q: q,
  33637. script: script,
  33638. select: select,
  33639. slot: slot,
  33640. source: source,
  33641. style: style,
  33642. table: table,
  33643. tbody: tbody,
  33644. td: td,
  33645. textarea: textarea,
  33646. tfoot: tfoot,
  33647. th: th,
  33648. thead: thead,
  33649. time: time,
  33650. tr: tr,
  33651. track: track,
  33652. ul: ul,
  33653. video: video,
  33654. 'default': index$1
  33655. });
  33656. var htmlElementAttributes$1 = getCjsExportFromNamespace(htmlElementAttributes);
  33657. var CSS_DISPLAY_TAGS = json$1.CSS_DISPLAY_TAGS,
  33658. CSS_DISPLAY_DEFAULT = json$1.CSS_DISPLAY_DEFAULT,
  33659. CSS_WHITE_SPACE_TAGS = json$1.CSS_WHITE_SPACE_TAGS,
  33660. CSS_WHITE_SPACE_DEFAULT = json$1.CSS_WHITE_SPACE_DEFAULT;
  33661. var HTML_TAGS = arrayToMap(htmlTagNames$1);
  33662. var HTML_ELEMENT_ATTRIBUTES = mapObject(htmlElementAttributes$1, arrayToMap);
  33663. function arrayToMap(array) {
  33664. var map = Object.create(null);
  33665. var _iteratorNormalCompletion = true;
  33666. var _didIteratorError = false;
  33667. var _iteratorError = undefined;
  33668. try {
  33669. for (var _iterator = array[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  33670. var value = _step.value;
  33671. map[value] = true;
  33672. }
  33673. } catch (err) {
  33674. _didIteratorError = true;
  33675. _iteratorError = err;
  33676. } finally {
  33677. try {
  33678. if (!_iteratorNormalCompletion && _iterator.return != null) {
  33679. _iterator.return();
  33680. }
  33681. } finally {
  33682. if (_didIteratorError) {
  33683. throw _iteratorError;
  33684. }
  33685. }
  33686. }
  33687. return map;
  33688. }
  33689. function mapObject(object, fn) {
  33690. var newObject = Object.create(null);
  33691. for (var _i = 0, _Object$keys = Object.keys(object); _i < _Object$keys.length; _i++) {
  33692. var key = _Object$keys[_i];
  33693. newObject[key] = fn(object[key], key);
  33694. }
  33695. return newObject;
  33696. }
  33697. function shouldPreserveContent(node, options) {
  33698. if (node.type === "element" && node.fullName === "template" && node.attrMap.lang && node.attrMap.lang !== "html") {
  33699. return true;
  33700. } // unterminated node in ie conditional comment
  33701. // e.g. <!--[if lt IE 9]><html><![endif]-->
  33702. if (node.type === "ieConditionalComment" && node.lastChild && !node.lastChild.isSelfClosing && !node.lastChild.endSourceSpan) {
  33703. return true;
  33704. } // incomplete html in ie conditional comment
  33705. // e.g. <!--[if lt IE 9]></div><![endif]-->
  33706. if (node.type === "ieConditionalComment" && !node.complete) {
  33707. return true;
  33708. } // top-level elements (excluding <template>, <style> and <script>) in Vue SFC are considered custom block
  33709. // custom blocks can be written in other languages so we should preserve them to not break the code
  33710. if (options.parser === "vue" && node.type === "element" && node.parent.type === "root" && ["template", "style", "script", // vue parser can be used for vue dom template as well, so we should still format top-level <html>
  33711. "html"].indexOf(node.fullName) === -1) {
  33712. return true;
  33713. } // TODO: handle non-text children in <pre>
  33714. if (isPreLikeNode(node) && node.children.some(function (child) {
  33715. return child.type !== "text" && child.type !== "interpolation";
  33716. })) {
  33717. return true;
  33718. }
  33719. return false;
  33720. }
  33721. function hasPrettierIgnore$3(node) {
  33722. if (node.type === "attribute" || isTextLikeNode(node)) {
  33723. return false;
  33724. }
  33725. if (!node.parent) {
  33726. return false;
  33727. }
  33728. if (typeof node.index !== "number" || node.index === 0) {
  33729. return false;
  33730. }
  33731. var prevNode = node.parent.children[node.index - 1];
  33732. return isPrettierIgnore$1(prevNode);
  33733. }
  33734. function isPrettierIgnore$1(node) {
  33735. return node.type === "comment" && node.value.trim() === "prettier-ignore";
  33736. }
  33737. function getPrettierIgnoreAttributeCommentData(value) {
  33738. var match = value.trim().match(/^prettier-ignore-attribute(?:\s+([^]+))?$/);
  33739. if (!match) {
  33740. return false;
  33741. }
  33742. if (!match[1]) {
  33743. return true;
  33744. }
  33745. return match[1].split(/\s+/);
  33746. }
  33747. /** there's no opening/closing tag or it's considered not breakable */
  33748. function isTextLikeNode(node) {
  33749. return node.type === "text" || node.type === "comment";
  33750. }
  33751. function isScriptLikeTag(node) {
  33752. return node.type === "element" && (node.fullName === "script" || node.fullName === "style" || node.fullName === "svg:style");
  33753. }
  33754. function isFrontMatterNode(node) {
  33755. return node.type === "yaml" || node.type === "toml";
  33756. }
  33757. function canHaveInterpolation(node) {
  33758. return node.children && !isScriptLikeTag(node);
  33759. }
  33760. function isWhitespaceSensitiveNode(node) {
  33761. return isScriptLikeTag(node) || node.type === "interpolation" || isIndentationSensitiveNode(node);
  33762. }
  33763. function isIndentationSensitiveNode(node) {
  33764. return getNodeCssStyleWhiteSpace(node).startsWith("pre");
  33765. }
  33766. function isLeadingSpaceSensitiveNode(node) {
  33767. var isLeadingSpaceSensitive = _isLeadingSpaceSensitiveNode();
  33768. if (isLeadingSpaceSensitive && !node.prev && node.parent && node.parent.tagDefinition && node.parent.tagDefinition.ignoreFirstLf) {
  33769. return node.type === "interpolation";
  33770. }
  33771. return isLeadingSpaceSensitive;
  33772. function _isLeadingSpaceSensitiveNode() {
  33773. if (isFrontMatterNode(node)) {
  33774. return false;
  33775. }
  33776. if ((node.type === "text" || node.type === "interpolation") && node.prev && (node.prev.type === "text" || node.prev.type === "interpolation")) {
  33777. return true;
  33778. }
  33779. if (!node.parent || node.parent.cssDisplay === "none") {
  33780. return false;
  33781. }
  33782. if (isPreLikeNode(node.parent)) {
  33783. return true;
  33784. }
  33785. if (!node.prev && (node.parent.type === "root" || isScriptLikeTag(node.parent) || !isFirstChildLeadingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) {
  33786. return false;
  33787. }
  33788. if (node.prev && !isNextLeadingSpaceSensitiveCssDisplay(node.prev.cssDisplay)) {
  33789. return false;
  33790. }
  33791. return true;
  33792. }
  33793. }
  33794. function isTrailingSpaceSensitiveNode(node) {
  33795. if (isFrontMatterNode(node)) {
  33796. return false;
  33797. }
  33798. if ((node.type === "text" || node.type === "interpolation") && node.next && (node.next.type === "text" || node.next.type === "interpolation")) {
  33799. return true;
  33800. }
  33801. if (!node.parent || node.parent.cssDisplay === "none") {
  33802. return false;
  33803. }
  33804. if (isPreLikeNode(node.parent)) {
  33805. return true;
  33806. }
  33807. if (!node.next && (node.parent.type === "root" || isScriptLikeTag(node.parent) || !isLastChildTrailingSpaceSensitiveCssDisplay(node.parent.cssDisplay))) {
  33808. return false;
  33809. }
  33810. if (node.next && !isPrevTrailingSpaceSensitiveCssDisplay(node.next.cssDisplay)) {
  33811. return false;
  33812. }
  33813. return true;
  33814. }
  33815. function isDanglingSpaceSensitiveNode(node) {
  33816. return isDanglingSpaceSensitiveCssDisplay(node.cssDisplay) && !isScriptLikeTag(node);
  33817. }
  33818. function forceNextEmptyLine(node) {
  33819. return isFrontMatterNode(node) || node.next && node.sourceSpan.end.line + 1 < node.next.sourceSpan.start.line;
  33820. }
  33821. /** firstChild leadingSpaces and lastChild trailingSpaces */
  33822. function forceBreakContent(node) {
  33823. return forceBreakChildren(node) || node.type === "element" && node.children.length !== 0 && (["body", "script", "style"].indexOf(node.name) !== -1 || node.children.some(function (child) {
  33824. return hasNonTextChild(child);
  33825. })) || node.firstChild && node.firstChild === node.lastChild && hasLeadingLineBreak(node.firstChild) && (!node.lastChild.isTrailingSpaceSensitive || hasTrailingLineBreak(node.lastChild));
  33826. }
  33827. /** spaces between children */
  33828. function forceBreakChildren(node) {
  33829. return node.type === "element" && node.children.length !== 0 && (["html", "head", "ul", "ol", "select"].indexOf(node.name) !== -1 || node.cssDisplay.startsWith("table") && node.cssDisplay !== "table-cell");
  33830. }
  33831. function preferHardlineAsLeadingSpaces(node) {
  33832. return preferHardlineAsSurroundingSpaces(node) || node.prev && preferHardlineAsTrailingSpaces(node.prev) || hasSurroundingLineBreak(node);
  33833. }
  33834. function preferHardlineAsTrailingSpaces(node) {
  33835. return preferHardlineAsSurroundingSpaces(node) || node.type === "element" && node.fullName === "br" || hasSurroundingLineBreak(node);
  33836. }
  33837. function hasSurroundingLineBreak(node) {
  33838. return hasLeadingLineBreak(node) && hasTrailingLineBreak(node);
  33839. }
  33840. function hasLeadingLineBreak(node) {
  33841. 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);
  33842. }
  33843. function hasTrailingLineBreak(node) {
  33844. return node.hasTrailingSpaces && (node.next ? node.next.sourceSpan.start.line > node.sourceSpan.end.line : node.parent.type === "root" || node.parent.endSourceSpan.start.line > node.sourceSpan.end.line);
  33845. }
  33846. function preferHardlineAsSurroundingSpaces(node) {
  33847. switch (node.type) {
  33848. case "ieConditionalComment":
  33849. case "comment":
  33850. case "directive":
  33851. return true;
  33852. case "element":
  33853. return ["script", "select"].indexOf(node.name) !== -1;
  33854. }
  33855. return false;
  33856. }
  33857. function getLastDescendant(node) {
  33858. return node.lastChild ? getLastDescendant(node.lastChild) : node;
  33859. }
  33860. function hasNonTextChild(node) {
  33861. return node.children && node.children.some(function (child) {
  33862. return child.type !== "text";
  33863. });
  33864. }
  33865. function inferScriptParser(node) {
  33866. if (node.name === "script" && !node.attrMap.src) {
  33867. if (!node.attrMap.lang && !node.attrMap.type || node.attrMap.type === "module" || node.attrMap.type === "text/javascript" || node.attrMap.type === "text/babel" || node.attrMap.type === "application/javascript") {
  33868. return "babel";
  33869. }
  33870. if (node.attrMap.type === "application/x-typescript" || node.attrMap.lang === "ts" || node.attrMap.lang === "tsx") {
  33871. return "typescript";
  33872. }
  33873. if (node.attrMap.type === "text/markdown") {
  33874. return "markdown";
  33875. }
  33876. if (node.attrMap.type.endsWith("json") || node.attrMap.type.endsWith("importmap")) {
  33877. return "json";
  33878. }
  33879. }
  33880. if (node.name === "style") {
  33881. if (!node.attrMap.lang || node.attrMap.lang === "postcss" || node.attrMap.lang === "css") {
  33882. return "css";
  33883. }
  33884. if (node.attrMap.lang === "scss") {
  33885. return "scss";
  33886. }
  33887. if (node.attrMap.lang === "less") {
  33888. return "less";
  33889. }
  33890. }
  33891. return null;
  33892. }
  33893. function isBlockLikeCssDisplay(cssDisplay) {
  33894. return cssDisplay === "block" || cssDisplay === "list-item" || cssDisplay.startsWith("table");
  33895. }
  33896. function isFirstChildLeadingSpaceSensitiveCssDisplay(cssDisplay) {
  33897. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  33898. }
  33899. function isLastChildTrailingSpaceSensitiveCssDisplay(cssDisplay) {
  33900. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  33901. }
  33902. function isPrevTrailingSpaceSensitiveCssDisplay(cssDisplay) {
  33903. return !isBlockLikeCssDisplay(cssDisplay);
  33904. }
  33905. function isNextLeadingSpaceSensitiveCssDisplay(cssDisplay) {
  33906. return !isBlockLikeCssDisplay(cssDisplay);
  33907. }
  33908. function isDanglingSpaceSensitiveCssDisplay(cssDisplay) {
  33909. return !isBlockLikeCssDisplay(cssDisplay) && cssDisplay !== "inline-block";
  33910. }
  33911. function isPreLikeNode(node) {
  33912. return getNodeCssStyleWhiteSpace(node).startsWith("pre");
  33913. }
  33914. function countParents(path) {
  33915. var predicate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
  33916. return true;
  33917. };
  33918. var counter = 0;
  33919. for (var i = path.stack.length - 1; i >= 0; i--) {
  33920. var value = path.stack[i];
  33921. if (value && typeof value === "object" && !Array.isArray(value) && predicate(value)) {
  33922. counter++;
  33923. }
  33924. }
  33925. return counter;
  33926. }
  33927. function hasParent(node, fn) {
  33928. var current = node;
  33929. while (current) {
  33930. if (fn(current)) {
  33931. return true;
  33932. }
  33933. current = current.parent;
  33934. }
  33935. return false;
  33936. }
  33937. function getNodeCssStyleDisplay(node, options) {
  33938. if (node.prev && node.prev.type === "comment") {
  33939. // <!-- display: block -->
  33940. var match = node.prev.value.match(/^\s*display:\s*([a-z]+)\s*$/);
  33941. if (match) {
  33942. return match[1];
  33943. }
  33944. }
  33945. var isInSvgForeignObject = false;
  33946. if (node.type === "element" && node.namespace === "svg") {
  33947. if (hasParent(node, function (parent) {
  33948. return parent.fullName === "svg:foreignObject";
  33949. })) {
  33950. isInSvgForeignObject = true;
  33951. } else {
  33952. return node.name === "svg" ? "inline-block" : "block";
  33953. }
  33954. }
  33955. switch (options.htmlWhitespaceSensitivity) {
  33956. case "strict":
  33957. return "inline";
  33958. case "ignore":
  33959. return "block";
  33960. default:
  33961. return node.type === "element" && (!node.namespace || isInSvgForeignObject) && CSS_DISPLAY_TAGS[node.name] || CSS_DISPLAY_DEFAULT;
  33962. }
  33963. }
  33964. function getNodeCssStyleWhiteSpace(node) {
  33965. return node.type === "element" && !node.namespace && CSS_WHITE_SPACE_TAGS[node.name] || CSS_WHITE_SPACE_DEFAULT;
  33966. }
  33967. function getMinIndentation(text) {
  33968. var minIndentation = Infinity;
  33969. var _iteratorNormalCompletion2 = true;
  33970. var _didIteratorError2 = false;
  33971. var _iteratorError2 = undefined;
  33972. try {
  33973. for (var _iterator2 = text.split("\n")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  33974. var lineText = _step2.value;
  33975. if (lineText.length === 0) {
  33976. continue;
  33977. }
  33978. if (/\S/.test(lineText[0])) {
  33979. return 0;
  33980. }
  33981. var indentation = lineText.match(/^\s*/)[0].length;
  33982. if (lineText.length === indentation) {
  33983. continue;
  33984. }
  33985. if (indentation < minIndentation) {
  33986. minIndentation = indentation;
  33987. }
  33988. }
  33989. } catch (err) {
  33990. _didIteratorError2 = true;
  33991. _iteratorError2 = err;
  33992. } finally {
  33993. try {
  33994. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  33995. _iterator2.return();
  33996. }
  33997. } finally {
  33998. if (_didIteratorError2) {
  33999. throw _iteratorError2;
  34000. }
  34001. }
  34002. }
  34003. return minIndentation === Infinity ? 0 : minIndentation;
  34004. }
  34005. function dedentString(text) {
  34006. var minIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getMinIndentation(text);
  34007. return minIndent === 0 ? text : text.split("\n").map(function (lineText) {
  34008. return lineText.slice(minIndent);
  34009. }).join("\n");
  34010. }
  34011. function normalizeParts$1(parts) {
  34012. var newParts = [];
  34013. var restParts = parts.slice();
  34014. while (restParts.length !== 0) {
  34015. var part = restParts.shift();
  34016. if (!part) {
  34017. continue;
  34018. }
  34019. if (part.type === "concat") {
  34020. Array.prototype.unshift.apply(restParts, part.parts);
  34021. continue;
  34022. }
  34023. if (newParts.length !== 0 && typeof newParts[newParts.length - 1] === "string" && typeof part === "string") {
  34024. newParts.push(newParts.pop() + part);
  34025. continue;
  34026. }
  34027. newParts.push(part);
  34028. }
  34029. return newParts;
  34030. }
  34031. function identity$2(x) {
  34032. return x;
  34033. }
  34034. function shouldNotPrintClosingTag(node, options) {
  34035. return !node.isSelfClosing && !node.endSourceSpan && (hasPrettierIgnore$3(node) || shouldPreserveContent(node.parent, options));
  34036. }
  34037. function countChars(text, char) {
  34038. var counter = 0;
  34039. for (var i = 0; i < text.length; i++) {
  34040. if (text[i] === char) {
  34041. counter++;
  34042. }
  34043. }
  34044. return counter;
  34045. }
  34046. function unescapeQuoteEntities(text) {
  34047. return text.replace(/&apos;/g, "'").replace(/&quot;/g, '"');
  34048. }
  34049. var utils$5 = {
  34050. HTML_ELEMENT_ATTRIBUTES,
  34051. HTML_TAGS,
  34052. canHaveInterpolation,
  34053. countChars,
  34054. countParents,
  34055. dedentString,
  34056. forceBreakChildren,
  34057. forceBreakContent,
  34058. forceNextEmptyLine,
  34059. getLastDescendant,
  34060. getNodeCssStyleDisplay,
  34061. getNodeCssStyleWhiteSpace,
  34062. getPrettierIgnoreAttributeCommentData,
  34063. hasPrettierIgnore: hasPrettierIgnore$3,
  34064. identity: identity$2,
  34065. inferScriptParser,
  34066. isDanglingSpaceSensitiveNode,
  34067. isFrontMatterNode,
  34068. isIndentationSensitiveNode,
  34069. isLeadingSpaceSensitiveNode,
  34070. isPreLikeNode,
  34071. isScriptLikeTag,
  34072. isTextLikeNode,
  34073. isTrailingSpaceSensitiveNode,
  34074. isWhitespaceSensitiveNode,
  34075. normalizeParts: normalizeParts$1,
  34076. preferHardlineAsLeadingSpaces,
  34077. preferHardlineAsTrailingSpaces,
  34078. shouldNotPrintClosingTag,
  34079. shouldPreserveContent,
  34080. unescapeQuoteEntities
  34081. };
  34082. var canHaveInterpolation$1 = utils$5.canHaveInterpolation,
  34083. getNodeCssStyleDisplay$1 = utils$5.getNodeCssStyleDisplay,
  34084. isDanglingSpaceSensitiveNode$1 = utils$5.isDanglingSpaceSensitiveNode,
  34085. isIndentationSensitiveNode$1 = utils$5.isIndentationSensitiveNode,
  34086. isLeadingSpaceSensitiveNode$1 = utils$5.isLeadingSpaceSensitiveNode,
  34087. isTrailingSpaceSensitiveNode$1 = utils$5.isTrailingSpaceSensitiveNode,
  34088. isWhitespaceSensitiveNode$1 = utils$5.isWhitespaceSensitiveNode;
  34089. var PREPROCESS_PIPELINE = [removeIgnorableFirstLf, mergeIeConditonalStartEndCommentIntoElementOpeningTag, mergeCdataIntoText, extractInterpolation, extractWhitespaces, addCssDisplay, addIsSelfClosing, addHasHtmComponentClosingTag, addIsSpaceSensitive, mergeSimpleElementIntoText];
  34090. function preprocess$2(ast, options) {
  34091. var _iteratorNormalCompletion = true;
  34092. var _didIteratorError = false;
  34093. var _iteratorError = undefined;
  34094. try {
  34095. for (var _iterator = PREPROCESS_PIPELINE[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  34096. var fn = _step.value;
  34097. ast = fn(ast, options);
  34098. }
  34099. } catch (err) {
  34100. _didIteratorError = true;
  34101. _iteratorError = err;
  34102. } finally {
  34103. try {
  34104. if (!_iteratorNormalCompletion && _iterator.return != null) {
  34105. _iterator.return();
  34106. }
  34107. } finally {
  34108. if (_didIteratorError) {
  34109. throw _iteratorError;
  34110. }
  34111. }
  34112. }
  34113. return ast;
  34114. }
  34115. function removeIgnorableFirstLf(ast
  34116. /*, options */
  34117. ) {
  34118. return ast.map(function (node) {
  34119. if (node.type === "element" && node.tagDefinition.ignoreFirstLf && node.children.length !== 0 && node.children[0].type === "text" && node.children[0].value[0] === "\n") {
  34120. var text = node.children[0];
  34121. return node.clone({
  34122. children: text.value.length === 1 ? node.children.slice(1) : [].concat(text.clone({
  34123. value: text.value.slice(1)
  34124. }), node.children.slice(1))
  34125. });
  34126. }
  34127. return node;
  34128. });
  34129. }
  34130. function mergeIeConditonalStartEndCommentIntoElementOpeningTag(ast
  34131. /*, options */
  34132. ) {
  34133. /**
  34134. * <!--[if ...]><!--><target><!--<![endif]-->
  34135. */
  34136. var isTarget = function isTarget(node) {
  34137. return 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;
  34138. };
  34139. return ast.map(function (node) {
  34140. if (node.children) {
  34141. var isTargetResults = node.children.map(isTarget);
  34142. if (isTargetResults.some(Boolean)) {
  34143. var newChildren = [];
  34144. for (var i = 0; i < node.children.length; i++) {
  34145. var child = node.children[i];
  34146. if (isTargetResults[i + 1]) {
  34147. // ieConditionalStartComment
  34148. continue;
  34149. }
  34150. if (isTargetResults[i]) {
  34151. var ieConditionalStartComment = child.prev;
  34152. var ieConditionalEndComment = child.firstChild;
  34153. var ParseSourceSpan = child.sourceSpan.constructor;
  34154. var startSourceSpan = new ParseSourceSpan(ieConditionalStartComment.sourceSpan.start, ieConditionalEndComment.sourceSpan.end);
  34155. var sourceSpan = new ParseSourceSpan(startSourceSpan.start, child.sourceSpan.end);
  34156. newChildren.push(child.clone({
  34157. condition: ieConditionalStartComment.condition,
  34158. sourceSpan,
  34159. startSourceSpan,
  34160. children: child.children.slice(1)
  34161. }));
  34162. continue;
  34163. }
  34164. newChildren.push(child);
  34165. }
  34166. return node.clone({
  34167. children: newChildren
  34168. });
  34169. }
  34170. }
  34171. return node;
  34172. });
  34173. }
  34174. function mergeNodeIntoText(ast, shouldMerge, getValue) {
  34175. return ast.map(function (node) {
  34176. if (node.children) {
  34177. var shouldMergeResults = node.children.map(shouldMerge);
  34178. if (shouldMergeResults.some(Boolean)) {
  34179. var newChildren = [];
  34180. for (var i = 0; i < node.children.length; i++) {
  34181. var child = node.children[i];
  34182. if (child.type !== "text" && !shouldMergeResults[i]) {
  34183. newChildren.push(child);
  34184. continue;
  34185. }
  34186. var newChild = child.type === "text" ? child : child.clone({
  34187. type: "text",
  34188. value: getValue(child)
  34189. });
  34190. if (newChildren.length === 0 || newChildren[newChildren.length - 1].type !== "text") {
  34191. newChildren.push(newChild);
  34192. continue;
  34193. }
  34194. var lastChild = newChildren.pop();
  34195. var ParseSourceSpan = lastChild.sourceSpan.constructor;
  34196. newChildren.push(lastChild.clone({
  34197. value: lastChild.value + newChild.value,
  34198. sourceSpan: new ParseSourceSpan(lastChild.sourceSpan.start, newChild.sourceSpan.end)
  34199. }));
  34200. }
  34201. return node.clone({
  34202. children: newChildren
  34203. });
  34204. }
  34205. }
  34206. return node;
  34207. });
  34208. }
  34209. function mergeCdataIntoText(ast
  34210. /*, options */
  34211. ) {
  34212. return mergeNodeIntoText(ast, function (node) {
  34213. return node.type === "cdata";
  34214. }, function (node) {
  34215. return `<![CDATA[${node.value}]]>`;
  34216. });
  34217. }
  34218. function mergeSimpleElementIntoText(ast
  34219. /*, options */
  34220. ) {
  34221. var isSimpleElement = function isSimpleElement(node) {
  34222. return node.type === "element" && node.attrs.length === 0 && node.children.length === 1 && node.firstChild.type === "text" && // \xA0: non-breaking whitespace
  34223. !/[^\S\xA0]/.test(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";
  34224. };
  34225. return ast.map(function (node) {
  34226. if (node.children) {
  34227. var isSimpleElementResults = node.children.map(isSimpleElement);
  34228. if (isSimpleElementResults.some(Boolean)) {
  34229. var newChildren = [];
  34230. for (var i = 0; i < node.children.length; i++) {
  34231. var child = node.children[i];
  34232. if (isSimpleElementResults[i]) {
  34233. var lastChild = newChildren.pop();
  34234. var nextChild = node.children[++i];
  34235. var ParseSourceSpan = node.sourceSpan.constructor;
  34236. var isTrailingSpaceSensitive = nextChild.isTrailingSpaceSensitive,
  34237. hasTrailingSpaces = nextChild.hasTrailingSpaces;
  34238. newChildren.push(lastChild.clone({
  34239. value: lastChild.value + `<${child.rawName}>` + child.firstChild.value + `</${child.rawName}>` + nextChild.value,
  34240. sourceSpan: new ParseSourceSpan(lastChild.sourceSpan.start, nextChild.sourceSpan.end),
  34241. isTrailingSpaceSensitive,
  34242. hasTrailingSpaces
  34243. }));
  34244. } else {
  34245. newChildren.push(child);
  34246. }
  34247. }
  34248. return node.clone({
  34249. children: newChildren
  34250. });
  34251. }
  34252. }
  34253. return node;
  34254. });
  34255. }
  34256. function extractInterpolation(ast, options) {
  34257. if (options.parser === "html") {
  34258. return ast;
  34259. }
  34260. var interpolationRegex = /\{\{([\s\S]+?)\}\}/g;
  34261. return ast.map(function (node) {
  34262. if (!canHaveInterpolation$1(node)) {
  34263. return node;
  34264. }
  34265. var newChildren = [];
  34266. var _iteratorNormalCompletion2 = true;
  34267. var _didIteratorError2 = false;
  34268. var _iteratorError2 = undefined;
  34269. try {
  34270. for (var _iterator2 = node.children[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  34271. var child = _step2.value;
  34272. if (child.type !== "text") {
  34273. newChildren.push(child);
  34274. continue;
  34275. }
  34276. var ParseSourceSpan = child.sourceSpan.constructor;
  34277. var startSourceSpan = child.sourceSpan.start;
  34278. var endSourceSpan = null;
  34279. var components = child.value.split(interpolationRegex);
  34280. for (var i = 0; i < components.length; i++, startSourceSpan = endSourceSpan) {
  34281. var value = components[i];
  34282. if (i % 2 === 0) {
  34283. endSourceSpan = startSourceSpan.moveBy(value.length);
  34284. if (value.length !== 0) {
  34285. newChildren.push({
  34286. type: "text",
  34287. value,
  34288. sourceSpan: new ParseSourceSpan(startSourceSpan, endSourceSpan)
  34289. });
  34290. }
  34291. continue;
  34292. }
  34293. endSourceSpan = startSourceSpan.moveBy(value.length + 4); // `{{` + `}}`
  34294. newChildren.push({
  34295. type: "interpolation",
  34296. sourceSpan: new ParseSourceSpan(startSourceSpan, endSourceSpan),
  34297. children: value.length === 0 ? [] : [{
  34298. type: "text",
  34299. value,
  34300. sourceSpan: new ParseSourceSpan(startSourceSpan.moveBy(2), endSourceSpan.moveBy(-2))
  34301. }]
  34302. });
  34303. }
  34304. }
  34305. } catch (err) {
  34306. _didIteratorError2 = true;
  34307. _iteratorError2 = err;
  34308. } finally {
  34309. try {
  34310. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  34311. _iterator2.return();
  34312. }
  34313. } finally {
  34314. if (_didIteratorError2) {
  34315. throw _iteratorError2;
  34316. }
  34317. }
  34318. }
  34319. return node.clone({
  34320. children: newChildren
  34321. });
  34322. });
  34323. }
  34324. /**
  34325. * - add `hasLeadingSpaces` field
  34326. * - add `hasTrailingSpaces` field
  34327. * - add `hasDanglingSpaces` field for parent nodes
  34328. * - add `isWhitespaceSensitive`, `isIndentationSensitive` field for text nodes
  34329. * - remove insensitive whitespaces
  34330. */
  34331. function extractWhitespaces(ast
  34332. /*, options*/
  34333. ) {
  34334. var TYPE_WHITESPACE = "whitespace";
  34335. return ast.map(function (node) {
  34336. if (!node.children) {
  34337. return node;
  34338. }
  34339. if (node.children.length === 0 || node.children.length === 1 && node.children[0].type === "text" && node.children[0].value.trim().length === 0) {
  34340. return node.clone({
  34341. children: [],
  34342. hasDanglingSpaces: node.children.length !== 0
  34343. });
  34344. }
  34345. var isWhitespaceSensitive = isWhitespaceSensitiveNode$1(node);
  34346. var isIndentationSensitive = isIndentationSensitiveNode$1(node);
  34347. return node.clone({
  34348. isWhitespaceSensitive,
  34349. isIndentationSensitive,
  34350. children: node.children // extract whitespace nodes
  34351. .reduce(function (newChildren, child) {
  34352. if (child.type !== "text" || isWhitespaceSensitive) {
  34353. return newChildren.concat(child);
  34354. }
  34355. var localChildren = [];
  34356. var _child$value$match = child.value.match(/^(\s*)([\s\S]*?)(\s*)$/),
  34357. _child$value$match2 = _slicedToArray(_child$value$match, 4),
  34358. leadingSpaces = _child$value$match2[1],
  34359. text = _child$value$match2[2],
  34360. trailingSpaces = _child$value$match2[3];
  34361. if (leadingSpaces) {
  34362. localChildren.push({
  34363. type: TYPE_WHITESPACE
  34364. });
  34365. }
  34366. var ParseSourceSpan = child.sourceSpan.constructor;
  34367. if (text) {
  34368. localChildren.push({
  34369. type: "text",
  34370. value: text,
  34371. sourceSpan: new ParseSourceSpan(child.sourceSpan.start.moveBy(leadingSpaces.length), child.sourceSpan.end.moveBy(-trailingSpaces.length))
  34372. });
  34373. }
  34374. if (trailingSpaces) {
  34375. localChildren.push({
  34376. type: TYPE_WHITESPACE
  34377. });
  34378. }
  34379. return newChildren.concat(localChildren);
  34380. }, []) // set hasLeadingSpaces/hasTrailingSpaces and filter whitespace nodes
  34381. .reduce(function (newChildren, child, i, children) {
  34382. if (child.type === TYPE_WHITESPACE) {
  34383. return newChildren;
  34384. }
  34385. var hasLeadingSpaces = i !== 0 && children[i - 1].type === TYPE_WHITESPACE;
  34386. var hasTrailingSpaces = i !== children.length - 1 && children[i + 1].type === TYPE_WHITESPACE;
  34387. return newChildren.concat(Object.assign({}, child, {
  34388. hasLeadingSpaces,
  34389. hasTrailingSpaces
  34390. }));
  34391. }, [])
  34392. });
  34393. });
  34394. }
  34395. function addIsSelfClosing(ast
  34396. /*, options */
  34397. ) {
  34398. return ast.map(function (node) {
  34399. return Object.assign(node, {
  34400. isSelfClosing: !node.children || node.type === "element" && (node.tagDefinition.isVoid || // self-closing
  34401. node.startSourceSpan === node.endSourceSpan)
  34402. });
  34403. });
  34404. }
  34405. function addHasHtmComponentClosingTag(ast, options) {
  34406. return ast.map(function (node) {
  34407. return node.type !== "element" ? node : Object.assign(node, {
  34408. hasHtmComponentClosingTag: node.endSourceSpan && /^<\s*\/\s*\/\s*>$/.test(options.originalText.slice(node.endSourceSpan.start.offset, node.endSourceSpan.end.offset))
  34409. });
  34410. });
  34411. }
  34412. function addCssDisplay(ast, options) {
  34413. return ast.map(function (node) {
  34414. return Object.assign(node, {
  34415. cssDisplay: getNodeCssStyleDisplay$1(node, options)
  34416. });
  34417. });
  34418. }
  34419. /**
  34420. * - add `isLeadingSpaceSensitive` field
  34421. * - add `isTrailingSpaceSensitive` field
  34422. * - add `isDanglingSpaceSensitive` field for parent nodes
  34423. */
  34424. function addIsSpaceSensitive(ast
  34425. /*, options */
  34426. ) {
  34427. return ast.map(function (node) {
  34428. if (!node.children) {
  34429. return node;
  34430. }
  34431. if (node.children.length === 0) {
  34432. return node.clone({
  34433. isDanglingSpaceSensitive: isDanglingSpaceSensitiveNode$1(node)
  34434. });
  34435. }
  34436. return node.clone({
  34437. children: node.children.map(function (child) {
  34438. return Object.assign({}, child, {
  34439. isLeadingSpaceSensitive: isLeadingSpaceSensitiveNode$1(child),
  34440. isTrailingSpaceSensitive: isTrailingSpaceSensitiveNode$1(child)
  34441. });
  34442. }).map(function (child, index, children) {
  34443. return Object.assign({}, child, {
  34444. isLeadingSpaceSensitive: index === 0 ? child.isLeadingSpaceSensitive : children[index - 1].isTrailingSpaceSensitive && child.isLeadingSpaceSensitive,
  34445. isTrailingSpaceSensitive: index === children.length - 1 ? child.isTrailingSpaceSensitive : children[index + 1].isLeadingSpaceSensitive && child.isTrailingSpaceSensitive
  34446. });
  34447. })
  34448. });
  34449. });
  34450. }
  34451. var preprocess_1$2 = preprocess$2;
  34452. function hasPragma$3(text) {
  34453. return /^\s*<!--\s*@(format|prettier)\s*-->/.test(text);
  34454. }
  34455. function insertPragma$6(text) {
  34456. return "<!-- @format -->\n\n" + text.replace(/^\s*\n/, "");
  34457. }
  34458. var pragma$4 = {
  34459. hasPragma: hasPragma$3,
  34460. insertPragma: insertPragma$6
  34461. };
  34462. var _require$$0$builders$8 = doc.builders,
  34463. concat$e = _require$$0$builders$8.concat,
  34464. group$e = _require$$0$builders$8.group;
  34465. /**
  34466. * v-for="... in ..."
  34467. * v-for="... of ..."
  34468. * v-for="(..., ...) in ..."
  34469. * v-for="(..., ...) of ..."
  34470. */
  34471. function printVueFor(value, textToDoc) {
  34472. var _parseVueFor = parseVueFor(value),
  34473. left = _parseVueFor.left,
  34474. operator = _parseVueFor.operator,
  34475. right = _parseVueFor.right;
  34476. return concat$e([group$e(textToDoc(`function _(${left}) {}`, {
  34477. parser: "babel",
  34478. __isVueForBindingLeft: true
  34479. })), " ", operator, " ", textToDoc(right, {
  34480. parser: "__js_expression"
  34481. })]);
  34482. } // modified from https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/parser/index.js#L370-L387
  34483. function parseVueFor(value) {
  34484. var forAliasRE = /([^]*?)\s+(in|of)\s+([^]*)/;
  34485. var forIteratorRE = /,([^,}\]]*)(?:,([^,}\]]*))?$/;
  34486. var stripParensRE = /^\(|\)$/g;
  34487. var inMatch = value.match(forAliasRE);
  34488. if (!inMatch) {
  34489. return;
  34490. }
  34491. var res = {};
  34492. res.for = inMatch[3].trim();
  34493. var alias = inMatch[1].trim().replace(stripParensRE, "");
  34494. var iteratorMatch = alias.match(forIteratorRE);
  34495. if (iteratorMatch) {
  34496. res.alias = alias.replace(forIteratorRE, "");
  34497. res.iterator1 = iteratorMatch[1].trim();
  34498. if (iteratorMatch[2]) {
  34499. res.iterator2 = iteratorMatch[2].trim();
  34500. }
  34501. } else {
  34502. res.alias = alias;
  34503. }
  34504. return {
  34505. left: `${[res.alias, res.iterator1, res.iterator2].filter(Boolean).join(",")}`,
  34506. operator: inMatch[2],
  34507. right: res.for
  34508. };
  34509. }
  34510. function printVueSlotScope(value, textToDoc) {
  34511. return textToDoc(`function _(${value}) {}`, {
  34512. parser: "babel",
  34513. __isVueSlotScope: true
  34514. });
  34515. }
  34516. function isVueEventBindingExpression$2(eventBindingValue) {
  34517. // https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/codegen/events.js#L3-L4
  34518. // arrow function or anonymous function
  34519. var fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/; // simple member expression chain (a, a.b, a['b'], a["b"], a[0], a[b])
  34520. var simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/; // https://github.com/vuejs/vue/blob/v2.5.17/src/compiler/helpers.js#L104
  34521. var value = eventBindingValue.trim();
  34522. return fnExpRE.test(value) || simplePathRE.test(value);
  34523. }
  34524. var syntaxVue = {
  34525. isVueEventBindingExpression: isVueEventBindingExpression$2,
  34526. printVueFor,
  34527. printVueSlotScope
  34528. };
  34529. var parseSrcset = createCommonjsModule(function (module) {
  34530. /**
  34531. * Srcset Parser
  34532. *
  34533. * By Alex Bell | MIT License
  34534. *
  34535. * JS Parser for the string value that appears in markup <img srcset="here">
  34536. *
  34537. * @returns Array [{url: _, d: _, w: _, h:_}, ...]
  34538. *
  34539. * Based super duper closely on the reference algorithm at:
  34540. * https://html.spec.whatwg.org/multipage/embedded-content.html#parse-a-srcset-attribute
  34541. *
  34542. * Most comments are copied in directly from the spec
  34543. * (except for comments in parens).
  34544. */
  34545. (function (root, factory) {
  34546. if ( module.exports) {
  34547. // Node. Does not work with strict CommonJS, but
  34548. // only CommonJS-like environments that support module.exports,
  34549. // like Node.
  34550. module.exports = factory();
  34551. } else {
  34552. // Browser globals (root is window)
  34553. root.parseSrcset = factory();
  34554. }
  34555. })(this, function () {
  34556. // 1. Let input be the value passed to this algorithm.
  34557. return function (input, options) {
  34558. var logger = options && options.logger || console; // UTILITY FUNCTIONS
  34559. // Manual is faster than RegEx
  34560. // http://bjorn.tipling.com/state-and-regular-expressions-in-javascript
  34561. // http://jsperf.com/whitespace-character/5
  34562. function isSpace(c) {
  34563. return c === "\u0020" || // space
  34564. c === "\u0009" || // horizontal tab
  34565. c === "\u000A" || // new line
  34566. c === "\u000C" || // form feed
  34567. c === "\u000D"; // carriage return
  34568. }
  34569. function collectCharacters(regEx) {
  34570. var chars,
  34571. match = regEx.exec(input.substring(pos));
  34572. if (match) {
  34573. chars = match[0];
  34574. pos += chars.length;
  34575. return chars;
  34576. }
  34577. }
  34578. var inputLength = input.length,
  34579. // (Don't use \s, to avoid matching non-breaking space)
  34580. regexLeadingSpaces = /^[ \t\n\r\u000c]+/,
  34581. regexLeadingCommasOrSpaces = /^[, \t\n\r\u000c]+/,
  34582. regexLeadingNotSpaces = /^[^ \t\n\r\u000c]+/,
  34583. regexTrailingCommas = /[,]+$/,
  34584. regexNonNegativeInteger = /^\d+$/,
  34585. // ( Positive or negative or unsigned integers or decimals, without or without exponents.
  34586. // Must include at least one digit.
  34587. // According to spec tests any decimal point must be followed by a digit.
  34588. // No leading plus sign is allowed.)
  34589. // https://html.spec.whatwg.org/multipage/infrastructure.html#valid-floating-point-number
  34590. regexFloatingPoint = /^-?(?:[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/,
  34591. url,
  34592. descriptors,
  34593. currentDescriptor,
  34594. state,
  34595. c,
  34596. // 2. Let position be a pointer into input, initially pointing at the start
  34597. // of the string.
  34598. pos = 0,
  34599. // 3. Let candidates be an initially empty source set.
  34600. candidates = []; // 4. Splitting loop: Collect a sequence of characters that are space
  34601. // characters or U+002C COMMA characters. If any U+002C COMMA characters
  34602. // were collected, that is a parse error.
  34603. while (true) {
  34604. collectCharacters(regexLeadingCommasOrSpaces); // 5. If position is past the end of input, return candidates and abort these steps.
  34605. if (pos >= inputLength) {
  34606. return candidates; // (we're done, this is the sole return path)
  34607. } // 6. Collect a sequence of characters that are not space characters,
  34608. // and let that be url.
  34609. url = collectCharacters(regexLeadingNotSpaces); // 7. Let descriptors be a new empty list.
  34610. descriptors = []; // 8. If url ends with a U+002C COMMA character (,), follow these substeps:
  34611. // (1). Remove all trailing U+002C COMMA characters from url. If this removed
  34612. // more than one character, that is a parse error.
  34613. if (url.slice(-1) === ",") {
  34614. url = url.replace(regexTrailingCommas, ""); // (Jump ahead to step 9 to skip tokenization and just push the candidate).
  34615. parseDescriptors(); // Otherwise, follow these substeps:
  34616. } else {
  34617. tokenize();
  34618. } // (close else of step 8)
  34619. // 16. Return to the step labeled splitting loop.
  34620. } // (Close of big while loop.)
  34621. /**
  34622. * Tokenizes descriptor properties prior to parsing
  34623. * Returns undefined.
  34624. */
  34625. function tokenize() {
  34626. // 8.1. Descriptor tokeniser: Skip whitespace
  34627. collectCharacters(regexLeadingSpaces); // 8.2. Let current descriptor be the empty string.
  34628. currentDescriptor = ""; // 8.3. Let state be in descriptor.
  34629. state = "in descriptor";
  34630. while (true) {
  34631. // 8.4. Let c be the character at position.
  34632. c = input.charAt(pos); // Do the following depending on the value of state.
  34633. // For the purpose of this step, "EOF" is a special character representing
  34634. // that position is past the end of input.
  34635. // In descriptor
  34636. if (state === "in descriptor") {
  34637. // Do the following, depending on the value of c:
  34638. // Space character
  34639. // If current descriptor is not empty, append current descriptor to
  34640. // descriptors and let current descriptor be the empty string.
  34641. // Set state to after descriptor.
  34642. if (isSpace(c)) {
  34643. if (currentDescriptor) {
  34644. descriptors.push(currentDescriptor);
  34645. currentDescriptor = "";
  34646. state = "after descriptor";
  34647. } // U+002C COMMA (,)
  34648. // Advance position to the next character in input. If current descriptor
  34649. // is not empty, append current descriptor to descriptors. Jump to the step
  34650. // labeled descriptor parser.
  34651. } else if (c === ",") {
  34652. pos += 1;
  34653. if (currentDescriptor) {
  34654. descriptors.push(currentDescriptor);
  34655. }
  34656. parseDescriptors();
  34657. return; // U+0028 LEFT PARENTHESIS (()
  34658. // Append c to current descriptor. Set state to in parens.
  34659. } else if (c === "\u0028") {
  34660. currentDescriptor = currentDescriptor + c;
  34661. state = "in parens"; // EOF
  34662. // If current descriptor is not empty, append current descriptor to
  34663. // descriptors. Jump to the step labeled descriptor parser.
  34664. } else if (c === "") {
  34665. if (currentDescriptor) {
  34666. descriptors.push(currentDescriptor);
  34667. }
  34668. parseDescriptors();
  34669. return; // Anything else
  34670. // Append c to current descriptor.
  34671. } else {
  34672. currentDescriptor = currentDescriptor + c;
  34673. } // (end "in descriptor"
  34674. // In parens
  34675. } else if (state === "in parens") {
  34676. // U+0029 RIGHT PARENTHESIS ())
  34677. // Append c to current descriptor. Set state to in descriptor.
  34678. if (c === ")") {
  34679. currentDescriptor = currentDescriptor + c;
  34680. state = "in descriptor"; // EOF
  34681. // Append current descriptor to descriptors. Jump to the step labeled
  34682. // descriptor parser.
  34683. } else if (c === "") {
  34684. descriptors.push(currentDescriptor);
  34685. parseDescriptors();
  34686. return; // Anything else
  34687. // Append c to current descriptor.
  34688. } else {
  34689. currentDescriptor = currentDescriptor + c;
  34690. } // After descriptor
  34691. } else if (state === "after descriptor") {
  34692. // Do the following, depending on the value of c:
  34693. // Space character: Stay in this state.
  34694. if (isSpace(c)) ; else if (c === "") {
  34695. parseDescriptors();
  34696. return; // Anything else
  34697. // Set state to in descriptor. Set position to the previous character in input.
  34698. } else {
  34699. state = "in descriptor";
  34700. pos -= 1;
  34701. }
  34702. } // Advance position to the next character in input.
  34703. pos += 1; // Repeat this step.
  34704. } // (close while true loop)
  34705. }
  34706. /**
  34707. * Adds descriptor properties to a candidate, pushes to the candidates array
  34708. * @return undefined
  34709. */
  34710. // Declared outside of the while loop so that it's only created once.
  34711. function parseDescriptors() {
  34712. // 9. Descriptor parser: Let error be no.
  34713. var pError = false,
  34714. // 10. Let width be absent.
  34715. // 11. Let density be absent.
  34716. // 12. Let future-compat-h be absent. (We're implementing it now as h)
  34717. w,
  34718. d,
  34719. h,
  34720. i,
  34721. candidate = {},
  34722. desc,
  34723. lastChar,
  34724. value,
  34725. intVal,
  34726. floatVal; // 13. For each descriptor in descriptors, run the appropriate set of steps
  34727. // from the following list:
  34728. for (i = 0; i < descriptors.length; i++) {
  34729. desc = descriptors[i];
  34730. lastChar = desc[desc.length - 1];
  34731. value = desc.substring(0, desc.length - 1);
  34732. intVal = parseInt(value, 10);
  34733. floatVal = parseFloat(value); // If the descriptor consists of a valid non-negative integer followed by
  34734. // a U+0077 LATIN SMALL LETTER W character
  34735. if (regexNonNegativeInteger.test(value) && lastChar === "w") {
  34736. // If width and density are not both absent, then let error be yes.
  34737. if (w || d) {
  34738. pError = true;
  34739. } // Apply the rules for parsing non-negative integers to the descriptor.
  34740. // If the result is zero, let error be yes.
  34741. // Otherwise, let width be the result.
  34742. if (intVal === 0) {
  34743. pError = true;
  34744. } else {
  34745. w = intVal;
  34746. } // If the descriptor consists of a valid floating-point number followed by
  34747. // a U+0078 LATIN SMALL LETTER X character
  34748. } else if (regexFloatingPoint.test(value) && lastChar === "x") {
  34749. // If width, density and future-compat-h are not all absent, then let error
  34750. // be yes.
  34751. if (w || d || h) {
  34752. pError = true;
  34753. } // Apply the rules for parsing floating-point number values to the descriptor.
  34754. // If the result is less than zero, let error be yes. Otherwise, let density
  34755. // be the result.
  34756. if (floatVal < 0) {
  34757. pError = true;
  34758. } else {
  34759. d = floatVal;
  34760. } // If the descriptor consists of a valid non-negative integer followed by
  34761. // a U+0068 LATIN SMALL LETTER H character
  34762. } else if (regexNonNegativeInteger.test(value) && lastChar === "h") {
  34763. // If height and density are not both absent, then let error be yes.
  34764. if (h || d) {
  34765. pError = true;
  34766. } // Apply the rules for parsing non-negative integers to the descriptor.
  34767. // If the result is zero, let error be yes. Otherwise, let future-compat-h
  34768. // be the result.
  34769. if (intVal === 0) {
  34770. pError = true;
  34771. } else {
  34772. h = intVal;
  34773. } // Anything else, Let error be yes.
  34774. } else {
  34775. pError = true;
  34776. }
  34777. } // (close step 13 for loop)
  34778. // 15. If error is still no, then append a new image source to candidates whose
  34779. // URL is url, associated with a width width if not absent and a pixel
  34780. // density density if not absent. Otherwise, there is a parse error.
  34781. if (!pError) {
  34782. candidate.url = url;
  34783. if (w) {
  34784. candidate.w = w;
  34785. }
  34786. if (d) {
  34787. candidate.d = d;
  34788. }
  34789. if (h) {
  34790. candidate.h = h;
  34791. }
  34792. candidates.push(candidate);
  34793. } else if (logger && logger.error) {
  34794. logger.error("Invalid srcset descriptor found in '" + input + "' at '" + desc + "'.");
  34795. }
  34796. } // (close parseDescriptors fn)
  34797. };
  34798. });
  34799. });
  34800. var _require$$0$builders$9 = doc.builders,
  34801. concat$f = _require$$0$builders$9.concat,
  34802. ifBreak$6 = _require$$0$builders$9.ifBreak,
  34803. join$a = _require$$0$builders$9.join,
  34804. line$7 = _require$$0$builders$9.line;
  34805. function printImgSrcset(value) {
  34806. var srcset = parseSrcset(value, {
  34807. logger: {
  34808. error(message) {
  34809. throw new Error(message);
  34810. }
  34811. }
  34812. });
  34813. var hasW = srcset.some(function (src) {
  34814. return src.w;
  34815. });
  34816. var hasH = srcset.some(function (src) {
  34817. return src.h;
  34818. });
  34819. var hasX = srcset.some(function (src) {
  34820. return src.d;
  34821. });
  34822. if (hasW + hasH + hasX !== 1) {
  34823. throw new Error(`Mixed descriptor in srcset is not supported`);
  34824. }
  34825. var key = hasW ? "w" : hasH ? "h" : "d";
  34826. var unit = hasW ? "w" : hasH ? "h" : "x";
  34827. var getMax = function getMax(values) {
  34828. return Math.max.apply(Math, values);
  34829. };
  34830. var urls = srcset.map(function (src) {
  34831. return src.url;
  34832. });
  34833. var maxUrlLength = getMax(urls.map(function (url) {
  34834. return url.length;
  34835. }));
  34836. var descriptors = srcset.map(function (src) {
  34837. return src[key];
  34838. }).map(function (descriptor) {
  34839. return descriptor ? descriptor.toString() : "";
  34840. });
  34841. var descriptorLeftLengths = descriptors.map(function (descriptor) {
  34842. var index = descriptor.indexOf(".");
  34843. return index === -1 ? descriptor.length : index;
  34844. });
  34845. var maxDescriptorLeftLength = getMax(descriptorLeftLengths);
  34846. return join$a(concat$f([",", line$7]), urls.map(function (url, index) {
  34847. var parts = [url];
  34848. var descriptor = descriptors[index];
  34849. if (descriptor) {
  34850. var urlPadding = maxUrlLength - url.length + 1;
  34851. var descriptorPadding = maxDescriptorLeftLength - descriptorLeftLengths[index];
  34852. var alignment = " ".repeat(urlPadding + descriptorPadding);
  34853. parts.push(ifBreak$6(alignment, " "), descriptor + unit);
  34854. }
  34855. return concat$f(parts);
  34856. }));
  34857. }
  34858. var syntaxAttribute = {
  34859. printImgSrcset
  34860. };
  34861. var builders = doc.builders,
  34862. _require$$0$utils = doc.utils,
  34863. stripTrailingHardline$2 = _require$$0$utils.stripTrailingHardline,
  34864. mapDoc$7 = _require$$0$utils.mapDoc;
  34865. var breakParent$4 = builders.breakParent,
  34866. dedentToRoot$2 = builders.dedentToRoot,
  34867. fill$5 = builders.fill,
  34868. group$f = builders.group,
  34869. hardline$c = builders.hardline,
  34870. ifBreak$7 = builders.ifBreak,
  34871. indent$9 = builders.indent,
  34872. join$b = builders.join,
  34873. line$8 = builders.line,
  34874. literalline$6 = builders.literalline,
  34875. markAsRoot$4 = builders.markAsRoot,
  34876. softline$7 = builders.softline;
  34877. var countChars$1 = utils$5.countChars,
  34878. countParents$1 = utils$5.countParents,
  34879. dedentString$1 = utils$5.dedentString,
  34880. forceBreakChildren$1 = utils$5.forceBreakChildren,
  34881. forceBreakContent$1 = utils$5.forceBreakContent,
  34882. forceNextEmptyLine$1 = utils$5.forceNextEmptyLine,
  34883. getLastDescendant$1 = utils$5.getLastDescendant,
  34884. getPrettierIgnoreAttributeCommentData$1 = utils$5.getPrettierIgnoreAttributeCommentData,
  34885. hasPrettierIgnore$4 = utils$5.hasPrettierIgnore,
  34886. inferScriptParser$1 = utils$5.inferScriptParser,
  34887. isScriptLikeTag$1 = utils$5.isScriptLikeTag,
  34888. isTextLikeNode$1 = utils$5.isTextLikeNode,
  34889. normalizeParts$2 = utils$5.normalizeParts,
  34890. preferHardlineAsLeadingSpaces$1 = utils$5.preferHardlineAsLeadingSpaces,
  34891. shouldNotPrintClosingTag$1 = utils$5.shouldNotPrintClosingTag,
  34892. shouldPreserveContent$1 = utils$5.shouldPreserveContent,
  34893. unescapeQuoteEntities$1 = utils$5.unescapeQuoteEntities;
  34894. var replaceEndOfLineWith$2 = util.replaceEndOfLineWith;
  34895. var insertPragma$7 = pragma$4.insertPragma;
  34896. var printVueFor$1 = syntaxVue.printVueFor,
  34897. printVueSlotScope$1 = syntaxVue.printVueSlotScope,
  34898. isVueEventBindingExpression$3 = syntaxVue.isVueEventBindingExpression;
  34899. var printImgSrcset$1 = syntaxAttribute.printImgSrcset;
  34900. function concat$g(parts) {
  34901. var newParts = normalizeParts$2(parts);
  34902. return newParts.length === 0 ? "" : newParts.length === 1 ? newParts[0] : builders.concat(newParts);
  34903. }
  34904. function embed$4(path, print, textToDoc, options) {
  34905. var node = path.getValue();
  34906. switch (node.type) {
  34907. case "text":
  34908. {
  34909. if (isScriptLikeTag$1(node.parent)) {
  34910. var parser = inferScriptParser$1(node.parent);
  34911. if (parser) {
  34912. var value = parser === "markdown" ? dedentString$1(node.value.replace(/^[^\S\n]*?\n/, "")) : node.value;
  34913. return builders.concat([concat$g([breakParent$4, printOpeningTagPrefix(node, options), stripTrailingHardline$2(textToDoc(value, {
  34914. parser
  34915. })), printClosingTagSuffix(node, options)])]);
  34916. }
  34917. } else if (node.parent.type === "interpolation") {
  34918. return concat$g([indent$9(concat$g([line$8, textToDoc(node.value, Object.assign({
  34919. __isInHtmlInterpolation: true // to avoid unexpected `}}`
  34920. }, options.parser === "angular" ? {
  34921. parser: "__ng_interpolation",
  34922. trailingComma: "none"
  34923. } : options.parser === "vue" ? {
  34924. parser: "__vue_expression"
  34925. } : {
  34926. parser: "__js_expression"
  34927. }))])), node.parent.next && needsToBorrowPrevClosingTagEndMarker(node.parent.next) ? " " : line$8]);
  34928. }
  34929. break;
  34930. }
  34931. case "attribute":
  34932. {
  34933. if (!node.value) {
  34934. break;
  34935. } // lit-html: html`<my-element obj=${obj}></my-element>`
  34936. if (/^PRETTIER_HTML_PLACEHOLDER_\d+_\d+_IN_JS$/.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) {
  34937. return concat$g([node.rawName, "=", node.value]);
  34938. } // lwc: html`<my-element data-for={value}></my-element>`
  34939. if (options.parser === "lwc") {
  34940. var interpolationRegex = /^\{[\s\S]*\}$/;
  34941. if (interpolationRegex.test(options.originalText.slice(node.valueSpan.start.offset, node.valueSpan.end.offset))) {
  34942. return concat$g([node.rawName, "=", node.value]);
  34943. }
  34944. }
  34945. var embeddedAttributeValueDoc = printEmbeddedAttributeValue(node, function (code, opts) {
  34946. return (// strictly prefer single quote to avoid unnecessary html entity escape
  34947. textToDoc(code, Object.assign({
  34948. __isInHtmlAttribute: true
  34949. }, opts))
  34950. );
  34951. }, options);
  34952. if (embeddedAttributeValueDoc) {
  34953. return concat$g([node.rawName, '="', group$f(mapDoc$7(embeddedAttributeValueDoc, function (doc) {
  34954. return typeof doc === "string" ? doc.replace(/"/g, "&quot;") : doc;
  34955. })), '"']);
  34956. }
  34957. break;
  34958. }
  34959. case "yaml":
  34960. return markAsRoot$4(concat$g(["---", hardline$c, node.value.trim().length === 0 ? "" : textToDoc(node.value, {
  34961. parser: "yaml"
  34962. }), "---"]));
  34963. }
  34964. }
  34965. function genericPrint$5(path, options, print) {
  34966. var node = path.getValue();
  34967. switch (node.type) {
  34968. case "root":
  34969. // use original concat to not break stripTrailingHardline
  34970. return builders.concat([group$f(printChildren$2(path, options, print)), hardline$c]);
  34971. case "element":
  34972. case "ieConditionalComment":
  34973. {
  34974. /**
  34975. * do not break:
  34976. *
  34977. * <div>{{
  34978. * ~
  34979. * interpolation
  34980. * }}</div>
  34981. * ~
  34982. *
  34983. * exception: break if the opening tag breaks
  34984. *
  34985. * <div
  34986. * long
  34987. * ~
  34988. * >{{
  34989. * interpolation
  34990. * }}</div
  34991. * ~
  34992. * >
  34993. */
  34994. var shouldHugContent = node.children.length === 1 && node.firstChild.type === "interpolation" && node.firstChild.isLeadingSpaceSensitive && !node.firstChild.hasLeadingSpaces && node.lastChild.isTrailingSpaceSensitive && !node.lastChild.hasTrailingSpaces;
  34995. var attrGroupId = Symbol("element-attr-group-id");
  34996. return concat$g([group$f(concat$g([group$f(printOpeningTag(path, options, print), {
  34997. id: attrGroupId
  34998. }), node.children.length === 0 ? node.hasDanglingSpaces && node.isDanglingSpaceSensitive ? line$8 : "" : concat$g([forceBreakContent$1(node) ? breakParent$4 : "", function (childrenDoc) {
  34999. return shouldHugContent ? ifBreak$7(indent$9(childrenDoc), childrenDoc, {
  35000. groupId: attrGroupId
  35001. }) : isScriptLikeTag$1(node) && node.parent.type === "root" && options.parser === "vue" && !options.vueIndentScriptAndStyle ? childrenDoc : indent$9(childrenDoc);
  35002. }(concat$g([shouldHugContent ? ifBreak$7(softline$7, "", {
  35003. groupId: attrGroupId
  35004. }) : node.firstChild.hasLeadingSpaces && node.firstChild.isLeadingSpaceSensitive ? line$8 : node.firstChild.type === "text" && node.isWhitespaceSensitive && node.isIndentationSensitive ? dedentToRoot$2(softline$7) : softline$7, printChildren$2(path, options, print)])), (node.next ? needsToBorrowPrevClosingTagEndMarker(node.next) : needsToBorrowLastChildClosingTagEndMarker(node.parent)) ? node.lastChild.hasTrailingSpaces && node.lastChild.isTrailingSpaceSensitive ? " " : "" : shouldHugContent ? ifBreak$7(softline$7, "", {
  35005. groupId: attrGroupId
  35006. }) : node.lastChild.hasTrailingSpaces && node.lastChild.isTrailingSpaceSensitive ? line$8 : (node.lastChild.type === "comment" || node.lastChild.type === "text" && node.isWhitespaceSensitive && node.isIndentationSensitive) && new RegExp(`\\n\\s{${options.tabWidth * countParents$1(path, function (n) {
  35007. return n.parent && n.parent.type !== "root";
  35008. })}}$`).test(node.lastChild.value) ?
  35009. /**
  35010. * <div>
  35011. * <pre>
  35012. * something
  35013. * </pre>
  35014. * ~
  35015. * </div>
  35016. */
  35017. "" : softline$7])])), printClosingTag(node, options)]);
  35018. }
  35019. case "ieConditionalStartComment":
  35020. case "ieConditionalEndComment":
  35021. return concat$g([printOpeningTagStart(node), printClosingTagEnd(node)]);
  35022. case "interpolation":
  35023. return concat$g([printOpeningTagStart(node, options), concat$g(path.map(print, "children")), printClosingTagEnd(node, options)]);
  35024. case "text":
  35025. {
  35026. if (node.parent.type === "interpolation") {
  35027. // replace the trailing literalline with hardline for better readability
  35028. var trailingNewlineRegex = /\n[^\S\n]*?$/;
  35029. var hasTrailingNewline = trailingNewlineRegex.test(node.value);
  35030. var value = hasTrailingNewline ? node.value.replace(trailingNewlineRegex, "") : node.value;
  35031. return concat$g([concat$g(replaceEndOfLineWith$2(value, literalline$6)), hasTrailingNewline ? hardline$c : ""]);
  35032. }
  35033. return fill$5(normalizeParts$2([].concat(printOpeningTagPrefix(node, options), getTextValueParts(node), printClosingTagSuffix(node, options))));
  35034. }
  35035. case "docType":
  35036. return concat$g([group$f(concat$g([printOpeningTagStart(node, options), " ", node.value.replace(/^html\b/i, "html").replace(/\s+/g, " ")])), printClosingTagEnd(node, options)]);
  35037. case "comment":
  35038. {
  35039. return concat$g([printOpeningTagPrefix(node, options), concat$g(replaceEndOfLineWith$2(options.originalText.slice(options.locStart(node), options.locEnd(node)), literalline$6)), printClosingTagSuffix(node, options)]);
  35040. }
  35041. case "attribute":
  35042. {
  35043. if (node.value === null) {
  35044. return node.rawName;
  35045. }
  35046. var _value = unescapeQuoteEntities$1(node.value);
  35047. var singleQuoteCount = countChars$1(_value, "'");
  35048. var doubleQuoteCount = countChars$1(_value, '"');
  35049. var quote = singleQuoteCount < doubleQuoteCount ? "'" : '"';
  35050. return concat$g([node.rawName, concat$g(["=", quote, concat$g(replaceEndOfLineWith$2(quote === '"' ? _value.replace(/"/g, "&quot;") : _value.replace(/'/g, "&apos;"), literalline$6)), quote])]);
  35051. }
  35052. case "yaml":
  35053. case "toml":
  35054. return concat$g(replaceEndOfLineWith$2(node.raw, literalline$6));
  35055. default:
  35056. throw new Error(`Unexpected node type ${node.type}`);
  35057. }
  35058. }
  35059. function printChildren$2(path, options, print) {
  35060. var node = path.getValue();
  35061. if (forceBreakChildren$1(node)) {
  35062. return concat$g([breakParent$4, concat$g(path.map(function (childPath) {
  35063. var childNode = childPath.getValue();
  35064. var prevBetweenLine = !childNode.prev ? "" : printBetweenLine(childNode.prev, childNode);
  35065. return concat$g([!prevBetweenLine ? "" : concat$g([prevBetweenLine, forceNextEmptyLine$1(childNode.prev) ? hardline$c : ""]), printChild(childPath)]);
  35066. }, "children"))]);
  35067. }
  35068. var groupIds = node.children.map(function () {
  35069. return Symbol("");
  35070. });
  35071. return concat$g(path.map(function (childPath, childIndex) {
  35072. var childNode = childPath.getValue();
  35073. if (isTextLikeNode$1(childNode)) {
  35074. if (childNode.prev && isTextLikeNode$1(childNode.prev)) {
  35075. var _prevBetweenLine = printBetweenLine(childNode.prev, childNode);
  35076. if (_prevBetweenLine) {
  35077. if (forceNextEmptyLine$1(childNode.prev)) {
  35078. return concat$g([hardline$c, hardline$c, printChild(childPath)]);
  35079. }
  35080. return concat$g([_prevBetweenLine, printChild(childPath)]);
  35081. }
  35082. }
  35083. return printChild(childPath);
  35084. }
  35085. var prevParts = [];
  35086. var leadingParts = [];
  35087. var trailingParts = [];
  35088. var nextParts = [];
  35089. var prevBetweenLine = childNode.prev ? printBetweenLine(childNode.prev, childNode) : "";
  35090. var nextBetweenLine = childNode.next ? printBetweenLine(childNode, childNode.next) : "";
  35091. if (prevBetweenLine) {
  35092. if (forceNextEmptyLine$1(childNode.prev)) {
  35093. prevParts.push(hardline$c, hardline$c);
  35094. } else if (prevBetweenLine === hardline$c) {
  35095. prevParts.push(hardline$c);
  35096. } else {
  35097. if (isTextLikeNode$1(childNode.prev)) {
  35098. leadingParts.push(prevBetweenLine);
  35099. } else {
  35100. leadingParts.push(ifBreak$7("", softline$7, {
  35101. groupId: groupIds[childIndex - 1]
  35102. }));
  35103. }
  35104. }
  35105. }
  35106. if (nextBetweenLine) {
  35107. if (forceNextEmptyLine$1(childNode)) {
  35108. if (isTextLikeNode$1(childNode.next)) {
  35109. nextParts.push(hardline$c, hardline$c);
  35110. }
  35111. } else if (nextBetweenLine === hardline$c) {
  35112. if (isTextLikeNode$1(childNode.next)) {
  35113. nextParts.push(hardline$c);
  35114. }
  35115. } else {
  35116. trailingParts.push(nextBetweenLine);
  35117. }
  35118. }
  35119. return concat$g([].concat(prevParts, group$f(concat$g([concat$g(leadingParts), group$f(concat$g([printChild(childPath), concat$g(trailingParts)]), {
  35120. id: groupIds[childIndex]
  35121. })])), nextParts));
  35122. }, "children"));
  35123. function printChild(childPath) {
  35124. var child = childPath.getValue();
  35125. if (hasPrettierIgnore$4(child)) {
  35126. return concat$g([].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$6), printClosingTagSuffix(child, options)));
  35127. }
  35128. if (shouldPreserveContent$1(child, options)) {
  35129. return concat$g([].concat(printOpeningTagPrefix(child, options), group$f(printOpeningTag(childPath, options, print)), replaceEndOfLineWith$2(options.originalText.slice(child.startSourceSpan.end.offset + (child.firstChild && needsToBorrowParentOpeningTagEndMarker(child.firstChild) ? -printOpeningTagEndMarker(child).length : 0), child.endSourceSpan.start.offset + (child.lastChild && needsToBorrowParentClosingTagStartMarker(child.lastChild) ? printClosingTagStartMarker(child, options).length : needsToBorrowLastChildClosingTagEndMarker(child) ? -printClosingTagEndMarker(child.lastChild, options).length : 0)), literalline$6), printClosingTag(child, options), printClosingTagSuffix(child, options)));
  35130. }
  35131. return print(childPath);
  35132. }
  35133. function printBetweenLine(prevNode, nextNode) {
  35134. return isTextLikeNode$1(prevNode) && isTextLikeNode$1(nextNode) ? prevNode.isTrailingSpaceSensitive ? prevNode.hasTrailingSpaces ? preferHardlineAsLeadingSpaces$1(nextNode) ? hardline$c : line$8 : "" : preferHardlineAsLeadingSpaces$1(nextNode) ? hardline$c : softline$7 : needsToBorrowNextOpeningTagStartMarker(prevNode) && (
  35135. /**
  35136. * 123<a
  35137. * ~
  35138. * ><b>
  35139. */
  35140. nextNode.firstChild ||
  35141. /**
  35142. * 123<!--
  35143. * ~
  35144. * -->
  35145. */
  35146. nextNode.isSelfClosing ||
  35147. /**
  35148. * 123<span
  35149. * ~
  35150. * attr
  35151. */
  35152. nextNode.type === "element" && nextNode.attrs.length !== 0) ||
  35153. /**
  35154. * <img
  35155. * src="long"
  35156. * ~
  35157. * />123
  35158. */
  35159. prevNode.type === "element" && prevNode.isSelfClosing && needsToBorrowPrevClosingTagEndMarker(nextNode) ? "" : !nextNode.isLeadingSpaceSensitive || preferHardlineAsLeadingSpaces$1(nextNode) ||
  35160. /**
  35161. * Want to write us a letter? Use our<a
  35162. * ><b><a>mailing address</a></b></a
  35163. * ~
  35164. * >.
  35165. */
  35166. needsToBorrowPrevClosingTagEndMarker(nextNode) && prevNode.lastChild && needsToBorrowParentClosingTagStartMarker(prevNode.lastChild) && prevNode.lastChild.lastChild && needsToBorrowParentClosingTagStartMarker(prevNode.lastChild.lastChild) ? hardline$c : nextNode.hasLeadingSpaces ? line$8 : softline$7;
  35167. }
  35168. }
  35169. function printOpeningTag(path, options, print) {
  35170. var node = path.getValue();
  35171. var forceNotToBreakAttrContent = node.type === "element" && node.fullName === "script" && node.attrs.length === 1 && node.attrs[0].fullName === "src" && node.children.length === 0;
  35172. return concat$g([printOpeningTagStart(node, options), !node.attrs || node.attrs.length === 0 ? node.isSelfClosing ?
  35173. /**
  35174. * <br />
  35175. * ^
  35176. */
  35177. " " : "" : concat$g([indent$9(concat$g([forceNotToBreakAttrContent ? " " : line$8, join$b(line$8, function (ignoreAttributeData) {
  35178. var hasPrettierIgnoreAttribute = typeof ignoreAttributeData === "boolean" ? function () {
  35179. return ignoreAttributeData;
  35180. } : Array.isArray(ignoreAttributeData) ? function (attr) {
  35181. return ignoreAttributeData.indexOf(attr.rawName) !== -1;
  35182. } : function () {
  35183. return false;
  35184. };
  35185. return path.map(function (attrPath) {
  35186. var attr = attrPath.getValue();
  35187. return hasPrettierIgnoreAttribute(attr) ? concat$g(replaceEndOfLineWith$2(options.originalText.slice(options.locStart(attr), options.locEnd(attr)), literalline$6)) : print(attrPath);
  35188. }, "attrs");
  35189. }(node.prev && node.prev.type === "comment" && getPrettierIgnoreAttributeCommentData$1(node.prev.value)))])),
  35190. /**
  35191. * 123<a
  35192. * attr
  35193. * ~
  35194. * >456
  35195. */
  35196. node.firstChild && needsToBorrowParentOpeningTagEndMarker(node.firstChild) ||
  35197. /**
  35198. * <span
  35199. * >123<meta
  35200. * ~
  35201. * /></span>
  35202. */
  35203. node.isSelfClosing && needsToBorrowLastChildClosingTagEndMarker(node.parent) ? "" : node.isSelfClosing ? forceNotToBreakAttrContent ? " " : line$8 : forceNotToBreakAttrContent ? "" : softline$7]), node.isSelfClosing ? "" : printOpeningTagEnd(node)]);
  35204. }
  35205. function printOpeningTagStart(node, options) {
  35206. return node.prev && needsToBorrowNextOpeningTagStartMarker(node.prev) ? "" : concat$g([printOpeningTagPrefix(node, options), printOpeningTagStartMarker(node)]);
  35207. }
  35208. function printOpeningTagEnd(node) {
  35209. return node.firstChild && needsToBorrowParentOpeningTagEndMarker(node.firstChild) ? "" : printOpeningTagEndMarker(node);
  35210. }
  35211. function printClosingTag(node, options) {
  35212. return concat$g([node.isSelfClosing ? "" : printClosingTagStart(node, options), printClosingTagEnd(node, options)]);
  35213. }
  35214. function printClosingTagStart(node, options) {
  35215. return node.lastChild && needsToBorrowParentClosingTagStartMarker(node.lastChild) ? "" : concat$g([printClosingTagPrefix(node, options), printClosingTagStartMarker(node, options)]);
  35216. }
  35217. function printClosingTagEnd(node, options) {
  35218. return (node.next ? needsToBorrowPrevClosingTagEndMarker(node.next) : needsToBorrowLastChildClosingTagEndMarker(node.parent)) ? "" : concat$g([printClosingTagEndMarker(node, options), printClosingTagSuffix(node, options)]);
  35219. }
  35220. function needsToBorrowNextOpeningTagStartMarker(node) {
  35221. /**
  35222. * 123<p
  35223. * ^^
  35224. * >
  35225. */
  35226. return node.next && !isTextLikeNode$1(node.next) && isTextLikeNode$1(node) && node.isTrailingSpaceSensitive && !node.hasTrailingSpaces;
  35227. }
  35228. function needsToBorrowParentOpeningTagEndMarker(node) {
  35229. /**
  35230. * <p
  35231. * >123
  35232. * ^
  35233. *
  35234. * <p
  35235. * ><a
  35236. * ^
  35237. */
  35238. return !node.prev && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces;
  35239. }
  35240. function needsToBorrowPrevClosingTagEndMarker(node) {
  35241. /**
  35242. * <p></p
  35243. * >123
  35244. * ^
  35245. *
  35246. * <p></p
  35247. * ><a
  35248. * ^
  35249. */
  35250. return node.prev && !isTextLikeNode$1(node.prev) && node.isLeadingSpaceSensitive && !node.hasLeadingSpaces;
  35251. }
  35252. function needsToBorrowLastChildClosingTagEndMarker(node) {
  35253. /**
  35254. * <p
  35255. * ><a></a
  35256. * ></p
  35257. * ^
  35258. * >
  35259. */
  35260. return node.lastChild && node.lastChild.isTrailingSpaceSensitive && !node.lastChild.hasTrailingSpaces && !isTextLikeNode$1(getLastDescendant$1(node.lastChild));
  35261. }
  35262. function needsToBorrowParentClosingTagStartMarker(node) {
  35263. /**
  35264. * <p>
  35265. * 123</p
  35266. * ^^^
  35267. * >
  35268. *
  35269. * 123</b
  35270. * ></a
  35271. * ^^^
  35272. * >
  35273. */
  35274. return !node.next && !node.hasTrailingSpaces && node.isTrailingSpaceSensitive && isTextLikeNode$1(getLastDescendant$1(node));
  35275. }
  35276. function printOpeningTagPrefix(node, options) {
  35277. return needsToBorrowParentOpeningTagEndMarker(node) ? printOpeningTagEndMarker(node.parent) : needsToBorrowPrevClosingTagEndMarker(node) ? printClosingTagEndMarker(node.prev, options) : "";
  35278. }
  35279. function printClosingTagPrefix(node, options) {
  35280. return needsToBorrowLastChildClosingTagEndMarker(node) ? printClosingTagEndMarker(node.lastChild, options) : "";
  35281. }
  35282. function printClosingTagSuffix(node, options) {
  35283. return needsToBorrowParentClosingTagStartMarker(node) ? printClosingTagStartMarker(node.parent, options) : needsToBorrowNextOpeningTagStartMarker(node) ? printOpeningTagStartMarker(node.next) : "";
  35284. }
  35285. function printOpeningTagStartMarker(node) {
  35286. switch (node.type) {
  35287. case "ieConditionalComment":
  35288. case "ieConditionalStartComment":
  35289. return `<!--[if ${node.condition}`;
  35290. case "ieConditionalEndComment":
  35291. return `<!--<!`;
  35292. case "interpolation":
  35293. return "{{";
  35294. case "docType":
  35295. return "<!DOCTYPE";
  35296. case "element":
  35297. if (node.condition) {
  35298. return `<!--[if ${node.condition}]><!--><${node.rawName}`;
  35299. }
  35300. // fall through
  35301. default:
  35302. return `<${node.rawName}`;
  35303. }
  35304. }
  35305. function printOpeningTagEndMarker(node) {
  35306. assert$1(!node.isSelfClosing);
  35307. switch (node.type) {
  35308. case "ieConditionalComment":
  35309. return "]>";
  35310. case "element":
  35311. if (node.condition) {
  35312. return `><!--<![endif]-->`;
  35313. }
  35314. // fall through
  35315. default:
  35316. return `>`;
  35317. }
  35318. }
  35319. function printClosingTagStartMarker(node, options) {
  35320. assert$1(!node.isSelfClosing);
  35321. if (shouldNotPrintClosingTag$1(node, options)) {
  35322. return "";
  35323. }
  35324. switch (node.type) {
  35325. case "ieConditionalComment":
  35326. return "<!";
  35327. case "element":
  35328. if (node.hasHtmComponentClosingTag) {
  35329. return "<//";
  35330. }
  35331. // fall through
  35332. default:
  35333. return `</${node.rawName}`;
  35334. }
  35335. }
  35336. function printClosingTagEndMarker(node, options) {
  35337. if (shouldNotPrintClosingTag$1(node, options)) {
  35338. return "";
  35339. }
  35340. switch (node.type) {
  35341. case "ieConditionalComment":
  35342. case "ieConditionalEndComment":
  35343. return `[endif]-->`;
  35344. case "ieConditionalStartComment":
  35345. return `]><!-->`;
  35346. case "interpolation":
  35347. return "}}";
  35348. case "element":
  35349. if (node.isSelfClosing) {
  35350. return "/>";
  35351. }
  35352. // fall through
  35353. default:
  35354. return ">";
  35355. }
  35356. }
  35357. function getTextValueParts(node) {
  35358. var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : node.value;
  35359. return node.parent.isWhitespaceSensitive ? node.parent.isIndentationSensitive ? replaceEndOfLineWith$2(value, literalline$6) : replaceEndOfLineWith$2(dedentString$1(value.replace(/^\s*?\n|\n\s*?$/g, "")), hardline$c) : // https://infra.spec.whatwg.org/#ascii-whitespace
  35360. join$b(line$8, value.split(/[\t\n\f\r ]+/)).parts;
  35361. }
  35362. function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
  35363. var isKeyMatched = function isKeyMatched(patterns) {
  35364. return new RegExp(patterns.join("|")).test(node.fullName);
  35365. };
  35366. var getValue = function getValue() {
  35367. return unescapeQuoteEntities$1(node.value);
  35368. };
  35369. var shouldHug = false;
  35370. var __onHtmlBindingRoot = function __onHtmlBindingRoot(root) {
  35371. var 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;
  35372. if (rootNode && (rootNode.type === "ObjectExpression" || rootNode.type === "ArrayExpression")) {
  35373. shouldHug = true;
  35374. }
  35375. };
  35376. var printHug = function printHug(doc) {
  35377. return group$f(doc);
  35378. };
  35379. var printExpand = function printExpand(doc) {
  35380. return group$f(concat$g([indent$9(concat$g([softline$7, doc])), softline$7]));
  35381. };
  35382. var printMaybeHug = function printMaybeHug(doc) {
  35383. return shouldHug ? printHug(doc) : printExpand(doc);
  35384. };
  35385. var textToDoc = function textToDoc(code, opts) {
  35386. return originalTextToDoc(code, Object.assign({
  35387. __onHtmlBindingRoot
  35388. }, opts));
  35389. };
  35390. if (node.fullName === "srcset" && (node.parent.fullName === "img" || node.parent.fullName === "source")) {
  35391. return printExpand(printImgSrcset$1(getValue()));
  35392. }
  35393. if (options.parser === "vue") {
  35394. if (node.fullName === "v-for") {
  35395. return printVueFor$1(getValue(), textToDoc);
  35396. }
  35397. if (node.fullName === "slot-scope") {
  35398. return printVueSlotScope$1(getValue(), textToDoc);
  35399. }
  35400. /**
  35401. * @click="jsStatement"
  35402. * @click="jsExpression"
  35403. * v-on:click="jsStatement"
  35404. * v-on:click="jsExpression"
  35405. */
  35406. var vueEventBindingPatterns = ["^@", "^v-on:"];
  35407. /**
  35408. * :class="vueExpression"
  35409. * v-bind:id="vueExpression"
  35410. */
  35411. var vueExpressionBindingPatterns = ["^:", "^v-bind:"];
  35412. /**
  35413. * v-if="jsExpression"
  35414. */
  35415. var jsExpressionBindingPatterns = ["^v-"];
  35416. if (isKeyMatched(vueEventBindingPatterns)) {
  35417. var value = getValue();
  35418. return printMaybeHug(isVueEventBindingExpression$3(value) ? textToDoc(value, {
  35419. parser: "__js_expression"
  35420. }) : stripTrailingHardline$2(textToDoc(value, {
  35421. parser: "__vue_event_binding"
  35422. })));
  35423. }
  35424. if (isKeyMatched(vueExpressionBindingPatterns)) {
  35425. return printMaybeHug(textToDoc(getValue(), {
  35426. parser: "__vue_expression"
  35427. }));
  35428. }
  35429. if (isKeyMatched(jsExpressionBindingPatterns)) {
  35430. return printMaybeHug(textToDoc(getValue(), {
  35431. parser: "__js_expression"
  35432. }));
  35433. }
  35434. }
  35435. if (options.parser === "angular") {
  35436. var ngTextToDoc = function ngTextToDoc(code, opts) {
  35437. return (// angular does not allow trailing comma
  35438. textToDoc(code, Object.assign({
  35439. trailingComma: "none"
  35440. }, opts))
  35441. );
  35442. };
  35443. /**
  35444. * *directive="angularDirective"
  35445. */
  35446. var ngDirectiveBindingPatterns = ["^\\*"];
  35447. /**
  35448. * (click)="angularStatement"
  35449. * on-click="angularStatement"
  35450. */
  35451. var ngStatementBindingPatterns = ["^\\(.+\\)$", "^on-"];
  35452. /**
  35453. * [target]="angularExpression"
  35454. * bind-target="angularExpression"
  35455. * [(target)]="angularExpression"
  35456. * bindon-target="angularExpression"
  35457. */
  35458. var ngExpressionBindingPatterns = ["^\\[.+\\]$", "^bind(on)?-"];
  35459. /**
  35460. * i18n="longDescription"
  35461. * i18n-attr="longDescription"
  35462. */
  35463. var ngI18nPatterns = ["^i18n(-.+)?$"];
  35464. if (isKeyMatched(ngStatementBindingPatterns)) {
  35465. return printMaybeHug(ngTextToDoc(getValue(), {
  35466. parser: "__ng_action"
  35467. }));
  35468. }
  35469. if (isKeyMatched(ngExpressionBindingPatterns)) {
  35470. return printMaybeHug(ngTextToDoc(getValue(), {
  35471. parser: "__ng_binding"
  35472. }));
  35473. }
  35474. if (isKeyMatched(ngI18nPatterns)) {
  35475. return printExpand(fill$5(getTextValueParts(node, getValue())));
  35476. }
  35477. if (isKeyMatched(ngDirectiveBindingPatterns)) {
  35478. return printMaybeHug(ngTextToDoc(getValue(), {
  35479. parser: "__ng_directive"
  35480. }));
  35481. }
  35482. var interpolationRegex = /\{\{([\s\S]+?)\}\}/g;
  35483. var _value2 = getValue();
  35484. if (interpolationRegex.test(_value2)) {
  35485. var parts = [];
  35486. _value2.split(interpolationRegex).forEach(function (part, index) {
  35487. if (index % 2 === 0) {
  35488. parts.push(concat$g(replaceEndOfLineWith$2(part, literalline$6)));
  35489. } else {
  35490. try {
  35491. parts.push(group$f(concat$g(["{{", indent$9(concat$g([line$8, ngTextToDoc(part, {
  35492. parser: "__ng_interpolation",
  35493. __isInHtmlInterpolation: true // to avoid unexpected `}}`
  35494. })])), line$8, "}}"])));
  35495. } catch (e) {
  35496. parts.push("{{", concat$g(replaceEndOfLineWith$2(part, literalline$6)), "}}");
  35497. }
  35498. }
  35499. });
  35500. return group$f(concat$g(parts));
  35501. }
  35502. }
  35503. return null;
  35504. }
  35505. var printerHtml = {
  35506. preprocess: preprocess_1$2,
  35507. print: genericPrint$5,
  35508. insertPragma: insertPragma$7,
  35509. massageAstNode: clean$6,
  35510. embed: embed$4
  35511. };
  35512. var CATEGORY_HTML = "HTML"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  35513. var options$6 = {
  35514. htmlWhitespaceSensitivity: {
  35515. since: "1.15.0",
  35516. category: CATEGORY_HTML,
  35517. type: "choice",
  35518. default: "css",
  35519. description: "How to handle whitespaces in HTML.",
  35520. choices: [{
  35521. value: "css",
  35522. description: "Respect the default value of CSS display property."
  35523. }, {
  35524. value: "strict",
  35525. description: "Whitespaces are considered sensitive."
  35526. }, {
  35527. value: "ignore",
  35528. description: "Whitespaces are considered insensitive."
  35529. }]
  35530. },
  35531. vueIndentScriptAndStyle: {
  35532. since: "1.19.0",
  35533. category: CATEGORY_HTML,
  35534. type: "boolean",
  35535. default: false,
  35536. description: "Indent script and style tags in Vue files."
  35537. }
  35538. };
  35539. var name$g = "HTML";
  35540. var type$e = "markup";
  35541. var tmScope$e = "text.html.basic";
  35542. var aceMode$e = "html";
  35543. var codemirrorMode$b = "htmlmixed";
  35544. var codemirrorMimeType$b = "text/html";
  35545. var color$3 = "#e34c26";
  35546. var aliases$5 = [
  35547. "xhtml"
  35548. ];
  35549. var extensions$e = [
  35550. ".html",
  35551. ".htm",
  35552. ".html.hl",
  35553. ".inc",
  35554. ".st",
  35555. ".xht",
  35556. ".xhtml"
  35557. ];
  35558. var languageId$e = 146;
  35559. var HTML = {
  35560. name: name$g,
  35561. type: type$e,
  35562. tmScope: tmScope$e,
  35563. aceMode: aceMode$e,
  35564. codemirrorMode: codemirrorMode$b,
  35565. codemirrorMimeType: codemirrorMimeType$b,
  35566. color: color$3,
  35567. aliases: aliases$5,
  35568. extensions: extensions$e,
  35569. languageId: languageId$e
  35570. };
  35571. var HTML$1 = /*#__PURE__*/Object.freeze({
  35572. __proto__: null,
  35573. name: name$g,
  35574. type: type$e,
  35575. tmScope: tmScope$e,
  35576. aceMode: aceMode$e,
  35577. codemirrorMode: codemirrorMode$b,
  35578. codemirrorMimeType: codemirrorMimeType$b,
  35579. color: color$3,
  35580. aliases: aliases$5,
  35581. extensions: extensions$e,
  35582. languageId: languageId$e,
  35583. 'default': HTML
  35584. });
  35585. var name$h = "Vue";
  35586. var type$f = "markup";
  35587. var color$4 = "#2c3e50";
  35588. var extensions$f = [
  35589. ".vue"
  35590. ];
  35591. var tmScope$f = "text.html.vue";
  35592. var aceMode$f = "html";
  35593. var languageId$f = 391;
  35594. var Vue = {
  35595. name: name$h,
  35596. type: type$f,
  35597. color: color$4,
  35598. extensions: extensions$f,
  35599. tmScope: tmScope$f,
  35600. aceMode: aceMode$f,
  35601. languageId: languageId$f
  35602. };
  35603. var Vue$1 = /*#__PURE__*/Object.freeze({
  35604. __proto__: null,
  35605. name: name$h,
  35606. type: type$f,
  35607. color: color$4,
  35608. extensions: extensions$f,
  35609. tmScope: tmScope$f,
  35610. aceMode: aceMode$f,
  35611. languageId: languageId$f,
  35612. 'default': Vue
  35613. });
  35614. var require$$0$6 = getCjsExportFromNamespace(HTML$1);
  35615. var require$$1$2 = getCjsExportFromNamespace(Vue$1);
  35616. var languages$5 = [createLanguage(require$$0$6, function (data) {
  35617. return Object.assign(data, {
  35618. name: "Angular",
  35619. since: "1.15.0",
  35620. parsers: ["angular"],
  35621. vscodeLanguageIds: ["html"],
  35622. extensions: [".component.html"],
  35623. filenames: []
  35624. });
  35625. }), createLanguage(require$$0$6, function (data) {
  35626. return Object.assign(data, {
  35627. since: "1.15.0",
  35628. parsers: ["html"],
  35629. vscodeLanguageIds: ["html"],
  35630. extensions: data.extensions.concat([".mjml" // MJML is considered XML in Linguist but it should be formatted as HTML
  35631. ])
  35632. });
  35633. }), createLanguage(require$$0$6, function (data) {
  35634. return Object.assign(data, {
  35635. name: "Lightning Web Components",
  35636. since: "1.17.0",
  35637. parsers: ["lwc"],
  35638. vscodeLanguageIds: ["html"],
  35639. extensions: [],
  35640. filenames: []
  35641. });
  35642. }), createLanguage(require$$1$2, function (data) {
  35643. return Object.assign(data, {
  35644. since: "1.10.0",
  35645. parsers: ["vue"],
  35646. vscodeLanguageIds: ["vue"]
  35647. });
  35648. })];
  35649. var printers$5 = {
  35650. html: printerHtml
  35651. };
  35652. var languageHtml = {
  35653. languages: languages$5,
  35654. printers: printers$5,
  35655. options: options$6
  35656. };
  35657. function isPragma(text) {
  35658. return /^\s*@(prettier|format)\s*$/.test(text);
  35659. }
  35660. function hasPragma$4(text) {
  35661. return /^\s*#[^\n\S]*@(prettier|format)\s*?(\n|$)/.test(text);
  35662. }
  35663. function insertPragma$8(text) {
  35664. return `# @format\n\n${text}`;
  35665. }
  35666. var pragma$5 = {
  35667. isPragma,
  35668. hasPragma: hasPragma$4,
  35669. insertPragma: insertPragma$8
  35670. };
  35671. var getLast$4 = util.getLast;
  35672. function getAncestorCount(path, filter) {
  35673. var counter = 0;
  35674. var pathStackLength = path.stack.length - 1;
  35675. for (var i = 0; i < pathStackLength; i++) {
  35676. var value = path.stack[i];
  35677. if (isNode$1(value) && filter(value)) {
  35678. counter++;
  35679. }
  35680. }
  35681. return counter;
  35682. }
  35683. /**
  35684. * @param {any} value
  35685. * @param {string[]=} types
  35686. */
  35687. function isNode$1(value, types) {
  35688. return value && typeof value.type === "string" && (!types || types.indexOf(value.type) !== -1);
  35689. }
  35690. function mapNode(node, callback, parent) {
  35691. return callback("children" in node ? Object.assign({}, node, {
  35692. children: node.children.map(function (childNode) {
  35693. return mapNode(childNode, callback, node);
  35694. })
  35695. }) : node, parent);
  35696. }
  35697. function defineShortcut(x, key, getter) {
  35698. Object.defineProperty(x, key, {
  35699. get: getter,
  35700. enumerable: false
  35701. });
  35702. }
  35703. function isNextLineEmpty$5(node, text) {
  35704. var newlineCount = 0;
  35705. var textLength = text.length;
  35706. for (var i = node.position.end.offset - 1; i < textLength; i++) {
  35707. var char = text[i];
  35708. if (char === "\n") {
  35709. newlineCount++;
  35710. }
  35711. if (newlineCount === 1 && /\S/.test(char)) {
  35712. return false;
  35713. }
  35714. if (newlineCount === 2) {
  35715. return true;
  35716. }
  35717. }
  35718. return false;
  35719. }
  35720. function isLastDescendantNode(path) {
  35721. var node = path.getValue();
  35722. switch (node.type) {
  35723. case "tag":
  35724. case "anchor":
  35725. case "comment":
  35726. return false;
  35727. }
  35728. var pathStackLength = path.stack.length;
  35729. for (var i = 1; i < pathStackLength; i++) {
  35730. var item = path.stack[i];
  35731. var parentItem = path.stack[i - 1];
  35732. if (Array.isArray(parentItem) && typeof item === "number" && item !== parentItem.length - 1) {
  35733. return false;
  35734. }
  35735. }
  35736. return true;
  35737. }
  35738. function getLastDescendantNode$1(node) {
  35739. return "children" in node && node.children.length !== 0 ? getLastDescendantNode$1(getLast$4(node.children)) : node;
  35740. }
  35741. function isPrettierIgnore$2(comment) {
  35742. return comment.value.trim() === "prettier-ignore";
  35743. }
  35744. function hasPrettierIgnore$5(path) {
  35745. var node = path.getValue();
  35746. if (node.type === "documentBody") {
  35747. var document = path.getParentNode();
  35748. return hasEndComments(document.head) && isPrettierIgnore$2(getLast$4(document.head.endComments));
  35749. }
  35750. return hasLeadingComments(node) && isPrettierIgnore$2(getLast$4(node.leadingComments));
  35751. }
  35752. function isEmptyNode(node) {
  35753. return (!node.children || node.children.length === 0) && !hasComments(node);
  35754. }
  35755. function hasComments(node) {
  35756. return hasLeadingComments(node) || hasMiddleComments(node) || hasIndicatorComment(node) || hasTrailingComment$2(node) || hasEndComments(node);
  35757. }
  35758. function hasLeadingComments(node) {
  35759. return node && node.leadingComments && node.leadingComments.length !== 0;
  35760. }
  35761. function hasMiddleComments(node) {
  35762. return node && node.middleComments && node.middleComments.length !== 0;
  35763. }
  35764. function hasIndicatorComment(node) {
  35765. return node && node.indicatorComment;
  35766. }
  35767. function hasTrailingComment$2(node) {
  35768. return node && node.trailingComment;
  35769. }
  35770. function hasEndComments(node) {
  35771. return node && node.endComments && node.endComments.length !== 0;
  35772. }
  35773. /**
  35774. * " a b c d e f " -> [" a b", "c d", "e f "]
  35775. */
  35776. function splitWithSingleSpace(text) {
  35777. var parts = [];
  35778. var lastPart = undefined;
  35779. var _iteratorNormalCompletion = true;
  35780. var _didIteratorError = false;
  35781. var _iteratorError = undefined;
  35782. try {
  35783. for (var _iterator = text.split(/( +)/g)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  35784. var part = _step.value;
  35785. if (part !== " ") {
  35786. if (lastPart === " ") {
  35787. parts.push(part);
  35788. } else {
  35789. parts.push((parts.pop() || "") + part);
  35790. }
  35791. } else if (lastPart === undefined) {
  35792. parts.unshift("");
  35793. }
  35794. lastPart = part;
  35795. }
  35796. } catch (err) {
  35797. _didIteratorError = true;
  35798. _iteratorError = err;
  35799. } finally {
  35800. try {
  35801. if (!_iteratorNormalCompletion && _iterator.return != null) {
  35802. _iterator.return();
  35803. }
  35804. } finally {
  35805. if (_didIteratorError) {
  35806. throw _iteratorError;
  35807. }
  35808. }
  35809. }
  35810. if (lastPart === " ") {
  35811. parts.push((parts.pop() || "") + " ");
  35812. }
  35813. if (parts[0] === "") {
  35814. parts.shift();
  35815. parts.unshift(" " + (parts.shift() || ""));
  35816. }
  35817. return parts;
  35818. }
  35819. function getFlowScalarLineContents(nodeType, content, options) {
  35820. var rawLineContents = content.split("\n").map(function (lineContent, index, lineContents) {
  35821. return index === 0 && index === lineContents.length - 1 ? lineContent : index !== 0 && index !== lineContents.length - 1 ? lineContent.trim() : index === 0 ? lineContent.trimRight() : lineContent.trimLeft();
  35822. });
  35823. if (options.proseWrap === "preserve") {
  35824. return rawLineContents.map(function (lineContent) {
  35825. return lineContent.length === 0 ? [] : [lineContent];
  35826. });
  35827. }
  35828. return rawLineContents.map(function (lineContent) {
  35829. return lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent);
  35830. }).reduce(function (reduced, lineContentWords, index) {
  35831. return index !== 0 && rawLineContents[index - 1].length !== 0 && lineContentWords.length !== 0 && !( // trailing backslash in quoteDouble should be preserved
  35832. nodeType === "quoteDouble" && getLast$4(getLast$4(reduced)).endsWith("\\")) ? reduced.concat([reduced.pop().concat(lineContentWords)]) : reduced.concat([lineContentWords]);
  35833. }, []).map(function (lineContentWords) {
  35834. return options.proseWrap === "never" ? [lineContentWords.join(" ")] : lineContentWords;
  35835. });
  35836. }
  35837. function getBlockValueLineContents(node, _ref) {
  35838. var parentIndent = _ref.parentIndent,
  35839. isLastDescendant = _ref.isLastDescendant,
  35840. options = _ref.options;
  35841. var content = node.position.start.line === node.position.end.line ? "" : options.originalText.slice(node.position.start.offset, node.position.end.offset) // exclude open line `>` or `|`
  35842. .match(/^[^\n]*?\n([\s\S]*)$/)[1];
  35843. var leadingSpaceCount = node.indent === null ? function (match) {
  35844. return match ? match[1].length : Infinity;
  35845. }(content.match(/^( *)\S/m)) : node.indent - 1 + parentIndent;
  35846. var rawLineContents = content.split("\n").map(function (lineContent) {
  35847. return lineContent.slice(leadingSpaceCount);
  35848. });
  35849. if (options.proseWrap === "preserve" || node.type === "blockLiteral") {
  35850. return removeUnnecessaryTrailingNewlines(rawLineContents.map(function (lineContent) {
  35851. return lineContent.length === 0 ? [] : [lineContent];
  35852. }));
  35853. }
  35854. return removeUnnecessaryTrailingNewlines(rawLineContents.map(function (lineContent) {
  35855. return lineContent.length === 0 ? [] : splitWithSingleSpace(lineContent);
  35856. }).reduce(function (reduced, lineContentWords, index) {
  35857. return index !== 0 && rawLineContents[index - 1].length !== 0 && lineContentWords.length !== 0 && !/^\s/.test(lineContentWords[0]) && !/^\s|\s$/.test(getLast$4(reduced)) ? reduced.concat([reduced.pop().concat(lineContentWords)]) : reduced.concat([lineContentWords]);
  35858. }, []).map(function (lineContentWords) {
  35859. return lineContentWords.reduce(function (reduced, word) {
  35860. return (// disallow trailing spaces
  35861. reduced.length !== 0 && /\s$/.test(getLast$4(reduced)) ? reduced.concat(reduced.pop() + " " + word) : reduced.concat(word)
  35862. );
  35863. }, []);
  35864. }).map(function (lineContentWords) {
  35865. return options.proseWrap === "never" ? [lineContentWords.join(" ")] : lineContentWords;
  35866. }));
  35867. function removeUnnecessaryTrailingNewlines(lineContents) {
  35868. if (node.chomping === "keep") {
  35869. return getLast$4(lineContents).length === 0 ? lineContents.slice(0, -1) : lineContents;
  35870. }
  35871. var trailingNewlineCount = 0;
  35872. for (var i = lineContents.length - 1; i >= 0; i--) {
  35873. if (lineContents[i].length === 0) {
  35874. trailingNewlineCount++;
  35875. } else {
  35876. break;
  35877. }
  35878. }
  35879. return trailingNewlineCount === 0 ? lineContents : trailingNewlineCount >= 2 && !isLastDescendant ? // next empty line
  35880. lineContents.slice(0, -(trailingNewlineCount - 1)) : lineContents.slice(0, -trailingNewlineCount);
  35881. }
  35882. }
  35883. var utils$6 = {
  35884. getLast: getLast$4,
  35885. getAncestorCount,
  35886. isNode: isNode$1,
  35887. isEmptyNode,
  35888. mapNode,
  35889. defineShortcut,
  35890. isNextLineEmpty: isNextLineEmpty$5,
  35891. isLastDescendantNode,
  35892. getBlockValueLineContents,
  35893. getFlowScalarLineContents,
  35894. getLastDescendantNode: getLastDescendantNode$1,
  35895. hasPrettierIgnore: hasPrettierIgnore$5,
  35896. hasLeadingComments,
  35897. hasMiddleComments,
  35898. hasIndicatorComment,
  35899. hasTrailingComment: hasTrailingComment$2,
  35900. hasEndComments
  35901. };
  35902. var insertPragma$9 = pragma$5.insertPragma,
  35903. isPragma$1 = pragma$5.isPragma;
  35904. var getAncestorCount$1 = utils$6.getAncestorCount,
  35905. getBlockValueLineContents$1 = utils$6.getBlockValueLineContents,
  35906. getFlowScalarLineContents$1 = utils$6.getFlowScalarLineContents,
  35907. getLast$5 = utils$6.getLast,
  35908. getLastDescendantNode$2 = utils$6.getLastDescendantNode,
  35909. hasLeadingComments$1 = utils$6.hasLeadingComments,
  35910. hasMiddleComments$1 = utils$6.hasMiddleComments,
  35911. hasIndicatorComment$1 = utils$6.hasIndicatorComment,
  35912. hasTrailingComment$3 = utils$6.hasTrailingComment,
  35913. hasEndComments$1 = utils$6.hasEndComments,
  35914. hasPrettierIgnore$6 = utils$6.hasPrettierIgnore,
  35915. isLastDescendantNode$1 = utils$6.isLastDescendantNode,
  35916. isNextLineEmpty$6 = utils$6.isNextLineEmpty,
  35917. isNode$2 = utils$6.isNode,
  35918. isEmptyNode$1 = utils$6.isEmptyNode,
  35919. defineShortcut$1 = utils$6.defineShortcut,
  35920. mapNode$1 = utils$6.mapNode;
  35921. var docBuilders$2 = doc.builders;
  35922. var conditionalGroup$2 = docBuilders$2.conditionalGroup,
  35923. breakParent$5 = docBuilders$2.breakParent,
  35924. concat$h = docBuilders$2.concat,
  35925. dedent$3 = docBuilders$2.dedent,
  35926. dedentToRoot$3 = docBuilders$2.dedentToRoot,
  35927. fill$6 = docBuilders$2.fill,
  35928. group$g = docBuilders$2.group,
  35929. hardline$d = docBuilders$2.hardline,
  35930. ifBreak$8 = docBuilders$2.ifBreak,
  35931. join$c = docBuilders$2.join,
  35932. line$9 = docBuilders$2.line,
  35933. lineSuffix$2 = docBuilders$2.lineSuffix,
  35934. literalline$7 = docBuilders$2.literalline,
  35935. markAsRoot$5 = docBuilders$2.markAsRoot,
  35936. softline$8 = docBuilders$2.softline;
  35937. var replaceEndOfLineWith$3 = util.replaceEndOfLineWith;
  35938. function preprocess$3(ast) {
  35939. return mapNode$1(ast, defineShortcuts);
  35940. }
  35941. function defineShortcuts(node) {
  35942. switch (node.type) {
  35943. case "document":
  35944. defineShortcut$1(node, "head", function () {
  35945. return node.children[0];
  35946. });
  35947. defineShortcut$1(node, "body", function () {
  35948. return node.children[1];
  35949. });
  35950. break;
  35951. case "documentBody":
  35952. case "sequenceItem":
  35953. case "flowSequenceItem":
  35954. case "mappingKey":
  35955. case "mappingValue":
  35956. defineShortcut$1(node, "content", function () {
  35957. return node.children[0];
  35958. });
  35959. break;
  35960. case "mappingItem":
  35961. case "flowMappingItem":
  35962. defineShortcut$1(node, "key", function () {
  35963. return node.children[0];
  35964. });
  35965. defineShortcut$1(node, "value", function () {
  35966. return node.children[1];
  35967. });
  35968. break;
  35969. }
  35970. return node;
  35971. }
  35972. function genericPrint$6(path, options, print) {
  35973. var node = path.getValue();
  35974. var parentNode = path.getParentNode();
  35975. var tag = !node.tag ? "" : path.call(print, "tag");
  35976. var anchor = !node.anchor ? "" : path.call(print, "anchor");
  35977. var nextEmptyLine = isNode$2(node, ["mapping", "sequence", "comment", "directive", "mappingItem", "sequenceItem"]) && !isLastDescendantNode$1(path) ? printNextEmptyLine(path, options.originalText) : "";
  35978. return concat$h([node.type !== "mappingValue" && hasLeadingComments$1(node) ? concat$h([join$c(hardline$d, path.map(print, "leadingComments")), hardline$d]) : "", tag, tag && anchor ? " " : "", anchor, tag || anchor ? isNode$2(node, ["sequence", "mapping"]) && !hasMiddleComments$1(node) ? hardline$d : " " : "", hasMiddleComments$1(node) ? concat$h([node.middleComments.length === 1 ? "" : hardline$d, join$c(hardline$d, path.map(print, "middleComments")), hardline$d]) : "", hasPrettierIgnore$6(path) ? concat$h(replaceEndOfLineWith$3(options.originalText.slice(node.position.start.offset, node.position.end.offset), literalline$7)) : group$g(_print(node, parentNode, path, options, print)), hasTrailingComment$3(node) && !isNode$2(node, ["document", "documentHead"]) ? lineSuffix$2(concat$h([node.type === "mappingValue" && !node.content ? "" : " ", parentNode.type === "mappingKey" && path.getParentNode(2).type === "mapping" && isInlineNode$1(node) ? "" : breakParent$5, path.call(print, "trailingComment")])) : "", nextEmptyLine, hasEndComments$1(node) && !isNode$2(node, ["documentHead", "documentBody"]) ? align$3(node.type === "sequenceItem" ? 2 : 0, concat$h([hardline$d, join$c(hardline$d, path.map(print, "endComments"))])) : ""]);
  35979. }
  35980. function _print(node, parentNode, path, options, print) {
  35981. switch (node.type) {
  35982. case "root":
  35983. return concat$h([join$c(hardline$d, path.map(function (childPath, index) {
  35984. var document = node.children[index];
  35985. var nextDocument = node.children[index + 1];
  35986. return concat$h([print(childPath), shouldPrintDocumentEndMarker(document, nextDocument) ? concat$h([hardline$d, "...", hasTrailingComment$3(document) ? concat$h([" ", path.call(print, "trailingComment")]) : ""]) : !nextDocument || hasTrailingComment$3(nextDocument.head) ? "" : concat$h([hardline$d, "---"])]);
  35987. }, "children")), node.children.length === 0 || function (lastDescendantNode) {
  35988. return isNode$2(lastDescendantNode, ["blockLiteral", "blockFolded"]) && lastDescendantNode.chomping === "keep";
  35989. }(getLastDescendantNode$2(node)) ? "" : hardline$d]);
  35990. case "document":
  35991. {
  35992. var nextDocument = parentNode.children[path.getName() + 1];
  35993. return join$c(hardline$d, [shouldPrintDocumentHeadEndMarker(node, nextDocument, parentNode, options) === "head" ? join$c(hardline$d, [node.head.children.length === 0 && node.head.endComments.length === 0 ? "" : path.call(print, "head"), concat$h(["---", hasTrailingComment$3(node.head) ? concat$h([" ", path.call(print, "head", "trailingComment")]) : ""])].filter(Boolean)) : "", shouldPrintDocumentBody(node) ? path.call(print, "body") : ""].filter(Boolean));
  35994. }
  35995. case "documentHead":
  35996. return join$c(hardline$d, [].concat(path.map(print, "children"), path.map(print, "endComments")));
  35997. case "documentBody":
  35998. {
  35999. var children = join$c(hardline$d, path.map(print, "children")).parts;
  36000. var endComments = join$c(hardline$d, path.map(print, "endComments")).parts;
  36001. var separator = children.length === 0 || endComments.length === 0 ? "" : function (lastDescendantNode) {
  36002. return isNode$2(lastDescendantNode, ["blockFolded", "blockLiteral"]) ? lastDescendantNode.chomping === "keep" ? // there's already a newline printed at the end of blockValue (chomping=keep, lastDescendant=true)
  36003. "" : // an extra newline for better readability
  36004. concat$h([hardline$d, hardline$d]) : hardline$d;
  36005. }(getLastDescendantNode$2(node));
  36006. return concat$h([].concat(children, separator, endComments));
  36007. }
  36008. case "directive":
  36009. return concat$h(["%", join$c(" ", [node.name].concat(node.parameters))]);
  36010. case "comment":
  36011. return concat$h(["#", node.value]);
  36012. case "alias":
  36013. return concat$h(["*", node.value]);
  36014. case "tag":
  36015. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  36016. case "anchor":
  36017. return concat$h(["&", node.value]);
  36018. case "plain":
  36019. return printFlowScalarContent(node.type, options.originalText.slice(node.position.start.offset, node.position.end.offset), options);
  36020. case "quoteDouble":
  36021. case "quoteSingle":
  36022. {
  36023. var singleQuote = "'";
  36024. var doubleQuote = '"';
  36025. var raw = options.originalText.slice(node.position.start.offset + 1, node.position.end.offset - 1);
  36026. if (node.type === "quoteSingle" && raw.includes("\\") || node.type === "quoteDouble" && /\\[^"]/.test(raw)) {
  36027. // only quoteDouble can use escape chars
  36028. // and quoteSingle do not need to escape backslashes
  36029. var originalQuote = node.type === "quoteDouble" ? doubleQuote : singleQuote;
  36030. return concat$h([originalQuote, printFlowScalarContent(node.type, raw, options), originalQuote]);
  36031. } else if (raw.includes(doubleQuote)) {
  36032. return concat$h([singleQuote, printFlowScalarContent(node.type, node.type === "quoteDouble" ? raw // double quote needs to be escaped by backslash in quoteDouble
  36033. .replace(/\\"/g, doubleQuote).replace(/'/g, singleQuote.repeat(2)) : raw, options), singleQuote]);
  36034. }
  36035. if (raw.includes(singleQuote)) {
  36036. return concat$h([doubleQuote, printFlowScalarContent(node.type, node.type === "quoteSingle" ? // single quote needs to be escaped by 2 single quotes in quoteSingle
  36037. raw.replace(/''/g, singleQuote) : raw, options), doubleQuote]);
  36038. }
  36039. var quote = options.singleQuote ? singleQuote : doubleQuote;
  36040. return concat$h([quote, printFlowScalarContent(node.type, raw, options), quote]);
  36041. }
  36042. case "blockFolded":
  36043. case "blockLiteral":
  36044. {
  36045. var parentIndent = getAncestorCount$1(path, function (ancestorNode) {
  36046. return isNode$2(ancestorNode, ["sequence", "mapping"]);
  36047. });
  36048. var isLastDescendant = isLastDescendantNode$1(path);
  36049. return concat$h([node.type === "blockFolded" ? ">" : "|", node.indent === null ? "" : node.indent.toString(), node.chomping === "clip" ? "" : node.chomping === "keep" ? "+" : "-", hasIndicatorComment$1(node) ? concat$h([" ", path.call(print, "indicatorComment")]) : "", (node.indent === null ? dedent$3 : dedentToRoot$3)(align$3(node.indent === null ? options.tabWidth : node.indent - 1 + parentIndent, concat$h(getBlockValueLineContents$1(node, {
  36050. parentIndent,
  36051. isLastDescendant,
  36052. options
  36053. }).reduce(function (reduced, lineWords, index, lineContents) {
  36054. return reduced.concat(index === 0 ? hardline$d : "", fill$6(join$c(line$9, lineWords).parts), index !== lineContents.length - 1 ? lineWords.length === 0 ? hardline$d : markAsRoot$5(literalline$7) : node.chomping === "keep" && isLastDescendant ? lineWords.length === 0 ? dedentToRoot$3(hardline$d) : dedentToRoot$3(literalline$7) : "");
  36055. }, []))))]);
  36056. }
  36057. case "sequence":
  36058. return join$c(hardline$d, path.map(print, "children"));
  36059. case "sequenceItem":
  36060. return concat$h(["- ", align$3(2, !node.content ? "" : path.call(print, "content"))]);
  36061. case "mappingKey":
  36062. return !node.content ? "" : path.call(print, "content");
  36063. case "mappingValue":
  36064. return !node.content ? "" : path.call(print, "content");
  36065. case "mapping":
  36066. return join$c(hardline$d, path.map(print, "children"));
  36067. case "mappingItem":
  36068. case "flowMappingItem":
  36069. {
  36070. var isEmptyMappingKey = isEmptyNode$1(node.key);
  36071. var isEmptyMappingValue = isEmptyNode$1(node.value);
  36072. if (isEmptyMappingKey && isEmptyMappingValue) {
  36073. return concat$h([": "]);
  36074. }
  36075. var key = path.call(print, "key");
  36076. var value = path.call(print, "value");
  36077. if (isEmptyMappingValue) {
  36078. return node.type === "flowMappingItem" && parentNode.type === "flowMapping" ? key : node.type === "mappingItem" && isAbsolutelyPrintedAsSingleLineNode(node.key.content, options) && !hasTrailingComment$3(node.key.content) && (!parentNode.tag || parentNode.tag.value !== "tag:yaml.org,2002:set") ? concat$h([key, needsSpaceInFrontOfMappingValue(node) ? " " : "", ":"]) : concat$h(["? ", align$3(2, key)]);
  36079. }
  36080. if (isEmptyMappingKey) {
  36081. return concat$h([": ", align$3(2, value)]);
  36082. }
  36083. var groupId = Symbol("mappingKey");
  36084. var forceExplicitKey = hasLeadingComments$1(node.value) || !isInlineNode$1(node.key.content);
  36085. return forceExplicitKey ? concat$h(["? ", align$3(2, key), hardline$d, join$c("", path.map(print, "value", "leadingComments").map(function (comment) {
  36086. return concat$h([comment, hardline$d]);
  36087. })), ": ", align$3(2, value)]) : // force singleline
  36088. isSingleLineNode(node.key.content) && !hasLeadingComments$1(node.key.content) && !hasMiddleComments$1(node.key.content) && !hasTrailingComment$3(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$h([key, needsSpaceInFrontOfMappingValue(node) ? " " : "", ": ", value]) : conditionalGroup$2([concat$h([group$g(concat$h([ifBreak$8("? "), group$g(align$3(2, key), {
  36089. id: groupId
  36090. })])), ifBreak$8(concat$h([hardline$d, ": ", align$3(2, value)]), indent(concat$h([needsSpaceInFrontOfMappingValue(node) ? " " : "", ":", hasLeadingComments$1(node.value.content) || hasEndComments$1(node.value) && node.value.content && !isNode$2(node.value.content, ["mapping", "sequence"]) || parentNode.type === "mapping" && hasTrailingComment$3(node.key.content) && isInlineNode$1(node.value.content) || isNode$2(node.value.content, ["mapping", "sequence"]) && node.value.content.tag === null && node.value.content.anchor === null ? hardline$d : !node.value.content ? "" : line$9, value])), {
  36091. groupId
  36092. })])]);
  36093. }
  36094. case "flowMapping":
  36095. case "flowSequence":
  36096. {
  36097. var openMarker = node.type === "flowMapping" ? "{" : "[";
  36098. var closeMarker = node.type === "flowMapping" ? "}" : "]";
  36099. var bracketSpacing = node.type === "flowMapping" && node.children.length !== 0 && options.bracketSpacing ? line$9 : softline$8;
  36100. var isLastItemEmptyMappingItem = node.children.length !== 0 && function (lastItem) {
  36101. return lastItem.type === "flowMappingItem" && isEmptyNode$1(lastItem.key) && isEmptyNode$1(lastItem.value);
  36102. }(getLast$5(node.children));
  36103. return concat$h([openMarker, indent(concat$h([bracketSpacing, concat$h(path.map(function (childPath, index) {
  36104. return concat$h([print(childPath), index === node.children.length - 1 ? "" : concat$h([",", line$9, node.children[index].position.start.line !== node.children[index + 1].position.start.line ? printNextEmptyLine(childPath, options.originalText) : ""])]);
  36105. }, "children")), ifBreak$8(",", "")])), isLastItemEmptyMappingItem ? "" : bracketSpacing, closeMarker]);
  36106. }
  36107. case "flowSequenceItem":
  36108. return path.call(print, "content");
  36109. // istanbul ignore next
  36110. default:
  36111. throw new Error(`Unexpected node type ${node.type}`);
  36112. }
  36113. function indent(doc) {
  36114. return docBuilders$2.align(" ".repeat(options.tabWidth), doc);
  36115. }
  36116. }
  36117. function align$3(n, doc) {
  36118. return typeof n === "number" && n > 0 ? docBuilders$2.align(" ".repeat(n), doc) : docBuilders$2.align(n, doc);
  36119. }
  36120. function isInlineNode$1(node) {
  36121. if (!node) {
  36122. return true;
  36123. }
  36124. switch (node.type) {
  36125. case "plain":
  36126. case "quoteDouble":
  36127. case "quoteSingle":
  36128. case "alias":
  36129. case "flowMapping":
  36130. case "flowSequence":
  36131. return true;
  36132. default:
  36133. return false;
  36134. }
  36135. }
  36136. function isSingleLineNode(node) {
  36137. if (!node) {
  36138. return true;
  36139. }
  36140. switch (node.type) {
  36141. case "plain":
  36142. case "quoteDouble":
  36143. case "quoteSingle":
  36144. return node.position.start.line === node.position.end.line;
  36145. case "alias":
  36146. return true;
  36147. default:
  36148. return false;
  36149. }
  36150. }
  36151. function shouldPrintDocumentBody(document) {
  36152. return document.body.children.length !== 0 || hasEndComments$1(document.body);
  36153. }
  36154. function shouldPrintDocumentEndMarker(document, nextDocument) {
  36155. return (
  36156. /**
  36157. *... # trailingComment
  36158. */
  36159. hasTrailingComment$3(document) || nextDocument && (
  36160. /**
  36161. * ...
  36162. * %DIRECTIVE
  36163. * ---
  36164. */
  36165. nextDocument.head.children.length !== 0 ||
  36166. /**
  36167. * ...
  36168. * # endComment
  36169. * ---
  36170. */
  36171. hasEndComments$1(nextDocument.head))
  36172. );
  36173. }
  36174. function shouldPrintDocumentHeadEndMarker(document, nextDocument, root, options) {
  36175. if (
  36176. /**
  36177. * ---
  36178. * preserve the first document head end marker
  36179. */
  36180. root.children[0] === document && /---(\s|$)/.test(options.originalText.slice(options.locStart(document), options.locStart(document) + 4)) ||
  36181. /**
  36182. * %DIRECTIVE
  36183. * ---
  36184. */
  36185. document.head.children.length !== 0 ||
  36186. /**
  36187. * # end comment
  36188. * ---
  36189. */
  36190. hasEndComments$1(document.head) ||
  36191. /**
  36192. * --- # trailing comment
  36193. */
  36194. hasTrailingComment$3(document.head)) {
  36195. return "head";
  36196. }
  36197. if (shouldPrintDocumentEndMarker(document, nextDocument)) {
  36198. return false;
  36199. }
  36200. return nextDocument ? "root" : false;
  36201. }
  36202. function isAbsolutelyPrintedAsSingleLineNode(node, options) {
  36203. if (!node) {
  36204. return true;
  36205. }
  36206. switch (node.type) {
  36207. case "plain":
  36208. case "quoteSingle":
  36209. case "quoteDouble":
  36210. break;
  36211. case "alias":
  36212. return true;
  36213. default:
  36214. return false;
  36215. }
  36216. if (options.proseWrap === "preserve") {
  36217. return node.position.start.line === node.position.end.line;
  36218. }
  36219. if ( // backslash-newline
  36220. /\\$/m.test(options.originalText.slice(node.position.start.offset, node.position.end.offset))) {
  36221. return false;
  36222. }
  36223. switch (options.proseWrap) {
  36224. case "never":
  36225. return node.value.indexOf("\n") === -1;
  36226. case "always":
  36227. return !/[\n ]/.test(node.value);
  36228. // istanbul ignore next
  36229. default:
  36230. return false;
  36231. }
  36232. }
  36233. function needsSpaceInFrontOfMappingValue(node) {
  36234. return node.key.content && node.key.content.type === "alias";
  36235. }
  36236. function printNextEmptyLine(path, originalText) {
  36237. var node = path.getValue();
  36238. var root = path.stack[0];
  36239. root.isNextEmptyLinePrintedChecklist = root.isNextEmptyLinePrintedChecklist || [];
  36240. if (!root.isNextEmptyLinePrintedChecklist[node.position.end.line]) {
  36241. if (isNextLineEmpty$6(node, originalText)) {
  36242. root.isNextEmptyLinePrintedChecklist[node.position.end.line] = true;
  36243. return softline$8;
  36244. }
  36245. }
  36246. return "";
  36247. }
  36248. function printFlowScalarContent(nodeType, content, options) {
  36249. var lineContents = getFlowScalarLineContents$1(nodeType, content, options);
  36250. return join$c(hardline$d, lineContents.map(function (lineContentWords) {
  36251. return fill$6(join$c(line$9, lineContentWords).parts);
  36252. }));
  36253. }
  36254. function clean$7(node, newNode
  36255. /*, parent */
  36256. ) {
  36257. if (isNode$2(newNode)) {
  36258. delete newNode.position;
  36259. switch (newNode.type) {
  36260. case "comment":
  36261. // insert pragma
  36262. if (isPragma$1(newNode.value)) {
  36263. return null;
  36264. }
  36265. break;
  36266. case "quoteDouble":
  36267. case "quoteSingle":
  36268. newNode.type = "quote";
  36269. break;
  36270. }
  36271. }
  36272. }
  36273. var printerYaml = {
  36274. preprocess: preprocess$3,
  36275. print: genericPrint$6,
  36276. massageAstNode: clean$7,
  36277. insertPragma: insertPragma$9
  36278. };
  36279. var options$7 = {
  36280. bracketSpacing: commonOptions.bracketSpacing,
  36281. singleQuote: commonOptions.singleQuote,
  36282. proseWrap: commonOptions.proseWrap
  36283. };
  36284. var name$i = "YAML";
  36285. var type$g = "data";
  36286. var tmScope$g = "source.yaml";
  36287. var aliases$6 = [
  36288. "yml"
  36289. ];
  36290. var extensions$g = [
  36291. ".yml",
  36292. ".mir",
  36293. ".reek",
  36294. ".rviz",
  36295. ".sublime-syntax",
  36296. ".syntax",
  36297. ".yaml",
  36298. ".yaml-tmlanguage",
  36299. ".yml.mysql"
  36300. ];
  36301. var filenames$4 = [
  36302. ".clang-format",
  36303. ".clang-tidy",
  36304. ".gemrc",
  36305. "glide.lock"
  36306. ];
  36307. var aceMode$g = "yaml";
  36308. var codemirrorMode$c = "yaml";
  36309. var codemirrorMimeType$c = "text/x-yaml";
  36310. var languageId$g = 407;
  36311. var YAML = {
  36312. name: name$i,
  36313. type: type$g,
  36314. tmScope: tmScope$g,
  36315. aliases: aliases$6,
  36316. extensions: extensions$g,
  36317. filenames: filenames$4,
  36318. aceMode: aceMode$g,
  36319. codemirrorMode: codemirrorMode$c,
  36320. codemirrorMimeType: codemirrorMimeType$c,
  36321. languageId: languageId$g
  36322. };
  36323. var YAML$1 = /*#__PURE__*/Object.freeze({
  36324. __proto__: null,
  36325. name: name$i,
  36326. type: type$g,
  36327. tmScope: tmScope$g,
  36328. aliases: aliases$6,
  36329. extensions: extensions$g,
  36330. filenames: filenames$4,
  36331. aceMode: aceMode$g,
  36332. codemirrorMode: codemirrorMode$c,
  36333. codemirrorMimeType: codemirrorMimeType$c,
  36334. languageId: languageId$g,
  36335. 'default': YAML
  36336. });
  36337. var require$$0$7 = getCjsExportFromNamespace(YAML$1);
  36338. var languages$6 = [createLanguage(require$$0$7, function (data) {
  36339. return Object.assign(data, {
  36340. since: "1.14.0",
  36341. parsers: ["yaml"],
  36342. vscodeLanguageIds: ["yaml"]
  36343. });
  36344. })];
  36345. var languageYaml = {
  36346. languages: languages$6,
  36347. printers: {
  36348. yaml: printerYaml
  36349. },
  36350. options: options$7
  36351. };
  36352. // plugin will look for `eval("require")()` and transform to `require()` in the bundle,
  36353. // and rewrite the paths to require from the top-level.
  36354. // We need to list the parsers and getters so we can load them only when necessary.
  36355. var internalPlugins = [// JS
  36356. languageJs, {
  36357. parsers: {
  36358. // JS - Babel
  36359. get babel() {
  36360. return require("./parser-babylon").parsers.babel;
  36361. },
  36362. get "babel-flow"() {
  36363. return require("./parser-babylon").parsers["babel-flow"];
  36364. },
  36365. get babylon() {
  36366. return require("./parser-babylon").parsers.babel;
  36367. },
  36368. get json() {
  36369. return require("./parser-babylon").parsers.json;
  36370. },
  36371. get json5() {
  36372. return require("./parser-babylon").parsers.json5;
  36373. },
  36374. get "json-stringify"() {
  36375. return require("./parser-babylon").parsers["json-stringify"];
  36376. },
  36377. get __js_expression() {
  36378. return require("./parser-babylon").parsers.__js_expression;
  36379. },
  36380. get __vue_expression() {
  36381. return require("./parser-babylon").parsers.__vue_expression;
  36382. },
  36383. get __vue_event_binding() {
  36384. return require("./parser-babylon").parsers.__vue_event_binding;
  36385. },
  36386. // JS - Flow
  36387. get flow() {
  36388. return require("./parser-flow").parsers.flow;
  36389. },
  36390. // JS - TypeScript
  36391. get typescript() {
  36392. return require("./parser-typescript").parsers.typescript;
  36393. },
  36394. /**
  36395. * TODO: Remove this old alias in a major version
  36396. */
  36397. get "typescript-eslint"() {
  36398. return require("./parser-typescript").parsers.typescript;
  36399. },
  36400. // JS - Angular Action
  36401. get __ng_action() {
  36402. return require("./parser-angular").parsers.__ng_action;
  36403. },
  36404. // JS - Angular Binding
  36405. get __ng_binding() {
  36406. return require("./parser-angular").parsers.__ng_binding;
  36407. },
  36408. // JS - Angular Interpolation
  36409. get __ng_interpolation() {
  36410. return require("./parser-angular").parsers.__ng_interpolation;
  36411. },
  36412. // JS - Angular Directive
  36413. get __ng_directive() {
  36414. return require("./parser-angular").parsers.__ng_directive;
  36415. }
  36416. }
  36417. }, // CSS
  36418. languageCss, {
  36419. parsers: {
  36420. // TODO: switch these to just `postcss` and use `language` instead.
  36421. get css() {
  36422. return require("./parser-postcss").parsers.css;
  36423. },
  36424. get less() {
  36425. return require("./parser-postcss").parsers.css;
  36426. },
  36427. get scss() {
  36428. return require("./parser-postcss").parsers.css;
  36429. }
  36430. }
  36431. }, // Handlebars
  36432. languageHandlebars, {
  36433. parsers: {
  36434. get glimmer() {
  36435. return require("./parser-glimmer").parsers.glimmer;
  36436. }
  36437. }
  36438. }, // GraphQL
  36439. languageGraphql, {
  36440. parsers: {
  36441. get graphql() {
  36442. return require("./parser-graphql").parsers.graphql;
  36443. }
  36444. }
  36445. }, // Markdown
  36446. languageMarkdown, {
  36447. parsers: {
  36448. get remark() {
  36449. return require("./parser-markdown").parsers.remark;
  36450. },
  36451. // TODO: Delete this in 2.0
  36452. get markdown() {
  36453. return require("./parser-markdown").parsers.remark;
  36454. },
  36455. get mdx() {
  36456. return require("./parser-markdown").parsers.mdx;
  36457. }
  36458. }
  36459. }, languageHtml, {
  36460. parsers: {
  36461. // HTML
  36462. get html() {
  36463. return require("./parser-html").parsers.html;
  36464. },
  36465. // Vue
  36466. get vue() {
  36467. return require("./parser-html").parsers.vue;
  36468. },
  36469. // Angular
  36470. get angular() {
  36471. return require("./parser-html").parsers.angular;
  36472. },
  36473. // Lightning Web Components
  36474. get lwc() {
  36475. return require("./parser-html").parsers.lwc;
  36476. }
  36477. }
  36478. }, // YAML
  36479. languageYaml, {
  36480. parsers: {
  36481. get yaml() {
  36482. return require("./parser-yaml").parsers.yaml;
  36483. }
  36484. }
  36485. }];
  36486. var partition = function partition(array, fn) {
  36487. var a = [];
  36488. var b = [];
  36489. array.forEach(function (item) {
  36490. if (fn(item)) {
  36491. a.push(item);
  36492. } else {
  36493. b.push(item);
  36494. }
  36495. });
  36496. return [a, b];
  36497. };
  36498. function loadPlugins(plugins, pluginSearchDirs) {
  36499. if (!plugins) {
  36500. plugins = [];
  36501. }
  36502. if (!pluginSearchDirs) {
  36503. pluginSearchDirs = [];
  36504. } // unless pluginSearchDirs are provided, auto-load plugins from node_modules that are parent to Prettier
  36505. if (!pluginSearchDirs.length) {
  36506. var autoLoadDir = thirdParty.findParentDir(__dirname, "node_modules");
  36507. if (autoLoadDir) {
  36508. pluginSearchDirs = [autoLoadDir];
  36509. }
  36510. }
  36511. var _partition = partition(plugins, function (plugin) {
  36512. return typeof plugin === "string";
  36513. }),
  36514. _partition2 = _slicedToArray(_partition, 2),
  36515. externalPluginNames = _partition2[0],
  36516. externalPluginInstances = _partition2[1];
  36517. var externalManualLoadPluginInfos = externalPluginNames.map(function (pluginName) {
  36518. var requirePath;
  36519. try {
  36520. // try local files
  36521. requirePath = resolve.sync(path$2.resolve(process.cwd(), pluginName));
  36522. } catch (e) {
  36523. // try node modules
  36524. requirePath = resolve.sync(pluginName, {
  36525. basedir: process.cwd()
  36526. });
  36527. }
  36528. return {
  36529. name: pluginName,
  36530. requirePath
  36531. };
  36532. });
  36533. var externalAutoLoadPluginInfos = pluginSearchDirs.map(function (pluginSearchDir) {
  36534. var resolvedPluginSearchDir = path$2.resolve(process.cwd(), pluginSearchDir);
  36535. var nodeModulesDir = path$2.resolve(resolvedPluginSearchDir, "node_modules"); // In some fringe cases (ex: files "mounted" as virtual directories), the
  36536. // isDirectory(resolvedPluginSearchDir) check might be false even though
  36537. // the node_modules actually exists.
  36538. if (!isDirectory(nodeModulesDir) && !isDirectory(resolvedPluginSearchDir)) {
  36539. throw new Error(`${pluginSearchDir} does not exist or is not a directory`);
  36540. }
  36541. return findPluginsInNodeModules(nodeModulesDir).map(function (pluginName) {
  36542. return {
  36543. name: pluginName,
  36544. requirePath: resolve.sync(pluginName, {
  36545. basedir: resolvedPluginSearchDir
  36546. })
  36547. };
  36548. });
  36549. }).reduce(function (a, b) {
  36550. return a.concat(b);
  36551. }, []);
  36552. var externalPlugins = lodash_uniqby(externalManualLoadPluginInfos.concat(externalAutoLoadPluginInfos), "requirePath").map(function (externalPluginInfo) {
  36553. return Object.assign({
  36554. name: externalPluginInfo.name
  36555. }, require(externalPluginInfo.requirePath));
  36556. }).concat(externalPluginInstances);
  36557. return internalPlugins.concat(externalPlugins);
  36558. }
  36559. function findPluginsInNodeModules(nodeModulesDir) {
  36560. var pluginPackageJsonPaths = globby.sync(["prettier-plugin-*/package.json", "@*/prettier-plugin-*/package.json", "@prettier/plugin-*/package.json"], {
  36561. cwd: nodeModulesDir
  36562. });
  36563. return pluginPackageJsonPaths.map(path$2.dirname);
  36564. }
  36565. function isDirectory(dir) {
  36566. try {
  36567. return fs$1.statSync(dir).isDirectory();
  36568. } catch (e) {
  36569. return false;
  36570. }
  36571. }
  36572. var loadPlugins_1 = loadPlugins;
  36573. var version$3 = require$$0.version;
  36574. var getSupportInfo$2 = support.getSupportInfo; // Luckily `opts` is always the 2nd argument
  36575. function _withPlugins(fn) {
  36576. return function () {
  36577. var args = Array.from(arguments);
  36578. var opts = args[1] || {};
  36579. args[1] = Object.assign({}, opts, {
  36580. plugins: loadPlugins_1(opts.plugins, opts.pluginSearchDirs)
  36581. });
  36582. return fn.apply(null, args);
  36583. };
  36584. }
  36585. function withPlugins(fn) {
  36586. var resultingFn = _withPlugins(fn);
  36587. if (fn.sync) {
  36588. resultingFn.sync = _withPlugins(fn.sync);
  36589. }
  36590. return resultingFn;
  36591. }
  36592. var formatWithCursor = withPlugins(core.formatWithCursor);
  36593. var src$1 = {
  36594. formatWithCursor,
  36595. format(text, opts) {
  36596. return formatWithCursor(text, opts).formatted;
  36597. },
  36598. check: function check(text, opts) {
  36599. var formatted = formatWithCursor(text, opts).formatted;
  36600. return formatted === text;
  36601. },
  36602. doc,
  36603. resolveConfig: resolveConfig_1.resolveConfig,
  36604. resolveConfigFile: resolveConfig_1.resolveConfigFile,
  36605. clearConfigCache: resolveConfig_1.clearCache,
  36606. getFileInfo: withPlugins(getFileInfo_1),
  36607. getSupportInfo: withPlugins(getSupportInfo$2),
  36608. version: version$3,
  36609. util: utilShared,
  36610. /* istanbul ignore next */
  36611. __debug: {
  36612. parse: withPlugins(core.parse),
  36613. formatAST: withPlugins(core.formatAST),
  36614. formatDoc: withPlugins(core.formatDoc),
  36615. printToDoc: withPlugins(core.printToDoc),
  36616. printDocToString: withPlugins(core.printDocToString)
  36617. }
  36618. };
  36619. var prettier = src$1;
  36620. module.exports = prettier;