index.js 976 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267
  1. 'use strict';
  2. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  3. var path = _interopDefault(require('path'));
  4. var os = _interopDefault(require('os'));
  5. var assert = _interopDefault(require('assert'));
  6. var fs = _interopDefault(require('fs'));
  7. var util = _interopDefault(require('util'));
  8. var events = _interopDefault(require('events'));
  9. var thirdParty = require('./third-party');
  10. var thirdParty__default = thirdParty['default'];
  11. var name = "prettier";
  12. var version$1 = "1.13.7";
  13. var description = "Prettier is an opinionated code formatter";
  14. var bin = {
  15. "prettier": "./bin/prettier.js"
  16. };
  17. var repository = "prettier/prettier";
  18. var homepage = "https://prettier.io";
  19. var author = "James Long";
  20. var license = "MIT";
  21. var main = "./index.js";
  22. var engines = {
  23. "node": ">=6"
  24. };
  25. var dependencies = {
  26. "@babel/code-frame": "7.0.0-beta.49",
  27. "@babel/parser": "7.0.0-beta.49",
  28. "@glimmer/syntax": "0.30.3",
  29. "camelcase": "4.1.0",
  30. "chalk": "2.1.0",
  31. "cjk-regex": "1.0.2",
  32. "cosmiconfig": "3.1.0",
  33. "dashify": "0.2.2",
  34. "dedent": "0.7.0",
  35. "diff": "3.2.0",
  36. "editorconfig": "0.15.0",
  37. "editorconfig-to-prettier": "0.0.6",
  38. "emoji-regex": "6.5.1",
  39. "escape-string-regexp": "1.0.5",
  40. "esutils": "2.0.2",
  41. "find-parent-dir": "0.3.0",
  42. "find-project-root": "1.1.1",
  43. "flow-parser": "0.75.0",
  44. "get-stream": "3.0.0",
  45. "globby": "6.1.0",
  46. "graphql": "0.13.2",
  47. "html-tag-names": "1.1.2",
  48. "ignore": "3.3.7",
  49. "jest-docblock": "22.2.2",
  50. "json-stable-stringify": "1.0.1",
  51. "leven": "2.1.0",
  52. "lodash.uniqby": "4.7.0",
  53. "mem": "1.1.0",
  54. "minimatch": "3.0.4",
  55. "minimist": "1.2.0",
  56. "parse5": "3.0.3",
  57. "postcss-less": "1.1.5",
  58. "postcss-media-query-parser": "0.2.3",
  59. "postcss-scss": "1.0.5",
  60. "postcss-selector-parser": "2.2.3",
  61. "postcss-values-parser": "1.5.0",
  62. "remark-parse": "5.0.0",
  63. "resolve": "1.5.0",
  64. "semver": "5.4.1",
  65. "string-width": "2.1.1",
  66. "typescript": "2.9.0-dev.20180421",
  67. "typescript-eslint-parser": "16.0.0",
  68. "unicode-regex": "1.0.1",
  69. "unified": "6.1.6"
  70. };
  71. var devDependencies = {
  72. "@babel/cli": "7.0.0-beta.49",
  73. "@babel/core": "7.0.0-beta.49",
  74. "@babel/preset-env": "7.0.0-beta.49",
  75. "builtin-modules": "2.0.0",
  76. "codecov": "2.2.0",
  77. "cross-env": "5.0.5",
  78. "eslint": "4.18.2",
  79. "eslint-config-prettier": "2.9.0",
  80. "eslint-friendly-formatter": "3.0.0",
  81. "eslint-plugin-import": "2.9.0",
  82. "eslint-plugin-prettier": "2.6.0",
  83. "eslint-plugin-react": "7.7.0",
  84. "jest": "21.1.0",
  85. "mkdirp": "0.5.1",
  86. "prettier": "1.13.4",
  87. "prettylint": "1.0.0",
  88. "rimraf": "2.6.2",
  89. "rollup": "0.47.6",
  90. "rollup-plugin-babel": "4.0.0-beta.4",
  91. "rollup-plugin-commonjs": "8.2.6",
  92. "rollup-plugin-json": "2.1.1",
  93. "rollup-plugin-node-builtins": "2.0.0",
  94. "rollup-plugin-node-globals": "1.1.0",
  95. "rollup-plugin-node-resolve": "2.0.0",
  96. "rollup-plugin-replace": "1.2.1",
  97. "rollup-plugin-uglify": "3.0.0",
  98. "shelljs": "0.8.1",
  99. "snapshot-diff": "0.2.2",
  100. "strip-ansi": "4.0.0",
  101. "tempy": "0.2.1",
  102. "webpack": "2.6.1"
  103. };
  104. var scripts = {
  105. "prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1",
  106. "prepare-release": "yarn && yarn build && yarn test:dist",
  107. "test": "jest",
  108. "test:dist": "node ./scripts/test-dist.js",
  109. "test-integration": "jest tests_integration",
  110. "lint": "cross-env EFF_NO_LINK_RULES=true eslint . --format node_modules/eslint-friendly-formatter",
  111. "lint-docs": "prettylint {.,docs,website,website/blog}/*.md",
  112. "build": "node ./scripts/build/build.js",
  113. "build-docs": "node ./scripts/build-docs.js",
  114. "check-deps": "node ./scripts/check-deps.js"
  115. };
  116. var _package = {
  117. name: name,
  118. version: version$1,
  119. description: description,
  120. bin: bin,
  121. repository: repository,
  122. homepage: homepage,
  123. author: author,
  124. license: license,
  125. main: main,
  126. engines: engines,
  127. dependencies: dependencies,
  128. devDependencies: devDependencies,
  129. scripts: scripts
  130. };
  131. var _package$1 = Object.freeze({
  132. name: name,
  133. version: version$1,
  134. description: description,
  135. bin: bin,
  136. repository: repository,
  137. homepage: homepage,
  138. author: author,
  139. license: license,
  140. main: main,
  141. engines: engines,
  142. dependencies: dependencies,
  143. devDependencies: devDependencies,
  144. scripts: scripts,
  145. default: _package
  146. });
  147. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  148. function unwrapExports (x) {
  149. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  150. }
  151. function createCommonjsModule(fn, module) {
  152. return module = { exports: {} }, fn(module, module.exports), module.exports;
  153. }
  154. var base = createCommonjsModule(function (module, exports) {
  155. /*istanbul ignore start*/
  156. 'use strict';
  157. exports.__esModule = true;
  158. exports['default'] =
  159. /*istanbul ignore end*/
  160. Diff;
  161. function Diff() {}
  162. Diff.prototype = {
  163. /*istanbul ignore start*/
  164. /*istanbul ignore end*/
  165. diff: function diff(oldString, newString) {
  166. /*istanbul ignore start*/
  167. var
  168. /*istanbul ignore end*/
  169. options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  170. var callback = options.callback;
  171. if (typeof options === 'function') {
  172. callback = options;
  173. options = {};
  174. }
  175. this.options = options;
  176. var self = this;
  177. function done(value) {
  178. if (callback) {
  179. setTimeout(function () {
  180. callback(undefined, value);
  181. }, 0);
  182. return true;
  183. } else {
  184. return value;
  185. }
  186. } // Allow subclasses to massage the input prior to running
  187. oldString = this.castInput(oldString);
  188. newString = this.castInput(newString);
  189. oldString = this.removeEmpty(this.tokenize(oldString));
  190. newString = this.removeEmpty(this.tokenize(newString));
  191. var newLen = newString.length,
  192. oldLen = oldString.length;
  193. var editLength = 1;
  194. var maxEditLength = newLen + oldLen;
  195. var bestPath = [{
  196. newPos: -1,
  197. components: []
  198. }]; // Seed editLength = 0, i.e. the content starts with the same values
  199. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  200. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  201. // Identity per the equality and tokenizer
  202. return done([{
  203. value: this.join(newString),
  204. count: newString.length
  205. }]);
  206. } // Main worker method. checks all permutations of a given edit length for acceptance.
  207. function execEditLength() {
  208. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  209. var basePath =
  210. /*istanbul ignore start*/
  211. void 0;
  212. var addPath = bestPath[diagonalPath - 1],
  213. removePath = bestPath[diagonalPath + 1],
  214. _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  215. if (addPath) {
  216. // No one else is going to attempt to use this value, clear it
  217. bestPath[diagonalPath - 1] = undefined;
  218. }
  219. var canAdd = addPath && addPath.newPos + 1 < newLen,
  220. canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
  221. if (!canAdd && !canRemove) {
  222. // If this path is a terminal then prune
  223. bestPath[diagonalPath] = undefined;
  224. continue;
  225. } // Select the diagonal that we want to branch from. We select the prior
  226. // path whose position in the new string is the farthest from the origin
  227. // and does not pass the bounds of the diff graph
  228. if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
  229. basePath = clonePath(removePath);
  230. self.pushComponent(basePath.components, undefined, true);
  231. } else {
  232. basePath = addPath; // No need to clone, we've pulled it from the list
  233. basePath.newPos++;
  234. self.pushComponent(basePath.components, true, undefined);
  235. }
  236. _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
  237. if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
  238. return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
  239. } else {
  240. // Otherwise track this path as a potential candidate and continue.
  241. bestPath[diagonalPath] = basePath;
  242. }
  243. }
  244. editLength++;
  245. } // Performs the length of edit iteration. Is a bit fugly as this has to support the
  246. // sync and async mode which is never fun. Loops over execEditLength until a value
  247. // is produced.
  248. if (callback) {
  249. (function exec() {
  250. setTimeout(function () {
  251. // This should not happen, but we want to be safe.
  252. /* istanbul ignore next */
  253. if (editLength > maxEditLength) {
  254. return callback();
  255. }
  256. if (!execEditLength()) {
  257. exec();
  258. }
  259. }, 0);
  260. })();
  261. } else {
  262. while (editLength <= maxEditLength) {
  263. var ret = execEditLength();
  264. if (ret) {
  265. return ret;
  266. }
  267. }
  268. }
  269. },
  270. /*istanbul ignore start*/
  271. /*istanbul ignore end*/
  272. pushComponent: function pushComponent(components, added, removed) {
  273. var last = components[components.length - 1];
  274. if (last && last.added === added && last.removed === removed) {
  275. // We need to clone here as the component clone operation is just
  276. // as shallow array clone
  277. components[components.length - 1] = {
  278. count: last.count + 1,
  279. added: added,
  280. removed: removed
  281. };
  282. } else {
  283. components.push({
  284. count: 1,
  285. added: added,
  286. removed: removed
  287. });
  288. }
  289. },
  290. /*istanbul ignore start*/
  291. /*istanbul ignore end*/
  292. extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
  293. var newLen = newString.length,
  294. oldLen = oldString.length,
  295. newPos = basePath.newPos,
  296. oldPos = newPos - diagonalPath,
  297. commonCount = 0;
  298. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  299. newPos++;
  300. oldPos++;
  301. commonCount++;
  302. }
  303. if (commonCount) {
  304. basePath.components.push({
  305. count: commonCount
  306. });
  307. }
  308. basePath.newPos = newPos;
  309. return oldPos;
  310. },
  311. /*istanbul ignore start*/
  312. /*istanbul ignore end*/
  313. equals: function equals(left, right) {
  314. return left === right;
  315. },
  316. /*istanbul ignore start*/
  317. /*istanbul ignore end*/
  318. removeEmpty: function removeEmpty(array) {
  319. var ret = [];
  320. for (var i = 0; i < array.length; i++) {
  321. if (array[i]) {
  322. ret.push(array[i]);
  323. }
  324. }
  325. return ret;
  326. },
  327. /*istanbul ignore start*/
  328. /*istanbul ignore end*/
  329. castInput: function castInput(value) {
  330. return value;
  331. },
  332. /*istanbul ignore start*/
  333. /*istanbul ignore end*/
  334. tokenize: function tokenize(value) {
  335. return value.split('');
  336. },
  337. /*istanbul ignore start*/
  338. /*istanbul ignore end*/
  339. join: function join(chars) {
  340. return chars.join('');
  341. }
  342. };
  343. function buildValues(diff, components, newString, oldString, useLongestToken) {
  344. var componentPos = 0,
  345. componentLen = components.length,
  346. newPos = 0,
  347. oldPos = 0;
  348. for (; componentPos < componentLen; componentPos++) {
  349. var component = components[componentPos];
  350. if (!component.removed) {
  351. if (!component.added && useLongestToken) {
  352. var value = newString.slice(newPos, newPos + component.count);
  353. value = value.map(function (value, i) {
  354. var oldValue = oldString[oldPos + i];
  355. return oldValue.length > value.length ? oldValue : value;
  356. });
  357. component.value = diff.join(value);
  358. } else {
  359. component.value = diff.join(newString.slice(newPos, newPos + component.count));
  360. }
  361. newPos += component.count; // Common case
  362. if (!component.added) {
  363. oldPos += component.count;
  364. }
  365. } else {
  366. component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
  367. oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
  368. // The diffing algorithm is tied to add then remove output and this is the simplest
  369. // route to get the desired output with minimal overhead.
  370. if (componentPos && components[componentPos - 1].added) {
  371. var tmp = components[componentPos - 1];
  372. components[componentPos - 1] = components[componentPos];
  373. components[componentPos] = tmp;
  374. }
  375. }
  376. } // Special case handle for when one terminal is ignored. For this case we merge the
  377. // terminal into the prior string and drop the change.
  378. var lastComponent = components[componentLen - 1];
  379. if (componentLen > 1 && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
  380. components[componentLen - 2].value += lastComponent.value;
  381. components.pop();
  382. }
  383. return components;
  384. }
  385. function clonePath(path$$1) {
  386. return {
  387. newPos: path$$1.newPos,
  388. components: path$$1.components.slice(0)
  389. };
  390. }
  391. });
  392. unwrapExports(base);
  393. var character = createCommonjsModule(function (module, exports) {
  394. /*istanbul ignore start*/
  395. 'use strict';
  396. exports.__esModule = true;
  397. exports.characterDiff = undefined;
  398. exports.
  399. /*istanbul ignore end*/
  400. diffChars = diffChars;
  401. /*istanbul ignore start*/
  402. var _base2 = _interopRequireDefault(base);
  403. function _interopRequireDefault(obj) {
  404. return obj && obj.__esModule ? obj : {
  405. 'default': obj
  406. };
  407. }
  408. /*istanbul ignore end*/
  409. var characterDiff =
  410. /*istanbul ignore start*/
  411. exports.
  412. /*istanbul ignore end*/
  413. characterDiff = new
  414. /*istanbul ignore start*/
  415. _base2['default']();
  416. function diffChars(oldStr, newStr, callback) {
  417. return characterDiff.diff(oldStr, newStr, callback);
  418. }
  419. });
  420. unwrapExports(character);
  421. var params = createCommonjsModule(function (module, exports) {
  422. /*istanbul ignore start*/
  423. 'use strict';
  424. exports.__esModule = true;
  425. exports.
  426. /*istanbul ignore end*/
  427. generateOptions = generateOptions;
  428. function generateOptions(options, defaults) {
  429. if (typeof options === 'function') {
  430. defaults.callback = options;
  431. } else if (options) {
  432. for (var name in options) {
  433. /* istanbul ignore else */
  434. if (options.hasOwnProperty(name)) {
  435. defaults[name] = options[name];
  436. }
  437. }
  438. }
  439. return defaults;
  440. }
  441. });
  442. unwrapExports(params);
  443. var word = createCommonjsModule(function (module, exports) {
  444. /*istanbul ignore start*/
  445. 'use strict';
  446. exports.__esModule = true;
  447. exports.wordDiff = undefined;
  448. exports.
  449. /*istanbul ignore end*/
  450. diffWords = diffWords;
  451. /*istanbul ignore start*/
  452. exports.
  453. /*istanbul ignore end*/
  454. diffWordsWithSpace = diffWordsWithSpace;
  455. /*istanbul ignore start*/
  456. var _base2 = _interopRequireDefault(base);
  457. /*istanbul ignore end*/
  458. /*istanbul ignore start*/
  459. function _interopRequireDefault(obj) {
  460. return obj && obj.__esModule ? obj : {
  461. 'default': obj
  462. };
  463. }
  464. /*istanbul ignore end*/
  465. // Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
  466. //
  467. // Ranges and exceptions:
  468. // Latin-1 Supplement, 0080–00FF
  469. // - U+00D7 × Multiplication sign
  470. // - U+00F7 ÷ Division sign
  471. // Latin Extended-A, 0100–017F
  472. // Latin Extended-B, 0180–024F
  473. // IPA Extensions, 0250–02AF
  474. // Spacing Modifier Letters, 02B0–02FF
  475. // - U+02C7 ˇ &#711; Caron
  476. // - U+02D8 ˘ &#728; Breve
  477. // - U+02D9 ˙ &#729; Dot Above
  478. // - U+02DA ˚ &#730; Ring Above
  479. // - U+02DB ˛ &#731; Ogonek
  480. // - U+02DC ˜ &#732; Small Tilde
  481. // - U+02DD ˝ &#733; Double Acute Accent
  482. // Latin Extended Additional, 1E00–1EFF
  483. var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
  484. var reWhitespace = /\S/;
  485. var wordDiff =
  486. /*istanbul ignore start*/
  487. exports.
  488. /*istanbul ignore end*/
  489. wordDiff = new
  490. /*istanbul ignore start*/
  491. _base2['default']();
  492. wordDiff.equals = function (left, right) {
  493. return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
  494. };
  495. wordDiff.tokenize = function (value) {
  496. 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.
  497. for (var i = 0; i < tokens.length - 1; i++) {
  498. // If we have an empty string in the next field and we have only word chars before and after, merge
  499. if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
  500. tokens[i] += tokens[i + 2];
  501. tokens.splice(i + 1, 2);
  502. i--;
  503. }
  504. }
  505. return tokens;
  506. };
  507. function diffWords(oldStr, newStr, callback) {
  508. var options =
  509. /*istanbul ignore start*/
  510. (0, params.generateOptions
  511. /*istanbul ignore end*/
  512. )(callback, {
  513. ignoreWhitespace: true
  514. });
  515. return wordDiff.diff(oldStr, newStr, options);
  516. }
  517. function diffWordsWithSpace(oldStr, newStr, callback) {
  518. return wordDiff.diff(oldStr, newStr, callback);
  519. }
  520. });
  521. unwrapExports(word);
  522. var line = createCommonjsModule(function (module, exports) {
  523. /*istanbul ignore start*/
  524. 'use strict';
  525. exports.__esModule = true;
  526. exports.lineDiff = undefined;
  527. exports.
  528. /*istanbul ignore end*/
  529. diffLines = diffLines;
  530. /*istanbul ignore start*/
  531. exports.
  532. /*istanbul ignore end*/
  533. diffTrimmedLines = diffTrimmedLines;
  534. /*istanbul ignore start*/
  535. var _base2 = _interopRequireDefault(base);
  536. /*istanbul ignore end*/
  537. /*istanbul ignore start*/
  538. function _interopRequireDefault(obj) {
  539. return obj && obj.__esModule ? obj : {
  540. 'default': obj
  541. };
  542. }
  543. /*istanbul ignore end*/
  544. var lineDiff =
  545. /*istanbul ignore start*/
  546. exports.
  547. /*istanbul ignore end*/
  548. lineDiff = new
  549. /*istanbul ignore start*/
  550. _base2['default']();
  551. lineDiff.tokenize = function (value) {
  552. var retLines = [],
  553. linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
  554. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  555. linesAndNewlines.pop();
  556. } // Merge the content and line separators into single tokens
  557. for (var i = 0; i < linesAndNewlines.length; i++) {
  558. var line = linesAndNewlines[i];
  559. if (i % 2 && !this.options.newlineIsToken) {
  560. retLines[retLines.length - 1] += line;
  561. } else {
  562. if (this.options.ignoreWhitespace) {
  563. line = line.trim();
  564. }
  565. retLines.push(line);
  566. }
  567. }
  568. return retLines;
  569. };
  570. function diffLines(oldStr, newStr, callback) {
  571. return lineDiff.diff(oldStr, newStr, callback);
  572. }
  573. function diffTrimmedLines(oldStr, newStr, callback) {
  574. var options =
  575. /*istanbul ignore start*/
  576. (0, params.generateOptions
  577. /*istanbul ignore end*/
  578. )(callback, {
  579. ignoreWhitespace: true
  580. });
  581. return lineDiff.diff(oldStr, newStr, options);
  582. }
  583. });
  584. unwrapExports(line);
  585. var sentence = createCommonjsModule(function (module, exports) {
  586. /*istanbul ignore start*/
  587. 'use strict';
  588. exports.__esModule = true;
  589. exports.sentenceDiff = undefined;
  590. exports.
  591. /*istanbul ignore end*/
  592. diffSentences = diffSentences;
  593. /*istanbul ignore start*/
  594. var _base2 = _interopRequireDefault(base);
  595. function _interopRequireDefault(obj) {
  596. return obj && obj.__esModule ? obj : {
  597. 'default': obj
  598. };
  599. }
  600. /*istanbul ignore end*/
  601. var sentenceDiff =
  602. /*istanbul ignore start*/
  603. exports.
  604. /*istanbul ignore end*/
  605. sentenceDiff = new
  606. /*istanbul ignore start*/
  607. _base2['default']();
  608. sentenceDiff.tokenize = function (value) {
  609. return value.split(/(\S.+?[.!?])(?=\s+|$)/);
  610. };
  611. function diffSentences(oldStr, newStr, callback) {
  612. return sentenceDiff.diff(oldStr, newStr, callback);
  613. }
  614. });
  615. unwrapExports(sentence);
  616. var css = createCommonjsModule(function (module, exports) {
  617. /*istanbul ignore start*/
  618. 'use strict';
  619. exports.__esModule = true;
  620. exports.cssDiff = undefined;
  621. exports.
  622. /*istanbul ignore end*/
  623. diffCss = diffCss;
  624. /*istanbul ignore start*/
  625. var _base2 = _interopRequireDefault(base);
  626. function _interopRequireDefault(obj) {
  627. return obj && obj.__esModule ? obj : {
  628. 'default': obj
  629. };
  630. }
  631. /*istanbul ignore end*/
  632. var cssDiff =
  633. /*istanbul ignore start*/
  634. exports.
  635. /*istanbul ignore end*/
  636. cssDiff = new
  637. /*istanbul ignore start*/
  638. _base2['default']();
  639. cssDiff.tokenize = function (value) {
  640. return value.split(/([{}:;,]|\s+)/);
  641. };
  642. function diffCss(oldStr, newStr, callback) {
  643. return cssDiff.diff(oldStr, newStr, callback);
  644. }
  645. });
  646. unwrapExports(css);
  647. var json = createCommonjsModule(function (module, exports) {
  648. /*istanbul ignore start*/
  649. 'use strict';
  650. exports.__esModule = true;
  651. exports.jsonDiff = undefined;
  652. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  653. return typeof obj;
  654. } : function (obj) {
  655. return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
  656. };
  657. exports.
  658. /*istanbul ignore end*/
  659. diffJson = diffJson;
  660. /*istanbul ignore start*/
  661. exports.
  662. /*istanbul ignore end*/
  663. canonicalize = canonicalize;
  664. /*istanbul ignore start*/
  665. var _base2 = _interopRequireDefault(base);
  666. /*istanbul ignore end*/
  667. /*istanbul ignore start*/
  668. function _interopRequireDefault(obj) {
  669. return obj && obj.__esModule ? obj : {
  670. 'default': obj
  671. };
  672. }
  673. /*istanbul ignore end*/
  674. var objectPrototypeToString = Object.prototype.toString;
  675. var jsonDiff =
  676. /*istanbul ignore start*/
  677. exports.
  678. /*istanbul ignore end*/
  679. jsonDiff = new
  680. /*istanbul ignore start*/
  681. _base2['default'](); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  682. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  683. jsonDiff.useLongestToken = true;
  684. jsonDiff.tokenize =
  685. /*istanbul ignore start*/
  686. line.lineDiff.
  687. /*istanbul ignore end*/
  688. tokenize;
  689. jsonDiff.castInput = function (value) {
  690. /*istanbul ignore start*/
  691. var
  692. /*istanbul ignore end*/
  693. undefinedReplacement = this.options.undefinedReplacement;
  694. return typeof value === 'string' ? value : JSON.stringify(canonicalize(value), function (k, v) {
  695. if (typeof v === 'undefined') {
  696. return undefinedReplacement;
  697. }
  698. return v;
  699. }, ' ');
  700. };
  701. jsonDiff.equals = function (left, right) {
  702. return (
  703. /*istanbul ignore start*/
  704. _base2['default'].
  705. /*istanbul ignore end*/
  706. prototype.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'))
  707. );
  708. };
  709. function diffJson(oldObj, newObj, options) {
  710. return jsonDiff.diff(oldObj, newObj, options);
  711. } // This function handles the presence of circular references by bailing out when encountering an
  712. // object that is already on the "stack" of items being processed.
  713. function canonicalize(obj, stack, replacementStack) {
  714. stack = stack || [];
  715. replacementStack = replacementStack || [];
  716. var i =
  717. /*istanbul ignore start*/
  718. void 0;
  719. for (i = 0; i < stack.length; i += 1) {
  720. if (stack[i] === obj) {
  721. return replacementStack[i];
  722. }
  723. }
  724. var canonicalizedObj =
  725. /*istanbul ignore start*/
  726. void 0;
  727. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  728. stack.push(obj);
  729. canonicalizedObj = new Array(obj.length);
  730. replacementStack.push(canonicalizedObj);
  731. for (i = 0; i < obj.length; i += 1) {
  732. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack);
  733. }
  734. stack.pop();
  735. replacementStack.pop();
  736. return canonicalizedObj;
  737. }
  738. if (obj && obj.toJSON) {
  739. obj = obj.toJSON();
  740. }
  741. if (
  742. /*istanbul ignore start*/
  743. (typeof
  744. /*istanbul ignore end*/
  745. obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && obj !== null) {
  746. stack.push(obj);
  747. canonicalizedObj = {};
  748. replacementStack.push(canonicalizedObj);
  749. var sortedKeys = [],
  750. key =
  751. /*istanbul ignore start*/
  752. void 0;
  753. for (key in obj) {
  754. /* istanbul ignore else */
  755. if (obj.hasOwnProperty(key)) {
  756. sortedKeys.push(key);
  757. }
  758. }
  759. sortedKeys.sort();
  760. for (i = 0; i < sortedKeys.length; i += 1) {
  761. key = sortedKeys[i];
  762. canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack);
  763. }
  764. stack.pop();
  765. replacementStack.pop();
  766. } else {
  767. canonicalizedObj = obj;
  768. }
  769. return canonicalizedObj;
  770. }
  771. });
  772. unwrapExports(json);
  773. var array = createCommonjsModule(function (module, exports) {
  774. /*istanbul ignore start*/
  775. 'use strict';
  776. exports.__esModule = true;
  777. exports.arrayDiff = undefined;
  778. exports.
  779. /*istanbul ignore end*/
  780. diffArrays = diffArrays;
  781. /*istanbul ignore start*/
  782. var _base2 = _interopRequireDefault(base);
  783. function _interopRequireDefault(obj) {
  784. return obj && obj.__esModule ? obj : {
  785. 'default': obj
  786. };
  787. }
  788. /*istanbul ignore end*/
  789. var arrayDiff =
  790. /*istanbul ignore start*/
  791. exports.
  792. /*istanbul ignore end*/
  793. arrayDiff = new
  794. /*istanbul ignore start*/
  795. _base2['default']();
  796. arrayDiff.tokenize = arrayDiff.join = function (value) {
  797. return value.slice();
  798. };
  799. function diffArrays(oldArr, newArr, callback) {
  800. return arrayDiff.diff(oldArr, newArr, callback);
  801. }
  802. });
  803. unwrapExports(array);
  804. var parse = createCommonjsModule(function (module, exports) {
  805. /*istanbul ignore start*/
  806. 'use strict';
  807. exports.__esModule = true;
  808. exports.
  809. /*istanbul ignore end*/
  810. parsePatch = parsePatch;
  811. function parsePatch(uniDiff) {
  812. /*istanbul ignore start*/
  813. var
  814. /*istanbul ignore end*/
  815. options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  816. var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
  817. delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  818. list = [],
  819. i = 0;
  820. function parseIndex() {
  821. var index = {};
  822. list.push(index); // Parse diff metadata
  823. while (i < diffstr.length) {
  824. var line = diffstr[i]; // File header found, end parsing diff metadata
  825. if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
  826. break;
  827. } // Diff index
  828. var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
  829. if (header) {
  830. index.index = header[1];
  831. }
  832. i++;
  833. } // Parse file headers if they are defined. Unified diff requires them, but
  834. // there's no technical issues to have an isolated hunk without file header
  835. parseFileHeader(index);
  836. parseFileHeader(index); // Parse hunks
  837. index.hunks = [];
  838. while (i < diffstr.length) {
  839. var _line = diffstr[i];
  840. if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
  841. break;
  842. } else if (/^@@/.test(_line)) {
  843. index.hunks.push(parseHunk());
  844. } else if (_line && options.strict) {
  845. // Ignore unexpected content unless in strict mode
  846. throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
  847. } else {
  848. i++;
  849. }
  850. }
  851. } // Parses the --- and +++ headers, if none are found, no lines
  852. // are consumed.
  853. function parseFileHeader(index) {
  854. var headerPattern = /^(---|\+\+\+)\s+([\S ]*)(?:\t(.*?)\s*)?$/;
  855. var fileHeader = headerPattern.exec(diffstr[i]);
  856. if (fileHeader) {
  857. var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
  858. index[keyPrefix + 'FileName'] = fileHeader[2];
  859. index[keyPrefix + 'Header'] = fileHeader[3];
  860. i++;
  861. }
  862. } // Parses a hunk
  863. // This assumes that we are at the start of a hunk.
  864. function parseHunk() {
  865. var chunkHeaderIndex = i,
  866. chunkHeaderLine = diffstr[i++],
  867. chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
  868. var hunk = {
  869. oldStart: +chunkHeader[1],
  870. oldLines: +chunkHeader[2] || 1,
  871. newStart: +chunkHeader[3],
  872. newLines: +chunkHeader[4] || 1,
  873. lines: [],
  874. linedelimiters: []
  875. };
  876. var addCount = 0,
  877. removeCount = 0;
  878. for (; i < diffstr.length; i++) {
  879. // Lines starting with '---' could be mistaken for the "remove line" operation
  880. // But they could be the header for the next file. Therefore prune such cases out.
  881. if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
  882. break;
  883. }
  884. var operation = diffstr[i][0];
  885. if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
  886. hunk.lines.push(diffstr[i]);
  887. hunk.linedelimiters.push(delimiters[i] || '\n');
  888. if (operation === '+') {
  889. addCount++;
  890. } else if (operation === '-') {
  891. removeCount++;
  892. } else if (operation === ' ') {
  893. addCount++;
  894. removeCount++;
  895. }
  896. } else {
  897. break;
  898. }
  899. } // Handle the empty block count case
  900. if (!addCount && hunk.newLines === 1) {
  901. hunk.newLines = 0;
  902. }
  903. if (!removeCount && hunk.oldLines === 1) {
  904. hunk.oldLines = 0;
  905. } // Perform optional sanity checking
  906. if (options.strict) {
  907. if (addCount !== hunk.newLines) {
  908. throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  909. }
  910. if (removeCount !== hunk.oldLines) {
  911. throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  912. }
  913. }
  914. return hunk;
  915. }
  916. while (i < diffstr.length) {
  917. parseIndex();
  918. }
  919. return list;
  920. }
  921. });
  922. unwrapExports(parse);
  923. var distanceIterator = createCommonjsModule(function (module, exports) {
  924. /*istanbul ignore start*/
  925. "use strict";
  926. exports.__esModule = true;
  927. exports["default"] =
  928. /*istanbul ignore end*/
  929. function (start, minLine, maxLine) {
  930. var wantForward = true,
  931. backwardExhausted = false,
  932. forwardExhausted = false,
  933. localOffset = 1;
  934. return function iterator() {
  935. if (wantForward && !forwardExhausted) {
  936. if (backwardExhausted) {
  937. localOffset++;
  938. } else {
  939. wantForward = false;
  940. } // Check if trying to fit beyond text length, and if not, check it fits
  941. // after offset location (or desired location on first iteration)
  942. if (start + localOffset <= maxLine) {
  943. return localOffset;
  944. }
  945. forwardExhausted = true;
  946. }
  947. if (!backwardExhausted) {
  948. if (!forwardExhausted) {
  949. wantForward = true;
  950. } // Check if trying to fit before text beginning, and if not, check it fits
  951. // before offset location
  952. if (minLine <= start - localOffset) {
  953. return -localOffset++;
  954. }
  955. backwardExhausted = true;
  956. return iterator();
  957. } // We tried to fit hunk before text beginning and beyond text lenght, then
  958. // hunk can't fit on the text. Return undefined
  959. };
  960. };
  961. });
  962. unwrapExports(distanceIterator);
  963. var apply = createCommonjsModule(function (module, exports) {
  964. /*istanbul ignore start*/
  965. 'use strict';
  966. exports.__esModule = true;
  967. exports.
  968. /*istanbul ignore end*/
  969. applyPatch = applyPatch;
  970. /*istanbul ignore start*/
  971. exports.
  972. /*istanbul ignore end*/
  973. applyPatches = applyPatches;
  974. /*istanbul ignore start*/
  975. var _distanceIterator2 = _interopRequireDefault(distanceIterator);
  976. function _interopRequireDefault(obj) {
  977. return obj && obj.__esModule ? obj : {
  978. 'default': obj
  979. };
  980. }
  981. /*istanbul ignore end*/
  982. function applyPatch(source, uniDiff) {
  983. /*istanbul ignore start*/
  984. var
  985. /*istanbul ignore end*/
  986. options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  987. if (typeof uniDiff === 'string') {
  988. uniDiff =
  989. /*istanbul ignore start*/
  990. (0, parse.parsePatch
  991. /*istanbul ignore end*/
  992. )(uniDiff);
  993. }
  994. if (Array.isArray(uniDiff)) {
  995. if (uniDiff.length > 1) {
  996. throw new Error('applyPatch only works with a single input.');
  997. }
  998. uniDiff = uniDiff[0];
  999. } // Apply the diff to the input
  1000. var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
  1001. delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  1002. hunks = uniDiff.hunks,
  1003. compareLine = options.compareLine || function (lineNumber, line, operation, patchContent)
  1004. /*istanbul ignore start*/
  1005. {
  1006. return (
  1007. /*istanbul ignore end*/
  1008. line === patchContent
  1009. );
  1010. },
  1011. errorCount = 0,
  1012. fuzzFactor = options.fuzzFactor || 0,
  1013. minLine = 0,
  1014. offset = 0,
  1015. removeEOFNL =
  1016. /*istanbul ignore start*/
  1017. void 0
  1018. /*istanbul ignore end*/
  1019. ,
  1020. addEOFNL =
  1021. /*istanbul ignore start*/
  1022. void 0;
  1023. /**
  1024. * Checks if the hunk exactly fits on the provided location
  1025. */
  1026. function hunkFits(hunk, toPos) {
  1027. for (var j = 0; j < hunk.lines.length; j++) {
  1028. var line = hunk.lines[j],
  1029. operation = line[0],
  1030. content = line.substr(1);
  1031. if (operation === ' ' || operation === '-') {
  1032. // Context sanity check
  1033. if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
  1034. errorCount++;
  1035. if (errorCount > fuzzFactor) {
  1036. return false;
  1037. }
  1038. }
  1039. toPos++;
  1040. }
  1041. }
  1042. return true;
  1043. } // Search best fit offsets for each hunk based on the previous ones
  1044. for (var i = 0; i < hunks.length; i++) {
  1045. var hunk = hunks[i],
  1046. maxLine = lines.length - hunk.oldLines,
  1047. localOffset = 0,
  1048. toPos = offset + hunk.oldStart - 1;
  1049. var iterator =
  1050. /*istanbul ignore start*/
  1051. (0, _distanceIterator2['default']
  1052. /*istanbul ignore end*/
  1053. )(toPos, minLine, maxLine);
  1054. for (; localOffset !== undefined; localOffset = iterator()) {
  1055. if (hunkFits(hunk, toPos + localOffset)) {
  1056. hunk.offset = offset += localOffset;
  1057. break;
  1058. }
  1059. }
  1060. if (localOffset === undefined) {
  1061. return false;
  1062. } // Set lower text limit to end of the current hunk, so next ones don't try
  1063. // to fit over already patched text
  1064. minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
  1065. } // Apply patch hunks
  1066. for (var _i = 0; _i < hunks.length; _i++) {
  1067. var _hunk = hunks[_i],
  1068. _toPos = _hunk.offset + _hunk.newStart - 1;
  1069. if (_hunk.newLines == 0) {
  1070. _toPos++;
  1071. }
  1072. for (var j = 0; j < _hunk.lines.length; j++) {
  1073. var line = _hunk.lines[j],
  1074. operation = line[0],
  1075. content = line.substr(1),
  1076. delimiter = _hunk.linedelimiters[j];
  1077. if (operation === ' ') {
  1078. _toPos++;
  1079. } else if (operation === '-') {
  1080. lines.splice(_toPos, 1);
  1081. delimiters.splice(_toPos, 1);
  1082. /* istanbul ignore else */
  1083. } else if (operation === '+') {
  1084. lines.splice(_toPos, 0, content);
  1085. delimiters.splice(_toPos, 0, delimiter);
  1086. _toPos++;
  1087. } else if (operation === '\\') {
  1088. var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
  1089. if (previousOperation === '+') {
  1090. removeEOFNL = true;
  1091. } else if (previousOperation === '-') {
  1092. addEOFNL = true;
  1093. }
  1094. }
  1095. }
  1096. } // Handle EOFNL insertion/removal
  1097. if (removeEOFNL) {
  1098. while (!lines[lines.length - 1]) {
  1099. lines.pop();
  1100. delimiters.pop();
  1101. }
  1102. } else if (addEOFNL) {
  1103. lines.push('');
  1104. delimiters.push('\n');
  1105. }
  1106. for (var _k = 0; _k < lines.length - 1; _k++) {
  1107. lines[_k] = lines[_k] + delimiters[_k];
  1108. }
  1109. return lines.join('');
  1110. } // Wrapper that supports multiple file patches via callbacks.
  1111. function applyPatches(uniDiff, options) {
  1112. if (typeof uniDiff === 'string') {
  1113. uniDiff =
  1114. /*istanbul ignore start*/
  1115. (0, parse.parsePatch
  1116. /*istanbul ignore end*/
  1117. )(uniDiff);
  1118. }
  1119. var currentIndex = 0;
  1120. function processIndex() {
  1121. var index = uniDiff[currentIndex++];
  1122. if (!index) {
  1123. return options.complete();
  1124. }
  1125. options.loadFile(index, function (err, data) {
  1126. if (err) {
  1127. return options.complete(err);
  1128. }
  1129. var updatedContent = applyPatch(data, index, options);
  1130. options.patched(index, updatedContent, function (err) {
  1131. if (err) {
  1132. return options.complete(err);
  1133. }
  1134. processIndex();
  1135. });
  1136. });
  1137. }
  1138. processIndex();
  1139. }
  1140. });
  1141. unwrapExports(apply);
  1142. var create = createCommonjsModule(function (module, exports) {
  1143. /*istanbul ignore start*/
  1144. 'use strict';
  1145. exports.__esModule = true;
  1146. exports.
  1147. /*istanbul ignore end*/
  1148. structuredPatch = structuredPatch;
  1149. /*istanbul ignore start*/
  1150. exports.
  1151. /*istanbul ignore end*/
  1152. createTwoFilesPatch = createTwoFilesPatch;
  1153. /*istanbul ignore start*/
  1154. exports.
  1155. /*istanbul ignore end*/
  1156. createPatch = createPatch;
  1157. /*istanbul ignore start*/
  1158. function _toConsumableArray(arr) {
  1159. if (Array.isArray(arr)) {
  1160. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
  1161. arr2[i] = arr[i];
  1162. }
  1163. return arr2;
  1164. } else {
  1165. return Array.from(arr);
  1166. }
  1167. }
  1168. /*istanbul ignore end*/
  1169. function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  1170. if (!options) {
  1171. options = {};
  1172. }
  1173. if (typeof options.context === 'undefined') {
  1174. options.context = 4;
  1175. }
  1176. var diff =
  1177. /*istanbul ignore start*/
  1178. (0, line.diffLines
  1179. /*istanbul ignore end*/
  1180. )(oldStr, newStr, options);
  1181. diff.push({
  1182. value: '',
  1183. lines: []
  1184. }); // Append an empty value to make cleanup easier
  1185. function contextLines(lines) {
  1186. return lines.map(function (entry) {
  1187. return ' ' + entry;
  1188. });
  1189. }
  1190. var hunks = [];
  1191. var oldRangeStart = 0,
  1192. newRangeStart = 0,
  1193. curRange = [],
  1194. oldLine = 1,
  1195. newLine = 1;
  1196. /*istanbul ignore start*/
  1197. var _loop = function _loop(
  1198. /*istanbul ignore end*/
  1199. i) {
  1200. var current = diff[i],
  1201. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  1202. current.lines = lines;
  1203. if (current.added || current.removed) {
  1204. /*istanbul ignore start*/
  1205. var _curRange;
  1206. /*istanbul ignore end*/
  1207. // If we have previous context, start with that
  1208. if (!oldRangeStart) {
  1209. var prev = diff[i - 1];
  1210. oldRangeStart = oldLine;
  1211. newRangeStart = newLine;
  1212. if (prev) {
  1213. curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
  1214. oldRangeStart -= curRange.length;
  1215. newRangeStart -= curRange.length;
  1216. }
  1217. } // Output our changes
  1218. /*istanbul ignore start*/
  1219. (_curRange =
  1220. /*istanbul ignore end*/
  1221. curRange).push.
  1222. /*istanbul ignore start*/
  1223. apply
  1224. /*istanbul ignore end*/
  1225. (
  1226. /*istanbul ignore start*/
  1227. _curRange
  1228. /*istanbul ignore end*/
  1229. ,
  1230. /*istanbul ignore start*/
  1231. _toConsumableArray(
  1232. /*istanbul ignore end*/
  1233. lines.map(function (entry) {
  1234. return (current.added ? '+' : '-') + entry;
  1235. }))); // Track the updated file position
  1236. if (current.added) {
  1237. newLine += lines.length;
  1238. } else {
  1239. oldLine += lines.length;
  1240. }
  1241. } else {
  1242. // Identical context lines. Track line changes
  1243. if (oldRangeStart) {
  1244. // Close out any changes that have been output (or join overlapping)
  1245. if (lines.length <= options.context * 2 && i < diff.length - 2) {
  1246. /*istanbul ignore start*/
  1247. var _curRange2;
  1248. /*istanbul ignore end*/
  1249. // Overlapping
  1250. /*istanbul ignore start*/
  1251. (_curRange2 =
  1252. /*istanbul ignore end*/
  1253. curRange).push.
  1254. /*istanbul ignore start*/
  1255. apply
  1256. /*istanbul ignore end*/
  1257. (
  1258. /*istanbul ignore start*/
  1259. _curRange2
  1260. /*istanbul ignore end*/
  1261. ,
  1262. /*istanbul ignore start*/
  1263. _toConsumableArray(
  1264. /*istanbul ignore end*/
  1265. contextLines(lines)));
  1266. } else {
  1267. /*istanbul ignore start*/
  1268. var _curRange3;
  1269. /*istanbul ignore end*/
  1270. // end the range and output
  1271. var contextSize = Math.min(lines.length, options.context);
  1272. /*istanbul ignore start*/
  1273. (_curRange3 =
  1274. /*istanbul ignore end*/
  1275. curRange).push.
  1276. /*istanbul ignore start*/
  1277. apply
  1278. /*istanbul ignore end*/
  1279. (
  1280. /*istanbul ignore start*/
  1281. _curRange3
  1282. /*istanbul ignore end*/
  1283. ,
  1284. /*istanbul ignore start*/
  1285. _toConsumableArray(
  1286. /*istanbul ignore end*/
  1287. contextLines(lines.slice(0, contextSize))));
  1288. var hunk = {
  1289. oldStart: oldRangeStart,
  1290. oldLines: oldLine - oldRangeStart + contextSize,
  1291. newStart: newRangeStart,
  1292. newLines: newLine - newRangeStart + contextSize,
  1293. lines: curRange
  1294. };
  1295. if (i >= diff.length - 2 && lines.length <= options.context) {
  1296. // EOF is inside this hunk
  1297. var oldEOFNewline = /\n$/.test(oldStr);
  1298. var newEOFNewline = /\n$/.test(newStr);
  1299. if (lines.length == 0 && !oldEOFNewline) {
  1300. // special case: old has no eol and no trailing context; no-nl can end up before adds
  1301. curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
  1302. } else if (!oldEOFNewline || !newEOFNewline) {
  1303. curRange.push('\\ No newline at end of file');
  1304. }
  1305. }
  1306. hunks.push(hunk);
  1307. oldRangeStart = 0;
  1308. newRangeStart = 0;
  1309. curRange = [];
  1310. }
  1311. }
  1312. oldLine += lines.length;
  1313. newLine += lines.length;
  1314. }
  1315. };
  1316. for (var i = 0; i < diff.length; i++) {
  1317. /*istanbul ignore start*/
  1318. _loop(
  1319. /*istanbul ignore end*/
  1320. i);
  1321. }
  1322. return {
  1323. oldFileName: oldFileName,
  1324. newFileName: newFileName,
  1325. oldHeader: oldHeader,
  1326. newHeader: newHeader,
  1327. hunks: hunks
  1328. };
  1329. }
  1330. function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  1331. var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
  1332. var ret = [];
  1333. if (oldFileName == newFileName) {
  1334. ret.push('Index: ' + oldFileName);
  1335. }
  1336. ret.push('===================================================================');
  1337. ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
  1338. ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
  1339. for (var i = 0; i < diff.hunks.length; i++) {
  1340. var hunk = diff.hunks[i];
  1341. ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
  1342. ret.push.apply(ret, hunk.lines);
  1343. }
  1344. return ret.join('\n') + '\n';
  1345. }
  1346. function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
  1347. return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
  1348. }
  1349. });
  1350. unwrapExports(create);
  1351. var dmp = createCommonjsModule(function (module, exports) {
  1352. /*istanbul ignore start*/
  1353. "use strict";
  1354. exports.__esModule = true;
  1355. exports.
  1356. /*istanbul ignore end*/
  1357. convertChangesToDMP = convertChangesToDMP; // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  1358. function convertChangesToDMP(changes) {
  1359. var ret = [],
  1360. change =
  1361. /*istanbul ignore start*/
  1362. void 0
  1363. /*istanbul ignore end*/
  1364. ,
  1365. operation =
  1366. /*istanbul ignore start*/
  1367. void 0;
  1368. for (var i = 0; i < changes.length; i++) {
  1369. change = changes[i];
  1370. if (change.added) {
  1371. operation = 1;
  1372. } else if (change.removed) {
  1373. operation = -1;
  1374. } else {
  1375. operation = 0;
  1376. }
  1377. ret.push([operation, change.value]);
  1378. }
  1379. return ret;
  1380. }
  1381. });
  1382. unwrapExports(dmp);
  1383. var xml = createCommonjsModule(function (module, exports) {
  1384. /*istanbul ignore start*/
  1385. 'use strict';
  1386. exports.__esModule = true;
  1387. exports.
  1388. /*istanbul ignore end*/
  1389. convertChangesToXML = convertChangesToXML;
  1390. function convertChangesToXML(changes) {
  1391. var ret = [];
  1392. for (var i = 0; i < changes.length; i++) {
  1393. var change = changes[i];
  1394. if (change.added) {
  1395. ret.push('<ins>');
  1396. } else if (change.removed) {
  1397. ret.push('<del>');
  1398. }
  1399. ret.push(escapeHTML(change.value));
  1400. if (change.added) {
  1401. ret.push('</ins>');
  1402. } else if (change.removed) {
  1403. ret.push('</del>');
  1404. }
  1405. }
  1406. return ret.join('');
  1407. }
  1408. function escapeHTML(s) {
  1409. var n = s;
  1410. n = n.replace(/&/g, '&amp;');
  1411. n = n.replace(/</g, '&lt;');
  1412. n = n.replace(/>/g, '&gt;');
  1413. n = n.replace(/"/g, '&quot;');
  1414. return n;
  1415. }
  1416. });
  1417. unwrapExports(xml);
  1418. var lib = createCommonjsModule(function (module, exports) {
  1419. /*istanbul ignore start*/
  1420. 'use strict';
  1421. exports.__esModule = true;
  1422. exports.canonicalize = exports.convertChangesToXML = exports.convertChangesToDMP = exports.parsePatch = exports.applyPatches = exports.applyPatch = exports.createPatch = exports.createTwoFilesPatch = exports.structuredPatch = exports.diffArrays = exports.diffJson = exports.diffCss = exports.diffSentences = exports.diffTrimmedLines = exports.diffLines = exports.diffWordsWithSpace = exports.diffWords = exports.diffChars = exports.Diff = undefined;
  1423. /*istanbul ignore end*/
  1424. /*istanbul ignore start*/
  1425. var _base2 = _interopRequireDefault(base);
  1426. /*istanbul ignore end*/
  1427. /*istanbul ignore start*/
  1428. function _interopRequireDefault(obj) {
  1429. return obj && obj.__esModule ? obj : {
  1430. 'default': obj
  1431. };
  1432. }
  1433. exports.
  1434. /*istanbul ignore end*/
  1435. Diff = _base2['default'];
  1436. /*istanbul ignore start*/
  1437. exports.
  1438. /*istanbul ignore end*/
  1439. diffChars = character.diffChars;
  1440. /*istanbul ignore start*/
  1441. exports.
  1442. /*istanbul ignore end*/
  1443. diffWords = word.diffWords;
  1444. /*istanbul ignore start*/
  1445. exports.
  1446. /*istanbul ignore end*/
  1447. diffWordsWithSpace = word.diffWordsWithSpace;
  1448. /*istanbul ignore start*/
  1449. exports.
  1450. /*istanbul ignore end*/
  1451. diffLines = line.diffLines;
  1452. /*istanbul ignore start*/
  1453. exports.
  1454. /*istanbul ignore end*/
  1455. diffTrimmedLines = line.diffTrimmedLines;
  1456. /*istanbul ignore start*/
  1457. exports.
  1458. /*istanbul ignore end*/
  1459. diffSentences = sentence.diffSentences;
  1460. /*istanbul ignore start*/
  1461. exports.
  1462. /*istanbul ignore end*/
  1463. diffCss = css.diffCss;
  1464. /*istanbul ignore start*/
  1465. exports.
  1466. /*istanbul ignore end*/
  1467. diffJson = json.diffJson;
  1468. /*istanbul ignore start*/
  1469. exports.
  1470. /*istanbul ignore end*/
  1471. diffArrays = array.diffArrays;
  1472. /*istanbul ignore start*/
  1473. exports.
  1474. /*istanbul ignore end*/
  1475. structuredPatch = create.structuredPatch;
  1476. /*istanbul ignore start*/
  1477. exports.
  1478. /*istanbul ignore end*/
  1479. createTwoFilesPatch = create.createTwoFilesPatch;
  1480. /*istanbul ignore start*/
  1481. exports.
  1482. /*istanbul ignore end*/
  1483. createPatch = create.createPatch;
  1484. /*istanbul ignore start*/
  1485. exports.
  1486. /*istanbul ignore end*/
  1487. applyPatch = apply.applyPatch;
  1488. /*istanbul ignore start*/
  1489. exports.
  1490. /*istanbul ignore end*/
  1491. applyPatches = apply.applyPatches;
  1492. /*istanbul ignore start*/
  1493. exports.
  1494. /*istanbul ignore end*/
  1495. parsePatch = parse.parsePatch;
  1496. /*istanbul ignore start*/
  1497. exports.
  1498. /*istanbul ignore end*/
  1499. convertChangesToDMP = dmp.convertChangesToDMP;
  1500. /*istanbul ignore start*/
  1501. exports.
  1502. /*istanbul ignore end*/
  1503. convertChangesToXML = xml.convertChangesToXML;
  1504. /*istanbul ignore start*/
  1505. exports.
  1506. /*istanbul ignore end*/
  1507. canonicalize = json.canonicalize;
  1508. /* See LICENSE file for terms of use */
  1509. /*
  1510. * Text diff implementation.
  1511. *
  1512. * This library supports the following APIS:
  1513. * JsDiff.diffChars: Character by character diff
  1514. * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
  1515. * JsDiff.diffLines: Line based diff
  1516. *
  1517. * JsDiff.diffCss: Diff targeted at CSS content
  1518. *
  1519. * These methods are based on the implementation proposed in
  1520. * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
  1521. * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
  1522. */
  1523. });
  1524. unwrapExports(lib);
  1525. function _classCallCheck(instance, Constructor) {
  1526. if (!(instance instanceof Constructor)) {
  1527. throw new TypeError("Cannot call a class as a function");
  1528. }
  1529. }
  1530. function _inherits(subClass, superClass) {
  1531. if (typeof superClass !== "function" && superClass !== null) {
  1532. throw new TypeError("Super expression must either be null or a function");
  1533. }
  1534. subClass.prototype = Object.create(superClass && superClass.prototype, {
  1535. constructor: {
  1536. value: subClass,
  1537. writable: true,
  1538. configurable: true
  1539. }
  1540. });
  1541. if (superClass) _setPrototypeOf(subClass, superClass);
  1542. }
  1543. function _getPrototypeOf(o) {
  1544. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  1545. return o.__proto__ || Object.getPrototypeOf(o);
  1546. };
  1547. return _getPrototypeOf(o);
  1548. }
  1549. function _setPrototypeOf(o, p) {
  1550. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1551. o.__proto__ = p;
  1552. return o;
  1553. };
  1554. return _setPrototypeOf(o, p);
  1555. }
  1556. function isNativeReflectConstruct() {
  1557. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  1558. if (Reflect.construct.sham) return false;
  1559. if (typeof Proxy === "function") return true;
  1560. try {
  1561. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  1562. return true;
  1563. } catch (e) {
  1564. return false;
  1565. }
  1566. }
  1567. function _construct(Parent, args, Class) {
  1568. if (isNativeReflectConstruct()) {
  1569. _construct = Reflect.construct;
  1570. } else {
  1571. _construct = function _construct(Parent, args, Class) {
  1572. var a = [null];
  1573. a.push.apply(a, args);
  1574. var Constructor = Function.bind.apply(Parent, a);
  1575. var instance = new Constructor();
  1576. if (Class) _setPrototypeOf(instance, Class.prototype);
  1577. return instance;
  1578. };
  1579. }
  1580. return _construct.apply(null, arguments);
  1581. }
  1582. function _wrapNativeSuper(Class) {
  1583. var _cache = typeof Map === "function" ? new Map() : undefined;
  1584. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  1585. if (Class === null) return null;
  1586. if (typeof Class !== "function") {
  1587. throw new TypeError("Super expression must either be null or a function");
  1588. }
  1589. if (typeof _cache !== "undefined") {
  1590. if (_cache.has(Class)) return _cache.get(Class);
  1591. _cache.set(Class, Wrapper);
  1592. }
  1593. function Wrapper() {
  1594. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  1595. }
  1596. Wrapper.prototype = Object.create(Class.prototype, {
  1597. constructor: {
  1598. value: Wrapper,
  1599. enumerable: false,
  1600. writable: true,
  1601. configurable: true
  1602. }
  1603. });
  1604. return _setPrototypeOf(Wrapper, Class);
  1605. };
  1606. return _wrapNativeSuper(Class);
  1607. }
  1608. function _assertThisInitialized(self) {
  1609. if (self === void 0) {
  1610. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1611. }
  1612. return self;
  1613. }
  1614. function _possibleConstructorReturn(self, call) {
  1615. if (call && (typeof call === "object" || typeof call === "function")) {
  1616. return call;
  1617. }
  1618. return _assertThisInitialized(self);
  1619. }
  1620. function _slicedToArray(arr, i) {
  1621. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
  1622. }
  1623. function _arrayWithHoles(arr) {
  1624. if (Array.isArray(arr)) return arr;
  1625. }
  1626. function _iterableToArrayLimit(arr, i) {
  1627. var _arr = [];
  1628. var _n = true;
  1629. var _d = false;
  1630. var _e = undefined;
  1631. try {
  1632. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  1633. _arr.push(_s.value);
  1634. if (i && _arr.length === i) break;
  1635. }
  1636. } catch (err) {
  1637. _d = true;
  1638. _e = err;
  1639. } finally {
  1640. try {
  1641. if (!_n && _i["return"] != null) _i["return"]();
  1642. } finally {
  1643. if (_d) throw _e;
  1644. }
  1645. }
  1646. return _arr;
  1647. }
  1648. function _nonIterableRest() {
  1649. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  1650. }
  1651. var ConfigError =
  1652. /*#__PURE__*/
  1653. function (_Error) {
  1654. _inherits(ConfigError, _Error);
  1655. function ConfigError() {
  1656. _classCallCheck(this, ConfigError);
  1657. return _possibleConstructorReturn(this, _getPrototypeOf(ConfigError).apply(this, arguments));
  1658. }
  1659. return ConfigError;
  1660. }(_wrapNativeSuper(Error));
  1661. var DebugError =
  1662. /*#__PURE__*/
  1663. function (_Error2) {
  1664. _inherits(DebugError, _Error2);
  1665. function DebugError() {
  1666. _classCallCheck(this, DebugError);
  1667. return _possibleConstructorReturn(this, _getPrototypeOf(DebugError).apply(this, arguments));
  1668. }
  1669. return DebugError;
  1670. }(_wrapNativeSuper(Error));
  1671. var UndefinedParserError$1 =
  1672. /*#__PURE__*/
  1673. function (_Error3) {
  1674. _inherits(UndefinedParserError, _Error3);
  1675. function UndefinedParserError() {
  1676. _classCallCheck(this, UndefinedParserError);
  1677. return _possibleConstructorReturn(this, _getPrototypeOf(UndefinedParserError).apply(this, arguments));
  1678. }
  1679. return UndefinedParserError;
  1680. }(_wrapNativeSuper(Error));
  1681. var errors = {
  1682. ConfigError,
  1683. DebugError,
  1684. UndefinedParserError: UndefinedParserError$1
  1685. };
  1686. var semver = createCommonjsModule(function (module, exports) {
  1687. exports = module.exports = SemVer; // The debug function is excluded entirely from the minified version.
  1688. /* nomin */
  1689. var debug;
  1690. /* nomin */
  1691. if (typeof process === 'object' &&
  1692. /* nomin */
  1693. process.env &&
  1694. /* nomin */
  1695. process.env.NODE_DEBUG &&
  1696. /* nomin */
  1697. /\bsemver\b/i.test(process.env.NODE_DEBUG))
  1698. /* nomin */
  1699. debug = function debug() {
  1700. /* nomin */
  1701. var args = Array.prototype.slice.call(arguments, 0);
  1702. /* nomin */
  1703. args.unshift('SEMVER');
  1704. /* nomin */
  1705. console.log.apply(console, args);
  1706. /* nomin */
  1707. };
  1708. /* nomin */
  1709. else
  1710. /* nomin */
  1711. debug = function debug() {}; // Note: this is the semver.org version of the spec that it implements
  1712. // Not necessarily the package version of this code.
  1713. exports.SEMVER_SPEC_VERSION = '2.0.0';
  1714. var MAX_LENGTH = 256;
  1715. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // The actual regexps go on exports.re
  1716. var re = exports.re = [];
  1717. var src = exports.src = [];
  1718. var R = 0; // The following Regular Expressions can be used for tokenizing,
  1719. // validating, and parsing SemVer version strings.
  1720. // ## Numeric Identifier
  1721. // A single `0`, or a non-zero digit followed by zero or more digits.
  1722. var NUMERICIDENTIFIER = R++;
  1723. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  1724. var NUMERICIDENTIFIERLOOSE = R++;
  1725. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
  1726. // Zero or more digits, followed by a letter or hyphen, and then zero or
  1727. // more letters, digits, or hyphens.
  1728. var NONNUMERICIDENTIFIER = R++;
  1729. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
  1730. // Three dot-separated numeric identifiers.
  1731. var MAINVERSION = R++;
  1732. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')';
  1733. var MAINVERSIONLOOSE = R++;
  1734. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
  1735. // A numeric identifier, or a non-numeric identifier.
  1736. var PRERELEASEIDENTIFIER = R++;
  1737. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + '|' + src[NONNUMERICIDENTIFIER] + ')';
  1738. var PRERELEASEIDENTIFIERLOOSE = R++;
  1739. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + '|' + src[NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
  1740. // Hyphen, followed by one or more dot-separated pre-release version
  1741. // identifiers.
  1742. var PRERELEASE = R++;
  1743. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  1744. var PRERELEASELOOSE = R++;
  1745. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
  1746. // Any combination of digits, letters, or hyphens.
  1747. var BUILDIDENTIFIER = R++;
  1748. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
  1749. // Plus sign, followed by one or more period-separated build metadata
  1750. // identifiers.
  1751. var BUILD = R++;
  1752. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'; // ## Full Version String
  1753. // A main version, followed optionally by a pre-release version and
  1754. // build metadata.
  1755. // Note that the only major, minor, patch, and pre-release sections of
  1756. // the version string are capturing groups. The build metadata is not a
  1757. // capturing group, because it should not ever be used in version
  1758. // comparison.
  1759. var FULL = R++;
  1760. var FULLPLAIN = 'v?' + src[MAINVERSION] + src[PRERELEASE] + '?' + src[BUILD] + '?';
  1761. src[FULL] = '^' + FULLPLAIN + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  1762. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  1763. // common in the npm registry.
  1764. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + src[PRERELEASELOOSE] + '?' + src[BUILD] + '?';
  1765. var LOOSE = R++;
  1766. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  1767. var GTLT = R++;
  1768. src[GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
  1769. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  1770. // Only the first item is strictly required.
  1771. var XRANGEIDENTIFIERLOOSE = R++;
  1772. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  1773. var XRANGEIDENTIFIER = R++;
  1774. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  1775. var XRANGEPLAIN = R++;
  1776. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:' + src[PRERELEASE] + ')?' + src[BUILD] + '?' + ')?)?';
  1777. var XRANGEPLAINLOOSE = R++;
  1778. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[PRERELEASELOOSE] + ')?' + src[BUILD] + '?' + ')?)?';
  1779. var XRANGE = R++;
  1780. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  1781. var XRANGELOOSE = R++;
  1782. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'; // Tilde ranges.
  1783. // Meaning is "reasonably at or greater than"
  1784. var LONETILDE = R++;
  1785. src[LONETILDE] = '(?:~>?)';
  1786. var TILDETRIM = R++;
  1787. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  1788. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  1789. var tildeTrimReplace = '$1~';
  1790. var TILDE = R++;
  1791. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  1792. var TILDELOOSE = R++;
  1793. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'; // Caret ranges.
  1794. // Meaning is "at least and backwards compatible with"
  1795. var LONECARET = R++;
  1796. src[LONECARET] = '(?:\\^)';
  1797. var CARETTRIM = R++;
  1798. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  1799. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  1800. var caretTrimReplace = '$1^';
  1801. var CARET = R++;
  1802. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  1803. var CARETLOOSE = R++;
  1804. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
  1805. var COMPARATORLOOSE = R++;
  1806. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  1807. var COMPARATOR = R++;
  1808. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
  1809. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  1810. var COMPARATORTRIM = R++;
  1811. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'; // this one has to use the /g flag
  1812. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  1813. var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  1814. // Note that these all use the loose form, because they'll be
  1815. // checked against either the strict or loose comparator form
  1816. // later.
  1817. var HYPHENRANGE = R++;
  1818. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAIN] + ')' + '\\s*$';
  1819. var HYPHENRANGELOOSE = R++;
  1820. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
  1821. var STAR = R++;
  1822. src[STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
  1823. // All are flag-free, unless they were created above with a flag.
  1824. for (var i = 0; i < R; i++) {
  1825. debug(i, src[i]);
  1826. if (!re[i]) re[i] = new RegExp(src[i]);
  1827. }
  1828. exports.parse = parse;
  1829. function parse(version, loose) {
  1830. if (version instanceof SemVer) return version;
  1831. if (typeof version !== 'string') return null;
  1832. if (version.length > MAX_LENGTH) return null;
  1833. var r = loose ? re[LOOSE] : re[FULL];
  1834. if (!r.test(version)) return null;
  1835. try {
  1836. return new SemVer(version, loose);
  1837. } catch (er) {
  1838. return null;
  1839. }
  1840. }
  1841. exports.valid = valid;
  1842. function valid(version, loose) {
  1843. var v = parse(version, loose);
  1844. return v ? v.version : null;
  1845. }
  1846. exports.clean = clean;
  1847. function clean(version, loose) {
  1848. var s = parse(version.trim().replace(/^[=v]+/, ''), loose);
  1849. return s ? s.version : null;
  1850. }
  1851. exports.SemVer = SemVer;
  1852. function SemVer(version, loose) {
  1853. if (version instanceof SemVer) {
  1854. if (version.loose === loose) return version;else version = version.version;
  1855. } else if (typeof version !== 'string') {
  1856. throw new TypeError('Invalid Version: ' + version);
  1857. }
  1858. if (version.length > MAX_LENGTH) throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
  1859. if (!(this instanceof SemVer)) return new SemVer(version, loose);
  1860. debug('SemVer', version, loose);
  1861. this.loose = loose;
  1862. var m = version.trim().match(loose ? re[LOOSE] : re[FULL]);
  1863. if (!m) throw new TypeError('Invalid Version: ' + version);
  1864. this.raw = version; // these are actually numbers
  1865. this.major = +m[1];
  1866. this.minor = +m[2];
  1867. this.patch = +m[3];
  1868. if (this.major > MAX_SAFE_INTEGER || this.major < 0) throw new TypeError('Invalid major version');
  1869. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) throw new TypeError('Invalid minor version');
  1870. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) throw new TypeError('Invalid patch version'); // numberify any prerelease numeric ids
  1871. if (!m[4]) this.prerelease = [];else this.prerelease = m[4].split('.').map(function (id) {
  1872. if (/^[0-9]+$/.test(id)) {
  1873. var num = +id;
  1874. if (num >= 0 && num < MAX_SAFE_INTEGER) return num;
  1875. }
  1876. return id;
  1877. });
  1878. this.build = m[5] ? m[5].split('.') : [];
  1879. this.format();
  1880. }
  1881. SemVer.prototype.format = function () {
  1882. this.version = this.major + '.' + this.minor + '.' + this.patch;
  1883. if (this.prerelease.length) this.version += '-' + this.prerelease.join('.');
  1884. return this.version;
  1885. };
  1886. SemVer.prototype.toString = function () {
  1887. return this.version;
  1888. };
  1889. SemVer.prototype.compare = function (other) {
  1890. debug('SemVer.compare', this.version, this.loose, other);
  1891. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose);
  1892. return this.compareMain(other) || this.comparePre(other);
  1893. };
  1894. SemVer.prototype.compareMain = function (other) {
  1895. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose);
  1896. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  1897. };
  1898. SemVer.prototype.comparePre = function (other) {
  1899. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose); // NOT having a prerelease is > having one
  1900. 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;
  1901. var i = 0;
  1902. do {
  1903. var a = this.prerelease[i];
  1904. var b = other.prerelease[i];
  1905. debug('prerelease compare', i, a, b);
  1906. 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);
  1907. } while (++i);
  1908. }; // preminor will bump the version up to the next minor release, and immediately
  1909. // down to pre-release. premajor and prepatch work the same way.
  1910. SemVer.prototype.inc = function (release, identifier) {
  1911. switch (release) {
  1912. case 'premajor':
  1913. this.prerelease.length = 0;
  1914. this.patch = 0;
  1915. this.minor = 0;
  1916. this.major++;
  1917. this.inc('pre', identifier);
  1918. break;
  1919. case 'preminor':
  1920. this.prerelease.length = 0;
  1921. this.patch = 0;
  1922. this.minor++;
  1923. this.inc('pre', identifier);
  1924. break;
  1925. case 'prepatch':
  1926. // If this is already a prerelease, it will bump to the next version
  1927. // drop any prereleases that might already exist, since they are not
  1928. // relevant at this point.
  1929. this.prerelease.length = 0;
  1930. this.inc('patch', identifier);
  1931. this.inc('pre', identifier);
  1932. break;
  1933. // If the input is a non-prerelease version, this acts the same as
  1934. // prepatch.
  1935. case 'prerelease':
  1936. if (this.prerelease.length === 0) this.inc('patch', identifier);
  1937. this.inc('pre', identifier);
  1938. break;
  1939. case 'major':
  1940. // If this is a pre-major version, bump up to the same major version.
  1941. // Otherwise increment major.
  1942. // 1.0.0-5 bumps to 1.0.0
  1943. // 1.1.0 bumps to 2.0.0
  1944. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) this.major++;
  1945. this.minor = 0;
  1946. this.patch = 0;
  1947. this.prerelease = [];
  1948. break;
  1949. case 'minor':
  1950. // If this is a pre-minor version, bump up to the same minor version.
  1951. // Otherwise increment minor.
  1952. // 1.2.0-5 bumps to 1.2.0
  1953. // 1.2.1 bumps to 1.3.0
  1954. if (this.patch !== 0 || this.prerelease.length === 0) this.minor++;
  1955. this.patch = 0;
  1956. this.prerelease = [];
  1957. break;
  1958. case 'patch':
  1959. // If this is not a pre-release version, it will increment the patch.
  1960. // If it is a pre-release it will bump up to the same patch version.
  1961. // 1.2.0-5 patches to 1.2.0
  1962. // 1.2.0 patches to 1.2.1
  1963. if (this.prerelease.length === 0) this.patch++;
  1964. this.prerelease = [];
  1965. break;
  1966. // This probably shouldn't be used publicly.
  1967. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  1968. case 'pre':
  1969. if (this.prerelease.length === 0) this.prerelease = [0];else {
  1970. var i = this.prerelease.length;
  1971. while (--i >= 0) {
  1972. if (typeof this.prerelease[i] === 'number') {
  1973. this.prerelease[i]++;
  1974. i = -2;
  1975. }
  1976. }
  1977. if (i === -1) // didn't increment anything
  1978. this.prerelease.push(0);
  1979. }
  1980. if (identifier) {
  1981. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  1982. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  1983. if (this.prerelease[0] === identifier) {
  1984. if (isNaN(this.prerelease[1])) this.prerelease = [identifier, 0];
  1985. } else this.prerelease = [identifier, 0];
  1986. }
  1987. break;
  1988. default:
  1989. throw new Error('invalid increment argument: ' + release);
  1990. }
  1991. this.format();
  1992. this.raw = this.version;
  1993. return this;
  1994. };
  1995. exports.inc = inc;
  1996. function inc(version, release, loose, identifier) {
  1997. if (typeof loose === 'string') {
  1998. identifier = loose;
  1999. loose = undefined;
  2000. }
  2001. try {
  2002. return new SemVer(version, loose).inc(release, identifier).version;
  2003. } catch (er) {
  2004. return null;
  2005. }
  2006. }
  2007. exports.diff = diff;
  2008. function diff(version1, version2) {
  2009. if (eq(version1, version2)) {
  2010. return null;
  2011. } else {
  2012. var v1 = parse(version1);
  2013. var v2 = parse(version2);
  2014. if (v1.prerelease.length || v2.prerelease.length) {
  2015. for (var key in v1) {
  2016. if (key === 'major' || key === 'minor' || key === 'patch') {
  2017. if (v1[key] !== v2[key]) {
  2018. return 'pre' + key;
  2019. }
  2020. }
  2021. }
  2022. return 'prerelease';
  2023. }
  2024. for (var key in v1) {
  2025. if (key === 'major' || key === 'minor' || key === 'patch') {
  2026. if (v1[key] !== v2[key]) {
  2027. return key;
  2028. }
  2029. }
  2030. }
  2031. }
  2032. }
  2033. exports.compareIdentifiers = compareIdentifiers;
  2034. var numeric = /^[0-9]+$/;
  2035. function compareIdentifiers(a, b) {
  2036. var anum = numeric.test(a);
  2037. var bnum = numeric.test(b);
  2038. if (anum && bnum) {
  2039. a = +a;
  2040. b = +b;
  2041. }
  2042. return anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : a > b ? 1 : 0;
  2043. }
  2044. exports.rcompareIdentifiers = rcompareIdentifiers;
  2045. function rcompareIdentifiers(a, b) {
  2046. return compareIdentifiers(b, a);
  2047. }
  2048. exports.major = major;
  2049. function major(a, loose) {
  2050. return new SemVer(a, loose).major;
  2051. }
  2052. exports.minor = minor;
  2053. function minor(a, loose) {
  2054. return new SemVer(a, loose).minor;
  2055. }
  2056. exports.patch = patch;
  2057. function patch(a, loose) {
  2058. return new SemVer(a, loose).patch;
  2059. }
  2060. exports.compare = compare;
  2061. function compare(a, b, loose) {
  2062. return new SemVer(a, loose).compare(new SemVer(b, loose));
  2063. }
  2064. exports.compareLoose = compareLoose;
  2065. function compareLoose(a, b) {
  2066. return compare(a, b, true);
  2067. }
  2068. exports.rcompare = rcompare;
  2069. function rcompare(a, b, loose) {
  2070. return compare(b, a, loose);
  2071. }
  2072. exports.sort = sort;
  2073. function sort(list, loose) {
  2074. return list.sort(function (a, b) {
  2075. return exports.compare(a, b, loose);
  2076. });
  2077. }
  2078. exports.rsort = rsort;
  2079. function rsort(list, loose) {
  2080. return list.sort(function (a, b) {
  2081. return exports.rcompare(a, b, loose);
  2082. });
  2083. }
  2084. exports.gt = gt;
  2085. function gt(a, b, loose) {
  2086. return compare(a, b, loose) > 0;
  2087. }
  2088. exports.lt = lt;
  2089. function lt(a, b, loose) {
  2090. return compare(a, b, loose) < 0;
  2091. }
  2092. exports.eq = eq;
  2093. function eq(a, b, loose) {
  2094. return compare(a, b, loose) === 0;
  2095. }
  2096. exports.neq = neq;
  2097. function neq(a, b, loose) {
  2098. return compare(a, b, loose) !== 0;
  2099. }
  2100. exports.gte = gte;
  2101. function gte(a, b, loose) {
  2102. return compare(a, b, loose) >= 0;
  2103. }
  2104. exports.lte = lte;
  2105. function lte(a, b, loose) {
  2106. return compare(a, b, loose) <= 0;
  2107. }
  2108. exports.cmp = cmp;
  2109. function cmp(a, op, b, loose) {
  2110. var ret;
  2111. switch (op) {
  2112. case '===':
  2113. if (typeof a === 'object') a = a.version;
  2114. if (typeof b === 'object') b = b.version;
  2115. ret = a === b;
  2116. break;
  2117. case '!==':
  2118. if (typeof a === 'object') a = a.version;
  2119. if (typeof b === 'object') b = b.version;
  2120. ret = a !== b;
  2121. break;
  2122. case '':
  2123. case '=':
  2124. case '==':
  2125. ret = eq(a, b, loose);
  2126. break;
  2127. case '!=':
  2128. ret = neq(a, b, loose);
  2129. break;
  2130. case '>':
  2131. ret = gt(a, b, loose);
  2132. break;
  2133. case '>=':
  2134. ret = gte(a, b, loose);
  2135. break;
  2136. case '<':
  2137. ret = lt(a, b, loose);
  2138. break;
  2139. case '<=':
  2140. ret = lte(a, b, loose);
  2141. break;
  2142. default:
  2143. throw new TypeError('Invalid operator: ' + op);
  2144. }
  2145. return ret;
  2146. }
  2147. exports.Comparator = Comparator;
  2148. function Comparator(comp, loose) {
  2149. if (comp instanceof Comparator) {
  2150. if (comp.loose === loose) return comp;else comp = comp.value;
  2151. }
  2152. if (!(this instanceof Comparator)) return new Comparator(comp, loose);
  2153. debug('comparator', comp, loose);
  2154. this.loose = loose;
  2155. this.parse(comp);
  2156. if (this.semver === ANY) this.value = '';else this.value = this.operator + this.semver.version;
  2157. debug('comp', this);
  2158. }
  2159. var ANY = {};
  2160. Comparator.prototype.parse = function (comp) {
  2161. var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  2162. var m = comp.match(r);
  2163. if (!m) throw new TypeError('Invalid comparator: ' + comp);
  2164. this.operator = m[1];
  2165. if (this.operator === '=') this.operator = ''; // if it literally is just '>' or '' then allow anything.
  2166. if (!m[2]) this.semver = ANY;else this.semver = new SemVer(m[2], this.loose);
  2167. };
  2168. Comparator.prototype.toString = function () {
  2169. return this.value;
  2170. };
  2171. Comparator.prototype.test = function (version) {
  2172. debug('Comparator.test', version, this.loose);
  2173. if (this.semver === ANY) return true;
  2174. if (typeof version === 'string') version = new SemVer(version, this.loose);
  2175. return cmp(version, this.operator, this.semver, this.loose);
  2176. };
  2177. Comparator.prototype.intersects = function (comp, loose) {
  2178. if (!(comp instanceof Comparator)) {
  2179. throw new TypeError('a Comparator is required');
  2180. }
  2181. var rangeTmp;
  2182. if (this.operator === '') {
  2183. rangeTmp = new Range(comp.value, loose);
  2184. return satisfies(this.value, rangeTmp, loose);
  2185. } else if (comp.operator === '') {
  2186. rangeTmp = new Range(this.value, loose);
  2187. return satisfies(comp.semver, rangeTmp, loose);
  2188. }
  2189. var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
  2190. var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
  2191. var sameSemVer = this.semver.version === comp.semver.version;
  2192. var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
  2193. var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, loose) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
  2194. var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, loose) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
  2195. return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  2196. };
  2197. exports.Range = Range;
  2198. function Range(range, loose) {
  2199. if (range instanceof Range) {
  2200. if (range.loose === loose) {
  2201. return range;
  2202. } else {
  2203. return new Range(range.raw, loose);
  2204. }
  2205. }
  2206. if (range instanceof Comparator) {
  2207. return new Range(range.value, loose);
  2208. }
  2209. if (!(this instanceof Range)) return new Range(range, loose);
  2210. this.loose = loose; // First, split based on boolean or ||
  2211. this.raw = range;
  2212. this.set = range.split(/\s*\|\|\s*/).map(function (range) {
  2213. return this.parseRange(range.trim());
  2214. }, this).filter(function (c) {
  2215. // throw out any that are not relevant for whatever reason
  2216. return c.length;
  2217. });
  2218. if (!this.set.length) {
  2219. throw new TypeError('Invalid SemVer Range: ' + range);
  2220. }
  2221. this.format();
  2222. }
  2223. Range.prototype.format = function () {
  2224. this.range = this.set.map(function (comps) {
  2225. return comps.join(' ').trim();
  2226. }).join('||').trim();
  2227. return this.range;
  2228. };
  2229. Range.prototype.toString = function () {
  2230. return this.range;
  2231. };
  2232. Range.prototype.parseRange = function (range) {
  2233. var loose = this.loose;
  2234. range = range.trim();
  2235. debug('range', range, loose); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  2236. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  2237. range = range.replace(hr, hyphenReplace);
  2238. debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  2239. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  2240. debug('comparator trim', range, re[COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
  2241. range = range.replace(re[TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
  2242. range = range.replace(re[CARETTRIM], caretTrimReplace); // normalize spaces
  2243. range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
  2244. // ready to be split into comparators.
  2245. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  2246. var set = range.split(' ').map(function (comp) {
  2247. return parseComparator(comp, loose);
  2248. }).join(' ').split(/\s+/);
  2249. if (this.loose) {
  2250. // in loose mode, throw out any that are not valid comparators
  2251. set = set.filter(function (comp) {
  2252. return !!comp.match(compRe);
  2253. });
  2254. }
  2255. set = set.map(function (comp) {
  2256. return new Comparator(comp, loose);
  2257. });
  2258. return set;
  2259. };
  2260. Range.prototype.intersects = function (range, loose) {
  2261. if (!(range instanceof Range)) {
  2262. throw new TypeError('a Range is required');
  2263. }
  2264. return this.set.some(function (thisComparators) {
  2265. return thisComparators.every(function (thisComparator) {
  2266. return range.set.some(function (rangeComparators) {
  2267. return rangeComparators.every(function (rangeComparator) {
  2268. return thisComparator.intersects(rangeComparator, loose);
  2269. });
  2270. });
  2271. });
  2272. });
  2273. }; // Mostly just for testing and legacy API reasons
  2274. exports.toComparators = toComparators;
  2275. function toComparators(range, loose) {
  2276. return new Range(range, loose).set.map(function (comp) {
  2277. return comp.map(function (c) {
  2278. return c.value;
  2279. }).join(' ').trim().split(' ');
  2280. });
  2281. } // comprised of xranges, tildes, stars, and gtlt's at this point.
  2282. // already replaced the hyphen ranges
  2283. // turn into a set of JUST comparators.
  2284. function parseComparator(comp, loose) {
  2285. debug('comp', comp);
  2286. comp = replaceCarets(comp, loose);
  2287. debug('caret', comp);
  2288. comp = replaceTildes(comp, loose);
  2289. debug('tildes', comp);
  2290. comp = replaceXRanges(comp, loose);
  2291. debug('xrange', comp);
  2292. comp = replaceStars(comp, loose);
  2293. debug('stars', comp);
  2294. return comp;
  2295. }
  2296. function isX(id) {
  2297. return !id || id.toLowerCase() === 'x' || id === '*';
  2298. } // ~, ~> --> * (any, kinda silly)
  2299. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  2300. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  2301. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  2302. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  2303. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  2304. function replaceTildes(comp, loose) {
  2305. return comp.trim().split(/\s+/).map(function (comp) {
  2306. return replaceTilde(comp, loose);
  2307. }).join(' ');
  2308. }
  2309. function replaceTilde(comp, loose) {
  2310. var r = loose ? re[TILDELOOSE] : re[TILDE];
  2311. return comp.replace(r, function (_, M, m, p, pr) {
  2312. debug('tilde', comp, _, M, m, p, pr);
  2313. var ret;
  2314. 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
  2315. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else if (pr) {
  2316. debug('replaceTilde pr', pr);
  2317. if (pr.charAt(0) !== '-') pr = '-' + pr;
  2318. ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  2319. } else // ~1.2.3 == >=1.2.3 <1.3.0
  2320. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  2321. debug('tilde return', ret);
  2322. return ret;
  2323. });
  2324. } // ^ --> * (any, kinda silly)
  2325. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  2326. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  2327. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  2328. // ^1.2.3 --> >=1.2.3 <2.0.0
  2329. // ^1.2.0 --> >=1.2.0 <2.0.0
  2330. function replaceCarets(comp, loose) {
  2331. return comp.trim().split(/\s+/).map(function (comp) {
  2332. return replaceCaret(comp, loose);
  2333. }).join(' ');
  2334. }
  2335. function replaceCaret(comp, loose) {
  2336. debug('caret', comp, loose);
  2337. var r = loose ? re[CARETLOOSE] : re[CARET];
  2338. return comp.replace(r, function (_, M, m, p, pr) {
  2339. debug('caret', comp, _, M, m, p, pr);
  2340. var ret;
  2341. if (isX(M)) ret = '';else if (isX(m)) ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';else if (isX(p)) {
  2342. if (M === '0') ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  2343. } else if (pr) {
  2344. debug('replaceCaret pr', pr);
  2345. if (pr.charAt(0) !== '-') pr = '-' + pr;
  2346. if (M === '0') {
  2347. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  2348. } else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + (+M + 1) + '.0.0';
  2349. } else {
  2350. debug('no pr');
  2351. if (M === '0') {
  2352. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  2353. } else ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
  2354. }
  2355. debug('caret return', ret);
  2356. return ret;
  2357. });
  2358. }
  2359. function replaceXRanges(comp, loose) {
  2360. debug('replaceXRanges', comp, loose);
  2361. return comp.split(/\s+/).map(function (comp) {
  2362. return replaceXRange(comp, loose);
  2363. }).join(' ');
  2364. }
  2365. function replaceXRange(comp, loose) {
  2366. comp = comp.trim();
  2367. var r = loose ? re[XRANGELOOSE] : re[XRANGE];
  2368. return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
  2369. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  2370. var xM = isX(M);
  2371. var xm = xM || isX(m);
  2372. var xp = xm || isX(p);
  2373. var anyX = xp;
  2374. if (gtlt === '=' && anyX) gtlt = '';
  2375. if (xM) {
  2376. if (gtlt === '>' || gtlt === '<') {
  2377. // nothing is allowed
  2378. ret = '<0.0.0';
  2379. } else {
  2380. // nothing is forbidden
  2381. ret = '*';
  2382. }
  2383. } else if (gtlt && anyX) {
  2384. // replace X with 0
  2385. if (xm) m = 0;
  2386. if (xp) p = 0;
  2387. if (gtlt === '>') {
  2388. // >1 => >=2.0.0
  2389. // >1.2 => >=1.3.0
  2390. // >1.2.3 => >= 1.2.4
  2391. gtlt = '>=';
  2392. if (xm) {
  2393. M = +M + 1;
  2394. m = 0;
  2395. p = 0;
  2396. } else if (xp) {
  2397. m = +m + 1;
  2398. p = 0;
  2399. }
  2400. } else if (gtlt === '<=') {
  2401. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  2402. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  2403. gtlt = '<';
  2404. if (xm) M = +M + 1;else m = +m + 1;
  2405. }
  2406. ret = gtlt + M + '.' + m + '.' + p;
  2407. } else if (xm) {
  2408. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  2409. } else if (xp) {
  2410. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  2411. }
  2412. debug('xRange return', ret);
  2413. return ret;
  2414. });
  2415. } // Because * is AND-ed with everything else in the comparator,
  2416. // and '' means "any version", just remove the *s entirely.
  2417. function replaceStars(comp, loose) {
  2418. debug('replaceStars', comp, loose); // Looseness is ignored here. star is always as loose as it gets!
  2419. return comp.trim().replace(re[STAR], '');
  2420. } // This function is passed to string.replace(re[HYPHENRANGE])
  2421. // M, m, patch, prerelease, build
  2422. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  2423. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  2424. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  2425. function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
  2426. if (isX(fM)) from = '';else if (isX(fm)) from = '>=' + fM + '.0.0';else if (isX(fp)) from = '>=' + fM + '.' + fm + '.0';else from = '>=' + from;
  2427. 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;
  2428. return (from + ' ' + to).trim();
  2429. } // if ANY of the sets match ALL of its comparators, then pass
  2430. Range.prototype.test = function (version) {
  2431. if (!version) return false;
  2432. if (typeof version === 'string') version = new SemVer(version, this.loose);
  2433. for (var i = 0; i < this.set.length; i++) {
  2434. if (testSet(this.set[i], version)) return true;
  2435. }
  2436. return false;
  2437. };
  2438. function testSet(set, version) {
  2439. for (var i = 0; i < set.length; i++) {
  2440. if (!set[i].test(version)) return false;
  2441. }
  2442. if (version.prerelease.length) {
  2443. // Find the set of versions that are allowed to have prereleases
  2444. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  2445. // That should allow `1.2.3-pr.2` to pass.
  2446. // However, `1.2.4-alpha.notready` should NOT be allowed,
  2447. // even though it's within the range set by the comparators.
  2448. for (var i = 0; i < set.length; i++) {
  2449. debug(set[i].semver);
  2450. if (set[i].semver === ANY) continue;
  2451. if (set[i].semver.prerelease.length > 0) {
  2452. var allowed = set[i].semver;
  2453. if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) return true;
  2454. }
  2455. } // Version has a -pre, but it's not one of the ones we like.
  2456. return false;
  2457. }
  2458. return true;
  2459. }
  2460. exports.satisfies = satisfies;
  2461. function satisfies(version, range, loose) {
  2462. try {
  2463. range = new Range(range, loose);
  2464. } catch (er) {
  2465. return false;
  2466. }
  2467. return range.test(version);
  2468. }
  2469. exports.maxSatisfying = maxSatisfying;
  2470. function maxSatisfying(versions, range, loose) {
  2471. var max = null;
  2472. var maxSV = null;
  2473. try {
  2474. var rangeObj = new Range(range, loose);
  2475. } catch (er) {
  2476. return null;
  2477. }
  2478. versions.forEach(function (v) {
  2479. if (rangeObj.test(v)) {
  2480. // satisfies(v, range, loose)
  2481. if (!max || maxSV.compare(v) === -1) {
  2482. // compare(max, v, true)
  2483. max = v;
  2484. maxSV = new SemVer(max, loose);
  2485. }
  2486. }
  2487. });
  2488. return max;
  2489. }
  2490. exports.minSatisfying = minSatisfying;
  2491. function minSatisfying(versions, range, loose) {
  2492. var min = null;
  2493. var minSV = null;
  2494. try {
  2495. var rangeObj = new Range(range, loose);
  2496. } catch (er) {
  2497. return null;
  2498. }
  2499. versions.forEach(function (v) {
  2500. if (rangeObj.test(v)) {
  2501. // satisfies(v, range, loose)
  2502. if (!min || minSV.compare(v) === 1) {
  2503. // compare(min, v, true)
  2504. min = v;
  2505. minSV = new SemVer(min, loose);
  2506. }
  2507. }
  2508. });
  2509. return min;
  2510. }
  2511. exports.validRange = validRange;
  2512. function validRange(range, loose) {
  2513. try {
  2514. // Return '*' instead of '' so that truthiness works.
  2515. // This will throw if it's invalid anyway
  2516. return new Range(range, loose).range || '*';
  2517. } catch (er) {
  2518. return null;
  2519. }
  2520. } // Determine if version is less than all the versions possible in the range
  2521. exports.ltr = ltr;
  2522. function ltr(version, range, loose) {
  2523. return outside(version, range, '<', loose);
  2524. } // Determine if version is greater than all the versions possible in the range.
  2525. exports.gtr = gtr;
  2526. function gtr(version, range, loose) {
  2527. return outside(version, range, '>', loose);
  2528. }
  2529. exports.outside = outside;
  2530. function outside(version, range, hilo, loose) {
  2531. version = new SemVer(version, loose);
  2532. range = new Range(range, loose);
  2533. var gtfn, ltefn, ltfn, comp, ecomp;
  2534. switch (hilo) {
  2535. case '>':
  2536. gtfn = gt;
  2537. ltefn = lte;
  2538. ltfn = lt;
  2539. comp = '>';
  2540. ecomp = '>=';
  2541. break;
  2542. case '<':
  2543. gtfn = lt;
  2544. ltefn = gte;
  2545. ltfn = gt;
  2546. comp = '<';
  2547. ecomp = '<=';
  2548. break;
  2549. default:
  2550. throw new TypeError('Must provide a hilo val of "<" or ">"');
  2551. } // If it satisifes the range it is not outside
  2552. if (satisfies(version, range, loose)) {
  2553. return false;
  2554. } // From now on, variable terms are as if we're in "gtr" mode.
  2555. // but note that everything is flipped for the "ltr" function.
  2556. for (var i = 0; i < range.set.length; ++i) {
  2557. var comparators = range.set[i];
  2558. var high = null;
  2559. var low = null;
  2560. comparators.forEach(function (comparator) {
  2561. if (comparator.semver === ANY) {
  2562. comparator = new Comparator('>=0.0.0');
  2563. }
  2564. high = high || comparator;
  2565. low = low || comparator;
  2566. if (gtfn(comparator.semver, high.semver, loose)) {
  2567. high = comparator;
  2568. } else if (ltfn(comparator.semver, low.semver, loose)) {
  2569. low = comparator;
  2570. }
  2571. }); // If the edge version comparator has a operator then our version
  2572. // isn't outside it
  2573. if (high.operator === comp || high.operator === ecomp) {
  2574. return false;
  2575. } // If the lowest version comparator has an operator and our version
  2576. // is less than it then it isn't higher than the range
  2577. if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
  2578. return false;
  2579. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  2580. return false;
  2581. }
  2582. }
  2583. return true;
  2584. }
  2585. exports.prerelease = prerelease;
  2586. function prerelease(version, loose) {
  2587. var parsed = parse(version, loose);
  2588. return parsed && parsed.prerelease.length ? parsed.prerelease : null;
  2589. }
  2590. exports.intersects = intersects;
  2591. function intersects(r1, r2, loose) {
  2592. r1 = new Range(r1, loose);
  2593. r2 = new Range(r2, loose);
  2594. return r1.intersects(r2);
  2595. }
  2596. });
  2597. var arrayify = function arrayify(object, keyName) {
  2598. return Object.keys(object).reduce(function (array, key) {
  2599. return array.concat(Object.assign({
  2600. [keyName]: key
  2601. }, object[key]));
  2602. }, []);
  2603. };
  2604. var dedent_1 = createCommonjsModule(function (module) {
  2605. "use strict";
  2606. function dedent(strings) {
  2607. var raw = void 0;
  2608. if (typeof strings === "string") {
  2609. // dedent can be used as a plain function
  2610. raw = [strings];
  2611. } else {
  2612. raw = strings.raw;
  2613. } // first, perform interpolation
  2614. var result = "";
  2615. for (var i = 0; i < raw.length; i++) {
  2616. result += raw[i]. // join lines when there is a suppressed newline
  2617. replace(/\\\n[ \t]*/g, ""). // handle escaped backticks
  2618. replace(/\\`/g, "`");
  2619. if (i < (arguments.length <= 1 ? 0 : arguments.length - 1)) {
  2620. result += arguments.length <= i + 1 ? undefined : arguments[i + 1];
  2621. }
  2622. } // now strip indentation
  2623. var lines = result.split("\n");
  2624. var mindent = null;
  2625. lines.forEach(function (l) {
  2626. var m = l.match(/^(\s+)\S+/);
  2627. if (m) {
  2628. var indent = m[1].length;
  2629. if (!mindent) {
  2630. // this is the first indented line
  2631. mindent = indent;
  2632. } else {
  2633. mindent = Math.min(mindent, indent);
  2634. }
  2635. }
  2636. });
  2637. if (mindent !== null) {
  2638. result = lines.map(function (l) {
  2639. return l[0] === " " ? l.slice(mindent) : l;
  2640. }).join("\n");
  2641. } // dedent eats leading and trailing whitespace too
  2642. result = result.trim(); // handle escaped newlines at the end to ensure they don't get stripped too
  2643. return result.replace(/\\n/g, "\n");
  2644. }
  2645. {
  2646. module.exports = dedent;
  2647. }
  2648. });
  2649. var CATEGORY_CONFIG = "Config";
  2650. var CATEGORY_EDITOR = "Editor";
  2651. var CATEGORY_FORMAT = "Format";
  2652. var CATEGORY_OTHER = "Other";
  2653. var CATEGORY_OUTPUT = "Output";
  2654. var CATEGORY_GLOBAL = "Global";
  2655. var CATEGORY_SPECIAL = "Special";
  2656. /**
  2657. * @typedef {Object} OptionInfo
  2658. * @property {string} since - available since version
  2659. * @property {string} category
  2660. * @property {'int' | 'boolean' | 'choice' | 'path'} type
  2661. * @property {boolean} array - indicate it's an array of the specified type
  2662. * @property {boolean?} deprecated - deprecated since version
  2663. * @property {OptionRedirectInfo?} redirect - redirect deprecated option
  2664. * @property {string} description
  2665. * @property {string?} oppositeDescription - for `false` option
  2666. * @property {OptionValueInfo} default
  2667. * @property {OptionRangeInfo?} range - for type int
  2668. * @property {OptionChoiceInfo?} choices - for type choice
  2669. * @property {(value: any) => boolean} exception
  2670. *
  2671. * @typedef {number | boolean | string} OptionValue
  2672. * @typedef {OptionValue | [{ value: OptionValue[] }] | Array<{ since: string, value: OptionValue}>} OptionValueInfo
  2673. *
  2674. * @typedef {Object} OptionRedirectInfo
  2675. * @property {string} option
  2676. * @property {OptionValue} value
  2677. *
  2678. * @typedef {Object} OptionRangeInfo
  2679. * @property {number} start - recommended range start
  2680. * @property {number} end - recommended range end
  2681. * @property {number} step - recommended range step
  2682. *
  2683. * @typedef {Object} OptionChoiceInfo
  2684. * @property {boolean | string} value - boolean for the option that is originally boolean type
  2685. * @property {string?} description - undefined if redirect
  2686. * @property {string?} since - undefined if available since the first version of the option
  2687. * @property {string?} deprecated - deprecated since version
  2688. * @property {OptionValueInfo?} redirect - redirect deprecated value
  2689. *
  2690. * @property {string?} cliName
  2691. * @property {string?} cliCategory
  2692. * @property {string?} cliDescription
  2693. */
  2694. /** @type {{ [name: string]: OptionInfo } */
  2695. var options$2 = {
  2696. cursorOffset: {
  2697. since: "1.4.0",
  2698. category: CATEGORY_SPECIAL,
  2699. type: "int",
  2700. default: -1,
  2701. range: {
  2702. start: -1,
  2703. end: Infinity,
  2704. step: 1
  2705. },
  2706. description: dedent_1`
  2707. Print (to stderr) where a cursor at the given position would move to after formatting.
  2708. This option cannot be used with --range-start and --range-end.
  2709. `,
  2710. cliCategory: CATEGORY_EDITOR
  2711. },
  2712. filepath: {
  2713. since: "1.4.0",
  2714. category: CATEGORY_SPECIAL,
  2715. type: "path",
  2716. default: undefined,
  2717. description: "Specify the input filepath. This will be used to do parser inference.",
  2718. cliName: "stdin-filepath",
  2719. cliCategory: CATEGORY_OTHER,
  2720. cliDescription: "Path to the file to pretend that stdin comes from."
  2721. },
  2722. insertPragma: {
  2723. since: "1.8.0",
  2724. category: CATEGORY_SPECIAL,
  2725. type: "boolean",
  2726. default: false,
  2727. description: "Insert @format pragma into file's first docblock comment.",
  2728. cliCategory: CATEGORY_OTHER
  2729. },
  2730. parser: {
  2731. since: "0.0.10",
  2732. category: CATEGORY_GLOBAL,
  2733. type: "choice",
  2734. default: [{
  2735. since: "0.0.10",
  2736. value: "babylon"
  2737. }, {
  2738. since: "1.13.0",
  2739. value: undefined
  2740. }],
  2741. description: "Which parser to use.",
  2742. exception: function exception(value) {
  2743. return typeof value === "string" || typeof value === "function";
  2744. },
  2745. choices: [{
  2746. value: "flow",
  2747. description: "Flow"
  2748. }, {
  2749. value: "babylon",
  2750. description: "JavaScript"
  2751. }, {
  2752. value: "typescript",
  2753. since: "1.4.0",
  2754. description: "TypeScript"
  2755. }, {
  2756. value: "css",
  2757. since: "1.7.1",
  2758. description: "CSS"
  2759. }, {
  2760. value: "postcss",
  2761. since: "1.4.0",
  2762. description: "CSS/Less/SCSS",
  2763. deprecated: "1.7.1",
  2764. redirect: "css"
  2765. }, {
  2766. value: "less",
  2767. since: "1.7.1",
  2768. description: "Less"
  2769. }, {
  2770. value: "scss",
  2771. since: "1.7.1",
  2772. description: "SCSS"
  2773. }, {
  2774. value: "json",
  2775. since: "1.5.0",
  2776. description: "JSON"
  2777. }, {
  2778. value: "json5",
  2779. since: "1.13.0",
  2780. description: "JSON5"
  2781. }, {
  2782. value: "json-stringify",
  2783. since: "1.13.0",
  2784. description: "JSON.stringify"
  2785. }, {
  2786. value: "graphql",
  2787. since: "1.5.0",
  2788. description: "GraphQL"
  2789. }, {
  2790. value: "markdown",
  2791. since: "1.8.0",
  2792. description: "Markdown"
  2793. }, {
  2794. value: "vue",
  2795. since: "1.10.0",
  2796. description: "Vue"
  2797. }]
  2798. },
  2799. plugins: {
  2800. since: "1.10.0",
  2801. type: "path",
  2802. array: true,
  2803. default: [{
  2804. value: []
  2805. }],
  2806. category: CATEGORY_GLOBAL,
  2807. description: "Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
  2808. exception: function exception(value) {
  2809. return typeof value === "string" || typeof value === "object";
  2810. },
  2811. cliName: "plugin",
  2812. cliCategory: CATEGORY_CONFIG
  2813. },
  2814. pluginSearchDirs: {
  2815. since: "1.13.0",
  2816. type: "path",
  2817. array: true,
  2818. default: [{
  2819. value: []
  2820. }],
  2821. category: CATEGORY_GLOBAL,
  2822. description: dedent_1`
  2823. Custom directory that contains prettier plugins in node_modules subdirectory.
  2824. Overrides default behavior when plugins are searched relatively to the location of Prettier.
  2825. Multiple values are accepted.
  2826. `,
  2827. exception: function exception(value) {
  2828. return typeof value === "string" || typeof value === "object";
  2829. },
  2830. cliName: "plugin-search-dir",
  2831. cliCategory: CATEGORY_CONFIG
  2832. },
  2833. printWidth: {
  2834. since: "0.0.0",
  2835. category: CATEGORY_GLOBAL,
  2836. type: "int",
  2837. default: 80,
  2838. description: "The line length where Prettier will try wrap.",
  2839. range: {
  2840. start: 0,
  2841. end: Infinity,
  2842. step: 1
  2843. }
  2844. },
  2845. rangeEnd: {
  2846. since: "1.4.0",
  2847. category: CATEGORY_SPECIAL,
  2848. type: "int",
  2849. default: Infinity,
  2850. range: {
  2851. start: 0,
  2852. end: Infinity,
  2853. step: 1
  2854. },
  2855. description: dedent_1`
  2856. Format code ending at a given character offset (exclusive).
  2857. The range will extend forwards to the end of the selected statement.
  2858. This option cannot be used with --cursor-offset.
  2859. `,
  2860. cliCategory: CATEGORY_EDITOR
  2861. },
  2862. rangeStart: {
  2863. since: "1.4.0",
  2864. category: CATEGORY_SPECIAL,
  2865. type: "int",
  2866. default: 0,
  2867. range: {
  2868. start: 0,
  2869. end: Infinity,
  2870. step: 1
  2871. },
  2872. description: dedent_1`
  2873. Format code starting at a given character offset.
  2874. The range will extend backwards to the start of the first line containing the selected statement.
  2875. This option cannot be used with --cursor-offset.
  2876. `,
  2877. cliCategory: CATEGORY_EDITOR
  2878. },
  2879. requirePragma: {
  2880. since: "1.7.0",
  2881. category: CATEGORY_SPECIAL,
  2882. type: "boolean",
  2883. default: false,
  2884. description: dedent_1`
  2885. Require either '@prettier' or '@format' to be present in the file's first docblock comment
  2886. in order for it to be formatted.
  2887. `,
  2888. cliCategory: CATEGORY_OTHER
  2889. },
  2890. tabWidth: {
  2891. type: "int",
  2892. category: CATEGORY_GLOBAL,
  2893. default: 2,
  2894. description: "Number of spaces per indentation level.",
  2895. range: {
  2896. start: 0,
  2897. end: Infinity,
  2898. step: 1
  2899. }
  2900. },
  2901. useFlowParser: {
  2902. since: "0.0.0",
  2903. category: CATEGORY_GLOBAL,
  2904. type: "boolean",
  2905. default: false,
  2906. deprecated: "0.0.10",
  2907. description: "Use flow parser.",
  2908. redirect: {
  2909. option: "parser",
  2910. value: "flow"
  2911. },
  2912. cliName: "flow-parser"
  2913. },
  2914. useTabs: {
  2915. since: "1.0.0",
  2916. category: CATEGORY_GLOBAL,
  2917. type: "boolean",
  2918. default: false,
  2919. description: "Indent with tabs instead of spaces."
  2920. }
  2921. };
  2922. var coreOptions$1 = {
  2923. CATEGORY_CONFIG,
  2924. CATEGORY_EDITOR,
  2925. CATEGORY_FORMAT,
  2926. CATEGORY_OTHER,
  2927. CATEGORY_OUTPUT,
  2928. CATEGORY_GLOBAL,
  2929. CATEGORY_SPECIAL,
  2930. options: options$2
  2931. };
  2932. var require$$0 = ( _package$1 && _package ) || _package$1;
  2933. var currentVersion = require$$0.version;
  2934. var coreOptions = coreOptions$1.options;
  2935. function getSupportInfo$2(version, opts) {
  2936. opts = Object.assign({
  2937. plugins: [],
  2938. showUnreleased: false,
  2939. showDeprecated: false,
  2940. showInternal: false
  2941. }, opts);
  2942. if (!version) {
  2943. version = currentVersion;
  2944. }
  2945. var plugins = opts.plugins;
  2946. var options = arrayify(Object.assign(plugins.reduce(function (currentOptions, plugin) {
  2947. return Object.assign(currentOptions, plugin.options);
  2948. }, {}), coreOptions), "name").sort(function (a, b) {
  2949. return a.name === b.name ? 0 : a.name < b.name ? -1 : 1;
  2950. }).filter(filterSince).filter(filterDeprecated).map(mapDeprecated).map(mapInternal).map(function (option) {
  2951. var newOption = Object.assign({}, option);
  2952. if (Array.isArray(newOption.default)) {
  2953. newOption.default = newOption.default.length === 1 ? newOption.default[0].value : newOption.default.filter(filterSince).sort(function (info1, info2) {
  2954. return semver.compare(info2.since, info1.since);
  2955. })[0].value;
  2956. }
  2957. if (Array.isArray(newOption.choices)) {
  2958. newOption.choices = newOption.choices.filter(filterSince).filter(filterDeprecated).map(mapDeprecated);
  2959. }
  2960. return newOption;
  2961. }).map(function (option) {
  2962. var filteredPlugins = plugins.filter(function (plugin) {
  2963. return plugin.defaultOptions && plugin.defaultOptions[option.name];
  2964. });
  2965. var pluginDefaults = filteredPlugins.reduce(function (reduced, plugin) {
  2966. reduced[plugin.name] = plugin.defaultOptions[option.name];
  2967. return reduced;
  2968. }, {});
  2969. return Object.assign(option, {
  2970. pluginDefaults
  2971. });
  2972. });
  2973. var usePostCssParser = semver.lt(version, "1.7.1");
  2974. var languages = plugins.reduce(function (all, plugin) {
  2975. return all.concat(plugin.languages || []);
  2976. }, []).filter(function (language) {
  2977. return language.since ? semver.gte(version, language.since) : language.since !== null;
  2978. }).map(function (language) {
  2979. // Prevent breaking changes
  2980. if (language.name === "Markdown") {
  2981. return Object.assign({}, language, {
  2982. parsers: ["markdown"]
  2983. });
  2984. }
  2985. if (language.name === "TypeScript") {
  2986. return Object.assign({}, language, {
  2987. parsers: ["typescript"]
  2988. });
  2989. }
  2990. if (usePostCssParser && language.group === "CSS") {
  2991. return Object.assign({}, language, {
  2992. parsers: ["postcss"]
  2993. });
  2994. }
  2995. return language;
  2996. });
  2997. return {
  2998. languages,
  2999. options
  3000. };
  3001. function filterSince(object) {
  3002. return opts.showUnreleased || !("since" in object) || object.since && semver.gte(version, object.since);
  3003. }
  3004. function filterDeprecated(object) {
  3005. return opts.showDeprecated || !("deprecated" in object) || object.deprecated && semver.lt(version, object.deprecated);
  3006. }
  3007. function mapDeprecated(object) {
  3008. if (!object.deprecated || opts.showDeprecated) {
  3009. return object;
  3010. }
  3011. var newObject = Object.assign({}, object);
  3012. delete newObject.deprecated;
  3013. delete newObject.redirect;
  3014. return newObject;
  3015. }
  3016. function mapInternal(object) {
  3017. if (opts.showInternal) {
  3018. return object;
  3019. }
  3020. var newObject = Object.assign({}, object);
  3021. delete newObject.cliName;
  3022. delete newObject.cliCategory;
  3023. delete newObject.cliDescription;
  3024. return newObject;
  3025. }
  3026. }
  3027. var support = {
  3028. getSupportInfo: getSupportInfo$2
  3029. };
  3030. /* eslint-disable no-nested-ternary */
  3031. var arr = [];
  3032. var charCodeCache = [];
  3033. var leven = function leven(a, b) {
  3034. if (a === b) {
  3035. return 0;
  3036. }
  3037. var swap = a; // Swapping the strings if `a` is longer than `b` so we know which one is the
  3038. // shortest & which one is the longest
  3039. if (a.length > b.length) {
  3040. a = b;
  3041. b = swap;
  3042. }
  3043. var aLen = a.length;
  3044. var bLen = b.length;
  3045. if (aLen === 0) {
  3046. return bLen;
  3047. }
  3048. if (bLen === 0) {
  3049. return aLen;
  3050. } // Performing suffix trimming:
  3051. // We can linearly drop suffix common to both strings since they
  3052. // don't increase distance at all
  3053. // Note: `~-` is the bitwise way to perform a `- 1` operation
  3054. while (aLen > 0 && a.charCodeAt(~-aLen) === b.charCodeAt(~-bLen)) {
  3055. aLen--;
  3056. bLen--;
  3057. }
  3058. if (aLen === 0) {
  3059. return bLen;
  3060. } // Performing prefix trimming
  3061. // We can linearly drop prefix common to both strings since they
  3062. // don't increase distance at all
  3063. var start = 0;
  3064. while (start < aLen && a.charCodeAt(start) === b.charCodeAt(start)) {
  3065. start++;
  3066. }
  3067. aLen -= start;
  3068. bLen -= start;
  3069. if (aLen === 0) {
  3070. return bLen;
  3071. }
  3072. var bCharCode;
  3073. var ret;
  3074. var tmp;
  3075. var tmp2;
  3076. var i = 0;
  3077. var j = 0;
  3078. while (i < aLen) {
  3079. charCodeCache[start + i] = a.charCodeAt(start + i);
  3080. arr[i] = ++i;
  3081. }
  3082. while (j < bLen) {
  3083. bCharCode = b.charCodeAt(start + j);
  3084. tmp = j++;
  3085. ret = j;
  3086. for (i = 0; i < aLen; i++) {
  3087. tmp2 = bCharCode === charCodeCache[start + i] ? tmp : tmp + 1;
  3088. tmp = arr[i];
  3089. ret = arr[i] = tmp > ret ? tmp2 > ret ? ret + 1 : tmp2 : tmp2 > tmp ? tmp + 1 : tmp2;
  3090. }
  3091. }
  3092. return ret;
  3093. };
  3094. function apiDescriptor(name, value) {
  3095. return arguments.length === 1 ? JSON.stringify(name) : `\`{ ${apiDescriptor(name)}: ${JSON.stringify(value)} }\``;
  3096. }
  3097. function cliDescriptor(name, value) {
  3098. return value === false ? `\`--no-${name}\`` : value === true || arguments.length === 1 ? `\`--${name}\`` : value === "" ? `\`--${name}\` without an argument` : `\`--${name}=${value}\``;
  3099. }
  3100. var optionsDescriptor = {
  3101. apiDescriptor,
  3102. cliDescriptor
  3103. };
  3104. function validateOption(value, optionInfo, opts) {
  3105. opts = opts || {};
  3106. var descriptor = opts.descriptor || optionsDescriptor.apiDescriptor;
  3107. if (typeof optionInfo.exception === "function" && optionInfo.exception(value)) {
  3108. return;
  3109. }
  3110. try {
  3111. validateOptionType(value, optionInfo);
  3112. } catch (error) {
  3113. throw new Error(`Invalid \`${descriptor(optionInfo.name)}\` value. ${error.message}, but received \`${JSON.stringify(value)}\`.`);
  3114. }
  3115. }
  3116. function validateOptionType(value, optionInfo) {
  3117. if (optionInfo.array) {
  3118. if (!Array.isArray(value)) {
  3119. throw new Error(`Expected an array`);
  3120. }
  3121. value.forEach(function (v) {
  3122. return validateOptionType(v, Object.assign({}, optionInfo, {
  3123. array: false
  3124. }));
  3125. });
  3126. } else {
  3127. switch (optionInfo.type) {
  3128. case "int":
  3129. validateIntOption(value);
  3130. break;
  3131. case "boolean":
  3132. validateBooleanOption(value);
  3133. break;
  3134. case "choice":
  3135. validateChoiceOption(value, optionInfo.choices);
  3136. break;
  3137. }
  3138. }
  3139. }
  3140. function validateBooleanOption(value) {
  3141. if (typeof value !== "boolean") {
  3142. throw new Error(`Expected a boolean`);
  3143. }
  3144. }
  3145. function validateIntOption(value) {
  3146. if (!(typeof value === "number" && Math.floor(value) === value && value >= 0 && value !== Infinity)) {
  3147. throw new Error(`Expected an integer`);
  3148. }
  3149. }
  3150. function validateChoiceOption(value, choiceInfos) {
  3151. if (!choiceInfos.some(function (choiceInfo) {
  3152. return choiceInfo.value === value;
  3153. })) {
  3154. var choices = choiceInfos.filter(function (choiceInfo) {
  3155. return !choiceInfo.deprecated;
  3156. }).map(function (choiceInfo) {
  3157. return JSON.stringify(choiceInfo.value);
  3158. }).sort();
  3159. var head = choices.slice(0, -2);
  3160. var tail = choices.slice(-2);
  3161. throw new Error(`Expected ${head.concat(tail.join(" or ")).join(", ")}`);
  3162. }
  3163. }
  3164. var optionsValidator = {
  3165. validateOption
  3166. };
  3167. function normalizeOptions$1(options, optionInfos, opts) {
  3168. opts = opts || {};
  3169. var logger = opts.logger === false ? {
  3170. warn() {}
  3171. } : opts.logger !== undefined ? opts.logger : console;
  3172. var descriptor = opts.descriptor || optionsDescriptor.apiDescriptor;
  3173. var passThrough = opts.passThrough || [];
  3174. var optionInfoMap = optionInfos.reduce(function (reduced, optionInfo) {
  3175. return Object.assign(reduced, {
  3176. [optionInfo.name]: optionInfo
  3177. });
  3178. }, {});
  3179. var normalizedOptions = Object.keys(options).reduce(function (newOptions, key) {
  3180. var optionInfo = optionInfoMap[key];
  3181. var optionName = key;
  3182. var optionValue = options[key];
  3183. if (!optionInfo) {
  3184. if (passThrough === true || passThrough.indexOf(optionName) !== -1) {
  3185. newOptions[optionName] = optionValue;
  3186. } else {
  3187. logger.warn(createUnknownOptionMessage(optionName, optionValue, optionInfos, descriptor));
  3188. }
  3189. return newOptions;
  3190. }
  3191. if (!optionInfo.deprecated) {
  3192. optionValue = normalizeOption(optionValue, optionInfo);
  3193. } else if (typeof optionInfo.redirect === "string") {
  3194. logger.warn(createRedirectOptionMessage(optionInfo, descriptor));
  3195. optionName = optionInfo.redirect;
  3196. } else if (optionValue) {
  3197. logger.warn(createRedirectOptionMessage(optionInfo, descriptor));
  3198. optionValue = optionInfo.redirect.value;
  3199. optionName = optionInfo.redirect.option;
  3200. }
  3201. if (optionInfo.choices) {
  3202. var choiceInfo = optionInfo.choices.find(function (choice) {
  3203. return choice.value === optionValue;
  3204. });
  3205. if (choiceInfo && choiceInfo.deprecated) {
  3206. logger.warn(createRedirectChoiceMessage(optionInfo, choiceInfo, descriptor));
  3207. optionValue = choiceInfo.redirect;
  3208. }
  3209. }
  3210. if (optionInfo.array && !Array.isArray(optionValue)) {
  3211. optionValue = [optionValue];
  3212. }
  3213. if (optionValue !== optionInfo.default) {
  3214. optionsValidator.validateOption(optionValue, optionInfoMap[optionName], {
  3215. descriptor
  3216. });
  3217. }
  3218. newOptions[optionName] = optionValue;
  3219. return newOptions;
  3220. }, {});
  3221. return normalizedOptions;
  3222. }
  3223. function normalizeOption(option, optionInfo) {
  3224. return optionInfo.type === "int" ? Number(option) : option;
  3225. }
  3226. function createUnknownOptionMessage(key, value, optionInfos, descriptor) {
  3227. var messages = [`Ignored unknown option ${descriptor(key, value)}.`];
  3228. var suggestedOptionInfo = optionInfos.find(function (optionInfo) {
  3229. return leven(optionInfo.name, key) < 3;
  3230. });
  3231. if (suggestedOptionInfo) {
  3232. messages.push(`Did you mean ${JSON.stringify(suggestedOptionInfo.name)}?`);
  3233. }
  3234. return messages.join(" ");
  3235. }
  3236. function createRedirectOptionMessage(optionInfo, descriptor) {
  3237. return `${descriptor(optionInfo.name)} is deprecated. Prettier now treats it as ${typeof optionInfo.redirect === "string" ? descriptor(optionInfo.redirect) : descriptor(optionInfo.redirect.option, optionInfo.redirect.value)}.`;
  3238. }
  3239. function createRedirectChoiceMessage(optionInfo, choiceInfo, descriptor) {
  3240. return `${descriptor(optionInfo.name, choiceInfo.value)} is deprecated. Prettier now treats it as ${descriptor(optionInfo.name, choiceInfo.redirect)}.`;
  3241. }
  3242. function normalizeApiOptions(options, optionInfos, opts) {
  3243. return normalizeOptions$1(options, optionInfos, Object.assign({
  3244. descriptor: optionsDescriptor.apiDescriptor
  3245. }, opts));
  3246. }
  3247. function normalizeCliOptions(options, optionInfos, opts) {
  3248. var args = options["_"] || [];
  3249. var newOptions = normalizeOptions$1(Object.keys(options).reduce(function (reduced, key) {
  3250. return Object.assign(reduced, key.length === 1 // omit alias
  3251. ? null : {
  3252. [key]: options[key]
  3253. });
  3254. }, {}), optionInfos, Object.assign({
  3255. descriptor: optionsDescriptor.cliDescriptor
  3256. }, opts));
  3257. newOptions["_"] = args;
  3258. return newOptions;
  3259. }
  3260. var optionsNormalizer = {
  3261. normalizeApiOptions,
  3262. normalizeCliOptions
  3263. };
  3264. var getLast = function getLast(arr) {
  3265. return arr.length > 0 ? arr[arr.length - 1] : null;
  3266. };
  3267. function locStart$1(node) {
  3268. // Handle nodes with decorators. They should start at the first decorator
  3269. if (node.declaration && node.declaration.decorators && node.declaration.decorators.length > 0) {
  3270. return locStart$1(node.declaration.decorators[0]);
  3271. }
  3272. if (node.decorators && node.decorators.length > 0) {
  3273. return locStart$1(node.decorators[0]);
  3274. }
  3275. if (node.__location) {
  3276. return node.__location.startOffset;
  3277. }
  3278. if (node.range) {
  3279. return node.range[0];
  3280. }
  3281. if (typeof node.start === "number") {
  3282. return node.start;
  3283. }
  3284. if (node.loc) {
  3285. return node.loc.start;
  3286. }
  3287. return null;
  3288. }
  3289. function locEnd$1(node) {
  3290. var endNode = node.nodes && getLast(node.nodes);
  3291. if (endNode && node.source && !node.source.end) {
  3292. node = endNode;
  3293. }
  3294. if (node.__location) {
  3295. return node.__location.endOffset;
  3296. }
  3297. var loc = node.range ? node.range[1] : typeof node.end === "number" ? node.end : null;
  3298. if (node.typeAnnotation) {
  3299. return Math.max(loc, locEnd$1(node.typeAnnotation));
  3300. }
  3301. if (node.loc && !loc) {
  3302. return node.loc.end;
  3303. }
  3304. return loc;
  3305. }
  3306. var loc = {
  3307. locStart: locStart$1,
  3308. locEnd: locEnd$1
  3309. };
  3310. var jsTokens = createCommonjsModule(function (module, exports) {
  3311. // Copyright 2014, 2015, 2016, 2017 Simon Lydell
  3312. // License: MIT. (See LICENSE.)
  3313. Object.defineProperty(exports, "__esModule", {
  3314. value: true
  3315. }); // This regex comes from regex.coffee, and is inserted here by generate-index.js
  3316. // (run `npm run build`).
  3317. exports.default = /((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]).|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiyu]{1,5}\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;
  3318. exports.matchToToken = function (match) {
  3319. var token = {
  3320. type: "invalid",
  3321. value: match[0]
  3322. };
  3323. 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";
  3324. return token;
  3325. };
  3326. });
  3327. unwrapExports(jsTokens);
  3328. var ast = createCommonjsModule(function (module) {
  3329. /*
  3330. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  3331. Redistribution and use in source and binary forms, with or without
  3332. modification, are permitted provided that the following conditions are met:
  3333. * Redistributions of source code must retain the above copyright
  3334. notice, this list of conditions and the following disclaimer.
  3335. * Redistributions in binary form must reproduce the above copyright
  3336. notice, this list of conditions and the following disclaimer in the
  3337. documentation and/or other materials provided with the distribution.
  3338. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
  3339. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  3340. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  3341. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  3342. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  3343. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  3344. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  3345. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  3346. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  3347. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3348. */
  3349. (function () {
  3350. 'use strict';
  3351. function isExpression(node) {
  3352. if (node == null) {
  3353. return false;
  3354. }
  3355. switch (node.type) {
  3356. case 'ArrayExpression':
  3357. case 'AssignmentExpression':
  3358. case 'BinaryExpression':
  3359. case 'CallExpression':
  3360. case 'ConditionalExpression':
  3361. case 'FunctionExpression':
  3362. case 'Identifier':
  3363. case 'Literal':
  3364. case 'LogicalExpression':
  3365. case 'MemberExpression':
  3366. case 'NewExpression':
  3367. case 'ObjectExpression':
  3368. case 'SequenceExpression':
  3369. case 'ThisExpression':
  3370. case 'UnaryExpression':
  3371. case 'UpdateExpression':
  3372. return true;
  3373. }
  3374. return false;
  3375. }
  3376. function isIterationStatement(node) {
  3377. if (node == null) {
  3378. return false;
  3379. }
  3380. switch (node.type) {
  3381. case 'DoWhileStatement':
  3382. case 'ForInStatement':
  3383. case 'ForStatement':
  3384. case 'WhileStatement':
  3385. return true;
  3386. }
  3387. return false;
  3388. }
  3389. function isStatement(node) {
  3390. if (node == null) {
  3391. return false;
  3392. }
  3393. switch (node.type) {
  3394. case 'BlockStatement':
  3395. case 'BreakStatement':
  3396. case 'ContinueStatement':
  3397. case 'DebuggerStatement':
  3398. case 'DoWhileStatement':
  3399. case 'EmptyStatement':
  3400. case 'ExpressionStatement':
  3401. case 'ForInStatement':
  3402. case 'ForStatement':
  3403. case 'IfStatement':
  3404. case 'LabeledStatement':
  3405. case 'ReturnStatement':
  3406. case 'SwitchStatement':
  3407. case 'ThrowStatement':
  3408. case 'TryStatement':
  3409. case 'VariableDeclaration':
  3410. case 'WhileStatement':
  3411. case 'WithStatement':
  3412. return true;
  3413. }
  3414. return false;
  3415. }
  3416. function isSourceElement(node) {
  3417. return isStatement(node) || node != null && node.type === 'FunctionDeclaration';
  3418. }
  3419. function trailingStatement(node) {
  3420. switch (node.type) {
  3421. case 'IfStatement':
  3422. if (node.alternate != null) {
  3423. return node.alternate;
  3424. }
  3425. return node.consequent;
  3426. case 'LabeledStatement':
  3427. case 'ForStatement':
  3428. case 'ForInStatement':
  3429. case 'WhileStatement':
  3430. case 'WithStatement':
  3431. return node.body;
  3432. }
  3433. return null;
  3434. }
  3435. function isProblematicIfStatement(node) {
  3436. var current;
  3437. if (node.type !== 'IfStatement') {
  3438. return false;
  3439. }
  3440. if (node.alternate == null) {
  3441. return false;
  3442. }
  3443. current = node.consequent;
  3444. do {
  3445. if (current.type === 'IfStatement') {
  3446. if (current.alternate == null) {
  3447. return true;
  3448. }
  3449. }
  3450. current = trailingStatement(current);
  3451. } while (current);
  3452. return false;
  3453. }
  3454. module.exports = {
  3455. isExpression: isExpression,
  3456. isStatement: isStatement,
  3457. isIterationStatement: isIterationStatement,
  3458. isSourceElement: isSourceElement,
  3459. isProblematicIfStatement: isProblematicIfStatement,
  3460. trailingStatement: trailingStatement
  3461. };
  3462. })();
  3463. /* vim: set sw=4 ts=4 et tw=80 : */
  3464. });
  3465. var code = createCommonjsModule(function (module) {
  3466. /*
  3467. Copyright (C) 2013-2014 Yusuke Suzuki <utatane.tea@gmail.com>
  3468. Copyright (C) 2014 Ivan Nikulin <ifaaan@gmail.com>
  3469. Redistribution and use in source and binary forms, with or without
  3470. modification, are permitted provided that the following conditions are met:
  3471. * Redistributions of source code must retain the above copyright
  3472. notice, this list of conditions and the following disclaimer.
  3473. * Redistributions in binary form must reproduce the above copyright
  3474. notice, this list of conditions and the following disclaimer in the
  3475. documentation and/or other materials provided with the distribution.
  3476. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  3477. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  3478. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  3479. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  3480. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  3481. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  3482. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  3483. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  3484. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  3485. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3486. */
  3487. (function () {
  3488. 'use strict';
  3489. var ES6Regex, ES5Regex, NON_ASCII_WHITESPACES, IDENTIFIER_START, IDENTIFIER_PART, ch; // See `tools/generate-identifier-regex.js`.
  3490. ES5Regex = {
  3491. // ECMAScript 5.1/Unicode v7.0.0 NonAsciiIdentifierStart:
  3492. 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-\u08B2\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\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\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\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\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\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-\uAB5F\uAB64\uAB65\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/,
  3493. // ECMAScript 5.1/Unicode v7.0.0 NonAsciiIdentifierPart:
  3494. 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-\u08B2\u08E4-\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\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\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\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\u0D57\u0D60-\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-\u13F4\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\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\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-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA69D\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\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-\uAB5F\uAB64\uAB65\uABC0-\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-\uFE2D\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]/
  3495. };
  3496. ES6Regex = {
  3497. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierStart:
  3498. 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-\u08B2\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\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\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\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\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\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-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\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-\uAB5F\uAB64\uAB65\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\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\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\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]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDE00-\uDE11\uDE13-\uDE2B\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDE00-\uDE2F\uDE44\uDE80-\uDEAA]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF98]|\uD809[\uDC00-\uDC6E]|[\uD80C\uD840-\uD868\uD86A-\uD86C][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\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]|\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]|\uD87E[\uDC00-\uDE1D]/,
  3499. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierPart:
  3500. 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-\u08B2\u08E4-\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\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\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\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\u0D57\u0D60-\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-\u13F4\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\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\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-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA69D\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\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-\uAB5F\uAB64\uAB65\uABC0-\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-\uFE2D\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\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\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]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDD0-\uDDDA\uDE00-\uDE11\uDE13-\uDE37\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF01-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF98]|\uD809[\uDC00-\uDC6E]|[\uD80C\uD840-\uD868\uD86A-\uD86C][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\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]|\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]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\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]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/
  3501. };
  3502. function isDecimalDigit(ch) {
  3503. return 0x30 <= ch && ch <= 0x39; // 0..9
  3504. }
  3505. function isHexDigit(ch) {
  3506. return 0x30 <= ch && ch <= 0x39 || // 0..9
  3507. 0x61 <= ch && ch <= 0x66 || // a..f
  3508. 0x41 <= ch && ch <= 0x46; // A..F
  3509. }
  3510. function isOctalDigit(ch) {
  3511. return ch >= 0x30 && ch <= 0x37; // 0..7
  3512. } // 7.2 White Space
  3513. NON_ASCII_WHITESPACES = [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF];
  3514. function isWhiteSpace(ch) {
  3515. return ch === 0x20 || ch === 0x09 || ch === 0x0B || ch === 0x0C || ch === 0xA0 || ch >= 0x1680 && NON_ASCII_WHITESPACES.indexOf(ch) >= 0;
  3516. } // 7.3 Line Terminators
  3517. function isLineTerminator(ch) {
  3518. return ch === 0x0A || ch === 0x0D || ch === 0x2028 || ch === 0x2029;
  3519. } // 7.6 Identifier Names and Identifiers
  3520. function fromCodePoint(cp) {
  3521. if (cp <= 0xFFFF) {
  3522. return String.fromCharCode(cp);
  3523. }
  3524. var cu1 = String.fromCharCode(Math.floor((cp - 0x10000) / 0x400) + 0xD800);
  3525. var cu2 = String.fromCharCode((cp - 0x10000) % 0x400 + 0xDC00);
  3526. return cu1 + cu2;
  3527. }
  3528. IDENTIFIER_START = new Array(0x80);
  3529. for (ch = 0; ch < 0x80; ++ch) {
  3530. IDENTIFIER_START[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  3531. ch >= 0x41 && ch <= 0x5A || // A..Z
  3532. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  3533. }
  3534. IDENTIFIER_PART = new Array(0x80);
  3535. for (ch = 0; ch < 0x80; ++ch) {
  3536. IDENTIFIER_PART[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  3537. ch >= 0x41 && ch <= 0x5A || // A..Z
  3538. ch >= 0x30 && ch <= 0x39 || // 0..9
  3539. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  3540. }
  3541. function isIdentifierStartES5(ch) {
  3542. return ch < 0x80 ? IDENTIFIER_START[ch] : ES5Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  3543. }
  3544. function isIdentifierPartES5(ch) {
  3545. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES5Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  3546. }
  3547. function isIdentifierStartES6(ch) {
  3548. return ch < 0x80 ? IDENTIFIER_START[ch] : ES6Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  3549. }
  3550. function isIdentifierPartES6(ch) {
  3551. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES6Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  3552. }
  3553. module.exports = {
  3554. isDecimalDigit: isDecimalDigit,
  3555. isHexDigit: isHexDigit,
  3556. isOctalDigit: isOctalDigit,
  3557. isWhiteSpace: isWhiteSpace,
  3558. isLineTerminator: isLineTerminator,
  3559. isIdentifierStartES5: isIdentifierStartES5,
  3560. isIdentifierPartES5: isIdentifierPartES5,
  3561. isIdentifierStartES6: isIdentifierStartES6,
  3562. isIdentifierPartES6: isIdentifierPartES6
  3563. };
  3564. })();
  3565. /* vim: set sw=4 ts=4 et tw=80 : */
  3566. });
  3567. var keyword = createCommonjsModule(function (module) {
  3568. /*
  3569. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  3570. Redistribution and use in source and binary forms, with or without
  3571. modification, are permitted provided that the following conditions are met:
  3572. * Redistributions of source code must retain the above copyright
  3573. notice, this list of conditions and the following disclaimer.
  3574. * Redistributions in binary form must reproduce the above copyright
  3575. notice, this list of conditions and the following disclaimer in the
  3576. documentation and/or other materials provided with the distribution.
  3577. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  3578. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  3579. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  3580. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  3581. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  3582. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  3583. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  3584. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  3585. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  3586. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3587. */
  3588. (function () {
  3589. 'use strict';
  3590. var code$$1 = code;
  3591. function isStrictModeReservedWordES6(id) {
  3592. switch (id) {
  3593. case 'implements':
  3594. case 'interface':
  3595. case 'package':
  3596. case 'private':
  3597. case 'protected':
  3598. case 'public':
  3599. case 'static':
  3600. case 'let':
  3601. return true;
  3602. default:
  3603. return false;
  3604. }
  3605. }
  3606. function isKeywordES5(id, strict) {
  3607. // yield should not be treated as keyword under non-strict mode.
  3608. if (!strict && id === 'yield') {
  3609. return false;
  3610. }
  3611. return isKeywordES6(id, strict);
  3612. }
  3613. function isKeywordES6(id, strict) {
  3614. if (strict && isStrictModeReservedWordES6(id)) {
  3615. return true;
  3616. }
  3617. switch (id.length) {
  3618. case 2:
  3619. return id === 'if' || id === 'in' || id === 'do';
  3620. case 3:
  3621. return id === 'var' || id === 'for' || id === 'new' || id === 'try';
  3622. case 4:
  3623. return id === 'this' || id === 'else' || id === 'case' || id === 'void' || id === 'with' || id === 'enum';
  3624. case 5:
  3625. return id === 'while' || id === 'break' || id === 'catch' || id === 'throw' || id === 'const' || id === 'yield' || id === 'class' || id === 'super';
  3626. case 6:
  3627. return id === 'return' || id === 'typeof' || id === 'delete' || id === 'switch' || id === 'export' || id === 'import';
  3628. case 7:
  3629. return id === 'default' || id === 'finally' || id === 'extends';
  3630. case 8:
  3631. return id === 'function' || id === 'continue' || id === 'debugger';
  3632. case 10:
  3633. return id === 'instanceof';
  3634. default:
  3635. return false;
  3636. }
  3637. }
  3638. function isReservedWordES5(id, strict) {
  3639. return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);
  3640. }
  3641. function isReservedWordES6(id, strict) {
  3642. return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);
  3643. }
  3644. function isRestrictedWord(id) {
  3645. return id === 'eval' || id === 'arguments';
  3646. }
  3647. function isIdentifierNameES5(id) {
  3648. var i, iz, ch;
  3649. if (id.length === 0) {
  3650. return false;
  3651. }
  3652. ch = id.charCodeAt(0);
  3653. if (!code$$1.isIdentifierStartES5(ch)) {
  3654. return false;
  3655. }
  3656. for (i = 1, iz = id.length; i < iz; ++i) {
  3657. ch = id.charCodeAt(i);
  3658. if (!code$$1.isIdentifierPartES5(ch)) {
  3659. return false;
  3660. }
  3661. }
  3662. return true;
  3663. }
  3664. function decodeUtf16(lead, trail) {
  3665. return (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  3666. }
  3667. function isIdentifierNameES6(id) {
  3668. var i, iz, ch, lowCh, check;
  3669. if (id.length === 0) {
  3670. return false;
  3671. }
  3672. check = code$$1.isIdentifierStartES6;
  3673. for (i = 0, iz = id.length; i < iz; ++i) {
  3674. ch = id.charCodeAt(i);
  3675. if (0xD800 <= ch && ch <= 0xDBFF) {
  3676. ++i;
  3677. if (i >= iz) {
  3678. return false;
  3679. }
  3680. lowCh = id.charCodeAt(i);
  3681. if (!(0xDC00 <= lowCh && lowCh <= 0xDFFF)) {
  3682. return false;
  3683. }
  3684. ch = decodeUtf16(ch, lowCh);
  3685. }
  3686. if (!check(ch)) {
  3687. return false;
  3688. }
  3689. check = code$$1.isIdentifierPartES6;
  3690. }
  3691. return true;
  3692. }
  3693. function isIdentifierES5(id, strict) {
  3694. return isIdentifierNameES5(id) && !isReservedWordES5(id, strict);
  3695. }
  3696. function isIdentifierES6(id, strict) {
  3697. return isIdentifierNameES6(id) && !isReservedWordES6(id, strict);
  3698. }
  3699. module.exports = {
  3700. isKeywordES5: isKeywordES5,
  3701. isKeywordES6: isKeywordES6,
  3702. isReservedWordES5: isReservedWordES5,
  3703. isReservedWordES6: isReservedWordES6,
  3704. isRestrictedWord: isRestrictedWord,
  3705. isIdentifierNameES5: isIdentifierNameES5,
  3706. isIdentifierNameES6: isIdentifierNameES6,
  3707. isIdentifierES5: isIdentifierES5,
  3708. isIdentifierES6: isIdentifierES6
  3709. };
  3710. })();
  3711. /* vim: set sw=4 ts=4 et tw=80 : */
  3712. });
  3713. var utils = createCommonjsModule(function (module, exports) {
  3714. /*
  3715. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  3716. Redistribution and use in source and binary forms, with or without
  3717. modification, are permitted provided that the following conditions are met:
  3718. * Redistributions of source code must retain the above copyright
  3719. notice, this list of conditions and the following disclaimer.
  3720. * Redistributions in binary form must reproduce the above copyright
  3721. notice, this list of conditions and the following disclaimer in the
  3722. documentation and/or other materials provided with the distribution.
  3723. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  3724. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  3725. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  3726. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  3727. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  3728. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  3729. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  3730. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  3731. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  3732. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3733. */
  3734. (function () {
  3735. 'use strict';
  3736. exports.ast = ast;
  3737. exports.code = code;
  3738. exports.keyword = keyword;
  3739. })();
  3740. /* vim: set sw=4 ts=4 et tw=80 : */
  3741. });
  3742. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  3743. var escapeStringRegexp = function escapeStringRegexp(str) {
  3744. if (typeof str !== 'string') {
  3745. throw new TypeError('Expected a string');
  3746. }
  3747. return str.replace(matchOperatorsRe, '\\$&');
  3748. };
  3749. var colorName = {
  3750. "aliceblue": [240, 248, 255],
  3751. "antiquewhite": [250, 235, 215],
  3752. "aqua": [0, 255, 255],
  3753. "aquamarine": [127, 255, 212],
  3754. "azure": [240, 255, 255],
  3755. "beige": [245, 245, 220],
  3756. "bisque": [255, 228, 196],
  3757. "black": [0, 0, 0],
  3758. "blanchedalmond": [255, 235, 205],
  3759. "blue": [0, 0, 255],
  3760. "blueviolet": [138, 43, 226],
  3761. "brown": [165, 42, 42],
  3762. "burlywood": [222, 184, 135],
  3763. "cadetblue": [95, 158, 160],
  3764. "chartreuse": [127, 255, 0],
  3765. "chocolate": [210, 105, 30],
  3766. "coral": [255, 127, 80],
  3767. "cornflowerblue": [100, 149, 237],
  3768. "cornsilk": [255, 248, 220],
  3769. "crimson": [220, 20, 60],
  3770. "cyan": [0, 255, 255],
  3771. "darkblue": [0, 0, 139],
  3772. "darkcyan": [0, 139, 139],
  3773. "darkgoldenrod": [184, 134, 11],
  3774. "darkgray": [169, 169, 169],
  3775. "darkgreen": [0, 100, 0],
  3776. "darkgrey": [169, 169, 169],
  3777. "darkkhaki": [189, 183, 107],
  3778. "darkmagenta": [139, 0, 139],
  3779. "darkolivegreen": [85, 107, 47],
  3780. "darkorange": [255, 140, 0],
  3781. "darkorchid": [153, 50, 204],
  3782. "darkred": [139, 0, 0],
  3783. "darksalmon": [233, 150, 122],
  3784. "darkseagreen": [143, 188, 143],
  3785. "darkslateblue": [72, 61, 139],
  3786. "darkslategray": [47, 79, 79],
  3787. "darkslategrey": [47, 79, 79],
  3788. "darkturquoise": [0, 206, 209],
  3789. "darkviolet": [148, 0, 211],
  3790. "deeppink": [255, 20, 147],
  3791. "deepskyblue": [0, 191, 255],
  3792. "dimgray": [105, 105, 105],
  3793. "dimgrey": [105, 105, 105],
  3794. "dodgerblue": [30, 144, 255],
  3795. "firebrick": [178, 34, 34],
  3796. "floralwhite": [255, 250, 240],
  3797. "forestgreen": [34, 139, 34],
  3798. "fuchsia": [255, 0, 255],
  3799. "gainsboro": [220, 220, 220],
  3800. "ghostwhite": [248, 248, 255],
  3801. "gold": [255, 215, 0],
  3802. "goldenrod": [218, 165, 32],
  3803. "gray": [128, 128, 128],
  3804. "green": [0, 128, 0],
  3805. "greenyellow": [173, 255, 47],
  3806. "grey": [128, 128, 128],
  3807. "honeydew": [240, 255, 240],
  3808. "hotpink": [255, 105, 180],
  3809. "indianred": [205, 92, 92],
  3810. "indigo": [75, 0, 130],
  3811. "ivory": [255, 255, 240],
  3812. "khaki": [240, 230, 140],
  3813. "lavender": [230, 230, 250],
  3814. "lavenderblush": [255, 240, 245],
  3815. "lawngreen": [124, 252, 0],
  3816. "lemonchiffon": [255, 250, 205],
  3817. "lightblue": [173, 216, 230],
  3818. "lightcoral": [240, 128, 128],
  3819. "lightcyan": [224, 255, 255],
  3820. "lightgoldenrodyellow": [250, 250, 210],
  3821. "lightgray": [211, 211, 211],
  3822. "lightgreen": [144, 238, 144],
  3823. "lightgrey": [211, 211, 211],
  3824. "lightpink": [255, 182, 193],
  3825. "lightsalmon": [255, 160, 122],
  3826. "lightseagreen": [32, 178, 170],
  3827. "lightskyblue": [135, 206, 250],
  3828. "lightslategray": [119, 136, 153],
  3829. "lightslategrey": [119, 136, 153],
  3830. "lightsteelblue": [176, 196, 222],
  3831. "lightyellow": [255, 255, 224],
  3832. "lime": [0, 255, 0],
  3833. "limegreen": [50, 205, 50],
  3834. "linen": [250, 240, 230],
  3835. "magenta": [255, 0, 255],
  3836. "maroon": [128, 0, 0],
  3837. "mediumaquamarine": [102, 205, 170],
  3838. "mediumblue": [0, 0, 205],
  3839. "mediumorchid": [186, 85, 211],
  3840. "mediumpurple": [147, 112, 219],
  3841. "mediumseagreen": [60, 179, 113],
  3842. "mediumslateblue": [123, 104, 238],
  3843. "mediumspringgreen": [0, 250, 154],
  3844. "mediumturquoise": [72, 209, 204],
  3845. "mediumvioletred": [199, 21, 133],
  3846. "midnightblue": [25, 25, 112],
  3847. "mintcream": [245, 255, 250],
  3848. "mistyrose": [255, 228, 225],
  3849. "moccasin": [255, 228, 181],
  3850. "navajowhite": [255, 222, 173],
  3851. "navy": [0, 0, 128],
  3852. "oldlace": [253, 245, 230],
  3853. "olive": [128, 128, 0],
  3854. "olivedrab": [107, 142, 35],
  3855. "orange": [255, 165, 0],
  3856. "orangered": [255, 69, 0],
  3857. "orchid": [218, 112, 214],
  3858. "palegoldenrod": [238, 232, 170],
  3859. "palegreen": [152, 251, 152],
  3860. "paleturquoise": [175, 238, 238],
  3861. "palevioletred": [219, 112, 147],
  3862. "papayawhip": [255, 239, 213],
  3863. "peachpuff": [255, 218, 185],
  3864. "peru": [205, 133, 63],
  3865. "pink": [255, 192, 203],
  3866. "plum": [221, 160, 221],
  3867. "powderblue": [176, 224, 230],
  3868. "purple": [128, 0, 128],
  3869. "rebeccapurple": [102, 51, 153],
  3870. "red": [255, 0, 0],
  3871. "rosybrown": [188, 143, 143],
  3872. "royalblue": [65, 105, 225],
  3873. "saddlebrown": [139, 69, 19],
  3874. "salmon": [250, 128, 114],
  3875. "sandybrown": [244, 164, 96],
  3876. "seagreen": [46, 139, 87],
  3877. "seashell": [255, 245, 238],
  3878. "sienna": [160, 82, 45],
  3879. "silver": [192, 192, 192],
  3880. "skyblue": [135, 206, 235],
  3881. "slateblue": [106, 90, 205],
  3882. "slategray": [112, 128, 144],
  3883. "slategrey": [112, 128, 144],
  3884. "snow": [255, 250, 250],
  3885. "springgreen": [0, 255, 127],
  3886. "steelblue": [70, 130, 180],
  3887. "tan": [210, 180, 140],
  3888. "teal": [0, 128, 128],
  3889. "thistle": [216, 191, 216],
  3890. "tomato": [255, 99, 71],
  3891. "turquoise": [64, 224, 208],
  3892. "violet": [238, 130, 238],
  3893. "wheat": [245, 222, 179],
  3894. "white": [255, 255, 255],
  3895. "whitesmoke": [245, 245, 245],
  3896. "yellow": [255, 255, 0],
  3897. "yellowgreen": [154, 205, 50]
  3898. };
  3899. var conversions = createCommonjsModule(function (module) {
  3900. /* MIT license */
  3901. // NOTE: conversions should only return primitive values (i.e. arrays, or
  3902. // values that give correct `typeof` results).
  3903. // do not use box values types (i.e. Number(), String(), etc.)
  3904. var reverseKeywords = {};
  3905. for (var key in colorName) {
  3906. if (colorName.hasOwnProperty(key)) {
  3907. reverseKeywords[colorName[key]] = key;
  3908. }
  3909. }
  3910. var convert = module.exports = {
  3911. rgb: {
  3912. channels: 3,
  3913. labels: 'rgb'
  3914. },
  3915. hsl: {
  3916. channels: 3,
  3917. labels: 'hsl'
  3918. },
  3919. hsv: {
  3920. channels: 3,
  3921. labels: 'hsv'
  3922. },
  3923. hwb: {
  3924. channels: 3,
  3925. labels: 'hwb'
  3926. },
  3927. cmyk: {
  3928. channels: 4,
  3929. labels: 'cmyk'
  3930. },
  3931. xyz: {
  3932. channels: 3,
  3933. labels: 'xyz'
  3934. },
  3935. lab: {
  3936. channels: 3,
  3937. labels: 'lab'
  3938. },
  3939. lch: {
  3940. channels: 3,
  3941. labels: 'lch'
  3942. },
  3943. hex: {
  3944. channels: 1,
  3945. labels: ['hex']
  3946. },
  3947. keyword: {
  3948. channels: 1,
  3949. labels: ['keyword']
  3950. },
  3951. ansi16: {
  3952. channels: 1,
  3953. labels: ['ansi16']
  3954. },
  3955. ansi256: {
  3956. channels: 1,
  3957. labels: ['ansi256']
  3958. },
  3959. hcg: {
  3960. channels: 3,
  3961. labels: ['h', 'c', 'g']
  3962. },
  3963. apple: {
  3964. channels: 3,
  3965. labels: ['r16', 'g16', 'b16']
  3966. },
  3967. gray: {
  3968. channels: 1,
  3969. labels: ['gray']
  3970. }
  3971. }; // hide .channels and .labels properties
  3972. for (var model in convert) {
  3973. if (convert.hasOwnProperty(model)) {
  3974. if (!('channels' in convert[model])) {
  3975. throw new Error('missing channels property: ' + model);
  3976. }
  3977. if (!('labels' in convert[model])) {
  3978. throw new Error('missing channel labels property: ' + model);
  3979. }
  3980. if (convert[model].labels.length !== convert[model].channels) {
  3981. throw new Error('channel and label counts mismatch: ' + model);
  3982. }
  3983. var channels = convert[model].channels;
  3984. var labels = convert[model].labels;
  3985. delete convert[model].channels;
  3986. delete convert[model].labels;
  3987. Object.defineProperty(convert[model], 'channels', {
  3988. value: channels
  3989. });
  3990. Object.defineProperty(convert[model], 'labels', {
  3991. value: labels
  3992. });
  3993. }
  3994. }
  3995. convert.rgb.hsl = function (rgb) {
  3996. var r = rgb[0] / 255;
  3997. var g = rgb[1] / 255;
  3998. var b = rgb[2] / 255;
  3999. var min = Math.min(r, g, b);
  4000. var max = Math.max(r, g, b);
  4001. var delta = max - min;
  4002. var h;
  4003. var s;
  4004. var l;
  4005. if (max === min) {
  4006. h = 0;
  4007. } else if (r === max) {
  4008. h = (g - b) / delta;
  4009. } else if (g === max) {
  4010. h = 2 + (b - r) / delta;
  4011. } else if (b === max) {
  4012. h = 4 + (r - g) / delta;
  4013. }
  4014. h = Math.min(h * 60, 360);
  4015. if (h < 0) {
  4016. h += 360;
  4017. }
  4018. l = (min + max) / 2;
  4019. if (max === min) {
  4020. s = 0;
  4021. } else if (l <= 0.5) {
  4022. s = delta / (max + min);
  4023. } else {
  4024. s = delta / (2 - max - min);
  4025. }
  4026. return [h, s * 100, l * 100];
  4027. };
  4028. convert.rgb.hsv = function (rgb) {
  4029. var r = rgb[0];
  4030. var g = rgb[1];
  4031. var b = rgb[2];
  4032. var min = Math.min(r, g, b);
  4033. var max = Math.max(r, g, b);
  4034. var delta = max - min;
  4035. var h;
  4036. var s;
  4037. var v;
  4038. if (max === 0) {
  4039. s = 0;
  4040. } else {
  4041. s = delta / max * 1000 / 10;
  4042. }
  4043. if (max === min) {
  4044. h = 0;
  4045. } else if (r === max) {
  4046. h = (g - b) / delta;
  4047. } else if (g === max) {
  4048. h = 2 + (b - r) / delta;
  4049. } else if (b === max) {
  4050. h = 4 + (r - g) / delta;
  4051. }
  4052. h = Math.min(h * 60, 360);
  4053. if (h < 0) {
  4054. h += 360;
  4055. }
  4056. v = max / 255 * 1000 / 10;
  4057. return [h, s, v];
  4058. };
  4059. convert.rgb.hwb = function (rgb) {
  4060. var r = rgb[0];
  4061. var g = rgb[1];
  4062. var b = rgb[2];
  4063. var h = convert.rgb.hsl(rgb)[0];
  4064. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  4065. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  4066. return [h, w * 100, b * 100];
  4067. };
  4068. convert.rgb.cmyk = function (rgb) {
  4069. var r = rgb[0] / 255;
  4070. var g = rgb[1] / 255;
  4071. var b = rgb[2] / 255;
  4072. var c;
  4073. var m;
  4074. var y;
  4075. var k;
  4076. k = Math.min(1 - r, 1 - g, 1 - b);
  4077. c = (1 - r - k) / (1 - k) || 0;
  4078. m = (1 - g - k) / (1 - k) || 0;
  4079. y = (1 - b - k) / (1 - k) || 0;
  4080. return [c * 100, m * 100, y * 100, k * 100];
  4081. };
  4082. /**
  4083. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  4084. * */
  4085. function comparativeDistance(x, y) {
  4086. return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
  4087. }
  4088. convert.rgb.keyword = function (rgb) {
  4089. var reversed = reverseKeywords[rgb];
  4090. if (reversed) {
  4091. return reversed;
  4092. }
  4093. var currentClosestDistance = Infinity;
  4094. var currentClosestKeyword;
  4095. for (var keyword in colorName) {
  4096. if (colorName.hasOwnProperty(keyword)) {
  4097. var value = colorName[keyword]; // Compute comparative distance
  4098. var distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  4099. if (distance < currentClosestDistance) {
  4100. currentClosestDistance = distance;
  4101. currentClosestKeyword = keyword;
  4102. }
  4103. }
  4104. }
  4105. return currentClosestKeyword;
  4106. };
  4107. convert.keyword.rgb = function (keyword) {
  4108. return colorName[keyword];
  4109. };
  4110. convert.rgb.xyz = function (rgb) {
  4111. var r = rgb[0] / 255;
  4112. var g = rgb[1] / 255;
  4113. var b = rgb[2] / 255; // assume sRGB
  4114. r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
  4115. g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
  4116. b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
  4117. var x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  4118. var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  4119. var z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  4120. return [x * 100, y * 100, z * 100];
  4121. };
  4122. convert.rgb.lab = function (rgb) {
  4123. var xyz = convert.rgb.xyz(rgb);
  4124. var x = xyz[0];
  4125. var y = xyz[1];
  4126. var z = xyz[2];
  4127. var l;
  4128. var a;
  4129. var b;
  4130. x /= 95.047;
  4131. y /= 100;
  4132. z /= 108.883;
  4133. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  4134. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  4135. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  4136. l = 116 * y - 16;
  4137. a = 500 * (x - y);
  4138. b = 200 * (y - z);
  4139. return [l, a, b];
  4140. };
  4141. convert.hsl.rgb = function (hsl) {
  4142. var h = hsl[0] / 360;
  4143. var s = hsl[1] / 100;
  4144. var l = hsl[2] / 100;
  4145. var t1;
  4146. var t2;
  4147. var t3;
  4148. var rgb;
  4149. var val;
  4150. if (s === 0) {
  4151. val = l * 255;
  4152. return [val, val, val];
  4153. }
  4154. if (l < 0.5) {
  4155. t2 = l * (1 + s);
  4156. } else {
  4157. t2 = l + s - l * s;
  4158. }
  4159. t1 = 2 * l - t2;
  4160. rgb = [0, 0, 0];
  4161. for (var i = 0; i < 3; i++) {
  4162. t3 = h + 1 / 3 * -(i - 1);
  4163. if (t3 < 0) {
  4164. t3++;
  4165. }
  4166. if (t3 > 1) {
  4167. t3--;
  4168. }
  4169. if (6 * t3 < 1) {
  4170. val = t1 + (t2 - t1) * 6 * t3;
  4171. } else if (2 * t3 < 1) {
  4172. val = t2;
  4173. } else if (3 * t3 < 2) {
  4174. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  4175. } else {
  4176. val = t1;
  4177. }
  4178. rgb[i] = val * 255;
  4179. }
  4180. return rgb;
  4181. };
  4182. convert.hsl.hsv = function (hsl) {
  4183. var h = hsl[0];
  4184. var s = hsl[1] / 100;
  4185. var l = hsl[2] / 100;
  4186. var smin = s;
  4187. var lmin = Math.max(l, 0.01);
  4188. var sv;
  4189. var v;
  4190. l *= 2;
  4191. s *= l <= 1 ? l : 2 - l;
  4192. smin *= lmin <= 1 ? lmin : 2 - lmin;
  4193. v = (l + s) / 2;
  4194. sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  4195. return [h, sv * 100, v * 100];
  4196. };
  4197. convert.hsv.rgb = function (hsv) {
  4198. var h = hsv[0] / 60;
  4199. var s = hsv[1] / 100;
  4200. var v = hsv[2] / 100;
  4201. var hi = Math.floor(h) % 6;
  4202. var f = h - Math.floor(h);
  4203. var p = 255 * v * (1 - s);
  4204. var q = 255 * v * (1 - s * f);
  4205. var t = 255 * v * (1 - s * (1 - f));
  4206. v *= 255;
  4207. switch (hi) {
  4208. case 0:
  4209. return [v, t, p];
  4210. case 1:
  4211. return [q, v, p];
  4212. case 2:
  4213. return [p, v, t];
  4214. case 3:
  4215. return [p, q, v];
  4216. case 4:
  4217. return [t, p, v];
  4218. case 5:
  4219. return [v, p, q];
  4220. }
  4221. };
  4222. convert.hsv.hsl = function (hsv) {
  4223. var h = hsv[0];
  4224. var s = hsv[1] / 100;
  4225. var v = hsv[2] / 100;
  4226. var vmin = Math.max(v, 0.01);
  4227. var lmin;
  4228. var sl;
  4229. var l;
  4230. l = (2 - s) * v;
  4231. lmin = (2 - s) * vmin;
  4232. sl = s * vmin;
  4233. sl /= lmin <= 1 ? lmin : 2 - lmin;
  4234. sl = sl || 0;
  4235. l /= 2;
  4236. return [h, sl * 100, l * 100];
  4237. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  4238. convert.hwb.rgb = function (hwb) {
  4239. var h = hwb[0] / 360;
  4240. var wh = hwb[1] / 100;
  4241. var bl = hwb[2] / 100;
  4242. var ratio = wh + bl;
  4243. var i;
  4244. var v;
  4245. var f;
  4246. var n; // wh + bl cant be > 1
  4247. if (ratio > 1) {
  4248. wh /= ratio;
  4249. bl /= ratio;
  4250. }
  4251. i = Math.floor(6 * h);
  4252. v = 1 - bl;
  4253. f = 6 * h - i;
  4254. if ((i & 0x01) !== 0) {
  4255. f = 1 - f;
  4256. }
  4257. n = wh + f * (v - wh); // linear interpolation
  4258. var r;
  4259. var g;
  4260. var b;
  4261. switch (i) {
  4262. default:
  4263. case 6:
  4264. case 0:
  4265. r = v;
  4266. g = n;
  4267. b = wh;
  4268. break;
  4269. case 1:
  4270. r = n;
  4271. g = v;
  4272. b = wh;
  4273. break;
  4274. case 2:
  4275. r = wh;
  4276. g = v;
  4277. b = n;
  4278. break;
  4279. case 3:
  4280. r = wh;
  4281. g = n;
  4282. b = v;
  4283. break;
  4284. case 4:
  4285. r = n;
  4286. g = wh;
  4287. b = v;
  4288. break;
  4289. case 5:
  4290. r = v;
  4291. g = wh;
  4292. b = n;
  4293. break;
  4294. }
  4295. return [r * 255, g * 255, b * 255];
  4296. };
  4297. convert.cmyk.rgb = function (cmyk) {
  4298. var c = cmyk[0] / 100;
  4299. var m = cmyk[1] / 100;
  4300. var y = cmyk[2] / 100;
  4301. var k = cmyk[3] / 100;
  4302. var r;
  4303. var g;
  4304. var b;
  4305. r = 1 - Math.min(1, c * (1 - k) + k);
  4306. g = 1 - Math.min(1, m * (1 - k) + k);
  4307. b = 1 - Math.min(1, y * (1 - k) + k);
  4308. return [r * 255, g * 255, b * 255];
  4309. };
  4310. convert.xyz.rgb = function (xyz) {
  4311. var x = xyz[0] / 100;
  4312. var y = xyz[1] / 100;
  4313. var z = xyz[2] / 100;
  4314. var r;
  4315. var g;
  4316. var b;
  4317. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  4318. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  4319. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // assume sRGB
  4320. r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
  4321. g = g > 0.0031308 ? 1.055 * Math.pow(g, 1.0 / 2.4) - 0.055 : g * 12.92;
  4322. b = b > 0.0031308 ? 1.055 * Math.pow(b, 1.0 / 2.4) - 0.055 : b * 12.92;
  4323. r = Math.min(Math.max(0, r), 1);
  4324. g = Math.min(Math.max(0, g), 1);
  4325. b = Math.min(Math.max(0, b), 1);
  4326. return [r * 255, g * 255, b * 255];
  4327. };
  4328. convert.xyz.lab = function (xyz) {
  4329. var x = xyz[0];
  4330. var y = xyz[1];
  4331. var z = xyz[2];
  4332. var l;
  4333. var a;
  4334. var b;
  4335. x /= 95.047;
  4336. y /= 100;
  4337. z /= 108.883;
  4338. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  4339. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  4340. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  4341. l = 116 * y - 16;
  4342. a = 500 * (x - y);
  4343. b = 200 * (y - z);
  4344. return [l, a, b];
  4345. };
  4346. convert.lab.xyz = function (lab) {
  4347. var l = lab[0];
  4348. var a = lab[1];
  4349. var b = lab[2];
  4350. var x;
  4351. var y;
  4352. var z;
  4353. y = (l + 16) / 116;
  4354. x = a / 500 + y;
  4355. z = y - b / 200;
  4356. var y2 = Math.pow(y, 3);
  4357. var x2 = Math.pow(x, 3);
  4358. var z2 = Math.pow(z, 3);
  4359. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  4360. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  4361. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  4362. x *= 95.047;
  4363. y *= 100;
  4364. z *= 108.883;
  4365. return [x, y, z];
  4366. };
  4367. convert.lab.lch = function (lab) {
  4368. var l = lab[0];
  4369. var a = lab[1];
  4370. var b = lab[2];
  4371. var hr;
  4372. var h;
  4373. var c;
  4374. hr = Math.atan2(b, a);
  4375. h = hr * 360 / 2 / Math.PI;
  4376. if (h < 0) {
  4377. h += 360;
  4378. }
  4379. c = Math.sqrt(a * a + b * b);
  4380. return [l, c, h];
  4381. };
  4382. convert.lch.lab = function (lch) {
  4383. var l = lch[0];
  4384. var c = lch[1];
  4385. var h = lch[2];
  4386. var a;
  4387. var b;
  4388. var hr;
  4389. hr = h / 360 * 2 * Math.PI;
  4390. a = c * Math.cos(hr);
  4391. b = c * Math.sin(hr);
  4392. return [l, a, b];
  4393. };
  4394. convert.rgb.ansi16 = function (args) {
  4395. var r = args[0];
  4396. var g = args[1];
  4397. var b = args[2];
  4398. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  4399. value = Math.round(value / 50);
  4400. if (value === 0) {
  4401. return 30;
  4402. }
  4403. var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  4404. if (value === 2) {
  4405. ansi += 60;
  4406. }
  4407. return ansi;
  4408. };
  4409. convert.hsv.ansi16 = function (args) {
  4410. // optimization here; we already know the value and don't need to get
  4411. // it converted for us.
  4412. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  4413. };
  4414. convert.rgb.ansi256 = function (args) {
  4415. var r = args[0];
  4416. var g = args[1];
  4417. var b = args[2]; // we use the extended greyscale palette here, with the exception of
  4418. // black and white. normal palette only has 4 greyscale shades.
  4419. if (r === g && g === b) {
  4420. if (r < 8) {
  4421. return 16;
  4422. }
  4423. if (r > 248) {
  4424. return 231;
  4425. }
  4426. return Math.round((r - 8) / 247 * 24) + 232;
  4427. }
  4428. var ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  4429. return ansi;
  4430. };
  4431. convert.ansi16.rgb = function (args) {
  4432. var color = args % 10; // handle greyscale
  4433. if (color === 0 || color === 7) {
  4434. if (args > 50) {
  4435. color += 3.5;
  4436. }
  4437. color = color / 10.5 * 255;
  4438. return [color, color, color];
  4439. }
  4440. var mult = (~~(args > 50) + 1) * 0.5;
  4441. var r = (color & 1) * mult * 255;
  4442. var g = (color >> 1 & 1) * mult * 255;
  4443. var b = (color >> 2 & 1) * mult * 255;
  4444. return [r, g, b];
  4445. };
  4446. convert.ansi256.rgb = function (args) {
  4447. // handle greyscale
  4448. if (args >= 232) {
  4449. var c = (args - 232) * 10 + 8;
  4450. return [c, c, c];
  4451. }
  4452. args -= 16;
  4453. var rem;
  4454. var r = Math.floor(args / 36) / 5 * 255;
  4455. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  4456. var b = rem % 6 / 5 * 255;
  4457. return [r, g, b];
  4458. };
  4459. convert.rgb.hex = function (args) {
  4460. var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  4461. var string = integer.toString(16).toUpperCase();
  4462. return '000000'.substring(string.length) + string;
  4463. };
  4464. convert.hex.rgb = function (args) {
  4465. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  4466. if (!match) {
  4467. return [0, 0, 0];
  4468. }
  4469. var colorString = match[0];
  4470. if (match[0].length === 3) {
  4471. colorString = colorString.split('').map(function (char) {
  4472. return char + char;
  4473. }).join('');
  4474. }
  4475. var integer = parseInt(colorString, 16);
  4476. var r = integer >> 16 & 0xFF;
  4477. var g = integer >> 8 & 0xFF;
  4478. var b = integer & 0xFF;
  4479. return [r, g, b];
  4480. };
  4481. convert.rgb.hcg = function (rgb) {
  4482. var r = rgb[0] / 255;
  4483. var g = rgb[1] / 255;
  4484. var b = rgb[2] / 255;
  4485. var max = Math.max(Math.max(r, g), b);
  4486. var min = Math.min(Math.min(r, g), b);
  4487. var chroma = max - min;
  4488. var grayscale;
  4489. var hue;
  4490. if (chroma < 1) {
  4491. grayscale = min / (1 - chroma);
  4492. } else {
  4493. grayscale = 0;
  4494. }
  4495. if (chroma <= 0) {
  4496. hue = 0;
  4497. } else if (max === r) {
  4498. hue = (g - b) / chroma % 6;
  4499. } else if (max === g) {
  4500. hue = 2 + (b - r) / chroma;
  4501. } else {
  4502. hue = 4 + (r - g) / chroma + 4;
  4503. }
  4504. hue /= 6;
  4505. hue %= 1;
  4506. return [hue * 360, chroma * 100, grayscale * 100];
  4507. };
  4508. convert.hsl.hcg = function (hsl) {
  4509. var s = hsl[1] / 100;
  4510. var l = hsl[2] / 100;
  4511. var c = 1;
  4512. var f = 0;
  4513. if (l < 0.5) {
  4514. c = 2.0 * s * l;
  4515. } else {
  4516. c = 2.0 * s * (1.0 - l);
  4517. }
  4518. if (c < 1.0) {
  4519. f = (l - 0.5 * c) / (1.0 - c);
  4520. }
  4521. return [hsl[0], c * 100, f * 100];
  4522. };
  4523. convert.hsv.hcg = function (hsv) {
  4524. var s = hsv[1] / 100;
  4525. var v = hsv[2] / 100;
  4526. var c = s * v;
  4527. var f = 0;
  4528. if (c < 1.0) {
  4529. f = (v - c) / (1 - c);
  4530. }
  4531. return [hsv[0], c * 100, f * 100];
  4532. };
  4533. convert.hcg.rgb = function (hcg) {
  4534. var h = hcg[0] / 360;
  4535. var c = hcg[1] / 100;
  4536. var g = hcg[2] / 100;
  4537. if (c === 0.0) {
  4538. return [g * 255, g * 255, g * 255];
  4539. }
  4540. var pure = [0, 0, 0];
  4541. var hi = h % 1 * 6;
  4542. var v = hi % 1;
  4543. var w = 1 - v;
  4544. var mg = 0;
  4545. switch (Math.floor(hi)) {
  4546. case 0:
  4547. pure[0] = 1;
  4548. pure[1] = v;
  4549. pure[2] = 0;
  4550. break;
  4551. case 1:
  4552. pure[0] = w;
  4553. pure[1] = 1;
  4554. pure[2] = 0;
  4555. break;
  4556. case 2:
  4557. pure[0] = 0;
  4558. pure[1] = 1;
  4559. pure[2] = v;
  4560. break;
  4561. case 3:
  4562. pure[0] = 0;
  4563. pure[1] = w;
  4564. pure[2] = 1;
  4565. break;
  4566. case 4:
  4567. pure[0] = v;
  4568. pure[1] = 0;
  4569. pure[2] = 1;
  4570. break;
  4571. default:
  4572. pure[0] = 1;
  4573. pure[1] = 0;
  4574. pure[2] = w;
  4575. }
  4576. mg = (1.0 - c) * g;
  4577. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  4578. };
  4579. convert.hcg.hsv = function (hcg) {
  4580. var c = hcg[1] / 100;
  4581. var g = hcg[2] / 100;
  4582. var v = c + g * (1.0 - c);
  4583. var f = 0;
  4584. if (v > 0.0) {
  4585. f = c / v;
  4586. }
  4587. return [hcg[0], f * 100, v * 100];
  4588. };
  4589. convert.hcg.hsl = function (hcg) {
  4590. var c = hcg[1] / 100;
  4591. var g = hcg[2] / 100;
  4592. var l = g * (1.0 - c) + 0.5 * c;
  4593. var s = 0;
  4594. if (l > 0.0 && l < 0.5) {
  4595. s = c / (2 * l);
  4596. } else if (l >= 0.5 && l < 1.0) {
  4597. s = c / (2 * (1 - l));
  4598. }
  4599. return [hcg[0], s * 100, l * 100];
  4600. };
  4601. convert.hcg.hwb = function (hcg) {
  4602. var c = hcg[1] / 100;
  4603. var g = hcg[2] / 100;
  4604. var v = c + g * (1.0 - c);
  4605. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  4606. };
  4607. convert.hwb.hcg = function (hwb) {
  4608. var w = hwb[1] / 100;
  4609. var b = hwb[2] / 100;
  4610. var v = 1 - b;
  4611. var c = v - w;
  4612. var g = 0;
  4613. if (c < 1) {
  4614. g = (v - c) / (1 - c);
  4615. }
  4616. return [hwb[0], c * 100, g * 100];
  4617. };
  4618. convert.apple.rgb = function (apple) {
  4619. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  4620. };
  4621. convert.rgb.apple = function (rgb) {
  4622. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  4623. };
  4624. convert.gray.rgb = function (args) {
  4625. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  4626. };
  4627. convert.gray.hsl = convert.gray.hsv = function (args) {
  4628. return [0, 0, args[0]];
  4629. };
  4630. convert.gray.hwb = function (gray) {
  4631. return [0, 100, gray[0]];
  4632. };
  4633. convert.gray.cmyk = function (gray) {
  4634. return [0, 0, 0, gray[0]];
  4635. };
  4636. convert.gray.lab = function (gray) {
  4637. return [gray[0], 0, 0];
  4638. };
  4639. convert.gray.hex = function (gray) {
  4640. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  4641. var integer = (val << 16) + (val << 8) + val;
  4642. var string = integer.toString(16).toUpperCase();
  4643. return '000000'.substring(string.length) + string;
  4644. };
  4645. convert.rgb.gray = function (rgb) {
  4646. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  4647. return [val / 255 * 100];
  4648. };
  4649. });
  4650. /*
  4651. this function routes a model to all other models.
  4652. all functions that are routed have a property `.conversion` attached
  4653. to the returned synthetic function. This property is an array
  4654. of strings, each with the steps in between the 'from' and 'to'
  4655. color models (inclusive).
  4656. conversions that are not possible simply are not included.
  4657. */
  4658. // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  4659. var models$1 = Object.keys(conversions);
  4660. function buildGraph() {
  4661. var graph = {};
  4662. for (var len = models$1.length, i = 0; i < len; i++) {
  4663. graph[models$1[i]] = {
  4664. // http://jsperf.com/1-vs-infinity
  4665. // micro-opt, but this is simple.
  4666. distance: -1,
  4667. parent: null
  4668. };
  4669. }
  4670. return graph;
  4671. } // https://en.wikipedia.org/wiki/Breadth-first_search
  4672. function deriveBFS(fromModel) {
  4673. var graph = buildGraph();
  4674. var queue = [fromModel]; // unshift -> queue -> pop
  4675. graph[fromModel].distance = 0;
  4676. while (queue.length) {
  4677. var current = queue.pop();
  4678. var adjacents = Object.keys(conversions[current]);
  4679. for (var len = adjacents.length, i = 0; i < len; i++) {
  4680. var adjacent = adjacents[i];
  4681. var node = graph[adjacent];
  4682. if (node.distance === -1) {
  4683. node.distance = graph[current].distance + 1;
  4684. node.parent = current;
  4685. queue.unshift(adjacent);
  4686. }
  4687. }
  4688. }
  4689. return graph;
  4690. }
  4691. function link(from, to) {
  4692. return function (args) {
  4693. return to(from(args));
  4694. };
  4695. }
  4696. function wrapConversion(toModel, graph) {
  4697. var path$$1 = [graph[toModel].parent, toModel];
  4698. var fn = conversions[graph[toModel].parent][toModel];
  4699. var cur = graph[toModel].parent;
  4700. while (graph[cur].parent) {
  4701. path$$1.unshift(graph[cur].parent);
  4702. fn = link(conversions[graph[cur].parent][cur], fn);
  4703. cur = graph[cur].parent;
  4704. }
  4705. fn.conversion = path$$1;
  4706. return fn;
  4707. }
  4708. var route = function route(fromModel) {
  4709. var graph = deriveBFS(fromModel);
  4710. var conversion = {};
  4711. var models = Object.keys(graph);
  4712. for (var len = models.length, i = 0; i < len; i++) {
  4713. var toModel = models[i];
  4714. var node = graph[toModel];
  4715. if (node.parent === null) {
  4716. // no possible conversion, or this node is the source model.
  4717. continue;
  4718. }
  4719. conversion[toModel] = wrapConversion(toModel, graph);
  4720. }
  4721. return conversion;
  4722. };
  4723. var convert = {};
  4724. var models = Object.keys(conversions);
  4725. function wrapRaw(fn) {
  4726. var wrappedFn = function wrappedFn(args) {
  4727. if (args === undefined || args === null) {
  4728. return args;
  4729. }
  4730. if (arguments.length > 1) {
  4731. args = Array.prototype.slice.call(arguments);
  4732. }
  4733. return fn(args);
  4734. }; // preserve .conversion property if there is one
  4735. if ('conversion' in fn) {
  4736. wrappedFn.conversion = fn.conversion;
  4737. }
  4738. return wrappedFn;
  4739. }
  4740. function wrapRounded(fn) {
  4741. var wrappedFn = function wrappedFn(args) {
  4742. if (args === undefined || args === null) {
  4743. return args;
  4744. }
  4745. if (arguments.length > 1) {
  4746. args = Array.prototype.slice.call(arguments);
  4747. }
  4748. var result = fn(args); // we're assuming the result is an array here.
  4749. // see notice in conversions.js; don't use box types
  4750. // in conversion functions.
  4751. if (typeof result === 'object') {
  4752. for (var len = result.length, i = 0; i < len; i++) {
  4753. result[i] = Math.round(result[i]);
  4754. }
  4755. }
  4756. return result;
  4757. }; // preserve .conversion property if there is one
  4758. if ('conversion' in fn) {
  4759. wrappedFn.conversion = fn.conversion;
  4760. }
  4761. return wrappedFn;
  4762. }
  4763. models.forEach(function (fromModel) {
  4764. convert[fromModel] = {};
  4765. Object.defineProperty(convert[fromModel], 'channels', {
  4766. value: conversions[fromModel].channels
  4767. });
  4768. Object.defineProperty(convert[fromModel], 'labels', {
  4769. value: conversions[fromModel].labels
  4770. });
  4771. var routes = route(fromModel);
  4772. var routeModels = Object.keys(routes);
  4773. routeModels.forEach(function (toModel) {
  4774. var fn = routes[toModel];
  4775. convert[fromModel][toModel] = wrapRounded(fn);
  4776. convert[fromModel][toModel].raw = wrapRaw(fn);
  4777. });
  4778. });
  4779. var colorConvert = convert;
  4780. var ansiStyles = createCommonjsModule(function (module) {
  4781. 'use strict';
  4782. var wrapAnsi16 = function wrapAnsi16(fn, offset) {
  4783. return function () {
  4784. var code = fn.apply(colorConvert, arguments);
  4785. return `\u001B[${code + offset}m`;
  4786. };
  4787. };
  4788. var wrapAnsi256 = function wrapAnsi256(fn, offset) {
  4789. return function () {
  4790. var code = fn.apply(colorConvert, arguments);
  4791. return `\u001B[${38 + offset};5;${code}m`;
  4792. };
  4793. };
  4794. var wrapAnsi16m = function wrapAnsi16m(fn, offset) {
  4795. return function () {
  4796. var rgb = fn.apply(colorConvert, arguments);
  4797. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  4798. };
  4799. };
  4800. function assembleStyles() {
  4801. var styles = {
  4802. modifier: {
  4803. reset: [0, 0],
  4804. // 21 isn't widely supported and 22 does the same thing
  4805. bold: [1, 22],
  4806. dim: [2, 22],
  4807. italic: [3, 23],
  4808. underline: [4, 24],
  4809. inverse: [7, 27],
  4810. hidden: [8, 28],
  4811. strikethrough: [9, 29]
  4812. },
  4813. color: {
  4814. black: [30, 39],
  4815. red: [31, 39],
  4816. green: [32, 39],
  4817. yellow: [33, 39],
  4818. blue: [34, 39],
  4819. magenta: [35, 39],
  4820. cyan: [36, 39],
  4821. white: [37, 39],
  4822. gray: [90, 39],
  4823. // Bright color
  4824. redBright: [91, 39],
  4825. greenBright: [92, 39],
  4826. yellowBright: [93, 39],
  4827. blueBright: [94, 39],
  4828. magentaBright: [95, 39],
  4829. cyanBright: [96, 39],
  4830. whiteBright: [97, 39]
  4831. },
  4832. bgColor: {
  4833. bgBlack: [40, 49],
  4834. bgRed: [41, 49],
  4835. bgGreen: [42, 49],
  4836. bgYellow: [43, 49],
  4837. bgBlue: [44, 49],
  4838. bgMagenta: [45, 49],
  4839. bgCyan: [46, 49],
  4840. bgWhite: [47, 49],
  4841. // Bright color
  4842. bgBlackBright: [100, 49],
  4843. bgRedBright: [101, 49],
  4844. bgGreenBright: [102, 49],
  4845. bgYellowBright: [103, 49],
  4846. bgBlueBright: [104, 49],
  4847. bgMagentaBright: [105, 49],
  4848. bgCyanBright: [106, 49],
  4849. bgWhiteBright: [107, 49]
  4850. }
  4851. }; // Fix humans
  4852. styles.color.grey = styles.color.gray;
  4853. Object.keys(styles).forEach(function (groupName) {
  4854. var group = styles[groupName];
  4855. Object.keys(group).forEach(function (styleName) {
  4856. var style = group[styleName];
  4857. styles[styleName] = {
  4858. open: `\u001B[${style[0]}m`,
  4859. close: `\u001B[${style[1]}m`
  4860. };
  4861. group[styleName] = styles[styleName];
  4862. });
  4863. Object.defineProperty(styles, groupName, {
  4864. value: group,
  4865. enumerable: false
  4866. });
  4867. });
  4868. var rgb2rgb = function rgb2rgb(r, g, b) {
  4869. return [r, g, b];
  4870. };
  4871. styles.color.close = '\u001B[39m';
  4872. styles.bgColor.close = '\u001B[49m';
  4873. styles.color.ansi = {};
  4874. styles.color.ansi256 = {};
  4875. styles.color.ansi16m = {
  4876. rgb: wrapAnsi16m(rgb2rgb, 0)
  4877. };
  4878. styles.bgColor.ansi = {};
  4879. styles.bgColor.ansi256 = {};
  4880. styles.bgColor.ansi16m = {
  4881. rgb: wrapAnsi16m(rgb2rgb, 10)
  4882. };
  4883. var _arr = Object.keys(colorConvert);
  4884. for (var _i = 0; _i < _arr.length; _i++) {
  4885. var key = _arr[_i];
  4886. if (typeof colorConvert[key] !== 'object') {
  4887. continue;
  4888. }
  4889. var suite = colorConvert[key];
  4890. if ('ansi16' in suite) {
  4891. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  4892. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  4893. }
  4894. if ('ansi256' in suite) {
  4895. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  4896. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  4897. }
  4898. if ('rgb' in suite) {
  4899. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  4900. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  4901. }
  4902. }
  4903. return styles;
  4904. }
  4905. Object.defineProperty(module, 'exports', {
  4906. enumerable: true,
  4907. get: assembleStyles
  4908. });
  4909. });
  4910. var hasFlag = function hasFlag(flag, argv) {
  4911. argv = argv || process.argv;
  4912. var terminatorPos = argv.indexOf('--');
  4913. var prefix = /^-{1,2}/.test(flag) ? '' : '--';
  4914. var pos = argv.indexOf(prefix + flag);
  4915. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  4916. };
  4917. var supportsColor = createCommonjsModule(function (module) {
  4918. 'use strict';
  4919. var env = process.env;
  4920. var support = function support(level) {
  4921. if (level === 0) {
  4922. return false;
  4923. }
  4924. return {
  4925. level,
  4926. hasBasic: true,
  4927. has256: level >= 2,
  4928. has16m: level >= 3
  4929. };
  4930. };
  4931. var supportLevel = function () {
  4932. if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
  4933. return 0;
  4934. }
  4935. if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
  4936. return 3;
  4937. }
  4938. if (hasFlag('color=256')) {
  4939. return 2;
  4940. }
  4941. if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
  4942. return 1;
  4943. }
  4944. if (process.stdout && !process.stdout.isTTY) {
  4945. return 0;
  4946. }
  4947. if (process.platform === 'win32') {
  4948. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  4949. // libuv that enables 256 color output on Windows. Anything earlier and it
  4950. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  4951. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  4952. // release that supports 256 colors.
  4953. var osRelease = os.release().split('.');
  4954. if (Number(process.version.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  4955. return 2;
  4956. }
  4957. return 1;
  4958. }
  4959. if ('CI' in env) {
  4960. if ('TRAVIS' in env || env.CI === 'Travis' || 'CIRCLECI' in env) {
  4961. return 1;
  4962. }
  4963. return 0;
  4964. }
  4965. if ('TEAMCITY_VERSION' in env) {
  4966. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  4967. }
  4968. if ('TERM_PROGRAM' in env) {
  4969. var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  4970. switch (env.TERM_PROGRAM) {
  4971. case 'iTerm.app':
  4972. return version >= 3 ? 3 : 2;
  4973. case 'Hyper':
  4974. return 3;
  4975. case 'Apple_Terminal':
  4976. return 2;
  4977. // No default
  4978. }
  4979. }
  4980. if (/^(screen|xterm)-256(?:color)?/.test(env.TERM)) {
  4981. return 2;
  4982. }
  4983. if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) {
  4984. return 1;
  4985. }
  4986. if ('COLORTERM' in env) {
  4987. return 1;
  4988. }
  4989. if (env.TERM === 'dumb') {
  4990. return 0;
  4991. }
  4992. return 0;
  4993. }();
  4994. if ('FORCE_COLOR' in env) {
  4995. supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : supportLevel || 1;
  4996. }
  4997. module.exports = process && support(supportLevel);
  4998. });
  4999. var templates = createCommonjsModule(function (module) {
  5000. 'use strict';
  5001. var TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  5002. var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  5003. var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  5004. var ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  5005. var ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  5006. function unescape(c) {
  5007. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  5008. return String.fromCharCode(parseInt(c.slice(1), 16));
  5009. }
  5010. return ESCAPES.get(c) || c;
  5011. }
  5012. function parseArguments(name, args) {
  5013. var results = [];
  5014. var chunks = args.trim().split(/\s*,\s*/g);
  5015. var matches;
  5016. var _iteratorNormalCompletion = true;
  5017. var _didIteratorError = false;
  5018. var _iteratorError = undefined;
  5019. try {
  5020. for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5021. var chunk = _step.value;
  5022. if (!isNaN(chunk)) {
  5023. results.push(Number(chunk));
  5024. } else if (matches = chunk.match(STRING_REGEX)) {
  5025. results.push(matches[2].replace(ESCAPE_REGEX, function (m, escape, chr) {
  5026. return escape ? unescape(escape) : chr;
  5027. }));
  5028. } else {
  5029. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  5030. }
  5031. }
  5032. } catch (err) {
  5033. _didIteratorError = true;
  5034. _iteratorError = err;
  5035. } finally {
  5036. try {
  5037. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5038. _iterator.return();
  5039. }
  5040. } finally {
  5041. if (_didIteratorError) {
  5042. throw _iteratorError;
  5043. }
  5044. }
  5045. }
  5046. return results;
  5047. }
  5048. function parseStyle(style) {
  5049. STYLE_REGEX.lastIndex = 0;
  5050. var results = [];
  5051. var matches;
  5052. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  5053. var name = matches[1];
  5054. if (matches[2]) {
  5055. var args = parseArguments(name, matches[2]);
  5056. results.push([name].concat(args));
  5057. } else {
  5058. results.push([name]);
  5059. }
  5060. }
  5061. return results;
  5062. }
  5063. function buildStyle(chalk, styles) {
  5064. var enabled = {};
  5065. var _iteratorNormalCompletion2 = true;
  5066. var _didIteratorError2 = false;
  5067. var _iteratorError2 = undefined;
  5068. try {
  5069. for (var _iterator2 = styles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  5070. var layer = _step2.value;
  5071. var _iteratorNormalCompletion3 = true;
  5072. var _didIteratorError3 = false;
  5073. var _iteratorError3 = undefined;
  5074. try {
  5075. for (var _iterator3 = layer.styles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  5076. var style = _step3.value;
  5077. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  5078. }
  5079. } catch (err) {
  5080. _didIteratorError3 = true;
  5081. _iteratorError3 = err;
  5082. } finally {
  5083. try {
  5084. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  5085. _iterator3.return();
  5086. }
  5087. } finally {
  5088. if (_didIteratorError3) {
  5089. throw _iteratorError3;
  5090. }
  5091. }
  5092. }
  5093. }
  5094. } catch (err) {
  5095. _didIteratorError2 = true;
  5096. _iteratorError2 = err;
  5097. } finally {
  5098. try {
  5099. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  5100. _iterator2.return();
  5101. }
  5102. } finally {
  5103. if (_didIteratorError2) {
  5104. throw _iteratorError2;
  5105. }
  5106. }
  5107. }
  5108. var current = chalk;
  5109. var _arr = Object.keys(enabled);
  5110. for (var _i = 0; _i < _arr.length; _i++) {
  5111. var styleName = _arr[_i];
  5112. if (Array.isArray(enabled[styleName])) {
  5113. if (!(styleName in current)) {
  5114. throw new Error(`Unknown Chalk style: ${styleName}`);
  5115. }
  5116. if (enabled[styleName].length > 0) {
  5117. current = current[styleName].apply(current, enabled[styleName]);
  5118. } else {
  5119. current = current[styleName];
  5120. }
  5121. }
  5122. }
  5123. return current;
  5124. }
  5125. module.exports = function (chalk, tmp) {
  5126. var styles = [];
  5127. var chunks = [];
  5128. var chunk = []; // eslint-disable-next-line max-params
  5129. tmp.replace(TEMPLATE_REGEX, function (m, escapeChar, inverse, style, close, chr) {
  5130. if (escapeChar) {
  5131. chunk.push(unescape(escapeChar));
  5132. } else if (style) {
  5133. var str = chunk.join('');
  5134. chunk = [];
  5135. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  5136. styles.push({
  5137. inverse,
  5138. styles: parseStyle(style)
  5139. });
  5140. } else if (close) {
  5141. if (styles.length === 0) {
  5142. throw new Error('Found extraneous } in Chalk template literal');
  5143. }
  5144. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  5145. chunk = [];
  5146. styles.pop();
  5147. } else {
  5148. chunk.push(chr);
  5149. }
  5150. });
  5151. chunks.push(chunk.join(''));
  5152. if (styles.length > 0) {
  5153. var errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  5154. throw new Error(errMsg);
  5155. }
  5156. return chunks.join('');
  5157. };
  5158. });
  5159. var chalk = createCommonjsModule(function (module) {
  5160. 'use strict';
  5161. var isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  5162. var levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  5163. var skipModels = new Set(['gray']);
  5164. var styles = Object.create(null);
  5165. function applyOptions(obj, options) {
  5166. options = options || {}; // Detect level if not set manually
  5167. var scLevel = supportsColor ? supportsColor.level : 0;
  5168. obj.level = options.level === undefined ? scLevel : options.level;
  5169. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  5170. }
  5171. function Chalk(options) {
  5172. // We check for this.template here since calling `chalk.constructor()`
  5173. // by itself will have a `this` of a previously constructed chalk object
  5174. if (!this || !(this instanceof Chalk) || this.template) {
  5175. var _chalk = {};
  5176. applyOptions(_chalk, options);
  5177. _chalk.template = function () {
  5178. var args = [].slice.call(arguments);
  5179. return chalkTag.apply(null, [_chalk.template].concat(args));
  5180. };
  5181. Object.setPrototypeOf(_chalk, Chalk.prototype);
  5182. Object.setPrototypeOf(_chalk.template, _chalk);
  5183. _chalk.template.constructor = Chalk;
  5184. return _chalk.template;
  5185. }
  5186. applyOptions(this, options);
  5187. } // Use bright blue on Windows as the normal blue color is illegible
  5188. if (isSimpleWindowsTerm) {
  5189. ansiStyles.blue.open = '\u001B[94m';
  5190. }
  5191. var _arr = Object.keys(ansiStyles);
  5192. var _loop = function _loop() {
  5193. var key = _arr[_i];
  5194. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  5195. styles[key] = {
  5196. get() {
  5197. var codes = ansiStyles[key];
  5198. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  5199. }
  5200. };
  5201. };
  5202. for (var _i = 0; _i < _arr.length; _i++) {
  5203. _loop();
  5204. }
  5205. styles.visible = {
  5206. get() {
  5207. return build.call(this, this._styles || [], true, 'visible');
  5208. }
  5209. };
  5210. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  5211. var _arr2 = Object.keys(ansiStyles.color.ansi);
  5212. var _loop2 = function _loop2() {
  5213. var model = _arr2[_i2];
  5214. if (skipModels.has(model)) {
  5215. return "continue";
  5216. }
  5217. styles[model] = {
  5218. get() {
  5219. var level = this.level;
  5220. return function () {
  5221. var open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  5222. var codes = {
  5223. open,
  5224. close: ansiStyles.color.close,
  5225. closeRe: ansiStyles.color.closeRe
  5226. };
  5227. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  5228. };
  5229. }
  5230. };
  5231. };
  5232. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  5233. var _ret = _loop2();
  5234. if (_ret === "continue") continue;
  5235. }
  5236. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  5237. var _arr3 = Object.keys(ansiStyles.bgColor.ansi);
  5238. var _loop3 = function _loop3() {
  5239. var model = _arr3[_i3];
  5240. if (skipModels.has(model)) {
  5241. return "continue";
  5242. }
  5243. var bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  5244. styles[bgModel] = {
  5245. get() {
  5246. var level = this.level;
  5247. return function () {
  5248. var open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  5249. var codes = {
  5250. open,
  5251. close: ansiStyles.bgColor.close,
  5252. closeRe: ansiStyles.bgColor.closeRe
  5253. };
  5254. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  5255. };
  5256. }
  5257. };
  5258. };
  5259. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  5260. var _ret2 = _loop3();
  5261. if (_ret2 === "continue") continue;
  5262. }
  5263. var proto = Object.defineProperties(function () {}, styles);
  5264. function build(_styles, _empty, key) {
  5265. var builder = function builder() {
  5266. return applyStyle.apply(builder, arguments);
  5267. };
  5268. builder._styles = _styles;
  5269. builder._empty = _empty;
  5270. var self = this;
  5271. Object.defineProperty(builder, 'level', {
  5272. enumerable: true,
  5273. get() {
  5274. return self.level;
  5275. },
  5276. set(level) {
  5277. self.level = level;
  5278. }
  5279. });
  5280. Object.defineProperty(builder, 'enabled', {
  5281. enumerable: true,
  5282. get() {
  5283. return self.enabled;
  5284. },
  5285. set(enabled) {
  5286. self.enabled = enabled;
  5287. }
  5288. }); // See below for fix regarding invisible grey/dim combination on Windows
  5289. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  5290. // no way to create a function with a different prototype
  5291. builder.__proto__ = proto; // eslint-disable-line no-proto
  5292. return builder;
  5293. }
  5294. function applyStyle() {
  5295. // Support varags, but simply cast to string in case there's only one arg
  5296. var args = arguments;
  5297. var argsLen = args.length;
  5298. var str = String(arguments[0]);
  5299. if (argsLen === 0) {
  5300. return '';
  5301. }
  5302. if (argsLen > 1) {
  5303. // Don't slice `arguments`, it prevents V8 optimizations
  5304. for (var a = 1; a < argsLen; a++) {
  5305. str += ' ' + args[a];
  5306. }
  5307. }
  5308. if (!this.enabled || this.level <= 0 || !str) {
  5309. return this._empty ? '' : str;
  5310. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  5311. // see https://github.com/chalk/chalk/issues/58
  5312. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  5313. var originalDim = ansiStyles.dim.open;
  5314. if (isSimpleWindowsTerm && this.hasGrey) {
  5315. ansiStyles.dim.open = '';
  5316. }
  5317. var _iteratorNormalCompletion = true;
  5318. var _didIteratorError = false;
  5319. var _iteratorError = undefined;
  5320. try {
  5321. for (var _iterator = this._styles.slice().reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5322. var code = _step.value;
  5323. // Replace any instances already present with a re-opening code
  5324. // otherwise only the part of the string until said closing code
  5325. // will be colored, and the rest will simply be 'plain'.
  5326. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  5327. // after next line to fix a bleed issue on macOS
  5328. // https://github.com/chalk/chalk/pull/92
  5329. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  5330. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  5331. } catch (err) {
  5332. _didIteratorError = true;
  5333. _iteratorError = err;
  5334. } finally {
  5335. try {
  5336. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5337. _iterator.return();
  5338. }
  5339. } finally {
  5340. if (_didIteratorError) {
  5341. throw _iteratorError;
  5342. }
  5343. }
  5344. }
  5345. ansiStyles.dim.open = originalDim;
  5346. return str;
  5347. }
  5348. function chalkTag(chalk, strings) {
  5349. if (!Array.isArray(strings)) {
  5350. // If chalk() was called by itself or with a string,
  5351. // return the string itself as a string.
  5352. return [].slice.call(arguments, 1).join(' ');
  5353. }
  5354. var args = [].slice.call(arguments, 2);
  5355. var parts = [strings.raw[0]];
  5356. for (var i = 1; i < strings.length; i++) {
  5357. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  5358. parts.push(String(strings.raw[i]));
  5359. }
  5360. return templates(chalk, parts.join(''));
  5361. }
  5362. Object.defineProperties(Chalk.prototype, styles);
  5363. module.exports = Chalk(); // eslint-disable-line new-cap
  5364. module.exports.supportsColor = supportsColor;
  5365. module.exports.default = module.exports; // For TypeScript
  5366. });
  5367. var lib$2 = createCommonjsModule(function (module, exports) {
  5368. "use strict";
  5369. Object.defineProperty(exports, "__esModule", {
  5370. value: true
  5371. });
  5372. exports.shouldHighlight = shouldHighlight;
  5373. exports.getChalk = getChalk;
  5374. exports.default = highlight;
  5375. function _jsTokens() {
  5376. var data = _interopRequireWildcard$$1(jsTokens);
  5377. _jsTokens = function _jsTokens() {
  5378. return data;
  5379. };
  5380. return data;
  5381. }
  5382. function _esutils() {
  5383. var data = _interopRequireDefault$$1(utils);
  5384. _esutils = function _esutils() {
  5385. return data;
  5386. };
  5387. return data;
  5388. }
  5389. function _chalk() {
  5390. var data = _interopRequireDefault$$1(chalk);
  5391. _chalk = function _chalk() {
  5392. return data;
  5393. };
  5394. return data;
  5395. }
  5396. function _interopRequireDefault$$1(obj) {
  5397. return obj && obj.__esModule ? obj : {
  5398. default: obj
  5399. };
  5400. }
  5401. function _interopRequireWildcard$$1(obj) {
  5402. if (obj && obj.__esModule) {
  5403. return obj;
  5404. } else {
  5405. var newObj = {};
  5406. if (obj != null) {
  5407. for (var key in obj) {
  5408. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  5409. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
  5410. if (desc.get || desc.set) {
  5411. Object.defineProperty(newObj, key, desc);
  5412. } else {
  5413. newObj[key] = obj[key];
  5414. }
  5415. }
  5416. }
  5417. }
  5418. newObj.default = obj;
  5419. return newObj;
  5420. }
  5421. }
  5422. function getDefs(chalk$$1) {
  5423. return {
  5424. keyword: chalk$$1.cyan,
  5425. capitalized: chalk$$1.yellow,
  5426. jsx_tag: chalk$$1.yellow,
  5427. punctuator: chalk$$1.yellow,
  5428. number: chalk$$1.magenta,
  5429. string: chalk$$1.green,
  5430. regex: chalk$$1.magenta,
  5431. comment: chalk$$1.grey,
  5432. invalid: chalk$$1.white.bgRed.bold
  5433. };
  5434. }
  5435. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  5436. var JSX_TAG = /^[a-z][\w-]*$/i;
  5437. var BRACKET = /^[()[\]{}]$/;
  5438. function getTokenType(match) {
  5439. var _match$slice = match.slice(-2),
  5440. _match$slice2 = _slicedToArray(_match$slice, 2),
  5441. offset = _match$slice2[0],
  5442. text = _match$slice2[1];
  5443. var token = (0, _jsTokens().matchToToken)(match);
  5444. if (token.type === "name") {
  5445. if (_esutils().default.keyword.isReservedWordES6(token.value)) {
  5446. return "keyword";
  5447. }
  5448. if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
  5449. return "jsx_tag";
  5450. }
  5451. if (token.value[0] !== token.value[0].toLowerCase()) {
  5452. return "capitalized";
  5453. }
  5454. }
  5455. if (token.type === "punctuator" && BRACKET.test(token.value)) {
  5456. return "bracket";
  5457. }
  5458. if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
  5459. return "punctuator";
  5460. }
  5461. return token.type;
  5462. }
  5463. function highlightTokens(defs, text) {
  5464. return text.replace(_jsTokens().default, function () {
  5465. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  5466. args[_key] = arguments[_key];
  5467. }
  5468. var type = getTokenType(args);
  5469. var colorize = defs[type];
  5470. if (colorize) {
  5471. return args[0].split(NEWLINE).map(function (str) {
  5472. return colorize(str);
  5473. }).join("\n");
  5474. } else {
  5475. return args[0];
  5476. }
  5477. });
  5478. }
  5479. function shouldHighlight(options) {
  5480. return _chalk().default.supportsColor || options.forceColor;
  5481. }
  5482. function getChalk(options) {
  5483. var chalk$$1 = _chalk().default;
  5484. if (options.forceColor) {
  5485. chalk$$1 = new (_chalk().default.constructor)({
  5486. enabled: true,
  5487. level: 1
  5488. });
  5489. }
  5490. return chalk$$1;
  5491. }
  5492. function highlight(code) {
  5493. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  5494. if (shouldHighlight(options)) {
  5495. var chalk$$1 = getChalk(options);
  5496. var defs = getDefs(chalk$$1);
  5497. return highlightTokens(defs, code);
  5498. } else {
  5499. return code;
  5500. }
  5501. }
  5502. });
  5503. unwrapExports(lib$2);
  5504. var lib$1 = createCommonjsModule(function (module, exports) {
  5505. "use strict";
  5506. Object.defineProperty(exports, "__esModule", {
  5507. value: true
  5508. });
  5509. exports.codeFrameColumns = codeFrameColumns;
  5510. exports.default = _default;
  5511. function _highlight() {
  5512. var data = _interopRequireWildcard(lib$2);
  5513. _highlight = function _highlight() {
  5514. return data;
  5515. };
  5516. return data;
  5517. }
  5518. function _interopRequireWildcard(obj) {
  5519. if (obj && obj.__esModule) {
  5520. return obj;
  5521. } else {
  5522. var newObj = {};
  5523. if (obj != null) {
  5524. for (var key in obj) {
  5525. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  5526. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
  5527. if (desc.get || desc.set) {
  5528. Object.defineProperty(newObj, key, desc);
  5529. } else {
  5530. newObj[key] = obj[key];
  5531. }
  5532. }
  5533. }
  5534. }
  5535. newObj.default = obj;
  5536. return newObj;
  5537. }
  5538. }
  5539. var deprecationWarningShown = false;
  5540. function getDefs(chalk) {
  5541. return {
  5542. gutter: chalk.grey,
  5543. marker: chalk.red.bold,
  5544. message: chalk.red.bold
  5545. };
  5546. }
  5547. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  5548. function getMarkerLines(loc, source, opts) {
  5549. var startLoc = Object.assign({
  5550. column: 0,
  5551. line: -1
  5552. }, loc.start);
  5553. var endLoc = Object.assign({}, startLoc, loc.end);
  5554. var _ref = opts || {},
  5555. _ref$linesAbove = _ref.linesAbove,
  5556. linesAbove = _ref$linesAbove === void 0 ? 2 : _ref$linesAbove,
  5557. _ref$linesBelow = _ref.linesBelow,
  5558. linesBelow = _ref$linesBelow === void 0 ? 3 : _ref$linesBelow;
  5559. var startLine = startLoc.line;
  5560. var startColumn = startLoc.column;
  5561. var endLine = endLoc.line;
  5562. var endColumn = endLoc.column;
  5563. var start = Math.max(startLine - (linesAbove + 1), 0);
  5564. var end = Math.min(source.length, endLine + linesBelow);
  5565. if (startLine === -1) {
  5566. start = 0;
  5567. }
  5568. if (endLine === -1) {
  5569. end = source.length;
  5570. }
  5571. var lineDiff = endLine - startLine;
  5572. var markerLines = {};
  5573. if (lineDiff) {
  5574. for (var i = 0; i <= lineDiff; i++) {
  5575. var lineNumber = i + startLine;
  5576. if (!startColumn) {
  5577. markerLines[lineNumber] = true;
  5578. } else if (i === 0) {
  5579. var sourceLength = source[lineNumber - 1].length;
  5580. markerLines[lineNumber] = [startColumn, sourceLength - startColumn];
  5581. } else if (i === lineDiff) {
  5582. markerLines[lineNumber] = [0, endColumn];
  5583. } else {
  5584. var _sourceLength = source[lineNumber - i].length;
  5585. markerLines[lineNumber] = [0, _sourceLength];
  5586. }
  5587. }
  5588. } else {
  5589. if (startColumn === endColumn) {
  5590. if (startColumn) {
  5591. markerLines[startLine] = [startColumn, 0];
  5592. } else {
  5593. markerLines[startLine] = true;
  5594. }
  5595. } else {
  5596. markerLines[startLine] = [startColumn, endColumn - startColumn];
  5597. }
  5598. }
  5599. return {
  5600. start,
  5601. end,
  5602. markerLines
  5603. };
  5604. }
  5605. function codeFrameColumns(rawLines, loc) {
  5606. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  5607. var highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight().shouldHighlight)(opts);
  5608. var chalk = (0, _highlight().getChalk)(opts);
  5609. var defs = getDefs(chalk);
  5610. var maybeHighlight = function maybeHighlight(chalkFn, string) {
  5611. return highlighted ? chalkFn(string) : string;
  5612. };
  5613. if (highlighted) rawLines = (0, _highlight().default)(rawLines, opts);
  5614. var lines = rawLines.split(NEWLINE);
  5615. var _getMarkerLines = getMarkerLines(loc, lines, opts),
  5616. start = _getMarkerLines.start,
  5617. end = _getMarkerLines.end,
  5618. markerLines = _getMarkerLines.markerLines;
  5619. var hasColumns = loc.start && typeof loc.start.column === "number";
  5620. var numberMaxWidth = String(end).length;
  5621. var frame = lines.slice(start, end).map(function (line, index) {
  5622. var number = start + 1 + index;
  5623. var paddedNumber = ` ${number}`.slice(-numberMaxWidth);
  5624. var gutter = ` ${paddedNumber} | `;
  5625. var hasMarker = markerLines[number];
  5626. var lastMarkerLine = !markerLines[number + 1];
  5627. if (hasMarker) {
  5628. var markerLine = "";
  5629. if (Array.isArray(hasMarker)) {
  5630. var markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  5631. var numberOfMarkers = hasMarker[1] || 1;
  5632. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  5633. if (lastMarkerLine && opts.message) {
  5634. markerLine += " " + maybeHighlight(defs.message, opts.message);
  5635. }
  5636. }
  5637. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
  5638. } else {
  5639. return ` ${maybeHighlight(defs.gutter, gutter)}${line}`;
  5640. }
  5641. }).join("\n");
  5642. if (opts.message && !hasColumns) {
  5643. frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
  5644. }
  5645. if (highlighted) {
  5646. return chalk.reset(frame);
  5647. } else {
  5648. return frame;
  5649. }
  5650. }
  5651. function _default(rawLines, lineNumber, colNumber) {
  5652. var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  5653. if (!deprecationWarningShown) {
  5654. deprecationWarningShown = true;
  5655. var message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
  5656. if (process.emitWarning) {
  5657. process.emitWarning(message, "DeprecationWarning");
  5658. } else {
  5659. var deprecationError = new Error(message);
  5660. deprecationError.name = "DeprecationWarning";
  5661. console.warn(new Error(message));
  5662. }
  5663. }
  5664. colNumber = Math.max(colNumber, 0);
  5665. var location = {
  5666. start: {
  5667. column: colNumber,
  5668. line: lineNumber
  5669. }
  5670. };
  5671. return codeFrameColumns(rawLines, location, opts);
  5672. }
  5673. });
  5674. unwrapExports(lib$1);
  5675. var ConfigError$1 = errors.ConfigError;
  5676. var locStart = loc.locStart;
  5677. var locEnd = loc.locEnd; // Use defineProperties()/getOwnPropertyDescriptor() to prevent
  5678. // triggering the parsers getters.
  5679. var ownNames = Object.getOwnPropertyNames;
  5680. var ownDescriptor = Object.getOwnPropertyDescriptor;
  5681. function getParsers(options) {
  5682. var parsers = {};
  5683. var _iteratorNormalCompletion = true;
  5684. var _didIteratorError = false;
  5685. var _iteratorError = undefined;
  5686. try {
  5687. for (var _iterator = options.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5688. var plugin = _step.value;
  5689. if (!plugin.parsers) {
  5690. continue;
  5691. }
  5692. var _iteratorNormalCompletion2 = true;
  5693. var _didIteratorError2 = false;
  5694. var _iteratorError2 = undefined;
  5695. try {
  5696. for (var _iterator2 = ownNames(plugin.parsers)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  5697. var name = _step2.value;
  5698. Object.defineProperty(parsers, name, ownDescriptor(plugin.parsers, name));
  5699. }
  5700. } catch (err) {
  5701. _didIteratorError2 = true;
  5702. _iteratorError2 = err;
  5703. } finally {
  5704. try {
  5705. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  5706. _iterator2.return();
  5707. }
  5708. } finally {
  5709. if (_didIteratorError2) {
  5710. throw _iteratorError2;
  5711. }
  5712. }
  5713. }
  5714. }
  5715. } catch (err) {
  5716. _didIteratorError = true;
  5717. _iteratorError = err;
  5718. } finally {
  5719. try {
  5720. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5721. _iterator.return();
  5722. }
  5723. } finally {
  5724. if (_didIteratorError) {
  5725. throw _iteratorError;
  5726. }
  5727. }
  5728. }
  5729. return parsers;
  5730. }
  5731. function resolveParser$1(opts, parsers) {
  5732. parsers = parsers || getParsers(opts);
  5733. if (typeof opts.parser === "function") {
  5734. // Custom parser API always works with JavaScript.
  5735. return {
  5736. parse: opts.parser,
  5737. astFormat: "estree",
  5738. locStart,
  5739. locEnd
  5740. };
  5741. }
  5742. if (typeof opts.parser === "string") {
  5743. if (parsers.hasOwnProperty(opts.parser)) {
  5744. return parsers[opts.parser];
  5745. }
  5746. try {
  5747. return {
  5748. parse: require(path.resolve(process.cwd(), opts.parser)),
  5749. astFormat: "estree",
  5750. locStart,
  5751. locEnd
  5752. };
  5753. } catch (err) {
  5754. /* istanbul ignore next */
  5755. throw new ConfigError$1(`Couldn't resolve parser "${opts.parser}"`);
  5756. }
  5757. }
  5758. }
  5759. function parse$2(text, opts) {
  5760. var parsers = getParsers(opts); // Create a new object {parserName: parseFn}. Uses defineProperty() to only call
  5761. // the parsers getters when actually calling the parser `parse` function.
  5762. var parsersForCustomParserApi = Object.keys(parsers).reduce(function (object, parserName) {
  5763. return Object.defineProperty(object, parserName, {
  5764. enumerable: true,
  5765. get() {
  5766. return parsers[parserName].parse;
  5767. }
  5768. });
  5769. }, {});
  5770. var parser = resolveParser$1(opts, parsers);
  5771. try {
  5772. if (parser.preprocess) {
  5773. text = parser.preprocess(text, opts);
  5774. }
  5775. return {
  5776. text,
  5777. ast: parser.parse(text, parsersForCustomParserApi, opts)
  5778. };
  5779. } catch (error) {
  5780. var loc$$1 = error.loc;
  5781. if (loc$$1) {
  5782. var codeFrame = lib$1;
  5783. error.codeFrame = codeFrame.codeFrameColumns(text, loc$$1, {
  5784. highlightCode: true
  5785. });
  5786. error.message += "\n" + error.codeFrame;
  5787. throw error;
  5788. }
  5789. /* istanbul ignore next */
  5790. throw error.stack;
  5791. }
  5792. }
  5793. var parser = {
  5794. parse: parse$2,
  5795. resolveParser: resolveParser$1
  5796. };
  5797. var UndefinedParserError = errors.UndefinedParserError;
  5798. var getSupportInfo$1 = support.getSupportInfo;
  5799. var resolveParser = parser.resolveParser;
  5800. var hiddenDefaults = {
  5801. astFormat: "estree",
  5802. printer: {},
  5803. locStart: null,
  5804. locEnd: null
  5805. }; // Copy options and fill in default values.
  5806. function normalize(options, opts) {
  5807. opts = opts || {};
  5808. var rawOptions = Object.assign({}, options);
  5809. var supportOptions = getSupportInfo$1(null, {
  5810. plugins: options.plugins,
  5811. showUnreleased: true,
  5812. showDeprecated: true
  5813. }).options;
  5814. var defaults = supportOptions.reduce(function (reduced, optionInfo) {
  5815. return Object.assign(reduced, {
  5816. [optionInfo.name]: optionInfo.default
  5817. });
  5818. }, Object.assign({}, hiddenDefaults));
  5819. if (!rawOptions.parser) {
  5820. if (!rawOptions.filepath) {
  5821. var logger = opts.logger || console;
  5822. logger.warn("No parser and no filepath given, using 'babylon' the parser now " + "but this will throw an error in the future. " + "Please specify a parser or a filepath so one can be inferred.");
  5823. rawOptions.parser = "babylon";
  5824. } else {
  5825. rawOptions.parser = inferParser(rawOptions.filepath, rawOptions.plugins);
  5826. if (!rawOptions.parser) {
  5827. throw new UndefinedParserError(`No parser could be inferred for file: ${rawOptions.filepath}`);
  5828. }
  5829. }
  5830. }
  5831. var parser$$1 = resolveParser(optionsNormalizer.normalizeApiOptions(rawOptions, [supportOptions.find(function (x) {
  5832. return x.name === "parser";
  5833. })], {
  5834. passThrough: true,
  5835. logger: false
  5836. }));
  5837. rawOptions.astFormat = parser$$1.astFormat;
  5838. rawOptions.locEnd = parser$$1.locEnd;
  5839. rawOptions.locStart = parser$$1.locStart;
  5840. var plugin = getPlugin(rawOptions);
  5841. rawOptions.printer = plugin.printers[rawOptions.astFormat];
  5842. var pluginDefaults = supportOptions.filter(function (optionInfo) {
  5843. return optionInfo.pluginDefaults && optionInfo.pluginDefaults[plugin.name];
  5844. }).reduce(function (reduced, optionInfo) {
  5845. return Object.assign(reduced, {
  5846. [optionInfo.name]: optionInfo.pluginDefaults[plugin.name]
  5847. });
  5848. }, {});
  5849. var mixedDefaults = Object.assign({}, defaults, pluginDefaults);
  5850. Object.keys(mixedDefaults).forEach(function (k) {
  5851. if (rawOptions[k] == null) {
  5852. rawOptions[k] = mixedDefaults[k];
  5853. }
  5854. });
  5855. if (rawOptions.parser === "json") {
  5856. rawOptions.trailingComma = "none";
  5857. }
  5858. return optionsNormalizer.normalizeApiOptions(rawOptions, supportOptions, Object.assign({
  5859. passThrough: Object.keys(hiddenDefaults)
  5860. }, opts));
  5861. }
  5862. function getPlugin(options) {
  5863. var astFormat = options.astFormat;
  5864. if (!astFormat) {
  5865. throw new Error("getPlugin() requires astFormat to be set");
  5866. }
  5867. var printerPlugin = options.plugins.find(function (plugin) {
  5868. return plugin.printers && plugin.printers[astFormat];
  5869. });
  5870. if (!printerPlugin) {
  5871. throw new Error(`Couldn't find plugin for AST format "${astFormat}"`);
  5872. }
  5873. return printerPlugin;
  5874. }
  5875. function inferParser(filepath, plugins) {
  5876. var extension = path.extname(filepath);
  5877. var filename = path.basename(filepath).toLowerCase();
  5878. var language = getSupportInfo$1(null, {
  5879. plugins
  5880. }).languages.find(function (language) {
  5881. return language.since !== null && (language.extensions && language.extensions.indexOf(extension) > -1 || language.filenames && language.filenames.find(function (name) {
  5882. return name.toLowerCase() === filename;
  5883. }));
  5884. });
  5885. return language && language.parsers[0];
  5886. }
  5887. var options = {
  5888. normalize,
  5889. hiddenDefaults,
  5890. inferParser
  5891. };
  5892. function massageAST(ast, options, parent) {
  5893. if (Array.isArray(ast)) {
  5894. return ast.map(function (e) {
  5895. return massageAST(e, options, parent);
  5896. }).filter(function (e) {
  5897. return e;
  5898. });
  5899. }
  5900. if (!ast || typeof ast !== "object") {
  5901. return ast;
  5902. }
  5903. var newObj = {};
  5904. var _arr = Object.keys(ast);
  5905. for (var _i = 0; _i < _arr.length; _i++) {
  5906. var key = _arr[_i];
  5907. if (typeof ast[key] !== "function") {
  5908. newObj[key] = massageAST(ast[key], options, ast);
  5909. }
  5910. }
  5911. if (options.printer.massageAstNode) {
  5912. var result = options.printer.massageAstNode(ast, newObj, parent);
  5913. if (result === null) {
  5914. return undefined;
  5915. }
  5916. if (result) {
  5917. return result;
  5918. }
  5919. }
  5920. return newObj;
  5921. }
  5922. var massageAst = massageAST;
  5923. function assertDoc(val) {
  5924. /* istanbul ignore if */
  5925. if (!(typeof val === "string" || val != null && typeof val.type === "string")) {
  5926. throw new Error("Value " + JSON.stringify(val) + " is not a valid document");
  5927. }
  5928. }
  5929. function concat$1(parts) {
  5930. if (process.env.NODE_ENV !== "production") {
  5931. parts.forEach(assertDoc);
  5932. } // We cannot do this until we change `printJSXElement` to not
  5933. // access the internals of a document directly.
  5934. // if(parts.length === 1) {
  5935. // // If it's a single document, no need to concat it.
  5936. // return parts[0];
  5937. // }
  5938. return {
  5939. type: "concat",
  5940. parts
  5941. };
  5942. }
  5943. function indent$1(contents) {
  5944. if (process.env.NODE_ENV !== "production") {
  5945. assertDoc(contents);
  5946. }
  5947. return {
  5948. type: "indent",
  5949. contents
  5950. };
  5951. }
  5952. function align(n, contents) {
  5953. if (process.env.NODE_ENV !== "production") {
  5954. assertDoc(contents);
  5955. }
  5956. return {
  5957. type: "align",
  5958. contents,
  5959. n
  5960. };
  5961. }
  5962. function group(contents, opts) {
  5963. opts = opts || {};
  5964. if (process.env.NODE_ENV !== "production") {
  5965. assertDoc(contents);
  5966. }
  5967. return {
  5968. type: "group",
  5969. contents: contents,
  5970. break: !!opts.shouldBreak,
  5971. expandedStates: opts.expandedStates
  5972. };
  5973. }
  5974. function dedentToRoot(contents) {
  5975. return align(-Infinity, contents);
  5976. }
  5977. function markAsRoot(contents) {
  5978. return align({
  5979. type: "root"
  5980. }, contents);
  5981. }
  5982. function dedent$1(contents) {
  5983. return align(-1, contents);
  5984. }
  5985. function conditionalGroup(states, opts) {
  5986. return group(states[0], Object.assign(opts || {}, {
  5987. expandedStates: states
  5988. }));
  5989. }
  5990. function fill(parts) {
  5991. if (process.env.NODE_ENV !== "production") {
  5992. parts.forEach(assertDoc);
  5993. }
  5994. return {
  5995. type: "fill",
  5996. parts
  5997. };
  5998. }
  5999. function ifBreak(breakContents, flatContents) {
  6000. if (process.env.NODE_ENV !== "production") {
  6001. if (breakContents) {
  6002. assertDoc(breakContents);
  6003. }
  6004. if (flatContents) {
  6005. assertDoc(flatContents);
  6006. }
  6007. }
  6008. return {
  6009. type: "if-break",
  6010. breakContents,
  6011. flatContents
  6012. };
  6013. }
  6014. function lineSuffix$1(contents) {
  6015. if (process.env.NODE_ENV !== "production") {
  6016. assertDoc(contents);
  6017. }
  6018. return {
  6019. type: "line-suffix",
  6020. contents
  6021. };
  6022. }
  6023. var lineSuffixBoundary = {
  6024. type: "line-suffix-boundary"
  6025. };
  6026. var breakParent$1 = {
  6027. type: "break-parent"
  6028. };
  6029. var line$2 = {
  6030. type: "line"
  6031. };
  6032. var softline = {
  6033. type: "line",
  6034. soft: true
  6035. };
  6036. var hardline$1 = concat$1([{
  6037. type: "line",
  6038. hard: true
  6039. }, breakParent$1]);
  6040. var literalline = concat$1([{
  6041. type: "line",
  6042. hard: true,
  6043. literal: true
  6044. }, breakParent$1]);
  6045. var cursor$1 = {
  6046. type: "cursor",
  6047. placeholder: Symbol("cursor")
  6048. };
  6049. function join$1(sep, arr) {
  6050. var res = [];
  6051. for (var i = 0; i < arr.length; i++) {
  6052. if (i !== 0) {
  6053. res.push(sep);
  6054. }
  6055. res.push(arr[i]);
  6056. }
  6057. return concat$1(res);
  6058. }
  6059. function addAlignmentToDoc(doc, size, tabWidth) {
  6060. var aligned = doc;
  6061. if (size > 0) {
  6062. // Use indent to add tabs for all the levels of tabs we need
  6063. for (var i = 0; i < Math.floor(size / tabWidth); ++i) {
  6064. aligned = indent$1(aligned);
  6065. } // Use align for all the spaces that are needed
  6066. aligned = align(size % tabWidth, aligned); // size is absolute from 0 and not relative to the current
  6067. // indentation, so we use -Infinity to reset the indentation to 0
  6068. aligned = align(-Infinity, aligned);
  6069. }
  6070. return aligned;
  6071. }
  6072. var docBuilders = {
  6073. concat: concat$1,
  6074. join: join$1,
  6075. line: line$2,
  6076. softline,
  6077. hardline: hardline$1,
  6078. literalline,
  6079. group,
  6080. conditionalGroup,
  6081. fill,
  6082. lineSuffix: lineSuffix$1,
  6083. lineSuffixBoundary,
  6084. cursor: cursor$1,
  6085. breakParent: breakParent$1,
  6086. ifBreak,
  6087. indent: indent$1,
  6088. align,
  6089. addAlignmentToDoc,
  6090. markAsRoot,
  6091. dedentToRoot,
  6092. dedent: dedent$1
  6093. };
  6094. var ansiRegex = createCommonjsModule(function (module) {
  6095. 'use strict';
  6096. module.exports = function () {
  6097. var pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))'].join('|');
  6098. return new RegExp(pattern, 'g');
  6099. };
  6100. });
  6101. var stripAnsi = function stripAnsi(input) {
  6102. return typeof input === 'string' ? input.replace(ansiRegex(), '') : input;
  6103. };
  6104. var isFullwidthCodePoint = createCommonjsModule(function (module) {
  6105. 'use strict';
  6106. /* eslint-disable yoda */
  6107. module.exports = function (x) {
  6108. if (Number.isNaN(x)) {
  6109. return false;
  6110. } // code points are derived from:
  6111. // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
  6112. if (x >= 0x1100 && (x <= 0x115f || // Hangul Jamo
  6113. x === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  6114. x === 0x232a || // RIGHT-POINTING ANGLE BRACKET
  6115. // CJK Radicals Supplement .. Enclosed CJK Letters and Months
  6116. 0x2e80 <= x && x <= 0x3247 && x !== 0x303f || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
  6117. 0x3250 <= x && x <= 0x4dbf || // CJK Unified Ideographs .. Yi Radicals
  6118. 0x4e00 <= x && x <= 0xa4c6 || // Hangul Jamo Extended-A
  6119. 0xa960 <= x && x <= 0xa97c || // Hangul Syllables
  6120. 0xac00 <= x && x <= 0xd7a3 || // CJK Compatibility Ideographs
  6121. 0xf900 <= x && x <= 0xfaff || // Vertical Forms
  6122. 0xfe10 <= x && x <= 0xfe19 || // CJK Compatibility Forms .. Small Form Variants
  6123. 0xfe30 <= x && x <= 0xfe6b || // Halfwidth and Fullwidth Forms
  6124. 0xff01 <= x && x <= 0xff60 || 0xffe0 <= x && x <= 0xffe6 || // Kana Supplement
  6125. 0x1b000 <= x && x <= 0x1b001 || // Enclosed Ideographic Supplement
  6126. 0x1f200 <= x && x <= 0x1f251 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
  6127. 0x20000 <= x && x <= 0x3fffd)) {
  6128. return true;
  6129. }
  6130. return false;
  6131. };
  6132. });
  6133. var stringWidth = createCommonjsModule(function (module) {
  6134. 'use strict';
  6135. module.exports = function (str) {
  6136. if (typeof str !== 'string' || str.length === 0) {
  6137. return 0;
  6138. }
  6139. str = stripAnsi(str);
  6140. var width = 0;
  6141. for (var i = 0; i < str.length; i++) {
  6142. var code = str.codePointAt(i); // Ignore control characters
  6143. if (code <= 0x1F || code >= 0x7F && code <= 0x9F) {
  6144. continue;
  6145. } // Ignore combining characters
  6146. if (code >= 0x300 && code <= 0x36F) {
  6147. continue;
  6148. } // Surrogates
  6149. if (code > 0xFFFF) {
  6150. i++;
  6151. }
  6152. width += isFullwidthCodePoint(code) ? 2 : 1;
  6153. }
  6154. return width;
  6155. };
  6156. });
  6157. var emojiRegex$1 = function emojiRegex() {
  6158. // https://mathiasbynens.be/notes/es-unicode-property-escapes#emoji
  6159. return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74)\uDB40\uDC7F|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC68(?:\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])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92])|(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2695\u2696\u2708]\uFE0F|(?:\uD83C[\uDFFB-\uDFFF])\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]))|\uD83D\uDC69\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])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])\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\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83D\uDC69\u200D[\u2695\u2696\u2708])\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC68(?:\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92])|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|(?:\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\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\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDD1-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC69\uDC6E\uDC70-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD18-\uDD1C\uDD1E\uDD1F\uDD26\uDD30-\uDD39\uDD3D\uDD3E\uDDD1-\uDDDD])(?:\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\uDEEB\uDEEC\uDEF4-\uDEF8]|\uD83E[\uDD10-\uDD3A\uDD3C-\uDD3E\uDD40-\uDD45\uDD47-\uDD4C\uDD50-\uDD6B\uDD80-\uDD97\uDDC0\uDDD0-\uDDE6])|(?:[#\*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\u2660\u2663\u2665\u2666\u2668\u267B\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\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEF8]|\uD83E[\uDD10-\uDD3A\uDD3C-\uDD3E\uDD40-\uDD45\uDD47-\uDD4C\uDD50-\uDD6B\uDD80-\uDD97\uDDC0\uDDD0-\uDDE6])\uFE0F/g;
  6160. };
  6161. var punctuation_ranges = [// http://www.unicode.org/charts/PDF/U3000.pdf CJK Symbols and Punctuation
  6162. [0x3000, 0x303f], // http://www.unicode.org/charts/PDF/UAC00.pdf Hangul Syllables
  6163. [0xac00, 0xd7af], // http://www.unicode.org/charts/PDF/UFE10.pdf Vertical Forms
  6164. [0xfe10, 0xfe1f], // http://www.unicode.org/charts/PDF/UFE30.pdf CJK Compatibility Forms
  6165. // http://www.unicode.org/charts/PDF/UFE50.pdf Small Form Variants
  6166. [0xfe30, 0xfe6f], // http://www.unicode.org/charts/PDF/UFF00.pdf Halfwidth and Fullwidth Forms
  6167. [0xff00, 0xff60], [0xffe0, 0xffef]];
  6168. var character_ranges = [// http://www.unicode.org/charts/PDF/U1100.pdf Hangul Jamo
  6169. [0x1100, 0x11ff], // http://www.unicode.org/charts/PDF/U2E80.pdf CJK Radicals Supplement
  6170. // http://www.unicode.org/charts/PDF/U2F00.pdf Kangxi Radicals
  6171. [0x2e80, 0x2fdf], // http://www.unicode.org/charts/PDF/U3040.pdf Hiragana
  6172. // http://www.unicode.org/charts/PDF/U30A0.pdf Katakana
  6173. // http://www.unicode.org/charts/PDF/U3100.pdf Bopomofo
  6174. // http://www.unicode.org/charts/PDF/U3130.pdf Hangul Compatibility Jamo
  6175. [0x3040, 0x318f], // http://www.unicode.org/charts/PDF/U3200.pdf Enclosed CJK Letters and Months
  6176. // http://www.unicode.org/charts/PDF/U3300.pdf CJK Compatibility
  6177. // http://www.unicode.org/charts/PDF/U3400.pdf CJK Unified Ideographs Extension A
  6178. [0x3200, 0x4dbf], // http://www.unicode.org/charts/PDF/U4E00.pdf CJK Unified Ideographs (Han)
  6179. [0x4e00, 0x9fff], // http://www.unicode.org/charts/PDF/UA960.pdf Hangul Jamo Extended-A
  6180. [0xa960, 0xa97f], // http://www.unicode.org/charts/PDF/UF900.pdf CJK Compatibility Ideographs
  6181. [0xf900, 0xfaff]];
  6182. function get_regex() {
  6183. return create_regex(character_ranges.concat(punctuation_ranges));
  6184. } // istanbul ignore next
  6185. // tslint:disable-next-line:no-namespace
  6186. (function (get_regex) {
  6187. function punctuations() {
  6188. return create_regex(punctuation_ranges);
  6189. }
  6190. get_regex.punctuations = punctuations;
  6191. function characters() {
  6192. return create_regex(character_ranges);
  6193. }
  6194. get_regex.characters = characters;
  6195. })(get_regex || (get_regex = {}));
  6196. function create_regex(ranges) {
  6197. return new RegExp("[" + ranges.map(get_bracket_content).reduce(function (a, b) {
  6198. return a + b;
  6199. }) + "]", 'g');
  6200. }
  6201. function get_bracket_content(range) {
  6202. return get_escaped_unicode(range[0]) + "-" + get_escaped_unicode(range[1]);
  6203. }
  6204. function get_escaped_unicode(num) {
  6205. return "\\u" + num.toString(16);
  6206. }
  6207. var lib$3 = get_regex;
  6208. var data_generated = createCommonjsModule(function (module, exports) {
  6209. "use strict";
  6210. exports.__esModule = true;
  6211. exports.get_data = function () {
  6212. return {
  6213. "Pc": [[95, 95], [8255, 8256], [8276, 8276], [65075, 65076], [65101, 65103], [65343, 65343]],
  6214. "Pe": [[41, 41], [93, 93], [125, 125], [3899, 3899], [3901, 3901], [5788, 5788], [8262, 8262], [8318, 8318], [8334, 8334], [8969, 8969], [8971, 8971], [9002, 9002], [10089, 10089], [10091, 10091], [10093, 10093], [10095, 10095], [10097, 10097], [10099, 10099], [10101, 10101], [10182, 10182], [10215, 10215], [10217, 10217], [10219, 10219], [10221, 10221], [10223, 10223], [10628, 10628], [10630, 10630], [10632, 10632], [10634, 10634], [10636, 10636], [10638, 10638], [10640, 10640], [10642, 10642], [10644, 10644], [10646, 10646], [10648, 10648], [10713, 10713], [10715, 10715], [10749, 10749], [11811, 11811], [11813, 11813], [11815, 11815], [11817, 11817], [12297, 12297], [12299, 12299], [12301, 12301], [12303, 12303], [12305, 12305], [12309, 12309], [12311, 12311], [12313, 12313], [12315, 12315], [12318, 12319], [64830, 64830], [65048, 65048], [65078, 65078], [65080, 65080], [65082, 65082], [65084, 65084], [65086, 65086], [65088, 65088], [65090, 65090], [65092, 65092], [65096, 65096], [65114, 65114], [65116, 65116], [65118, 65118], [65289, 65289], [65341, 65341], [65373, 65373], [65376, 65376], [65379, 65379]],
  6215. "Ps": [[40, 40], [91, 91], [123, 123], [3898, 3898], [3900, 3900], [5787, 5787], [8218, 8218], [8222, 8222], [8261, 8261], [8317, 8317], [8333, 8333], [8968, 8968], [8970, 8970], [9001, 9001], [10088, 10088], [10090, 10090], [10092, 10092], [10094, 10094], [10096, 10096], [10098, 10098], [10100, 10100], [10181, 10181], [10214, 10214], [10216, 10216], [10218, 10218], [10220, 10220], [10222, 10222], [10627, 10627], [10629, 10629], [10631, 10631], [10633, 10633], [10635, 10635], [10637, 10637], [10639, 10639], [10641, 10641], [10643, 10643], [10645, 10645], [10647, 10647], [10712, 10712], [10714, 10714], [10748, 10748], [11810, 11810], [11812, 11812], [11814, 11814], [11816, 11816], [11842, 11842], [12296, 12296], [12298, 12298], [12300, 12300], [12302, 12302], [12304, 12304], [12308, 12308], [12310, 12310], [12312, 12312], [12314, 12314], [12317, 12317], [64831, 64831], [65047, 65047], [65077, 65077], [65079, 65079], [65081, 65081], [65083, 65083], [65085, 65085], [65087, 65087], [65089, 65089], [65091, 65091], [65095, 65095], [65113, 65113], [65115, 65115], [65117, 65117], [65288, 65288], [65339, 65339], [65371, 65371], [65375, 65375], [65378, 65378]],
  6216. "Lm": [[688, 705], [710, 721], [736, 740], [748, 748], [750, 750], [884, 884], [890, 890], [1369, 1369], [1600, 1600], [1765, 1766], [2036, 2037], [2042, 2042], [2074, 2074], [2084, 2084], [2088, 2088], [2417, 2417], [3654, 3654], [3782, 3782], [4348, 4348], [6103, 6103], [6211, 6211], [6823, 6823], [7288, 7293], [7468, 7530], [7544, 7544], [7579, 7615], [8305, 8305], [8319, 8319], [8336, 8348], [11388, 11389], [11631, 11631], [11823, 11823], [12293, 12293], [12337, 12341], [12347, 12347], [12445, 12446], [12540, 12542], [40981, 40981], [42232, 42237], [42508, 42508], [42623, 42623], [42652, 42653], [42775, 42783], [42864, 42864], [42888, 42888], [43000, 43001], [43471, 43471], [43494, 43494], [43632, 43632], [43741, 43741], [43763, 43764], [43868, 43871], [65392, 65392], [65438, 65439]],
  6217. "Mc": [[2307, 2307], [2363, 2363], [2366, 2368], [2377, 2380], [2382, 2383], [2434, 2435], [2494, 2496], [2503, 2504], [2507, 2508], [2519, 2519], [2563, 2563], [2622, 2624], [2691, 2691], [2750, 2752], [2761, 2761], [2763, 2764], [2818, 2819], [2878, 2878], [2880, 2880], [2887, 2888], [2891, 2892], [2903, 2903], [3006, 3007], [3009, 3010], [3014, 3016], [3018, 3020], [3031, 3031], [3073, 3075], [3137, 3140], [3202, 3203], [3262, 3262], [3264, 3268], [3271, 3272], [3274, 3275], [3285, 3286], [3330, 3331], [3390, 3392], [3398, 3400], [3402, 3404], [3415, 3415], [3458, 3459], [3535, 3537], [3544, 3551], [3570, 3571], [3902, 3903], [3967, 3967], [4139, 4140], [4145, 4145], [4152, 4152], [4155, 4156], [4182, 4183], [4194, 4196], [4199, 4205], [4227, 4228], [4231, 4236], [4239, 4239], [4250, 4252], [6070, 6070], [6078, 6085], [6087, 6088], [6435, 6438], [6441, 6443], [6448, 6449], [6451, 6456], [6681, 6682], [6741, 6741], [6743, 6743], [6753, 6753], [6755, 6756], [6765, 6770], [6916, 6916], [6965, 6965], [6971, 6971], [6973, 6977], [6979, 6980], [7042, 7042], [7073, 7073], [7078, 7079], [7082, 7082], [7143, 7143], [7146, 7148], [7150, 7150], [7154, 7155], [7204, 7211], [7220, 7221], [7393, 7393], [7410, 7411], [7415, 7415], [12334, 12335], [43043, 43044], [43047, 43047], [43136, 43137], [43188, 43203], [43346, 43347], [43395, 43395], [43444, 43445], [43450, 43451], [43453, 43456], [43567, 43568], [43571, 43572], [43597, 43597], [43643, 43643], [43645, 43645], [43755, 43755], [43758, 43759], [43765, 43765], [44003, 44004], [44006, 44007], [44009, 44010], [44012, 44012]],
  6218. "Zp": [[8233, 8233]],
  6219. "Sc": [[36, 36], [162, 165], [1423, 1423], [1547, 1547], [2546, 2547], [2555, 2555], [2801, 2801], [3065, 3065], [3647, 3647], [6107, 6107], [8352, 8383], [43064, 43064], [65020, 65020], [65129, 65129], [65284, 65284], [65504, 65505], [65509, 65510]],
  6220. "Me": [[1160, 1161], [6846, 6846], [8413, 8416], [8418, 8420], [42608, 42610]],
  6221. "Sk": [[94, 94], [96, 96], [168, 168], [175, 175], [180, 180], [184, 184], [706, 709], [722, 735], [741, 747], [749, 749], [751, 767], [885, 885], [900, 901], [8125, 8125], [8127, 8129], [8141, 8143], [8157, 8159], [8173, 8175], [8189, 8190], [12443, 12444], [42752, 42774], [42784, 42785], [42889, 42890], [43867, 43867], [64434, 64449], [65342, 65342], [65344, 65344], [65507, 65507]],
  6222. "Cs": [[55296, 55296], [56191, 56192], [56319, 56320], [57343, 57343]],
  6223. "Nl": [[5870, 5872], [8544, 8578], [8581, 8584], [12295, 12295], [12321, 12329], [12344, 12346], [42726, 42735]],
  6224. "So": [[166, 166], [169, 169], [174, 174], [176, 176], [1154, 1154], [1421, 1422], [1550, 1551], [1758, 1758], [1769, 1769], [1789, 1790], [2038, 2038], [2554, 2554], [2928, 2928], [3059, 3064], [3066, 3066], [3199, 3199], [3407, 3407], [3449, 3449], [3841, 3843], [3859, 3859], [3861, 3863], [3866, 3871], [3892, 3892], [3894, 3894], [3896, 3896], [4030, 4037], [4039, 4044], [4046, 4047], [4053, 4056], [4254, 4255], [5008, 5017], [6464, 6464], [6622, 6655], [7009, 7018], [7028, 7036], [8448, 8449], [8451, 8454], [8456, 8457], [8468, 8468], [8470, 8471], [8478, 8483], [8485, 8485], [8487, 8487], [8489, 8489], [8494, 8494], [8506, 8507], [8522, 8522], [8524, 8525], [8527, 8527], [8586, 8587], [8597, 8601], [8604, 8607], [8609, 8610], [8612, 8613], [8615, 8621], [8623, 8653], [8656, 8657], [8659, 8659], [8661, 8691], [8960, 8967], [8972, 8991], [8994, 9000], [9003, 9083], [9085, 9114], [9140, 9179], [9186, 9254], [9280, 9290], [9372, 9449], [9472, 9654], [9656, 9664], [9666, 9719], [9728, 9838], [9840, 10087], [10132, 10175], [10240, 10495], [11008, 11055], [11077, 11078], [11085, 11123], [11126, 11157], [11160, 11193], [11197, 11208], [11210, 11218], [11244, 11247], [11493, 11498], [11904, 11929], [11931, 12019], [12032, 12245], [12272, 12283], [12292, 12292], [12306, 12307], [12320, 12320], [12342, 12343], [12350, 12351], [12688, 12689], [12694, 12703], [12736, 12771], [12800, 12830], [12842, 12871], [12880, 12880], [12896, 12927], [12938, 12976], [12992, 13054], [13056, 13311], [19904, 19967], [42128, 42182], [43048, 43051], [43062, 43063], [43065, 43065], [43639, 43641], [65021, 65021], [65508, 65508], [65512, 65512], [65517, 65518], [65532, 65533]],
  6225. "Lt": [[453, 453], [456, 456], [459, 459], [498, 498], [8072, 8079], [8088, 8095], [8104, 8111], [8124, 8124], [8140, 8140], [8188, 8188]],
  6226. "Zl": [[8232, 8232]],
  6227. "Lo": [[170, 170], [186, 186], [443, 443], [448, 451], [660, 660], [1488, 1514], [1520, 1522], [1568, 1599], [1601, 1610], [1646, 1647], [1649, 1747], [1749, 1749], [1774, 1775], [1786, 1788], [1791, 1791], [1808, 1808], [1810, 1839], [1869, 1957], [1969, 1969], [1994, 2026], [2048, 2069], [2112, 2136], [2144, 2154], [2208, 2228], [2230, 2237], [2308, 2361], [2365, 2365], [2384, 2384], [2392, 2401], [2418, 2432], [2437, 2444], [2447, 2448], [2451, 2472], [2474, 2480], [2482, 2482], [2486, 2489], [2493, 2493], [2510, 2510], [2524, 2525], [2527, 2529], [2544, 2545], [2556, 2556], [2565, 2570], [2575, 2576], [2579, 2600], [2602, 2608], [2610, 2611], [2613, 2614], [2616, 2617], [2649, 2652], [2654, 2654], [2674, 2676], [2693, 2701], [2703, 2705], [2707, 2728], [2730, 2736], [2738, 2739], [2741, 2745], [2749, 2749], [2768, 2768], [2784, 2785], [2809, 2809], [2821, 2828], [2831, 2832], [2835, 2856], [2858, 2864], [2866, 2867], [2869, 2873], [2877, 2877], [2908, 2909], [2911, 2913], [2929, 2929], [2947, 2947], [2949, 2954], [2958, 2960], [2962, 2965], [2969, 2970], [2972, 2972], [2974, 2975], [2979, 2980], [2984, 2986], [2990, 3001], [3024, 3024], [3077, 3084], [3086, 3088], [3090, 3112], [3114, 3129], [3133, 3133], [3160, 3162], [3168, 3169], [3200, 3200], [3205, 3212], [3214, 3216], [3218, 3240], [3242, 3251], [3253, 3257], [3261, 3261], [3294, 3294], [3296, 3297], [3313, 3314], [3333, 3340], [3342, 3344], [3346, 3386], [3389, 3389], [3406, 3406], [3412, 3414], [3423, 3425], [3450, 3455], [3461, 3478], [3482, 3505], [3507, 3515], [3517, 3517], [3520, 3526], [3585, 3632], [3634, 3635], [3648, 3653], [3713, 3714], [3716, 3716], [3719, 3720], [3722, 3722], [3725, 3725], [3732, 3735], [3737, 3743], [3745, 3747], [3749, 3749], [3751, 3751], [3754, 3755], [3757, 3760], [3762, 3763], [3773, 3773], [3776, 3780], [3804, 3807], [3840, 3840], [3904, 3911], [3913, 3948], [3976, 3980], [4096, 4138], [4159, 4159], [4176, 4181], [4186, 4189], [4193, 4193], [4197, 4198], [4206, 4208], [4213, 4225], [4238, 4238], [4304, 4346], [4349, 4680], [4682, 4685], [4688, 4694], [4696, 4696], [4698, 4701], [4704, 4744], [4746, 4749], [4752, 4784], [4786, 4789], [4792, 4798], [4800, 4800], [4802, 4805], [4808, 4822], [4824, 4880], [4882, 4885], [4888, 4954], [4992, 5007], [5121, 5740], [5743, 5759], [5761, 5786], [5792, 5866], [5873, 5880], [5888, 5900], [5902, 5905], [5920, 5937], [5952, 5969], [5984, 5996], [5998, 6000], [6016, 6067], [6108, 6108], [6176, 6210], [6212, 6263], [6272, 6276], [6279, 6312], [6314, 6314], [6320, 6389], [6400, 6430], [6480, 6509], [6512, 6516], [6528, 6571], [6576, 6601], [6656, 6678], [6688, 6740], [6917, 6963], [6981, 6987], [7043, 7072], [7086, 7087], [7098, 7141], [7168, 7203], [7245, 7247], [7258, 7287], [7401, 7404], [7406, 7409], [7413, 7414], [8501, 8504], [11568, 11623], [11648, 11670], [11680, 11686], [11688, 11694], [11696, 11702], [11704, 11710], [11712, 11718], [11720, 11726], [11728, 11734], [11736, 11742], [12294, 12294], [12348, 12348], [12353, 12438], [12447, 12447], [12449, 12538], [12543, 12543], [12549, 12590], [12593, 12686], [12704, 12730], [12784, 12799], [13312, 13312], [19893, 19893], [19968, 19968], [40938, 40938], [40960, 40980], [40982, 42124], [42192, 42231], [42240, 42507], [42512, 42527], [42538, 42539], [42606, 42606], [42656, 42725], [42895, 42895], [42999, 42999], [43003, 43009], [43011, 43013], [43015, 43018], [43020, 43042], [43072, 43123], [43138, 43187], [43250, 43255], [43259, 43259], [43261, 43261], [43274, 43301], [43312, 43334], [43360, 43388], [43396, 43442], [43488, 43492], [43495, 43503], [43514, 43518], [43520, 43560], [43584, 43586], [43588, 43595], [43616, 43631], [43633, 43638], [43642, 43642], [43646, 43695], [43697, 43697], [43701, 43702], [43705, 43709], [43712, 43712], [43714, 43714], [43739, 43740], [43744, 43754], [43762, 43762], [43777, 43782], [43785, 43790], [43793, 43798], [43808, 43814], [43816, 43822], [43968, 44002], [44032, 44032], [55203, 55203], [55216, 55238], [55243, 55291], [63744, 64109], [64112, 64217], [64285, 64285], [64287, 64296], [64298, 64310], [64312, 64316], [64318, 64318], [64320, 64321], [64323, 64324], [64326, 64433], [64467, 64829], [64848, 64911], [64914, 64967], [65008, 65019], [65136, 65140], [65142, 65276], [65382, 65391], [65393, 65437], [65440, 65470], [65474, 65479], [65482, 65487], [65490, 65495], [65498, 65500]],
  6228. "Mn": [[768, 879], [1155, 1159], [1425, 1469], [1471, 1471], [1473, 1474], [1476, 1477], [1479, 1479], [1552, 1562], [1611, 1631], [1648, 1648], [1750, 1756], [1759, 1764], [1767, 1768], [1770, 1773], [1809, 1809], [1840, 1866], [1958, 1968], [2027, 2035], [2070, 2073], [2075, 2083], [2085, 2087], [2089, 2093], [2137, 2139], [2260, 2273], [2275, 2306], [2362, 2362], [2364, 2364], [2369, 2376], [2381, 2381], [2385, 2391], [2402, 2403], [2433, 2433], [2492, 2492], [2497, 2500], [2509, 2509], [2530, 2531], [2561, 2562], [2620, 2620], [2625, 2626], [2631, 2632], [2635, 2637], [2641, 2641], [2672, 2673], [2677, 2677], [2689, 2690], [2748, 2748], [2753, 2757], [2759, 2760], [2765, 2765], [2786, 2787], [2810, 2815], [2817, 2817], [2876, 2876], [2879, 2879], [2881, 2884], [2893, 2893], [2902, 2902], [2914, 2915], [2946, 2946], [3008, 3008], [3021, 3021], [3072, 3072], [3134, 3136], [3142, 3144], [3146, 3149], [3157, 3158], [3170, 3171], [3201, 3201], [3260, 3260], [3263, 3263], [3270, 3270], [3276, 3277], [3298, 3299], [3328, 3329], [3387, 3388], [3393, 3396], [3405, 3405], [3426, 3427], [3530, 3530], [3538, 3540], [3542, 3542], [3633, 3633], [3636, 3642], [3655, 3662], [3761, 3761], [3764, 3769], [3771, 3772], [3784, 3789], [3864, 3865], [3893, 3893], [3895, 3895], [3897, 3897], [3953, 3966], [3968, 3972], [3974, 3975], [3981, 3991], [3993, 4028], [4038, 4038], [4141, 4144], [4146, 4151], [4153, 4154], [4157, 4158], [4184, 4185], [4190, 4192], [4209, 4212], [4226, 4226], [4229, 4230], [4237, 4237], [4253, 4253], [4957, 4959], [5906, 5908], [5938, 5940], [5970, 5971], [6002, 6003], [6068, 6069], [6071, 6077], [6086, 6086], [6089, 6099], [6109, 6109], [6155, 6157], [6277, 6278], [6313, 6313], [6432, 6434], [6439, 6440], [6450, 6450], [6457, 6459], [6679, 6680], [6683, 6683], [6742, 6742], [6744, 6750], [6752, 6752], [6754, 6754], [6757, 6764], [6771, 6780], [6783, 6783], [6832, 6845], [6912, 6915], [6964, 6964], [6966, 6970], [6972, 6972], [6978, 6978], [7019, 7027], [7040, 7041], [7074, 7077], [7080, 7081], [7083, 7085], [7142, 7142], [7144, 7145], [7149, 7149], [7151, 7153], [7212, 7219], [7222, 7223], [7376, 7378], [7380, 7392], [7394, 7400], [7405, 7405], [7412, 7412], [7416, 7417], [7616, 7673], [7675, 7679], [8400, 8412], [8417, 8417], [8421, 8432], [11503, 11505], [11647, 11647], [11744, 11775], [12330, 12333], [12441, 12442], [42607, 42607], [42612, 42621], [42654, 42655], [42736, 42737], [43010, 43010], [43014, 43014], [43019, 43019], [43045, 43046], [43204, 43205], [43232, 43249], [43302, 43309], [43335, 43345], [43392, 43394], [43443, 43443], [43446, 43449], [43452, 43452], [43493, 43493], [43561, 43566], [43569, 43570], [43573, 43574], [43587, 43587], [43596, 43596], [43644, 43644], [43696, 43696], [43698, 43700], [43703, 43704], [43710, 43711], [43713, 43713], [43756, 43757], [43766, 43766], [44005, 44005], [44008, 44008], [44013, 44013], [64286, 64286], [65024, 65039], [65056, 65071]],
  6229. "Po": [[33, 35], [37, 39], [42, 42], [44, 44], [46, 47], [58, 59], [63, 64], [92, 92], [161, 161], [167, 167], [182, 183], [191, 191], [894, 894], [903, 903], [1370, 1375], [1417, 1417], [1472, 1472], [1475, 1475], [1478, 1478], [1523, 1524], [1545, 1546], [1548, 1549], [1563, 1563], [1566, 1567], [1642, 1645], [1748, 1748], [1792, 1805], [2039, 2041], [2096, 2110], [2142, 2142], [2404, 2405], [2416, 2416], [2557, 2557], [2800, 2800], [3572, 3572], [3663, 3663], [3674, 3675], [3844, 3858], [3860, 3860], [3973, 3973], [4048, 4052], [4057, 4058], [4170, 4175], [4347, 4347], [4960, 4968], [5741, 5742], [5867, 5869], [5941, 5942], [6100, 6102], [6104, 6106], [6144, 6149], [6151, 6154], [6468, 6469], [6686, 6687], [6816, 6822], [6824, 6829], [7002, 7008], [7164, 7167], [7227, 7231], [7294, 7295], [7360, 7367], [7379, 7379], [8214, 8215], [8224, 8231], [8240, 8248], [8251, 8254], [8257, 8259], [8263, 8273], [8275, 8275], [8277, 8286], [11513, 11516], [11518, 11519], [11632, 11632], [11776, 11777], [11782, 11784], [11787, 11787], [11790, 11798], [11800, 11801], [11803, 11803], [11806, 11807], [11818, 11822], [11824, 11833], [11836, 11839], [11841, 11841], [11843, 11849], [12289, 12291], [12349, 12349], [12539, 12539], [42238, 42239], [42509, 42511], [42611, 42611], [42622, 42622], [42738, 42743], [43124, 43127], [43214, 43215], [43256, 43258], [43260, 43260], [43310, 43311], [43359, 43359], [43457, 43469], [43486, 43487], [43612, 43615], [43742, 43743], [43760, 43761], [44011, 44011], [65040, 65046], [65049, 65049], [65072, 65072], [65093, 65094], [65097, 65100], [65104, 65106], [65108, 65111], [65119, 65121], [65128, 65128], [65130, 65131], [65281, 65283], [65285, 65287], [65290, 65290], [65292, 65292], [65294, 65295], [65306, 65307], [65311, 65312], [65340, 65340], [65377, 65377], [65380, 65381]],
  6230. "Co": [[57344, 57344], [63743, 63743]],
  6231. "Sm": [[43, 43], [60, 62], [124, 124], [126, 126], [172, 172], [177, 177], [215, 215], [247, 247], [1014, 1014], [1542, 1544], [8260, 8260], [8274, 8274], [8314, 8316], [8330, 8332], [8472, 8472], [8512, 8516], [8523, 8523], [8592, 8596], [8602, 8603], [8608, 8608], [8611, 8611], [8614, 8614], [8622, 8622], [8654, 8655], [8658, 8658], [8660, 8660], [8692, 8959], [8992, 8993], [9084, 9084], [9115, 9139], [9180, 9185], [9655, 9655], [9665, 9665], [9720, 9727], [9839, 9839], [10176, 10180], [10183, 10213], [10224, 10239], [10496, 10626], [10649, 10711], [10716, 10747], [10750, 11007], [11056, 11076], [11079, 11084], [64297, 64297], [65122, 65122], [65124, 65126], [65291, 65291], [65308, 65310], [65372, 65372], [65374, 65374], [65506, 65506], [65513, 65516]],
  6232. "Pf": [[187, 187], [8217, 8217], [8221, 8221], [8250, 8250], [11779, 11779], [11781, 11781], [11786, 11786], [11789, 11789], [11805, 11805], [11809, 11809]],
  6233. "Cc": [[0, 31], [127, 159]],
  6234. "Pi": [[171, 171], [8216, 8216], [8219, 8220], [8223, 8223], [8249, 8249], [11778, 11778], [11780, 11780], [11785, 11785], [11788, 11788], [11804, 11804], [11808, 11808]],
  6235. "Lu": [[65, 90], [192, 214], [216, 222], [256, 256], [258, 258], [260, 260], [262, 262], [264, 264], [266, 266], [268, 268], [270, 270], [272, 272], [274, 274], [276, 276], [278, 278], [280, 280], [282, 282], [284, 284], [286, 286], [288, 288], [290, 290], [292, 292], [294, 294], [296, 296], [298, 298], [300, 300], [302, 302], [304, 304], [306, 306], [308, 308], [310, 310], [313, 313], [315, 315], [317, 317], [319, 319], [321, 321], [323, 323], [325, 325], [327, 327], [330, 330], [332, 332], [334, 334], [336, 336], [338, 338], [340, 340], [342, 342], [344, 344], [346, 346], [348, 348], [350, 350], [352, 352], [354, 354], [356, 356], [358, 358], [360, 360], [362, 362], [364, 364], [366, 366], [368, 368], [370, 370], [372, 372], [374, 374], [376, 377], [379, 379], [381, 381], [385, 386], [388, 388], [390, 391], [393, 395], [398, 401], [403, 404], [406, 408], [412, 413], [415, 416], [418, 418], [420, 420], [422, 423], [425, 425], [428, 428], [430, 431], [433, 435], [437, 437], [439, 440], [444, 444], [452, 452], [455, 455], [458, 458], [461, 461], [463, 463], [465, 465], [467, 467], [469, 469], [471, 471], [473, 473], [475, 475], [478, 478], [480, 480], [482, 482], [484, 484], [486, 486], [488, 488], [490, 490], [492, 492], [494, 494], [497, 497], [500, 500], [502, 504], [506, 506], [508, 508], [510, 510], [512, 512], [514, 514], [516, 516], [518, 518], [520, 520], [522, 522], [524, 524], [526, 526], [528, 528], [530, 530], [532, 532], [534, 534], [536, 536], [538, 538], [540, 540], [542, 542], [544, 544], [546, 546], [548, 548], [550, 550], [552, 552], [554, 554], [556, 556], [558, 558], [560, 560], [562, 562], [570, 571], [573, 574], [577, 577], [579, 582], [584, 584], [586, 586], [588, 588], [590, 590], [880, 880], [882, 882], [886, 886], [895, 895], [902, 902], [904, 906], [908, 908], [910, 911], [913, 929], [931, 939], [975, 975], [978, 980], [984, 984], [986, 986], [988, 988], [990, 990], [992, 992], [994, 994], [996, 996], [998, 998], [1000, 1000], [1002, 1002], [1004, 1004], [1006, 1006], [1012, 1012], [1015, 1015], [1017, 1018], [1021, 1071], [1120, 1120], [1122, 1122], [1124, 1124], [1126, 1126], [1128, 1128], [1130, 1130], [1132, 1132], [1134, 1134], [1136, 1136], [1138, 1138], [1140, 1140], [1142, 1142], [1144, 1144], [1146, 1146], [1148, 1148], [1150, 1150], [1152, 1152], [1162, 1162], [1164, 1164], [1166, 1166], [1168, 1168], [1170, 1170], [1172, 1172], [1174, 1174], [1176, 1176], [1178, 1178], [1180, 1180], [1182, 1182], [1184, 1184], [1186, 1186], [1188, 1188], [1190, 1190], [1192, 1192], [1194, 1194], [1196, 1196], [1198, 1198], [1200, 1200], [1202, 1202], [1204, 1204], [1206, 1206], [1208, 1208], [1210, 1210], [1212, 1212], [1214, 1214], [1216, 1217], [1219, 1219], [1221, 1221], [1223, 1223], [1225, 1225], [1227, 1227], [1229, 1229], [1232, 1232], [1234, 1234], [1236, 1236], [1238, 1238], [1240, 1240], [1242, 1242], [1244, 1244], [1246, 1246], [1248, 1248], [1250, 1250], [1252, 1252], [1254, 1254], [1256, 1256], [1258, 1258], [1260, 1260], [1262, 1262], [1264, 1264], [1266, 1266], [1268, 1268], [1270, 1270], [1272, 1272], [1274, 1274], [1276, 1276], [1278, 1278], [1280, 1280], [1282, 1282], [1284, 1284], [1286, 1286], [1288, 1288], [1290, 1290], [1292, 1292], [1294, 1294], [1296, 1296], [1298, 1298], [1300, 1300], [1302, 1302], [1304, 1304], [1306, 1306], [1308, 1308], [1310, 1310], [1312, 1312], [1314, 1314], [1316, 1316], [1318, 1318], [1320, 1320], [1322, 1322], [1324, 1324], [1326, 1326], [1329, 1366], [4256, 4293], [4295, 4295], [4301, 4301], [5024, 5109], [7680, 7680], [7682, 7682], [7684, 7684], [7686, 7686], [7688, 7688], [7690, 7690], [7692, 7692], [7694, 7694], [7696, 7696], [7698, 7698], [7700, 7700], [7702, 7702], [7704, 7704], [7706, 7706], [7708, 7708], [7710, 7710], [7712, 7712], [7714, 7714], [7716, 7716], [7718, 7718], [7720, 7720], [7722, 7722], [7724, 7724], [7726, 7726], [7728, 7728], [7730, 7730], [7732, 7732], [7734, 7734], [7736, 7736], [7738, 7738], [7740, 7740], [7742, 7742], [7744, 7744], [7746, 7746], [7748, 7748], [7750, 7750], [7752, 7752], [7754, 7754], [7756, 7756], [7758, 7758], [7760, 7760], [7762, 7762], [7764, 7764], [7766, 7766], [7768, 7768], [7770, 7770], [7772, 7772], [7774, 7774], [7776, 7776], [7778, 7778], [7780, 7780], [7782, 7782], [7784, 7784], [7786, 7786], [7788, 7788], [7790, 7790], [7792, 7792], [7794, 7794], [7796, 7796], [7798, 7798], [7800, 7800], [7802, 7802], [7804, 7804], [7806, 7806], [7808, 7808], [7810, 7810], [7812, 7812], [7814, 7814], [7816, 7816], [7818, 7818], [7820, 7820], [7822, 7822], [7824, 7824], [7826, 7826], [7828, 7828], [7838, 7838], [7840, 7840], [7842, 7842], [7844, 7844], [7846, 7846], [7848, 7848], [7850, 7850], [7852, 7852], [7854, 7854], [7856, 7856], [7858, 7858], [7860, 7860], [7862, 7862], [7864, 7864], [7866, 7866], [7868, 7868], [7870, 7870], [7872, 7872], [7874, 7874], [7876, 7876], [7878, 7878], [7880, 7880], [7882, 7882], [7884, 7884], [7886, 7886], [7888, 7888], [7890, 7890], [7892, 7892], [7894, 7894], [7896, 7896], [7898, 7898], [7900, 7900], [7902, 7902], [7904, 7904], [7906, 7906], [7908, 7908], [7910, 7910], [7912, 7912], [7914, 7914], [7916, 7916], [7918, 7918], [7920, 7920], [7922, 7922], [7924, 7924], [7926, 7926], [7928, 7928], [7930, 7930], [7932, 7932], [7934, 7934], [7944, 7951], [7960, 7965], [7976, 7983], [7992, 7999], [8008, 8013], [8025, 8025], [8027, 8027], [8029, 8029], [8031, 8031], [8040, 8047], [8120, 8123], [8136, 8139], [8152, 8155], [8168, 8172], [8184, 8187], [8450, 8450], [8455, 8455], [8459, 8461], [8464, 8466], [8469, 8469], [8473, 8477], [8484, 8484], [8486, 8486], [8488, 8488], [8490, 8493], [8496, 8499], [8510, 8511], [8517, 8517], [8579, 8579], [11264, 11310], [11360, 11360], [11362, 11364], [11367, 11367], [11369, 11369], [11371, 11371], [11373, 11376], [11378, 11378], [11381, 11381], [11390, 11392], [11394, 11394], [11396, 11396], [11398, 11398], [11400, 11400], [11402, 11402], [11404, 11404], [11406, 11406], [11408, 11408], [11410, 11410], [11412, 11412], [11414, 11414], [11416, 11416], [11418, 11418], [11420, 11420], [11422, 11422], [11424, 11424], [11426, 11426], [11428, 11428], [11430, 11430], [11432, 11432], [11434, 11434], [11436, 11436], [11438, 11438], [11440, 11440], [11442, 11442], [11444, 11444], [11446, 11446], [11448, 11448], [11450, 11450], [11452, 11452], [11454, 11454], [11456, 11456], [11458, 11458], [11460, 11460], [11462, 11462], [11464, 11464], [11466, 11466], [11468, 11468], [11470, 11470], [11472, 11472], [11474, 11474], [11476, 11476], [11478, 11478], [11480, 11480], [11482, 11482], [11484, 11484], [11486, 11486], [11488, 11488], [11490, 11490], [11499, 11499], [11501, 11501], [11506, 11506], [42560, 42560], [42562, 42562], [42564, 42564], [42566, 42566], [42568, 42568], [42570, 42570], [42572, 42572], [42574, 42574], [42576, 42576], [42578, 42578], [42580, 42580], [42582, 42582], [42584, 42584], [42586, 42586], [42588, 42588], [42590, 42590], [42592, 42592], [42594, 42594], [42596, 42596], [42598, 42598], [42600, 42600], [42602, 42602], [42604, 42604], [42624, 42624], [42626, 42626], [42628, 42628], [42630, 42630], [42632, 42632], [42634, 42634], [42636, 42636], [42638, 42638], [42640, 42640], [42642, 42642], [42644, 42644], [42646, 42646], [42648, 42648], [42650, 42650], [42786, 42786], [42788, 42788], [42790, 42790], [42792, 42792], [42794, 42794], [42796, 42796], [42798, 42798], [42802, 42802], [42804, 42804], [42806, 42806], [42808, 42808], [42810, 42810], [42812, 42812], [42814, 42814], [42816, 42816], [42818, 42818], [42820, 42820], [42822, 42822], [42824, 42824], [42826, 42826], [42828, 42828], [42830, 42830], [42832, 42832], [42834, 42834], [42836, 42836], [42838, 42838], [42840, 42840], [42842, 42842], [42844, 42844], [42846, 42846], [42848, 42848], [42850, 42850], [42852, 42852], [42854, 42854], [42856, 42856], [42858, 42858], [42860, 42860], [42862, 42862], [42873, 42873], [42875, 42875], [42877, 42878], [42880, 42880], [42882, 42882], [42884, 42884], [42886, 42886], [42891, 42891], [42893, 42893], [42896, 42896], [42898, 42898], [42902, 42902], [42904, 42904], [42906, 42906], [42908, 42908], [42910, 42910], [42912, 42912], [42914, 42914], [42916, 42916], [42918, 42918], [42920, 42920], [42922, 42926], [42928, 42932], [42934, 42934], [65313, 65338]],
  6236. "Pd": [[45, 45], [1418, 1418], [1470, 1470], [5120, 5120], [6150, 6150], [8208, 8213], [11799, 11799], [11802, 11802], [11834, 11835], [11840, 11840], [12316, 12316], [12336, 12336], [12448, 12448], [65073, 65074], [65112, 65112], [65123, 65123], [65293, 65293]],
  6237. "Cf": [[173, 173], [1536, 1541], [1564, 1564], [1757, 1757], [1807, 1807], [2274, 2274], [6158, 6158], [8203, 8207], [8234, 8238], [8288, 8292], [8294, 8303], [65279, 65279], [65529, 65531]],
  6238. "Nd": [[48, 57], [1632, 1641], [1776, 1785], [1984, 1993], [2406, 2415], [2534, 2543], [2662, 2671], [2790, 2799], [2918, 2927], [3046, 3055], [3174, 3183], [3302, 3311], [3430, 3439], [3558, 3567], [3664, 3673], [3792, 3801], [3872, 3881], [4160, 4169], [4240, 4249], [6112, 6121], [6160, 6169], [6470, 6479], [6608, 6617], [6784, 6793], [6800, 6809], [6992, 7001], [7088, 7097], [7232, 7241], [7248, 7257], [42528, 42537], [43216, 43225], [43264, 43273], [43472, 43481], [43504, 43513], [43600, 43609], [44016, 44025], [65296, 65305]],
  6239. "Ll": [[97, 122], [181, 181], [223, 246], [248, 255], [257, 257], [259, 259], [261, 261], [263, 263], [265, 265], [267, 267], [269, 269], [271, 271], [273, 273], [275, 275], [277, 277], [279, 279], [281, 281], [283, 283], [285, 285], [287, 287], [289, 289], [291, 291], [293, 293], [295, 295], [297, 297], [299, 299], [301, 301], [303, 303], [305, 305], [307, 307], [309, 309], [311, 312], [314, 314], [316, 316], [318, 318], [320, 320], [322, 322], [324, 324], [326, 326], [328, 329], [331, 331], [333, 333], [335, 335], [337, 337], [339, 339], [341, 341], [343, 343], [345, 345], [347, 347], [349, 349], [351, 351], [353, 353], [355, 355], [357, 357], [359, 359], [361, 361], [363, 363], [365, 365], [367, 367], [369, 369], [371, 371], [373, 373], [375, 375], [378, 378], [380, 380], [382, 384], [387, 387], [389, 389], [392, 392], [396, 397], [402, 402], [405, 405], [409, 411], [414, 414], [417, 417], [419, 419], [421, 421], [424, 424], [426, 427], [429, 429], [432, 432], [436, 436], [438, 438], [441, 442], [445, 447], [454, 454], [457, 457], [460, 460], [462, 462], [464, 464], [466, 466], [468, 468], [470, 470], [472, 472], [474, 474], [476, 477], [479, 479], [481, 481], [483, 483], [485, 485], [487, 487], [489, 489], [491, 491], [493, 493], [495, 496], [499, 499], [501, 501], [505, 505], [507, 507], [509, 509], [511, 511], [513, 513], [515, 515], [517, 517], [519, 519], [521, 521], [523, 523], [525, 525], [527, 527], [529, 529], [531, 531], [533, 533], [535, 535], [537, 537], [539, 539], [541, 541], [543, 543], [545, 545], [547, 547], [549, 549], [551, 551], [553, 553], [555, 555], [557, 557], [559, 559], [561, 561], [563, 569], [572, 572], [575, 576], [578, 578], [583, 583], [585, 585], [587, 587], [589, 589], [591, 659], [661, 687], [881, 881], [883, 883], [887, 887], [891, 893], [912, 912], [940, 974], [976, 977], [981, 983], [985, 985], [987, 987], [989, 989], [991, 991], [993, 993], [995, 995], [997, 997], [999, 999], [1001, 1001], [1003, 1003], [1005, 1005], [1007, 1011], [1013, 1013], [1016, 1016], [1019, 1020], [1072, 1119], [1121, 1121], [1123, 1123], [1125, 1125], [1127, 1127], [1129, 1129], [1131, 1131], [1133, 1133], [1135, 1135], [1137, 1137], [1139, 1139], [1141, 1141], [1143, 1143], [1145, 1145], [1147, 1147], [1149, 1149], [1151, 1151], [1153, 1153], [1163, 1163], [1165, 1165], [1167, 1167], [1169, 1169], [1171, 1171], [1173, 1173], [1175, 1175], [1177, 1177], [1179, 1179], [1181, 1181], [1183, 1183], [1185, 1185], [1187, 1187], [1189, 1189], [1191, 1191], [1193, 1193], [1195, 1195], [1197, 1197], [1199, 1199], [1201, 1201], [1203, 1203], [1205, 1205], [1207, 1207], [1209, 1209], [1211, 1211], [1213, 1213], [1215, 1215], [1218, 1218], [1220, 1220], [1222, 1222], [1224, 1224], [1226, 1226], [1228, 1228], [1230, 1231], [1233, 1233], [1235, 1235], [1237, 1237], [1239, 1239], [1241, 1241], [1243, 1243], [1245, 1245], [1247, 1247], [1249, 1249], [1251, 1251], [1253, 1253], [1255, 1255], [1257, 1257], [1259, 1259], [1261, 1261], [1263, 1263], [1265, 1265], [1267, 1267], [1269, 1269], [1271, 1271], [1273, 1273], [1275, 1275], [1277, 1277], [1279, 1279], [1281, 1281], [1283, 1283], [1285, 1285], [1287, 1287], [1289, 1289], [1291, 1291], [1293, 1293], [1295, 1295], [1297, 1297], [1299, 1299], [1301, 1301], [1303, 1303], [1305, 1305], [1307, 1307], [1309, 1309], [1311, 1311], [1313, 1313], [1315, 1315], [1317, 1317], [1319, 1319], [1321, 1321], [1323, 1323], [1325, 1325], [1327, 1327], [1377, 1415], [5112, 5117], [7296, 7304], [7424, 7467], [7531, 7543], [7545, 7578], [7681, 7681], [7683, 7683], [7685, 7685], [7687, 7687], [7689, 7689], [7691, 7691], [7693, 7693], [7695, 7695], [7697, 7697], [7699, 7699], [7701, 7701], [7703, 7703], [7705, 7705], [7707, 7707], [7709, 7709], [7711, 7711], [7713, 7713], [7715, 7715], [7717, 7717], [7719, 7719], [7721, 7721], [7723, 7723], [7725, 7725], [7727, 7727], [7729, 7729], [7731, 7731], [7733, 7733], [7735, 7735], [7737, 7737], [7739, 7739], [7741, 7741], [7743, 7743], [7745, 7745], [7747, 7747], [7749, 7749], [7751, 7751], [7753, 7753], [7755, 7755], [7757, 7757], [7759, 7759], [7761, 7761], [7763, 7763], [7765, 7765], [7767, 7767], [7769, 7769], [7771, 7771], [7773, 7773], [7775, 7775], [7777, 7777], [7779, 7779], [7781, 7781], [7783, 7783], [7785, 7785], [7787, 7787], [7789, 7789], [7791, 7791], [7793, 7793], [7795, 7795], [7797, 7797], [7799, 7799], [7801, 7801], [7803, 7803], [7805, 7805], [7807, 7807], [7809, 7809], [7811, 7811], [7813, 7813], [7815, 7815], [7817, 7817], [7819, 7819], [7821, 7821], [7823, 7823], [7825, 7825], [7827, 7827], [7829, 7837], [7839, 7839], [7841, 7841], [7843, 7843], [7845, 7845], [7847, 7847], [7849, 7849], [7851, 7851], [7853, 7853], [7855, 7855], [7857, 7857], [7859, 7859], [7861, 7861], [7863, 7863], [7865, 7865], [7867, 7867], [7869, 7869], [7871, 7871], [7873, 7873], [7875, 7875], [7877, 7877], [7879, 7879], [7881, 7881], [7883, 7883], [7885, 7885], [7887, 7887], [7889, 7889], [7891, 7891], [7893, 7893], [7895, 7895], [7897, 7897], [7899, 7899], [7901, 7901], [7903, 7903], [7905, 7905], [7907, 7907], [7909, 7909], [7911, 7911], [7913, 7913], [7915, 7915], [7917, 7917], [7919, 7919], [7921, 7921], [7923, 7923], [7925, 7925], [7927, 7927], [7929, 7929], [7931, 7931], [7933, 7933], [7935, 7943], [7952, 7957], [7968, 7975], [7984, 7991], [8000, 8005], [8016, 8023], [8032, 8039], [8048, 8061], [8064, 8071], [8080, 8087], [8096, 8103], [8112, 8116], [8118, 8119], [8126, 8126], [8130, 8132], [8134, 8135], [8144, 8147], [8150, 8151], [8160, 8167], [8178, 8180], [8182, 8183], [8458, 8458], [8462, 8463], [8467, 8467], [8495, 8495], [8500, 8500], [8505, 8505], [8508, 8509], [8518, 8521], [8526, 8526], [8580, 8580], [11312, 11358], [11361, 11361], [11365, 11366], [11368, 11368], [11370, 11370], [11372, 11372], [11377, 11377], [11379, 11380], [11382, 11387], [11393, 11393], [11395, 11395], [11397, 11397], [11399, 11399], [11401, 11401], [11403, 11403], [11405, 11405], [11407, 11407], [11409, 11409], [11411, 11411], [11413, 11413], [11415, 11415], [11417, 11417], [11419, 11419], [11421, 11421], [11423, 11423], [11425, 11425], [11427, 11427], [11429, 11429], [11431, 11431], [11433, 11433], [11435, 11435], [11437, 11437], [11439, 11439], [11441, 11441], [11443, 11443], [11445, 11445], [11447, 11447], [11449, 11449], [11451, 11451], [11453, 11453], [11455, 11455], [11457, 11457], [11459, 11459], [11461, 11461], [11463, 11463], [11465, 11465], [11467, 11467], [11469, 11469], [11471, 11471], [11473, 11473], [11475, 11475], [11477, 11477], [11479, 11479], [11481, 11481], [11483, 11483], [11485, 11485], [11487, 11487], [11489, 11489], [11491, 11492], [11500, 11500], [11502, 11502], [11507, 11507], [11520, 11557], [11559, 11559], [11565, 11565], [42561, 42561], [42563, 42563], [42565, 42565], [42567, 42567], [42569, 42569], [42571, 42571], [42573, 42573], [42575, 42575], [42577, 42577], [42579, 42579], [42581, 42581], [42583, 42583], [42585, 42585], [42587, 42587], [42589, 42589], [42591, 42591], [42593, 42593], [42595, 42595], [42597, 42597], [42599, 42599], [42601, 42601], [42603, 42603], [42605, 42605], [42625, 42625], [42627, 42627], [42629, 42629], [42631, 42631], [42633, 42633], [42635, 42635], [42637, 42637], [42639, 42639], [42641, 42641], [42643, 42643], [42645, 42645], [42647, 42647], [42649, 42649], [42651, 42651], [42787, 42787], [42789, 42789], [42791, 42791], [42793, 42793], [42795, 42795], [42797, 42797], [42799, 42801], [42803, 42803], [42805, 42805], [42807, 42807], [42809, 42809], [42811, 42811], [42813, 42813], [42815, 42815], [42817, 42817], [42819, 42819], [42821, 42821], [42823, 42823], [42825, 42825], [42827, 42827], [42829, 42829], [42831, 42831], [42833, 42833], [42835, 42835], [42837, 42837], [42839, 42839], [42841, 42841], [42843, 42843], [42845, 42845], [42847, 42847], [42849, 42849], [42851, 42851], [42853, 42853], [42855, 42855], [42857, 42857], [42859, 42859], [42861, 42861], [42863, 42863], [42865, 42872], [42874, 42874], [42876, 42876], [42879, 42879], [42881, 42881], [42883, 42883], [42885, 42885], [42887, 42887], [42892, 42892], [42894, 42894], [42897, 42897], [42899, 42901], [42903, 42903], [42905, 42905], [42907, 42907], [42909, 42909], [42911, 42911], [42913, 42913], [42915, 42915], [42917, 42917], [42919, 42919], [42921, 42921], [42933, 42933], [42935, 42935], [43002, 43002], [43824, 43866], [43872, 43877], [43888, 43967], [64256, 64262], [64275, 64279], [65345, 65370]],
  6240. "No": [[178, 179], [185, 185], [188, 190], [2548, 2553], [2930, 2935], [3056, 3058], [3192, 3198], [3416, 3422], [3440, 3448], [3882, 3891], [4969, 4988], [6128, 6137], [6618, 6618], [8304, 8304], [8308, 8313], [8320, 8329], [8528, 8543], [8585, 8585], [9312, 9371], [9450, 9471], [10102, 10131], [11517, 11517], [12690, 12693], [12832, 12841], [12872, 12879], [12881, 12895], [12928, 12937], [12977, 12991], [43056, 43061]],
  6241. "Zs": [[32, 32], [160, 160], [5760, 5760], [8192, 8202], [8239, 8239], [8287, 8287], [12288, 12288]]
  6242. };
  6243. };
  6244. });
  6245. unwrapExports(data_generated);
  6246. var utils$2 = createCommonjsModule(function (module, exports) {
  6247. "use strict";
  6248. exports.__esModule = true;
  6249. function normalize_ranges(ranges) {
  6250. return ranges.sort(function (_a, _b) {
  6251. var start1 = _a[0];
  6252. var start2 = _b[0];
  6253. return start1 - start2;
  6254. }).reduce(function (current, tuple, index) {
  6255. if (index === 0) {
  6256. return [tuple];
  6257. }
  6258. var _a = current[current.length - 1],
  6259. last_start = _a[0],
  6260. last_end = _a[1];
  6261. var start = tuple[0],
  6262. end = tuple[1];
  6263. return last_end + 1 === start ? current.slice(0, -1).concat([[last_start, end]]) : current.concat([tuple]);
  6264. }, []);
  6265. }
  6266. exports.normalize_ranges = normalize_ranges;
  6267. function build_regex(ranges, flag) {
  6268. var pattern = ranges.map(function (_a) {
  6269. var start = _a[0],
  6270. end = _a[1];
  6271. return start === end ? "\\u" + get_hex(start) : "\\u" + get_hex(start) + "-\\u" + get_hex(end);
  6272. }).join('');
  6273. return new RegExp("[" + pattern + "]", flag);
  6274. }
  6275. exports.build_regex = build_regex;
  6276. function get_hex(char_code) {
  6277. var hex = char_code.toString(16);
  6278. while (hex.length < 4) {
  6279. hex = "0" + hex;
  6280. }
  6281. return hex;
  6282. }
  6283. });
  6284. unwrapExports(utils$2);
  6285. var lib$5 = function lib(categories, flag) {
  6286. var data = data_generated.get_data();
  6287. var ranges = categories.reduce(function (current, category) {
  6288. return current.concat(data[category]);
  6289. }, []);
  6290. return utils$2.build_regex(utils$2.normalize_ranges(ranges), flag);
  6291. };
  6292. var emojiRegex = emojiRegex$1();
  6293. var cjkPattern = lib$3().source; // http://spec.commonmark.org/0.25/#ascii-punctuation-character
  6294. var asciiPunctuationCharRange = escapeStringRegexp("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"); // http://spec.commonmark.org/0.25/#punctuation-character
  6295. var punctuationCharRange = `${asciiPunctuationCharRange}${lib$5(["Pc", "Pd", "Pe", "Pf", "Pi", "Po", "Ps"]).source.slice(1, -1)}`; // remove bracket expression `[` and `]`
  6296. var punctuationRegex = new RegExp(`[${punctuationCharRange}]`);
  6297. function isExportDeclaration(node) {
  6298. if (node) {
  6299. switch (node.type) {
  6300. case "ExportDefaultDeclaration":
  6301. case "ExportDefaultSpecifier":
  6302. case "DeclareExportDeclaration":
  6303. case "ExportNamedDeclaration":
  6304. case "ExportAllDeclaration":
  6305. return true;
  6306. }
  6307. }
  6308. return false;
  6309. }
  6310. function getParentExportDeclaration(path$$1) {
  6311. var parentNode = path$$1.getParentNode();
  6312. if (path$$1.getName() === "declaration" && isExportDeclaration(parentNode)) {
  6313. return parentNode;
  6314. }
  6315. return null;
  6316. }
  6317. function getPenultimate(arr) {
  6318. if (arr.length > 1) {
  6319. return arr[arr.length - 2];
  6320. }
  6321. return null;
  6322. }
  6323. function getLast$3(arr) {
  6324. if (arr.length > 0) {
  6325. return arr[arr.length - 1];
  6326. }
  6327. return null;
  6328. }
  6329. function skip(chars) {
  6330. return function (text, index, opts) {
  6331. var backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
  6332. // to check for failures (did someone say monads?).
  6333. if (index === false) {
  6334. return false;
  6335. }
  6336. var length = text.length;
  6337. var cursor = index;
  6338. while (cursor >= 0 && cursor < length) {
  6339. var c = text.charAt(cursor);
  6340. if (chars instanceof RegExp) {
  6341. if (!chars.test(c)) {
  6342. return cursor;
  6343. }
  6344. } else if (chars.indexOf(c) === -1) {
  6345. return cursor;
  6346. }
  6347. backwards ? cursor-- : cursor++;
  6348. }
  6349. if (cursor === -1 || cursor === length) {
  6350. // If we reached the beginning or end of the file, return the
  6351. // out-of-bounds cursor. It's up to the caller to handle this
  6352. // correctly. We don't want to indicate `false` though if it
  6353. // actually skipped valid characters.
  6354. return cursor;
  6355. }
  6356. return false;
  6357. };
  6358. }
  6359. var skipWhitespace = skip(/\s/);
  6360. var skipSpaces = skip(" \t");
  6361. var skipToLineEnd = skip(",; \t");
  6362. var skipEverythingButNewLine = skip(/[^\r\n]/);
  6363. function skipInlineComment(text, index) {
  6364. if (index === false) {
  6365. return false;
  6366. }
  6367. if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
  6368. for (var i = index + 2; i < text.length; ++i) {
  6369. if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
  6370. return i + 2;
  6371. }
  6372. }
  6373. }
  6374. return index;
  6375. }
  6376. function skipTrailingComment(text, index) {
  6377. if (index === false) {
  6378. return false;
  6379. }
  6380. if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
  6381. return skipEverythingButNewLine(text, index);
  6382. }
  6383. return index;
  6384. } // This one doesn't use the above helper function because it wants to
  6385. // test \r\n in order and `skip` doesn't support ordering and we only
  6386. // want to skip one newline. It's simple to implement.
  6387. function skipNewline$1(text, index, opts) {
  6388. var backwards = opts && opts.backwards;
  6389. if (index === false) {
  6390. return false;
  6391. }
  6392. var atIndex = text.charAt(index);
  6393. if (backwards) {
  6394. if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
  6395. return index - 2;
  6396. }
  6397. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  6398. return index - 1;
  6399. }
  6400. } else {
  6401. if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
  6402. return index + 2;
  6403. }
  6404. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  6405. return index + 1;
  6406. }
  6407. }
  6408. return index;
  6409. }
  6410. function hasNewline$1(text, index, opts) {
  6411. opts = opts || {};
  6412. var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  6413. var idx2 = skipNewline$1(text, idx, opts);
  6414. return idx !== idx2;
  6415. }
  6416. function hasNewlineInRange(text, start, end) {
  6417. for (var i = start; i < end; ++i) {
  6418. if (text.charAt(i) === "\n") {
  6419. return true;
  6420. }
  6421. }
  6422. return false;
  6423. } // Note: this function doesn't ignore leading comments unlike isNextLineEmpty
  6424. function isPreviousLineEmpty$1(text, node, locStart) {
  6425. var idx = locStart(node) - 1;
  6426. idx = skipSpaces(text, idx, {
  6427. backwards: true
  6428. });
  6429. idx = skipNewline$1(text, idx, {
  6430. backwards: true
  6431. });
  6432. idx = skipSpaces(text, idx, {
  6433. backwards: true
  6434. });
  6435. var idx2 = skipNewline$1(text, idx, {
  6436. backwards: true
  6437. });
  6438. return idx !== idx2;
  6439. }
  6440. function isNextLineEmptyAfterIndex(text, index) {
  6441. var oldIdx = null;
  6442. var idx = index;
  6443. while (idx !== oldIdx) {
  6444. // We need to skip all the potential trailing inline comments
  6445. oldIdx = idx;
  6446. idx = skipToLineEnd(text, idx);
  6447. idx = skipInlineComment(text, idx);
  6448. idx = skipSpaces(text, idx);
  6449. }
  6450. idx = skipTrailingComment(text, idx);
  6451. idx = skipNewline$1(text, idx);
  6452. return hasNewline$1(text, idx);
  6453. }
  6454. function isNextLineEmpty(text, node, locEnd) {
  6455. return isNextLineEmptyAfterIndex(text, locEnd(node));
  6456. }
  6457. function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
  6458. var oldIdx = null;
  6459. var idx = locEnd(node);
  6460. while (idx !== oldIdx) {
  6461. oldIdx = idx;
  6462. idx = skipSpaces(text, idx);
  6463. idx = skipInlineComment(text, idx);
  6464. idx = skipTrailingComment(text, idx);
  6465. idx = skipNewline$1(text, idx);
  6466. }
  6467. return idx;
  6468. }
  6469. function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
  6470. return text.charAt(getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd));
  6471. }
  6472. function hasSpaces(text, index, opts) {
  6473. opts = opts || {};
  6474. var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  6475. return idx !== index;
  6476. }
  6477. function setLocStart(node, index) {
  6478. if (node.range) {
  6479. node.range[0] = index;
  6480. } else {
  6481. node.start = index;
  6482. }
  6483. }
  6484. function setLocEnd(node, index) {
  6485. if (node.range) {
  6486. node.range[1] = index;
  6487. } else {
  6488. node.end = index;
  6489. }
  6490. }
  6491. var PRECEDENCE = {};
  6492. [["|>"], ["||", "??"], ["&&"], ["|"], ["^"], ["&"], ["==", "===", "!=", "!=="], ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], ["*", "/", "%"], ["**"]].forEach(function (tier, i) {
  6493. tier.forEach(function (op) {
  6494. PRECEDENCE[op] = i;
  6495. });
  6496. });
  6497. function getPrecedence(op) {
  6498. return PRECEDENCE[op];
  6499. }
  6500. var equalityOperators = {
  6501. "==": true,
  6502. "!=": true,
  6503. "===": true,
  6504. "!==": true
  6505. };
  6506. var additiveOperators = {
  6507. "+": true,
  6508. "-": true
  6509. };
  6510. var multiplicativeOperators = {
  6511. "*": true,
  6512. "/": true,
  6513. "%": true
  6514. };
  6515. var bitshiftOperators = {
  6516. ">>": true,
  6517. ">>>": true,
  6518. "<<": true
  6519. };
  6520. function shouldFlatten(parentOp, nodeOp) {
  6521. if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) {
  6522. // x + y % z --> (x + y) % z
  6523. if (nodeOp === "%" && !additiveOperators[parentOp]) {
  6524. return true;
  6525. }
  6526. return false;
  6527. } // ** is right-associative
  6528. // x ** y ** z --> x ** (y ** z)
  6529. if (parentOp === "**") {
  6530. return false;
  6531. } // x == y == z --> (x == y) == z
  6532. if (equalityOperators[parentOp] && equalityOperators[nodeOp]) {
  6533. return false;
  6534. } // x * y % z --> (x * y) % z
  6535. if (nodeOp === "%" && multiplicativeOperators[parentOp] || parentOp === "%" && multiplicativeOperators[nodeOp]) {
  6536. return false;
  6537. } // x * y / z --> (x * y) / z
  6538. // x / y * z --> (x / y) * z
  6539. if (nodeOp !== parentOp && multiplicativeOperators[nodeOp] && multiplicativeOperators[parentOp]) {
  6540. return false;
  6541. } // x << y << z --> (x << y) << z
  6542. if (bitshiftOperators[parentOp] && bitshiftOperators[nodeOp]) {
  6543. return false;
  6544. }
  6545. return true;
  6546. }
  6547. function isBitwiseOperator(operator) {
  6548. return !!bitshiftOperators[operator] || operator === "|" || operator === "^" || operator === "&";
  6549. } // Tests if an expression starts with `{`, or (if forbidFunctionClassAndDoExpr
  6550. // holds) `function`, `class`, or `do {}`. Will be overzealous if there's
  6551. // already necessary grouping parentheses.
  6552. function startsWithNoLookaheadToken(node, forbidFunctionClassAndDoExpr) {
  6553. node = getLeftMost(node);
  6554. switch (node.type) {
  6555. // Hack. Remove after https://github.com/eslint/typescript-eslint-parser/issues/331
  6556. case "ObjectPattern":
  6557. return !forbidFunctionClassAndDoExpr;
  6558. case "FunctionExpression":
  6559. case "ClassExpression":
  6560. case "DoExpression":
  6561. return forbidFunctionClassAndDoExpr;
  6562. case "ObjectExpression":
  6563. return true;
  6564. case "MemberExpression":
  6565. return startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  6566. case "TaggedTemplateExpression":
  6567. if (node.tag.type === "FunctionExpression") {
  6568. // IIFEs are always already parenthesized
  6569. return false;
  6570. }
  6571. return startsWithNoLookaheadToken(node.tag, forbidFunctionClassAndDoExpr);
  6572. case "CallExpression":
  6573. if (node.callee.type === "FunctionExpression") {
  6574. // IIFEs are always already parenthesized
  6575. return false;
  6576. }
  6577. return startsWithNoLookaheadToken(node.callee, forbidFunctionClassAndDoExpr);
  6578. case "ConditionalExpression":
  6579. return startsWithNoLookaheadToken(node.test, forbidFunctionClassAndDoExpr);
  6580. case "UpdateExpression":
  6581. return !node.prefix && startsWithNoLookaheadToken(node.argument, forbidFunctionClassAndDoExpr);
  6582. case "BindExpression":
  6583. return node.object && startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  6584. case "SequenceExpression":
  6585. return startsWithNoLookaheadToken(node.expressions[0], forbidFunctionClassAndDoExpr);
  6586. case "TSAsExpression":
  6587. return startsWithNoLookaheadToken(node.expression, forbidFunctionClassAndDoExpr);
  6588. default:
  6589. return false;
  6590. }
  6591. }
  6592. function getLeftMost(node) {
  6593. if (node.left) {
  6594. return getLeftMost(node.left);
  6595. }
  6596. return node;
  6597. }
  6598. function getAlignmentSize(value, tabWidth, startIndex) {
  6599. startIndex = startIndex || 0;
  6600. var size = 0;
  6601. for (var i = startIndex; i < value.length; ++i) {
  6602. if (value[i] === "\t") {
  6603. // Tabs behave in a way that they are aligned to the nearest
  6604. // multiple of tabWidth:
  6605. // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
  6606. // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
  6607. size = size + tabWidth - size % tabWidth;
  6608. } else {
  6609. size++;
  6610. }
  6611. }
  6612. return size;
  6613. }
  6614. function getIndentSize(value, tabWidth) {
  6615. var lastNewlineIndex = value.lastIndexOf("\n");
  6616. if (lastNewlineIndex === -1) {
  6617. return 0;
  6618. }
  6619. return getAlignmentSize( // All the leading whitespaces
  6620. value.slice(lastNewlineIndex + 1).match(/^[ \t]*/)[0], tabWidth);
  6621. }
  6622. function printString(raw, options, isDirectiveLiteral) {
  6623. // `rawContent` is the string exactly like it appeared in the input source
  6624. // code, without its enclosing quotes.
  6625. var rawContent = raw.slice(1, -1);
  6626. var double = {
  6627. quote: '"',
  6628. regex: /"/g
  6629. };
  6630. var single = {
  6631. quote: "'",
  6632. regex: /'/g
  6633. };
  6634. var preferred = options.singleQuote ? single : double;
  6635. var alternate = preferred === single ? double : single;
  6636. var shouldUseAlternateQuote = false;
  6637. var canChangeDirectiveQuotes = false; // If `rawContent` contains at least one of the quote preferred for enclosing
  6638. // the string, we might want to enclose with the alternate quote instead, to
  6639. // minimize the number of escaped quotes.
  6640. // Also check for the alternate quote, to determine if we're allowed to swap
  6641. // the quotes on a DirectiveLiteral.
  6642. if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
  6643. var numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
  6644. var numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
  6645. shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes;
  6646. } else {
  6647. canChangeDirectiveQuotes = true;
  6648. }
  6649. var enclosingQuote = options.parser === "json" ? double.quote : shouldUseAlternateQuote ? alternate.quote : preferred.quote; // Directives are exact code unit sequences, which means that you can't
  6650. // change the escape sequences they use.
  6651. // See https://github.com/prettier/prettier/issues/1555
  6652. // and https://tc39.github.io/ecma262/#directive-prologue
  6653. if (isDirectiveLiteral) {
  6654. if (canChangeDirectiveQuotes) {
  6655. return enclosingQuote + rawContent + enclosingQuote;
  6656. }
  6657. return raw;
  6658. } // It might sound unnecessary to use `makeString` even if the string already
  6659. // is enclosed with `enclosingQuote`, but it isn't. The string could contain
  6660. // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
  6661. // sure that we consistently output the minimum amount of escaped quotes.
  6662. return makeString(rawContent, enclosingQuote, !(options.parser === "css" || options.parser === "less" || options.parser === "scss"));
  6663. }
  6664. function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
  6665. var otherQuote = enclosingQuote === '"' ? "'" : '"'; // Matches _any_ escape and unescaped quotes (both single and double).
  6666. var regex = /\\([\s\S])|(['"])/g; // Escape and unescape single and double quotes as needed to be able to
  6667. // enclose `rawContent` with `enclosingQuote`.
  6668. var newContent = rawContent.replace(regex, function (match, escaped, quote) {
  6669. // If we matched an escape, and the escaped character is a quote of the
  6670. // other type than we intend to enclose the string with, there's no need for
  6671. // it to be escaped, so return it _without_ the backslash.
  6672. if (escaped === otherQuote) {
  6673. return escaped;
  6674. } // If we matched an unescaped quote and it is of the _same_ type as we
  6675. // intend to enclose the string with, it must be escaped, so return it with
  6676. // a backslash.
  6677. if (quote === enclosingQuote) {
  6678. return "\\" + quote;
  6679. }
  6680. if (quote) {
  6681. return quote;
  6682. } // Unescape any unnecessarily escaped character.
  6683. // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
  6684. return unescapeUnnecessaryEscapes && /^[^\\nrvtbfux\r\n\u2028\u2029"'0-7]$/.test(escaped) ? escaped : "\\" + escaped;
  6685. });
  6686. return enclosingQuote + newContent + enclosingQuote;
  6687. }
  6688. function printNumber(rawNumber) {
  6689. return rawNumber.toLowerCase() // Remove unnecessary plus and zeroes from scientific notation.
  6690. .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3") // Remove unnecessary scientific notation (1e0).
  6691. .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1") // Make sure numbers always start with a digit.
  6692. .replace(/^([+-])?\./, "$10.") // Remove extraneous trailing decimal zeroes.
  6693. .replace(/(\.\d+?)0+(?=e|$)/, "$1") // Remove trailing dot.
  6694. .replace(/\.(?=e|$)/, "");
  6695. }
  6696. function getMaxContinuousCount(str, target) {
  6697. var results = str.match(new RegExp(`(${escapeStringRegexp(target)})+`, "g"));
  6698. if (results === null) {
  6699. return 0;
  6700. }
  6701. return results.reduce(function (maxCount, result) {
  6702. return Math.max(maxCount, result.length / target.length);
  6703. }, 0);
  6704. }
  6705. /**
  6706. * split text into whitespaces and words
  6707. * @param {string} text
  6708. * @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
  6709. */
  6710. function splitText(text, options) {
  6711. var KIND_NON_CJK = "non-cjk";
  6712. var KIND_CJK_CHARACTER = "cjk-character";
  6713. var KIND_CJK_PUNCTUATION = "cjk-punctuation";
  6714. var nodes = [];
  6715. (options.proseWrap === "preserve" ? text : text.replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")).split(/([ \t\n]+)/).forEach(function (token, index, tokens) {
  6716. // whitespace
  6717. if (index % 2 === 1) {
  6718. nodes.push({
  6719. type: "whitespace",
  6720. value: /\n/.test(token) ? "\n" : " "
  6721. });
  6722. return;
  6723. } // word separated by whitespace
  6724. if ((index === 0 || index === tokens.length - 1) && token === "") {
  6725. return;
  6726. }
  6727. token.split(new RegExp(`(${cjkPattern})`)).forEach(function (innerToken, innerIndex, innerTokens) {
  6728. if ((innerIndex === 0 || innerIndex === innerTokens.length - 1) && innerToken === "") {
  6729. return;
  6730. } // non-CJK word
  6731. if (innerIndex % 2 === 0) {
  6732. if (innerToken !== "") {
  6733. appendNode({
  6734. type: "word",
  6735. value: innerToken,
  6736. kind: KIND_NON_CJK,
  6737. hasLeadingPunctuation: punctuationRegex.test(innerToken[0]),
  6738. hasTrailingPunctuation: punctuationRegex.test(getLast$3(innerToken))
  6739. });
  6740. }
  6741. return;
  6742. } // CJK character
  6743. appendNode(punctuationRegex.test(innerToken) ? {
  6744. type: "word",
  6745. value: innerToken,
  6746. kind: KIND_CJK_PUNCTUATION,
  6747. hasLeadingPunctuation: true,
  6748. hasTrailingPunctuation: true
  6749. } : {
  6750. type: "word",
  6751. value: innerToken,
  6752. kind: KIND_CJK_CHARACTER,
  6753. hasLeadingPunctuation: false,
  6754. hasTrailingPunctuation: false
  6755. });
  6756. });
  6757. });
  6758. return nodes;
  6759. function appendNode(node) {
  6760. var lastNode = getLast$3(nodes);
  6761. if (lastNode && lastNode.type === "word") {
  6762. if (lastNode.kind === KIND_NON_CJK && node.kind === KIND_CJK_CHARACTER && !lastNode.hasTrailingPunctuation || lastNode.kind === KIND_CJK_CHARACTER && node.kind === KIND_NON_CJK && !node.hasLeadingPunctuation) {
  6763. nodes.push({
  6764. type: "whitespace",
  6765. value: " "
  6766. });
  6767. } else if (!isBetween(KIND_NON_CJK, KIND_CJK_PUNCTUATION) && // disallow leading/trailing full-width whitespace
  6768. ![lastNode.value, node.value].some(function (value) {
  6769. return /\u3000/.test(value);
  6770. })) {
  6771. nodes.push({
  6772. type: "whitespace",
  6773. value: ""
  6774. });
  6775. }
  6776. }
  6777. nodes.push(node);
  6778. function isBetween(kind1, kind2) {
  6779. return lastNode.kind === kind1 && node.kind === kind2 || lastNode.kind === kind2 && node.kind === kind1;
  6780. }
  6781. }
  6782. }
  6783. function getStringWidth(text) {
  6784. if (!text) {
  6785. return 0;
  6786. } // emojis are considered 2-char width for consistency
  6787. // see https://github.com/sindresorhus/string-width/issues/11
  6788. // for the reason why not implemented in `string-width`
  6789. return stringWidth(text.replace(emojiRegex, " "));
  6790. }
  6791. function hasIgnoreComment(path$$1) {
  6792. var node = path$$1.getValue();
  6793. return hasNodeIgnoreComment(node);
  6794. }
  6795. function hasNodeIgnoreComment(node) {
  6796. return node && node.comments && node.comments.length > 0 && node.comments.some(function (comment) {
  6797. return comment.value.trim() === "prettier-ignore";
  6798. });
  6799. }
  6800. function addCommentHelper(node, comment) {
  6801. var comments = node.comments || (node.comments = []);
  6802. comments.push(comment);
  6803. comment.printed = false; // For some reason, TypeScript parses `// x` inside of JSXText as a comment
  6804. // We already "print" it via the raw text, we don't need to re-print it as a
  6805. // comment
  6806. if (node.type === "JSXText") {
  6807. comment.printed = true;
  6808. }
  6809. }
  6810. function addLeadingComment$1(node, comment) {
  6811. comment.leading = true;
  6812. comment.trailing = false;
  6813. addCommentHelper(node, comment);
  6814. }
  6815. function addDanglingComment$1(node, comment) {
  6816. comment.leading = false;
  6817. comment.trailing = false;
  6818. addCommentHelper(node, comment);
  6819. }
  6820. function addTrailingComment$1(node, comment) {
  6821. comment.leading = false;
  6822. comment.trailing = true;
  6823. addCommentHelper(node, comment);
  6824. }
  6825. var util$1 = {
  6826. punctuationRegex,
  6827. punctuationCharRange,
  6828. getStringWidth,
  6829. splitText,
  6830. getMaxContinuousCount,
  6831. getPrecedence,
  6832. shouldFlatten,
  6833. isBitwiseOperator,
  6834. isExportDeclaration,
  6835. getParentExportDeclaration,
  6836. getPenultimate,
  6837. getLast: getLast$3,
  6838. getNextNonSpaceNonCommentCharacterIndex,
  6839. getNextNonSpaceNonCommentCharacter,
  6840. skipWhitespace,
  6841. skipSpaces,
  6842. skipNewline: skipNewline$1,
  6843. isNextLineEmptyAfterIndex,
  6844. isNextLineEmpty,
  6845. isPreviousLineEmpty: isPreviousLineEmpty$1,
  6846. hasNewline: hasNewline$1,
  6847. hasNewlineInRange,
  6848. hasSpaces,
  6849. setLocStart,
  6850. setLocEnd,
  6851. startsWithNoLookaheadToken,
  6852. getAlignmentSize,
  6853. getIndentSize,
  6854. printString,
  6855. printNumber,
  6856. hasIgnoreComment,
  6857. hasNodeIgnoreComment,
  6858. makeString,
  6859. addLeadingComment: addLeadingComment$1,
  6860. addDanglingComment: addDanglingComment$1,
  6861. addTrailingComment: addTrailingComment$1
  6862. };
  6863. var concat$2 = docBuilders.concat;
  6864. var fill$1 = docBuilders.fill;
  6865. var cursor$2 = docBuilders.cursor;
  6866. var MODE_BREAK = 1;
  6867. var MODE_FLAT = 2;
  6868. function rootIndent() {
  6869. return {
  6870. value: "",
  6871. length: 0,
  6872. queue: []
  6873. };
  6874. }
  6875. function makeIndent(ind, options) {
  6876. return generateInd(ind, {
  6877. type: "indent"
  6878. }, options);
  6879. }
  6880. function makeAlign(ind, n, options) {
  6881. return n === -Infinity ? ind.root || rootIndent() : n < 0 ? generateInd(ind, {
  6882. type: "dedent"
  6883. }, options) : !n ? ind : n.type === "root" ? Object.assign({}, ind, {
  6884. root: ind
  6885. }) : typeof n === "string" ? generateInd(ind, {
  6886. type: "stringAlign",
  6887. n
  6888. }, options) : generateInd(ind, {
  6889. type: "numberAlign",
  6890. n
  6891. }, options);
  6892. }
  6893. function generateInd(ind, newPart, options) {
  6894. var queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : ind.queue.concat(newPart);
  6895. var value = "";
  6896. var length = 0;
  6897. var lastTabs = 0;
  6898. var lastSpaces = 0;
  6899. var _iteratorNormalCompletion = true;
  6900. var _didIteratorError = false;
  6901. var _iteratorError = undefined;
  6902. try {
  6903. for (var _iterator = queue[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  6904. var part = _step.value;
  6905. switch (part.type) {
  6906. case "indent":
  6907. flush();
  6908. if (options.useTabs) {
  6909. addTabs(1);
  6910. } else {
  6911. addSpaces(options.tabWidth);
  6912. }
  6913. break;
  6914. case "stringAlign":
  6915. flush();
  6916. value += part.n;
  6917. length += part.n.length;
  6918. break;
  6919. case "numberAlign":
  6920. lastTabs += 1;
  6921. lastSpaces += part.n;
  6922. break;
  6923. /* istanbul ignore next */
  6924. default:
  6925. throw new Error(`Unexpected type '${part.type}'`);
  6926. }
  6927. }
  6928. } catch (err) {
  6929. _didIteratorError = true;
  6930. _iteratorError = err;
  6931. } finally {
  6932. try {
  6933. if (!_iteratorNormalCompletion && _iterator.return != null) {
  6934. _iterator.return();
  6935. }
  6936. } finally {
  6937. if (_didIteratorError) {
  6938. throw _iteratorError;
  6939. }
  6940. }
  6941. }
  6942. flushSpaces();
  6943. return Object.assign({}, ind, {
  6944. value,
  6945. length,
  6946. queue
  6947. });
  6948. function addTabs(count) {
  6949. value += "\t".repeat(count);
  6950. length += options.tabWidth * count;
  6951. }
  6952. function addSpaces(count) {
  6953. value += " ".repeat(count);
  6954. length += count;
  6955. }
  6956. function flush() {
  6957. if (options.useTabs) {
  6958. flushTabs();
  6959. } else {
  6960. flushSpaces();
  6961. }
  6962. }
  6963. function flushTabs() {
  6964. if (lastTabs > 0) {
  6965. addTabs(lastTabs);
  6966. }
  6967. resetLast();
  6968. }
  6969. function flushSpaces() {
  6970. if (lastSpaces > 0) {
  6971. addSpaces(lastSpaces);
  6972. }
  6973. resetLast();
  6974. }
  6975. function resetLast() {
  6976. lastTabs = 0;
  6977. lastSpaces = 0;
  6978. }
  6979. }
  6980. function fits(next, restCommands, width, options, mustBeFlat) {
  6981. var restIdx = restCommands.length;
  6982. var cmds = [next];
  6983. while (width >= 0) {
  6984. if (cmds.length === 0) {
  6985. if (restIdx === 0) {
  6986. return true;
  6987. }
  6988. cmds.push(restCommands[restIdx - 1]);
  6989. restIdx--;
  6990. continue;
  6991. }
  6992. var x = cmds.pop();
  6993. var ind = x[0];
  6994. var mode = x[1];
  6995. var doc = x[2];
  6996. if (typeof doc === "string") {
  6997. width -= util$1.getStringWidth(doc);
  6998. } else {
  6999. switch (doc.type) {
  7000. case "concat":
  7001. for (var i = doc.parts.length - 1; i >= 0; i--) {
  7002. cmds.push([ind, mode, doc.parts[i]]);
  7003. }
  7004. break;
  7005. case "indent":
  7006. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  7007. break;
  7008. case "align":
  7009. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  7010. break;
  7011. case "group":
  7012. if (mustBeFlat && doc.break) {
  7013. return false;
  7014. }
  7015. cmds.push([ind, doc.break ? MODE_BREAK : mode, doc.contents]);
  7016. break;
  7017. case "fill":
  7018. for (var _i = doc.parts.length - 1; _i >= 0; _i--) {
  7019. cmds.push([ind, mode, doc.parts[_i]]);
  7020. }
  7021. break;
  7022. case "if-break":
  7023. if (mode === MODE_BREAK) {
  7024. if (doc.breakContents) {
  7025. cmds.push([ind, mode, doc.breakContents]);
  7026. }
  7027. }
  7028. if (mode === MODE_FLAT) {
  7029. if (doc.flatContents) {
  7030. cmds.push([ind, mode, doc.flatContents]);
  7031. }
  7032. }
  7033. break;
  7034. case "line":
  7035. switch (mode) {
  7036. // fallthrough
  7037. case MODE_FLAT:
  7038. if (!doc.hard) {
  7039. if (!doc.soft) {
  7040. width -= 1;
  7041. }
  7042. break;
  7043. }
  7044. return true;
  7045. case MODE_BREAK:
  7046. return true;
  7047. }
  7048. break;
  7049. }
  7050. }
  7051. }
  7052. return false;
  7053. }
  7054. function printDocToString$1(doc, options) {
  7055. var width = options.printWidth;
  7056. var newLine = options.newLine || "\n";
  7057. var pos = 0; // cmds is basically a stack. We've turned a recursive call into a
  7058. // while loop which is much faster. The while loop below adds new
  7059. // cmds to the array instead of recursively calling `print`.
  7060. var cmds = [[rootIndent(), MODE_BREAK, doc]];
  7061. var out = [];
  7062. var shouldRemeasure = false;
  7063. var lineSuffix = [];
  7064. while (cmds.length !== 0) {
  7065. var x = cmds.pop();
  7066. var ind = x[0];
  7067. var mode = x[1];
  7068. var _doc = x[2];
  7069. if (typeof _doc === "string") {
  7070. out.push(_doc);
  7071. pos += util$1.getStringWidth(_doc);
  7072. } else {
  7073. switch (_doc.type) {
  7074. case "cursor":
  7075. out.push(cursor$2.placeholder);
  7076. break;
  7077. case "concat":
  7078. for (var i = _doc.parts.length - 1; i >= 0; i--) {
  7079. cmds.push([ind, mode, _doc.parts[i]]);
  7080. }
  7081. break;
  7082. case "indent":
  7083. cmds.push([makeIndent(ind, options), mode, _doc.contents]);
  7084. break;
  7085. case "align":
  7086. cmds.push([makeAlign(ind, _doc.n, options), mode, _doc.contents]);
  7087. break;
  7088. case "group":
  7089. switch (mode) {
  7090. case MODE_FLAT:
  7091. if (!shouldRemeasure) {
  7092. cmds.push([ind, _doc.break ? MODE_BREAK : MODE_FLAT, _doc.contents]);
  7093. break;
  7094. }
  7095. // fallthrough
  7096. case MODE_BREAK:
  7097. {
  7098. shouldRemeasure = false;
  7099. var next = [ind, MODE_FLAT, _doc.contents];
  7100. var rem = width - pos;
  7101. if (!_doc.break && fits(next, cmds, rem, options)) {
  7102. cmds.push(next);
  7103. } else {
  7104. // Expanded states are a rare case where a document
  7105. // can manually provide multiple representations of
  7106. // itself. It provides an array of documents
  7107. // going from the least expanded (most flattened)
  7108. // representation first to the most expanded. If a
  7109. // group has these, we need to manually go through
  7110. // these states and find the first one that fits.
  7111. if (_doc.expandedStates) {
  7112. var mostExpanded = _doc.expandedStates[_doc.expandedStates.length - 1];
  7113. if (_doc.break) {
  7114. cmds.push([ind, MODE_BREAK, mostExpanded]);
  7115. break;
  7116. } else {
  7117. for (var _i2 = 1; _i2 < _doc.expandedStates.length + 1; _i2++) {
  7118. if (_i2 >= _doc.expandedStates.length) {
  7119. cmds.push([ind, MODE_BREAK, mostExpanded]);
  7120. break;
  7121. } else {
  7122. var state = _doc.expandedStates[_i2];
  7123. var cmd = [ind, MODE_FLAT, state];
  7124. if (fits(cmd, cmds, rem, options)) {
  7125. cmds.push(cmd);
  7126. break;
  7127. }
  7128. }
  7129. }
  7130. }
  7131. } else {
  7132. cmds.push([ind, MODE_BREAK, _doc.contents]);
  7133. }
  7134. }
  7135. break;
  7136. }
  7137. }
  7138. break;
  7139. // Fills each line with as much code as possible before moving to a new
  7140. // line with the same indentation.
  7141. //
  7142. // Expects doc.parts to be an array of alternating content and
  7143. // whitespace. The whitespace contains the linebreaks.
  7144. //
  7145. // For example:
  7146. // ["I", line, "love", line, "monkeys"]
  7147. // or
  7148. // [{ type: group, ... }, softline, { type: group, ... }]
  7149. //
  7150. // It uses this parts structure to handle three main layout cases:
  7151. // * The first two content items fit on the same line without
  7152. // breaking
  7153. // -> output the first content item and the whitespace "flat".
  7154. // * Only the first content item fits on the line without breaking
  7155. // -> output the first content item "flat" and the whitespace with
  7156. // "break".
  7157. // * Neither content item fits on the line without breaking
  7158. // -> output the first content item and the whitespace with "break".
  7159. case "fill":
  7160. {
  7161. var _rem = width - pos;
  7162. var parts = _doc.parts;
  7163. if (parts.length === 0) {
  7164. break;
  7165. }
  7166. var content = parts[0];
  7167. var contentFlatCmd = [ind, MODE_FLAT, content];
  7168. var contentBreakCmd = [ind, MODE_BREAK, content];
  7169. var contentFits = fits(contentFlatCmd, [], _rem, options, true);
  7170. if (parts.length === 1) {
  7171. if (contentFits) {
  7172. cmds.push(contentFlatCmd);
  7173. } else {
  7174. cmds.push(contentBreakCmd);
  7175. }
  7176. break;
  7177. }
  7178. var whitespace = parts[1];
  7179. var whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
  7180. var whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
  7181. if (parts.length === 2) {
  7182. if (contentFits) {
  7183. cmds.push(whitespaceFlatCmd);
  7184. cmds.push(contentFlatCmd);
  7185. } else {
  7186. cmds.push(whitespaceBreakCmd);
  7187. cmds.push(contentBreakCmd);
  7188. }
  7189. break;
  7190. } // At this point we've handled the first pair (context, separator)
  7191. // and will create a new fill doc for the rest of the content.
  7192. // Ideally we wouldn't mutate the array here but coping all the
  7193. // elements to a new array would make this algorithm quadratic,
  7194. // which is unusable for large arrays (e.g. large texts in JSX).
  7195. parts.splice(0, 2);
  7196. var remainingCmd = [ind, mode, fill$1(parts)];
  7197. var secondContent = parts[0];
  7198. var firstAndSecondContentFlatCmd = [ind, MODE_FLAT, concat$2([content, whitespace, secondContent])];
  7199. var firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], _rem, options, true);
  7200. if (firstAndSecondContentFits) {
  7201. cmds.push(remainingCmd);
  7202. cmds.push(whitespaceFlatCmd);
  7203. cmds.push(contentFlatCmd);
  7204. } else if (contentFits) {
  7205. cmds.push(remainingCmd);
  7206. cmds.push(whitespaceBreakCmd);
  7207. cmds.push(contentFlatCmd);
  7208. } else {
  7209. cmds.push(remainingCmd);
  7210. cmds.push(whitespaceBreakCmd);
  7211. cmds.push(contentBreakCmd);
  7212. }
  7213. break;
  7214. }
  7215. case "if-break":
  7216. if (mode === MODE_BREAK) {
  7217. if (_doc.breakContents) {
  7218. cmds.push([ind, mode, _doc.breakContents]);
  7219. }
  7220. }
  7221. if (mode === MODE_FLAT) {
  7222. if (_doc.flatContents) {
  7223. cmds.push([ind, mode, _doc.flatContents]);
  7224. }
  7225. }
  7226. break;
  7227. case "line-suffix":
  7228. lineSuffix.push([ind, mode, _doc.contents]);
  7229. break;
  7230. case "line-suffix-boundary":
  7231. if (lineSuffix.length > 0) {
  7232. cmds.push([ind, mode, {
  7233. type: "line",
  7234. hard: true
  7235. }]);
  7236. }
  7237. break;
  7238. case "line":
  7239. switch (mode) {
  7240. case MODE_FLAT:
  7241. if (!_doc.hard) {
  7242. if (!_doc.soft) {
  7243. out.push(" ");
  7244. pos += 1;
  7245. }
  7246. break;
  7247. } else {
  7248. // This line was forced into the output even if we
  7249. // were in flattened mode, so we need to tell the next
  7250. // group that no matter what, it needs to remeasure
  7251. // because the previous measurement didn't accurately
  7252. // capture the entire expression (this is necessary
  7253. // for nested groups)
  7254. shouldRemeasure = true;
  7255. }
  7256. // fallthrough
  7257. case MODE_BREAK:
  7258. if (lineSuffix.length) {
  7259. cmds.push([ind, mode, _doc]);
  7260. [].push.apply(cmds, lineSuffix.reverse());
  7261. lineSuffix = [];
  7262. break;
  7263. }
  7264. if (_doc.literal) {
  7265. if (ind.root) {
  7266. out.push(newLine, ind.root.value);
  7267. pos = ind.root.length;
  7268. } else {
  7269. out.push(newLine);
  7270. pos = 0;
  7271. }
  7272. } else {
  7273. if (out.length > 0) {
  7274. // Trim whitespace at the end of line
  7275. while (out.length > 0 && typeof out[out.length - 1] === "string" && out[out.length - 1].match(/^[^\S\n]*$/)) {
  7276. out.pop();
  7277. }
  7278. if (out.length && typeof out[out.length - 1] === "string") {
  7279. out[out.length - 1] = out[out.length - 1].replace(/[^\S\n]*$/, "");
  7280. }
  7281. }
  7282. out.push(newLine + ind.value);
  7283. pos = ind.length;
  7284. }
  7285. break;
  7286. }
  7287. break;
  7288. default:
  7289. }
  7290. }
  7291. }
  7292. var cursorPlaceholderIndex = out.indexOf(cursor$2.placeholder);
  7293. if (cursorPlaceholderIndex !== -1) {
  7294. var otherCursorPlaceholderIndex = out.indexOf(cursor$2.placeholder, cursorPlaceholderIndex + 1);
  7295. var beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
  7296. var aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
  7297. var afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
  7298. return {
  7299. formatted: beforeCursor + aroundCursor + afterCursor,
  7300. cursorNodeStart: beforeCursor.length,
  7301. cursorNodeText: aroundCursor
  7302. };
  7303. }
  7304. return {
  7305. formatted: out.join("")
  7306. };
  7307. }
  7308. var docPrinter = {
  7309. printDocToString: printDocToString$1
  7310. };
  7311. function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
  7312. function traverseDocRec(doc) {
  7313. var shouldRecurse = true;
  7314. if (onEnter) {
  7315. if (onEnter(doc) === false) {
  7316. shouldRecurse = false;
  7317. }
  7318. }
  7319. if (shouldRecurse) {
  7320. if (doc.type === "concat" || doc.type === "fill") {
  7321. for (var i = 0; i < doc.parts.length; i++) {
  7322. traverseDocRec(doc.parts[i]);
  7323. }
  7324. } else if (doc.type === "if-break") {
  7325. if (doc.breakContents) {
  7326. traverseDocRec(doc.breakContents);
  7327. }
  7328. if (doc.flatContents) {
  7329. traverseDocRec(doc.flatContents);
  7330. }
  7331. } else if (doc.type === "group" && doc.expandedStates) {
  7332. if (shouldTraverseConditionalGroups) {
  7333. doc.expandedStates.forEach(traverseDocRec);
  7334. } else {
  7335. traverseDocRec(doc.contents);
  7336. }
  7337. } else if (doc.contents) {
  7338. traverseDocRec(doc.contents);
  7339. }
  7340. }
  7341. if (onExit) {
  7342. onExit(doc);
  7343. }
  7344. }
  7345. traverseDocRec(doc);
  7346. }
  7347. function mapDoc(doc, cb) {
  7348. if (doc.type === "concat" || doc.type === "fill") {
  7349. var parts = doc.parts.map(function (part) {
  7350. return mapDoc(part, cb);
  7351. });
  7352. return cb(Object.assign({}, doc, {
  7353. parts
  7354. }));
  7355. } else if (doc.type === "if-break") {
  7356. var breakContents = doc.breakContents && mapDoc(doc.breakContents, cb);
  7357. var flatContents = doc.flatContents && mapDoc(doc.flatContents, cb);
  7358. return cb(Object.assign({}, doc, {
  7359. breakContents,
  7360. flatContents
  7361. }));
  7362. } else if (doc.contents) {
  7363. var contents = mapDoc(doc.contents, cb);
  7364. return cb(Object.assign({}, doc, {
  7365. contents
  7366. }));
  7367. }
  7368. return cb(doc);
  7369. }
  7370. function findInDoc(doc, fn, defaultValue) {
  7371. var result = defaultValue;
  7372. var hasStopped = false;
  7373. traverseDoc(doc, function (doc) {
  7374. var maybeResult = fn(doc);
  7375. if (maybeResult !== undefined) {
  7376. hasStopped = true;
  7377. result = maybeResult;
  7378. }
  7379. if (hasStopped) {
  7380. return false;
  7381. }
  7382. });
  7383. return result;
  7384. }
  7385. function isEmpty(n) {
  7386. return typeof n === "string" && n.length === 0;
  7387. }
  7388. function isLineNext(doc) {
  7389. return findInDoc(doc, function (doc) {
  7390. if (typeof doc === "string") {
  7391. return false;
  7392. }
  7393. if (doc.type === "line") {
  7394. return true;
  7395. }
  7396. }, false);
  7397. }
  7398. function willBreak(doc) {
  7399. return findInDoc(doc, function (doc) {
  7400. if (doc.type === "group" && doc.break) {
  7401. return true;
  7402. }
  7403. if (doc.type === "line" && doc.hard) {
  7404. return true;
  7405. }
  7406. if (doc.type === "break-parent") {
  7407. return true;
  7408. }
  7409. }, false);
  7410. }
  7411. function breakParentGroup(groupStack) {
  7412. if (groupStack.length > 0) {
  7413. var parentGroup = groupStack[groupStack.length - 1]; // Breaks are not propagated through conditional groups because
  7414. // the user is expected to manually handle what breaks.
  7415. if (!parentGroup.expandedStates) {
  7416. parentGroup.break = true;
  7417. }
  7418. }
  7419. return null;
  7420. }
  7421. function propagateBreaks(doc) {
  7422. var alreadyVisited = new Map();
  7423. var groupStack = [];
  7424. traverseDoc(doc, function (doc) {
  7425. if (doc.type === "break-parent") {
  7426. breakParentGroup(groupStack);
  7427. }
  7428. if (doc.type === "group") {
  7429. groupStack.push(doc);
  7430. if (alreadyVisited.has(doc)) {
  7431. return false;
  7432. }
  7433. alreadyVisited.set(doc, true);
  7434. }
  7435. }, function (doc) {
  7436. if (doc.type === "group") {
  7437. var group = groupStack.pop();
  7438. if (group.break) {
  7439. breakParentGroup(groupStack);
  7440. }
  7441. }
  7442. },
  7443. /* shouldTraverseConditionalGroups */
  7444. true);
  7445. }
  7446. function removeLines(doc) {
  7447. // Force this doc into flat mode by statically converting all
  7448. // lines into spaces (or soft lines into nothing). Hard lines
  7449. // should still output because there's too great of a chance
  7450. // of breaking existing assumptions otherwise.
  7451. return mapDoc(doc, function (d) {
  7452. if (d.type === "line" && !d.hard) {
  7453. return d.soft ? "" : " ";
  7454. } else if (d.type === "if-break") {
  7455. return d.flatContents || "";
  7456. }
  7457. return d;
  7458. });
  7459. }
  7460. function stripTrailingHardline(doc) {
  7461. // HACK remove ending hardline, original PR: #1984
  7462. if (doc.type === "concat" && doc.parts.length === 2 && doc.parts[1].type === "concat" && doc.parts[1].parts.length === 2 && doc.parts[1].parts[0].hard && doc.parts[1].parts[1].type === "break-parent") {
  7463. return doc.parts[0];
  7464. }
  7465. return doc;
  7466. }
  7467. var docUtils = {
  7468. isEmpty,
  7469. willBreak,
  7470. isLineNext,
  7471. traverseDoc,
  7472. mapDoc,
  7473. propagateBreaks,
  7474. removeLines,
  7475. stripTrailingHardline
  7476. };
  7477. function flattenDoc(doc) {
  7478. if (doc.type === "concat") {
  7479. var res = [];
  7480. for (var i = 0; i < doc.parts.length; ++i) {
  7481. var doc2 = doc.parts[i];
  7482. if (typeof doc2 !== "string" && doc2.type === "concat") {
  7483. [].push.apply(res, flattenDoc(doc2).parts);
  7484. } else {
  7485. var flattened = flattenDoc(doc2);
  7486. if (flattened !== "") {
  7487. res.push(flattened);
  7488. }
  7489. }
  7490. }
  7491. return Object.assign({}, doc, {
  7492. parts: res
  7493. });
  7494. } else if (doc.type === "if-break") {
  7495. return Object.assign({}, doc, {
  7496. breakContents: doc.breakContents != null ? flattenDoc(doc.breakContents) : null,
  7497. flatContents: doc.flatContents != null ? flattenDoc(doc.flatContents) : null
  7498. });
  7499. } else if (doc.type === "group") {
  7500. return Object.assign({}, doc, {
  7501. contents: flattenDoc(doc.contents),
  7502. expandedStates: doc.expandedStates ? doc.expandedStates.map(flattenDoc) : doc.expandedStates
  7503. });
  7504. } else if (doc.contents) {
  7505. return Object.assign({}, doc, {
  7506. contents: flattenDoc(doc.contents)
  7507. });
  7508. }
  7509. return doc;
  7510. }
  7511. function printDoc(doc) {
  7512. if (typeof doc === "string") {
  7513. return JSON.stringify(doc);
  7514. }
  7515. if (doc.type === "line") {
  7516. if (doc.literalline) {
  7517. return "literalline";
  7518. }
  7519. if (doc.hard) {
  7520. return "hardline";
  7521. }
  7522. if (doc.soft) {
  7523. return "softline";
  7524. }
  7525. return "line";
  7526. }
  7527. if (doc.type === "break-parent") {
  7528. return "breakParent";
  7529. }
  7530. if (doc.type === "concat") {
  7531. return "[" + doc.parts.map(printDoc).join(", ") + "]";
  7532. }
  7533. if (doc.type === "indent") {
  7534. return "indent(" + printDoc(doc.contents) + ")";
  7535. }
  7536. if (doc.type === "align") {
  7537. 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) + ")";
  7538. }
  7539. if (doc.type === "if-break") {
  7540. return "ifBreak(" + printDoc(doc.breakContents) + (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") + ")";
  7541. }
  7542. if (doc.type === "group") {
  7543. if (doc.expandedStates) {
  7544. return "conditionalGroup(" + "[" + doc.expandedStates.map(printDoc).join(",") + "])";
  7545. }
  7546. return (doc.break ? "wrappedGroup" : "group") + "(" + printDoc(doc.contents) + ")";
  7547. }
  7548. if (doc.type === "fill") {
  7549. return "fill" + "(" + doc.parts.map(printDoc).join(", ") + ")";
  7550. }
  7551. if (doc.type === "line-suffix") {
  7552. return "lineSuffix(" + printDoc(doc.contents) + ")";
  7553. }
  7554. if (doc.type === "line-suffix-boundary") {
  7555. return "lineSuffixBoundary";
  7556. }
  7557. throw new Error("Unknown doc type " + doc.type);
  7558. }
  7559. var docDebug = {
  7560. printDocToDebug: function printDocToDebug(doc) {
  7561. return printDoc(flattenDoc(doc));
  7562. }
  7563. };
  7564. var doc = {
  7565. builders: docBuilders,
  7566. printer: docPrinter,
  7567. utils: docUtils,
  7568. debug: docDebug
  7569. };
  7570. var mapDoc$1 = doc.utils.mapDoc;
  7571. function isNextLineEmpty$1(text, node, options) {
  7572. return util$1.isNextLineEmpty(text, node, options.locEnd);
  7573. }
  7574. function getNextNonSpaceNonCommentCharacterIndex$1(text, node, options) {
  7575. return util$1.getNextNonSpaceNonCommentCharacterIndex(text, node, options.locEnd);
  7576. }
  7577. var utilShared = {
  7578. isNextLineEmpty: isNextLineEmpty$1,
  7579. isNextLineEmptyAfterIndex: util$1.isNextLineEmptyAfterIndex,
  7580. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$1,
  7581. mapDoc: mapDoc$1,
  7582. // TODO: remove in 2.0, we already exposed it in docUtils
  7583. makeString: util$1.makeString,
  7584. addLeadingComment: util$1.addLeadingComment,
  7585. addDanglingComment: util$1.addDanglingComment,
  7586. addTrailingComment: util$1.addTrailingComment
  7587. };
  7588. var _require$$0$builders = doc.builders;
  7589. var concat = _require$$0$builders.concat;
  7590. var hardline = _require$$0$builders.hardline;
  7591. var breakParent = _require$$0$builders.breakParent;
  7592. var indent = _require$$0$builders.indent;
  7593. var lineSuffix = _require$$0$builders.lineSuffix;
  7594. var join = _require$$0$builders.join;
  7595. var cursor = _require$$0$builders.cursor;
  7596. var hasNewline = util$1.hasNewline;
  7597. var skipNewline = util$1.skipNewline;
  7598. var isPreviousLineEmpty = util$1.isPreviousLineEmpty;
  7599. var addLeadingComment = utilShared.addLeadingComment;
  7600. var addDanglingComment = utilShared.addDanglingComment;
  7601. var addTrailingComment = utilShared.addTrailingComment;
  7602. var childNodesCacheKey = Symbol("child-nodes");
  7603. function getSortedChildNodes(node, options, resultArray) {
  7604. if (!node) {
  7605. return;
  7606. }
  7607. var printer = options.printer;
  7608. var locStart = options.locStart;
  7609. var locEnd = options.locEnd;
  7610. if (resultArray) {
  7611. if (node && printer.canAttachComment && printer.canAttachComment(node)) {
  7612. // This reverse insertion sort almost always takes constant
  7613. // time because we almost always (maybe always?) append the
  7614. // nodes in order anyway.
  7615. var i;
  7616. for (i = resultArray.length - 1; i >= 0; --i) {
  7617. if (locStart(resultArray[i]) <= locStart(node) && locEnd(resultArray[i]) <= locEnd(node)) {
  7618. break;
  7619. }
  7620. }
  7621. resultArray.splice(i + 1, 0, node);
  7622. return;
  7623. }
  7624. } else if (node[childNodesCacheKey]) {
  7625. return node[childNodesCacheKey];
  7626. }
  7627. var childNodes;
  7628. if (printer.getCommentChildNodes) {
  7629. childNodes = printer.getCommentChildNodes(node);
  7630. } else if (node && typeof node === "object") {
  7631. childNodes = Object.keys(node).filter(function (n) {
  7632. return n !== "enclosingNode" && n !== "precedingNode" && n !== "followingNode";
  7633. }).map(function (n) {
  7634. return node[n];
  7635. });
  7636. }
  7637. if (!childNodes) {
  7638. return;
  7639. }
  7640. if (!resultArray) {
  7641. Object.defineProperty(node, childNodesCacheKey, {
  7642. value: resultArray = [],
  7643. enumerable: false
  7644. });
  7645. }
  7646. childNodes.forEach(function (childNode) {
  7647. getSortedChildNodes(childNode, options, resultArray);
  7648. });
  7649. return resultArray;
  7650. } // As efficiently as possible, decorate the comment object with
  7651. // .precedingNode, .enclosingNode, and/or .followingNode properties, at
  7652. // least one of which is guaranteed to be defined.
  7653. function decorateComment(node, comment, options) {
  7654. var locStart = options.locStart;
  7655. var locEnd = options.locEnd;
  7656. var childNodes = getSortedChildNodes(node, options);
  7657. var precedingNode;
  7658. var followingNode; // Time to dust off the old binary search robes and wizard hat.
  7659. var left = 0;
  7660. var right = childNodes.length;
  7661. while (left < right) {
  7662. var middle = left + right >> 1;
  7663. var child = childNodes[middle];
  7664. if (locStart(child) - locStart(comment) <= 0 && locEnd(comment) - locEnd(child) <= 0) {
  7665. // The comment is completely contained by this child node.
  7666. comment.enclosingNode = child;
  7667. decorateComment(child, comment, options);
  7668. return; // Abandon the binary search at this level.
  7669. }
  7670. if (locEnd(child) - locStart(comment) <= 0) {
  7671. // This child node falls completely before the comment.
  7672. // Because we will never consider this node or any nodes
  7673. // before it again, this node must be the closest preceding
  7674. // node we have encountered so far.
  7675. precedingNode = child;
  7676. left = middle + 1;
  7677. continue;
  7678. }
  7679. if (locEnd(comment) - locStart(child) <= 0) {
  7680. // This child node falls completely after the comment.
  7681. // Because we will never consider this node or any nodes after
  7682. // it again, this node must be the closest following node we
  7683. // have encountered so far.
  7684. followingNode = child;
  7685. right = middle;
  7686. continue;
  7687. }
  7688. /* istanbul ignore next */
  7689. throw new Error("Comment location overlaps with node location");
  7690. } // We don't want comments inside of different expressions inside of the same
  7691. // template literal to move to another expression.
  7692. if (comment.enclosingNode && comment.enclosingNode.type === "TemplateLiteral") {
  7693. var quasis = comment.enclosingNode.quasis;
  7694. var commentIndex = findExpressionIndexForComment(quasis, comment, options);
  7695. if (precedingNode && findExpressionIndexForComment(quasis, precedingNode, options) !== commentIndex) {
  7696. precedingNode = null;
  7697. }
  7698. if (followingNode && findExpressionIndexForComment(quasis, followingNode, options) !== commentIndex) {
  7699. followingNode = null;
  7700. }
  7701. }
  7702. if (precedingNode) {
  7703. comment.precedingNode = precedingNode;
  7704. }
  7705. if (followingNode) {
  7706. comment.followingNode = followingNode;
  7707. }
  7708. }
  7709. function attach(comments, ast, text, options) {
  7710. if (!Array.isArray(comments)) {
  7711. return;
  7712. }
  7713. var tiesToBreak = [];
  7714. var locStart = options.locStart;
  7715. var locEnd = options.locEnd;
  7716. comments.forEach(function (comment, i) {
  7717. if ((options.parser === "json" || options.parser === "json5") && locStart(comment) - locStart(ast) <= 0) {
  7718. addLeadingComment(ast, comment);
  7719. return;
  7720. }
  7721. decorateComment(ast, comment, options);
  7722. var precedingNode = comment.precedingNode;
  7723. var enclosingNode = comment.enclosingNode;
  7724. var followingNode = comment.followingNode;
  7725. var pluginHandleOwnLineComment = options.printer.handleComments && options.printer.handleComments.ownLine ? options.printer.handleComments.ownLine : function () {
  7726. return false;
  7727. };
  7728. var pluginHandleEndOfLineComment = options.printer.handleComments && options.printer.handleComments.endOfLine ? options.printer.handleComments.endOfLine : function () {
  7729. return false;
  7730. };
  7731. var pluginHandleRemainingComment = options.printer.handleComments && options.printer.handleComments.remaining ? options.printer.handleComments.remaining : function () {
  7732. return false;
  7733. };
  7734. var isLastComment = comments.length - 1 === i;
  7735. if (hasNewline(text, locStart(comment), {
  7736. backwards: true
  7737. })) {
  7738. // If a comment exists on its own line, prefer a leading comment.
  7739. // We also need to check if it's the first line of the file.
  7740. if (pluginHandleOwnLineComment(comment, text, options, ast, isLastComment)) {// We're good
  7741. } else if (followingNode) {
  7742. // Always a leading comment.
  7743. addLeadingComment(followingNode, comment);
  7744. } else if (precedingNode) {
  7745. addTrailingComment(precedingNode, comment);
  7746. } else if (enclosingNode) {
  7747. addDanglingComment(enclosingNode, comment);
  7748. } else {
  7749. // There are no nodes, let's attach it to the root of the ast
  7750. /* istanbul ignore next */
  7751. addDanglingComment(ast, comment);
  7752. }
  7753. } else if (hasNewline(text, locEnd(comment))) {
  7754. if (pluginHandleEndOfLineComment(comment, text, options, ast, isLastComment)) {// We're good
  7755. } else if (precedingNode) {
  7756. // There is content before this comment on the same line, but
  7757. // none after it, so prefer a trailing comment of the previous node.
  7758. addTrailingComment(precedingNode, comment);
  7759. } else if (followingNode) {
  7760. addLeadingComment(followingNode, comment);
  7761. } else if (enclosingNode) {
  7762. addDanglingComment(enclosingNode, comment);
  7763. } else {
  7764. // There are no nodes, let's attach it to the root of the ast
  7765. /* istanbul ignore next */
  7766. addDanglingComment(ast, comment);
  7767. }
  7768. } else {
  7769. if (pluginHandleRemainingComment(comment, text, options, ast, isLastComment)) {// We're good
  7770. } else if (precedingNode && followingNode) {
  7771. // Otherwise, text exists both before and after the comment on
  7772. // the same line. If there is both a preceding and following
  7773. // node, use a tie-breaking algorithm to determine if it should
  7774. // be attached to the next or previous node. In the last case,
  7775. // simply attach the right node;
  7776. var tieCount = tiesToBreak.length;
  7777. if (tieCount > 0) {
  7778. var lastTie = tiesToBreak[tieCount - 1];
  7779. if (lastTie.followingNode !== comment.followingNode) {
  7780. breakTies(tiesToBreak, text, options);
  7781. }
  7782. }
  7783. tiesToBreak.push(comment);
  7784. } else if (precedingNode) {
  7785. addTrailingComment(precedingNode, comment);
  7786. } else if (followingNode) {
  7787. addLeadingComment(followingNode, comment);
  7788. } else if (enclosingNode) {
  7789. addDanglingComment(enclosingNode, comment);
  7790. } else {
  7791. // There are no nodes, let's attach it to the root of the ast
  7792. /* istanbul ignore next */
  7793. addDanglingComment(ast, comment);
  7794. }
  7795. }
  7796. });
  7797. breakTies(tiesToBreak, text, options);
  7798. comments.forEach(function (comment) {
  7799. // These node references were useful for breaking ties, but we
  7800. // don't need them anymore, and they create cycles in the AST that
  7801. // may lead to infinite recursion if we don't delete them here.
  7802. delete comment.precedingNode;
  7803. delete comment.enclosingNode;
  7804. delete comment.followingNode;
  7805. });
  7806. }
  7807. function breakTies(tiesToBreak, text, options) {
  7808. var tieCount = tiesToBreak.length;
  7809. if (tieCount === 0) {
  7810. return;
  7811. }
  7812. var precedingNode = tiesToBreak[0].precedingNode;
  7813. var followingNode = tiesToBreak[0].followingNode;
  7814. var gapEndPos = options.locStart(followingNode); // Iterate backwards through tiesToBreak, examining the gaps
  7815. // between the tied comments. In order to qualify as leading, a
  7816. // comment must be separated from followingNode by an unbroken series of
  7817. // gaps (or other comments). Gaps should only contain whitespace or open
  7818. // parentheses.
  7819. var indexOfFirstLeadingComment;
  7820. for (indexOfFirstLeadingComment = tieCount; indexOfFirstLeadingComment > 0; --indexOfFirstLeadingComment) {
  7821. var comment = tiesToBreak[indexOfFirstLeadingComment - 1];
  7822. assert.strictEqual(comment.precedingNode, precedingNode);
  7823. assert.strictEqual(comment.followingNode, followingNode);
  7824. var gap = text.slice(options.locEnd(comment), gapEndPos).trim();
  7825. if (gap === "" || /^\(+$/.test(gap)) {
  7826. gapEndPos = options.locStart(comment);
  7827. } else {
  7828. // The gap string contained something other than whitespace or open
  7829. // parentheses.
  7830. break;
  7831. }
  7832. }
  7833. tiesToBreak.forEach(function (comment, i) {
  7834. if (i < indexOfFirstLeadingComment) {
  7835. addTrailingComment(precedingNode, comment);
  7836. } else {
  7837. addLeadingComment(followingNode, comment);
  7838. }
  7839. });
  7840. tiesToBreak.length = 0;
  7841. }
  7842. function printComment(commentPath, options) {
  7843. var comment = commentPath.getValue();
  7844. comment.printed = true;
  7845. return options.printer.printComment(commentPath, options);
  7846. }
  7847. function findExpressionIndexForComment(quasis, comment, options) {
  7848. var startPos = options.locStart(comment) - 1;
  7849. for (var i = 1; i < quasis.length; ++i) {
  7850. if (startPos < getQuasiRange(quasis[i]).start) {
  7851. return i - 1;
  7852. }
  7853. } // We haven't found it, it probably means that some of the locations are off.
  7854. // Let's just return the first one.
  7855. /* istanbul ignore next */
  7856. return 0;
  7857. }
  7858. function getQuasiRange(expr) {
  7859. if (expr.start !== undefined) {
  7860. // Babylon
  7861. return {
  7862. start: expr.start,
  7863. end: expr.end
  7864. };
  7865. } // Flow
  7866. return {
  7867. start: expr.range[0],
  7868. end: expr.range[1]
  7869. };
  7870. }
  7871. function printLeadingComment(commentPath, print, options) {
  7872. var comment = commentPath.getValue();
  7873. var contents = printComment(commentPath, options);
  7874. if (!contents) {
  7875. return "";
  7876. }
  7877. var isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // Leading block comments should see if they need to stay on the
  7878. // same line or not.
  7879. if (isBlock) {
  7880. return concat([contents, hasNewline(options.originalText, options.locEnd(comment)) ? hardline : " "]);
  7881. }
  7882. return concat([contents, hardline]);
  7883. }
  7884. function printTrailingComment(commentPath, print, options) {
  7885. var comment = commentPath.getValue();
  7886. var contents = printComment(commentPath, options);
  7887. if (!contents) {
  7888. return "";
  7889. }
  7890. var isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // We don't want the line to break
  7891. // when the parentParentNode is a ClassDeclaration/-Expression
  7892. // And the parentNode is in the superClass property
  7893. var parentNode = commentPath.getNode(1);
  7894. var parentParentNode = commentPath.getNode(2);
  7895. var isParentSuperClass = parentParentNode && (parentParentNode.type === "ClassDeclaration" || parentParentNode.type === "ClassExpression") && parentParentNode.superClass === parentNode;
  7896. if (hasNewline(options.originalText, options.locStart(comment), {
  7897. backwards: true
  7898. })) {
  7899. // This allows comments at the end of nested structures:
  7900. // {
  7901. // x: 1,
  7902. // y: 2
  7903. // // A comment
  7904. // }
  7905. // Those kinds of comments are almost always leading comments, but
  7906. // here it doesn't go "outside" the block and turns it into a
  7907. // trailing comment for `2`. We can simulate the above by checking
  7908. // if this a comment on its own line; normal trailing comments are
  7909. // always at the end of another expression.
  7910. var isLineBeforeEmpty = isPreviousLineEmpty(options.originalText, comment, options.locStart);
  7911. return lineSuffix(concat([hardline, isLineBeforeEmpty ? hardline : "", contents]));
  7912. } else if (isBlock || isParentSuperClass) {
  7913. // Trailing block comments never need a newline
  7914. return concat([" ", contents]);
  7915. }
  7916. return concat([lineSuffix(" " + contents), !isBlock ? breakParent : ""]);
  7917. }
  7918. function printDanglingComments(path$$1, options, sameIndent, filter) {
  7919. var parts = [];
  7920. var node = path$$1.getValue();
  7921. if (!node || !node.comments) {
  7922. return "";
  7923. }
  7924. path$$1.each(function (commentPath) {
  7925. var comment = commentPath.getValue();
  7926. if (comment && !comment.leading && !comment.trailing && (!filter || filter(comment))) {
  7927. parts.push(printComment(commentPath, options));
  7928. }
  7929. }, "comments");
  7930. if (parts.length === 0) {
  7931. return "";
  7932. }
  7933. if (sameIndent) {
  7934. return join(hardline, parts);
  7935. }
  7936. return indent(concat([hardline, join(hardline, parts)]));
  7937. }
  7938. function prependCursorPlaceholder(path$$1, options, printed) {
  7939. if (path$$1.getNode() === options.cursorNode && path$$1.getValue()) {
  7940. return concat([cursor, printed, cursor]);
  7941. }
  7942. return printed;
  7943. }
  7944. function printComments(path$$1, print, options, needsSemi) {
  7945. var value = path$$1.getValue();
  7946. var printed = print(path$$1);
  7947. var comments = value && value.comments;
  7948. if (!comments || comments.length === 0) {
  7949. return prependCursorPlaceholder(path$$1, options, printed);
  7950. }
  7951. var leadingParts = [];
  7952. var trailingParts = [needsSemi ? ";" : "", printed];
  7953. path$$1.each(function (commentPath) {
  7954. var comment = commentPath.getValue();
  7955. var leading = comment.leading;
  7956. var trailing = comment.trailing;
  7957. if (leading) {
  7958. var contents = printLeadingComment(commentPath, print, options);
  7959. if (!contents) {
  7960. return;
  7961. }
  7962. leadingParts.push(contents);
  7963. var text = options.originalText;
  7964. if (hasNewline(text, skipNewline(text, options.locEnd(comment)))) {
  7965. leadingParts.push(hardline);
  7966. }
  7967. } else if (trailing) {
  7968. trailingParts.push(printTrailingComment(commentPath, print, options));
  7969. }
  7970. }, "comments");
  7971. return prependCursorPlaceholder(path$$1, options, concat(leadingParts.concat(trailingParts)));
  7972. }
  7973. var comments = {
  7974. attach,
  7975. printComments,
  7976. printDanglingComments,
  7977. getSortedChildNodes
  7978. };
  7979. function FastPath(value) {
  7980. assert.ok(this instanceof FastPath);
  7981. this.stack = [value];
  7982. } // The name of the current property is always the penultimate element of
  7983. // this.stack, and always a String.
  7984. FastPath.prototype.getName = function getName() {
  7985. var s = this.stack;
  7986. var len = s.length;
  7987. if (len > 1) {
  7988. return s[len - 2];
  7989. } // Since the name is always a string, null is a safe sentinel value to
  7990. // return if we do not know the name of the (root) value.
  7991. /* istanbul ignore next */
  7992. return null;
  7993. }; // The value of the current property is always the final element of
  7994. // this.stack.
  7995. FastPath.prototype.getValue = function getValue() {
  7996. var s = this.stack;
  7997. return s[s.length - 1];
  7998. };
  7999. function getNodeHelper(path$$1, count) {
  8000. var s = path$$1.stack;
  8001. for (var i = s.length - 1; i >= 0; i -= 2) {
  8002. var value = s[i];
  8003. if (value && !Array.isArray(value) && --count < 0) {
  8004. return value;
  8005. }
  8006. }
  8007. return null;
  8008. }
  8009. FastPath.prototype.getNode = function getNode(count) {
  8010. return getNodeHelper(this, ~~count);
  8011. };
  8012. FastPath.prototype.getParentNode = function getParentNode(count) {
  8013. return getNodeHelper(this, ~~count + 1);
  8014. }; // Temporarily push properties named by string arguments given after the
  8015. // callback function onto this.stack, then call the callback with a
  8016. // reference to this (modified) FastPath object. Note that the stack will
  8017. // be restored to its original state after the callback is finished, so it
  8018. // is probably a mistake to retain a reference to the path.
  8019. FastPath.prototype.call = function call(callback
  8020. /*, name1, name2, ... */
  8021. ) {
  8022. var s = this.stack;
  8023. var origLen = s.length;
  8024. var value = s[origLen - 1];
  8025. var argc = arguments.length;
  8026. for (var i = 1; i < argc; ++i) {
  8027. var name = arguments[i];
  8028. value = value[name];
  8029. s.push(name, value);
  8030. }
  8031. var result = callback(this);
  8032. s.length = origLen;
  8033. return result;
  8034. }; // Similar to FastPath.prototype.call, except that the value obtained by
  8035. // accessing this.getValue()[name1][name2]... should be array-like. The
  8036. // callback will be called with a reference to this path object for each
  8037. // element of the array.
  8038. FastPath.prototype.each = function each(callback
  8039. /*, name1, name2, ... */
  8040. ) {
  8041. var s = this.stack;
  8042. var origLen = s.length;
  8043. var value = s[origLen - 1];
  8044. var argc = arguments.length;
  8045. for (var i = 1; i < argc; ++i) {
  8046. var name = arguments[i];
  8047. value = value[name];
  8048. s.push(name, value);
  8049. }
  8050. for (var _i = 0; _i < value.length; ++_i) {
  8051. if (_i in value) {
  8052. s.push(_i, value[_i]); // If the callback needs to know the value of i, call
  8053. // path.getName(), assuming path is the parameter name.
  8054. callback(this);
  8055. s.length -= 2;
  8056. }
  8057. }
  8058. s.length = origLen;
  8059. }; // Similar to FastPath.prototype.each, except that the results of the
  8060. // callback function invocations are stored in an array and returned at
  8061. // the end of the iteration.
  8062. FastPath.prototype.map = function map(callback
  8063. /*, name1, name2, ... */
  8064. ) {
  8065. var s = this.stack;
  8066. var origLen = s.length;
  8067. var value = s[origLen - 1];
  8068. var argc = arguments.length;
  8069. for (var i = 1; i < argc; ++i) {
  8070. var name = arguments[i];
  8071. value = value[name];
  8072. s.push(name, value);
  8073. }
  8074. var result = new Array(value.length);
  8075. for (var _i2 = 0; _i2 < value.length; ++_i2) {
  8076. if (_i2 in value) {
  8077. s.push(_i2, value[_i2]);
  8078. result[_i2] = callback(this, _i2);
  8079. s.length -= 2;
  8080. }
  8081. }
  8082. s.length = origLen;
  8083. return result;
  8084. };
  8085. var fastPath = FastPath;
  8086. var normalize$1 = options.normalize;
  8087. function printSubtree(path$$1, print, options$$1, printAstToDoc) {
  8088. if (options$$1.printer.embed) {
  8089. return options$$1.printer.embed(path$$1, print, function (text, partialNextOptions) {
  8090. return textToDoc(text, partialNextOptions, options$$1, printAstToDoc);
  8091. }, options$$1);
  8092. }
  8093. }
  8094. function textToDoc(text, partialNextOptions, parentOptions, printAstToDoc) {
  8095. var nextOptions = normalize$1(Object.assign({}, parentOptions, partialNextOptions, {
  8096. parentParser: parentOptions.parser,
  8097. originalText: text
  8098. }), {
  8099. passThrough: true
  8100. });
  8101. var result = parser.parse(text, nextOptions);
  8102. var ast = result.ast;
  8103. text = result.text;
  8104. var astComments = ast.comments;
  8105. delete ast.comments;
  8106. comments.attach(astComments, ast, text, nextOptions);
  8107. return printAstToDoc(ast, nextOptions);
  8108. }
  8109. var multiparser = {
  8110. printSubtree
  8111. };
  8112. var doc$2 = doc;
  8113. var docBuilders$2 = doc$2.builders;
  8114. var concat$3 = docBuilders$2.concat;
  8115. var hardline$2 = docBuilders$2.hardline;
  8116. var addAlignmentToDoc$1 = docBuilders$2.addAlignmentToDoc;
  8117. var docUtils$2 = doc$2.utils;
  8118. function printAstToDoc(ast, options, addAlignmentSize) {
  8119. addAlignmentSize = addAlignmentSize || 0;
  8120. var printer = options.printer;
  8121. var cache = new Map();
  8122. function printGenerically(path$$1, args) {
  8123. var node = path$$1.getValue();
  8124. var shouldCache = node && typeof node === "object" && args === undefined;
  8125. if (shouldCache && cache.has(node)) {
  8126. return cache.get(node);
  8127. } // We let JSXElement print its comments itself because it adds () around
  8128. // UnionTypeAnnotation has to align the child without the comments
  8129. var res;
  8130. if (printer.willPrintOwnComments && printer.willPrintOwnComments(path$$1)) {
  8131. res = genericPrint(path$$1, options, printGenerically, args);
  8132. } else {
  8133. res = comments.printComments(path$$1, function (p) {
  8134. return genericPrint(p, options, printGenerically, args);
  8135. }, options, args && args.needsSemi);
  8136. }
  8137. if (shouldCache) {
  8138. cache.set(node, res);
  8139. }
  8140. return res;
  8141. }
  8142. var doc$$2 = printGenerically(new fastPath(ast));
  8143. if (addAlignmentSize > 0) {
  8144. // Add a hardline to make the indents take effect
  8145. // It should be removed in index.js format()
  8146. doc$$2 = addAlignmentToDoc$1(docUtils$2.removeLines(concat$3([hardline$2, doc$$2])), addAlignmentSize, options.tabWidth);
  8147. }
  8148. docUtils$2.propagateBreaks(doc$$2);
  8149. if (options.parser === "json" || options.parser === "json5" || options.parser === "json-stringify") {
  8150. doc$$2 = concat$3([doc$$2, hardline$2]);
  8151. }
  8152. return doc$$2;
  8153. }
  8154. function genericPrint(path$$1, options, printPath, args) {
  8155. assert.ok(path$$1 instanceof fastPath);
  8156. var node = path$$1.getValue();
  8157. var printer = options.printer; // Escape hatch
  8158. if (printer.hasPrettierIgnore && printer.hasPrettierIgnore(path$$1)) {
  8159. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  8160. }
  8161. if (node) {
  8162. try {
  8163. // Potentially switch to a different parser
  8164. var sub = multiparser.printSubtree(path$$1, printPath, options, printAstToDoc);
  8165. if (sub) {
  8166. return sub;
  8167. }
  8168. } catch (error) {
  8169. /* istanbul ignore if */
  8170. if (process.env.PRETTIER_DEBUG) {
  8171. throw error;
  8172. } // Continue with current parser
  8173. }
  8174. }
  8175. return printer.print(path$$1, options, printPath, args);
  8176. }
  8177. var astToDoc = printAstToDoc;
  8178. function findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts) {
  8179. var resultStartNode = startNodeAndParents.node;
  8180. var resultEndNode = endNodeAndParents.node;
  8181. if (resultStartNode === resultEndNode) {
  8182. return {
  8183. startNode: resultStartNode,
  8184. endNode: resultEndNode
  8185. };
  8186. }
  8187. var _iteratorNormalCompletion = true;
  8188. var _didIteratorError = false;
  8189. var _iteratorError = undefined;
  8190. try {
  8191. for (var _iterator = endNodeAndParents.parentNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  8192. var endParent = _step.value;
  8193. if (endParent.type !== "Program" && endParent.type !== "File" && opts.locStart(endParent) >= opts.locStart(startNodeAndParents.node)) {
  8194. resultEndNode = endParent;
  8195. } else {
  8196. break;
  8197. }
  8198. }
  8199. } catch (err) {
  8200. _didIteratorError = true;
  8201. _iteratorError = err;
  8202. } finally {
  8203. try {
  8204. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8205. _iterator.return();
  8206. }
  8207. } finally {
  8208. if (_didIteratorError) {
  8209. throw _iteratorError;
  8210. }
  8211. }
  8212. }
  8213. var _iteratorNormalCompletion2 = true;
  8214. var _didIteratorError2 = false;
  8215. var _iteratorError2 = undefined;
  8216. try {
  8217. for (var _iterator2 = startNodeAndParents.parentNodes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  8218. var startParent = _step2.value;
  8219. if (startParent.type !== "Program" && startParent.type !== "File" && opts.locEnd(startParent) <= opts.locEnd(endNodeAndParents.node)) {
  8220. resultStartNode = startParent;
  8221. } else {
  8222. break;
  8223. }
  8224. }
  8225. } catch (err) {
  8226. _didIteratorError2 = true;
  8227. _iteratorError2 = err;
  8228. } finally {
  8229. try {
  8230. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  8231. _iterator2.return();
  8232. }
  8233. } finally {
  8234. if (_didIteratorError2) {
  8235. throw _iteratorError2;
  8236. }
  8237. }
  8238. }
  8239. return {
  8240. startNode: resultStartNode,
  8241. endNode: resultEndNode
  8242. };
  8243. }
  8244. function findNodeAtOffset(node, offset, options, predicate, parentNodes) {
  8245. predicate = predicate || function () {
  8246. return true;
  8247. };
  8248. parentNodes = parentNodes || [];
  8249. var start = options.locStart(node, options.locStart);
  8250. var end = options.locEnd(node, options.locEnd);
  8251. if (start <= offset && offset <= end) {
  8252. var _iteratorNormalCompletion3 = true;
  8253. var _didIteratorError3 = false;
  8254. var _iteratorError3 = undefined;
  8255. try {
  8256. for (var _iterator3 = comments.getSortedChildNodes(node, options)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  8257. var childNode = _step3.value;
  8258. var childResult = findNodeAtOffset(childNode, offset, options, predicate, [node].concat(parentNodes));
  8259. if (childResult) {
  8260. return childResult;
  8261. }
  8262. }
  8263. } catch (err) {
  8264. _didIteratorError3 = true;
  8265. _iteratorError3 = err;
  8266. } finally {
  8267. try {
  8268. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  8269. _iterator3.return();
  8270. }
  8271. } finally {
  8272. if (_didIteratorError3) {
  8273. throw _iteratorError3;
  8274. }
  8275. }
  8276. }
  8277. if (predicate(node)) {
  8278. return {
  8279. node: node,
  8280. parentNodes: parentNodes
  8281. };
  8282. }
  8283. }
  8284. } // See https://www.ecma-international.org/ecma-262/5.1/#sec-A.5
  8285. function isSourceElement(opts, node) {
  8286. if (node == null) {
  8287. return false;
  8288. } // JS and JS like to avoid repetitions
  8289. var jsSourceElements = ["FunctionDeclaration", "BlockStatement", "BreakStatement", "ContinueStatement", "DebuggerStatement", "DoWhileStatement", "EmptyStatement", "ExpressionStatement", "ForInStatement", "ForStatement", "IfStatement", "LabeledStatement", "ReturnStatement", "SwitchStatement", "ThrowStatement", "TryStatement", "VariableDeclaration", "WhileStatement", "WithStatement", "ClassDeclaration", // ES 2015
  8290. "ImportDeclaration", // Module
  8291. "ExportDefaultDeclaration", // Module
  8292. "ExportNamedDeclaration", // Module
  8293. "ExportAllDeclaration", // Module
  8294. "TypeAlias", // Flow
  8295. "InterfaceDeclaration", // Flow, TypeScript
  8296. "TypeAliasDeclaration", // TypeScript
  8297. "ExportAssignment", // TypeScript
  8298. "ExportDeclaration" // TypeScript
  8299. ];
  8300. var jsonSourceElements = ["ObjectExpression", "ArrayExpression", "StringLiteral", "NumericLiteral", "BooleanLiteral", "NullLiteral"];
  8301. var graphqlSourceElements = ["OperationDefinition", "FragmentDefinition", "VariableDefinition", "TypeExtensionDefinition", "ObjectTypeDefinition", "FieldDefinition", "DirectiveDefinition", "EnumTypeDefinition", "EnumValueDefinition", "InputValueDefinition", "InputObjectTypeDefinition", "SchemaDefinition", "OperationTypeDefinition", "InterfaceTypeDefinition", "UnionTypeDefinition", "ScalarTypeDefinition"];
  8302. switch (opts.parser) {
  8303. case "flow":
  8304. case "babylon":
  8305. case "typescript":
  8306. return jsSourceElements.indexOf(node.type) > -1;
  8307. case "json":
  8308. return jsonSourceElements.indexOf(node.type) > -1;
  8309. case "graphql":
  8310. return graphqlSourceElements.indexOf(node.kind) > -1;
  8311. }
  8312. return false;
  8313. }
  8314. function calculateRange(text, opts, ast) {
  8315. // Contract the range so that it has non-whitespace characters at its endpoints.
  8316. // This ensures we can format a range that doesn't end on a node.
  8317. var rangeStringOrig = text.slice(opts.rangeStart, opts.rangeEnd);
  8318. var startNonWhitespace = Math.max(opts.rangeStart + rangeStringOrig.search(/\S/), opts.rangeStart);
  8319. var endNonWhitespace;
  8320. for (endNonWhitespace = opts.rangeEnd; endNonWhitespace > opts.rangeStart; --endNonWhitespace) {
  8321. if (text[endNonWhitespace - 1].match(/\S/)) {
  8322. break;
  8323. }
  8324. }
  8325. var startNodeAndParents = findNodeAtOffset(ast, startNonWhitespace, opts, function (node) {
  8326. return isSourceElement(opts, node);
  8327. });
  8328. var endNodeAndParents = findNodeAtOffset(ast, endNonWhitespace, opts, function (node) {
  8329. return isSourceElement(opts, node);
  8330. });
  8331. if (!startNodeAndParents || !endNodeAndParents) {
  8332. return {
  8333. rangeStart: 0,
  8334. rangeEnd: 0
  8335. };
  8336. }
  8337. var siblingAncestors = findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts);
  8338. var startNode = siblingAncestors.startNode;
  8339. var endNode = siblingAncestors.endNode;
  8340. var rangeStart = Math.min(opts.locStart(startNode, opts.locStart), opts.locStart(endNode, opts.locStart));
  8341. var rangeEnd = Math.max(opts.locEnd(startNode, opts.locEnd), opts.locEnd(endNode, opts.locEnd));
  8342. return {
  8343. rangeStart: rangeStart,
  8344. rangeEnd: rangeEnd
  8345. };
  8346. }
  8347. var rangeUtil = {
  8348. calculateRange,
  8349. findNodeAtOffset
  8350. };
  8351. var normalizeOptions = options.normalize;
  8352. var printDocToString = doc.printer.printDocToString;
  8353. var printDocToDebug = doc.debug.printDocToDebug;
  8354. var UTF8BOM = 0xfeff;
  8355. var CURSOR = Symbol("cursor");
  8356. function guessLineEnding(text) {
  8357. var index = text.indexOf("\n");
  8358. if (index >= 0 && text.charAt(index - 1) === "\r") {
  8359. return "\r\n";
  8360. }
  8361. return "\n";
  8362. }
  8363. function ensureAllCommentsPrinted(astComments) {
  8364. if (!astComments) {
  8365. return;
  8366. }
  8367. for (var i = 0; i < astComments.length; ++i) {
  8368. if (astComments[i].value.trim() === "prettier-ignore") {
  8369. // If there's a prettier-ignore, we're not printing that sub-tree so we
  8370. // don't know if the comments was printed or not.
  8371. return;
  8372. }
  8373. }
  8374. astComments.forEach(function (comment) {
  8375. if (!comment.printed) {
  8376. throw new Error('Comment "' + comment.value.trim() + '" was not printed. Please report this error!');
  8377. }
  8378. delete comment.printed;
  8379. });
  8380. }
  8381. function attachComments(text, ast, opts) {
  8382. var astComments = ast.comments;
  8383. if (astComments) {
  8384. delete ast.comments;
  8385. comments.attach(astComments, ast, text, opts);
  8386. }
  8387. ast.tokens = [];
  8388. opts.originalText = text.trimRight();
  8389. return astComments;
  8390. }
  8391. function coreFormat(text, opts, addAlignmentSize) {
  8392. if (!text || !text.trim().length) {
  8393. return {
  8394. formatted: "",
  8395. cursorOffset: 0
  8396. };
  8397. }
  8398. addAlignmentSize = addAlignmentSize || 0;
  8399. var parsed = parser.parse(text, opts);
  8400. var ast = parsed.ast;
  8401. text = parsed.text;
  8402. if (opts.cursorOffset >= 0) {
  8403. var nodeResult = rangeUtil.findNodeAtOffset(ast, opts.cursorOffset, opts);
  8404. if (nodeResult && nodeResult.node) {
  8405. opts.cursorNode = nodeResult.node;
  8406. }
  8407. }
  8408. var astComments = attachComments(text, ast, opts);
  8409. var doc$$1 = astToDoc(ast, opts, addAlignmentSize);
  8410. opts.newLine = guessLineEnding(text);
  8411. var result = printDocToString(doc$$1, opts);
  8412. ensureAllCommentsPrinted(astComments); // Remove extra leading indentation as well as the added indentation after last newline
  8413. if (addAlignmentSize > 0) {
  8414. var trimmed = result.formatted.trim();
  8415. if (result.cursorNodeStart !== undefined) {
  8416. result.cursorNodeStart -= result.formatted.indexOf(trimmed);
  8417. }
  8418. result.formatted = trimmed + opts.newLine;
  8419. }
  8420. if (opts.cursorOffset >= 0) {
  8421. var oldCursorNodeStart;
  8422. var oldCursorNodeText;
  8423. var cursorOffsetRelativeToOldCursorNode;
  8424. var newCursorNodeStart;
  8425. var newCursorNodeText;
  8426. if (opts.cursorNode && result.cursorNodeText) {
  8427. oldCursorNodeStart = opts.locStart(opts.cursorNode);
  8428. oldCursorNodeText = text.slice(oldCursorNodeStart, opts.locEnd(opts.cursorNode));
  8429. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset - oldCursorNodeStart;
  8430. newCursorNodeStart = result.cursorNodeStart;
  8431. newCursorNodeText = result.cursorNodeText;
  8432. } else {
  8433. oldCursorNodeStart = 0;
  8434. oldCursorNodeText = text;
  8435. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset;
  8436. newCursorNodeStart = 0;
  8437. newCursorNodeText = result.formatted;
  8438. }
  8439. if (oldCursorNodeText === newCursorNodeText) {
  8440. return {
  8441. formatted: result.formatted,
  8442. cursorOffset: newCursorNodeStart + cursorOffsetRelativeToOldCursorNode
  8443. };
  8444. } // diff old and new cursor node texts, with a special cursor
  8445. // symbol inserted to find out where it moves to
  8446. var oldCursorNodeCharArray = oldCursorNodeText.split("");
  8447. oldCursorNodeCharArray.splice(cursorOffsetRelativeToOldCursorNode, 0, CURSOR);
  8448. var newCursorNodeCharArray = newCursorNodeText.split("");
  8449. var cursorNodeDiff = lib.diffArrays(oldCursorNodeCharArray, newCursorNodeCharArray);
  8450. var cursorOffset = newCursorNodeStart;
  8451. var _iteratorNormalCompletion = true;
  8452. var _didIteratorError = false;
  8453. var _iteratorError = undefined;
  8454. try {
  8455. for (var _iterator = cursorNodeDiff[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  8456. var entry = _step.value;
  8457. if (entry.removed) {
  8458. if (entry.value.indexOf(CURSOR) > -1) {
  8459. break;
  8460. }
  8461. } else {
  8462. cursorOffset += entry.count;
  8463. }
  8464. }
  8465. } catch (err) {
  8466. _didIteratorError = true;
  8467. _iteratorError = err;
  8468. } finally {
  8469. try {
  8470. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8471. _iterator.return();
  8472. }
  8473. } finally {
  8474. if (_didIteratorError) {
  8475. throw _iteratorError;
  8476. }
  8477. }
  8478. }
  8479. return {
  8480. formatted: result.formatted,
  8481. cursorOffset
  8482. };
  8483. }
  8484. return {
  8485. formatted: result.formatted
  8486. };
  8487. }
  8488. function formatRange(text, opts) {
  8489. var parsed = parser.parse(text, opts);
  8490. var ast = parsed.ast;
  8491. text = parsed.text;
  8492. var range = rangeUtil.calculateRange(text, opts, ast);
  8493. var rangeStart = range.rangeStart;
  8494. var rangeEnd = range.rangeEnd;
  8495. var rangeString = text.slice(rangeStart, rangeEnd); // Try to extend the range backwards to the beginning of the line.
  8496. // This is so we can detect indentation correctly and restore it.
  8497. // Use `Math.min` since `lastIndexOf` returns 0 when `rangeStart` is 0
  8498. var rangeStart2 = Math.min(rangeStart, text.lastIndexOf("\n", rangeStart) + 1);
  8499. var indentString = text.slice(rangeStart2, rangeStart);
  8500. var alignmentSize = util$1.getAlignmentSize(indentString, opts.tabWidth);
  8501. var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
  8502. rangeStart: 0,
  8503. rangeEnd: Infinity,
  8504. printWidth: opts.printWidth - alignmentSize,
  8505. // track the cursor offset only if it's within our range
  8506. cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
  8507. }), alignmentSize); // Since the range contracts to avoid trailing whitespace,
  8508. // we need to remove the newline that was inserted by the `format` call.
  8509. var rangeTrimmed = rangeResult.formatted.trimRight();
  8510. var formatted = text.slice(0, rangeStart) + rangeTrimmed + text.slice(rangeEnd);
  8511. var cursorOffset = opts.cursorOffset;
  8512. if (opts.cursorOffset >= rangeEnd) {
  8513. // handle the case where the cursor was past the end of the range
  8514. cursorOffset = opts.cursorOffset - rangeEnd + (rangeStart + rangeTrimmed.length);
  8515. } else if (rangeResult.cursorOffset !== undefined) {
  8516. // handle the case where the cursor was in the range
  8517. cursorOffset = rangeResult.cursorOffset + rangeStart;
  8518. } // keep the cursor as it was if it was before the start of the range
  8519. return {
  8520. formatted,
  8521. cursorOffset
  8522. };
  8523. }
  8524. function format(text, opts) {
  8525. var selectedParser = parser.resolveParser(opts);
  8526. var hasPragma = !selectedParser.hasPragma || selectedParser.hasPragma(text);
  8527. if (opts.requirePragma && !hasPragma) {
  8528. return {
  8529. formatted: text
  8530. };
  8531. }
  8532. if (opts.rangeStart > 0 || opts.rangeEnd < text.length) {
  8533. return formatRange(text, opts);
  8534. }
  8535. var hasUnicodeBOM = text.charCodeAt(0) === UTF8BOM;
  8536. if (hasUnicodeBOM) {
  8537. text = text.substring(1);
  8538. }
  8539. if (opts.insertPragma && opts.printer.insertPragma && !hasPragma) {
  8540. text = opts.printer.insertPragma(text);
  8541. }
  8542. var result = coreFormat(text, opts);
  8543. if (hasUnicodeBOM) {
  8544. result.formatted = String.fromCharCode(UTF8BOM) + result.formatted;
  8545. }
  8546. return result;
  8547. }
  8548. var core = {
  8549. formatWithCursor(text, opts) {
  8550. opts = normalizeOptions(opts);
  8551. return format(text, normalizeOptions(opts));
  8552. },
  8553. parse(text, opts, massage) {
  8554. opts = normalizeOptions(opts);
  8555. var parsed = parser.parse(text, opts);
  8556. if (massage) {
  8557. parsed.ast = massageAst(parsed.ast, opts);
  8558. }
  8559. return parsed;
  8560. },
  8561. formatAST(ast, opts) {
  8562. opts = normalizeOptions(opts);
  8563. var doc$$1 = astToDoc(ast, opts);
  8564. return printDocToString(doc$$1, opts);
  8565. },
  8566. // Doesn't handle shebang for now
  8567. formatDoc(doc$$1, opts) {
  8568. var debug = printDocToDebug(doc$$1);
  8569. opts = normalizeOptions(Object.assign({}, opts, {
  8570. parser: "babylon"
  8571. }));
  8572. return format(debug, opts).formatted;
  8573. },
  8574. printToDoc(text, opts) {
  8575. opts = normalizeOptions(opts);
  8576. var parsed = parser.parse(text, opts);
  8577. var ast = parsed.ast;
  8578. text = parsed.text;
  8579. attachComments(text, ast, opts);
  8580. return astToDoc(ast, opts);
  8581. },
  8582. printDocToString(doc$$1, opts) {
  8583. return printDocToString(doc$$1, normalizeOptions(opts));
  8584. }
  8585. };
  8586. var _createClass$1 = function () {
  8587. function defineProperties(target, props) {
  8588. for (var i = 0; i < props.length; i++) {
  8589. var descriptor = props[i];
  8590. descriptor.enumerable = descriptor.enumerable || false;
  8591. descriptor.configurable = true;
  8592. if ("value" in descriptor) descriptor.writable = true;
  8593. Object.defineProperty(target, descriptor.key, descriptor);
  8594. }
  8595. }
  8596. return function (Constructor, protoProps, staticProps) {
  8597. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  8598. if (staticProps) defineProperties(Constructor, staticProps);
  8599. return Constructor;
  8600. };
  8601. }();
  8602. function _classCallCheck$1(instance, Constructor) {
  8603. if (!(instance instanceof Constructor)) {
  8604. throw new TypeError("Cannot call a class as a function");
  8605. }
  8606. }
  8607. var ignore = function ignore() {
  8608. return new IgnoreBase();
  8609. }; // A simple implementation of make-array
  8610. function make_array(subject) {
  8611. return Array.isArray(subject) ? subject : [subject];
  8612. }
  8613. var REGEX_BLANK_LINE = /^\s+$/;
  8614. var REGEX_LEADING_EXCAPED_EXCLAMATION = /^\\\!/;
  8615. var REGEX_LEADING_EXCAPED_HASH = /^\\#/;
  8616. var SLASH = '/';
  8617. var KEY_IGNORE = typeof Symbol !== 'undefined' ? Symbol.for('node-ignore')
  8618. /* istanbul ignore next */
  8619. : 'node-ignore';
  8620. var IgnoreBase = function () {
  8621. function IgnoreBase() {
  8622. _classCallCheck$1(this, IgnoreBase);
  8623. this._rules = [];
  8624. this[KEY_IGNORE] = true;
  8625. this._initCache();
  8626. }
  8627. _createClass$1(IgnoreBase, [{
  8628. key: '_initCache',
  8629. value: function _initCache() {
  8630. this._cache = {};
  8631. } // @param {Array.<string>|string|Ignore} pattern
  8632. }, {
  8633. key: 'add',
  8634. value: function add(pattern) {
  8635. this._added = false;
  8636. if (typeof pattern === 'string') {
  8637. pattern = pattern.split(/\r?\n/g);
  8638. }
  8639. make_array(pattern).forEach(this._addPattern, this); // Some rules have just added to the ignore,
  8640. // making the behavior changed.
  8641. if (this._added) {
  8642. this._initCache();
  8643. }
  8644. return this;
  8645. } // legacy
  8646. }, {
  8647. key: 'addPattern',
  8648. value: function addPattern(pattern) {
  8649. return this.add(pattern);
  8650. }
  8651. }, {
  8652. key: '_addPattern',
  8653. value: function _addPattern(pattern) {
  8654. // #32
  8655. if (pattern && pattern[KEY_IGNORE]) {
  8656. this._rules = this._rules.concat(pattern._rules);
  8657. this._added = true;
  8658. return;
  8659. }
  8660. if (this._checkPattern(pattern)) {
  8661. var rule = this._createRule(pattern);
  8662. this._added = true;
  8663. this._rules.push(rule);
  8664. }
  8665. }
  8666. }, {
  8667. key: '_checkPattern',
  8668. value: function _checkPattern(pattern) {
  8669. // > A blank line matches no files, so it can serve as a separator for readability.
  8670. return pattern && typeof pattern === 'string' && !REGEX_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment.
  8671. && pattern.indexOf('#') !== 0;
  8672. }
  8673. }, {
  8674. key: 'filter',
  8675. value: function filter(paths) {
  8676. var _this = this;
  8677. return make_array(paths).filter(function (path$$1) {
  8678. return _this._filter(path$$1);
  8679. });
  8680. }
  8681. }, {
  8682. key: 'createFilter',
  8683. value: function createFilter() {
  8684. var _this2 = this;
  8685. return function (path$$1) {
  8686. return _this2._filter(path$$1);
  8687. };
  8688. }
  8689. }, {
  8690. key: 'ignores',
  8691. value: function ignores(path$$1) {
  8692. return !this._filter(path$$1);
  8693. }
  8694. }, {
  8695. key: '_createRule',
  8696. value: function _createRule(pattern) {
  8697. var origin = pattern;
  8698. var negative = false; // > An optional prefix "!" which negates the pattern;
  8699. if (pattern.indexOf('!') === 0) {
  8700. negative = true;
  8701. pattern = pattern.substr(1);
  8702. }
  8703. pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, `"\!important!.txt"`.
  8704. .replace(REGEX_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that begin with a hash.
  8705. .replace(REGEX_LEADING_EXCAPED_HASH, '#');
  8706. var regex = make_regex(pattern, negative);
  8707. return {
  8708. origin: origin,
  8709. pattern: pattern,
  8710. negative: negative,
  8711. regex: regex
  8712. };
  8713. } // @returns `Boolean` true if the `path` is NOT ignored
  8714. }, {
  8715. key: '_filter',
  8716. value: function _filter(path$$1, slices) {
  8717. if (!path$$1) {
  8718. return false;
  8719. }
  8720. if (path$$1 in this._cache) {
  8721. return this._cache[path$$1];
  8722. }
  8723. if (!slices) {
  8724. // path/to/a.js
  8725. // ['path', 'to', 'a.js']
  8726. slices = path$$1.split(SLASH);
  8727. }
  8728. slices.pop();
  8729. return this._cache[path$$1] = slices.length // > It is not possible to re-include a file if a parent directory of that file is excluded.
  8730. // If the path contains a parent directory, check the parent first
  8731. ? this._filter(slices.join(SLASH) + SLASH, slices) && this._test(path$$1) // Or only test the path
  8732. : this._test(path$$1);
  8733. } // @returns {Boolean} true if a file is NOT ignored
  8734. }, {
  8735. key: '_test',
  8736. value: function _test(path$$1) {
  8737. // Explicitly define variable type by setting matched to `0`
  8738. var matched = 0;
  8739. this._rules.forEach(function (rule) {
  8740. // if matched = true, then we only test negative rules
  8741. // if matched = false, then we test non-negative rules
  8742. if (!(matched ^ rule.negative)) {
  8743. matched = rule.negative ^ rule.regex.test(path$$1);
  8744. }
  8745. });
  8746. return !matched;
  8747. }
  8748. }]);
  8749. return IgnoreBase;
  8750. }(); // > If the pattern ends with a slash,
  8751. // > it is removed for the purpose of the following description,
  8752. // > but it would only find a match with a directory.
  8753. // > In other words, foo/ will match a directory foo and paths underneath it,
  8754. // > but will not match a regular file or a symbolic link foo
  8755. // > (this is consistent with the way how pathspec works in general in Git).
  8756. // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
  8757. // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
  8758. // you could use option `mark: true` with `glob`
  8759. // '`foo/`' should not continue with the '`..`'
  8760. var DEFAULT_REPLACER_PREFIX = [// > Trailing spaces are ignored unless they are quoted with backslash ("\")
  8761. [// (a\ ) -> (a )
  8762. // (a ) -> (a)
  8763. // (a \ ) -> (a )
  8764. /\\?\s+$/, function (match) {
  8765. return match.indexOf('\\') === 0 ? ' ' : '';
  8766. }], // replace (\ ) with ' '
  8767. [/\\\s/g, function () {
  8768. return ' ';
  8769. }], // Escape metacharacters
  8770. // which is written down by users but means special for regular expressions.
  8771. // > There are 12 characters with special meanings:
  8772. // > - the backslash \,
  8773. // > - the caret ^,
  8774. // > - the dollar sign $,
  8775. // > - the period or dot .,
  8776. // > - the vertical bar or pipe symbol |,
  8777. // > - the question mark ?,
  8778. // > - the asterisk or star *,
  8779. // > - the plus sign +,
  8780. // > - the opening parenthesis (,
  8781. // > - the closing parenthesis ),
  8782. // > - and the opening square bracket [,
  8783. // > - the opening curly brace {,
  8784. // > These special characters are often called "metacharacters".
  8785. [/[\\\^$.|?*+()\[{]/g, function (match) {
  8786. return '\\' + match;
  8787. }], // leading slash
  8788. [// > A leading slash matches the beginning of the pathname.
  8789. // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
  8790. // A leading slash matches the beginning of the pathname
  8791. /^\//, function () {
  8792. return '^';
  8793. }], // replace special metacharacter slash after the leading slash
  8794. [/\//g, function () {
  8795. return '\\/';
  8796. }], [// > A leading "**" followed by a slash means match in all directories.
  8797. // > For example, "**/foo" matches file or directory "foo" anywhere,
  8798. // > the same as pattern "foo".
  8799. // > "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".
  8800. // Notice that the '*'s have been replaced as '\\*'
  8801. /^\^*\\\*\\\*\\\//, // '**/foo' <-> 'foo'
  8802. function () {
  8803. return '^(?:.*\\/)?';
  8804. }]];
  8805. var DEFAULT_REPLACER_SUFFIX = [// starting
  8806. [// there will be no leading '/' (which has been replaced by section "leading slash")
  8807. // If starts with '**', adding a '^' to the regular expression also works
  8808. /^(?=[^\^])/, function () {
  8809. return !/\/(?!$)/.test(this) // > If the pattern does not contain a slash /, Git treats it as a shell glob pattern
  8810. // Actually, if there is only a trailing slash, git also treats it as a shell glob pattern
  8811. ? '(?:^|\\/)' // > Otherwise, Git treats the pattern as a shell glob suitable for consumption by fnmatch(3)
  8812. : '^';
  8813. }], // two globstars
  8814. [// Use lookahead assertions so that we could match more than one `'/**'`
  8815. /\\\/\\\*\\\*(?=\\\/|$)/g, // Zero, one or several directories
  8816. // should not use '*', or it will be replaced by the next replacer
  8817. // Check if it is not the last `'/**'`
  8818. function (match, index, str) {
  8819. return index + 6 < str.length // case: /**/
  8820. // > A slash followed by two consecutive asterisks then a slash matches zero or more directories.
  8821. // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
  8822. // '/**/'
  8823. ? '(?:\\/[^\\/]+)*' // case: /**
  8824. // > A trailing `"/**"` matches everything inside.
  8825. // #21: everything inside but it should not include the current folder
  8826. : '\\/.+';
  8827. }], // intermediate wildcards
  8828. [// Never replace escaped '*'
  8829. // ignore rule '\*' will match the path '*'
  8830. // 'abc.*/' -> go
  8831. // 'abc.*' -> skip this rule
  8832. /(^|[^\\]+)\\\*(?=.+)/g, // '*.js' matches '.js'
  8833. // '*.js' doesn't match 'abc'
  8834. function (match, p1) {
  8835. return p1 + '[^\\/]*';
  8836. }], // trailing wildcard
  8837. [/(\^|\\\/)?\\\*$/, function (match, p1) {
  8838. return (p1 // '\^':
  8839. // '/*' does not match ''
  8840. // '/*' does not match everything
  8841. // '\\\/':
  8842. // 'abc/*' does not match 'abc/'
  8843. ? p1 + '[^/]+' // 'a*' matches 'a'
  8844. // 'a*' matches 'aa'
  8845. : '[^/]*') + '(?=$|\\/$)';
  8846. }], [// unescape
  8847. /\\\\\\/g, function () {
  8848. return '\\';
  8849. }]];
  8850. var POSITIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [// 'f'
  8851. // matches
  8852. // - /f(end)
  8853. // - /f/
  8854. // - (start)f(end)
  8855. // - (start)f/
  8856. // doesn't match
  8857. // - oof
  8858. // - foo
  8859. // pseudo:
  8860. // -> (^|/)f(/|$)
  8861. // ending
  8862. [// 'js' will not match 'js.'
  8863. // 'ab' will not match 'abc'
  8864. /(?:[^*\/])$/, // 'js*' will not match 'a.js'
  8865. // 'js/' will not match 'a.js'
  8866. // 'js' will match 'a.js' and 'a.js/'
  8867. function (match) {
  8868. return match + '(?=$|\\/)';
  8869. }]], DEFAULT_REPLACER_SUFFIX);
  8870. var NEGATIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [// #24
  8871. // The MISSING rule of [gitignore docs](https://git-scm.com/docs/gitignore)
  8872. // A negative pattern without a trailing wildcard should not
  8873. // re-include the things inside that directory.
  8874. // eg:
  8875. // ['node_modules/*', '!node_modules']
  8876. // should ignore `node_modules/a.js`
  8877. [/(?:[^*\/])$/, function (match) {
  8878. return match + '(?=$|\\/$)';
  8879. }]], DEFAULT_REPLACER_SUFFIX); // A simple cache, because an ignore rule only has only one certain meaning
  8880. var cache = {}; // @param {pattern}
  8881. function make_regex(pattern, negative) {
  8882. var r = cache[pattern];
  8883. if (r) {
  8884. return r;
  8885. }
  8886. var replacers = negative ? NEGATIVE_REPLACERS : POSITIVE_REPLACERS;
  8887. var source = replacers.reduce(function (prev, current) {
  8888. return prev.replace(current[0], current[1].bind(pattern));
  8889. }, pattern);
  8890. return cache[pattern] = new RegExp(source, 'i');
  8891. } // Windows
  8892. // --------------------------------------------------------------
  8893. /* istanbul ignore if */
  8894. if ( // Detect `process` so that it can run in browsers.
  8895. typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) {
  8896. var filter = IgnoreBase.prototype._filter;
  8897. var make_posix = function make_posix(str) {
  8898. return /^\\\\\?\\/.test(str) || /[^\x00-\x80]+/.test(str) ? str : str.replace(/\\/g, '/');
  8899. };
  8900. IgnoreBase.prototype._filter = function (path$$1, slices) {
  8901. path$$1 = make_posix(path$$1);
  8902. return filter.call(this, path$$1, slices);
  8903. };
  8904. }
  8905. /**
  8906. * @param {string} filename
  8907. * @returns {Promise<null | string>}
  8908. */
  8909. function getFileContentOrNull(filename) {
  8910. return new Promise(function (resolve, reject) {
  8911. fs.readFile(filename, "utf8", function (error, data) {
  8912. if (error && error.code !== "ENOENT") {
  8913. reject(createError(filename, error));
  8914. } else {
  8915. resolve(error ? null : data);
  8916. }
  8917. });
  8918. });
  8919. }
  8920. /**
  8921. * @param {string} filename
  8922. * @returns {null | string}
  8923. */
  8924. getFileContentOrNull.sync = function (filename) {
  8925. try {
  8926. return fs.readFileSync(filename, "utf8");
  8927. } catch (error) {
  8928. if (error && error.code === "ENOENT") {
  8929. return null;
  8930. }
  8931. throw createError(filename, error);
  8932. }
  8933. };
  8934. function createError(filename, error) {
  8935. return new Error(`Unable to read ${filename}: ${error.message}`);
  8936. }
  8937. var getFileContentOrNull_1 = getFileContentOrNull;
  8938. /**
  8939. * @param {undefined | string} ignorePath
  8940. * @param {undefined | boolean} withNodeModules
  8941. */
  8942. function createIgnorer(ignorePath, withNodeModules) {
  8943. return (!ignorePath ? Promise.resolve(null) : getFileContentOrNull_1(path.resolve(ignorePath))).then(function (ignoreContent) {
  8944. return _createIgnorer(ignoreContent, withNodeModules);
  8945. });
  8946. }
  8947. /**
  8948. * @param {undefined | string} ignorePath
  8949. * @param {undefined | boolean} withNodeModules
  8950. */
  8951. createIgnorer.sync = function (ignorePath, withNodeModules) {
  8952. var ignoreContent = !ignorePath ? null : getFileContentOrNull_1.sync(path.resolve(ignorePath));
  8953. return _createIgnorer(ignoreContent, withNodeModules);
  8954. };
  8955. /**
  8956. * @param {null | string} ignoreContent
  8957. * @param {undefined | boolean} withNodeModules
  8958. */
  8959. function _createIgnorer(ignoreContent, withNodeModules) {
  8960. var ignorer = ignore().add(ignoreContent || "");
  8961. if (!withNodeModules) {
  8962. ignorer.add("node_modules");
  8963. }
  8964. return ignorer;
  8965. }
  8966. var createIgnorer_1 = createIgnorer;
  8967. /**
  8968. * @typedef {{ ignorePath?: string, withNodeModules?: boolean, plugins: object }} FileInfoOptions
  8969. * @typedef {{ ignored: boolean, inferredParser: string | null }} FileInfoResult
  8970. */
  8971. /**
  8972. * @param {string} filePath
  8973. * @param {FileInfoOptions} opts
  8974. * @returns {Promise<FileInfoResult>}
  8975. *
  8976. * Please note that prettier.getFileInfo() expects opts.plugins to be an array of paths,
  8977. * not an object. A transformation from this array to an object is automatically done
  8978. * internally by the method wrapper. See withPlugins() in index.js.
  8979. */
  8980. function getFileInfo(filePath, opts) {
  8981. return createIgnorer_1(opts.ignorePath, opts.withNodeModules).then(function (ignorer) {
  8982. return _getFileInfo(ignorer, filePath, opts.plugins);
  8983. });
  8984. }
  8985. /**
  8986. * @param {string} filePath
  8987. * @param {FileInfoOptions} opts
  8988. * @returns {FileInfoResult}
  8989. */
  8990. getFileInfo.sync = function (filePath, opts) {
  8991. var ignorer = createIgnorer_1.sync(opts.ignorePath, opts.withNodeModules);
  8992. return _getFileInfo(ignorer, filePath, opts.plugins);
  8993. };
  8994. function _getFileInfo(ignorer, filePath, plugins) {
  8995. var ignored = ignorer.ignores(filePath);
  8996. var inferredParser = options.inferParser(filePath, plugins) || null;
  8997. return {
  8998. ignored,
  8999. inferredParser
  9000. };
  9001. }
  9002. var getFileInfo_1 = getFileInfo;
  9003. var lodash_uniqby = createCommonjsModule(function (module, exports) {
  9004. /**
  9005. * lodash (Custom Build) <https://lodash.com/>
  9006. * Build: `lodash modularize exports="npm" -o ./`
  9007. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  9008. * Released under MIT license <https://lodash.com/license>
  9009. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9010. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9011. */
  9012. /** Used as the size to enable large array optimizations. */
  9013. var LARGE_ARRAY_SIZE = 200;
  9014. /** Used as the `TypeError` message for "Functions" methods. */
  9015. var FUNC_ERROR_TEXT = 'Expected a function';
  9016. /** Used to stand-in for `undefined` hash values. */
  9017. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  9018. /** Used to compose bitmasks for comparison styles. */
  9019. var UNORDERED_COMPARE_FLAG = 1,
  9020. PARTIAL_COMPARE_FLAG = 2;
  9021. /** Used as references for various `Number` constants. */
  9022. var INFINITY = 1 / 0,
  9023. MAX_SAFE_INTEGER = 9007199254740991;
  9024. /** `Object#toString` result references. */
  9025. var argsTag = '[object Arguments]',
  9026. arrayTag = '[object Array]',
  9027. boolTag = '[object Boolean]',
  9028. dateTag = '[object Date]',
  9029. errorTag = '[object Error]',
  9030. funcTag = '[object Function]',
  9031. genTag = '[object GeneratorFunction]',
  9032. mapTag = '[object Map]',
  9033. numberTag = '[object Number]',
  9034. objectTag = '[object Object]',
  9035. promiseTag = '[object Promise]',
  9036. regexpTag = '[object RegExp]',
  9037. setTag = '[object Set]',
  9038. stringTag = '[object String]',
  9039. symbolTag = '[object Symbol]',
  9040. weakMapTag = '[object WeakMap]';
  9041. var arrayBufferTag = '[object ArrayBuffer]',
  9042. dataViewTag = '[object DataView]',
  9043. float32Tag = '[object Float32Array]',
  9044. float64Tag = '[object Float64Array]',
  9045. int8Tag = '[object Int8Array]',
  9046. int16Tag = '[object Int16Array]',
  9047. int32Tag = '[object Int32Array]',
  9048. uint8Tag = '[object Uint8Array]',
  9049. uint8ClampedTag = '[object Uint8ClampedArray]',
  9050. uint16Tag = '[object Uint16Array]',
  9051. uint32Tag = '[object Uint32Array]';
  9052. /** Used to match property names within property paths. */
  9053. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  9054. reIsPlainProp = /^\w*$/,
  9055. reLeadingDot = /^\./,
  9056. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  9057. /**
  9058. * Used to match `RegExp`
  9059. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  9060. */
  9061. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  9062. /** Used to match backslashes in property paths. */
  9063. var reEscapeChar = /\\(\\)?/g;
  9064. /** Used to detect host constructors (Safari). */
  9065. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  9066. /** Used to detect unsigned integer values. */
  9067. var reIsUint = /^(?:0|[1-9]\d*)$/;
  9068. /** Used to identify `toStringTag` values of typed arrays. */
  9069. var typedArrayTags = {};
  9070. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  9071. 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;
  9072. /** Detect free variable `global` from Node.js. */
  9073. var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
  9074. /** Detect free variable `self`. */
  9075. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  9076. /** Used as a reference to the global object. */
  9077. var root = freeGlobal || freeSelf || Function('return this')();
  9078. /** Detect free variable `exports`. */
  9079. var freeExports = 'object' == 'object' && exports && !exports.nodeType && exports;
  9080. /** Detect free variable `module`. */
  9081. var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
  9082. /** Detect the popular CommonJS extension `module.exports`. */
  9083. var moduleExports = freeModule && freeModule.exports === freeExports;
  9084. /** Detect free variable `process` from Node.js. */
  9085. var freeProcess = moduleExports && freeGlobal.process;
  9086. /** Used to access faster Node.js helpers. */
  9087. var nodeUtil = function () {
  9088. try {
  9089. return freeProcess && freeProcess.binding('util');
  9090. } catch (e) {}
  9091. }();
  9092. /* Node.js helper references. */
  9093. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  9094. /**
  9095. * A specialized version of `_.includes` for arrays without support for
  9096. * specifying an index to search from.
  9097. *
  9098. * @private
  9099. * @param {Array} [array] The array to inspect.
  9100. * @param {*} target The value to search for.
  9101. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  9102. */
  9103. function arrayIncludes(array, value) {
  9104. var length = array ? array.length : 0;
  9105. return !!length && baseIndexOf(array, value, 0) > -1;
  9106. }
  9107. /**
  9108. * This function is like `arrayIncludes` except that it accepts a comparator.
  9109. *
  9110. * @private
  9111. * @param {Array} [array] The array to inspect.
  9112. * @param {*} target The value to search for.
  9113. * @param {Function} comparator The comparator invoked per element.
  9114. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  9115. */
  9116. function arrayIncludesWith(array, value, comparator) {
  9117. var index = -1,
  9118. length = array ? array.length : 0;
  9119. while (++index < length) {
  9120. if (comparator(value, array[index])) {
  9121. return true;
  9122. }
  9123. }
  9124. return false;
  9125. }
  9126. /**
  9127. * A specialized version of `_.some` for arrays without support for iteratee
  9128. * shorthands.
  9129. *
  9130. * @private
  9131. * @param {Array} [array] The array to iterate over.
  9132. * @param {Function} predicate The function invoked per iteration.
  9133. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9134. * else `false`.
  9135. */
  9136. function arraySome(array, predicate) {
  9137. var index = -1,
  9138. length = array ? array.length : 0;
  9139. while (++index < length) {
  9140. if (predicate(array[index], index, array)) {
  9141. return true;
  9142. }
  9143. }
  9144. return false;
  9145. }
  9146. /**
  9147. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  9148. * support for iteratee shorthands.
  9149. *
  9150. * @private
  9151. * @param {Array} array The array to inspect.
  9152. * @param {Function} predicate The function invoked per iteration.
  9153. * @param {number} fromIndex The index to search from.
  9154. * @param {boolean} [fromRight] Specify iterating from right to left.
  9155. * @returns {number} Returns the index of the matched value, else `-1`.
  9156. */
  9157. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  9158. var length = array.length,
  9159. index = fromIndex + (fromRight ? 1 : -1);
  9160. while (fromRight ? index-- : ++index < length) {
  9161. if (predicate(array[index], index, array)) {
  9162. return index;
  9163. }
  9164. }
  9165. return -1;
  9166. }
  9167. /**
  9168. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  9169. *
  9170. * @private
  9171. * @param {Array} array The array to inspect.
  9172. * @param {*} value The value to search for.
  9173. * @param {number} fromIndex The index to search from.
  9174. * @returns {number} Returns the index of the matched value, else `-1`.
  9175. */
  9176. function baseIndexOf(array, value, fromIndex) {
  9177. if (value !== value) {
  9178. return baseFindIndex(array, baseIsNaN, fromIndex);
  9179. }
  9180. var index = fromIndex - 1,
  9181. length = array.length;
  9182. while (++index < length) {
  9183. if (array[index] === value) {
  9184. return index;
  9185. }
  9186. }
  9187. return -1;
  9188. }
  9189. /**
  9190. * The base implementation of `_.isNaN` without support for number objects.
  9191. *
  9192. * @private
  9193. * @param {*} value The value to check.
  9194. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  9195. */
  9196. function baseIsNaN(value) {
  9197. return value !== value;
  9198. }
  9199. /**
  9200. * The base implementation of `_.property` without support for deep paths.
  9201. *
  9202. * @private
  9203. * @param {string} key The key of the property to get.
  9204. * @returns {Function} Returns the new accessor function.
  9205. */
  9206. function baseProperty(key) {
  9207. return function (object) {
  9208. return object == null ? undefined : object[key];
  9209. };
  9210. }
  9211. /**
  9212. * The base implementation of `_.times` without support for iteratee shorthands
  9213. * or max array length checks.
  9214. *
  9215. * @private
  9216. * @param {number} n The number of times to invoke `iteratee`.
  9217. * @param {Function} iteratee The function invoked per iteration.
  9218. * @returns {Array} Returns the array of results.
  9219. */
  9220. function baseTimes(n, iteratee) {
  9221. var index = -1,
  9222. result = Array(n);
  9223. while (++index < n) {
  9224. result[index] = iteratee(index);
  9225. }
  9226. return result;
  9227. }
  9228. /**
  9229. * The base implementation of `_.unary` without support for storing metadata.
  9230. *
  9231. * @private
  9232. * @param {Function} func The function to cap arguments for.
  9233. * @returns {Function} Returns the new capped function.
  9234. */
  9235. function baseUnary(func) {
  9236. return function (value) {
  9237. return func(value);
  9238. };
  9239. }
  9240. /**
  9241. * Checks if a cache value for `key` exists.
  9242. *
  9243. * @private
  9244. * @param {Object} cache The cache to query.
  9245. * @param {string} key The key of the entry to check.
  9246. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9247. */
  9248. function cacheHas(cache, key) {
  9249. return cache.has(key);
  9250. }
  9251. /**
  9252. * Gets the value at `key` of `object`.
  9253. *
  9254. * @private
  9255. * @param {Object} [object] The object to query.
  9256. * @param {string} key The key of the property to get.
  9257. * @returns {*} Returns the property value.
  9258. */
  9259. function getValue(object, key) {
  9260. return object == null ? undefined : object[key];
  9261. }
  9262. /**
  9263. * Checks if `value` is a host object in IE < 9.
  9264. *
  9265. * @private
  9266. * @param {*} value The value to check.
  9267. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  9268. */
  9269. function isHostObject(value) {
  9270. // Many host objects are `Object` objects that can coerce to strings
  9271. // despite having improperly defined `toString` methods.
  9272. var result = false;
  9273. if (value != null && typeof value.toString != 'function') {
  9274. try {
  9275. result = !!(value + '');
  9276. } catch (e) {}
  9277. }
  9278. return result;
  9279. }
  9280. /**
  9281. * Converts `map` to its key-value pairs.
  9282. *
  9283. * @private
  9284. * @param {Object} map The map to convert.
  9285. * @returns {Array} Returns the key-value pairs.
  9286. */
  9287. function mapToArray(map) {
  9288. var index = -1,
  9289. result = Array(map.size);
  9290. map.forEach(function (value, key) {
  9291. result[++index] = [key, value];
  9292. });
  9293. return result;
  9294. }
  9295. /**
  9296. * Creates a unary function that invokes `func` with its argument transformed.
  9297. *
  9298. * @private
  9299. * @param {Function} func The function to wrap.
  9300. * @param {Function} transform The argument transform.
  9301. * @returns {Function} Returns the new function.
  9302. */
  9303. function overArg(func, transform) {
  9304. return function (arg) {
  9305. return func(transform(arg));
  9306. };
  9307. }
  9308. /**
  9309. * Converts `set` to an array of its values.
  9310. *
  9311. * @private
  9312. * @param {Object} set The set to convert.
  9313. * @returns {Array} Returns the values.
  9314. */
  9315. function setToArray(set) {
  9316. var index = -1,
  9317. result = Array(set.size);
  9318. set.forEach(function (value) {
  9319. result[++index] = value;
  9320. });
  9321. return result;
  9322. }
  9323. /** Used for built-in method references. */
  9324. var arrayProto = Array.prototype,
  9325. funcProto = Function.prototype,
  9326. objectProto = Object.prototype;
  9327. /** Used to detect overreaching core-js shims. */
  9328. var coreJsData = root['__core-js_shared__'];
  9329. /** Used to detect methods masquerading as native. */
  9330. var maskSrcKey = function () {
  9331. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  9332. return uid ? 'Symbol(src)_1.' + uid : '';
  9333. }();
  9334. /** Used to resolve the decompiled source of functions. */
  9335. var funcToString = funcProto.toString;
  9336. /** Used to check objects for own properties. */
  9337. var hasOwnProperty = objectProto.hasOwnProperty;
  9338. /**
  9339. * Used to resolve the
  9340. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  9341. * of values.
  9342. */
  9343. var objectToString = objectProto.toString;
  9344. /** Used to detect if a method is native. */
  9345. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  9346. /** Built-in value references. */
  9347. var Symbol = root.Symbol,
  9348. Uint8Array = root.Uint8Array,
  9349. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  9350. splice = arrayProto.splice;
  9351. /* Built-in method references for those with the same name as other `lodash` methods. */
  9352. var nativeKeys = overArg(Object.keys, Object);
  9353. /* Built-in method references that are verified to be native. */
  9354. var DataView = getNative(root, 'DataView'),
  9355. Map = getNative(root, 'Map'),
  9356. Promise = getNative(root, 'Promise'),
  9357. Set = getNative(root, 'Set'),
  9358. WeakMap = getNative(root, 'WeakMap'),
  9359. nativeCreate = getNative(Object, 'create');
  9360. /** Used to detect maps, sets, and weakmaps. */
  9361. var dataViewCtorString = toSource(DataView),
  9362. mapCtorString = toSource(Map),
  9363. promiseCtorString = toSource(Promise),
  9364. setCtorString = toSource(Set),
  9365. weakMapCtorString = toSource(WeakMap);
  9366. /** Used to convert symbols to primitives and strings. */
  9367. var symbolProto = Symbol ? Symbol.prototype : undefined,
  9368. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  9369. symbolToString = symbolProto ? symbolProto.toString : undefined;
  9370. /**
  9371. * Creates a hash object.
  9372. *
  9373. * @private
  9374. * @constructor
  9375. * @param {Array} [entries] The key-value pairs to cache.
  9376. */
  9377. function Hash(entries) {
  9378. var index = -1,
  9379. length = entries ? entries.length : 0;
  9380. this.clear();
  9381. while (++index < length) {
  9382. var entry = entries[index];
  9383. this.set(entry[0], entry[1]);
  9384. }
  9385. }
  9386. /**
  9387. * Removes all key-value entries from the hash.
  9388. *
  9389. * @private
  9390. * @name clear
  9391. * @memberOf Hash
  9392. */
  9393. function hashClear() {
  9394. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  9395. }
  9396. /**
  9397. * Removes `key` and its value from the hash.
  9398. *
  9399. * @private
  9400. * @name delete
  9401. * @memberOf Hash
  9402. * @param {Object} hash The hash to modify.
  9403. * @param {string} key The key of the value to remove.
  9404. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  9405. */
  9406. function hashDelete(key) {
  9407. return this.has(key) && delete this.__data__[key];
  9408. }
  9409. /**
  9410. * Gets the hash value for `key`.
  9411. *
  9412. * @private
  9413. * @name get
  9414. * @memberOf Hash
  9415. * @param {string} key The key of the value to get.
  9416. * @returns {*} Returns the entry value.
  9417. */
  9418. function hashGet(key) {
  9419. var data = this.__data__;
  9420. if (nativeCreate) {
  9421. var result = data[key];
  9422. return result === HASH_UNDEFINED ? undefined : result;
  9423. }
  9424. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  9425. }
  9426. /**
  9427. * Checks if a hash value for `key` exists.
  9428. *
  9429. * @private
  9430. * @name has
  9431. * @memberOf Hash
  9432. * @param {string} key The key of the entry to check.
  9433. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9434. */
  9435. function hashHas(key) {
  9436. var data = this.__data__;
  9437. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  9438. }
  9439. /**
  9440. * Sets the hash `key` to `value`.
  9441. *
  9442. * @private
  9443. * @name set
  9444. * @memberOf Hash
  9445. * @param {string} key The key of the value to set.
  9446. * @param {*} value The value to set.
  9447. * @returns {Object} Returns the hash instance.
  9448. */
  9449. function hashSet(key, value) {
  9450. var data = this.__data__;
  9451. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  9452. return this;
  9453. } // Add methods to `Hash`.
  9454. Hash.prototype.clear = hashClear;
  9455. Hash.prototype['delete'] = hashDelete;
  9456. Hash.prototype.get = hashGet;
  9457. Hash.prototype.has = hashHas;
  9458. Hash.prototype.set = hashSet;
  9459. /**
  9460. * Creates an list cache object.
  9461. *
  9462. * @private
  9463. * @constructor
  9464. * @param {Array} [entries] The key-value pairs to cache.
  9465. */
  9466. function ListCache(entries) {
  9467. var index = -1,
  9468. length = entries ? entries.length : 0;
  9469. this.clear();
  9470. while (++index < length) {
  9471. var entry = entries[index];
  9472. this.set(entry[0], entry[1]);
  9473. }
  9474. }
  9475. /**
  9476. * Removes all key-value entries from the list cache.
  9477. *
  9478. * @private
  9479. * @name clear
  9480. * @memberOf ListCache
  9481. */
  9482. function listCacheClear() {
  9483. this.__data__ = [];
  9484. }
  9485. /**
  9486. * Removes `key` and its value from the list cache.
  9487. *
  9488. * @private
  9489. * @name delete
  9490. * @memberOf ListCache
  9491. * @param {string} key The key of the value to remove.
  9492. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  9493. */
  9494. function listCacheDelete(key) {
  9495. var data = this.__data__,
  9496. index = assocIndexOf(data, key);
  9497. if (index < 0) {
  9498. return false;
  9499. }
  9500. var lastIndex = data.length - 1;
  9501. if (index == lastIndex) {
  9502. data.pop();
  9503. } else {
  9504. splice.call(data, index, 1);
  9505. }
  9506. return true;
  9507. }
  9508. /**
  9509. * Gets the list cache value for `key`.
  9510. *
  9511. * @private
  9512. * @name get
  9513. * @memberOf ListCache
  9514. * @param {string} key The key of the value to get.
  9515. * @returns {*} Returns the entry value.
  9516. */
  9517. function listCacheGet(key) {
  9518. var data = this.__data__,
  9519. index = assocIndexOf(data, key);
  9520. return index < 0 ? undefined : data[index][1];
  9521. }
  9522. /**
  9523. * Checks if a list cache value for `key` exists.
  9524. *
  9525. * @private
  9526. * @name has
  9527. * @memberOf ListCache
  9528. * @param {string} key The key of the entry to check.
  9529. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9530. */
  9531. function listCacheHas(key) {
  9532. return assocIndexOf(this.__data__, key) > -1;
  9533. }
  9534. /**
  9535. * Sets the list cache `key` to `value`.
  9536. *
  9537. * @private
  9538. * @name set
  9539. * @memberOf ListCache
  9540. * @param {string} key The key of the value to set.
  9541. * @param {*} value The value to set.
  9542. * @returns {Object} Returns the list cache instance.
  9543. */
  9544. function listCacheSet(key, value) {
  9545. var data = this.__data__,
  9546. index = assocIndexOf(data, key);
  9547. if (index < 0) {
  9548. data.push([key, value]);
  9549. } else {
  9550. data[index][1] = value;
  9551. }
  9552. return this;
  9553. } // Add methods to `ListCache`.
  9554. ListCache.prototype.clear = listCacheClear;
  9555. ListCache.prototype['delete'] = listCacheDelete;
  9556. ListCache.prototype.get = listCacheGet;
  9557. ListCache.prototype.has = listCacheHas;
  9558. ListCache.prototype.set = listCacheSet;
  9559. /**
  9560. * Creates a map cache object to store key-value pairs.
  9561. *
  9562. * @private
  9563. * @constructor
  9564. * @param {Array} [entries] The key-value pairs to cache.
  9565. */
  9566. function MapCache(entries) {
  9567. var index = -1,
  9568. length = entries ? entries.length : 0;
  9569. this.clear();
  9570. while (++index < length) {
  9571. var entry = entries[index];
  9572. this.set(entry[0], entry[1]);
  9573. }
  9574. }
  9575. /**
  9576. * Removes all key-value entries from the map.
  9577. *
  9578. * @private
  9579. * @name clear
  9580. * @memberOf MapCache
  9581. */
  9582. function mapCacheClear() {
  9583. this.__data__ = {
  9584. 'hash': new Hash(),
  9585. 'map': new (Map || ListCache)(),
  9586. 'string': new Hash()
  9587. };
  9588. }
  9589. /**
  9590. * Removes `key` and its value from the map.
  9591. *
  9592. * @private
  9593. * @name delete
  9594. * @memberOf MapCache
  9595. * @param {string} key The key of the value to remove.
  9596. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  9597. */
  9598. function mapCacheDelete(key) {
  9599. return getMapData(this, key)['delete'](key);
  9600. }
  9601. /**
  9602. * Gets the map value for `key`.
  9603. *
  9604. * @private
  9605. * @name get
  9606. * @memberOf MapCache
  9607. * @param {string} key The key of the value to get.
  9608. * @returns {*} Returns the entry value.
  9609. */
  9610. function mapCacheGet(key) {
  9611. return getMapData(this, key).get(key);
  9612. }
  9613. /**
  9614. * Checks if a map value for `key` exists.
  9615. *
  9616. * @private
  9617. * @name has
  9618. * @memberOf MapCache
  9619. * @param {string} key The key of the entry to check.
  9620. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9621. */
  9622. function mapCacheHas(key) {
  9623. return getMapData(this, key).has(key);
  9624. }
  9625. /**
  9626. * Sets the map `key` to `value`.
  9627. *
  9628. * @private
  9629. * @name set
  9630. * @memberOf MapCache
  9631. * @param {string} key The key of the value to set.
  9632. * @param {*} value The value to set.
  9633. * @returns {Object} Returns the map cache instance.
  9634. */
  9635. function mapCacheSet(key, value) {
  9636. getMapData(this, key).set(key, value);
  9637. return this;
  9638. } // Add methods to `MapCache`.
  9639. MapCache.prototype.clear = mapCacheClear;
  9640. MapCache.prototype['delete'] = mapCacheDelete;
  9641. MapCache.prototype.get = mapCacheGet;
  9642. MapCache.prototype.has = mapCacheHas;
  9643. MapCache.prototype.set = mapCacheSet;
  9644. /**
  9645. *
  9646. * Creates an array cache object to store unique values.
  9647. *
  9648. * @private
  9649. * @constructor
  9650. * @param {Array} [values] The values to cache.
  9651. */
  9652. function SetCache(values) {
  9653. var index = -1,
  9654. length = values ? values.length : 0;
  9655. this.__data__ = new MapCache();
  9656. while (++index < length) {
  9657. this.add(values[index]);
  9658. }
  9659. }
  9660. /**
  9661. * Adds `value` to the array cache.
  9662. *
  9663. * @private
  9664. * @name add
  9665. * @memberOf SetCache
  9666. * @alias push
  9667. * @param {*} value The value to cache.
  9668. * @returns {Object} Returns the cache instance.
  9669. */
  9670. function setCacheAdd(value) {
  9671. this.__data__.set(value, HASH_UNDEFINED);
  9672. return this;
  9673. }
  9674. /**
  9675. * Checks if `value` is in the array cache.
  9676. *
  9677. * @private
  9678. * @name has
  9679. * @memberOf SetCache
  9680. * @param {*} value The value to search for.
  9681. * @returns {number} Returns `true` if `value` is found, else `false`.
  9682. */
  9683. function setCacheHas(value) {
  9684. return this.__data__.has(value);
  9685. } // Add methods to `SetCache`.
  9686. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  9687. SetCache.prototype.has = setCacheHas;
  9688. /**
  9689. * Creates a stack cache object to store key-value pairs.
  9690. *
  9691. * @private
  9692. * @constructor
  9693. * @param {Array} [entries] The key-value pairs to cache.
  9694. */
  9695. function Stack(entries) {
  9696. this.__data__ = new ListCache(entries);
  9697. }
  9698. /**
  9699. * Removes all key-value entries from the stack.
  9700. *
  9701. * @private
  9702. * @name clear
  9703. * @memberOf Stack
  9704. */
  9705. function stackClear() {
  9706. this.__data__ = new ListCache();
  9707. }
  9708. /**
  9709. * Removes `key` and its value from the stack.
  9710. *
  9711. * @private
  9712. * @name delete
  9713. * @memberOf Stack
  9714. * @param {string} key The key of the value to remove.
  9715. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  9716. */
  9717. function stackDelete(key) {
  9718. return this.__data__['delete'](key);
  9719. }
  9720. /**
  9721. * Gets the stack value for `key`.
  9722. *
  9723. * @private
  9724. * @name get
  9725. * @memberOf Stack
  9726. * @param {string} key The key of the value to get.
  9727. * @returns {*} Returns the entry value.
  9728. */
  9729. function stackGet(key) {
  9730. return this.__data__.get(key);
  9731. }
  9732. /**
  9733. * Checks if a stack value for `key` exists.
  9734. *
  9735. * @private
  9736. * @name has
  9737. * @memberOf Stack
  9738. * @param {string} key The key of the entry to check.
  9739. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9740. */
  9741. function stackHas(key) {
  9742. return this.__data__.has(key);
  9743. }
  9744. /**
  9745. * Sets the stack `key` to `value`.
  9746. *
  9747. * @private
  9748. * @name set
  9749. * @memberOf Stack
  9750. * @param {string} key The key of the value to set.
  9751. * @param {*} value The value to set.
  9752. * @returns {Object} Returns the stack cache instance.
  9753. */
  9754. function stackSet(key, value) {
  9755. var cache = this.__data__;
  9756. if (cache instanceof ListCache) {
  9757. var pairs = cache.__data__;
  9758. if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  9759. pairs.push([key, value]);
  9760. return this;
  9761. }
  9762. cache = this.__data__ = new MapCache(pairs);
  9763. }
  9764. cache.set(key, value);
  9765. return this;
  9766. } // Add methods to `Stack`.
  9767. Stack.prototype.clear = stackClear;
  9768. Stack.prototype['delete'] = stackDelete;
  9769. Stack.prototype.get = stackGet;
  9770. Stack.prototype.has = stackHas;
  9771. Stack.prototype.set = stackSet;
  9772. /**
  9773. * Creates an array of the enumerable property names of the array-like `value`.
  9774. *
  9775. * @private
  9776. * @param {*} value The value to query.
  9777. * @param {boolean} inherited Specify returning inherited property names.
  9778. * @returns {Array} Returns the array of property names.
  9779. */
  9780. function arrayLikeKeys(value, inherited) {
  9781. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  9782. // Safari 9 makes `arguments.length` enumerable in strict mode.
  9783. var result = isArray(value) || isArguments(value) ? baseTimes(value.length, String) : [];
  9784. var length = result.length,
  9785. skipIndexes = !!length;
  9786. for (var key in value) {
  9787. if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  9788. result.push(key);
  9789. }
  9790. }
  9791. return result;
  9792. }
  9793. /**
  9794. * Gets the index at which the `key` is found in `array` of key-value pairs.
  9795. *
  9796. * @private
  9797. * @param {Array} array The array to inspect.
  9798. * @param {*} key The key to search for.
  9799. * @returns {number} Returns the index of the matched value, else `-1`.
  9800. */
  9801. function assocIndexOf(array, key) {
  9802. var length = array.length;
  9803. while (length--) {
  9804. if (eq(array[length][0], key)) {
  9805. return length;
  9806. }
  9807. }
  9808. return -1;
  9809. }
  9810. /**
  9811. * The base implementation of `_.get` without support for default values.
  9812. *
  9813. * @private
  9814. * @param {Object} object The object to query.
  9815. * @param {Array|string} path The path of the property to get.
  9816. * @returns {*} Returns the resolved value.
  9817. */
  9818. function baseGet(object, path$$1) {
  9819. path$$1 = isKey(path$$1, object) ? [path$$1] : castPath(path$$1);
  9820. var index = 0,
  9821. length = path$$1.length;
  9822. while (object != null && index < length) {
  9823. object = object[toKey(path$$1[index++])];
  9824. }
  9825. return index && index == length ? object : undefined;
  9826. }
  9827. /**
  9828. * The base implementation of `getTag`.
  9829. *
  9830. * @private
  9831. * @param {*} value The value to query.
  9832. * @returns {string} Returns the `toStringTag`.
  9833. */
  9834. function baseGetTag(value) {
  9835. return objectToString.call(value);
  9836. }
  9837. /**
  9838. * The base implementation of `_.hasIn` without support for deep paths.
  9839. *
  9840. * @private
  9841. * @param {Object} [object] The object to query.
  9842. * @param {Array|string} key The key to check.
  9843. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  9844. */
  9845. function baseHasIn(object, key) {
  9846. return object != null && key in Object(object);
  9847. }
  9848. /**
  9849. * The base implementation of `_.isEqual` which supports partial comparisons
  9850. * and tracks traversed objects.
  9851. *
  9852. * @private
  9853. * @param {*} value The value to compare.
  9854. * @param {*} other The other value to compare.
  9855. * @param {Function} [customizer] The function to customize comparisons.
  9856. * @param {boolean} [bitmask] The bitmask of comparison flags.
  9857. * The bitmask may be composed of the following flags:
  9858. * 1 - Unordered comparison
  9859. * 2 - Partial comparison
  9860. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  9861. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  9862. */
  9863. function baseIsEqual(value, other, customizer, bitmask, stack) {
  9864. if (value === other) {
  9865. return true;
  9866. }
  9867. if (value == null || other == null || !isObject(value) && !isObjectLike(other)) {
  9868. return value !== value && other !== other;
  9869. }
  9870. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  9871. }
  9872. /**
  9873. * A specialized version of `baseIsEqual` for arrays and objects which performs
  9874. * deep comparisons and tracks traversed objects enabling objects with circular
  9875. * references to be compared.
  9876. *
  9877. * @private
  9878. * @param {Object} object The object to compare.
  9879. * @param {Object} other The other object to compare.
  9880. * @param {Function} equalFunc The function to determine equivalents of values.
  9881. * @param {Function} [customizer] The function to customize comparisons.
  9882. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  9883. * for more details.
  9884. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  9885. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  9886. */
  9887. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  9888. var objIsArr = isArray(object),
  9889. othIsArr = isArray(other),
  9890. objTag = arrayTag,
  9891. othTag = arrayTag;
  9892. if (!objIsArr) {
  9893. objTag = getTag(object);
  9894. objTag = objTag == argsTag ? objectTag : objTag;
  9895. }
  9896. if (!othIsArr) {
  9897. othTag = getTag(other);
  9898. othTag = othTag == argsTag ? objectTag : othTag;
  9899. }
  9900. var objIsObj = objTag == objectTag && !isHostObject(object),
  9901. othIsObj = othTag == objectTag && !isHostObject(other),
  9902. isSameTag = objTag == othTag;
  9903. if (isSameTag && !objIsObj) {
  9904. stack || (stack = new Stack());
  9905. return objIsArr || isTypedArray(object) ? equalArrays(object, other, equalFunc, customizer, bitmask, stack) : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  9906. }
  9907. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  9908. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  9909. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  9910. if (objIsWrapped || othIsWrapped) {
  9911. var objUnwrapped = objIsWrapped ? object.value() : object,
  9912. othUnwrapped = othIsWrapped ? other.value() : other;
  9913. stack || (stack = new Stack());
  9914. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  9915. }
  9916. }
  9917. if (!isSameTag) {
  9918. return false;
  9919. }
  9920. stack || (stack = new Stack());
  9921. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  9922. }
  9923. /**
  9924. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  9925. *
  9926. * @private
  9927. * @param {Object} object The object to inspect.
  9928. * @param {Object} source The object of property values to match.
  9929. * @param {Array} matchData The property names, values, and compare flags to match.
  9930. * @param {Function} [customizer] The function to customize comparisons.
  9931. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  9932. */
  9933. function baseIsMatch(object, source, matchData, customizer) {
  9934. var index = matchData.length,
  9935. length = index,
  9936. noCustomizer = !customizer;
  9937. if (object == null) {
  9938. return !length;
  9939. }
  9940. object = Object(object);
  9941. while (index--) {
  9942. var data = matchData[index];
  9943. if (noCustomizer && data[2] ? data[1] !== object[data[0]] : !(data[0] in object)) {
  9944. return false;
  9945. }
  9946. }
  9947. while (++index < length) {
  9948. data = matchData[index];
  9949. var key = data[0],
  9950. objValue = object[key],
  9951. srcValue = data[1];
  9952. if (noCustomizer && data[2]) {
  9953. if (objValue === undefined && !(key in object)) {
  9954. return false;
  9955. }
  9956. } else {
  9957. var stack = new Stack();
  9958. if (customizer) {
  9959. var result = customizer(objValue, srcValue, key, object, source, stack);
  9960. }
  9961. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) : result)) {
  9962. return false;
  9963. }
  9964. }
  9965. }
  9966. return true;
  9967. }
  9968. /**
  9969. * The base implementation of `_.isNative` without bad shim checks.
  9970. *
  9971. * @private
  9972. * @param {*} value The value to check.
  9973. * @returns {boolean} Returns `true` if `value` is a native function,
  9974. * else `false`.
  9975. */
  9976. function baseIsNative(value) {
  9977. if (!isObject(value) || isMasked(value)) {
  9978. return false;
  9979. }
  9980. var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
  9981. return pattern.test(toSource(value));
  9982. }
  9983. /**
  9984. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  9985. *
  9986. * @private
  9987. * @param {*} value The value to check.
  9988. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  9989. */
  9990. function baseIsTypedArray(value) {
  9991. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  9992. }
  9993. /**
  9994. * The base implementation of `_.iteratee`.
  9995. *
  9996. * @private
  9997. * @param {*} [value=_.identity] The value to convert to an iteratee.
  9998. * @returns {Function} Returns the iteratee.
  9999. */
  10000. function baseIteratee(value) {
  10001. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  10002. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  10003. if (typeof value == 'function') {
  10004. return value;
  10005. }
  10006. if (value == null) {
  10007. return identity;
  10008. }
  10009. if (typeof value == 'object') {
  10010. return isArray(value) ? baseMatchesProperty(value[0], value[1]) : baseMatches(value);
  10011. }
  10012. return property(value);
  10013. }
  10014. /**
  10015. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  10016. *
  10017. * @private
  10018. * @param {Object} object The object to query.
  10019. * @returns {Array} Returns the array of property names.
  10020. */
  10021. function baseKeys(object) {
  10022. if (!isPrototype(object)) {
  10023. return nativeKeys(object);
  10024. }
  10025. var result = [];
  10026. for (var key in Object(object)) {
  10027. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  10028. result.push(key);
  10029. }
  10030. }
  10031. return result;
  10032. }
  10033. /**
  10034. * The base implementation of `_.matches` which doesn't clone `source`.
  10035. *
  10036. * @private
  10037. * @param {Object} source The object of property values to match.
  10038. * @returns {Function} Returns the new spec function.
  10039. */
  10040. function baseMatches(source) {
  10041. var matchData = getMatchData(source);
  10042. if (matchData.length == 1 && matchData[0][2]) {
  10043. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  10044. }
  10045. return function (object) {
  10046. return object === source || baseIsMatch(object, source, matchData);
  10047. };
  10048. }
  10049. /**
  10050. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  10051. *
  10052. * @private
  10053. * @param {string} path The path of the property to get.
  10054. * @param {*} srcValue The value to match.
  10055. * @returns {Function} Returns the new spec function.
  10056. */
  10057. function baseMatchesProperty(path$$1, srcValue) {
  10058. if (isKey(path$$1) && isStrictComparable(srcValue)) {
  10059. return matchesStrictComparable(toKey(path$$1), srcValue);
  10060. }
  10061. return function (object) {
  10062. var objValue = get(object, path$$1);
  10063. return objValue === undefined && objValue === srcValue ? hasIn(object, path$$1) : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  10064. };
  10065. }
  10066. /**
  10067. * A specialized version of `baseProperty` which supports deep paths.
  10068. *
  10069. * @private
  10070. * @param {Array|string} path The path of the property to get.
  10071. * @returns {Function} Returns the new accessor function.
  10072. */
  10073. function basePropertyDeep(path$$1) {
  10074. return function (object) {
  10075. return baseGet(object, path$$1);
  10076. };
  10077. }
  10078. /**
  10079. * The base implementation of `_.toString` which doesn't convert nullish
  10080. * values to empty strings.
  10081. *
  10082. * @private
  10083. * @param {*} value The value to process.
  10084. * @returns {string} Returns the string.
  10085. */
  10086. function baseToString(value) {
  10087. // Exit early for strings to avoid a performance hit in some environments.
  10088. if (typeof value == 'string') {
  10089. return value;
  10090. }
  10091. if (isSymbol(value)) {
  10092. return symbolToString ? symbolToString.call(value) : '';
  10093. }
  10094. var result = value + '';
  10095. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  10096. }
  10097. /**
  10098. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  10099. *
  10100. * @private
  10101. * @param {Array} array The array to inspect.
  10102. * @param {Function} [iteratee] The iteratee invoked per element.
  10103. * @param {Function} [comparator] The comparator invoked per element.
  10104. * @returns {Array} Returns the new duplicate free array.
  10105. */
  10106. function baseUniq(array, iteratee, comparator) {
  10107. var index = -1,
  10108. includes = arrayIncludes,
  10109. length = array.length,
  10110. isCommon = true,
  10111. result = [],
  10112. seen = result;
  10113. if (comparator) {
  10114. isCommon = false;
  10115. includes = arrayIncludesWith;
  10116. } else if (length >= LARGE_ARRAY_SIZE) {
  10117. var set = iteratee ? null : createSet(array);
  10118. if (set) {
  10119. return setToArray(set);
  10120. }
  10121. isCommon = false;
  10122. includes = cacheHas;
  10123. seen = new SetCache();
  10124. } else {
  10125. seen = iteratee ? [] : result;
  10126. }
  10127. outer: while (++index < length) {
  10128. var value = array[index],
  10129. computed = iteratee ? iteratee(value) : value;
  10130. value = comparator || value !== 0 ? value : 0;
  10131. if (isCommon && computed === computed) {
  10132. var seenIndex = seen.length;
  10133. while (seenIndex--) {
  10134. if (seen[seenIndex] === computed) {
  10135. continue outer;
  10136. }
  10137. }
  10138. if (iteratee) {
  10139. seen.push(computed);
  10140. }
  10141. result.push(value);
  10142. } else if (!includes(seen, computed, comparator)) {
  10143. if (seen !== result) {
  10144. seen.push(computed);
  10145. }
  10146. result.push(value);
  10147. }
  10148. }
  10149. return result;
  10150. }
  10151. /**
  10152. * Casts `value` to a path array if it's not one.
  10153. *
  10154. * @private
  10155. * @param {*} value The value to inspect.
  10156. * @returns {Array} Returns the cast property path array.
  10157. */
  10158. function castPath(value) {
  10159. return isArray(value) ? value : stringToPath(value);
  10160. }
  10161. /**
  10162. * Creates a set object of `values`.
  10163. *
  10164. * @private
  10165. * @param {Array} values The values to add to the set.
  10166. * @returns {Object} Returns the new set.
  10167. */
  10168. var createSet = !(Set && 1 / setToArray(new Set([, -0]))[1] == INFINITY) ? noop : function (values) {
  10169. return new Set(values);
  10170. };
  10171. /**
  10172. * A specialized version of `baseIsEqualDeep` for arrays with support for
  10173. * partial deep comparisons.
  10174. *
  10175. * @private
  10176. * @param {Array} array The array to compare.
  10177. * @param {Array} other The other array to compare.
  10178. * @param {Function} equalFunc The function to determine equivalents of values.
  10179. * @param {Function} customizer The function to customize comparisons.
  10180. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  10181. * for more details.
  10182. * @param {Object} stack Tracks traversed `array` and `other` objects.
  10183. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  10184. */
  10185. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  10186. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  10187. arrLength = array.length,
  10188. othLength = other.length;
  10189. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  10190. return false;
  10191. } // Assume cyclic values are equal.
  10192. var stacked = stack.get(array);
  10193. if (stacked && stack.get(other)) {
  10194. return stacked == other;
  10195. }
  10196. var index = -1,
  10197. result = true,
  10198. seen = bitmask & UNORDERED_COMPARE_FLAG ? new SetCache() : undefined;
  10199. stack.set(array, other);
  10200. stack.set(other, array); // Ignore non-index properties.
  10201. while (++index < arrLength) {
  10202. var arrValue = array[index],
  10203. othValue = other[index];
  10204. if (customizer) {
  10205. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  10206. }
  10207. if (compared !== undefined) {
  10208. if (compared) {
  10209. continue;
  10210. }
  10211. result = false;
  10212. break;
  10213. } // Recursively compare arrays (susceptible to call stack limits).
  10214. if (seen) {
  10215. if (!arraySome(other, function (othValue, othIndex) {
  10216. if (!seen.has(othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  10217. return seen.add(othIndex);
  10218. }
  10219. })) {
  10220. result = false;
  10221. break;
  10222. }
  10223. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  10224. result = false;
  10225. break;
  10226. }
  10227. }
  10228. stack['delete'](array);
  10229. stack['delete'](other);
  10230. return result;
  10231. }
  10232. /**
  10233. * A specialized version of `baseIsEqualDeep` for comparing objects of
  10234. * the same `toStringTag`.
  10235. *
  10236. * **Note:** This function only supports comparing values with tags of
  10237. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  10238. *
  10239. * @private
  10240. * @param {Object} object The object to compare.
  10241. * @param {Object} other The other object to compare.
  10242. * @param {string} tag The `toStringTag` of the objects to compare.
  10243. * @param {Function} equalFunc The function to determine equivalents of values.
  10244. * @param {Function} customizer The function to customize comparisons.
  10245. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  10246. * for more details.
  10247. * @param {Object} stack Tracks traversed `object` and `other` objects.
  10248. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  10249. */
  10250. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  10251. switch (tag) {
  10252. case dataViewTag:
  10253. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  10254. return false;
  10255. }
  10256. object = object.buffer;
  10257. other = other.buffer;
  10258. case arrayBufferTag:
  10259. if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  10260. return false;
  10261. }
  10262. return true;
  10263. case boolTag:
  10264. case dateTag:
  10265. case numberTag:
  10266. // Coerce booleans to `1` or `0` and dates to milliseconds.
  10267. // Invalid dates are coerced to `NaN`.
  10268. return eq(+object, +other);
  10269. case errorTag:
  10270. return object.name == other.name && object.message == other.message;
  10271. case regexpTag:
  10272. case stringTag:
  10273. // Coerce regexes to strings and treat strings, primitives and objects,
  10274. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  10275. // for more details.
  10276. return object == other + '';
  10277. case mapTag:
  10278. var convert = mapToArray;
  10279. case setTag:
  10280. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  10281. convert || (convert = setToArray);
  10282. if (object.size != other.size && !isPartial) {
  10283. return false;
  10284. } // Assume cyclic values are equal.
  10285. var stacked = stack.get(object);
  10286. if (stacked) {
  10287. return stacked == other;
  10288. }
  10289. bitmask |= UNORDERED_COMPARE_FLAG; // Recursively compare objects (susceptible to call stack limits).
  10290. stack.set(object, other);
  10291. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  10292. stack['delete'](object);
  10293. return result;
  10294. case symbolTag:
  10295. if (symbolValueOf) {
  10296. return symbolValueOf.call(object) == symbolValueOf.call(other);
  10297. }
  10298. }
  10299. return false;
  10300. }
  10301. /**
  10302. * A specialized version of `baseIsEqualDeep` for objects with support for
  10303. * partial deep comparisons.
  10304. *
  10305. * @private
  10306. * @param {Object} object The object to compare.
  10307. * @param {Object} other The other object to compare.
  10308. * @param {Function} equalFunc The function to determine equivalents of values.
  10309. * @param {Function} customizer The function to customize comparisons.
  10310. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  10311. * for more details.
  10312. * @param {Object} stack Tracks traversed `object` and `other` objects.
  10313. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  10314. */
  10315. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  10316. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  10317. objProps = keys(object),
  10318. objLength = objProps.length,
  10319. othProps = keys(other),
  10320. othLength = othProps.length;
  10321. if (objLength != othLength && !isPartial) {
  10322. return false;
  10323. }
  10324. var index = objLength;
  10325. while (index--) {
  10326. var key = objProps[index];
  10327. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  10328. return false;
  10329. }
  10330. } // Assume cyclic values are equal.
  10331. var stacked = stack.get(object);
  10332. if (stacked && stack.get(other)) {
  10333. return stacked == other;
  10334. }
  10335. var result = true;
  10336. stack.set(object, other);
  10337. stack.set(other, object);
  10338. var skipCtor = isPartial;
  10339. while (++index < objLength) {
  10340. key = objProps[index];
  10341. var objValue = object[key],
  10342. othValue = other[key];
  10343. if (customizer) {
  10344. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  10345. } // Recursively compare objects (susceptible to call stack limits).
  10346. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack) : compared)) {
  10347. result = false;
  10348. break;
  10349. }
  10350. skipCtor || (skipCtor = key == 'constructor');
  10351. }
  10352. if (result && !skipCtor) {
  10353. var objCtor = object.constructor,
  10354. othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal.
  10355. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  10356. result = false;
  10357. }
  10358. }
  10359. stack['delete'](object);
  10360. stack['delete'](other);
  10361. return result;
  10362. }
  10363. /**
  10364. * Gets the data for `map`.
  10365. *
  10366. * @private
  10367. * @param {Object} map The map to query.
  10368. * @param {string} key The reference key.
  10369. * @returns {*} Returns the map data.
  10370. */
  10371. function getMapData(map, key) {
  10372. var data = map.__data__;
  10373. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  10374. }
  10375. /**
  10376. * Gets the property names, values, and compare flags of `object`.
  10377. *
  10378. * @private
  10379. * @param {Object} object The object to query.
  10380. * @returns {Array} Returns the match data of `object`.
  10381. */
  10382. function getMatchData(object) {
  10383. var result = keys(object),
  10384. length = result.length;
  10385. while (length--) {
  10386. var key = result[length],
  10387. value = object[key];
  10388. result[length] = [key, value, isStrictComparable(value)];
  10389. }
  10390. return result;
  10391. }
  10392. /**
  10393. * Gets the native function at `key` of `object`.
  10394. *
  10395. * @private
  10396. * @param {Object} object The object to query.
  10397. * @param {string} key The key of the method to get.
  10398. * @returns {*} Returns the function if it's native, else `undefined`.
  10399. */
  10400. function getNative(object, key) {
  10401. var value = getValue(object, key);
  10402. return baseIsNative(value) ? value : undefined;
  10403. }
  10404. /**
  10405. * Gets the `toStringTag` of `value`.
  10406. *
  10407. * @private
  10408. * @param {*} value The value to query.
  10409. * @returns {string} Returns the `toStringTag`.
  10410. */
  10411. var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11,
  10412. // for data views in Edge < 14, and promises in Node.js.
  10413. 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) {
  10414. getTag = function getTag(value) {
  10415. var result = objectToString.call(value),
  10416. Ctor = result == objectTag ? value.constructor : undefined,
  10417. ctorString = Ctor ? toSource(Ctor) : undefined;
  10418. if (ctorString) {
  10419. switch (ctorString) {
  10420. case dataViewCtorString:
  10421. return dataViewTag;
  10422. case mapCtorString:
  10423. return mapTag;
  10424. case promiseCtorString:
  10425. return promiseTag;
  10426. case setCtorString:
  10427. return setTag;
  10428. case weakMapCtorString:
  10429. return weakMapTag;
  10430. }
  10431. }
  10432. return result;
  10433. };
  10434. }
  10435. /**
  10436. * Checks if `path` exists on `object`.
  10437. *
  10438. * @private
  10439. * @param {Object} object The object to query.
  10440. * @param {Array|string} path The path to check.
  10441. * @param {Function} hasFunc The function to check properties.
  10442. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  10443. */
  10444. function hasPath(object, path$$1, hasFunc) {
  10445. path$$1 = isKey(path$$1, object) ? [path$$1] : castPath(path$$1);
  10446. var result,
  10447. index = -1,
  10448. length = path$$1.length;
  10449. while (++index < length) {
  10450. var key = toKey(path$$1[index]);
  10451. if (!(result = object != null && hasFunc(object, key))) {
  10452. break;
  10453. }
  10454. object = object[key];
  10455. }
  10456. if (result) {
  10457. return result;
  10458. }
  10459. var length = object ? object.length : 0;
  10460. return !!length && isLength(length) && isIndex(key, length) && (isArray(object) || isArguments(object));
  10461. }
  10462. /**
  10463. * Checks if `value` is a valid array-like index.
  10464. *
  10465. * @private
  10466. * @param {*} value The value to check.
  10467. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  10468. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  10469. */
  10470. function isIndex(value, length) {
  10471. length = length == null ? MAX_SAFE_INTEGER : length;
  10472. return !!length && (typeof value == 'number' || reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  10473. }
  10474. /**
  10475. * Checks if `value` is a property name and not a property path.
  10476. *
  10477. * @private
  10478. * @param {*} value The value to check.
  10479. * @param {Object} [object] The object to query keys on.
  10480. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  10481. */
  10482. function isKey(value, object) {
  10483. if (isArray(value)) {
  10484. return false;
  10485. }
  10486. var type = typeof value;
  10487. if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol(value)) {
  10488. return true;
  10489. }
  10490. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
  10491. }
  10492. /**
  10493. * Checks if `value` is suitable for use as unique object key.
  10494. *
  10495. * @private
  10496. * @param {*} value The value to check.
  10497. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  10498. */
  10499. function isKeyable(value) {
  10500. var type = typeof value;
  10501. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  10502. }
  10503. /**
  10504. * Checks if `func` has its source masked.
  10505. *
  10506. * @private
  10507. * @param {Function} func The function to check.
  10508. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  10509. */
  10510. function isMasked(func) {
  10511. return !!maskSrcKey && maskSrcKey in func;
  10512. }
  10513. /**
  10514. * Checks if `value` is likely a prototype object.
  10515. *
  10516. * @private
  10517. * @param {*} value The value to check.
  10518. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  10519. */
  10520. function isPrototype(value) {
  10521. var Ctor = value && value.constructor,
  10522. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto;
  10523. return value === proto;
  10524. }
  10525. /**
  10526. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  10527. *
  10528. * @private
  10529. * @param {*} value The value to check.
  10530. * @returns {boolean} Returns `true` if `value` if suitable for strict
  10531. * equality comparisons, else `false`.
  10532. */
  10533. function isStrictComparable(value) {
  10534. return value === value && !isObject(value);
  10535. }
  10536. /**
  10537. * A specialized version of `matchesProperty` for source values suitable
  10538. * for strict equality comparisons, i.e. `===`.
  10539. *
  10540. * @private
  10541. * @param {string} key The key of the property to get.
  10542. * @param {*} srcValue The value to match.
  10543. * @returns {Function} Returns the new spec function.
  10544. */
  10545. function matchesStrictComparable(key, srcValue) {
  10546. return function (object) {
  10547. if (object == null) {
  10548. return false;
  10549. }
  10550. return object[key] === srcValue && (srcValue !== undefined || key in Object(object));
  10551. };
  10552. }
  10553. /**
  10554. * Converts `string` to a property path array.
  10555. *
  10556. * @private
  10557. * @param {string} string The string to convert.
  10558. * @returns {Array} Returns the property path array.
  10559. */
  10560. var stringToPath = memoize(function (string) {
  10561. string = toString(string);
  10562. var result = [];
  10563. if (reLeadingDot.test(string)) {
  10564. result.push('');
  10565. }
  10566. string.replace(rePropName, function (match, number, quote, string) {
  10567. result.push(quote ? string.replace(reEscapeChar, '$1') : number || match);
  10568. });
  10569. return result;
  10570. });
  10571. /**
  10572. * Converts `value` to a string key if it's not a string or symbol.
  10573. *
  10574. * @private
  10575. * @param {*} value The value to inspect.
  10576. * @returns {string|symbol} Returns the key.
  10577. */
  10578. function toKey(value) {
  10579. if (typeof value == 'string' || isSymbol(value)) {
  10580. return value;
  10581. }
  10582. var result = value + '';
  10583. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  10584. }
  10585. /**
  10586. * Converts `func` to its source code.
  10587. *
  10588. * @private
  10589. * @param {Function} func The function to process.
  10590. * @returns {string} Returns the source code.
  10591. */
  10592. function toSource(func) {
  10593. if (func != null) {
  10594. try {
  10595. return funcToString.call(func);
  10596. } catch (e) {}
  10597. try {
  10598. return func + '';
  10599. } catch (e) {}
  10600. }
  10601. return '';
  10602. }
  10603. /**
  10604. * This method is like `_.uniq` except that it accepts `iteratee` which is
  10605. * invoked for each element in `array` to generate the criterion by which
  10606. * uniqueness is computed. The iteratee is invoked with one argument: (value).
  10607. *
  10608. * @static
  10609. * @memberOf _
  10610. * @since 4.0.0
  10611. * @category Array
  10612. * @param {Array} array The array to inspect.
  10613. * @param {Function} [iteratee=_.identity]
  10614. * The iteratee invoked per element.
  10615. * @returns {Array} Returns the new duplicate free array.
  10616. * @example
  10617. *
  10618. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  10619. * // => [2.1, 1.2]
  10620. *
  10621. * // The `_.property` iteratee shorthand.
  10622. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  10623. * // => [{ 'x': 1 }, { 'x': 2 }]
  10624. */
  10625. function uniqBy(array, iteratee) {
  10626. return array && array.length ? baseUniq(array, baseIteratee(iteratee, 2)) : [];
  10627. }
  10628. /**
  10629. * Creates a function that memoizes the result of `func`. If `resolver` is
  10630. * provided, it determines the cache key for storing the result based on the
  10631. * arguments provided to the memoized function. By default, the first argument
  10632. * provided to the memoized function is used as the map cache key. The `func`
  10633. * is invoked with the `this` binding of the memoized function.
  10634. *
  10635. * **Note:** The cache is exposed as the `cache` property on the memoized
  10636. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  10637. * constructor with one whose instances implement the
  10638. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  10639. * method interface of `delete`, `get`, `has`, and `set`.
  10640. *
  10641. * @static
  10642. * @memberOf _
  10643. * @since 0.1.0
  10644. * @category Function
  10645. * @param {Function} func The function to have its output memoized.
  10646. * @param {Function} [resolver] The function to resolve the cache key.
  10647. * @returns {Function} Returns the new memoized function.
  10648. * @example
  10649. *
  10650. * var object = { 'a': 1, 'b': 2 };
  10651. * var other = { 'c': 3, 'd': 4 };
  10652. *
  10653. * var values = _.memoize(_.values);
  10654. * values(object);
  10655. * // => [1, 2]
  10656. *
  10657. * values(other);
  10658. * // => [3, 4]
  10659. *
  10660. * object.a = 2;
  10661. * values(object);
  10662. * // => [1, 2]
  10663. *
  10664. * // Modify the result cache.
  10665. * values.cache.set(object, ['a', 'b']);
  10666. * values(object);
  10667. * // => ['a', 'b']
  10668. *
  10669. * // Replace `_.memoize.Cache`.
  10670. * _.memoize.Cache = WeakMap;
  10671. */
  10672. function memoize(func, resolver) {
  10673. if (typeof func != 'function' || resolver && typeof resolver != 'function') {
  10674. throw new TypeError(FUNC_ERROR_TEXT);
  10675. }
  10676. var memoized = function memoized() {
  10677. var args = arguments,
  10678. key = resolver ? resolver.apply(this, args) : args[0],
  10679. cache = memoized.cache;
  10680. if (cache.has(key)) {
  10681. return cache.get(key);
  10682. }
  10683. var result = func.apply(this, args);
  10684. memoized.cache = cache.set(key, result);
  10685. return result;
  10686. };
  10687. memoized.cache = new (memoize.Cache || MapCache)();
  10688. return memoized;
  10689. } // Assign cache to `_.memoize`.
  10690. memoize.Cache = MapCache;
  10691. /**
  10692. * Performs a
  10693. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10694. * comparison between two values to determine if they are equivalent.
  10695. *
  10696. * @static
  10697. * @memberOf _
  10698. * @since 4.0.0
  10699. * @category Lang
  10700. * @param {*} value The value to compare.
  10701. * @param {*} other The other value to compare.
  10702. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10703. * @example
  10704. *
  10705. * var object = { 'a': 1 };
  10706. * var other = { 'a': 1 };
  10707. *
  10708. * _.eq(object, object);
  10709. * // => true
  10710. *
  10711. * _.eq(object, other);
  10712. * // => false
  10713. *
  10714. * _.eq('a', 'a');
  10715. * // => true
  10716. *
  10717. * _.eq('a', Object('a'));
  10718. * // => false
  10719. *
  10720. * _.eq(NaN, NaN);
  10721. * // => true
  10722. */
  10723. function eq(value, other) {
  10724. return value === other || value !== value && other !== other;
  10725. }
  10726. /**
  10727. * Checks if `value` is likely an `arguments` object.
  10728. *
  10729. * @static
  10730. * @memberOf _
  10731. * @since 0.1.0
  10732. * @category Lang
  10733. * @param {*} value The value to check.
  10734. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10735. * else `false`.
  10736. * @example
  10737. *
  10738. * _.isArguments(function() { return arguments; }());
  10739. * // => true
  10740. *
  10741. * _.isArguments([1, 2, 3]);
  10742. * // => false
  10743. */
  10744. function isArguments(value) {
  10745. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  10746. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  10747. }
  10748. /**
  10749. * Checks if `value` is classified as an `Array` object.
  10750. *
  10751. * @static
  10752. * @memberOf _
  10753. * @since 0.1.0
  10754. * @category Lang
  10755. * @param {*} value The value to check.
  10756. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10757. * @example
  10758. *
  10759. * _.isArray([1, 2, 3]);
  10760. * // => true
  10761. *
  10762. * _.isArray(document.body.children);
  10763. * // => false
  10764. *
  10765. * _.isArray('abc');
  10766. * // => false
  10767. *
  10768. * _.isArray(_.noop);
  10769. * // => false
  10770. */
  10771. var isArray = Array.isArray;
  10772. /**
  10773. * Checks if `value` is array-like. A value is considered array-like if it's
  10774. * not a function and has a `value.length` that's an integer greater than or
  10775. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10776. *
  10777. * @static
  10778. * @memberOf _
  10779. * @since 4.0.0
  10780. * @category Lang
  10781. * @param {*} value The value to check.
  10782. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10783. * @example
  10784. *
  10785. * _.isArrayLike([1, 2, 3]);
  10786. * // => true
  10787. *
  10788. * _.isArrayLike(document.body.children);
  10789. * // => true
  10790. *
  10791. * _.isArrayLike('abc');
  10792. * // => true
  10793. *
  10794. * _.isArrayLike(_.noop);
  10795. * // => false
  10796. */
  10797. function isArrayLike(value) {
  10798. return value != null && isLength(value.length) && !isFunction(value);
  10799. }
  10800. /**
  10801. * This method is like `_.isArrayLike` except that it also checks if `value`
  10802. * is an object.
  10803. *
  10804. * @static
  10805. * @memberOf _
  10806. * @since 4.0.0
  10807. * @category Lang
  10808. * @param {*} value The value to check.
  10809. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10810. * else `false`.
  10811. * @example
  10812. *
  10813. * _.isArrayLikeObject([1, 2, 3]);
  10814. * // => true
  10815. *
  10816. * _.isArrayLikeObject(document.body.children);
  10817. * // => true
  10818. *
  10819. * _.isArrayLikeObject('abc');
  10820. * // => false
  10821. *
  10822. * _.isArrayLikeObject(_.noop);
  10823. * // => false
  10824. */
  10825. function isArrayLikeObject(value) {
  10826. return isObjectLike(value) && isArrayLike(value);
  10827. }
  10828. /**
  10829. * Checks if `value` is classified as a `Function` object.
  10830. *
  10831. * @static
  10832. * @memberOf _
  10833. * @since 0.1.0
  10834. * @category Lang
  10835. * @param {*} value The value to check.
  10836. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10837. * @example
  10838. *
  10839. * _.isFunction(_);
  10840. * // => true
  10841. *
  10842. * _.isFunction(/abc/);
  10843. * // => false
  10844. */
  10845. function isFunction(value) {
  10846. // The use of `Object#toString` avoids issues with the `typeof` operator
  10847. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  10848. var tag = isObject(value) ? objectToString.call(value) : '';
  10849. return tag == funcTag || tag == genTag;
  10850. }
  10851. /**
  10852. * Checks if `value` is a valid array-like length.
  10853. *
  10854. * **Note:** This method is loosely based on
  10855. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10856. *
  10857. * @static
  10858. * @memberOf _
  10859. * @since 4.0.0
  10860. * @category Lang
  10861. * @param {*} value The value to check.
  10862. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10863. * @example
  10864. *
  10865. * _.isLength(3);
  10866. * // => true
  10867. *
  10868. * _.isLength(Number.MIN_VALUE);
  10869. * // => false
  10870. *
  10871. * _.isLength(Infinity);
  10872. * // => false
  10873. *
  10874. * _.isLength('3');
  10875. * // => false
  10876. */
  10877. function isLength(value) {
  10878. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10879. }
  10880. /**
  10881. * Checks if `value` is the
  10882. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10883. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10884. *
  10885. * @static
  10886. * @memberOf _
  10887. * @since 0.1.0
  10888. * @category Lang
  10889. * @param {*} value The value to check.
  10890. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10891. * @example
  10892. *
  10893. * _.isObject({});
  10894. * // => true
  10895. *
  10896. * _.isObject([1, 2, 3]);
  10897. * // => true
  10898. *
  10899. * _.isObject(_.noop);
  10900. * // => true
  10901. *
  10902. * _.isObject(null);
  10903. * // => false
  10904. */
  10905. function isObject(value) {
  10906. var type = typeof value;
  10907. return !!value && (type == 'object' || type == 'function');
  10908. }
  10909. /**
  10910. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10911. * and has a `typeof` result of "object".
  10912. *
  10913. * @static
  10914. * @memberOf _
  10915. * @since 4.0.0
  10916. * @category Lang
  10917. * @param {*} value The value to check.
  10918. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10919. * @example
  10920. *
  10921. * _.isObjectLike({});
  10922. * // => true
  10923. *
  10924. * _.isObjectLike([1, 2, 3]);
  10925. * // => true
  10926. *
  10927. * _.isObjectLike(_.noop);
  10928. * // => false
  10929. *
  10930. * _.isObjectLike(null);
  10931. * // => false
  10932. */
  10933. function isObjectLike(value) {
  10934. return !!value && typeof value == 'object';
  10935. }
  10936. /**
  10937. * Checks if `value` is classified as a `Symbol` primitive or object.
  10938. *
  10939. * @static
  10940. * @memberOf _
  10941. * @since 4.0.0
  10942. * @category Lang
  10943. * @param {*} value The value to check.
  10944. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  10945. * @example
  10946. *
  10947. * _.isSymbol(Symbol.iterator);
  10948. * // => true
  10949. *
  10950. * _.isSymbol('abc');
  10951. * // => false
  10952. */
  10953. function isSymbol(value) {
  10954. return typeof value == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;
  10955. }
  10956. /**
  10957. * Checks if `value` is classified as a typed array.
  10958. *
  10959. * @static
  10960. * @memberOf _
  10961. * @since 3.0.0
  10962. * @category Lang
  10963. * @param {*} value The value to check.
  10964. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  10965. * @example
  10966. *
  10967. * _.isTypedArray(new Uint8Array);
  10968. * // => true
  10969. *
  10970. * _.isTypedArray([]);
  10971. * // => false
  10972. */
  10973. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  10974. /**
  10975. * Converts `value` to a string. An empty string is returned for `null`
  10976. * and `undefined` values. The sign of `-0` is preserved.
  10977. *
  10978. * @static
  10979. * @memberOf _
  10980. * @since 4.0.0
  10981. * @category Lang
  10982. * @param {*} value The value to process.
  10983. * @returns {string} Returns the string.
  10984. * @example
  10985. *
  10986. * _.toString(null);
  10987. * // => ''
  10988. *
  10989. * _.toString(-0);
  10990. * // => '-0'
  10991. *
  10992. * _.toString([1, 2, 3]);
  10993. * // => '1,2,3'
  10994. */
  10995. function toString(value) {
  10996. return value == null ? '' : baseToString(value);
  10997. }
  10998. /**
  10999. * Gets the value at `path` of `object`. If the resolved value is
  11000. * `undefined`, the `defaultValue` is returned in its place.
  11001. *
  11002. * @static
  11003. * @memberOf _
  11004. * @since 3.7.0
  11005. * @category Object
  11006. * @param {Object} object The object to query.
  11007. * @param {Array|string} path The path of the property to get.
  11008. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  11009. * @returns {*} Returns the resolved value.
  11010. * @example
  11011. *
  11012. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  11013. *
  11014. * _.get(object, 'a[0].b.c');
  11015. * // => 3
  11016. *
  11017. * _.get(object, ['a', '0', 'b', 'c']);
  11018. * // => 3
  11019. *
  11020. * _.get(object, 'a.b.c', 'default');
  11021. * // => 'default'
  11022. */
  11023. function get(object, path$$1, defaultValue) {
  11024. var result = object == null ? undefined : baseGet(object, path$$1);
  11025. return result === undefined ? defaultValue : result;
  11026. }
  11027. /**
  11028. * Checks if `path` is a direct or inherited property of `object`.
  11029. *
  11030. * @static
  11031. * @memberOf _
  11032. * @since 4.0.0
  11033. * @category Object
  11034. * @param {Object} object The object to query.
  11035. * @param {Array|string} path The path to check.
  11036. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  11037. * @example
  11038. *
  11039. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  11040. *
  11041. * _.hasIn(object, 'a');
  11042. * // => true
  11043. *
  11044. * _.hasIn(object, 'a.b');
  11045. * // => true
  11046. *
  11047. * _.hasIn(object, ['a', 'b']);
  11048. * // => true
  11049. *
  11050. * _.hasIn(object, 'b');
  11051. * // => false
  11052. */
  11053. function hasIn(object, path$$1) {
  11054. return object != null && hasPath(object, path$$1, baseHasIn);
  11055. }
  11056. /**
  11057. * Creates an array of the own enumerable property names of `object`.
  11058. *
  11059. * **Note:** Non-object values are coerced to objects. See the
  11060. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  11061. * for more details.
  11062. *
  11063. * @static
  11064. * @since 0.1.0
  11065. * @memberOf _
  11066. * @category Object
  11067. * @param {Object} object The object to query.
  11068. * @returns {Array} Returns the array of property names.
  11069. * @example
  11070. *
  11071. * function Foo() {
  11072. * this.a = 1;
  11073. * this.b = 2;
  11074. * }
  11075. *
  11076. * Foo.prototype.c = 3;
  11077. *
  11078. * _.keys(new Foo);
  11079. * // => ['a', 'b'] (iteration order is not guaranteed)
  11080. *
  11081. * _.keys('hi');
  11082. * // => ['0', '1']
  11083. */
  11084. function keys(object) {
  11085. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  11086. }
  11087. /**
  11088. * This method returns the first argument it receives.
  11089. *
  11090. * @static
  11091. * @since 0.1.0
  11092. * @memberOf _
  11093. * @category Util
  11094. * @param {*} value Any value.
  11095. * @returns {*} Returns `value`.
  11096. * @example
  11097. *
  11098. * var object = { 'a': 1 };
  11099. *
  11100. * console.log(_.identity(object) === object);
  11101. * // => true
  11102. */
  11103. function identity(value) {
  11104. return value;
  11105. }
  11106. /**
  11107. * This method returns `undefined`.
  11108. *
  11109. * @static
  11110. * @memberOf _
  11111. * @since 2.3.0
  11112. * @category Util
  11113. * @example
  11114. *
  11115. * _.times(2, _.noop);
  11116. * // => [undefined, undefined]
  11117. */
  11118. function noop() {} // No operation performed.
  11119. /**
  11120. * Creates a function that returns the value at `path` of a given object.
  11121. *
  11122. * @static
  11123. * @memberOf _
  11124. * @since 2.4.0
  11125. * @category Util
  11126. * @param {Array|string} path The path of the property to get.
  11127. * @returns {Function} Returns the new accessor function.
  11128. * @example
  11129. *
  11130. * var objects = [
  11131. * { 'a': { 'b': 2 } },
  11132. * { 'a': { 'b': 1 } }
  11133. * ];
  11134. *
  11135. * _.map(objects, _.property('a.b'));
  11136. * // => [2, 1]
  11137. *
  11138. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  11139. * // => [1, 2]
  11140. */
  11141. function property(path$$1) {
  11142. return isKey(path$$1) ? baseProperty(toKey(path$$1)) : basePropertyDeep(path$$1);
  11143. }
  11144. module.exports = uniqBy;
  11145. });
  11146. var PENDING = 'pending';
  11147. var SETTLED = 'settled';
  11148. var FULFILLED = 'fulfilled';
  11149. var REJECTED = 'rejected';
  11150. var NOOP = function NOOP() {};
  11151. var isNode = typeof commonjsGlobal !== 'undefined' && typeof commonjsGlobal.process !== 'undefined' && typeof commonjsGlobal.process.emit === 'function';
  11152. var asyncSetTimer = typeof setImmediate === 'undefined' ? setTimeout : setImmediate;
  11153. var asyncQueue = [];
  11154. var asyncTimer;
  11155. function asyncFlush() {
  11156. // run promise callbacks
  11157. for (var i = 0; i < asyncQueue.length; i++) {
  11158. asyncQueue[i][0](asyncQueue[i][1]);
  11159. } // reset async asyncQueue
  11160. asyncQueue = [];
  11161. asyncTimer = false;
  11162. }
  11163. function asyncCall(callback, arg) {
  11164. asyncQueue.push([callback, arg]);
  11165. if (!asyncTimer) {
  11166. asyncTimer = true;
  11167. asyncSetTimer(asyncFlush, 0);
  11168. }
  11169. }
  11170. function invokeResolver(resolver, promise) {
  11171. function resolvePromise(value) {
  11172. resolve(promise, value);
  11173. }
  11174. function rejectPromise(reason) {
  11175. reject(promise, reason);
  11176. }
  11177. try {
  11178. resolver(resolvePromise, rejectPromise);
  11179. } catch (e) {
  11180. rejectPromise(e);
  11181. }
  11182. }
  11183. function invokeCallback(subscriber) {
  11184. var owner = subscriber.owner;
  11185. var settled = owner._state;
  11186. var value = owner._data;
  11187. var callback = subscriber[settled];
  11188. var promise = subscriber.then;
  11189. if (typeof callback === 'function') {
  11190. settled = FULFILLED;
  11191. try {
  11192. value = callback(value);
  11193. } catch (e) {
  11194. reject(promise, e);
  11195. }
  11196. }
  11197. if (!handleThenable(promise, value)) {
  11198. if (settled === FULFILLED) {
  11199. resolve(promise, value);
  11200. }
  11201. if (settled === REJECTED) {
  11202. reject(promise, value);
  11203. }
  11204. }
  11205. }
  11206. function handleThenable(promise, value) {
  11207. var resolved;
  11208. try {
  11209. if (promise === value) {
  11210. throw new TypeError('A promises callback cannot return that same promise.');
  11211. }
  11212. if (value && (typeof value === 'function' || typeof value === 'object')) {
  11213. // then should be retrieved only once
  11214. var then = value.then;
  11215. if (typeof then === 'function') {
  11216. then.call(value, function (val) {
  11217. if (!resolved) {
  11218. resolved = true;
  11219. if (value === val) {
  11220. fulfill(promise, val);
  11221. } else {
  11222. resolve(promise, val);
  11223. }
  11224. }
  11225. }, function (reason) {
  11226. if (!resolved) {
  11227. resolved = true;
  11228. reject(promise, reason);
  11229. }
  11230. });
  11231. return true;
  11232. }
  11233. }
  11234. } catch (e) {
  11235. if (!resolved) {
  11236. reject(promise, e);
  11237. }
  11238. return true;
  11239. }
  11240. return false;
  11241. }
  11242. function resolve(promise, value) {
  11243. if (promise === value || !handleThenable(promise, value)) {
  11244. fulfill(promise, value);
  11245. }
  11246. }
  11247. function fulfill(promise, value) {
  11248. if (promise._state === PENDING) {
  11249. promise._state = SETTLED;
  11250. promise._data = value;
  11251. asyncCall(publishFulfillment, promise);
  11252. }
  11253. }
  11254. function reject(promise, reason) {
  11255. if (promise._state === PENDING) {
  11256. promise._state = SETTLED;
  11257. promise._data = reason;
  11258. asyncCall(publishRejection, promise);
  11259. }
  11260. }
  11261. function publish(promise) {
  11262. promise._then = promise._then.forEach(invokeCallback);
  11263. }
  11264. function publishFulfillment(promise) {
  11265. promise._state = FULFILLED;
  11266. publish(promise);
  11267. }
  11268. function publishRejection(promise) {
  11269. promise._state = REJECTED;
  11270. publish(promise);
  11271. if (!promise._handled && isNode) {
  11272. commonjsGlobal.process.emit('unhandledRejection', promise._data, promise);
  11273. }
  11274. }
  11275. function notifyRejectionHandled(promise) {
  11276. commonjsGlobal.process.emit('rejectionHandled', promise);
  11277. }
  11278. /**
  11279. * @class
  11280. */
  11281. function Promise$1(resolver) {
  11282. if (typeof resolver !== 'function') {
  11283. throw new TypeError('Promise resolver ' + resolver + ' is not a function');
  11284. }
  11285. if (this instanceof Promise$1 === false) {
  11286. throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object constructor cannot be called as a function.');
  11287. }
  11288. this._then = [];
  11289. invokeResolver(resolver, this);
  11290. }
  11291. Promise$1.prototype = {
  11292. constructor: Promise$1,
  11293. _state: PENDING,
  11294. _then: null,
  11295. _data: undefined,
  11296. _handled: false,
  11297. then: function then(onFulfillment, onRejection) {
  11298. var subscriber = {
  11299. owner: this,
  11300. then: new this.constructor(NOOP),
  11301. fulfilled: onFulfillment,
  11302. rejected: onRejection
  11303. };
  11304. if ((onRejection || onFulfillment) && !this._handled) {
  11305. this._handled = true;
  11306. if (this._state === REJECTED && isNode) {
  11307. asyncCall(notifyRejectionHandled, this);
  11308. }
  11309. }
  11310. if (this._state === FULFILLED || this._state === REJECTED) {
  11311. // already resolved, call callback async
  11312. asyncCall(invokeCallback, subscriber);
  11313. } else {
  11314. // subscribe
  11315. this._then.push(subscriber);
  11316. }
  11317. return subscriber.then;
  11318. },
  11319. catch: function _catch(onRejection) {
  11320. return this.then(null, onRejection);
  11321. }
  11322. };
  11323. Promise$1.all = function (promises) {
  11324. if (!Array.isArray(promises)) {
  11325. throw new TypeError('You must pass an array to Promise.all().');
  11326. }
  11327. return new Promise$1(function (resolve, reject) {
  11328. var results = [];
  11329. var remaining = 0;
  11330. function resolver(index) {
  11331. remaining++;
  11332. return function (value) {
  11333. results[index] = value;
  11334. if (! --remaining) {
  11335. resolve(results);
  11336. }
  11337. };
  11338. }
  11339. for (var i = 0, promise; i < promises.length; i++) {
  11340. promise = promises[i];
  11341. if (promise && typeof promise.then === 'function') {
  11342. promise.then(resolver(i), reject);
  11343. } else {
  11344. results[i] = promise;
  11345. }
  11346. }
  11347. if (!remaining) {
  11348. resolve(results);
  11349. }
  11350. });
  11351. };
  11352. Promise$1.race = function (promises) {
  11353. if (!Array.isArray(promises)) {
  11354. throw new TypeError('You must pass an array to Promise.race().');
  11355. }
  11356. return new Promise$1(function (resolve, reject) {
  11357. for (var i = 0, promise; i < promises.length; i++) {
  11358. promise = promises[i];
  11359. if (promise && typeof promise.then === 'function') {
  11360. promise.then(resolve, reject);
  11361. } else {
  11362. resolve(promise);
  11363. }
  11364. }
  11365. });
  11366. };
  11367. Promise$1.resolve = function (value) {
  11368. if (value && typeof value === 'object' && value.constructor === Promise$1) {
  11369. return value;
  11370. }
  11371. return new Promise$1(function (resolve) {
  11372. resolve(value);
  11373. });
  11374. };
  11375. Promise$1.reject = function (reason) {
  11376. return new Promise$1(function (resolve, reject) {
  11377. reject(reason);
  11378. });
  11379. };
  11380. var pinkie = Promise$1;
  11381. var pinkiePromise = typeof Promise === 'function' ? Promise : pinkie;
  11382. var arrayUniq = createCommonjsModule(function (module) {
  11383. 'use strict'; // there's 3 implementations written in increasing order of efficiency
  11384. // 1 - no Set type is defined
  11385. function uniqNoSet(arr) {
  11386. var ret = [];
  11387. for (var i = 0; i < arr.length; i++) {
  11388. if (ret.indexOf(arr[i]) === -1) {
  11389. ret.push(arr[i]);
  11390. }
  11391. }
  11392. return ret;
  11393. } // 2 - a simple Set type is defined
  11394. function uniqSet(arr) {
  11395. var seen = new Set();
  11396. return arr.filter(function (el) {
  11397. if (!seen.has(el)) {
  11398. seen.add(el);
  11399. return true;
  11400. }
  11401. return false;
  11402. });
  11403. } // 3 - a standard Set type is defined and it has a forEach method
  11404. function uniqSetWithForEach(arr) {
  11405. var ret = [];
  11406. new Set(arr).forEach(function (el) {
  11407. ret.push(el);
  11408. });
  11409. return ret;
  11410. } // V8 currently has a broken implementation
  11411. // https://github.com/joyent/node/issues/8449
  11412. function doesForEachActuallyWork() {
  11413. var ret = false;
  11414. new Set([true]).forEach(function (el) {
  11415. ret = el;
  11416. });
  11417. return ret === true;
  11418. }
  11419. if ('Set' in commonjsGlobal) {
  11420. if (typeof Set.prototype.forEach === 'function' && doesForEachActuallyWork()) {
  11421. module.exports = uniqSetWithForEach;
  11422. } else {
  11423. module.exports = uniqSet;
  11424. }
  11425. } else {
  11426. module.exports = uniqNoSet;
  11427. }
  11428. });
  11429. var arrayUnion = function arrayUnion() {
  11430. return arrayUniq([].concat.apply([], arguments));
  11431. };
  11432. /*
  11433. object-assign
  11434. (c) Sindre Sorhus
  11435. @license MIT
  11436. */
  11437. /* eslint-disable no-unused-vars */
  11438. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  11439. var hasOwnProperty = Object.prototype.hasOwnProperty;
  11440. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  11441. function toObject(val) {
  11442. if (val === null || val === undefined) {
  11443. throw new TypeError('Object.assign cannot be called with null or undefined');
  11444. }
  11445. return Object(val);
  11446. }
  11447. function shouldUseNative() {
  11448. try {
  11449. if (!Object.assign) {
  11450. return false;
  11451. } // Detect buggy property enumeration order in older V8 versions.
  11452. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  11453. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  11454. test1[5] = 'de';
  11455. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  11456. return false;
  11457. } // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  11458. var test2 = {};
  11459. for (var i = 0; i < 10; i++) {
  11460. test2['_' + String.fromCharCode(i)] = i;
  11461. }
  11462. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  11463. return test2[n];
  11464. });
  11465. if (order2.join('') !== '0123456789') {
  11466. return false;
  11467. } // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  11468. var test3 = {};
  11469. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  11470. test3[letter] = letter;
  11471. });
  11472. if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') {
  11473. return false;
  11474. }
  11475. return true;
  11476. } catch (err) {
  11477. // We don't expect any of the above to throw, but better to be safe.
  11478. return false;
  11479. }
  11480. }
  11481. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  11482. var from;
  11483. var to = toObject(target);
  11484. var symbols;
  11485. for (var s = 1; s < arguments.length; s++) {
  11486. from = Object(arguments[s]);
  11487. for (var key in from) {
  11488. if (hasOwnProperty.call(from, key)) {
  11489. to[key] = from[key];
  11490. }
  11491. }
  11492. if (getOwnPropertySymbols) {
  11493. symbols = getOwnPropertySymbols(from);
  11494. for (var i = 0; i < symbols.length; i++) {
  11495. if (propIsEnumerable.call(from, symbols[i])) {
  11496. to[symbols[i]] = from[symbols[i]];
  11497. }
  11498. }
  11499. }
  11500. }
  11501. return to;
  11502. };
  11503. //
  11504. // Permission is hereby granted, free of charge, to any person obtaining a
  11505. // copy of this software and associated documentation files (the
  11506. // "Software"), to deal in the Software without restriction, including
  11507. // without limitation the rights to use, copy, modify, merge, publish,
  11508. // distribute, sublicense, and/or sell copies of the Software, and to permit
  11509. // persons to whom the Software is furnished to do so, subject to the
  11510. // following conditions:
  11511. //
  11512. // The above copyright notice and this permission notice shall be included
  11513. // in all copies or substantial portions of the Software.
  11514. //
  11515. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11516. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11517. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  11518. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  11519. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  11520. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  11521. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  11522. var isWindows = process.platform === 'win32'; // JavaScript implementation of realpath, ported from node pre-v6
  11523. var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
  11524. function rethrow() {
  11525. // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
  11526. // is fairly slow to generate.
  11527. var callback;
  11528. if (DEBUG) {
  11529. var backtrace = new Error();
  11530. callback = debugCallback;
  11531. } else callback = missingCallback;
  11532. return callback;
  11533. function debugCallback(err) {
  11534. if (err) {
  11535. backtrace.message = err.message;
  11536. err = backtrace;
  11537. missingCallback(err);
  11538. }
  11539. }
  11540. function missingCallback(err) {
  11541. if (err) {
  11542. if (process.throwDeprecation) throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
  11543. else if (!process.noDeprecation) {
  11544. var msg = 'fs: missing callback ' + (err.stack || err.message);
  11545. if (process.traceDeprecation) console.trace(msg);else console.error(msg);
  11546. }
  11547. }
  11548. }
  11549. }
  11550. function maybeCallback(cb) {
  11551. return typeof cb === 'function' ? cb : rethrow();
  11552. }
  11553. // result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
  11554. if (isWindows) {
  11555. var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
  11556. } else {
  11557. var nextPartRe = /(.*?)(?:[\/]+|$)/g;
  11558. } // Regex to find the device root, including trailing slash. E.g. 'c:\\'.
  11559. if (isWindows) {
  11560. var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
  11561. } else {
  11562. var splitRootRe = /^[\/]*/;
  11563. }
  11564. var realpathSync$1 = function realpathSync(p, cache) {
  11565. // make p is absolute
  11566. p = path.resolve(p);
  11567. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  11568. return cache[p];
  11569. }
  11570. var original = p,
  11571. seenLinks = {},
  11572. knownHard = {}; // current character position in p
  11573. var pos; // the partial path so far, including a trailing slash if any
  11574. var current; // the partial path without a trailing slash (except when pointing at a root)
  11575. var base; // the partial path scanned in the previous round, with slash
  11576. var previous;
  11577. start();
  11578. function start() {
  11579. // Skip over roots
  11580. var m = splitRootRe.exec(p);
  11581. pos = m[0].length;
  11582. current = m[0];
  11583. base = m[0];
  11584. previous = ''; // On windows, check that the root exists. On unix there is no need.
  11585. if (isWindows && !knownHard[base]) {
  11586. fs.lstatSync(base);
  11587. knownHard[base] = true;
  11588. }
  11589. } // walk down the path, swapping out linked pathparts for their real
  11590. // values
  11591. // NB: p.length changes.
  11592. while (pos < p.length) {
  11593. // find the next part
  11594. nextPartRe.lastIndex = pos;
  11595. var result = nextPartRe.exec(p);
  11596. previous = current;
  11597. current += result[0];
  11598. base = previous + result[1];
  11599. pos = nextPartRe.lastIndex; // continue if not a symlink
  11600. if (knownHard[base] || cache && cache[base] === base) {
  11601. continue;
  11602. }
  11603. var resolvedLink;
  11604. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  11605. // some known symbolic link. no need to stat again.
  11606. resolvedLink = cache[base];
  11607. } else {
  11608. var stat = fs.lstatSync(base);
  11609. if (!stat.isSymbolicLink()) {
  11610. knownHard[base] = true;
  11611. if (cache) cache[base] = base;
  11612. continue;
  11613. } // read the link if it wasn't read before
  11614. // dev/ino always return 0 on windows, so skip the check.
  11615. var linkTarget = null;
  11616. if (!isWindows) {
  11617. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  11618. if (seenLinks.hasOwnProperty(id)) {
  11619. linkTarget = seenLinks[id];
  11620. }
  11621. }
  11622. if (linkTarget === null) {
  11623. fs.statSync(base);
  11624. linkTarget = fs.readlinkSync(base);
  11625. }
  11626. resolvedLink = path.resolve(previous, linkTarget); // track this, if given a cache.
  11627. if (cache) cache[base] = resolvedLink;
  11628. if (!isWindows) seenLinks[id] = linkTarget;
  11629. } // resolve the link, then start over
  11630. p = path.resolve(resolvedLink, p.slice(pos));
  11631. start();
  11632. }
  11633. if (cache) cache[original] = p;
  11634. return p;
  11635. };
  11636. var realpath$1 = function realpath(p, cache, cb) {
  11637. if (typeof cb !== 'function') {
  11638. cb = maybeCallback(cache);
  11639. cache = null;
  11640. } // make p is absolute
  11641. p = path.resolve(p);
  11642. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  11643. return process.nextTick(cb.bind(null, null, cache[p]));
  11644. }
  11645. var original = p,
  11646. seenLinks = {},
  11647. knownHard = {}; // current character position in p
  11648. var pos; // the partial path so far, including a trailing slash if any
  11649. var current; // the partial path without a trailing slash (except when pointing at a root)
  11650. var base; // the partial path scanned in the previous round, with slash
  11651. var previous;
  11652. start();
  11653. function start() {
  11654. // Skip over roots
  11655. var m = splitRootRe.exec(p);
  11656. pos = m[0].length;
  11657. current = m[0];
  11658. base = m[0];
  11659. previous = ''; // On windows, check that the root exists. On unix there is no need.
  11660. if (isWindows && !knownHard[base]) {
  11661. fs.lstat(base, function (err) {
  11662. if (err) return cb(err);
  11663. knownHard[base] = true;
  11664. LOOP();
  11665. });
  11666. } else {
  11667. process.nextTick(LOOP);
  11668. }
  11669. } // walk down the path, swapping out linked pathparts for their real
  11670. // values
  11671. function LOOP() {
  11672. // stop if scanned past end of path
  11673. if (pos >= p.length) {
  11674. if (cache) cache[original] = p;
  11675. return cb(null, p);
  11676. } // find the next part
  11677. nextPartRe.lastIndex = pos;
  11678. var result = nextPartRe.exec(p);
  11679. previous = current;
  11680. current += result[0];
  11681. base = previous + result[1];
  11682. pos = nextPartRe.lastIndex; // continue if not a symlink
  11683. if (knownHard[base] || cache && cache[base] === base) {
  11684. return process.nextTick(LOOP);
  11685. }
  11686. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  11687. // known symbolic link. no need to stat again.
  11688. return gotResolvedLink(cache[base]);
  11689. }
  11690. return fs.lstat(base, gotStat);
  11691. }
  11692. function gotStat(err, stat) {
  11693. if (err) return cb(err); // if not a symlink, skip to the next path part
  11694. if (!stat.isSymbolicLink()) {
  11695. knownHard[base] = true;
  11696. if (cache) cache[base] = base;
  11697. return process.nextTick(LOOP);
  11698. } // stat & read the link if not read before
  11699. // call gotTarget as soon as the link target is known
  11700. // dev/ino always return 0 on windows, so skip the check.
  11701. if (!isWindows) {
  11702. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  11703. if (seenLinks.hasOwnProperty(id)) {
  11704. return gotTarget(null, seenLinks[id], base);
  11705. }
  11706. }
  11707. fs.stat(base, function (err) {
  11708. if (err) return cb(err);
  11709. fs.readlink(base, function (err, target) {
  11710. if (!isWindows) seenLinks[id] = target;
  11711. gotTarget(err, target);
  11712. });
  11713. });
  11714. }
  11715. function gotTarget(err, target, base) {
  11716. if (err) return cb(err);
  11717. var resolvedLink = path.resolve(previous, target);
  11718. if (cache) cache[base] = resolvedLink;
  11719. gotResolvedLink(resolvedLink);
  11720. }
  11721. function gotResolvedLink(resolvedLink) {
  11722. // resolve the link, then start over
  11723. p = path.resolve(resolvedLink, p.slice(pos));
  11724. start();
  11725. }
  11726. };
  11727. var old = {
  11728. realpathSync: realpathSync$1,
  11729. realpath: realpath$1
  11730. };
  11731. var fs_realpath = realpath;
  11732. realpath.realpath = realpath;
  11733. realpath.sync = realpathSync;
  11734. realpath.realpathSync = realpathSync;
  11735. realpath.monkeypatch = monkeypatch;
  11736. realpath.unmonkeypatch = unmonkeypatch;
  11737. var origRealpath = fs.realpath;
  11738. var origRealpathSync = fs.realpathSync;
  11739. var version$2 = process.version;
  11740. var ok = /^v[0-5]\./.test(version$2);
  11741. function newError(er) {
  11742. return er && er.syscall === 'realpath' && (er.code === 'ELOOP' || er.code === 'ENOMEM' || er.code === 'ENAMETOOLONG');
  11743. }
  11744. function realpath(p, cache, cb) {
  11745. if (ok) {
  11746. return origRealpath(p, cache, cb);
  11747. }
  11748. if (typeof cache === 'function') {
  11749. cb = cache;
  11750. cache = null;
  11751. }
  11752. origRealpath(p, cache, function (er, result) {
  11753. if (newError(er)) {
  11754. old.realpath(p, cache, cb);
  11755. } else {
  11756. cb(er, result);
  11757. }
  11758. });
  11759. }
  11760. function realpathSync(p, cache) {
  11761. if (ok) {
  11762. return origRealpathSync(p, cache);
  11763. }
  11764. try {
  11765. return origRealpathSync(p, cache);
  11766. } catch (er) {
  11767. if (newError(er)) {
  11768. return old.realpathSync(p, cache);
  11769. } else {
  11770. throw er;
  11771. }
  11772. }
  11773. }
  11774. function monkeypatch() {
  11775. fs.realpath = realpath;
  11776. fs.realpathSync = realpathSync;
  11777. }
  11778. function unmonkeypatch() {
  11779. fs.realpath = origRealpath;
  11780. fs.realpathSync = origRealpathSync;
  11781. }
  11782. var concatMap = function concatMap(xs, fn) {
  11783. var res = [];
  11784. for (var i = 0; i < xs.length; i++) {
  11785. var x = fn(xs[i], i);
  11786. if (isArray(x)) res.push.apply(res, x);else res.push(x);
  11787. }
  11788. return res;
  11789. };
  11790. var isArray = Array.isArray || function (xs) {
  11791. return Object.prototype.toString.call(xs) === '[object Array]';
  11792. };
  11793. var balancedMatch = balanced;
  11794. function balanced(a, b, str) {
  11795. if (a instanceof RegExp) a = maybeMatch(a, str);
  11796. if (b instanceof RegExp) b = maybeMatch(b, str);
  11797. var r = range(a, b, str);
  11798. return r && {
  11799. start: r[0],
  11800. end: r[1],
  11801. pre: str.slice(0, r[0]),
  11802. body: str.slice(r[0] + a.length, r[1]),
  11803. post: str.slice(r[1] + b.length)
  11804. };
  11805. }
  11806. function maybeMatch(reg, str) {
  11807. var m = str.match(reg);
  11808. return m ? m[0] : null;
  11809. }
  11810. balanced.range = range;
  11811. function range(a, b, str) {
  11812. var begs, beg, left, right, result;
  11813. var ai = str.indexOf(a);
  11814. var bi = str.indexOf(b, ai + 1);
  11815. var i = ai;
  11816. if (ai >= 0 && bi > 0) {
  11817. begs = [];
  11818. left = str.length;
  11819. while (i >= 0 && !result) {
  11820. if (i == ai) {
  11821. begs.push(i);
  11822. ai = str.indexOf(a, i + 1);
  11823. } else if (begs.length == 1) {
  11824. result = [begs.pop(), bi];
  11825. } else {
  11826. beg = begs.pop();
  11827. if (beg < left) {
  11828. left = beg;
  11829. right = bi;
  11830. }
  11831. bi = str.indexOf(b, i + 1);
  11832. }
  11833. i = ai < bi && ai >= 0 ? ai : bi;
  11834. }
  11835. if (begs.length) {
  11836. result = [left, right];
  11837. }
  11838. }
  11839. return result;
  11840. }
  11841. var braceExpansion = expandTop;
  11842. var escSlash = '\0SLASH' + Math.random() + '\0';
  11843. var escOpen = '\0OPEN' + Math.random() + '\0';
  11844. var escClose = '\0CLOSE' + Math.random() + '\0';
  11845. var escComma = '\0COMMA' + Math.random() + '\0';
  11846. var escPeriod = '\0PERIOD' + Math.random() + '\0';
  11847. function numeric(str) {
  11848. return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
  11849. }
  11850. function escapeBraces(str) {
  11851. return str.split('\\\\').join(escSlash).split('\\{').join(escOpen).split('\\}').join(escClose).split('\\,').join(escComma).split('\\.').join(escPeriod);
  11852. }
  11853. function unescapeBraces(str) {
  11854. return str.split(escSlash).join('\\').split(escOpen).join('{').split(escClose).join('}').split(escComma).join(',').split(escPeriod).join('.');
  11855. } // Basically just str.split(","), but handling cases
  11856. // where we have nested braced sections, which should be
  11857. // treated as individual members, like {a,{b,c},d}
  11858. function parseCommaParts(str) {
  11859. if (!str) return [''];
  11860. var parts = [];
  11861. var m = balancedMatch('{', '}', str);
  11862. if (!m) return str.split(',');
  11863. var pre = m.pre;
  11864. var body = m.body;
  11865. var post = m.post;
  11866. var p = pre.split(',');
  11867. p[p.length - 1] += '{' + body + '}';
  11868. var postParts = parseCommaParts(post);
  11869. if (post.length) {
  11870. p[p.length - 1] += postParts.shift();
  11871. p.push.apply(p, postParts);
  11872. }
  11873. parts.push.apply(parts, p);
  11874. return parts;
  11875. }
  11876. function expandTop(str) {
  11877. if (!str) return []; // I don't know why Bash 4.3 does this, but it does.
  11878. // Anything starting with {} will have the first two bytes preserved
  11879. // but *only* at the top level, so {},a}b will not expand to anything,
  11880. // but a{},b}c will be expanded to [a}c,abc].
  11881. // One could argue that this is a bug in Bash, but since the goal of
  11882. // this module is to match Bash's rules, we escape a leading {}
  11883. if (str.substr(0, 2) === '{}') {
  11884. str = '\\{\\}' + str.substr(2);
  11885. }
  11886. return expand(escapeBraces(str), true).map(unescapeBraces);
  11887. }
  11888. function embrace(str) {
  11889. return '{' + str + '}';
  11890. }
  11891. function isPadded(el) {
  11892. return /^-?0\d/.test(el);
  11893. }
  11894. function lte(i, y) {
  11895. return i <= y;
  11896. }
  11897. function gte(i, y) {
  11898. return i >= y;
  11899. }
  11900. function expand(str, isTop) {
  11901. var expansions = [];
  11902. var m = balancedMatch('{', '}', str);
  11903. if (!m || /\$$/.test(m.pre)) return [str];
  11904. var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
  11905. var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
  11906. var isSequence = isNumericSequence || isAlphaSequence;
  11907. var isOptions = m.body.indexOf(',') >= 0;
  11908. if (!isSequence && !isOptions) {
  11909. // {a},b}
  11910. if (m.post.match(/,.*\}/)) {
  11911. str = m.pre + '{' + m.body + escClose + m.post;
  11912. return expand(str);
  11913. }
  11914. return [str];
  11915. }
  11916. var n;
  11917. if (isSequence) {
  11918. n = m.body.split(/\.\./);
  11919. } else {
  11920. n = parseCommaParts(m.body);
  11921. if (n.length === 1) {
  11922. // x{{a,b}}y ==> x{a}y x{b}y
  11923. n = expand(n[0], false).map(embrace);
  11924. if (n.length === 1) {
  11925. var post = m.post.length ? expand(m.post, false) : [''];
  11926. return post.map(function (p) {
  11927. return m.pre + n[0] + p;
  11928. });
  11929. }
  11930. }
  11931. } // at this point, n is the parts, and we know it's not a comma set
  11932. // with a single entry.
  11933. // no need to expand pre, since it is guaranteed to be free of brace-sets
  11934. var pre = m.pre;
  11935. var post = m.post.length ? expand(m.post, false) : [''];
  11936. var N;
  11937. if (isSequence) {
  11938. var x = numeric(n[0]);
  11939. var y = numeric(n[1]);
  11940. var width = Math.max(n[0].length, n[1].length);
  11941. var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
  11942. var test = lte;
  11943. var reverse = y < x;
  11944. if (reverse) {
  11945. incr *= -1;
  11946. test = gte;
  11947. }
  11948. var pad = n.some(isPadded);
  11949. N = [];
  11950. for (var i = x; test(i, y); i += incr) {
  11951. var c;
  11952. if (isAlphaSequence) {
  11953. c = String.fromCharCode(i);
  11954. if (c === '\\') c = '';
  11955. } else {
  11956. c = String(i);
  11957. if (pad) {
  11958. var need = width - c.length;
  11959. if (need > 0) {
  11960. var z = new Array(need + 1).join('0');
  11961. if (i < 0) c = '-' + z + c.slice(1);else c = z + c;
  11962. }
  11963. }
  11964. }
  11965. N.push(c);
  11966. }
  11967. } else {
  11968. N = concatMap(n, function (el) {
  11969. return expand(el, false);
  11970. });
  11971. }
  11972. for (var j = 0; j < N.length; j++) {
  11973. for (var k = 0; k < post.length; k++) {
  11974. var expansion = pre + N[j] + post[k];
  11975. if (!isTop || isSequence || expansion) expansions.push(expansion);
  11976. }
  11977. }
  11978. return expansions;
  11979. }
  11980. var minimatch_1 = minimatch;
  11981. minimatch.Minimatch = Minimatch$1;
  11982. var path$2 = {
  11983. sep: '/'
  11984. };
  11985. try {
  11986. path$2 = path;
  11987. } catch (er) {}
  11988. var GLOBSTAR = minimatch.GLOBSTAR = Minimatch$1.GLOBSTAR = {};
  11989. var plTypes = {
  11990. '!': {
  11991. open: '(?:(?!(?:',
  11992. close: '))[^/]*?)'
  11993. },
  11994. '?': {
  11995. open: '(?:',
  11996. close: ')?'
  11997. },
  11998. '+': {
  11999. open: '(?:',
  12000. close: ')+'
  12001. },
  12002. '*': {
  12003. open: '(?:',
  12004. close: ')*'
  12005. },
  12006. '@': {
  12007. open: '(?:',
  12008. close: ')'
  12009. } // any single thing other than /
  12010. // don't need to escape / when using new RegExp()
  12011. };
  12012. var qmark = '[^/]'; // * => any number of characters
  12013. var star = qmark + '*?'; // ** when dots are allowed. Anything goes, except .. and .
  12014. // not (^ or / followed by one or two dots followed by $ or /),
  12015. // followed by anything, any number of times.
  12016. var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'; // not a ^ or / followed by a dot,
  12017. // followed by anything, any number of times.
  12018. var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'; // characters that need to be escaped in RegExp.
  12019. var reSpecials = charSet('().*{}+?[]^$\\!'); // "abc" -> { a:true, b:true, c:true }
  12020. function charSet(s) {
  12021. return s.split('').reduce(function (set, c) {
  12022. set[c] = true;
  12023. return set;
  12024. }, {});
  12025. } // normalizes slashes.
  12026. var slashSplit = /\/+/;
  12027. minimatch.filter = filter$1;
  12028. function filter$1(pattern, options) {
  12029. options = options || {};
  12030. return function (p, i, list) {
  12031. return minimatch(p, pattern, options);
  12032. };
  12033. }
  12034. function ext(a, b) {
  12035. a = a || {};
  12036. b = b || {};
  12037. var t = {};
  12038. Object.keys(b).forEach(function (k) {
  12039. t[k] = b[k];
  12040. });
  12041. Object.keys(a).forEach(function (k) {
  12042. t[k] = a[k];
  12043. });
  12044. return t;
  12045. }
  12046. minimatch.defaults = function (def) {
  12047. if (!def || !Object.keys(def).length) return minimatch;
  12048. var orig = minimatch;
  12049. var m = function minimatch(p, pattern, options) {
  12050. return orig.minimatch(p, pattern, ext(def, options));
  12051. };
  12052. m.Minimatch = function Minimatch(pattern, options) {
  12053. return new orig.Minimatch(pattern, ext(def, options));
  12054. };
  12055. return m;
  12056. };
  12057. Minimatch$1.defaults = function (def) {
  12058. if (!def || !Object.keys(def).length) return Minimatch$1;
  12059. return minimatch.defaults(def).Minimatch;
  12060. };
  12061. function minimatch(p, pattern, options) {
  12062. if (typeof pattern !== 'string') {
  12063. throw new TypeError('glob pattern string required');
  12064. }
  12065. if (!options) options = {}; // shortcut: comments match nothing.
  12066. if (!options.nocomment && pattern.charAt(0) === '#') {
  12067. return false;
  12068. } // "" only matches ""
  12069. if (pattern.trim() === '') return p === '';
  12070. return new Minimatch$1(pattern, options).match(p);
  12071. }
  12072. function Minimatch$1(pattern, options) {
  12073. if (!(this instanceof Minimatch$1)) {
  12074. return new Minimatch$1(pattern, options);
  12075. }
  12076. if (typeof pattern !== 'string') {
  12077. throw new TypeError('glob pattern string required');
  12078. }
  12079. if (!options) options = {};
  12080. pattern = pattern.trim(); // windows support: need to use /, not \
  12081. if (path$2.sep !== '/') {
  12082. pattern = pattern.split(path$2.sep).join('/');
  12083. }
  12084. this.options = options;
  12085. this.set = [];
  12086. this.pattern = pattern;
  12087. this.regexp = null;
  12088. this.negate = false;
  12089. this.comment = false;
  12090. this.empty = false; // make the set of regexps etc.
  12091. this.make();
  12092. }
  12093. Minimatch$1.prototype.debug = function () {};
  12094. Minimatch$1.prototype.make = make;
  12095. function make() {
  12096. // don't do it more than once.
  12097. if (this._made) return;
  12098. var pattern = this.pattern;
  12099. var options = this.options; // empty patterns and comments match nothing.
  12100. if (!options.nocomment && pattern.charAt(0) === '#') {
  12101. this.comment = true;
  12102. return;
  12103. }
  12104. if (!pattern) {
  12105. this.empty = true;
  12106. return;
  12107. } // step 1: figure out negation, etc.
  12108. this.parseNegate(); // step 2: expand braces
  12109. var set = this.globSet = this.braceExpand();
  12110. if (options.debug) this.debug = console.error;
  12111. this.debug(this.pattern, set); // step 3: now we have a set, so turn each one into a series of path-portion
  12112. // matching patterns.
  12113. // These will be regexps, except in the case of "**", which is
  12114. // set to the GLOBSTAR object for globstar behavior,
  12115. // and will not contain any / characters
  12116. set = this.globParts = set.map(function (s) {
  12117. return s.split(slashSplit);
  12118. });
  12119. this.debug(this.pattern, set); // glob --> regexps
  12120. set = set.map(function (s, si, set) {
  12121. return s.map(this.parse, this);
  12122. }, this);
  12123. this.debug(this.pattern, set); // filter out everything that didn't compile properly.
  12124. set = set.filter(function (s) {
  12125. return s.indexOf(false) === -1;
  12126. });
  12127. this.debug(this.pattern, set);
  12128. this.set = set;
  12129. }
  12130. Minimatch$1.prototype.parseNegate = parseNegate;
  12131. function parseNegate() {
  12132. var pattern = this.pattern;
  12133. var negate = false;
  12134. var options = this.options;
  12135. var negateOffset = 0;
  12136. if (options.nonegate) return;
  12137. for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === '!'; i++) {
  12138. negate = !negate;
  12139. negateOffset++;
  12140. }
  12141. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  12142. this.negate = negate;
  12143. } // Brace expansion:
  12144. // a{b,c}d -> abd acd
  12145. // a{b,}c -> abc ac
  12146. // a{0..3}d -> a0d a1d a2d a3d
  12147. // a{b,c{d,e}f}g -> abg acdfg acefg
  12148. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  12149. //
  12150. // Invalid sets are not expanded.
  12151. // a{2..}b -> a{2..}b
  12152. // a{b}c -> a{b}c
  12153. minimatch.braceExpand = function (pattern, options) {
  12154. return braceExpand(pattern, options);
  12155. };
  12156. Minimatch$1.prototype.braceExpand = braceExpand;
  12157. function braceExpand(pattern, options) {
  12158. if (!options) {
  12159. if (this instanceof Minimatch$1) {
  12160. options = this.options;
  12161. } else {
  12162. options = {};
  12163. }
  12164. }
  12165. pattern = typeof pattern === 'undefined' ? this.pattern : pattern;
  12166. if (typeof pattern === 'undefined') {
  12167. throw new TypeError('undefined pattern');
  12168. }
  12169. if (options.nobrace || !pattern.match(/\{.*\}/)) {
  12170. // shortcut. no need to expand.
  12171. return [pattern];
  12172. }
  12173. return braceExpansion(pattern);
  12174. } // parse a component of the expanded set.
  12175. // At this point, no pattern may contain "/" in it
  12176. // so we're going to return a 2d array, where each entry is the full
  12177. // pattern, split on '/', and then turned into a regular expression.
  12178. // A regexp is made at the end which joins each array with an
  12179. // escaped /, and another full one which joins each regexp with |.
  12180. //
  12181. // Following the lead of Bash 4.1, note that "**" only has special meaning
  12182. // when it is the *only* thing in a path portion. Otherwise, any series
  12183. // of * is equivalent to a single *. Globstar behavior is enabled by
  12184. // default, and can be disabled by setting options.noglobstar.
  12185. Minimatch$1.prototype.parse = parse$3;
  12186. var SUBPARSE = {};
  12187. function parse$3(pattern, isSub) {
  12188. if (pattern.length > 1024 * 64) {
  12189. throw new TypeError('pattern is too long');
  12190. }
  12191. var options = this.options; // shortcuts
  12192. if (!options.noglobstar && pattern === '**') return GLOBSTAR;
  12193. if (pattern === '') return '';
  12194. var re = '';
  12195. var hasMagic = !!options.nocase;
  12196. var escaping = false; // ? => one single character
  12197. var patternListStack = [];
  12198. var negativeLists = [];
  12199. var stateChar;
  12200. var inClass = false;
  12201. var reClassStart = -1;
  12202. var classStart = -1; // . and .. never match anything that doesn't start with .,
  12203. // even when options.dot is set.
  12204. var patternStart = pattern.charAt(0) === '.' ? '' // anything
  12205. // not (start or / followed by . or .. followed by / or end)
  12206. : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' : '(?!\\.)';
  12207. var self = this;
  12208. function clearStateChar() {
  12209. if (stateChar) {
  12210. // we had some state-tracking character
  12211. // that wasn't consumed by this pass.
  12212. switch (stateChar) {
  12213. case '*':
  12214. re += star;
  12215. hasMagic = true;
  12216. break;
  12217. case '?':
  12218. re += qmark;
  12219. hasMagic = true;
  12220. break;
  12221. default:
  12222. re += '\\' + stateChar;
  12223. break;
  12224. }
  12225. self.debug('clearStateChar %j %j', stateChar, re);
  12226. stateChar = false;
  12227. }
  12228. }
  12229. for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
  12230. this.debug('%s\t%s %s %j', pattern, i, re, c); // skip over any that are escaped.
  12231. if (escaping && reSpecials[c]) {
  12232. re += '\\' + c;
  12233. escaping = false;
  12234. continue;
  12235. }
  12236. switch (c) {
  12237. case '/':
  12238. // completely not allowed, even escaped.
  12239. // Should already be path-split by now.
  12240. return false;
  12241. case '\\':
  12242. clearStateChar();
  12243. escaping = true;
  12244. continue;
  12245. // the various stateChar values
  12246. // for the "extglob" stuff.
  12247. case '?':
  12248. case '*':
  12249. case '+':
  12250. case '@':
  12251. case '!':
  12252. this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c); // all of those are literals inside a class, except that
  12253. // the glob [!a] means [^a] in regexp
  12254. if (inClass) {
  12255. this.debug(' in class');
  12256. if (c === '!' && i === classStart + 1) c = '^';
  12257. re += c;
  12258. continue;
  12259. } // if we already have a stateChar, then it means
  12260. // that there was something like ** or +? in there.
  12261. // Handle the stateChar, then proceed with this one.
  12262. self.debug('call clearStateChar %j', stateChar);
  12263. clearStateChar();
  12264. stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
  12265. // just clear the statechar *now*, rather than even diving into
  12266. // the patternList stuff.
  12267. if (options.noext) clearStateChar();
  12268. continue;
  12269. case '(':
  12270. if (inClass) {
  12271. re += '(';
  12272. continue;
  12273. }
  12274. if (!stateChar) {
  12275. re += '\\(';
  12276. continue;
  12277. }
  12278. patternListStack.push({
  12279. type: stateChar,
  12280. start: i - 1,
  12281. reStart: re.length,
  12282. open: plTypes[stateChar].open,
  12283. close: plTypes[stateChar].close
  12284. }); // negation is (?:(?!js)[^/]*)
  12285. re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
  12286. this.debug('plType %j %j', stateChar, re);
  12287. stateChar = false;
  12288. continue;
  12289. case ')':
  12290. if (inClass || !patternListStack.length) {
  12291. re += '\\)';
  12292. continue;
  12293. }
  12294. clearStateChar();
  12295. hasMagic = true;
  12296. var pl = patternListStack.pop(); // negation is (?:(?!js)[^/]*)
  12297. // The others are (?:<pattern>)<type>
  12298. re += pl.close;
  12299. if (pl.type === '!') {
  12300. negativeLists.push(pl);
  12301. }
  12302. pl.reEnd = re.length;
  12303. continue;
  12304. case '|':
  12305. if (inClass || !patternListStack.length || escaping) {
  12306. re += '\\|';
  12307. escaping = false;
  12308. continue;
  12309. }
  12310. clearStateChar();
  12311. re += '|';
  12312. continue;
  12313. // these are mostly the same in regexp and glob
  12314. case '[':
  12315. // swallow any state-tracking char before the [
  12316. clearStateChar();
  12317. if (inClass) {
  12318. re += '\\' + c;
  12319. continue;
  12320. }
  12321. inClass = true;
  12322. classStart = i;
  12323. reClassStart = re.length;
  12324. re += c;
  12325. continue;
  12326. case ']':
  12327. // a right bracket shall lose its special
  12328. // meaning and represent itself in
  12329. // a bracket expression if it occurs
  12330. // first in the list. -- POSIX.2 2.8.3.2
  12331. if (i === classStart + 1 || !inClass) {
  12332. re += '\\' + c;
  12333. escaping = false;
  12334. continue;
  12335. } // handle the case where we left a class open.
  12336. // "[z-a]" is valid, equivalent to "\[z-a\]"
  12337. if (inClass) {
  12338. // split where the last [ was, make sure we don't have
  12339. // an invalid re. if so, re-walk the contents of the
  12340. // would-be class to re-translate any characters that
  12341. // were passed through as-is
  12342. // TODO: It would probably be faster to determine this
  12343. // without a try/catch and a new RegExp, but it's tricky
  12344. // to do safely. For now, this is safe and works.
  12345. var cs = pattern.substring(classStart + 1, i);
  12346. try {
  12347. RegExp('[' + cs + ']');
  12348. } catch (er) {
  12349. // not a valid class!
  12350. var sp = this.parse(cs, SUBPARSE);
  12351. re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
  12352. hasMagic = hasMagic || sp[1];
  12353. inClass = false;
  12354. continue;
  12355. }
  12356. } // finish up the class.
  12357. hasMagic = true;
  12358. inClass = false;
  12359. re += c;
  12360. continue;
  12361. default:
  12362. // swallow any state char that wasn't consumed
  12363. clearStateChar();
  12364. if (escaping) {
  12365. // no need
  12366. escaping = false;
  12367. } else if (reSpecials[c] && !(c === '^' && inClass)) {
  12368. re += '\\';
  12369. }
  12370. re += c;
  12371. } // switch
  12372. } // for
  12373. // handle the case where we left a class open.
  12374. // "[abc" is valid, equivalent to "\[abc"
  12375. if (inClass) {
  12376. // split where the last [ was, and escape it
  12377. // this is a huge pita. We now have to re-walk
  12378. // the contents of the would-be class to re-translate
  12379. // any characters that were passed through as-is
  12380. cs = pattern.substr(classStart + 1);
  12381. sp = this.parse(cs, SUBPARSE);
  12382. re = re.substr(0, reClassStart) + '\\[' + sp[0];
  12383. hasMagic = hasMagic || sp[1];
  12384. } // handle the case where we had a +( thing at the *end*
  12385. // of the pattern.
  12386. // each pattern list stack adds 3 chars, and we need to go through
  12387. // and escape any | chars that were passed through as-is for the regexp.
  12388. // Go through and escape them, taking care not to double-escape any
  12389. // | chars that were already escaped.
  12390. for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
  12391. var tail = re.slice(pl.reStart + pl.open.length);
  12392. this.debug('setting tail', re, pl); // maybe some even number of \, then maybe 1 \, followed by a |
  12393. tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
  12394. if (!$2) {
  12395. // the | isn't already escaped, so escape it.
  12396. $2 = '\\';
  12397. } // need to escape all those slashes *again*, without escaping the
  12398. // one that we need for escaping the | character. As it works out,
  12399. // escaping an even number of slashes can be done by simply repeating
  12400. // it exactly after itself. That's why this trick works.
  12401. //
  12402. // I am sorry that you have to see this.
  12403. return $1 + $1 + $2 + '|';
  12404. });
  12405. this.debug('tail=%j\n %s', tail, tail, pl, re);
  12406. var t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
  12407. hasMagic = true;
  12408. re = re.slice(0, pl.reStart) + t + '\\(' + tail;
  12409. } // handle trailing things that only matter at the very end.
  12410. clearStateChar();
  12411. if (escaping) {
  12412. // trailing \\
  12413. re += '\\\\';
  12414. } // only need to apply the nodot start if the re starts with
  12415. // something that could conceivably capture a dot
  12416. var addPatternStart = false;
  12417. switch (re.charAt(0)) {
  12418. case '.':
  12419. case '[':
  12420. case '(':
  12421. addPatternStart = true;
  12422. } // Hack to work around lack of negative lookbehind in JS
  12423. // A pattern like: *.!(x).!(y|z) needs to ensure that a name
  12424. // like 'a.xyz.yz' doesn't match. So, the first negative
  12425. // lookahead, has to look ALL the way ahead, to the end of
  12426. // the pattern.
  12427. for (var n = negativeLists.length - 1; n > -1; n--) {
  12428. var nl = negativeLists[n];
  12429. var nlBefore = re.slice(0, nl.reStart);
  12430. var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
  12431. var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
  12432. var nlAfter = re.slice(nl.reEnd);
  12433. nlLast += nlAfter; // Handle nested stuff like *(*.js|!(*.json)), where open parens
  12434. // mean that we should *not* include the ) in the bit that is considered
  12435. // "after" the negated section.
  12436. var openParensBefore = nlBefore.split('(').length - 1;
  12437. var cleanAfter = nlAfter;
  12438. for (i = 0; i < openParensBefore; i++) {
  12439. cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
  12440. }
  12441. nlAfter = cleanAfter;
  12442. var dollar = '';
  12443. if (nlAfter === '' && isSub !== SUBPARSE) {
  12444. dollar = '$';
  12445. }
  12446. var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
  12447. re = newRe;
  12448. } // if the re is not "" at this point, then we need to make sure
  12449. // it doesn't match against an empty path part.
  12450. // Otherwise a/* will match a/, which it should not.
  12451. if (re !== '' && hasMagic) {
  12452. re = '(?=.)' + re;
  12453. }
  12454. if (addPatternStart) {
  12455. re = patternStart + re;
  12456. } // parsing just a piece of a larger pattern.
  12457. if (isSub === SUBPARSE) {
  12458. return [re, hasMagic];
  12459. } // skip the regexp for non-magical patterns
  12460. // unescape anything in it, though, so that it'll be
  12461. // an exact match against a file etc.
  12462. if (!hasMagic) {
  12463. return globUnescape(pattern);
  12464. }
  12465. var flags = options.nocase ? 'i' : '';
  12466. try {
  12467. var regExp = new RegExp('^' + re + '$', flags);
  12468. } catch (er) {
  12469. // If it was an invalid regular expression, then it can't match
  12470. // anything. This trick looks for a character after the end of
  12471. // the string, which is of course impossible, except in multi-line
  12472. // mode, but it's not a /m regex.
  12473. return new RegExp('$.');
  12474. }
  12475. regExp._glob = pattern;
  12476. regExp._src = re;
  12477. return regExp;
  12478. }
  12479. minimatch.makeRe = function (pattern, options) {
  12480. return new Minimatch$1(pattern, options || {}).makeRe();
  12481. };
  12482. Minimatch$1.prototype.makeRe = makeRe;
  12483. function makeRe() {
  12484. if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
  12485. // pattern strings, or "**".
  12486. //
  12487. // It's better to use .match(). This function shouldn't
  12488. // be used, really, but it's pretty convenient sometimes,
  12489. // when you just want to work with a regex.
  12490. var set = this.set;
  12491. if (!set.length) {
  12492. this.regexp = false;
  12493. return this.regexp;
  12494. }
  12495. var options = this.options;
  12496. var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
  12497. var flags = options.nocase ? 'i' : '';
  12498. var re = set.map(function (pattern) {
  12499. return pattern.map(function (p) {
  12500. return p === GLOBSTAR ? twoStar : typeof p === 'string' ? regExpEscape(p) : p._src;
  12501. }).join('\\\/');
  12502. }).join('|'); // must match entire pattern
  12503. // ending in a * or ** will make it less strict.
  12504. re = '^(?:' + re + ')$'; // can match anything, as long as it's not this.
  12505. if (this.negate) re = '^(?!' + re + ').*$';
  12506. try {
  12507. this.regexp = new RegExp(re, flags);
  12508. } catch (ex) {
  12509. this.regexp = false;
  12510. }
  12511. return this.regexp;
  12512. }
  12513. minimatch.match = function (list, pattern, options) {
  12514. options = options || {};
  12515. var mm = new Minimatch$1(pattern, options);
  12516. list = list.filter(function (f) {
  12517. return mm.match(f);
  12518. });
  12519. if (mm.options.nonull && !list.length) {
  12520. list.push(pattern);
  12521. }
  12522. return list;
  12523. };
  12524. Minimatch$1.prototype.match = match;
  12525. function match(f, partial) {
  12526. this.debug('match', f, this.pattern); // short-circuit in the case of busted things.
  12527. // comments, etc.
  12528. if (this.comment) return false;
  12529. if (this.empty) return f === '';
  12530. if (f === '/' && partial) return true;
  12531. var options = this.options; // windows: need to use /, not \
  12532. if (path$2.sep !== '/') {
  12533. f = f.split(path$2.sep).join('/');
  12534. } // treat the test path as a set of pathparts.
  12535. f = f.split(slashSplit);
  12536. this.debug(this.pattern, 'split', f); // just ONE of the pattern sets in this.set needs to match
  12537. // in order for it to be valid. If negating, then just one
  12538. // match means that we have failed.
  12539. // Either way, return on the first hit.
  12540. var set = this.set;
  12541. this.debug(this.pattern, 'set', set); // Find the basename of the path by looking for the last non-empty segment
  12542. var filename;
  12543. var i;
  12544. for (i = f.length - 1; i >= 0; i--) {
  12545. filename = f[i];
  12546. if (filename) break;
  12547. }
  12548. for (i = 0; i < set.length; i++) {
  12549. var pattern = set[i];
  12550. var file = f;
  12551. if (options.matchBase && pattern.length === 1) {
  12552. file = [filename];
  12553. }
  12554. var hit = this.matchOne(file, pattern, partial);
  12555. if (hit) {
  12556. if (options.flipNegate) return true;
  12557. return !this.negate;
  12558. }
  12559. } // didn't get any hits. this is success if it's a negative
  12560. // pattern, failure otherwise.
  12561. if (options.flipNegate) return false;
  12562. return this.negate;
  12563. } // set partial to true to test if, for example,
  12564. // "/a/b" matches the start of "/*/b/*/d"
  12565. // Partial means, if you run out of file before you run
  12566. // out of pattern, then that's fine, as long as all
  12567. // the parts match.
  12568. Minimatch$1.prototype.matchOne = function (file, pattern, partial) {
  12569. var options = this.options;
  12570. this.debug('matchOne', {
  12571. 'this': this,
  12572. file: file,
  12573. pattern: pattern
  12574. });
  12575. this.debug('matchOne', file.length, pattern.length);
  12576. for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
  12577. this.debug('matchOne loop');
  12578. var p = pattern[pi];
  12579. var f = file[fi];
  12580. this.debug(pattern, p, f); // should be impossible.
  12581. // some invalid regexp stuff in the set.
  12582. if (p === false) return false;
  12583. if (p === GLOBSTAR) {
  12584. this.debug('GLOBSTAR', [pattern, p, f]); // "**"
  12585. // a/**/b/**/c would match the following:
  12586. // a/b/x/y/z/c
  12587. // a/x/y/z/b/c
  12588. // a/b/x/b/x/c
  12589. // a/b/c
  12590. // To do this, take the rest of the pattern after
  12591. // the **, and see if it would match the file remainder.
  12592. // If so, return success.
  12593. // If not, the ** "swallows" a segment, and try again.
  12594. // This is recursively awful.
  12595. //
  12596. // a/**/b/**/c matching a/b/x/y/z/c
  12597. // - a matches a
  12598. // - doublestar
  12599. // - matchOne(b/x/y/z/c, b/**/c)
  12600. // - b matches b
  12601. // - doublestar
  12602. // - matchOne(x/y/z/c, c) -> no
  12603. // - matchOne(y/z/c, c) -> no
  12604. // - matchOne(z/c, c) -> no
  12605. // - matchOne(c, c) yes, hit
  12606. var fr = fi;
  12607. var pr = pi + 1;
  12608. if (pr === pl) {
  12609. this.debug('** at the end'); // a ** at the end will just swallow the rest.
  12610. // We have found a match.
  12611. // however, it will not swallow /.x, unless
  12612. // options.dot is set.
  12613. // . and .. are *never* matched by **, for explosively
  12614. // exponential reasons.
  12615. for (; fi < fl; fi++) {
  12616. if (file[fi] === '.' || file[fi] === '..' || !options.dot && file[fi].charAt(0) === '.') return false;
  12617. }
  12618. return true;
  12619. } // ok, let's see if we can swallow whatever we can.
  12620. while (fr < fl) {
  12621. var swallowee = file[fr];
  12622. this.debug('\nglobstar while', file, fr, pattern, pr, swallowee); // XXX remove this slice. Just pass the start index.
  12623. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  12624. this.debug('globstar found match!', fr, fl, swallowee); // found a match.
  12625. return true;
  12626. } else {
  12627. // can't swallow "." or ".." ever.
  12628. // can only swallow ".foo" when explicitly asked.
  12629. if (swallowee === '.' || swallowee === '..' || !options.dot && swallowee.charAt(0) === '.') {
  12630. this.debug('dot detected!', file, fr, pattern, pr);
  12631. break;
  12632. } // ** swallows a segment, and continue.
  12633. this.debug('globstar swallow a segment, and continue');
  12634. fr++;
  12635. }
  12636. } // no match was found.
  12637. // However, in partial mode, we can't say this is necessarily over.
  12638. // If there's more *pattern* left, then
  12639. if (partial) {
  12640. // ran out of file
  12641. this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
  12642. if (fr === fl) return true;
  12643. }
  12644. return false;
  12645. } // something other than **
  12646. // non-magic patterns just have to match exactly
  12647. // patterns with magic have been turned into regexps.
  12648. var hit;
  12649. if (typeof p === 'string') {
  12650. if (options.nocase) {
  12651. hit = f.toLowerCase() === p.toLowerCase();
  12652. } else {
  12653. hit = f === p;
  12654. }
  12655. this.debug('string match', p, f, hit);
  12656. } else {
  12657. hit = f.match(p);
  12658. this.debug('pattern match', p, f, hit);
  12659. }
  12660. if (!hit) return false;
  12661. } // Note: ending in / means that we'll get a final ""
  12662. // at the end of the pattern. This can only match a
  12663. // corresponding "" at the end of the file.
  12664. // If the file ends in /, then it can only match a
  12665. // a pattern that ends in /, unless the pattern just
  12666. // doesn't have any more for it. But, a/b/ should *not*
  12667. // match "a/b/*", even though "" matches against the
  12668. // [^/]*? pattern, except in partial mode, where it might
  12669. // simply not be reached yet.
  12670. // However, a/b/ should still satisfy a/*
  12671. // now either we fell off the end of the pattern, or we're done.
  12672. if (fi === fl && pi === pl) {
  12673. // ran out of pattern and filename at the same time.
  12674. // an exact hit!
  12675. return true;
  12676. } else if (fi === fl) {
  12677. // ran out of file, but still had pattern left.
  12678. // this is ok if we're doing the match as part of
  12679. // a glob fs traversal.
  12680. return partial;
  12681. } else if (pi === pl) {
  12682. // ran out of pattern, still have file left.
  12683. // this is only acceptable if we're on the very last
  12684. // empty segment of a file with a trailing slash.
  12685. // a/* should match a/b/
  12686. var emptyFileEnd = fi === fl - 1 && file[fi] === '';
  12687. return emptyFileEnd;
  12688. } // should be unreachable.
  12689. throw new Error('wtf?');
  12690. }; // replace stuff like \* with *
  12691. function globUnescape(s) {
  12692. return s.replace(/\\(.)/g, '$1');
  12693. }
  12694. function regExpEscape(s) {
  12695. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
  12696. }
  12697. var inherits_browser = createCommonjsModule(function (module) {
  12698. if (typeof Object.create === 'function') {
  12699. // implementation from standard node.js 'util' module
  12700. module.exports = function inherits(ctor, superCtor) {
  12701. ctor.super_ = superCtor;
  12702. ctor.prototype = Object.create(superCtor.prototype, {
  12703. constructor: {
  12704. value: ctor,
  12705. enumerable: false,
  12706. writable: true,
  12707. configurable: true
  12708. }
  12709. });
  12710. };
  12711. } else {
  12712. // old school shim for old browsers
  12713. module.exports = function inherits(ctor, superCtor) {
  12714. ctor.super_ = superCtor;
  12715. var TempCtor = function TempCtor() {};
  12716. TempCtor.prototype = superCtor.prototype;
  12717. ctor.prototype = new TempCtor();
  12718. ctor.prototype.constructor = ctor;
  12719. };
  12720. }
  12721. });
  12722. var inherits = createCommonjsModule(function (module) {
  12723. try {
  12724. var util$$1 = util;
  12725. if (typeof util$$1.inherits !== 'function') throw '';
  12726. module.exports = util$$1.inherits;
  12727. } catch (e) {
  12728. module.exports = inherits_browser;
  12729. }
  12730. });
  12731. function posix(path$$1) {
  12732. return path$$1.charAt(0) === '/';
  12733. }
  12734. function win32(path$$1) {
  12735. // https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
  12736. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
  12737. var result = splitDeviceRe.exec(path$$1);
  12738. var device = result[1] || '';
  12739. var isUnc = Boolean(device && device.charAt(1) !== ':'); // UNC paths are always absolute
  12740. return Boolean(result[2] || isUnc);
  12741. }
  12742. var pathIsAbsolute = process.platform === 'win32' ? win32 : posix;
  12743. var posix_1 = posix;
  12744. var win32_1 = win32;
  12745. pathIsAbsolute.posix = posix_1;
  12746. pathIsAbsolute.win32 = win32_1;
  12747. var alphasort_1 = alphasort$2;
  12748. var alphasorti_1 = alphasorti$2;
  12749. var setopts_1 = setopts$2;
  12750. var ownProp_1 = ownProp$2;
  12751. var makeAbs_1 = makeAbs;
  12752. var finish_1 = finish;
  12753. var mark_1 = mark;
  12754. var isIgnored_1 = isIgnored$2;
  12755. var childrenIgnored_1 = childrenIgnored$2;
  12756. function ownProp$2(obj, field) {
  12757. return Object.prototype.hasOwnProperty.call(obj, field);
  12758. }
  12759. var Minimatch$3 = minimatch_1.Minimatch;
  12760. function alphasorti$2(a, b) {
  12761. return a.toLowerCase().localeCompare(b.toLowerCase());
  12762. }
  12763. function alphasort$2(a, b) {
  12764. return a.localeCompare(b);
  12765. }
  12766. function setupIgnores(self, options) {
  12767. self.ignore = options.ignore || [];
  12768. if (!Array.isArray(self.ignore)) self.ignore = [self.ignore];
  12769. if (self.ignore.length) {
  12770. self.ignore = self.ignore.map(ignoreMap);
  12771. }
  12772. } // ignore patterns are always in dot:true mode.
  12773. function ignoreMap(pattern) {
  12774. var gmatcher = null;
  12775. if (pattern.slice(-3) === '/**') {
  12776. var gpattern = pattern.replace(/(\/\*\*)+$/, '');
  12777. gmatcher = new Minimatch$3(gpattern, {
  12778. dot: true
  12779. });
  12780. }
  12781. return {
  12782. matcher: new Minimatch$3(pattern, {
  12783. dot: true
  12784. }),
  12785. gmatcher: gmatcher
  12786. };
  12787. }
  12788. function setopts$2(self, pattern, options) {
  12789. if (!options) options = {}; // base-matching: just use globstar for that.
  12790. if (options.matchBase && -1 === pattern.indexOf("/")) {
  12791. if (options.noglobstar) {
  12792. throw new Error("base matching requires globstar");
  12793. }
  12794. pattern = "**/" + pattern;
  12795. }
  12796. self.silent = !!options.silent;
  12797. self.pattern = pattern;
  12798. self.strict = options.strict !== false;
  12799. self.realpath = !!options.realpath;
  12800. self.realpathCache = options.realpathCache || Object.create(null);
  12801. self.follow = !!options.follow;
  12802. self.dot = !!options.dot;
  12803. self.mark = !!options.mark;
  12804. self.nodir = !!options.nodir;
  12805. if (self.nodir) self.mark = true;
  12806. self.sync = !!options.sync;
  12807. self.nounique = !!options.nounique;
  12808. self.nonull = !!options.nonull;
  12809. self.nosort = !!options.nosort;
  12810. self.nocase = !!options.nocase;
  12811. self.stat = !!options.stat;
  12812. self.noprocess = !!options.noprocess;
  12813. self.absolute = !!options.absolute;
  12814. self.maxLength = options.maxLength || Infinity;
  12815. self.cache = options.cache || Object.create(null);
  12816. self.statCache = options.statCache || Object.create(null);
  12817. self.symlinks = options.symlinks || Object.create(null);
  12818. setupIgnores(self, options);
  12819. self.changedCwd = false;
  12820. var cwd = process.cwd();
  12821. if (!ownProp$2(options, "cwd")) self.cwd = cwd;else {
  12822. self.cwd = path.resolve(options.cwd);
  12823. self.changedCwd = self.cwd !== cwd;
  12824. }
  12825. self.root = options.root || path.resolve(self.cwd, "/");
  12826. self.root = path.resolve(self.root);
  12827. if (process.platform === "win32") self.root = self.root.replace(/\\/g, "/"); // TODO: is an absolute `cwd` supposed to be resolved against `root`?
  12828. // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
  12829. self.cwdAbs = pathIsAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
  12830. if (process.platform === "win32") self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
  12831. self.nomount = !!options.nomount; // disable comments and negation in Minimatch.
  12832. // Note that they are not supported in Glob itself anyway.
  12833. options.nonegate = true;
  12834. options.nocomment = true;
  12835. self.minimatch = new Minimatch$3(pattern, options);
  12836. self.options = self.minimatch.options;
  12837. }
  12838. function finish(self) {
  12839. var nou = self.nounique;
  12840. var all = nou ? [] : Object.create(null);
  12841. for (var i = 0, l = self.matches.length; i < l; i++) {
  12842. var matches = self.matches[i];
  12843. if (!matches || Object.keys(matches).length === 0) {
  12844. if (self.nonull) {
  12845. // do like the shell, and spit out the literal glob
  12846. var literal = self.minimatch.globSet[i];
  12847. if (nou) all.push(literal);else all[literal] = true;
  12848. }
  12849. } else {
  12850. // had matches
  12851. var m = Object.keys(matches);
  12852. if (nou) all.push.apply(all, m);else m.forEach(function (m) {
  12853. all[m] = true;
  12854. });
  12855. }
  12856. }
  12857. if (!nou) all = Object.keys(all);
  12858. if (!self.nosort) all = all.sort(self.nocase ? alphasorti$2 : alphasort$2); // at *some* point we statted all of these
  12859. if (self.mark) {
  12860. for (var i = 0; i < all.length; i++) {
  12861. all[i] = self._mark(all[i]);
  12862. }
  12863. if (self.nodir) {
  12864. all = all.filter(function (e) {
  12865. var notDir = !/\/$/.test(e);
  12866. var c = self.cache[e] || self.cache[makeAbs(self, e)];
  12867. if (notDir && c) notDir = c !== 'DIR' && !Array.isArray(c);
  12868. return notDir;
  12869. });
  12870. }
  12871. }
  12872. if (self.ignore.length) all = all.filter(function (m) {
  12873. return !isIgnored$2(self, m);
  12874. });
  12875. self.found = all;
  12876. }
  12877. function mark(self, p) {
  12878. var abs = makeAbs(self, p);
  12879. var c = self.cache[abs];
  12880. var m = p;
  12881. if (c) {
  12882. var isDir = c === 'DIR' || Array.isArray(c);
  12883. var slash = p.slice(-1) === '/';
  12884. if (isDir && !slash) m += '/';else if (!isDir && slash) m = m.slice(0, -1);
  12885. if (m !== p) {
  12886. var mabs = makeAbs(self, m);
  12887. self.statCache[mabs] = self.statCache[abs];
  12888. self.cache[mabs] = self.cache[abs];
  12889. }
  12890. }
  12891. return m;
  12892. } // lotta situps...
  12893. function makeAbs(self, f) {
  12894. var abs = f;
  12895. if (f.charAt(0) === '/') {
  12896. abs = path.join(self.root, f);
  12897. } else if (pathIsAbsolute(f) || f === '') {
  12898. abs = f;
  12899. } else if (self.changedCwd) {
  12900. abs = path.resolve(self.cwd, f);
  12901. } else {
  12902. abs = path.resolve(f);
  12903. }
  12904. if (process.platform === 'win32') abs = abs.replace(/\\/g, '/');
  12905. return abs;
  12906. } // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
  12907. // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
  12908. function isIgnored$2(self, path$$2) {
  12909. if (!self.ignore.length) return false;
  12910. return self.ignore.some(function (item) {
  12911. return item.matcher.match(path$$2) || !!(item.gmatcher && item.gmatcher.match(path$$2));
  12912. });
  12913. }
  12914. function childrenIgnored$2(self, path$$2) {
  12915. if (!self.ignore.length) return false;
  12916. return self.ignore.some(function (item) {
  12917. return !!(item.gmatcher && item.gmatcher.match(path$$2));
  12918. });
  12919. }
  12920. var common = {
  12921. alphasort: alphasort_1,
  12922. alphasorti: alphasorti_1,
  12923. setopts: setopts_1,
  12924. ownProp: ownProp_1,
  12925. makeAbs: makeAbs_1,
  12926. finish: finish_1,
  12927. mark: mark_1,
  12928. isIgnored: isIgnored_1,
  12929. childrenIgnored: childrenIgnored_1
  12930. };
  12931. var sync$1 = globSync;
  12932. globSync.GlobSync = GlobSync$1;
  12933. var setopts$1 = common.setopts;
  12934. var ownProp$1 = common.ownProp;
  12935. var childrenIgnored$1 = common.childrenIgnored;
  12936. var isIgnored$1 = common.isIgnored;
  12937. function globSync(pattern, options) {
  12938. 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');
  12939. return new GlobSync$1(pattern, options).found;
  12940. }
  12941. function GlobSync$1(pattern, options) {
  12942. if (!pattern) throw new Error('must provide pattern');
  12943. 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');
  12944. if (!(this instanceof GlobSync$1)) return new GlobSync$1(pattern, options);
  12945. setopts$1(this, pattern, options);
  12946. if (this.noprocess) return this;
  12947. var n = this.minimatch.set.length;
  12948. this.matches = new Array(n);
  12949. for (var i = 0; i < n; i++) {
  12950. this._process(this.minimatch.set[i], i, false);
  12951. }
  12952. this._finish();
  12953. }
  12954. GlobSync$1.prototype._finish = function () {
  12955. assert(this instanceof GlobSync$1);
  12956. if (this.realpath) {
  12957. var self = this;
  12958. this.matches.forEach(function (matchset, index) {
  12959. var set = self.matches[index] = Object.create(null);
  12960. for (var p in matchset) {
  12961. try {
  12962. p = self._makeAbs(p);
  12963. var real = fs_realpath.realpathSync(p, self.realpathCache);
  12964. set[real] = true;
  12965. } catch (er) {
  12966. if (er.syscall === 'stat') set[self._makeAbs(p)] = true;else throw er;
  12967. }
  12968. }
  12969. });
  12970. }
  12971. common.finish(this);
  12972. };
  12973. GlobSync$1.prototype._process = function (pattern, index, inGlobStar) {
  12974. assert(this instanceof GlobSync$1); // Get the first [n] parts of pattern that are all strings.
  12975. var n = 0;
  12976. while (typeof pattern[n] === 'string') {
  12977. n++;
  12978. } // now n is the index of the first one that is *not* a string.
  12979. // See if there's anything else
  12980. var prefix;
  12981. switch (n) {
  12982. // if not, then this is rather simple
  12983. case pattern.length:
  12984. this._processSimple(pattern.join('/'), index);
  12985. return;
  12986. case 0:
  12987. // pattern *starts* with some non-trivial item.
  12988. // going to readdir(cwd), but not include the prefix in matches.
  12989. prefix = null;
  12990. break;
  12991. default:
  12992. // pattern has some string bits in the front.
  12993. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  12994. // or 'relative' like '../baz'
  12995. prefix = pattern.slice(0, n).join('/');
  12996. break;
  12997. }
  12998. var remain = pattern.slice(n); // get the list of entries.
  12999. var read;
  13000. if (prefix === null) read = '.';else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  13001. if (!prefix || !pathIsAbsolute(prefix)) prefix = '/' + prefix;
  13002. read = prefix;
  13003. } else read = prefix;
  13004. var abs = this._makeAbs(read); //if ignored, skip processing
  13005. if (childrenIgnored$1(this, read)) return;
  13006. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  13007. if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar);
  13008. };
  13009. GlobSync$1.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
  13010. var entries = this._readdir(abs, inGlobStar); // if the abs isn't a dir, then nothing can match!
  13011. if (!entries) return; // It will only match dot entries if it starts with a dot, or if
  13012. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  13013. var pn = remain[0];
  13014. var negate = !!this.minimatch.negate;
  13015. var rawGlob = pn._glob;
  13016. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  13017. var matchedEntries = [];
  13018. for (var i = 0; i < entries.length; i++) {
  13019. var e = entries[i];
  13020. if (e.charAt(0) !== '.' || dotOk) {
  13021. var m;
  13022. if (negate && !prefix) {
  13023. m = !e.match(pn);
  13024. } else {
  13025. m = e.match(pn);
  13026. }
  13027. if (m) matchedEntries.push(e);
  13028. }
  13029. }
  13030. var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
  13031. if (len === 0) return; // if this is the last remaining pattern bit, then no need for
  13032. // an additional stat *unless* the user has specified mark or
  13033. // stat explicitly. We know they exist, since readdir returned
  13034. // them.
  13035. if (remain.length === 1 && !this.mark && !this.stat) {
  13036. if (!this.matches[index]) this.matches[index] = Object.create(null);
  13037. for (var i = 0; i < len; i++) {
  13038. var e = matchedEntries[i];
  13039. if (prefix) {
  13040. if (prefix.slice(-1) !== '/') e = prefix + '/' + e;else e = prefix + e;
  13041. }
  13042. if (e.charAt(0) === '/' && !this.nomount) {
  13043. e = path.join(this.root, e);
  13044. }
  13045. this._emitMatch(index, e);
  13046. } // This was the last one, and no stats were needed
  13047. return;
  13048. } // now test all matched entries as stand-ins for that part
  13049. // of the pattern.
  13050. remain.shift();
  13051. for (var i = 0; i < len; i++) {
  13052. var e = matchedEntries[i];
  13053. var newPattern;
  13054. if (prefix) newPattern = [prefix, e];else newPattern = [e];
  13055. this._process(newPattern.concat(remain), index, inGlobStar);
  13056. }
  13057. };
  13058. GlobSync$1.prototype._emitMatch = function (index, e) {
  13059. if (isIgnored$1(this, e)) return;
  13060. var abs = this._makeAbs(e);
  13061. if (this.mark) e = this._mark(e);
  13062. if (this.absolute) {
  13063. e = abs;
  13064. }
  13065. if (this.matches[index][e]) return;
  13066. if (this.nodir) {
  13067. var c = this.cache[abs];
  13068. if (c === 'DIR' || Array.isArray(c)) return;
  13069. }
  13070. this.matches[index][e] = true;
  13071. if (this.stat) this._stat(e);
  13072. };
  13073. GlobSync$1.prototype._readdirInGlobStar = function (abs) {
  13074. // follow all symlinked directories forever
  13075. // just proceed as if this is a non-globstar situation
  13076. if (this.follow) return this._readdir(abs, false);
  13077. var entries;
  13078. var lstat;
  13079. var stat;
  13080. try {
  13081. lstat = fs.lstatSync(abs);
  13082. } catch (er) {
  13083. if (er.code === 'ENOENT') {
  13084. // lstat failed, doesn't exist
  13085. return null;
  13086. }
  13087. }
  13088. var isSym = lstat && lstat.isSymbolicLink();
  13089. this.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
  13090. // don't bother doing a readdir in that case.
  13091. if (!isSym && lstat && !lstat.isDirectory()) this.cache[abs] = 'FILE';else entries = this._readdir(abs, false);
  13092. return entries;
  13093. };
  13094. GlobSync$1.prototype._readdir = function (abs, inGlobStar) {
  13095. var entries;
  13096. if (inGlobStar && !ownProp$1(this.symlinks, abs)) return this._readdirInGlobStar(abs);
  13097. if (ownProp$1(this.cache, abs)) {
  13098. var c = this.cache[abs];
  13099. if (!c || c === 'FILE') return null;
  13100. if (Array.isArray(c)) return c;
  13101. }
  13102. try {
  13103. return this._readdirEntries(abs, fs.readdirSync(abs));
  13104. } catch (er) {
  13105. this._readdirError(abs, er);
  13106. return null;
  13107. }
  13108. };
  13109. GlobSync$1.prototype._readdirEntries = function (abs, entries) {
  13110. // if we haven't asked to stat everything, then just
  13111. // assume that everything in there exists, so we can avoid
  13112. // having to stat it a second time.
  13113. if (!this.mark && !this.stat) {
  13114. for (var i = 0; i < entries.length; i++) {
  13115. var e = entries[i];
  13116. if (abs === '/') e = abs + e;else e = abs + '/' + e;
  13117. this.cache[e] = true;
  13118. }
  13119. }
  13120. this.cache[abs] = entries; // mark and cache dir-ness
  13121. return entries;
  13122. };
  13123. GlobSync$1.prototype._readdirError = function (f, er) {
  13124. // handle errors, and cache the information
  13125. switch (er.code) {
  13126. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  13127. case 'ENOTDIR':
  13128. // totally normal. means it *does* exist.
  13129. var abs = this._makeAbs(f);
  13130. this.cache[abs] = 'FILE';
  13131. if (abs === this.cwdAbs) {
  13132. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  13133. error.path = this.cwd;
  13134. error.code = er.code;
  13135. throw error;
  13136. }
  13137. break;
  13138. case 'ENOENT': // not terribly unusual
  13139. case 'ELOOP':
  13140. case 'ENAMETOOLONG':
  13141. case 'UNKNOWN':
  13142. this.cache[this._makeAbs(f)] = false;
  13143. break;
  13144. default:
  13145. // some unusual error. Treat as failure.
  13146. this.cache[this._makeAbs(f)] = false;
  13147. if (this.strict) throw er;
  13148. if (!this.silent) console.error('glob error', er);
  13149. break;
  13150. }
  13151. };
  13152. GlobSync$1.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
  13153. var entries = this._readdir(abs, inGlobStar); // no entries means not a dir, so it can never have matches
  13154. // foo.txt/** doesn't match foo.txt
  13155. if (!entries) return; // test without the globstar, and with every child both below
  13156. // and replacing the globstar.
  13157. var remainWithoutGlobStar = remain.slice(1);
  13158. var gspref = prefix ? [prefix] : [];
  13159. var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
  13160. this._process(noGlobStar, index, false);
  13161. var len = entries.length;
  13162. var isSym = this.symlinks[abs]; // If it's a symlink, and we're in a globstar, then stop
  13163. if (isSym && inGlobStar) return;
  13164. for (var i = 0; i < len; i++) {
  13165. var e = entries[i];
  13166. if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
  13167. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  13168. this._process(instead, index, true);
  13169. var below = gspref.concat(entries[i], remain);
  13170. this._process(below, index, true);
  13171. }
  13172. };
  13173. GlobSync$1.prototype._processSimple = function (prefix, index) {
  13174. // XXX review this. Shouldn't it be doing the mounting etc
  13175. // before doing stat? kinda weird?
  13176. var exists = this._stat(prefix);
  13177. if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
  13178. if (!exists) return;
  13179. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  13180. var trail = /[\/\\]$/.test(prefix);
  13181. if (prefix.charAt(0) === '/') {
  13182. prefix = path.join(this.root, prefix);
  13183. } else {
  13184. prefix = path.resolve(this.root, prefix);
  13185. if (trail) prefix += '/';
  13186. }
  13187. }
  13188. if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
  13189. this._emitMatch(index, prefix);
  13190. }; // Returns either 'DIR', 'FILE', or false
  13191. GlobSync$1.prototype._stat = function (f) {
  13192. var abs = this._makeAbs(f);
  13193. var needDir = f.slice(-1) === '/';
  13194. if (f.length > this.maxLength) return false;
  13195. if (!this.stat && ownProp$1(this.cache, abs)) {
  13196. var c = this.cache[abs];
  13197. if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
  13198. if (!needDir || c === 'DIR') return c;
  13199. if (needDir && c === 'FILE') return false; // otherwise we have to stat, because maybe c=true
  13200. // if we know it exists, but not what it is.
  13201. }
  13202. var exists;
  13203. var stat = this.statCache[abs];
  13204. if (!stat) {
  13205. var lstat;
  13206. try {
  13207. lstat = fs.lstatSync(abs);
  13208. } catch (er) {
  13209. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  13210. this.statCache[abs] = false;
  13211. return false;
  13212. }
  13213. }
  13214. if (lstat && lstat.isSymbolicLink()) {
  13215. try {
  13216. stat = fs.statSync(abs);
  13217. } catch (er) {
  13218. stat = lstat;
  13219. }
  13220. } else {
  13221. stat = lstat;
  13222. }
  13223. }
  13224. this.statCache[abs] = stat;
  13225. var c = true;
  13226. if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
  13227. this.cache[abs] = this.cache[abs] || c;
  13228. if (needDir && c === 'FILE') return false;
  13229. return c;
  13230. };
  13231. GlobSync$1.prototype._mark = function (p) {
  13232. return common.mark(this, p);
  13233. };
  13234. GlobSync$1.prototype._makeAbs = function (f) {
  13235. return common.makeAbs(this, f);
  13236. };
  13237. // Returns a wrapper function that returns a wrapped callback
  13238. // The wrapper function should do some stuff, and return a
  13239. // presumably different callback function.
  13240. // This makes sure that own properties are retained, so that
  13241. // decorations and such are not lost along the way.
  13242. var wrappy_1 = wrappy;
  13243. function wrappy(fn, cb) {
  13244. if (fn && cb) return wrappy(fn)(cb);
  13245. if (typeof fn !== 'function') throw new TypeError('need wrapper function');
  13246. Object.keys(fn).forEach(function (k) {
  13247. wrapper[k] = fn[k];
  13248. });
  13249. return wrapper;
  13250. function wrapper() {
  13251. var args = new Array(arguments.length);
  13252. for (var i = 0; i < args.length; i++) {
  13253. args[i] = arguments[i];
  13254. }
  13255. var ret = fn.apply(this, args);
  13256. var cb = args[args.length - 1];
  13257. if (typeof ret === 'function' && ret !== cb) {
  13258. Object.keys(cb).forEach(function (k) {
  13259. ret[k] = cb[k];
  13260. });
  13261. }
  13262. return ret;
  13263. }
  13264. }
  13265. var once_1 = wrappy_1(once);
  13266. var strict = wrappy_1(onceStrict);
  13267. once.proto = once(function () {
  13268. Object.defineProperty(Function.prototype, 'once', {
  13269. value: function value() {
  13270. return once(this);
  13271. },
  13272. configurable: true
  13273. });
  13274. Object.defineProperty(Function.prototype, 'onceStrict', {
  13275. value: function value() {
  13276. return onceStrict(this);
  13277. },
  13278. configurable: true
  13279. });
  13280. });
  13281. function once(fn) {
  13282. var f = function f() {
  13283. if (f.called) return f.value;
  13284. f.called = true;
  13285. return f.value = fn.apply(this, arguments);
  13286. };
  13287. f.called = false;
  13288. return f;
  13289. }
  13290. function onceStrict(fn) {
  13291. var f = function f() {
  13292. if (f.called) throw new Error(f.onceError);
  13293. f.called = true;
  13294. return f.value = fn.apply(this, arguments);
  13295. };
  13296. var name = fn.name || 'Function wrapped with `once`';
  13297. f.onceError = name + " shouldn't be called more than once";
  13298. f.called = false;
  13299. return f;
  13300. }
  13301. once_1.strict = strict;
  13302. var reqs = Object.create(null);
  13303. var inflight_1 = wrappy_1(inflight);
  13304. function inflight(key, cb) {
  13305. if (reqs[key]) {
  13306. reqs[key].push(cb);
  13307. return null;
  13308. } else {
  13309. reqs[key] = [cb];
  13310. return makeres(key);
  13311. }
  13312. }
  13313. function makeres(key) {
  13314. return once_1(function RES() {
  13315. var cbs = reqs[key];
  13316. var len = cbs.length;
  13317. var args = slice(arguments); // XXX It's somewhat ambiguous whether a new callback added in this
  13318. // pass should be queued for later execution if something in the
  13319. // list of callbacks throws, or if it should just be discarded.
  13320. // However, it's such an edge case that it hardly matters, and either
  13321. // choice is likely as surprising as the other.
  13322. // As it happens, we do go ahead and schedule it for later execution.
  13323. try {
  13324. for (var i = 0; i < len; i++) {
  13325. cbs[i].apply(null, args);
  13326. }
  13327. } finally {
  13328. if (cbs.length > len) {
  13329. // added more in the interim.
  13330. // de-zalgo, just in case, but don't call again.
  13331. cbs.splice(0, len);
  13332. process.nextTick(function () {
  13333. RES.apply(null, args);
  13334. });
  13335. } else {
  13336. delete reqs[key];
  13337. }
  13338. }
  13339. });
  13340. }
  13341. function slice(args) {
  13342. var length = args.length;
  13343. var array = [];
  13344. for (var i = 0; i < length; i++) {
  13345. array[i] = args[i];
  13346. }
  13347. return array;
  13348. }
  13349. //
  13350. // 1. Get the minimatch set
  13351. // 2. For each pattern in the set, PROCESS(pattern, false)
  13352. // 3. Store matches per-set, then uniq them
  13353. //
  13354. // PROCESS(pattern, inGlobStar)
  13355. // Get the first [n] items from pattern that are all strings
  13356. // Join these together. This is PREFIX.
  13357. // If there is no more remaining, then stat(PREFIX) and
  13358. // add to matches if it succeeds. END.
  13359. //
  13360. // If inGlobStar and PREFIX is symlink and points to dir
  13361. // set ENTRIES = []
  13362. // else readdir(PREFIX) as ENTRIES
  13363. // If fail, END
  13364. //
  13365. // with ENTRIES
  13366. // If pattern[n] is GLOBSTAR
  13367. // // handle the case where the globstar match is empty
  13368. // // by pruning it out, and testing the resulting pattern
  13369. // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
  13370. // // handle other cases.
  13371. // for ENTRY in ENTRIES (not dotfiles)
  13372. // // attach globstar + tail onto the entry
  13373. // // Mark that this entry is a globstar match
  13374. // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
  13375. //
  13376. // else // not globstar
  13377. // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
  13378. // Test ENTRY against pattern[n]
  13379. // If fails, continue
  13380. // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
  13381. //
  13382. // Caveat:
  13383. // Cache all stats and readdirs results to minimize syscall. Since all
  13384. // we ever care about is existence and directory-ness, we can just keep
  13385. // `true` for files, and [children,...] for directories, or `false` for
  13386. // things that don't exist.
  13387. var glob_1 = glob;
  13388. var EE = events.EventEmitter;
  13389. var setopts = common.setopts;
  13390. var ownProp = common.ownProp;
  13391. var childrenIgnored = common.childrenIgnored;
  13392. var isIgnored = common.isIgnored;
  13393. function glob(pattern, options, cb) {
  13394. if (typeof options === 'function') cb = options, options = {};
  13395. if (!options) options = {};
  13396. if (options.sync) {
  13397. if (cb) throw new TypeError('callback provided to sync glob');
  13398. return sync$1(pattern, options);
  13399. }
  13400. return new Glob(pattern, options, cb);
  13401. }
  13402. glob.sync = sync$1;
  13403. var GlobSync = glob.GlobSync = sync$1.GlobSync; // old api surface
  13404. glob.glob = glob;
  13405. function extend(origin, add) {
  13406. if (add === null || typeof add !== 'object') {
  13407. return origin;
  13408. }
  13409. var keys = Object.keys(add);
  13410. var i = keys.length;
  13411. while (i--) {
  13412. origin[keys[i]] = add[keys[i]];
  13413. }
  13414. return origin;
  13415. }
  13416. glob.hasMagic = function (pattern, options_) {
  13417. var options = extend({}, options_);
  13418. options.noprocess = true;
  13419. var g = new Glob(pattern, options);
  13420. var set = g.minimatch.set;
  13421. if (!pattern) return false;
  13422. if (set.length > 1) return true;
  13423. for (var j = 0; j < set[0].length; j++) {
  13424. if (typeof set[0][j] !== 'string') return true;
  13425. }
  13426. return false;
  13427. };
  13428. glob.Glob = Glob;
  13429. inherits(Glob, EE);
  13430. function Glob(pattern, options, cb) {
  13431. if (typeof options === 'function') {
  13432. cb = options;
  13433. options = null;
  13434. }
  13435. if (options && options.sync) {
  13436. if (cb) throw new TypeError('callback provided to sync glob');
  13437. return new GlobSync(pattern, options);
  13438. }
  13439. if (!(this instanceof Glob)) return new Glob(pattern, options, cb);
  13440. setopts(this, pattern, options);
  13441. this._didRealPath = false; // process each pattern in the minimatch set
  13442. var n = this.minimatch.set.length; // The matches are stored as {<filename>: true,...} so that
  13443. // duplicates are automagically pruned.
  13444. // Later, we do an Object.keys() on these.
  13445. // Keep them as a list so we can fill in when nonull is set.
  13446. this.matches = new Array(n);
  13447. if (typeof cb === 'function') {
  13448. cb = once_1(cb);
  13449. this.on('error', cb);
  13450. this.on('end', function (matches) {
  13451. cb(null, matches);
  13452. });
  13453. }
  13454. var self = this;
  13455. this._processing = 0;
  13456. this._emitQueue = [];
  13457. this._processQueue = [];
  13458. this.paused = false;
  13459. if (this.noprocess) return this;
  13460. if (n === 0) return done();
  13461. var sync = true;
  13462. for (var i = 0; i < n; i++) {
  13463. this._process(this.minimatch.set[i], i, false, done);
  13464. }
  13465. sync = false;
  13466. function done() {
  13467. --self._processing;
  13468. if (self._processing <= 0) {
  13469. if (sync) {
  13470. process.nextTick(function () {
  13471. self._finish();
  13472. });
  13473. } else {
  13474. self._finish();
  13475. }
  13476. }
  13477. }
  13478. }
  13479. Glob.prototype._finish = function () {
  13480. assert(this instanceof Glob);
  13481. if (this.aborted) return;
  13482. if (this.realpath && !this._didRealpath) return this._realpath();
  13483. common.finish(this);
  13484. this.emit('end', this.found);
  13485. };
  13486. Glob.prototype._realpath = function () {
  13487. if (this._didRealpath) return;
  13488. this._didRealpath = true;
  13489. var n = this.matches.length;
  13490. if (n === 0) return this._finish();
  13491. var self = this;
  13492. for (var i = 0; i < this.matches.length; i++) {
  13493. this._realpathSet(i, next);
  13494. }
  13495. function next() {
  13496. if (--n === 0) self._finish();
  13497. }
  13498. };
  13499. Glob.prototype._realpathSet = function (index, cb) {
  13500. var matchset = this.matches[index];
  13501. if (!matchset) return cb();
  13502. var found = Object.keys(matchset);
  13503. var self = this;
  13504. var n = found.length;
  13505. if (n === 0) return cb();
  13506. var set = this.matches[index] = Object.create(null);
  13507. found.forEach(function (p, i) {
  13508. // If there's a problem with the stat, then it means that
  13509. // one or more of the links in the realpath couldn't be
  13510. // resolved. just return the abs value in that case.
  13511. p = self._makeAbs(p);
  13512. fs_realpath.realpath(p, self.realpathCache, function (er, real) {
  13513. if (!er) set[real] = true;else if (er.syscall === 'stat') set[p] = true;else self.emit('error', er); // srsly wtf right here
  13514. if (--n === 0) {
  13515. self.matches[index] = set;
  13516. cb();
  13517. }
  13518. });
  13519. });
  13520. };
  13521. Glob.prototype._mark = function (p) {
  13522. return common.mark(this, p);
  13523. };
  13524. Glob.prototype._makeAbs = function (f) {
  13525. return common.makeAbs(this, f);
  13526. };
  13527. Glob.prototype.abort = function () {
  13528. this.aborted = true;
  13529. this.emit('abort');
  13530. };
  13531. Glob.prototype.pause = function () {
  13532. if (!this.paused) {
  13533. this.paused = true;
  13534. this.emit('pause');
  13535. }
  13536. };
  13537. Glob.prototype.resume = function () {
  13538. if (this.paused) {
  13539. this.emit('resume');
  13540. this.paused = false;
  13541. if (this._emitQueue.length) {
  13542. var eq = this._emitQueue.slice(0);
  13543. this._emitQueue.length = 0;
  13544. for (var i = 0; i < eq.length; i++) {
  13545. var e = eq[i];
  13546. this._emitMatch(e[0], e[1]);
  13547. }
  13548. }
  13549. if (this._processQueue.length) {
  13550. var pq = this._processQueue.slice(0);
  13551. this._processQueue.length = 0;
  13552. for (var i = 0; i < pq.length; i++) {
  13553. var p = pq[i];
  13554. this._processing--;
  13555. this._process(p[0], p[1], p[2], p[3]);
  13556. }
  13557. }
  13558. }
  13559. };
  13560. Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
  13561. assert(this instanceof Glob);
  13562. assert(typeof cb === 'function');
  13563. if (this.aborted) return;
  13564. this._processing++;
  13565. if (this.paused) {
  13566. this._processQueue.push([pattern, index, inGlobStar, cb]);
  13567. return;
  13568. } //console.error('PROCESS %d', this._processing, pattern)
  13569. // Get the first [n] parts of pattern that are all strings.
  13570. var n = 0;
  13571. while (typeof pattern[n] === 'string') {
  13572. n++;
  13573. } // now n is the index of the first one that is *not* a string.
  13574. // see if there's anything else
  13575. var prefix;
  13576. switch (n) {
  13577. // if not, then this is rather simple
  13578. case pattern.length:
  13579. this._processSimple(pattern.join('/'), index, cb);
  13580. return;
  13581. case 0:
  13582. // pattern *starts* with some non-trivial item.
  13583. // going to readdir(cwd), but not include the prefix in matches.
  13584. prefix = null;
  13585. break;
  13586. default:
  13587. // pattern has some string bits in the front.
  13588. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  13589. // or 'relative' like '../baz'
  13590. prefix = pattern.slice(0, n).join('/');
  13591. break;
  13592. }
  13593. var remain = pattern.slice(n); // get the list of entries.
  13594. var read;
  13595. if (prefix === null) read = '.';else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  13596. if (!prefix || !pathIsAbsolute(prefix)) prefix = '/' + prefix;
  13597. read = prefix;
  13598. } else read = prefix;
  13599. var abs = this._makeAbs(read); //if ignored, skip _processing
  13600. if (childrenIgnored(this, read)) return cb();
  13601. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  13602. if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb);
  13603. };
  13604. Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  13605. var self = this;
  13606. this._readdir(abs, inGlobStar, function (er, entries) {
  13607. return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
  13608. });
  13609. };
  13610. Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  13611. // if the abs isn't a dir, then nothing can match!
  13612. if (!entries) return cb(); // It will only match dot entries if it starts with a dot, or if
  13613. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  13614. var pn = remain[0];
  13615. var negate = !!this.minimatch.negate;
  13616. var rawGlob = pn._glob;
  13617. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  13618. var matchedEntries = [];
  13619. for (var i = 0; i < entries.length; i++) {
  13620. var e = entries[i];
  13621. if (e.charAt(0) !== '.' || dotOk) {
  13622. var m;
  13623. if (negate && !prefix) {
  13624. m = !e.match(pn);
  13625. } else {
  13626. m = e.match(pn);
  13627. }
  13628. if (m) matchedEntries.push(e);
  13629. }
  13630. } //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
  13631. var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
  13632. if (len === 0) return cb(); // if this is the last remaining pattern bit, then no need for
  13633. // an additional stat *unless* the user has specified mark or
  13634. // stat explicitly. We know they exist, since readdir returned
  13635. // them.
  13636. if (remain.length === 1 && !this.mark && !this.stat) {
  13637. if (!this.matches[index]) this.matches[index] = Object.create(null);
  13638. for (var i = 0; i < len; i++) {
  13639. var e = matchedEntries[i];
  13640. if (prefix) {
  13641. if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
  13642. }
  13643. if (e.charAt(0) === '/' && !this.nomount) {
  13644. e = path.join(this.root, e);
  13645. }
  13646. this._emitMatch(index, e);
  13647. } // This was the last one, and no stats were needed
  13648. return cb();
  13649. } // now test all matched entries as stand-ins for that part
  13650. // of the pattern.
  13651. remain.shift();
  13652. for (var i = 0; i < len; i++) {
  13653. var e = matchedEntries[i];
  13654. var newPattern;
  13655. if (prefix) {
  13656. if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
  13657. }
  13658. this._process([e].concat(remain), index, inGlobStar, cb);
  13659. }
  13660. cb();
  13661. };
  13662. Glob.prototype._emitMatch = function (index, e) {
  13663. if (this.aborted) return;
  13664. if (isIgnored(this, e)) return;
  13665. if (this.paused) {
  13666. this._emitQueue.push([index, e]);
  13667. return;
  13668. }
  13669. var abs = pathIsAbsolute(e) ? e : this._makeAbs(e);
  13670. if (this.mark) e = this._mark(e);
  13671. if (this.absolute) e = abs;
  13672. if (this.matches[index][e]) return;
  13673. if (this.nodir) {
  13674. var c = this.cache[abs];
  13675. if (c === 'DIR' || Array.isArray(c)) return;
  13676. }
  13677. this.matches[index][e] = true;
  13678. var st = this.statCache[abs];
  13679. if (st) this.emit('stat', e, st);
  13680. this.emit('match', e);
  13681. };
  13682. Glob.prototype._readdirInGlobStar = function (abs, cb) {
  13683. if (this.aborted) return; // follow all symlinked directories forever
  13684. // just proceed as if this is a non-globstar situation
  13685. if (this.follow) return this._readdir(abs, false, cb);
  13686. var lstatkey = 'lstat\0' + abs;
  13687. var self = this;
  13688. var lstatcb = inflight_1(lstatkey, lstatcb_);
  13689. if (lstatcb) fs.lstat(abs, lstatcb);
  13690. function lstatcb_(er, lstat) {
  13691. if (er && er.code === 'ENOENT') return cb();
  13692. var isSym = lstat && lstat.isSymbolicLink();
  13693. self.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
  13694. // don't bother doing a readdir in that case.
  13695. if (!isSym && lstat && !lstat.isDirectory()) {
  13696. self.cache[abs] = 'FILE';
  13697. cb();
  13698. } else self._readdir(abs, false, cb);
  13699. }
  13700. };
  13701. Glob.prototype._readdir = function (abs, inGlobStar, cb) {
  13702. if (this.aborted) return;
  13703. cb = inflight_1('readdir\0' + abs + '\0' + inGlobStar, cb);
  13704. if (!cb) return; //console.error('RD %j %j', +inGlobStar, abs)
  13705. if (inGlobStar && !ownProp(this.symlinks, abs)) return this._readdirInGlobStar(abs, cb);
  13706. if (ownProp(this.cache, abs)) {
  13707. var c = this.cache[abs];
  13708. if (!c || c === 'FILE') return cb();
  13709. if (Array.isArray(c)) return cb(null, c);
  13710. }
  13711. var self = this;
  13712. fs.readdir(abs, readdirCb(this, abs, cb));
  13713. };
  13714. function readdirCb(self, abs, cb) {
  13715. return function (er, entries) {
  13716. if (er) self._readdirError(abs, er, cb);else self._readdirEntries(abs, entries, cb);
  13717. };
  13718. }
  13719. Glob.prototype._readdirEntries = function (abs, entries, cb) {
  13720. if (this.aborted) return; // if we haven't asked to stat everything, then just
  13721. // assume that everything in there exists, so we can avoid
  13722. // having to stat it a second time.
  13723. if (!this.mark && !this.stat) {
  13724. for (var i = 0; i < entries.length; i++) {
  13725. var e = entries[i];
  13726. if (abs === '/') e = abs + e;else e = abs + '/' + e;
  13727. this.cache[e] = true;
  13728. }
  13729. }
  13730. this.cache[abs] = entries;
  13731. return cb(null, entries);
  13732. };
  13733. Glob.prototype._readdirError = function (f, er, cb) {
  13734. if (this.aborted) return; // handle errors, and cache the information
  13735. switch (er.code) {
  13736. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  13737. case 'ENOTDIR':
  13738. // totally normal. means it *does* exist.
  13739. var abs = this._makeAbs(f);
  13740. this.cache[abs] = 'FILE';
  13741. if (abs === this.cwdAbs) {
  13742. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  13743. error.path = this.cwd;
  13744. error.code = er.code;
  13745. this.emit('error', error);
  13746. this.abort();
  13747. }
  13748. break;
  13749. case 'ENOENT': // not terribly unusual
  13750. case 'ELOOP':
  13751. case 'ENAMETOOLONG':
  13752. case 'UNKNOWN':
  13753. this.cache[this._makeAbs(f)] = false;
  13754. break;
  13755. default:
  13756. // some unusual error. Treat as failure.
  13757. this.cache[this._makeAbs(f)] = false;
  13758. if (this.strict) {
  13759. this.emit('error', er); // If the error is handled, then we abort
  13760. // if not, we threw out of here
  13761. this.abort();
  13762. }
  13763. if (!this.silent) console.error('glob error', er);
  13764. break;
  13765. }
  13766. return cb();
  13767. };
  13768. Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  13769. var self = this;
  13770. this._readdir(abs, inGlobStar, function (er, entries) {
  13771. self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
  13772. });
  13773. };
  13774. Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  13775. //console.error('pgs2', prefix, remain[0], entries)
  13776. // no entries means not a dir, so it can never have matches
  13777. // foo.txt/** doesn't match foo.txt
  13778. if (!entries) return cb(); // test without the globstar, and with every child both below
  13779. // and replacing the globstar.
  13780. var remainWithoutGlobStar = remain.slice(1);
  13781. var gspref = prefix ? [prefix] : [];
  13782. var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
  13783. this._process(noGlobStar, index, false, cb);
  13784. var isSym = this.symlinks[abs];
  13785. var len = entries.length; // If it's a symlink, and we're in a globstar, then stop
  13786. if (isSym && inGlobStar) return cb();
  13787. for (var i = 0; i < len; i++) {
  13788. var e = entries[i];
  13789. if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
  13790. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  13791. this._process(instead, index, true, cb);
  13792. var below = gspref.concat(entries[i], remain);
  13793. this._process(below, index, true, cb);
  13794. }
  13795. cb();
  13796. };
  13797. Glob.prototype._processSimple = function (prefix, index, cb) {
  13798. // XXX review this. Shouldn't it be doing the mounting etc
  13799. // before doing stat? kinda weird?
  13800. var self = this;
  13801. this._stat(prefix, function (er, exists) {
  13802. self._processSimple2(prefix, index, er, exists, cb);
  13803. });
  13804. };
  13805. Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
  13806. //console.error('ps2', prefix, exists)
  13807. if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
  13808. if (!exists) return cb();
  13809. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  13810. var trail = /[\/\\]$/.test(prefix);
  13811. if (prefix.charAt(0) === '/') {
  13812. prefix = path.join(this.root, prefix);
  13813. } else {
  13814. prefix = path.resolve(this.root, prefix);
  13815. if (trail) prefix += '/';
  13816. }
  13817. }
  13818. if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
  13819. this._emitMatch(index, prefix);
  13820. cb();
  13821. }; // Returns either 'DIR', 'FILE', or false
  13822. Glob.prototype._stat = function (f, cb) {
  13823. var abs = this._makeAbs(f);
  13824. var needDir = f.slice(-1) === '/';
  13825. if (f.length > this.maxLength) return cb();
  13826. if (!this.stat && ownProp(this.cache, abs)) {
  13827. var c = this.cache[abs];
  13828. if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
  13829. if (!needDir || c === 'DIR') return cb(null, c);
  13830. if (needDir && c === 'FILE') return cb(); // otherwise we have to stat, because maybe c=true
  13831. // if we know it exists, but not what it is.
  13832. }
  13833. var exists;
  13834. var stat = this.statCache[abs];
  13835. if (stat !== undefined) {
  13836. if (stat === false) return cb(null, stat);else {
  13837. var type = stat.isDirectory() ? 'DIR' : 'FILE';
  13838. if (needDir && type === 'FILE') return cb();else return cb(null, type, stat);
  13839. }
  13840. }
  13841. var self = this;
  13842. var statcb = inflight_1('stat\0' + abs, lstatcb_);
  13843. if (statcb) fs.lstat(abs, statcb);
  13844. function lstatcb_(er, lstat) {
  13845. if (lstat && lstat.isSymbolicLink()) {
  13846. // If it's a symlink, then treat it as the target, unless
  13847. // the target does not exist, then treat it as a file.
  13848. return fs.stat(abs, function (er, stat) {
  13849. if (er) self._stat2(f, abs, null, lstat, cb);else self._stat2(f, abs, er, stat, cb);
  13850. });
  13851. } else {
  13852. self._stat2(f, abs, er, lstat, cb);
  13853. }
  13854. }
  13855. };
  13856. Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
  13857. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  13858. this.statCache[abs] = false;
  13859. return cb();
  13860. }
  13861. var needDir = f.slice(-1) === '/';
  13862. this.statCache[abs] = stat;
  13863. if (abs.slice(-1) === '/' && stat && !stat.isDirectory()) return cb(null, false, stat);
  13864. var c = true;
  13865. if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
  13866. this.cache[abs] = this.cache[abs] || c;
  13867. if (needDir && c === 'FILE') return cb();
  13868. return cb(null, c, stat);
  13869. };
  13870. var pify_1 = createCommonjsModule(function (module) {
  13871. 'use strict';
  13872. var processFn = function processFn(fn, P, opts) {
  13873. return function () {
  13874. var that = this;
  13875. var args = new Array(arguments.length);
  13876. for (var i = 0; i < arguments.length; i++) {
  13877. args[i] = arguments[i];
  13878. }
  13879. return new P(function (resolve, reject) {
  13880. args.push(function (err, result) {
  13881. if (err) {
  13882. reject(err);
  13883. } else if (opts.multiArgs) {
  13884. var results = new Array(arguments.length - 1);
  13885. for (var i = 1; i < arguments.length; i++) {
  13886. results[i - 1] = arguments[i];
  13887. }
  13888. resolve(results);
  13889. } else {
  13890. resolve(result);
  13891. }
  13892. });
  13893. fn.apply(that, args);
  13894. });
  13895. };
  13896. };
  13897. var pify = module.exports = function (obj, P, opts) {
  13898. if (typeof P !== 'function') {
  13899. opts = P;
  13900. P = Promise;
  13901. }
  13902. opts = opts || {};
  13903. opts.exclude = opts.exclude || [/.+Sync$/];
  13904. var filter = function filter(key) {
  13905. var match = function match(pattern) {
  13906. return typeof pattern === 'string' ? key === pattern : pattern.test(key);
  13907. };
  13908. return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
  13909. };
  13910. var ret = typeof obj === 'function' ? function () {
  13911. if (opts.excludeMain) {
  13912. return obj.apply(this, arguments);
  13913. }
  13914. return processFn(obj, P, opts).apply(this, arguments);
  13915. } : {};
  13916. return Object.keys(obj).reduce(function (ret, key) {
  13917. var x = obj[key];
  13918. ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x;
  13919. return ret;
  13920. }, ret);
  13921. };
  13922. pify.all = pify;
  13923. });
  13924. var globP = pify_1(glob_1, pinkiePromise).bind(glob_1);
  13925. function isNegative(pattern) {
  13926. return pattern[0] === '!';
  13927. }
  13928. function isString(value) {
  13929. return typeof value === 'string';
  13930. }
  13931. function assertPatternsInput(patterns) {
  13932. if (!patterns.every(isString)) {
  13933. throw new TypeError('patterns must be a string or an array of strings');
  13934. }
  13935. }
  13936. function generateGlobTasks(patterns, opts) {
  13937. patterns = [].concat(patterns);
  13938. assertPatternsInput(patterns);
  13939. var globTasks = [];
  13940. opts = objectAssign({
  13941. cache: Object.create(null),
  13942. statCache: Object.create(null),
  13943. realpathCache: Object.create(null),
  13944. symlinks: Object.create(null),
  13945. ignore: []
  13946. }, opts);
  13947. patterns.forEach(function (pattern, i) {
  13948. if (isNegative(pattern)) {
  13949. return;
  13950. }
  13951. var ignore = patterns.slice(i).filter(isNegative).map(function (pattern) {
  13952. return pattern.slice(1);
  13953. });
  13954. globTasks.push({
  13955. pattern: pattern,
  13956. opts: objectAssign({}, opts, {
  13957. ignore: opts.ignore.concat(ignore)
  13958. })
  13959. });
  13960. });
  13961. return globTasks;
  13962. }
  13963. var globby = function globby(patterns, opts) {
  13964. var globTasks;
  13965. try {
  13966. globTasks = generateGlobTasks(patterns, opts);
  13967. } catch (err) {
  13968. return pinkiePromise.reject(err);
  13969. }
  13970. return pinkiePromise.all(globTasks.map(function (task) {
  13971. return globP(task.pattern, task.opts);
  13972. })).then(function (paths) {
  13973. return arrayUnion.apply(null, paths);
  13974. });
  13975. };
  13976. var sync = function sync(patterns, opts) {
  13977. var globTasks = generateGlobTasks(patterns, opts);
  13978. return globTasks.reduce(function (matches, task) {
  13979. return arrayUnion(matches, glob_1.sync(task.pattern, task.opts));
  13980. }, []);
  13981. };
  13982. var generateGlobTasks_1 = generateGlobTasks;
  13983. var hasMagic = function hasMagic(patterns, opts) {
  13984. return [].concat(patterns).some(function (pattern) {
  13985. return glob_1.hasMagic(pattern, opts);
  13986. });
  13987. };
  13988. globby.sync = sync;
  13989. globby.generateGlobTasks = generateGlobTasks_1;
  13990. globby.hasMagic = hasMagic;
  13991. var assert$2 = true;
  13992. var buffer_ieee754 = "< 0.9.7";
  13993. var buffer = true;
  13994. var child_process = true;
  13995. var cluster = true;
  13996. var console$1 = true;
  13997. var constants = true;
  13998. var crypto = true;
  13999. var _debugger = "< 8";
  14000. var dgram = true;
  14001. var dns = true;
  14002. var domain = true;
  14003. var events$1 = true;
  14004. var freelist = "< 6";
  14005. var fs$2 = true;
  14006. var http = true;
  14007. var http2 = ">= 8.8";
  14008. var https = true;
  14009. var _http_server = ">= 0.11";
  14010. var _linklist = "< 8";
  14011. var module$1 = true;
  14012. var net = true;
  14013. var os$1 = true;
  14014. var path$3 = true;
  14015. var perf_hooks = ">= 8.5";
  14016. var process$1 = ">= 1";
  14017. var punycode = true;
  14018. var querystring = true;
  14019. var readline = true;
  14020. var repl = true;
  14021. var stream = true;
  14022. var string_decoder = true;
  14023. var sys = true;
  14024. var timers = true;
  14025. var tls = true;
  14026. var tty = true;
  14027. var url = true;
  14028. var util$4 = true;
  14029. var v8 = ">= 1";
  14030. var vm = true;
  14031. var zlib = true;
  14032. var core$3 = {
  14033. assert: assert$2,
  14034. buffer_ieee754: buffer_ieee754,
  14035. buffer: buffer,
  14036. child_process: child_process,
  14037. cluster: cluster,
  14038. console: console$1,
  14039. constants: constants,
  14040. crypto: crypto,
  14041. _debugger: _debugger,
  14042. dgram: dgram,
  14043. dns: dns,
  14044. domain: domain,
  14045. events: events$1,
  14046. freelist: freelist,
  14047. fs: fs$2,
  14048. http: http,
  14049. http2: http2,
  14050. https: https,
  14051. _http_server: _http_server,
  14052. _linklist: _linklist,
  14053. module: module$1,
  14054. net: net,
  14055. os: os$1,
  14056. path: path$3,
  14057. perf_hooks: perf_hooks,
  14058. process: process$1,
  14059. punycode: punycode,
  14060. querystring: querystring,
  14061. readline: readline,
  14062. repl: repl,
  14063. stream: stream,
  14064. string_decoder: string_decoder,
  14065. sys: sys,
  14066. timers: timers,
  14067. tls: tls,
  14068. tty: tty,
  14069. url: url,
  14070. util: util$4,
  14071. v8: v8,
  14072. vm: vm,
  14073. zlib: zlib
  14074. };
  14075. var core$4 = Object.freeze({
  14076. assert: assert$2,
  14077. buffer_ieee754: buffer_ieee754,
  14078. buffer: buffer,
  14079. child_process: child_process,
  14080. cluster: cluster,
  14081. console: console$1,
  14082. constants: constants,
  14083. crypto: crypto,
  14084. _debugger: _debugger,
  14085. dgram: dgram,
  14086. dns: dns,
  14087. domain: domain,
  14088. events: events$1,
  14089. freelist: freelist,
  14090. fs: fs$2,
  14091. http: http,
  14092. http2: http2,
  14093. https: https,
  14094. _http_server: _http_server,
  14095. _linklist: _linklist,
  14096. module: module$1,
  14097. net: net,
  14098. os: os$1,
  14099. path: path$3,
  14100. perf_hooks: perf_hooks,
  14101. process: process$1,
  14102. punycode: punycode,
  14103. querystring: querystring,
  14104. readline: readline,
  14105. repl: repl,
  14106. stream: stream,
  14107. string_decoder: string_decoder,
  14108. sys: sys,
  14109. timers: timers,
  14110. tls: tls,
  14111. tty: tty,
  14112. url: url,
  14113. util: util$4,
  14114. v8: v8,
  14115. vm: vm,
  14116. zlib: zlib,
  14117. default: core$3
  14118. });
  14119. var data = ( core$4 && core$3 ) || core$4;
  14120. var current = process.versions && process.versions.node && process.versions.node.split('.') || [];
  14121. function versionIncluded(specifier) {
  14122. if (specifier === true) {
  14123. return true;
  14124. }
  14125. var parts = specifier.split(' ');
  14126. var op = parts[0];
  14127. var versionParts = parts[1].split('.');
  14128. for (var i = 0; i < 3; ++i) {
  14129. var cur = Number(current[i] || 0);
  14130. var ver = Number(versionParts[i] || 0);
  14131. if (cur === ver) {
  14132. continue; // eslint-disable-line no-restricted-syntax, no-continue
  14133. }
  14134. if (op === '<') {
  14135. return cur < ver;
  14136. } else if (op === '>=') {
  14137. return cur >= ver;
  14138. } else {
  14139. return false;
  14140. }
  14141. }
  14142. return false;
  14143. }
  14144. var core$2 = {};
  14145. for (var mod in data) {
  14146. // eslint-disable-line no-restricted-syntax
  14147. if (Object.prototype.hasOwnProperty.call(data, mod)) {
  14148. core$2[mod] = versionIncluded(data[mod]);
  14149. }
  14150. }
  14151. var core_1 = core$2;
  14152. var caller = function caller() {
  14153. // see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
  14154. var origPrepareStackTrace = Error.prepareStackTrace;
  14155. Error.prepareStackTrace = function (_, stack) {
  14156. return stack;
  14157. };
  14158. var stack = new Error().stack;
  14159. Error.prepareStackTrace = origPrepareStackTrace;
  14160. return stack[2].getFileName();
  14161. };
  14162. var pathParse = createCommonjsModule(function (module) {
  14163. 'use strict';
  14164. var isWindows = process.platform === 'win32'; // Regex to split a windows path into three parts: [*, device, slash,
  14165. // tail] windows-only
  14166. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/; // Regex to split the tail part of the above into [*, dir, basename, ext]
  14167. var splitTailRe = /^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
  14168. var win32 = {}; // Function to split a filename into [root, dir, basename, ext]
  14169. function win32SplitPath(filename) {
  14170. // Separate device+slash from tail
  14171. var result = splitDeviceRe.exec(filename),
  14172. device = (result[1] || '') + (result[2] || ''),
  14173. tail = result[3] || ''; // Split the tail into dir, basename and extension
  14174. var result2 = splitTailRe.exec(tail),
  14175. dir = result2[1],
  14176. basename = result2[2],
  14177. ext = result2[3];
  14178. return [device, dir, basename, ext];
  14179. }
  14180. win32.parse = function (pathString) {
  14181. if (typeof pathString !== 'string') {
  14182. throw new TypeError("Parameter 'pathString' must be a string, not " + typeof pathString);
  14183. }
  14184. var allParts = win32SplitPath(pathString);
  14185. if (!allParts || allParts.length !== 4) {
  14186. throw new TypeError("Invalid path '" + pathString + "'");
  14187. }
  14188. return {
  14189. root: allParts[0],
  14190. dir: allParts[0] + allParts[1].slice(0, -1),
  14191. base: allParts[2],
  14192. ext: allParts[3],
  14193. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  14194. };
  14195. }; // Split a filename into [root, dir, basename, ext], unix version
  14196. // 'root' is just a slash, or nothing.
  14197. var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  14198. var posix = {};
  14199. function posixSplitPath(filename) {
  14200. return splitPathRe.exec(filename).slice(1);
  14201. }
  14202. posix.parse = function (pathString) {
  14203. if (typeof pathString !== 'string') {
  14204. throw new TypeError("Parameter 'pathString' must be a string, not " + typeof pathString);
  14205. }
  14206. var allParts = posixSplitPath(pathString);
  14207. if (!allParts || allParts.length !== 4) {
  14208. throw new TypeError("Invalid path '" + pathString + "'");
  14209. }
  14210. allParts[1] = allParts[1] || '';
  14211. allParts[2] = allParts[2] || '';
  14212. allParts[3] = allParts[3] || '';
  14213. return {
  14214. root: allParts[0],
  14215. dir: allParts[0] + allParts[1].slice(0, -1),
  14216. base: allParts[2],
  14217. ext: allParts[3],
  14218. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  14219. };
  14220. };
  14221. if (isWindows) module.exports = win32.parse;else
  14222. /* posix */
  14223. module.exports = posix.parse;
  14224. module.exports.posix = posix.parse;
  14225. module.exports.win32 = win32.parse;
  14226. });
  14227. var parse$4 = path.parse || pathParse;
  14228. var nodeModulesPaths = function nodeModulesPaths(start, opts) {
  14229. var modules = opts && opts.moduleDirectory ? [].concat(opts.moduleDirectory) : ['node_modules']; // ensure that `start` is an absolute path at this point,
  14230. // resolving against the process' current working directory
  14231. var absoluteStart = path.resolve(start);
  14232. if (opts && opts.preserveSymlinks === false) {
  14233. try {
  14234. absoluteStart = fs.realpathSync(absoluteStart);
  14235. } catch (err) {
  14236. if (err.code !== 'ENOENT') {
  14237. throw err;
  14238. }
  14239. }
  14240. }
  14241. var prefix = '/';
  14242. if (/^([A-Za-z]:)/.test(absoluteStart)) {
  14243. prefix = '';
  14244. } else if (/^\\\\/.test(absoluteStart)) {
  14245. prefix = '\\\\';
  14246. }
  14247. var paths = [absoluteStart];
  14248. var parsed = parse$4(absoluteStart);
  14249. while (parsed.dir !== paths[paths.length - 1]) {
  14250. paths.push(parsed.dir);
  14251. parsed = parse$4(parsed.dir);
  14252. }
  14253. var dirs = paths.reduce(function (dirs, aPath) {
  14254. return dirs.concat(modules.map(function (moduleDir) {
  14255. return path.join(prefix, aPath, moduleDir);
  14256. }));
  14257. }, []);
  14258. return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
  14259. };
  14260. var async = function resolve(x, options, callback) {
  14261. var cb = callback;
  14262. var opts = options || {};
  14263. if (typeof opts === 'function') {
  14264. cb = opts;
  14265. opts = {};
  14266. }
  14267. if (typeof x !== 'string') {
  14268. var err = new TypeError('Path must be a string.');
  14269. return process.nextTick(function () {
  14270. cb(err);
  14271. });
  14272. }
  14273. var isFile = opts.isFile || function (file, cb) {
  14274. fs.stat(file, function (err, stat) {
  14275. if (!err) {
  14276. return cb(null, stat.isFile() || stat.isFIFO());
  14277. }
  14278. if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
  14279. return cb(err);
  14280. });
  14281. };
  14282. var readFile = opts.readFile || fs.readFile;
  14283. var extensions = opts.extensions || ['.js'];
  14284. var y = opts.basedir || path.dirname(caller());
  14285. opts.paths = opts.paths || [];
  14286. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  14287. var res = path.resolve(y, x);
  14288. if (x === '..' || x.slice(-1) === '/') res += '/';
  14289. if (/\/$/.test(x) && res === y) {
  14290. loadAsDirectory(res, opts.package, onfile);
  14291. } else loadAsFile(res, opts.package, onfile);
  14292. } else loadNodeModules(x, y, function (err, n, pkg) {
  14293. if (err) cb(err);else if (n) cb(null, n, pkg);else if (core_1[x]) return cb(null, x);else {
  14294. var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
  14295. moduleError.code = 'MODULE_NOT_FOUND';
  14296. cb(moduleError);
  14297. }
  14298. });
  14299. function onfile(err, m, pkg) {
  14300. if (err) cb(err);else if (m) cb(null, m, pkg);else loadAsDirectory(res, function (err, d, pkg) {
  14301. if (err) cb(err);else if (d) cb(null, d, pkg);else {
  14302. var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
  14303. moduleError.code = 'MODULE_NOT_FOUND';
  14304. cb(moduleError);
  14305. }
  14306. });
  14307. }
  14308. function loadAsFile(x, thePackage, callback) {
  14309. var loadAsFilePackage = thePackage;
  14310. var cb = callback;
  14311. if (typeof loadAsFilePackage === 'function') {
  14312. cb = loadAsFilePackage;
  14313. loadAsFilePackage = undefined;
  14314. }
  14315. var exts = [''].concat(extensions);
  14316. load(exts, x, loadAsFilePackage);
  14317. function load(exts, x, loadPackage) {
  14318. if (exts.length === 0) return cb(null, undefined, loadPackage);
  14319. var file = x + exts[0];
  14320. var pkg = loadPackage;
  14321. if (pkg) onpkg(null, pkg);else loadpkg(path.dirname(file), onpkg);
  14322. function onpkg(err, pkg_, dir) {
  14323. pkg = pkg_;
  14324. if (err) return cb(err);
  14325. if (dir && pkg && opts.pathFilter) {
  14326. var rfile = path.relative(dir, file);
  14327. var rel = rfile.slice(0, rfile.length - exts[0].length);
  14328. var r = opts.pathFilter(pkg, x, rel);
  14329. if (r) return load([''].concat(extensions.slice()), path.resolve(dir, r), pkg);
  14330. }
  14331. isFile(file, onex);
  14332. }
  14333. function onex(err, ex) {
  14334. if (err) return cb(err);
  14335. if (ex) return cb(null, file, pkg);
  14336. load(exts.slice(1), x, pkg);
  14337. }
  14338. }
  14339. }
  14340. function loadpkg(dir, cb) {
  14341. if (dir === '' || dir === '/') return cb(null);
  14342. if (process.platform === 'win32' && /^\w:[/\\]*$/.test(dir)) {
  14343. return cb(null);
  14344. }
  14345. if (/[/\\]node_modules[/\\]*$/.test(dir)) return cb(null);
  14346. var pkgfile = path.join(dir, 'package.json');
  14347. isFile(pkgfile, function (err, ex) {
  14348. // on err, ex is false
  14349. if (!ex) return loadpkg(path.dirname(dir), cb);
  14350. readFile(pkgfile, function (err, body) {
  14351. if (err) cb(err);
  14352. try {
  14353. var pkg = JSON.parse(body);
  14354. } catch (jsonErr) {}
  14355. if (pkg && opts.packageFilter) {
  14356. pkg = opts.packageFilter(pkg, pkgfile);
  14357. }
  14358. cb(null, pkg, dir);
  14359. });
  14360. });
  14361. }
  14362. function loadAsDirectory(x, loadAsDirectoryPackage, callback) {
  14363. var cb = callback;
  14364. var fpkg = loadAsDirectoryPackage;
  14365. if (typeof fpkg === 'function') {
  14366. cb = fpkg;
  14367. fpkg = opts.package;
  14368. }
  14369. var pkgfile = path.join(x, 'package.json');
  14370. isFile(pkgfile, function (err, ex) {
  14371. if (err) return cb(err);
  14372. if (!ex) return loadAsFile(path.join(x, 'index'), fpkg, cb);
  14373. readFile(pkgfile, function (err, body) {
  14374. if (err) return cb(err);
  14375. try {
  14376. var pkg = JSON.parse(body);
  14377. } catch (jsonErr) {}
  14378. if (opts.packageFilter) {
  14379. pkg = opts.packageFilter(pkg, pkgfile);
  14380. }
  14381. if (pkg.main) {
  14382. if (pkg.main === '.' || pkg.main === './') {
  14383. pkg.main = 'index';
  14384. }
  14385. loadAsFile(path.resolve(x, pkg.main), pkg, function (err, m, pkg) {
  14386. if (err) return cb(err);
  14387. if (m) return cb(null, m, pkg);
  14388. if (!pkg) return loadAsFile(path.join(x, 'index'), pkg, cb);
  14389. var dir = path.resolve(x, pkg.main);
  14390. loadAsDirectory(dir, pkg, function (err, n, pkg) {
  14391. if (err) return cb(err);
  14392. if (n) return cb(null, n, pkg);
  14393. loadAsFile(path.join(x, 'index'), pkg, cb);
  14394. });
  14395. });
  14396. return;
  14397. }
  14398. loadAsFile(path.join(x, '/index'), pkg, cb);
  14399. });
  14400. });
  14401. }
  14402. function processDirs(cb, dirs) {
  14403. if (dirs.length === 0) return cb(null, undefined);
  14404. var dir = dirs[0];
  14405. var file = path.join(dir, x);
  14406. loadAsFile(file, undefined, onfile);
  14407. function onfile(err, m, pkg) {
  14408. if (err) return cb(err);
  14409. if (m) return cb(null, m, pkg);
  14410. loadAsDirectory(path.join(dir, x), undefined, ondir);
  14411. }
  14412. function ondir(err, n, pkg) {
  14413. if (err) return cb(err);
  14414. if (n) return cb(null, n, pkg);
  14415. processDirs(cb, dirs.slice(1));
  14416. }
  14417. }
  14418. function loadNodeModules(x, start, cb) {
  14419. processDirs(cb, nodeModulesPaths(start, opts));
  14420. }
  14421. };
  14422. var sync$3 = function sync(x, options) {
  14423. if (typeof x !== 'string') {
  14424. throw new TypeError('Path must be a string.');
  14425. }
  14426. var opts = options || {};
  14427. var isFile = opts.isFile || function (file) {
  14428. try {
  14429. var stat = fs.statSync(file);
  14430. } catch (e) {
  14431. if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
  14432. throw e;
  14433. }
  14434. return stat.isFile() || stat.isFIFO();
  14435. };
  14436. var readFileSync = opts.readFileSync || fs.readFileSync;
  14437. var extensions = opts.extensions || ['.js'];
  14438. var y = opts.basedir || path.dirname(caller());
  14439. opts.paths = opts.paths || [];
  14440. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  14441. var res = path.resolve(y, x);
  14442. if (x === '..' || x.slice(-1) === '/') res += '/';
  14443. var m = loadAsFileSync(res) || loadAsDirectorySync(res);
  14444. if (m) return m;
  14445. } else {
  14446. var n = loadNodeModulesSync(x, y);
  14447. if (n) return n;
  14448. }
  14449. if (core_1[x]) return x;
  14450. var err = new Error("Cannot find module '" + x + "' from '" + y + "'");
  14451. err.code = 'MODULE_NOT_FOUND';
  14452. throw err;
  14453. function loadAsFileSync(x) {
  14454. if (isFile(x)) {
  14455. return x;
  14456. }
  14457. for (var i = 0; i < extensions.length; i++) {
  14458. var file = x + extensions[i];
  14459. if (isFile(file)) {
  14460. return file;
  14461. }
  14462. }
  14463. }
  14464. function loadAsDirectorySync(x) {
  14465. var pkgfile = path.join(x, '/package.json');
  14466. if (isFile(pkgfile)) {
  14467. try {
  14468. var body = readFileSync(pkgfile, 'UTF8');
  14469. var pkg = JSON.parse(body);
  14470. if (opts.packageFilter) {
  14471. pkg = opts.packageFilter(pkg, x);
  14472. }
  14473. if (pkg.main) {
  14474. if (pkg.main === '.' || pkg.main === './') {
  14475. pkg.main = 'index';
  14476. }
  14477. var m = loadAsFileSync(path.resolve(x, pkg.main));
  14478. if (m) return m;
  14479. var n = loadAsDirectorySync(path.resolve(x, pkg.main));
  14480. if (n) return n;
  14481. }
  14482. } catch (e) {}
  14483. }
  14484. return loadAsFileSync(path.join(x, '/index'));
  14485. }
  14486. function loadNodeModulesSync(x, start) {
  14487. var dirs = nodeModulesPaths(start, opts);
  14488. for (var i = 0; i < dirs.length; i++) {
  14489. var dir = dirs[i];
  14490. var m = loadAsFileSync(path.join(dir, '/', x));
  14491. if (m) return m;
  14492. var n = loadAsDirectorySync(path.join(dir, '/', x));
  14493. if (n) return n;
  14494. }
  14495. }
  14496. };
  14497. var resolve$1 = createCommonjsModule(function (module, exports) {
  14498. async.core = core_1;
  14499. async.isCore = function isCore(x) {
  14500. return core_1[x];
  14501. };
  14502. async.sync = sync$3;
  14503. exports = async;
  14504. module.exports = async;
  14505. });
  14506. var _require$$0$builders$1 = doc.builders;
  14507. var indent$3 = _require$$0$builders$1.indent;
  14508. var join$3 = _require$$0$builders$1.join;
  14509. var hardline$4 = _require$$0$builders$1.hardline;
  14510. var softline$2 = _require$$0$builders$1.softline;
  14511. var literalline$2 = _require$$0$builders$1.literalline;
  14512. var concat$5 = _require$$0$builders$1.concat;
  14513. var dedentToRoot$1 = _require$$0$builders$1.dedentToRoot;
  14514. var _require$$0$utils = doc.utils;
  14515. var mapDoc$2 = _require$$0$utils.mapDoc;
  14516. var stripTrailingHardline$1 = _require$$0$utils.stripTrailingHardline;
  14517. function embed(path$$1, print, textToDoc
  14518. /*, options */
  14519. ) {
  14520. var node = path$$1.getValue();
  14521. var parent = path$$1.getParentNode();
  14522. var parentParent = path$$1.getParentNode(1);
  14523. switch (node.type) {
  14524. case "TemplateLiteral":
  14525. {
  14526. var isCss = [isStyledJsx, isStyledComponents, isCssProp, isAngularComponentStyles].some(function (isIt) {
  14527. return isIt(path$$1);
  14528. });
  14529. if (isCss) {
  14530. // Get full template literal with expressions replaced by placeholders
  14531. var rawQuasis = node.quasis.map(function (q) {
  14532. return q.value.raw;
  14533. });
  14534. var placeholderID = 0;
  14535. var text = rawQuasis.reduce(function (prevVal, currVal, idx) {
  14536. return idx == 0 ? currVal : prevVal + "@prettier-placeholder-" + placeholderID++ + "-id" + currVal;
  14537. }, "");
  14538. var doc$$2 = textToDoc(text, {
  14539. parser: "css"
  14540. });
  14541. return transformCssDoc(doc$$2, path$$1, print);
  14542. }
  14543. /*
  14544. * react-relay and graphql-tag
  14545. * graphql`...`
  14546. * graphql.experimental`...`
  14547. * gql`...`
  14548. *
  14549. * This intentionally excludes Relay Classic tags, as Prettier does not
  14550. * support Relay Classic formatting.
  14551. */
  14552. if (isGraphQL(path$$1)) {
  14553. var expressionDocs = node.expressions ? path$$1.map(print, "expressions") : [];
  14554. var numQuasis = node.quasis.length;
  14555. if (numQuasis === 1 && node.quasis[0].value.raw.trim() === "") {
  14556. return "``";
  14557. }
  14558. var parts = [];
  14559. for (var i = 0; i < numQuasis; i++) {
  14560. var templateElement = node.quasis[i];
  14561. var isFirst = i === 0;
  14562. var isLast = i === numQuasis - 1;
  14563. var _text = templateElement.value.cooked; // Bail out if any of the quasis have an invalid escape sequence
  14564. // (which would make the `cooked` value be `null` or `undefined`)
  14565. if (typeof _text !== "string") {
  14566. return null;
  14567. }
  14568. var lines = _text.split("\n");
  14569. var numLines = lines.length;
  14570. var expressionDoc = expressionDocs[i];
  14571. var startsWithBlankLine = numLines > 2 && lines[0].trim() === "" && lines[1].trim() === "";
  14572. var endsWithBlankLine = numLines > 2 && lines[numLines - 1].trim() === "" && lines[numLines - 2].trim() === "";
  14573. var commentsAndWhitespaceOnly = lines.every(function (line) {
  14574. return /^\s*(?:#[^\r\n]*)?$/.test(line);
  14575. }); // Bail out if an interpolation occurs within a comment.
  14576. if (!isLast && /#[^\r\n]*$/.test(lines[numLines - 1])) {
  14577. return null;
  14578. }
  14579. var _doc = null;
  14580. if (commentsAndWhitespaceOnly) {
  14581. _doc = printGraphqlComments(lines);
  14582. } else {
  14583. _doc = stripTrailingHardline$1(textToDoc(_text, {
  14584. parser: "graphql"
  14585. }));
  14586. }
  14587. if (_doc) {
  14588. _doc = escapeBackticks(_doc);
  14589. if (!isFirst && startsWithBlankLine) {
  14590. parts.push("");
  14591. }
  14592. parts.push(_doc);
  14593. if (!isLast && endsWithBlankLine) {
  14594. parts.push("");
  14595. }
  14596. } else if (!isFirst && !isLast && startsWithBlankLine) {
  14597. parts.push("");
  14598. }
  14599. if (expressionDoc) {
  14600. parts.push(concat$5(["${", expressionDoc, "}"]));
  14601. }
  14602. }
  14603. return concat$5(["`", indent$3(concat$5([hardline$4, join$3(hardline$4, parts)])), hardline$4, "`"]);
  14604. }
  14605. break;
  14606. }
  14607. case "TemplateElement":
  14608. {
  14609. /**
  14610. * md`...`
  14611. * markdown`...`
  14612. */
  14613. if (parentParent && parentParent.type === "TaggedTemplateExpression" && parent.quasis.length === 1 && parentParent.tag.type === "Identifier" && (parentParent.tag.name === "md" || parentParent.tag.name === "markdown")) {
  14614. var _text2 = parent.quasis[0].value.raw.replace(/((?:\\\\)*)\\`/g, function (_, backslashes) {
  14615. return "\\".repeat(backslashes.length / 2) + "`";
  14616. });
  14617. var indentation = getIndentation(_text2);
  14618. var hasIndent = indentation !== "";
  14619. return concat$5([hasIndent ? indent$3(concat$5([softline$2, printMarkdown(_text2.replace(new RegExp(`^${indentation}`, "gm"), ""))])) : concat$5([literalline$2, dedentToRoot$1(printMarkdown(_text2))]), softline$2]);
  14620. }
  14621. break;
  14622. }
  14623. }
  14624. function printMarkdown(text) {
  14625. var doc$$2 = textToDoc(text, {
  14626. parser: "markdown",
  14627. __inJsTemplate: true
  14628. });
  14629. return stripTrailingHardline$1(escapeBackticks(doc$$2));
  14630. }
  14631. }
  14632. function isPropertyWithinAngularComponentDecorator(path$$1, parentIndexToCheck) {
  14633. var parent = path$$1.getParentNode(parentIndexToCheck);
  14634. return !!(parent && parent.type === "Decorator" && parent.expression && parent.expression.type === "CallExpression" && parent.expression.callee && parent.expression.callee.name === "Component");
  14635. }
  14636. function getIndentation(str) {
  14637. var firstMatchedIndent = str.match(/^([^\S\n]*)\S/m);
  14638. return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
  14639. }
  14640. function escapeBackticks(doc$$2) {
  14641. return mapDoc$2(doc$$2, function (currentDoc) {
  14642. if (!currentDoc.parts) {
  14643. return currentDoc;
  14644. }
  14645. var parts = [];
  14646. currentDoc.parts.forEach(function (part) {
  14647. if (typeof part === "string") {
  14648. parts.push(part.replace(/(\\*)`/g, "$1$1\\`"));
  14649. } else {
  14650. parts.push(part);
  14651. }
  14652. });
  14653. return Object.assign({}, currentDoc, {
  14654. parts
  14655. });
  14656. });
  14657. }
  14658. function transformCssDoc(quasisDoc, path$$1, print) {
  14659. var parentNode = path$$1.getValue();
  14660. var isEmpty = parentNode.quasis.length === 1 && !parentNode.quasis[0].value.raw.trim();
  14661. if (isEmpty) {
  14662. return "``";
  14663. }
  14664. var expressionDocs = parentNode.expressions ? path$$1.map(print, "expressions") : [];
  14665. var newDoc = replacePlaceholders(quasisDoc, expressionDocs);
  14666. /* istanbul ignore if */
  14667. if (!newDoc) {
  14668. throw new Error("Couldn't insert all the expressions");
  14669. }
  14670. return concat$5(["`", indent$3(concat$5([hardline$4, stripTrailingHardline$1(newDoc)])), softline$2, "`"]);
  14671. } // Search all the placeholders in the quasisDoc tree
  14672. // and replace them with the expression docs one by one
  14673. // returns a new doc with all the placeholders replaced,
  14674. // or null if it couldn't replace any expression
  14675. function replacePlaceholders(quasisDoc, expressionDocs) {
  14676. if (!expressionDocs || !expressionDocs.length) {
  14677. return quasisDoc;
  14678. }
  14679. var expressions = expressionDocs.slice();
  14680. var replaceCounter = 0;
  14681. var newDoc = mapDoc$2(quasisDoc, function (doc$$2) {
  14682. if (!doc$$2 || !doc$$2.parts || !doc$$2.parts.length) {
  14683. return doc$$2;
  14684. }
  14685. var parts = doc$$2.parts;
  14686. var atIndex = parts.indexOf("@");
  14687. var placeholderIndex = atIndex + 1;
  14688. if (atIndex > -1 && typeof parts[placeholderIndex] === "string" && parts[placeholderIndex].startsWith("prettier-placeholder")) {
  14689. // If placeholder is split, join it
  14690. var at = parts[atIndex];
  14691. var placeholder = parts[placeholderIndex];
  14692. var rest = parts.slice(placeholderIndex + 1);
  14693. parts = parts.slice(0, atIndex).concat([at + placeholder]).concat(rest);
  14694. }
  14695. var atPlaceholderIndex = parts.findIndex(function (part) {
  14696. return typeof part === "string" && part.startsWith("@prettier-placeholder");
  14697. });
  14698. if (atPlaceholderIndex > -1) {
  14699. var _placeholder = parts[atPlaceholderIndex];
  14700. var _rest = parts.slice(atPlaceholderIndex + 1);
  14701. var placeholderMatch = _placeholder.match(/@prettier-placeholder-(.+)-id([\s\S]*)/);
  14702. var placeholderID = placeholderMatch[1]; // When the expression has a suffix appended, like:
  14703. // animation: linear ${time}s ease-out;
  14704. var suffix = placeholderMatch[2];
  14705. var expression = expressions[placeholderID];
  14706. replaceCounter++;
  14707. parts = parts.slice(0, atPlaceholderIndex).concat(["${", expression, "}" + suffix]).concat(_rest);
  14708. }
  14709. return Object.assign({}, doc$$2, {
  14710. parts: parts
  14711. });
  14712. });
  14713. return expressions.length === replaceCounter ? newDoc : null;
  14714. }
  14715. function printGraphqlComments(lines) {
  14716. var parts = [];
  14717. var seenComment = false;
  14718. lines.map(function (textLine) {
  14719. return textLine.trim();
  14720. }).forEach(function (textLine, i, array) {
  14721. // Lines are either whitespace only, or a comment (with poential whitespace
  14722. // around it). Drop whitespace-only lines.
  14723. if (textLine === "") {
  14724. return;
  14725. }
  14726. if (array[i - 1] === "" && seenComment) {
  14727. // If a non-first comment is preceded by a blank (whitespace only) line,
  14728. // add in a blank line.
  14729. parts.push(concat$5([hardline$4, textLine]));
  14730. } else {
  14731. parts.push(textLine);
  14732. }
  14733. seenComment = true;
  14734. }); // If `lines` was whitespace only, return `null`.
  14735. return parts.length === 0 ? null : join$3(hardline$4, parts);
  14736. }
  14737. /**
  14738. * Template literal in this context:
  14739. * <style jsx>{`div{color:red}`}</style>
  14740. */
  14741. function isStyledJsx(path$$1) {
  14742. var node = path$$1.getValue();
  14743. var parent = path$$1.getParentNode();
  14744. var parentParent = path$$1.getParentNode(1);
  14745. return parentParent && node.quasis && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXElement" && parentParent.openingElement.name.name === "style" && parentParent.openingElement.attributes.some(function (attribute) {
  14746. return attribute.name.name === "jsx";
  14747. });
  14748. }
  14749. /**
  14750. * Angular Components can have:
  14751. * - Inline HTML template
  14752. * - Inline CSS styles
  14753. *
  14754. * ...which are both within template literals somewhere
  14755. * inside of the Component decorator factory.
  14756. *
  14757. * TODO: Format HTML template once prettier's HTML
  14758. * formatting is "ready"
  14759. *
  14760. * E.g.
  14761. * @Component({
  14762. * template: `<div>...</div>`,
  14763. * styles: [`h1 { color: blue; }`]
  14764. * })
  14765. */
  14766. function isAngularComponentStyles(path$$1) {
  14767. var parent = path$$1.getParentNode();
  14768. var parentParent = path$$1.getParentNode(1);
  14769. var isWithinArrayValueFromProperty = !!(parent && parent.type === "ArrayExpression" && parentParent.type === "Property");
  14770. if (isWithinArrayValueFromProperty && isPropertyWithinAngularComponentDecorator(path$$1, 4)) {
  14771. if (parentParent.key && parentParent.key.name === "styles") {
  14772. return true;
  14773. }
  14774. }
  14775. return false;
  14776. }
  14777. /**
  14778. * styled-components template literals
  14779. */
  14780. function isStyledComponents(path$$1) {
  14781. var parent = path$$1.getParentNode();
  14782. if (!parent || parent.type !== "TaggedTemplateExpression") {
  14783. return false;
  14784. }
  14785. var tag = parent.tag;
  14786. switch (tag.type) {
  14787. case "MemberExpression":
  14788. return (// styled.foo``
  14789. isStyledIdentifier(tag.object) || // Component.extend``
  14790. isStyledExtend(tag)
  14791. );
  14792. case "CallExpression":
  14793. return (// styled(Component)``
  14794. isStyledIdentifier(tag.callee) || tag.callee.type === "MemberExpression" && (tag.callee.object.type === "MemberExpression" && ( // styled.foo.attr({})``
  14795. isStyledIdentifier(tag.callee.object.object) || // Component.extend.attr({)``
  14796. isStyledExtend(tag.callee.object)) || // styled(Component).attr({})``
  14797. tag.callee.object.type === "CallExpression" && isStyledIdentifier(tag.callee.object.callee))
  14798. );
  14799. case "Identifier":
  14800. // css``
  14801. return tag.name === "css";
  14802. default:
  14803. return false;
  14804. }
  14805. }
  14806. /**
  14807. * JSX element with CSS prop
  14808. */
  14809. function isCssProp(path$$1) {
  14810. var parent = path$$1.getParentNode();
  14811. var parentParent = path$$1.getParentNode(1);
  14812. return parentParent && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" && parentParent.name.type === "JSXIdentifier" && parentParent.name.name === "css";
  14813. }
  14814. function isStyledIdentifier(node) {
  14815. return node.type === "Identifier" && node.name === "styled";
  14816. }
  14817. function isStyledExtend(node) {
  14818. return /^[A-Z]/.test(node.object.name) && node.property.name === "extend";
  14819. }
  14820. /*
  14821. * react-relay and graphql-tag
  14822. * graphql`...`
  14823. * graphql.experimental`...`
  14824. * gql`...`
  14825. * GraphQL comment block
  14826. *
  14827. * This intentionally excludes Relay Classic tags, as Prettier does not
  14828. * support Relay Classic formatting.
  14829. */
  14830. function isGraphQL(path$$1) {
  14831. var node = path$$1.getValue();
  14832. var parent = path$$1.getParentNode(); // This checks for a leading comment that is exactly `/* GraphQL */`
  14833. // In order to be in line with other implementations of this comment tag
  14834. // we will not trim the comment value and we will expect exactly one space on
  14835. // either side of the GraphQL string
  14836. // Also see ./clean.js
  14837. var hasGraphQLComment = node.leadingComments && node.leadingComments.some(function (comment) {
  14838. return comment.type === "CommentBlock" && comment.value === " GraphQL ";
  14839. });
  14840. return hasGraphQLComment || 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");
  14841. }
  14842. var embed_1 = embed;
  14843. function clean(ast, newObj, parent) {
  14844. ["range", "raw", "comments", "leadingComments", "trailingComments", "extra", "start", "end", "flags"].forEach(function (name) {
  14845. delete newObj[name];
  14846. }); // We remove extra `;` and add them when needed
  14847. if (ast.type === "EmptyStatement") {
  14848. return null;
  14849. } // We move text around, including whitespaces and add {" "}
  14850. if (ast.type === "JSXText") {
  14851. return null;
  14852. }
  14853. if (ast.type === "JSXExpressionContainer" && ast.expression.type === "Literal" && ast.expression.value === " ") {
  14854. return null;
  14855. } // (TypeScript) Ignore `static` in `constructor(static p) {}`
  14856. // and `export` in `constructor(export p) {}`
  14857. if (ast.type === "TSParameterProperty" && ast.accessibility === null && !ast.readonly) {
  14858. return {
  14859. type: "Identifier",
  14860. name: ast.parameter.name,
  14861. typeAnnotation: newObj.parameter.typeAnnotation,
  14862. decorators: newObj.decorators
  14863. };
  14864. } // (TypeScript) ignore empty `specifiers` array
  14865. if (ast.type === "TSNamespaceExportDeclaration" && ast.specifiers && ast.specifiers.length === 0) {
  14866. delete newObj.specifiers;
  14867. } // (TypeScript) bypass TSParenthesizedType
  14868. if (ast.type === "TSParenthesizedType" && ast.typeAnnotation.type === "TSTypeAnnotation") {
  14869. return newObj.typeAnnotation.typeAnnotation;
  14870. } // We convert <div></div> to <div />
  14871. if (ast.type === "JSXOpeningElement") {
  14872. delete newObj.selfClosing;
  14873. }
  14874. if (ast.type === "JSXElement") {
  14875. delete newObj.closingElement;
  14876. } // We change {'key': value} into {key: value}
  14877. 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")) {
  14878. delete newObj.key;
  14879. }
  14880. if (ast.type === "OptionalMemberExpression" && ast.optional === false) {
  14881. newObj.type = "MemberExpression";
  14882. delete newObj.optional;
  14883. } // Remove raw and cooked values from TemplateElement when it's CSS
  14884. // styled-jsx
  14885. if (ast.type === "JSXElement" && ast.openingElement.name.name === "style" && ast.openingElement.attributes.some(function (attr) {
  14886. return attr.name.name === "jsx";
  14887. })) {
  14888. var templateLiterals = newObj.children.filter(function (child) {
  14889. return child.type === "JSXExpressionContainer" && child.expression.type === "TemplateLiteral";
  14890. }).map(function (container) {
  14891. return container.expression;
  14892. });
  14893. var quasis = templateLiterals.reduce(function (quasis, templateLiteral) {
  14894. return quasis.concat(templateLiteral.quasis);
  14895. }, []);
  14896. quasis.forEach(function (q) {
  14897. return delete q.value;
  14898. });
  14899. } // CSS template literals in css prop
  14900. if (ast.type === "JSXAttribute" && ast.name.name === "css" && ast.value.type === "JSXExpressionContainer" && ast.value.expression.type === "TemplateLiteral") {
  14901. newObj.value.expression.quasis.forEach(function (q) {
  14902. return delete q.value;
  14903. });
  14904. } // CSS template literals in Angular Component decorator
  14905. var expression = ast.expression || ast.callee;
  14906. if (ast.type === "Decorator" && expression.type === "CallExpression" && expression.callee.name === "Component" && expression.arguments.length === 1 && expression.arguments[0].properties.some(function (prop) {
  14907. return prop.key.name === "styles" && prop.value.type === "ArrayExpression";
  14908. })) {
  14909. newObj.expression.arguments[0].properties.forEach(function (prop) {
  14910. if (prop.value.type === "ArrayExpression") {
  14911. prop.value.elements[0].quasis.forEach(function (q) {
  14912. return delete q.value;
  14913. });
  14914. }
  14915. });
  14916. } // styled-components, graphql, markdown
  14917. 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.type === "CallExpression")) {
  14918. newObj.quasi.quasis.forEach(function (quasi) {
  14919. return delete quasi.value;
  14920. });
  14921. }
  14922. if (ast.type === "TemplateLiteral") {
  14923. // This checks for a leading comment that is exactly `/* GraphQL */`
  14924. // In order to be in line with other implementations of this comment tag
  14925. // we will not trim the comment value and we will expect exactly one space on
  14926. // either side of the GraphQL string
  14927. // Also see ./embed.js
  14928. var hasGraphQLComment = ast.leadingComments && ast.leadingComments.some(function (comment) {
  14929. return comment.type === "CommentBlock" && comment.value === " GraphQL ";
  14930. });
  14931. if (hasGraphQLComment || parent.type === "CallExpression" && parent.callee.name === "graphql") {
  14932. newObj.quasis.forEach(function (quasi) {
  14933. return delete quasi.value;
  14934. });
  14935. }
  14936. }
  14937. }
  14938. var clean_1 = clean;
  14939. var detectNewline = createCommonjsModule(function (module) {
  14940. 'use strict';
  14941. module.exports = function (str) {
  14942. if (typeof str !== 'string') {
  14943. throw new TypeError('Expected a string');
  14944. }
  14945. var newlines = str.match(/(?:\r?\n)/g) || [];
  14946. if (newlines.length === 0) {
  14947. return null;
  14948. }
  14949. var crlf = newlines.filter(function (el) {
  14950. return el === '\r\n';
  14951. }).length;
  14952. var lf = newlines.length - crlf;
  14953. return crlf > lf ? '\r\n' : '\n';
  14954. };
  14955. module.exports.graceful = function (str) {
  14956. return module.exports(str) || '\n';
  14957. };
  14958. });
  14959. var build = createCommonjsModule(function (module, exports) {
  14960. 'use strict';
  14961. Object.defineProperty(exports, "__esModule", {
  14962. value: true
  14963. });
  14964. exports.extract = extract;
  14965. exports.strip = strip;
  14966. exports.parse = parse;
  14967. exports.parseWithComments = parseWithComments;
  14968. exports.print = print;
  14969. var _detectNewline;
  14970. function _load_detectNewline() {
  14971. return _detectNewline = _interopRequireDefault(detectNewline);
  14972. }
  14973. var _os;
  14974. function _load_os() {
  14975. return _os = os;
  14976. }
  14977. function _interopRequireDefault(obj) {
  14978. return obj && obj.__esModule ? obj : {
  14979. default: obj
  14980. };
  14981. }
  14982. /**
  14983. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  14984. *
  14985. * This source code is licensed under the MIT license found in the
  14986. * LICENSE file in the root directory of this source tree.
  14987. *
  14988. *
  14989. */
  14990. var commentEndRe = /\*\/$/;
  14991. var commentStartRe = /^\/\*\*/;
  14992. var docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;
  14993. var lineCommentRe = /(^|\s+)\/\/([^\r\n]*)/g;
  14994. var ltrimRe = /^\s*/;
  14995. var rtrimRe = /\s*$/;
  14996. var ltrimNewlineRe = /^(\r?\n)+/;
  14997. var multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *(?![^@\r\n]*\/\/[^]*)([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
  14998. var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
  14999. var stringStartRe = /(\r?\n|^) *\* ?/g;
  15000. function extract(contents) {
  15001. var match = contents.match(docblockRe);
  15002. return match ? match[0].replace(ltrimRe, '') || '' : '';
  15003. }
  15004. function strip(contents) {
  15005. var match = contents.match(docblockRe);
  15006. return match && match[0] ? contents.substring(match[0].length) : contents;
  15007. }
  15008. function parse(docblock) {
  15009. return parseWithComments(docblock).pragmas;
  15010. }
  15011. function parseWithComments(docblock) {
  15012. var line = (0, (_detectNewline || _load_detectNewline()).default)(docblock) || (_os || _load_os()).EOL;
  15013. docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replace(stringStartRe, '$1'); // Normalize multi-line directives
  15014. var prev = '';
  15015. while (prev !== docblock) {
  15016. prev = docblock;
  15017. docblock = docblock.replace(multilineRe, `${line}$1 $2${line}`);
  15018. }
  15019. docblock = docblock.replace(ltrimNewlineRe, '').replace(rtrimRe, '');
  15020. var result = Object.create(null);
  15021. var comments = docblock.replace(propertyRe, '').replace(ltrimNewlineRe, '').replace(rtrimRe, '');
  15022. var match;
  15023. while (match = propertyRe.exec(docblock)) {
  15024. // strip linecomments from pragmas
  15025. var nextPragma = match[2].replace(lineCommentRe, '');
  15026. if (typeof result[match[1]] === 'string' || Array.isArray(result[match[1]])) {
  15027. result[match[1]] = [].concat(result[match[1]], nextPragma);
  15028. } else {
  15029. result[match[1]] = nextPragma;
  15030. }
  15031. }
  15032. return {
  15033. comments,
  15034. pragmas: result
  15035. };
  15036. }
  15037. function print(_ref) {
  15038. var _ref$comments = _ref.comments;
  15039. var comments = _ref$comments === undefined ? '' : _ref$comments;
  15040. var _ref$pragmas = _ref.pragmas;
  15041. var pragmas = _ref$pragmas === undefined ? {} : _ref$pragmas;
  15042. var line = (0, (_detectNewline || _load_detectNewline()).default)(comments) || (_os || _load_os()).EOL;
  15043. var head = '/**';
  15044. var start = ' *';
  15045. var tail = ' */';
  15046. var keys = Object.keys(pragmas);
  15047. var printedObject = keys.map(function (key) {
  15048. return printKeyValues(key, pragmas[key]);
  15049. }).reduce(function (arr, next) {
  15050. return arr.concat(next);
  15051. }, []).map(function (keyValue) {
  15052. return start + ' ' + keyValue + line;
  15053. }).join('');
  15054. if (!comments) {
  15055. if (keys.length === 0) {
  15056. return '';
  15057. }
  15058. if (keys.length === 1 && !Array.isArray(pragmas[keys[0]])) {
  15059. var value = pragmas[keys[0]];
  15060. return `${head} ${printKeyValues(keys[0], value)[0]}${tail}`;
  15061. }
  15062. }
  15063. var printedComments = comments.split(line).map(function (textLine) {
  15064. return `${start} ${textLine}`;
  15065. }).join(line) + line;
  15066. return head + line + (comments ? printedComments : '') + (comments && keys.length ? start + line : '') + printedObject + tail;
  15067. }
  15068. function printKeyValues(key, valueOrArray) {
  15069. return [].concat(valueOrArray).map(function (value) {
  15070. return `@${key} ${value}`.trim();
  15071. });
  15072. }
  15073. });
  15074. unwrapExports(build);
  15075. function hasPragma(text) {
  15076. var pragmas = Object.keys(build.parse(build.extract(text)));
  15077. return pragmas.indexOf("prettier") !== -1 || pragmas.indexOf("format") !== -1;
  15078. }
  15079. function insertPragma$1(text) {
  15080. var parsedDocblock = build.parseWithComments(build.extract(text));
  15081. var pragmas = Object.assign({
  15082. format: ""
  15083. }, parsedDocblock.pragmas);
  15084. var newDocblock = build.print({
  15085. pragmas,
  15086. comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, "") // remove leading newlines
  15087. });
  15088. var strippedText = build.strip(text);
  15089. var separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n";
  15090. return newDocblock + separatingNewlines + strippedText;
  15091. }
  15092. var pragma = {
  15093. hasPragma,
  15094. insertPragma: insertPragma$1
  15095. };
  15096. var addLeadingComment$2 = utilShared.addLeadingComment;
  15097. var addTrailingComment$2 = utilShared.addTrailingComment;
  15098. var addDanglingComment$2 = utilShared.addDanglingComment;
  15099. function handleOwnLineComment(comment, text, options, ast, isLastComment) {
  15100. var precedingNode = comment.precedingNode;
  15101. var enclosingNode = comment.enclosingNode;
  15102. var followingNode = comment.followingNode;
  15103. if (handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleMemberExpressionComments(enclosingNode, followingNode, comment) || handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleTryStatementComments(enclosingNode, 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)) {
  15104. return true;
  15105. }
  15106. return false;
  15107. }
  15108. function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
  15109. var precedingNode = comment.precedingNode;
  15110. var enclosingNode = comment.enclosingNode;
  15111. var followingNode = comment.followingNode;
  15112. 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) || 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)) {
  15113. return true;
  15114. }
  15115. return false;
  15116. }
  15117. function handleRemainingComment(comment, text, options, ast, isLastComment) {
  15118. var precedingNode = comment.precedingNode;
  15119. var enclosingNode = comment.enclosingNode;
  15120. var followingNode = comment.followingNode;
  15121. if (handleIfStatementComments(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)) {
  15122. return true;
  15123. }
  15124. return false;
  15125. }
  15126. function addBlockStatementFirstComment(node, comment) {
  15127. var body = node.body.filter(function (n) {
  15128. return n.type !== "EmptyStatement";
  15129. });
  15130. if (body.length === 0) {
  15131. addDanglingComment$2(node, comment);
  15132. } else {
  15133. addLeadingComment$2(body[0], comment);
  15134. }
  15135. }
  15136. function addBlockOrNotComment(node, comment) {
  15137. if (node.type === "BlockStatement") {
  15138. addBlockStatementFirstComment(node, comment);
  15139. } else {
  15140. addLeadingComment$2(node, comment);
  15141. }
  15142. } // There are often comments before the else clause of if statements like
  15143. //
  15144. // if (1) { ... }
  15145. // // comment
  15146. // else { ... }
  15147. //
  15148. // They are being attached as leading comments of the BlockExpression which
  15149. // is not well printed. What we want is to instead move the comment inside
  15150. // of the block and make it leadingComment of the first element of the block
  15151. // or dangling comment of the block if there is nothing inside
  15152. //
  15153. // if (1) { ... }
  15154. // else {
  15155. // // comment
  15156. // ...
  15157. // }
  15158. function handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  15159. if (!enclosingNode || enclosingNode.type !== "IfStatement" || !followingNode) {
  15160. return false;
  15161. } // We unfortunately have no way using the AST or location of nodes to know
  15162. // if the comment is positioned before the condition parenthesis:
  15163. // if (a /* comment */) {}
  15164. // The only workaround I found is to look at the next character to see if
  15165. // it is a ).
  15166. var nextCharacter = util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd);
  15167. if (nextCharacter === ")") {
  15168. addTrailingComment$2(precedingNode, comment);
  15169. return true;
  15170. } // Comments before `else`:
  15171. // - treat as trailing comments of the consequent, if it's a BlockStatement
  15172. // - treat as a dangling comment otherwise
  15173. if (precedingNode === enclosingNode.consequent && followingNode === enclosingNode.alternate) {
  15174. if (precedingNode.type === "BlockStatement") {
  15175. addTrailingComment$2(precedingNode, comment);
  15176. } else {
  15177. addDanglingComment$2(enclosingNode, comment);
  15178. }
  15179. return true;
  15180. }
  15181. if (followingNode.type === "BlockStatement") {
  15182. addBlockStatementFirstComment(followingNode, comment);
  15183. return true;
  15184. }
  15185. if (followingNode.type === "IfStatement") {
  15186. addBlockOrNotComment(followingNode.consequent, comment);
  15187. return true;
  15188. } // For comments positioned after the condition parenthesis in an if statement
  15189. // before the consequent with or without brackets on, such as
  15190. // if (a) /* comment */ {} or if (a) /* comment */ true,
  15191. // we look at the next character to see if it is a { or if the following node
  15192. // is the consequent for the if statement
  15193. if (nextCharacter === "{" || enclosingNode.consequent === followingNode) {
  15194. addLeadingComment$2(followingNode, comment);
  15195. return true;
  15196. }
  15197. return false;
  15198. } // Same as IfStatement but for TryStatement
  15199. function handleTryStatementComments(enclosingNode, followingNode, comment) {
  15200. if (!enclosingNode || enclosingNode.type !== "TryStatement" || !followingNode) {
  15201. return false;
  15202. }
  15203. if (followingNode.type === "BlockStatement") {
  15204. addBlockStatementFirstComment(followingNode, comment);
  15205. return true;
  15206. }
  15207. if (followingNode.type === "TryStatement") {
  15208. addBlockOrNotComment(followingNode.finalizer, comment);
  15209. return true;
  15210. }
  15211. if (followingNode.type === "CatchClause") {
  15212. addBlockOrNotComment(followingNode.body, comment);
  15213. return true;
  15214. }
  15215. return false;
  15216. }
  15217. function handleMemberExpressionComments(enclosingNode, followingNode, comment) {
  15218. if (enclosingNode && enclosingNode.type === "MemberExpression" && followingNode && followingNode.type === "Identifier") {
  15219. addLeadingComment$2(enclosingNode, comment);
  15220. return true;
  15221. }
  15222. return false;
  15223. }
  15224. function handleConditionalExpressionComments(enclosingNode, precedingNode, followingNode, comment, text, options) {
  15225. var isSameLineAsPrecedingNode = precedingNode && !util$1.hasNewlineInRange(text, options.locEnd(precedingNode), options.locStart(comment));
  15226. if ((!precedingNode || !isSameLineAsPrecedingNode) && enclosingNode && enclosingNode.type === "ConditionalExpression" && followingNode) {
  15227. addLeadingComment$2(followingNode, comment);
  15228. return true;
  15229. }
  15230. return false;
  15231. }
  15232. function handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) {
  15233. if (enclosingNode && (enclosingNode.type === "ObjectProperty" || enclosingNode.type === "Property") && enclosingNode.shorthand && enclosingNode.key === precedingNode && enclosingNode.value.type === "AssignmentPattern") {
  15234. addTrailingComment$2(enclosingNode.value.left, comment);
  15235. return true;
  15236. }
  15237. return false;
  15238. }
  15239. function handleClassComments(enclosingNode, precedingNode, followingNode, comment) {
  15240. if (enclosingNode && (enclosingNode.type === "ClassDeclaration" || enclosingNode.type === "ClassExpression") && enclosingNode.decorators && enclosingNode.decorators.length > 0 && !(followingNode && followingNode.type === "Decorator")) {
  15241. if (!enclosingNode.decorators || enclosingNode.decorators.length === 0) {
  15242. addLeadingComment$2(enclosingNode, comment);
  15243. } else {
  15244. addTrailingComment$2(enclosingNode.decorators[enclosingNode.decorators.length - 1], comment);
  15245. }
  15246. return true;
  15247. }
  15248. return false;
  15249. }
  15250. function handleMethodNameComments(text, enclosingNode, precedingNode, comment, options) {
  15251. // This is only needed for estree parsers (flow, typescript) to attach
  15252. // after a method name:
  15253. // obj = { fn /*comment*/() {} };
  15254. if (enclosingNode && precedingNode && (enclosingNode.type === "Property" || enclosingNode.type === "MethodDefinition") && precedingNode.type === "Identifier" && enclosingNode.key === precedingNode && // special Property case: { key: /*comment*/(value) };
  15255. // comment should be attached to value instead of key
  15256. util$1.getNextNonSpaceNonCommentCharacter(text, precedingNode, options.locEnd) !== ":") {
  15257. addTrailingComment$2(precedingNode, comment);
  15258. return true;
  15259. } // Print comments between decorators and class methods as a trailing comment
  15260. // on the decorator node instead of the method node
  15261. if (precedingNode && enclosingNode && precedingNode.type === "Decorator" && (enclosingNode.type === "ClassMethod" || enclosingNode.type === "ClassProperty" || enclosingNode.type === "TSAbstractClassProperty" || enclosingNode.type === "TSAbstractMethodDefinition" || enclosingNode.type === "MethodDefinition")) {
  15262. addTrailingComment$2(precedingNode, comment);
  15263. return true;
  15264. }
  15265. return false;
  15266. }
  15267. function handleFunctionNameComments(text, enclosingNode, precedingNode, comment, options) {
  15268. if (util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) !== "(") {
  15269. return false;
  15270. }
  15271. if (precedingNode && enclosingNode && (enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ClassMethod" || enclosingNode.type === "MethodDefinition" || enclosingNode.type === "ObjectMethod")) {
  15272. addTrailingComment$2(precedingNode, comment);
  15273. return true;
  15274. }
  15275. return false;
  15276. }
  15277. function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
  15278. if (!(enclosingNode && enclosingNode.type === "ArrowFunctionExpression")) {
  15279. return false;
  15280. }
  15281. var index = utilShared.getNextNonSpaceNonCommentCharacterIndex(text, comment, options);
  15282. if (text.substr(index, 2) === "=>") {
  15283. addDanglingComment$2(enclosingNode, comment);
  15284. return true;
  15285. }
  15286. return false;
  15287. }
  15288. function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
  15289. if (util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) !== ")") {
  15290. return false;
  15291. } // Only add dangling comments to fix the case when no params are present,
  15292. // i.e. a function without any argument.
  15293. if (enclosingNode && ((enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ArrowFunctionExpression" && (enclosingNode.body.type !== "CallExpression" || enclosingNode.body.arguments.length === 0) || enclosingNode.type === "ClassMethod" || enclosingNode.type === "ObjectMethod") && enclosingNode.params.length === 0 || enclosingNode.type === "CallExpression" && enclosingNode.arguments.length === 0)) {
  15294. addDanglingComment$2(enclosingNode, comment);
  15295. return true;
  15296. }
  15297. if (enclosingNode && enclosingNode.type === "MethodDefinition" && enclosingNode.value.params.length === 0) {
  15298. addDanglingComment$2(enclosingNode.value, comment);
  15299. return true;
  15300. }
  15301. return false;
  15302. }
  15303. function handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  15304. // Type definitions functions
  15305. if (precedingNode && precedingNode.type === "FunctionTypeParam" && enclosingNode && enclosingNode.type === "FunctionTypeAnnotation" && followingNode && followingNode.type !== "FunctionTypeParam") {
  15306. addTrailingComment$2(precedingNode, comment);
  15307. return true;
  15308. } // Real functions
  15309. 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$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) === ")") {
  15310. addTrailingComment$2(precedingNode, comment);
  15311. return true;
  15312. }
  15313. return false;
  15314. }
  15315. function handleImportSpecifierComments(enclosingNode, comment) {
  15316. if (enclosingNode && enclosingNode.type === "ImportSpecifier") {
  15317. addLeadingComment$2(enclosingNode, comment);
  15318. return true;
  15319. }
  15320. return false;
  15321. }
  15322. function handleLabeledStatementComments(enclosingNode, comment) {
  15323. if (enclosingNode && enclosingNode.type === "LabeledStatement") {
  15324. addLeadingComment$2(enclosingNode, comment);
  15325. return true;
  15326. }
  15327. return false;
  15328. }
  15329. function handleBreakAndContinueStatementComments(enclosingNode, comment) {
  15330. if (enclosingNode && (enclosingNode.type === "ContinueStatement" || enclosingNode.type === "BreakStatement") && !enclosingNode.label) {
  15331. addTrailingComment$2(enclosingNode, comment);
  15332. return true;
  15333. }
  15334. return false;
  15335. }
  15336. function handleCallExpressionComments(precedingNode, enclosingNode, comment) {
  15337. if (enclosingNode && enclosingNode.type === "CallExpression" && precedingNode && enclosingNode.callee === precedingNode && enclosingNode.arguments.length > 0) {
  15338. addLeadingComment$2(enclosingNode.arguments[0], comment);
  15339. return true;
  15340. }
  15341. return false;
  15342. }
  15343. function handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) {
  15344. if (enclosingNode && (enclosingNode.type === "UnionTypeAnnotation" || enclosingNode.type === "TSUnionType")) {
  15345. addTrailingComment$2(precedingNode, comment);
  15346. return true;
  15347. }
  15348. return false;
  15349. }
  15350. function handlePropertyComments(enclosingNode, comment) {
  15351. if (enclosingNode && (enclosingNode.type === "Property" || enclosingNode.type === "ObjectProperty")) {
  15352. addLeadingComment$2(enclosingNode, comment);
  15353. return true;
  15354. }
  15355. return false;
  15356. }
  15357. function handleOnlyComments(enclosingNode, ast, comment, isLastComment) {
  15358. // With Flow the enclosingNode is undefined so use the AST instead.
  15359. if (ast && ast.body && ast.body.length === 0) {
  15360. if (isLastComment) {
  15361. addDanglingComment$2(ast, comment);
  15362. } else {
  15363. addLeadingComment$2(ast, comment);
  15364. }
  15365. return true;
  15366. } else if (enclosingNode && enclosingNode.type === "Program" && enclosingNode.body.length === 0 && enclosingNode.directives && enclosingNode.directives.length === 0) {
  15367. if (isLastComment) {
  15368. addDanglingComment$2(enclosingNode, comment);
  15369. } else {
  15370. addLeadingComment$2(enclosingNode, comment);
  15371. }
  15372. return true;
  15373. }
  15374. return false;
  15375. }
  15376. function handleForComments(enclosingNode, precedingNode, comment) {
  15377. if (enclosingNode && (enclosingNode.type === "ForInStatement" || enclosingNode.type === "ForOfStatement")) {
  15378. addLeadingComment$2(enclosingNode, comment);
  15379. return true;
  15380. }
  15381. return false;
  15382. }
  15383. function handleImportDeclarationComments(text, enclosingNode, precedingNode, comment, options) {
  15384. if (precedingNode && enclosingNode && enclosingNode.type === "ImportDeclaration" && util$1.hasNewline(text, options.locEnd(comment))) {
  15385. addTrailingComment$2(precedingNode, comment);
  15386. return true;
  15387. }
  15388. return false;
  15389. }
  15390. function handleAssignmentPatternComments(enclosingNode, comment) {
  15391. if (enclosingNode && enclosingNode.type === "AssignmentPattern") {
  15392. addLeadingComment$2(enclosingNode, comment);
  15393. return true;
  15394. }
  15395. return false;
  15396. }
  15397. function handleTypeAliasComments(enclosingNode, followingNode, comment) {
  15398. if (enclosingNode && enclosingNode.type === "TypeAlias") {
  15399. addLeadingComment$2(enclosingNode, comment);
  15400. return true;
  15401. }
  15402. return false;
  15403. }
  15404. function handleVariableDeclaratorComments(enclosingNode, followingNode, comment) {
  15405. if (enclosingNode && (enclosingNode.type === "VariableDeclarator" || enclosingNode.type === "AssignmentExpression") && followingNode && (followingNode.type === "ObjectExpression" || followingNode.type === "ArrayExpression" || followingNode.type === "TemplateLiteral" || followingNode.type === "TaggedTemplateExpression")) {
  15406. addLeadingComment$2(followingNode, comment);
  15407. return true;
  15408. }
  15409. return false;
  15410. }
  15411. function handleTSMappedTypeComments(text, enclosingNode, precedingNode, followingNode, comment) {
  15412. if (!enclosingNode || enclosingNode.type !== "TSMappedType") {
  15413. return false;
  15414. }
  15415. if (followingNode && followingNode.type === "TSTypeParameter" && followingNode.name) {
  15416. addLeadingComment$2(followingNode.name, comment);
  15417. return true;
  15418. }
  15419. if (precedingNode && precedingNode.type === "TSTypeParameter" && precedingNode.constraint) {
  15420. addTrailingComment$2(precedingNode.constraint, comment);
  15421. return true;
  15422. }
  15423. return false;
  15424. }
  15425. function isBlockComment(comment) {
  15426. return comment.type === "Block" || comment.type === "CommentBlock";
  15427. }
  15428. var comments$3 = {
  15429. handleOwnLineComment,
  15430. handleEndOfLineComment,
  15431. handleRemainingComment,
  15432. isBlockComment
  15433. };
  15434. function hasClosureCompilerTypeCastComment(text, path$$1, locStart, locEnd) {
  15435. // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
  15436. // Syntax example: var x = /** @type {string} */ (fruit);
  15437. var n = path$$1.getValue();
  15438. return util$1.getNextNonSpaceNonCommentCharacter(text, n, locEnd) === ")" && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
  15439. function hasAncestorTypeCastComment(index) {
  15440. var ancestor = path$$1.getParentNode(index);
  15441. return ancestor && util$1.getNextNonSpaceNonCommentCharacter(text, ancestor, locEnd) !== ")" && /^[\s(]*$/.test(text.slice(locStart(ancestor), locStart(n))) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
  15442. }
  15443. function hasTypeCastComment(node) {
  15444. return node.comments && node.comments.some(function (comment) {
  15445. return comment.leading && comments$3.isBlockComment(comment) && comment.value.match(/^\*\s*@type\s*{[^}]+}\s*$/) && util$1.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
  15446. });
  15447. }
  15448. }
  15449. function needsParens(path$$1, options) {
  15450. var parent = path$$1.getParentNode();
  15451. if (!parent) {
  15452. return false;
  15453. }
  15454. var name = path$$1.getName();
  15455. var node = path$$1.getNode(); // If the value of this path is some child of a Node and not a Node
  15456. // itself, then it doesn't need parentheses. Only Node objects (in
  15457. // fact, only Expression nodes) need parentheses.
  15458. if (path$$1.getValue() !== node) {
  15459. return false;
  15460. } // Only statements don't need parentheses.
  15461. if (isStatement(node)) {
  15462. return false;
  15463. } // Closure compiler requires that type casted expressions to be surrounded by
  15464. // parentheses.
  15465. if (hasClosureCompilerTypeCastComment(options.originalText, path$$1, options.locStart, options.locEnd)) {
  15466. return true;
  15467. } // Identifiers never need parentheses.
  15468. if (node.type === "Identifier") {
  15469. return false;
  15470. }
  15471. if (parent.type === "ParenthesizedExpression") {
  15472. return false;
  15473. } // Add parens around the extends clause of a class. It is needed for almost
  15474. // all expressions.
  15475. 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")) {
  15476. return true;
  15477. }
  15478. if (parent.type === "ArrowFunctionExpression" && parent.body === node && node.type !== "SequenceExpression" && // these have parens added anyway
  15479. util$1.startsWithNoLookaheadToken(node,
  15480. /* forbidFunctionClassAndDoExpr */
  15481. false) || parent.type === "ExpressionStatement" && util$1.startsWithNoLookaheadToken(node,
  15482. /* forbidFunctionClassAndDoExpr */
  15483. true)) {
  15484. return true;
  15485. }
  15486. switch (node.type) {
  15487. case "CallExpression":
  15488. {
  15489. var firstParentNotMemberExpression = parent;
  15490. var i = 0;
  15491. while (firstParentNotMemberExpression && firstParentNotMemberExpression.type === "MemberExpression") {
  15492. firstParentNotMemberExpression = path$$1.getParentNode(++i);
  15493. }
  15494. if (firstParentNotMemberExpression.type === "NewExpression" && firstParentNotMemberExpression.callee === path$$1.getParentNode(i - 1)) {
  15495. return true;
  15496. }
  15497. return false;
  15498. }
  15499. case "SpreadElement":
  15500. case "SpreadProperty":
  15501. return parent.type === "MemberExpression" && name === "object" && parent.object === node;
  15502. case "UpdateExpression":
  15503. if (parent.type === "UnaryExpression") {
  15504. return node.prefix && (node.operator === "++" && parent.operator === "+" || node.operator === "--" && parent.operator === "-");
  15505. }
  15506. // else fallthrough
  15507. case "UnaryExpression":
  15508. switch (parent.type) {
  15509. case "UnaryExpression":
  15510. return node.operator === parent.operator && (node.operator === "+" || node.operator === "-");
  15511. case "MemberExpression":
  15512. return name === "object" && parent.object === node;
  15513. case "TaggedTemplateExpression":
  15514. return true;
  15515. case "NewExpression":
  15516. case "CallExpression":
  15517. return name === "callee" && parent.callee === node;
  15518. case "BinaryExpression":
  15519. return parent.operator === "**" && name === "left";
  15520. case "TSNonNullExpression":
  15521. return true;
  15522. default:
  15523. return false;
  15524. }
  15525. case "BinaryExpression":
  15526. {
  15527. if (parent.type === "UpdateExpression") {
  15528. return true;
  15529. }
  15530. var isLeftOfAForStatement = function isLeftOfAForStatement(node) {
  15531. var i = 0;
  15532. while (node) {
  15533. var _parent = path$$1.getParentNode(i++);
  15534. if (!_parent) {
  15535. return false;
  15536. }
  15537. if (_parent.type === "ForStatement" && _parent.init === node) {
  15538. return true;
  15539. }
  15540. node = _parent;
  15541. }
  15542. return false;
  15543. };
  15544. if (node.operator === "in" && isLeftOfAForStatement(node)) {
  15545. return true;
  15546. }
  15547. }
  15548. // fallthrough
  15549. case "TSTypeAssertionExpression":
  15550. case "TSAsExpression":
  15551. case "LogicalExpression":
  15552. switch (parent.type) {
  15553. case "ConditionalExpression":
  15554. return node.type === "TSAsExpression";
  15555. case "CallExpression":
  15556. case "NewExpression":
  15557. return name === "callee" && parent.callee === node;
  15558. case "ClassDeclaration":
  15559. case "TSAbstractClassDeclaration":
  15560. return name === "superClass" && parent.superClass === node;
  15561. case "TSTypeAssertionExpression":
  15562. case "TaggedTemplateExpression":
  15563. case "UnaryExpression":
  15564. case "SpreadElement":
  15565. case "SpreadProperty":
  15566. case "ExperimentalSpreadProperty":
  15567. case "BindExpression":
  15568. case "AwaitExpression":
  15569. case "TSAsExpression":
  15570. case "TSNonNullExpression":
  15571. case "UpdateExpression":
  15572. return true;
  15573. case "MemberExpression":
  15574. return name === "object" && parent.object === node;
  15575. case "AssignmentExpression":
  15576. return parent.left === node && (node.type === "TSTypeAssertionExpression" || node.type === "TSAsExpression");
  15577. case "Decorator":
  15578. return parent.expression === node && (node.type === "TSTypeAssertionExpression" || node.type === "TSAsExpression");
  15579. case "BinaryExpression":
  15580. case "LogicalExpression":
  15581. {
  15582. if (!node.operator && node.type !== "TSTypeAssertionExpression") {
  15583. return true;
  15584. }
  15585. var po = parent.operator;
  15586. var pp = util$1.getPrecedence(po);
  15587. var no = node.operator;
  15588. var np = util$1.getPrecedence(no);
  15589. if (pp > np) {
  15590. return true;
  15591. }
  15592. if ((po === "||" || po === "??") && no === "&&") {
  15593. return true;
  15594. }
  15595. if (pp === np && name === "right") {
  15596. assert.strictEqual(parent.right, node);
  15597. return true;
  15598. }
  15599. if (pp === np && !util$1.shouldFlatten(po, no)) {
  15600. return true;
  15601. }
  15602. if (pp < np && no === "%") {
  15603. return !util$1.shouldFlatten(po, no);
  15604. } // Add parenthesis when working with binary operators
  15605. // It's not stricly needed but helps with code understanding
  15606. if (util$1.isBitwiseOperator(po)) {
  15607. return true;
  15608. }
  15609. return false;
  15610. }
  15611. default:
  15612. return false;
  15613. }
  15614. case "TSParenthesizedType":
  15615. {
  15616. var grandParent = path$$1.getParentNode(1);
  15617. if ((parent.type === "TSTypeParameter" || parent.type === "TypeParameter" || parent.type === "VariableDeclarator" || parent.type === "TSTypeAnnotation" || parent.type === "GenericTypeAnnotation" || parent.type === "TSTypeReference") && node.typeAnnotation.type === "TSTypeAnnotation" && node.typeAnnotation.typeAnnotation.type !== "TSFunctionType" && grandParent.type !== "TSTypeOperator") {
  15618. return false;
  15619. } // Delegate to inner TSParenthesizedType
  15620. if (node.typeAnnotation.type === "TSParenthesizedType") {
  15621. return false;
  15622. }
  15623. return true;
  15624. }
  15625. case "SequenceExpression":
  15626. switch (parent.type) {
  15627. case "ReturnStatement":
  15628. return false;
  15629. case "ForStatement":
  15630. // Although parentheses wouldn't hurt around sequence
  15631. // expressions in the head of for loops, traditional style
  15632. // dictates that e.g. i++, j++ should not be wrapped with
  15633. // parentheses.
  15634. return false;
  15635. case "ExpressionStatement":
  15636. return name !== "expression";
  15637. case "ArrowFunctionExpression":
  15638. // We do need parentheses, but SequenceExpressions are handled
  15639. // specially when printing bodies of arrow functions.
  15640. return name !== "body";
  15641. default:
  15642. // Otherwise err on the side of overparenthesization, adding
  15643. // explicit exceptions above if this proves overzealous.
  15644. return true;
  15645. }
  15646. case "YieldExpression":
  15647. if (parent.type === "UnaryExpression" || parent.type === "AwaitExpression" || parent.type === "TSAsExpression" || parent.type === "TSNonNullExpression") {
  15648. return true;
  15649. }
  15650. // else fallthrough
  15651. case "AwaitExpression":
  15652. switch (parent.type) {
  15653. case "TaggedTemplateExpression":
  15654. case "UnaryExpression":
  15655. case "BinaryExpression":
  15656. case "LogicalExpression":
  15657. case "SpreadElement":
  15658. case "SpreadProperty":
  15659. case "ExperimentalSpreadProperty":
  15660. case "TSAsExpression":
  15661. case "TSNonNullExpression":
  15662. return true;
  15663. case "MemberExpression":
  15664. return parent.object === node;
  15665. case "NewExpression":
  15666. case "CallExpression":
  15667. return parent.callee === node;
  15668. case "ConditionalExpression":
  15669. return parent.test === node;
  15670. default:
  15671. return false;
  15672. }
  15673. case "ArrayTypeAnnotation":
  15674. return parent.type === "NullableTypeAnnotation";
  15675. case "IntersectionTypeAnnotation":
  15676. case "UnionTypeAnnotation":
  15677. return parent.type === "ArrayTypeAnnotation" || parent.type === "NullableTypeAnnotation" || parent.type === "IntersectionTypeAnnotation" || parent.type === "UnionTypeAnnotation";
  15678. case "NullableTypeAnnotation":
  15679. return parent.type === "ArrayTypeAnnotation";
  15680. case "FunctionTypeAnnotation":
  15681. {
  15682. var ancestor = parent.type === "NullableTypeAnnotation" ? path$$1.getParentNode(1) : parent;
  15683. return ancestor.type === "UnionTypeAnnotation" || ancestor.type === "IntersectionTypeAnnotation" || ancestor.type === "ArrayTypeAnnotation" || // We should check ancestor's parent to know whether the parentheses
  15684. // are really needed, but since ??T doesn't make sense this check
  15685. // will almost never be true.
  15686. ancestor.type === "NullableTypeAnnotation";
  15687. }
  15688. case "StringLiteral":
  15689. case "NumericLiteral":
  15690. case "Literal":
  15691. if (typeof node.value === "string" && parent.type === "ExpressionStatement" && ( // TypeScript workaround for eslint/typescript-eslint-parser#267
  15692. // See corresponding workaround in printer.js case: "Literal"
  15693. options.parser !== "typescript" && !parent.directive || options.parser === "typescript" && options.originalText.substr(options.locStart(node) - 1, 1) === "(")) {
  15694. // To avoid becoming a directive
  15695. var _grandParent = path$$1.getParentNode(1);
  15696. return _grandParent.type === "Program" || _grandParent.type === "BlockStatement";
  15697. }
  15698. return parent.type === "MemberExpression" && typeof node.value === "number" && name === "object" && parent.object === node;
  15699. case "AssignmentExpression":
  15700. {
  15701. var _grandParent2 = path$$1.getParentNode(1);
  15702. if (parent.type === "ArrowFunctionExpression" && parent.body === node) {
  15703. return true;
  15704. } else if (parent.type === "ClassProperty" && parent.key === node && parent.computed) {
  15705. return false;
  15706. } else if (parent.type === "TSPropertySignature" && parent.name === node) {
  15707. return false;
  15708. } else if (parent.type === "ForStatement" && (parent.init === node || parent.update === node)) {
  15709. return false;
  15710. } else if (parent.type === "ExpressionStatement") {
  15711. return node.left.type === "ObjectPattern";
  15712. } else if (parent.type === "TSPropertySignature" && parent.key === node) {
  15713. return false;
  15714. } else if (parent.type === "AssignmentExpression") {
  15715. return false;
  15716. } else if (parent.type === "SequenceExpression" && _grandParent2 && _grandParent2.type === "ForStatement" && (_grandParent2.init === parent || _grandParent2.update === parent)) {
  15717. return false;
  15718. }
  15719. return true;
  15720. }
  15721. case "ConditionalExpression":
  15722. switch (parent.type) {
  15723. case "TaggedTemplateExpression":
  15724. case "UnaryExpression":
  15725. case "SpreadElement":
  15726. case "SpreadProperty":
  15727. case "ExperimentalSpreadProperty":
  15728. case "BinaryExpression":
  15729. case "LogicalExpression":
  15730. case "ExportDefaultDeclaration":
  15731. case "AwaitExpression":
  15732. case "JSXSpreadAttribute":
  15733. case "TSTypeAssertionExpression":
  15734. case "TypeCastExpression":
  15735. case "TSAsExpression":
  15736. case "TSNonNullExpression":
  15737. return true;
  15738. case "NewExpression":
  15739. case "CallExpression":
  15740. return name === "callee" && parent.callee === node;
  15741. case "ConditionalExpression":
  15742. return name === "test" && parent.test === node;
  15743. case "MemberExpression":
  15744. return name === "object" && parent.object === node;
  15745. default:
  15746. return false;
  15747. }
  15748. case "FunctionExpression":
  15749. switch (parent.type) {
  15750. case "CallExpression":
  15751. return name === "callee";
  15752. // Not strictly necessary, but it's clearer to the reader if IIFEs are wrapped in parentheses.
  15753. case "TaggedTemplateExpression":
  15754. return true;
  15755. // This is basically a kind of IIFE.
  15756. case "ExportDefaultDeclaration":
  15757. return true;
  15758. default:
  15759. return false;
  15760. }
  15761. case "ArrowFunctionExpression":
  15762. switch (parent.type) {
  15763. case "CallExpression":
  15764. return name === "callee";
  15765. case "NewExpression":
  15766. return name === "callee";
  15767. case "MemberExpression":
  15768. return name === "object";
  15769. case "TSAsExpression":
  15770. case "BindExpression":
  15771. case "TaggedTemplateExpression":
  15772. case "UnaryExpression":
  15773. case "LogicalExpression":
  15774. case "BinaryExpression":
  15775. case "AwaitExpression":
  15776. case "TSTypeAssertionExpression":
  15777. return true;
  15778. case "ConditionalExpression":
  15779. return name === "test";
  15780. default:
  15781. return false;
  15782. }
  15783. case "ClassExpression":
  15784. return parent.type === "ExportDefaultDeclaration";
  15785. case "OptionalMemberExpression":
  15786. return parent.type === "MemberExpression";
  15787. }
  15788. return false;
  15789. }
  15790. function isStatement(node) {
  15791. 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 === "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 === "TSAbstractClassDeclaration" || 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";
  15792. }
  15793. var needsParens_1 = needsParens;
  15794. var getParentExportDeclaration$1 = util$1.getParentExportDeclaration;
  15795. var isExportDeclaration$1 = util$1.isExportDeclaration;
  15796. var shouldFlatten$1 = util$1.shouldFlatten;
  15797. var getNextNonSpaceNonCommentCharacter$1 = util$1.getNextNonSpaceNonCommentCharacter;
  15798. var hasNewline$2 = util$1.hasNewline;
  15799. var hasNewlineInRange$1 = util$1.hasNewlineInRange;
  15800. var getLast$4 = util$1.getLast;
  15801. var getStringWidth$1 = util$1.getStringWidth;
  15802. var printString$1 = util$1.printString;
  15803. var printNumber$1 = util$1.printNumber;
  15804. var hasIgnoreComment$1 = util$1.hasIgnoreComment;
  15805. var skipWhitespace$1 = util$1.skipWhitespace;
  15806. var hasNodeIgnoreComment$1 = util$1.hasNodeIgnoreComment;
  15807. var getPenultimate$1 = util$1.getPenultimate;
  15808. var startsWithNoLookaheadToken$1 = util$1.startsWithNoLookaheadToken;
  15809. var getIndentSize$1 = util$1.getIndentSize;
  15810. var isNextLineEmpty$2 = utilShared.isNextLineEmpty;
  15811. var isNextLineEmptyAfterIndex$1 = utilShared.isNextLineEmptyAfterIndex;
  15812. var getNextNonSpaceNonCommentCharacterIndex$2 = utilShared.getNextNonSpaceNonCommentCharacterIndex;
  15813. var isIdentifierName = utils.keyword.isIdentifierNameES6;
  15814. var insertPragma = pragma.insertPragma;
  15815. var _require$$4$builders = doc.builders;
  15816. var concat$4 = _require$$4$builders.concat;
  15817. var join$2 = _require$$4$builders.join;
  15818. var line$3 = _require$$4$builders.line;
  15819. var hardline$3 = _require$$4$builders.hardline;
  15820. var softline$1 = _require$$4$builders.softline;
  15821. var literalline$1 = _require$$4$builders.literalline;
  15822. var group$1 = _require$$4$builders.group;
  15823. var indent$2 = _require$$4$builders.indent;
  15824. var align$1 = _require$$4$builders.align;
  15825. var conditionalGroup$1 = _require$$4$builders.conditionalGroup;
  15826. var fill$2 = _require$$4$builders.fill;
  15827. var ifBreak$1 = _require$$4$builders.ifBreak;
  15828. var breakParent$2 = _require$$4$builders.breakParent;
  15829. var lineSuffixBoundary$1 = _require$$4$builders.lineSuffixBoundary;
  15830. var addAlignmentToDoc$2 = _require$$4$builders.addAlignmentToDoc;
  15831. var dedent$2 = _require$$4$builders.dedent;
  15832. var _require$$4$utils = doc.utils;
  15833. var willBreak$1 = _require$$4$utils.willBreak;
  15834. var isLineNext$1 = _require$$4$utils.isLineNext;
  15835. var isEmpty$1 = _require$$4$utils.isEmpty;
  15836. var removeLines$1 = _require$$4$utils.removeLines;
  15837. var printDocToString$2 = doc.printer.printDocToString;
  15838. function shouldPrintComma(options, level) {
  15839. level = level || "es5";
  15840. switch (options.trailingComma) {
  15841. case "all":
  15842. if (level === "all") {
  15843. return true;
  15844. }
  15845. // fallthrough
  15846. case "es5":
  15847. if (level === "es5") {
  15848. return true;
  15849. }
  15850. // fallthrough
  15851. case "none":
  15852. default:
  15853. return false;
  15854. }
  15855. }
  15856. function genericPrint$1(path$$1, options, printPath, args) {
  15857. var node = path$$1.getValue();
  15858. var needsParens = false;
  15859. var linesWithoutParens = printPathNoParens(path$$1, options, printPath, args);
  15860. if (!node || isEmpty$1(linesWithoutParens)) {
  15861. return linesWithoutParens;
  15862. }
  15863. var decorators = [];
  15864. if (node.decorators && node.decorators.length > 0 && // If the parent node is an export declaration, it will be
  15865. // responsible for printing node.decorators.
  15866. !getParentExportDeclaration$1(path$$1)) {
  15867. var separator = hardline$3;
  15868. path$$1.each(function (decoratorPath) {
  15869. var decorator = decoratorPath.getValue();
  15870. if (decorator.expression) {
  15871. decorator = decorator.expression;
  15872. } else {
  15873. decorator = decorator.callee;
  15874. }
  15875. if (node.decorators.length === 1 && node.type !== "ClassDeclaration" && node.type !== "MethodDefinition" && node.type !== "ClassMethod" && (decorator.type === "Identifier" || decorator.type === "MemberExpression" || decorator.type === "OptionalMemberExpression" || (decorator.type === "CallExpression" || decorator.type === "OptionalCallExpression") && (decorator.arguments.length === 0 || decorator.arguments.length === 1 && (isStringLiteral(decorator.arguments[0]) || decorator.arguments[0].type === "Identifier" || decorator.arguments[0].type === "MemberExpression" || decorator.arguments[0].type === "OptionalMemberExpression")))) {
  15876. separator = line$3;
  15877. }
  15878. decorators.push(printPath(decoratorPath), separator);
  15879. }, "decorators");
  15880. } else if (isExportDeclaration$1(node) && node.declaration && node.declaration.decorators) {
  15881. // Export declarations are responsible for printing any decorators
  15882. // that logically apply to node.declaration.
  15883. path$$1.each(function (decoratorPath) {
  15884. var decorator = decoratorPath.getValue();
  15885. var prefix = decorator.type === "Decorator" ? "" : "@";
  15886. decorators.push(prefix, printPath(decoratorPath), hardline$3);
  15887. }, "declaration", "decorators");
  15888. } else {
  15889. // Nodes with decorators can't have parentheses, so we can avoid
  15890. // computing pathNeedsParens() except in this case.
  15891. needsParens = needsParens_1(path$$1, options);
  15892. }
  15893. var parts = [];
  15894. if (needsParens) {
  15895. parts.unshift("(");
  15896. }
  15897. parts.push(linesWithoutParens);
  15898. if (needsParens) {
  15899. parts.push(")");
  15900. }
  15901. if (decorators.length > 0) {
  15902. return group$1(concat$4(decorators.concat(parts)));
  15903. }
  15904. return concat$4(parts);
  15905. }
  15906. function hasPrettierIgnore(path$$1) {
  15907. return hasIgnoreComment$1(path$$1) || hasJsxIgnoreComment(path$$1);
  15908. }
  15909. function hasJsxIgnoreComment(path$$1) {
  15910. var node = path$$1.getValue();
  15911. var parent = path$$1.getParentNode();
  15912. if (!parent || !node || !isJSXNode(node) || !isJSXNode(parent)) {
  15913. return false;
  15914. } // Lookup the previous sibling, ignoring any empty JSXText elements
  15915. var index = parent.children.indexOf(node);
  15916. var prevSibling = null;
  15917. for (var i = index; i > 0; i--) {
  15918. var candidate = parent.children[i - 1];
  15919. if (candidate.type === "JSXText" && !isMeaningfulJSXText(candidate)) {
  15920. continue;
  15921. }
  15922. prevSibling = candidate;
  15923. break;
  15924. }
  15925. return prevSibling && prevSibling.type === "JSXExpressionContainer" && prevSibling.expression.type === "JSXEmptyExpression" && prevSibling.expression.comments && prevSibling.expression.comments.find(function (comment) {
  15926. return comment.value.trim() === "prettier-ignore";
  15927. });
  15928. } // The following is the shared logic for
  15929. // ternary operators, namely ConditionalExpression
  15930. // and TSConditionalType
  15931. function formatTernaryOperator(path$$1, options, print, operatorOptions) {
  15932. var n = path$$1.getValue();
  15933. var parts = [];
  15934. var operatorOpts = Object.assign({
  15935. beforeParts: function beforeParts() {
  15936. return [""];
  15937. },
  15938. afterParts: function afterParts() {
  15939. return [""];
  15940. },
  15941. shouldCheckJsx: true,
  15942. operatorName: "ConditionalExpression",
  15943. consequentNode: "consequent",
  15944. alternateNode: "alternate",
  15945. testNode: "test",
  15946. breakNested: true
  15947. }, operatorOptions || {}); // We print a ConditionalExpression in either "JSX mode" or "normal mode".
  15948. // See tests/jsx/conditional-expression.js for more info.
  15949. var jsxMode = false;
  15950. var parent = path$$1.getParentNode();
  15951. var forceNoIndent = parent.type === operatorOpts.operatorName; // Find the outermost non-ConditionalExpression parent, and the outermost
  15952. // ConditionalExpression parent. We'll use these to determine if we should
  15953. // print in JSX mode.
  15954. var currentParent;
  15955. var previousParent;
  15956. var i = 0;
  15957. do {
  15958. previousParent = currentParent || n;
  15959. currentParent = path$$1.getParentNode(i);
  15960. i++;
  15961. } while (currentParent && currentParent.type === operatorOpts.operatorName);
  15962. var firstNonConditionalParent = currentParent || parent;
  15963. var lastConditionalParent = previousParent;
  15964. if (operatorOpts.shouldCheckJsx && isJSXNode(n[operatorOpts.testNode]) || isJSXNode(n[operatorOpts.consequentNode]) || isJSXNode(n[operatorOpts.alternateNode]) || conditionalExpressionChainContainsJSX(lastConditionalParent)) {
  15965. jsxMode = true;
  15966. forceNoIndent = true; // Even though they don't need parens, we wrap (almost) everything in
  15967. // parens when using ?: within JSX, because the parens are analogous to
  15968. // curly braces in an if statement.
  15969. var wrap = function wrap(doc$$2) {
  15970. return concat$4([ifBreak$1("(", ""), indent$2(concat$4([softline$1, doc$$2])), softline$1, ifBreak$1(")", "")]);
  15971. }; // The only things we don't wrap are:
  15972. // * Nested conditional expressions in alternates
  15973. // * null
  15974. var isNull = function isNull(node) {
  15975. return node.type === "NullLiteral" || node.type === "Literal" && node.value === null;
  15976. };
  15977. parts.push(" ? ", isNull(n[operatorOpts.consequentNode]) ? path$$1.call(print, operatorOpts.consequentNode) : wrap(path$$1.call(print, operatorOpts.consequentNode)), " : ", n[operatorOpts.alternateNode].type === operatorOpts.operatorName || isNull(n[operatorOpts.alternateNode]) ? path$$1.call(print, operatorOpts.alternateNode) : wrap(path$$1.call(print, operatorOpts.alternateNode)));
  15978. } else {
  15979. // normal mode
  15980. var part = concat$4([line$3, "? ", n[operatorOpts.consequentNode].type === operatorOpts.operatorName ? ifBreak$1("", "(") : "", align$1(2, path$$1.call(print, operatorOpts.consequentNode)), n[operatorOpts.consequentNode].type === operatorOpts.operatorName ? ifBreak$1("", ")") : "", line$3, ": ", align$1(2, path$$1.call(print, operatorOpts.alternateNode))]);
  15981. parts.push(parent.type === operatorOpts.operatorName ? options.useTabs ? dedent$2(indent$2(part)) : align$1(Math.max(0, options.tabWidth - 2), part) : part);
  15982. } // We want a whole chain of ConditionalExpressions to all
  15983. // break if any of them break. That means we should only group around the
  15984. // outer-most ConditionalExpression.
  15985. var maybeGroup = function maybeGroup(doc$$2) {
  15986. return operatorOpts.breakNested ? parent === firstNonConditionalParent ? group$1(doc$$2) : doc$$2 : group$1(doc$$2);
  15987. }; // Always group in normal mode.
  15988. // Break the closing paren to keep the chain right after it:
  15989. // (a
  15990. // ? b
  15991. // : c
  15992. // ).call()
  15993. var breakClosingParen = !jsxMode && (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && !parent.computed;
  15994. return maybeGroup(concat$4([].concat(operatorOpts.beforeParts(), forceNoIndent ? concat$4(parts) : indent$2(concat$4(parts)), operatorOpts.afterParts(breakClosingParen))));
  15995. }
  15996. function getTypeScriptMappedTypeModifier(tokenNode, keyword) {
  15997. if (tokenNode.type === "TSPlusToken") {
  15998. return "+" + keyword;
  15999. } else if (tokenNode.type === "TSMinusToken") {
  16000. return "-" + keyword;
  16001. }
  16002. return keyword;
  16003. }
  16004. function printPathNoParens(path$$1, options, print, args) {
  16005. var n = path$$1.getValue();
  16006. var semi = options.semi ? ";" : "";
  16007. if (!n) {
  16008. return "";
  16009. }
  16010. if (typeof n === "string") {
  16011. return n;
  16012. }
  16013. var parts = [];
  16014. switch (n.type) {
  16015. case "File":
  16016. // Print @babel/parser's InterpreterDirective here so that
  16017. // leading comments on the `Program` node get printed after the hashbang.
  16018. if (n.program && n.program.interpreter) {
  16019. parts.push(path$$1.call(function (programPath) {
  16020. return programPath.call(print, "interpreter");
  16021. }, "program"));
  16022. }
  16023. parts.push(path$$1.call(print, "program"));
  16024. return concat$4(parts);
  16025. case "Program":
  16026. // Babel 6
  16027. if (n.directives) {
  16028. path$$1.each(function (childPath) {
  16029. parts.push(print(childPath), semi, hardline$3);
  16030. if (isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  16031. parts.push(hardline$3);
  16032. }
  16033. }, "directives");
  16034. }
  16035. parts.push(path$$1.call(function (bodyPath) {
  16036. return printStatementSequence(bodyPath, options, print);
  16037. }, "body"));
  16038. parts.push(comments.printDanglingComments(path$$1, options,
  16039. /* sameIndent */
  16040. true)); // Only force a trailing newline if there were any contents.
  16041. if (n.body.length || n.comments) {
  16042. parts.push(hardline$3);
  16043. }
  16044. return concat$4(parts);
  16045. // Babel extension.
  16046. case "EmptyStatement":
  16047. return "";
  16048. case "ExpressionStatement":
  16049. // Detect Flow-parsed directives
  16050. if (n.directive) {
  16051. return concat$4([nodeStr(n.expression, options, true), semi]);
  16052. } // Do not append semicolon after the only JSX element in a program
  16053. return concat$4([path$$1.call(print, "expression"), isTheOnlyJSXElementInMarkdown(options, path$$1) ? "" : semi]);
  16054. // Babel extension.
  16055. case "ParenthesizedExpression":
  16056. return concat$4(["(", path$$1.call(print, "expression"), ")"]);
  16057. case "AssignmentExpression":
  16058. return printAssignment(n.left, path$$1.call(print, "left"), concat$4([" ", n.operator]), n.right, path$$1.call(print, "right"), options);
  16059. case "BinaryExpression":
  16060. case "LogicalExpression":
  16061. {
  16062. var parent = path$$1.getParentNode();
  16063. var parentParent = path$$1.getParentNode(1);
  16064. var isInsideParenthesis = n !== parent.body && (parent.type === "IfStatement" || parent.type === "WhileStatement" || parent.type === "DoWhileStatement");
  16065. var _parts = printBinaryishExpressions(path$$1, print, options,
  16066. /* isNested */
  16067. false, isInsideParenthesis); // if (
  16068. // this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft
  16069. // ) {
  16070. //
  16071. // looks super weird, we want to break the children if the parent breaks
  16072. //
  16073. // if (
  16074. // this.hasPlugin("dynamicImports") &&
  16075. // this.lookahead().type === tt.parenLeft
  16076. // ) {
  16077. if (isInsideParenthesis) {
  16078. return concat$4(_parts);
  16079. } // Break between the parens in unaries or in a member expression, i.e.
  16080. //
  16081. // (
  16082. // a &&
  16083. // b &&
  16084. // c
  16085. // ).call()
  16086. if (parent.type === "UnaryExpression" || (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && !parent.computed) {
  16087. return group$1(concat$4([indent$2(concat$4([softline$1, concat$4(_parts)])), softline$1]));
  16088. } // Avoid indenting sub-expressions in some cases where the first sub-expression is already
  16089. // indented accordingly. We should indent sub-expressions where the first case isn't indented.
  16090. var shouldNotIndent = parent.type === "ReturnStatement" || parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" || n === parent.body && parent.type === "ArrowFunctionExpression" || n !== parent.body && parent.type === "ForStatement" || parent.type === "ConditionalExpression" && parentParent.type !== "ReturnStatement";
  16091. var shouldIndentIfInlining = parent.type === "AssignmentExpression" || parent.type === "VariableDeclarator" || parent.type === "ClassProperty" || parent.type === "TSAbstractClassProperty" || parent.type === "ClassPrivateProperty" || parent.type === "ObjectProperty" || parent.type === "Property";
  16092. var samePrecedenceSubExpression = isBinaryish(n.left) && shouldFlatten$1(n.operator, n.left.operator);
  16093. if (shouldNotIndent || shouldInlineLogicalExpression(n) && !samePrecedenceSubExpression || !shouldInlineLogicalExpression(n) && shouldIndentIfInlining) {
  16094. return group$1(concat$4(_parts));
  16095. }
  16096. var rest = concat$4(_parts.slice(1));
  16097. return group$1(concat$4([// Don't include the initial expression in the indentation
  16098. // level. The first item is guaranteed to be the first
  16099. // left-most expression.
  16100. _parts.length > 0 ? _parts[0] : "", indent$2(rest)]));
  16101. }
  16102. case "AssignmentPattern":
  16103. return concat$4([path$$1.call(print, "left"), " = ", path$$1.call(print, "right")]);
  16104. case "TSTypeAssertionExpression":
  16105. {
  16106. var shouldBreakAfterCast = !(n.expression.type === "ArrayExpression" || n.expression.type === "ObjectExpression");
  16107. var castGroup = group$1(concat$4(["<", indent$2(concat$4([softline$1, path$$1.call(print, "typeAnnotation")])), softline$1, ">"]));
  16108. var exprContents = concat$4([ifBreak$1("("), indent$2(concat$4([softline$1, path$$1.call(print, "expression")])), softline$1, ifBreak$1(")")]);
  16109. if (shouldBreakAfterCast) {
  16110. return conditionalGroup$1([concat$4([castGroup, path$$1.call(print, "expression")]), concat$4([castGroup, group$1(exprContents, {
  16111. shouldBreak: true
  16112. })]), concat$4([castGroup, path$$1.call(print, "expression")])]);
  16113. }
  16114. return group$1(concat$4([castGroup, path$$1.call(print, "expression")]));
  16115. }
  16116. case "OptionalMemberExpression":
  16117. case "MemberExpression":
  16118. {
  16119. var _parent = path$$1.getParentNode();
  16120. var firstNonMemberParent;
  16121. var i = 0;
  16122. do {
  16123. firstNonMemberParent = path$$1.getParentNode(i);
  16124. i++;
  16125. } while (firstNonMemberParent && (firstNonMemberParent.type === "MemberExpression" || firstNonMemberParent.type === "OptionalMemberExpression" || firstNonMemberParent.type === "TSNonNullExpression"));
  16126. 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" && _parent.type !== "MemberExpression" && _parent.type !== "OptionalMemberExpression";
  16127. return concat$4([path$$1.call(print, "object"), shouldInline ? printMemberLookup(path$$1, options, print) : group$1(indent$2(concat$4([softline$1, printMemberLookup(path$$1, options, print)])))]);
  16128. }
  16129. case "MetaProperty":
  16130. return concat$4([path$$1.call(print, "meta"), ".", path$$1.call(print, "property")]);
  16131. case "BindExpression":
  16132. if (n.object) {
  16133. parts.push(path$$1.call(print, "object"));
  16134. }
  16135. parts.push(group$1(indent$2(concat$4([softline$1, printBindExpressionCallee(path$$1, options, print)]))));
  16136. return concat$4(parts);
  16137. case "Identifier":
  16138. {
  16139. return concat$4([n.name, printOptionalToken(path$$1), printTypeAnnotation(path$$1, options, print)]);
  16140. }
  16141. case "SpreadElement":
  16142. case "SpreadElementPattern":
  16143. case "RestProperty":
  16144. case "ExperimentalRestProperty":
  16145. case "ExperimentalSpreadProperty":
  16146. case "SpreadProperty":
  16147. case "SpreadPropertyPattern":
  16148. case "RestElement":
  16149. case "ObjectTypeSpreadProperty":
  16150. return concat$4(["...", path$$1.call(print, "argument"), printTypeAnnotation(path$$1, options, print)]);
  16151. case "FunctionDeclaration":
  16152. case "FunctionExpression":
  16153. if (isNodeStartingWithDeclare(n, options)) {
  16154. parts.push("declare ");
  16155. }
  16156. parts.push(printFunctionDeclaration(path$$1, print, options));
  16157. if (!n.body) {
  16158. parts.push(semi);
  16159. }
  16160. return concat$4(parts);
  16161. case "ArrowFunctionExpression":
  16162. {
  16163. if (n.async) {
  16164. parts.push("async ");
  16165. }
  16166. if (shouldPrintParamsWithoutParens(path$$1, options)) {
  16167. parts.push(path$$1.call(print, "params", 0));
  16168. } else {
  16169. parts.push(group$1(concat$4([printFunctionParams(path$$1, print, options,
  16170. /* expandLast */
  16171. args && (args.expandLastArg || args.expandFirstArg),
  16172. /* printTypeParams */
  16173. true), printReturnType(path$$1, print, options)])));
  16174. }
  16175. var dangling = comments.printDanglingComments(path$$1, options,
  16176. /* sameIndent */
  16177. true, function (comment) {
  16178. var nextCharacter = getNextNonSpaceNonCommentCharacterIndex$2(options.originalText, comment, options);
  16179. return options.originalText.substr(nextCharacter, 2) === "=>";
  16180. });
  16181. if (dangling) {
  16182. parts.push(" ", dangling);
  16183. }
  16184. parts.push(" =>");
  16185. var body = path$$1.call(function (bodyPath) {
  16186. return print(bodyPath, args);
  16187. }, "body"); // We want to always keep these types of nodes on the same line
  16188. // as the arrow.
  16189. if (!hasLeadingOwnLineComment(options.originalText, n.body, options) && (n.body.type === "ArrayExpression" || n.body.type === "ObjectExpression" || n.body.type === "BlockStatement" || isJSXNode(n.body) || isTemplateOnItsOwnLine(n.body, options.originalText, options) || n.body.type === "ArrowFunctionExpression" || n.body.type === "DoExpression")) {
  16190. return group$1(concat$4([concat$4(parts), " ", body]));
  16191. } // We handle sequence expressions as the body of arrows specially,
  16192. // so that the required parentheses end up on their own lines.
  16193. if (n.body.type === "SequenceExpression") {
  16194. return group$1(concat$4([concat$4(parts), group$1(concat$4([" (", indent$2(concat$4([softline$1, body])), softline$1, ")"]))]));
  16195. } // if the arrow function is expanded as last argument, we are adding a
  16196. // level of indentation and need to add a softline to align the closing )
  16197. // with the opening (, or if it's inside a JSXExpression (e.g. an attribute)
  16198. // we should align the expression's closing } with the line with the opening {.
  16199. var shouldAddSoftLine = (args && args.expandLastArg || path$$1.getParentNode().type === "JSXExpressionContainer") && !(n.comments && n.comments.length);
  16200. var printTrailingComma = args && args.expandLastArg && shouldPrintComma(options, "all"); // In order to avoid confusion between
  16201. // a => a ? a : a
  16202. // a <= a ? a : a
  16203. var shouldAddParens = n.body.type === "ConditionalExpression" && !startsWithNoLookaheadToken$1(n.body,
  16204. /* forbidFunctionAndClass */
  16205. false);
  16206. return group$1(concat$4([concat$4(parts), group$1(concat$4([indent$2(concat$4([line$3, shouldAddParens ? ifBreak$1("", "(") : "", body, shouldAddParens ? ifBreak$1("", ")") : ""])), shouldAddSoftLine ? concat$4([ifBreak$1(printTrailingComma ? "," : ""), softline$1]) : ""]))]));
  16207. }
  16208. case "MethodDefinition":
  16209. case "TSAbstractMethodDefinition":
  16210. if (n.accessibility) {
  16211. parts.push(n.accessibility + " ");
  16212. }
  16213. if (n.static) {
  16214. parts.push("static ");
  16215. }
  16216. if (n.type === "TSAbstractMethodDefinition") {
  16217. parts.push("abstract ");
  16218. }
  16219. parts.push(printMethod(path$$1, options, print));
  16220. return concat$4(parts);
  16221. case "YieldExpression":
  16222. parts.push("yield");
  16223. if (n.delegate) {
  16224. parts.push("*");
  16225. }
  16226. if (n.argument) {
  16227. parts.push(" ", path$$1.call(print, "argument"));
  16228. }
  16229. return concat$4(parts);
  16230. case "AwaitExpression":
  16231. return concat$4(["await ", path$$1.call(print, "argument")]);
  16232. case "ImportSpecifier":
  16233. if (n.importKind) {
  16234. parts.push(path$$1.call(print, "importKind"), " ");
  16235. }
  16236. parts.push(path$$1.call(print, "imported"));
  16237. if (n.local && n.local.name !== n.imported.name) {
  16238. parts.push(" as ", path$$1.call(print, "local"));
  16239. }
  16240. return concat$4(parts);
  16241. case "ExportSpecifier":
  16242. parts.push(path$$1.call(print, "local"));
  16243. if (n.exported && n.exported.name !== n.local.name) {
  16244. parts.push(" as ", path$$1.call(print, "exported"));
  16245. }
  16246. return concat$4(parts);
  16247. case "ImportNamespaceSpecifier":
  16248. parts.push("* as ");
  16249. if (n.local) {
  16250. parts.push(path$$1.call(print, "local"));
  16251. } else if (n.id) {
  16252. parts.push(path$$1.call(print, "id"));
  16253. }
  16254. return concat$4(parts);
  16255. case "ImportDefaultSpecifier":
  16256. if (n.local) {
  16257. return path$$1.call(print, "local");
  16258. }
  16259. return path$$1.call(print, "id");
  16260. case "TSExportAssignment":
  16261. return concat$4(["export = ", path$$1.call(print, "expression"), semi]);
  16262. case "ExportDefaultDeclaration":
  16263. case "ExportNamedDeclaration":
  16264. return printExportDeclaration(path$$1, options, print);
  16265. case "ExportAllDeclaration":
  16266. parts.push("export ");
  16267. if (n.exportKind === "type") {
  16268. parts.push("type ");
  16269. }
  16270. parts.push("* from ", path$$1.call(print, "source"), semi);
  16271. return concat$4(parts);
  16272. case "ExportNamespaceSpecifier":
  16273. case "ExportDefaultSpecifier":
  16274. return path$$1.call(print, "exported");
  16275. case "ImportDeclaration":
  16276. {
  16277. parts.push("import ");
  16278. if (n.importKind && n.importKind !== "value") {
  16279. parts.push(n.importKind + " ");
  16280. }
  16281. var standalones = [];
  16282. var grouped = [];
  16283. if (n.specifiers && n.specifiers.length > 0) {
  16284. path$$1.each(function (specifierPath) {
  16285. var value = specifierPath.getValue();
  16286. if (value.type === "ImportDefaultSpecifier" || value.type === "ImportNamespaceSpecifier") {
  16287. standalones.push(print(specifierPath));
  16288. } else {
  16289. grouped.push(print(specifierPath));
  16290. }
  16291. }, "specifiers");
  16292. if (standalones.length > 0) {
  16293. parts.push(join$2(", ", standalones));
  16294. }
  16295. if (standalones.length > 0 && grouped.length > 0) {
  16296. parts.push(", ");
  16297. }
  16298. if (grouped.length === 1 && standalones.length === 0 && n.specifiers && !n.specifiers.some(function (node) {
  16299. return node.comments;
  16300. })) {
  16301. parts.push(concat$4(["{", options.bracketSpacing ? " " : "", concat$4(grouped), options.bracketSpacing ? " " : "", "}"]));
  16302. } else if (grouped.length >= 1) {
  16303. parts.push(group$1(concat$4(["{", indent$2(concat$4([options.bracketSpacing ? line$3 : softline$1, join$2(concat$4([",", line$3]), grouped)])), ifBreak$1(shouldPrintComma(options) ? "," : ""), options.bracketSpacing ? line$3 : softline$1, "}"])));
  16304. }
  16305. parts.push(" from ");
  16306. } else if (n.importKind && n.importKind === "type" || // import {} from 'x'
  16307. /{\s*}/.test(options.originalText.slice(options.locStart(n), options.locStart(n.source)))) {
  16308. parts.push("{} from ");
  16309. }
  16310. parts.push(path$$1.call(print, "source"), semi);
  16311. return concat$4(parts);
  16312. }
  16313. case "Import":
  16314. return "import";
  16315. case "BlockStatement":
  16316. {
  16317. var naked = path$$1.call(function (bodyPath) {
  16318. return printStatementSequence(bodyPath, options, print);
  16319. }, "body");
  16320. var hasContent = n.body.find(function (node) {
  16321. return node.type !== "EmptyStatement";
  16322. });
  16323. var hasDirectives = n.directives && n.directives.length > 0;
  16324. var _parent2 = path$$1.getParentNode();
  16325. var _parentParent = path$$1.getParentNode(1);
  16326. if (!hasContent && !hasDirectives && !hasDanglingComments(n) && (_parent2.type === "ArrowFunctionExpression" || _parent2.type === "FunctionExpression" || _parent2.type === "FunctionDeclaration" || _parent2.type === "ObjectMethod" || _parent2.type === "ClassMethod" || _parent2.type === "ForStatement" || _parent2.type === "WhileStatement" || _parent2.type === "DoWhileStatement" || _parent2.type === "DoExpression" || _parent2.type === "CatchClause" && !_parentParent.finalizer)) {
  16327. return "{}";
  16328. }
  16329. parts.push("{"); // Babel 6
  16330. if (hasDirectives) {
  16331. path$$1.each(function (childPath) {
  16332. parts.push(indent$2(concat$4([hardline$3, print(childPath), semi])));
  16333. if (isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  16334. parts.push(hardline$3);
  16335. }
  16336. }, "directives");
  16337. }
  16338. if (hasContent) {
  16339. parts.push(indent$2(concat$4([hardline$3, naked])));
  16340. }
  16341. parts.push(comments.printDanglingComments(path$$1, options));
  16342. parts.push(hardline$3, "}");
  16343. return concat$4(parts);
  16344. }
  16345. case "ReturnStatement":
  16346. parts.push("return");
  16347. if (n.argument) {
  16348. if (returnArgumentHasLeadingComment(options, n.argument)) {
  16349. parts.push(concat$4([" (", indent$2(concat$4([hardline$3, path$$1.call(print, "argument")])), hardline$3, ")"]));
  16350. } else if (n.argument.type === "LogicalExpression" || n.argument.type === "BinaryExpression" || n.argument.type === "SequenceExpression") {
  16351. parts.push(group$1(concat$4([ifBreak$1(" (", " "), indent$2(concat$4([softline$1, path$$1.call(print, "argument")])), softline$1, ifBreak$1(")")])));
  16352. } else {
  16353. parts.push(" ", path$$1.call(print, "argument"));
  16354. }
  16355. }
  16356. if (hasDanglingComments(n)) {
  16357. parts.push(" ", comments.printDanglingComments(path$$1, options,
  16358. /* sameIndent */
  16359. true));
  16360. }
  16361. parts.push(semi);
  16362. return concat$4(parts);
  16363. case "NewExpression":
  16364. case "OptionalCallExpression":
  16365. case "CallExpression":
  16366. {
  16367. var isNew = n.type === "NewExpression";
  16368. var optional = printOptionalToken(path$$1);
  16369. if ( // We want to keep CommonJS- and AMD-style require calls, and AMD-style
  16370. // define calls, as a unit.
  16371. // e.g. `define(["some/lib", (lib) => {`
  16372. !isNew && n.callee.type === "Identifier" && (n.callee.name === "require" || n.callee.name === "define") || n.callee.type === "Import" || // Template literals as single arguments
  16373. n.arguments.length === 1 && isTemplateOnItsOwnLine(n.arguments[0], options.originalText, options) || // Keep test declarations on a single line
  16374. // e.g. `it('long name', () => {`
  16375. !isNew && isTestCall(n, path$$1.getParentNode())) {
  16376. return concat$4([isNew ? "new " : "", path$$1.call(print, "callee"), optional, printFunctionTypeParameters(path$$1, options, print), concat$4(["(", join$2(", ", path$$1.map(print, "arguments")), ")"])]);
  16377. } // We detect calls on member lookups and possibly print them in a
  16378. // special chain format. See `printMemberChain` for more info.
  16379. if (!isNew && isMemberish(n.callee)) {
  16380. return printMemberChain(path$$1, options, print);
  16381. }
  16382. return concat$4([isNew ? "new " : "", path$$1.call(print, "callee"), optional, printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)]);
  16383. }
  16384. case "TSInterfaceDeclaration":
  16385. if (isNodeStartingWithDeclare(n, options)) {
  16386. parts.push("declare ");
  16387. }
  16388. parts.push(n.abstract ? "abstract " : "", printTypeScriptModifiers(path$$1, options, print), "interface ", path$$1.call(print, "id"), n.typeParameters ? path$$1.call(print, "typeParameters") : "", " ");
  16389. if (n.heritage.length) {
  16390. parts.push(group$1(indent$2(concat$4([softline$1, "extends ", indent$2(join$2(concat$4([",", line$3]), path$$1.map(print, "heritage"))), " "]))));
  16391. }
  16392. parts.push(path$$1.call(print, "body"));
  16393. return concat$4(parts);
  16394. case "ObjectExpression":
  16395. case "ObjectPattern":
  16396. case "ObjectTypeAnnotation":
  16397. case "TSInterfaceBody":
  16398. case "TSTypeLiteral":
  16399. {
  16400. var isTypeAnnotation = n.type === "ObjectTypeAnnotation";
  16401. var _parent3 = path$$1.getParentNode(0);
  16402. var shouldBreak = n.type === "TSInterfaceBody" || n.type === "ObjectPattern" && _parent3.type !== "FunctionDeclaration" && _parent3.type !== "FunctionExpression" && _parent3.type !== "ArrowFunctionExpression" && _parent3.type !== "AssignmentPattern" && _parent3.type !== "CatchClause" && n.properties.some(function (property) {
  16403. return property.value && (property.value.type === "ObjectPattern" || property.value.type === "ArrayPattern");
  16404. }) || n.type !== "ObjectPattern" && hasNewlineInRange$1(options.originalText, options.locStart(n), options.locEnd(n));
  16405. var isFlowInterfaceLikeBody = isTypeAnnotation && _parent3 && (_parent3.type === "InterfaceDeclaration" || _parent3.type === "DeclareInterface" || _parent3.type === "DeclareClass") && path$$1.getName() === "body";
  16406. var separator = isFlowInterfaceLikeBody ? ";" : n.type === "TSInterfaceBody" || n.type === "TSTypeLiteral" ? ifBreak$1(semi, ";") : ",";
  16407. var fields = [];
  16408. var leftBrace = n.exact ? "{|" : "{";
  16409. var rightBrace = n.exact ? "|}" : "}";
  16410. var propertiesField;
  16411. if (n.type === "TSTypeLiteral") {
  16412. propertiesField = "members";
  16413. } else if (n.type === "TSInterfaceBody") {
  16414. propertiesField = "body";
  16415. } else {
  16416. propertiesField = "properties";
  16417. }
  16418. if (isTypeAnnotation) {
  16419. fields.push("indexers", "callProperties");
  16420. }
  16421. fields.push(propertiesField); // Unfortunately, things are grouped together in the ast can be
  16422. // interleaved in the source code. So we need to reorder them before
  16423. // printing them.
  16424. var propsAndLoc = [];
  16425. fields.forEach(function (field) {
  16426. path$$1.each(function (childPath) {
  16427. var node = childPath.getValue();
  16428. propsAndLoc.push({
  16429. node: node,
  16430. printed: print(childPath),
  16431. loc: options.locStart(node)
  16432. });
  16433. }, field);
  16434. });
  16435. var separatorParts = [];
  16436. var props = propsAndLoc.sort(function (a, b) {
  16437. return a.loc - b.loc;
  16438. }).map(function (prop) {
  16439. var result = concat$4(separatorParts.concat(group$1(prop.printed)));
  16440. separatorParts = [separator, line$3];
  16441. if (prop.node.type === "TSPropertySignature" && hasNodeIgnoreComment$1(prop.node)) {
  16442. separatorParts.shift();
  16443. }
  16444. if (isNextLineEmpty$2(options.originalText, prop.node, options)) {
  16445. separatorParts.push(hardline$3);
  16446. }
  16447. return result;
  16448. });
  16449. var lastElem = getLast$4(n[propertiesField]);
  16450. var canHaveTrailingSeparator = !(lastElem && (lastElem.type === "RestProperty" || lastElem.type === "RestElement" || lastElem.type === "ExperimentalRestProperty" || hasNodeIgnoreComment$1(lastElem)));
  16451. var content;
  16452. if (props.length === 0 && !n.typeAnnotation) {
  16453. if (!hasDanglingComments(n)) {
  16454. return concat$4([leftBrace, rightBrace]);
  16455. }
  16456. content = group$1(concat$4([leftBrace, comments.printDanglingComments(path$$1, options), softline$1, rightBrace, printOptionalToken(path$$1)]));
  16457. } else {
  16458. content = concat$4([leftBrace, indent$2(concat$4([options.bracketSpacing ? line$3 : softline$1, concat$4(props)])), ifBreak$1(canHaveTrailingSeparator && (separator !== "," || shouldPrintComma(options)) ? separator : ""), concat$4([options.bracketSpacing ? line$3 : softline$1, rightBrace]), printOptionalToken(path$$1), printTypeAnnotation(path$$1, options, print)]);
  16459. } // If we inline the object as first argument of the parent, we don't want
  16460. // to create another group so that the object breaks before the return
  16461. // type
  16462. var parentParentParent = path$$1.getParentNode(2);
  16463. if (n.type === "ObjectPattern" && _parent3 && shouldHugArguments(_parent3) && _parent3.params[0] === n || shouldHugType(n) && parentParentParent && shouldHugArguments(parentParentParent) && parentParentParent.params[0].typeAnnotation && parentParentParent.params[0].typeAnnotation.typeAnnotation === n) {
  16464. return content;
  16465. }
  16466. return group$1(content, {
  16467. shouldBreak
  16468. });
  16469. }
  16470. // Babel 6
  16471. case "ObjectProperty": // Non-standard AST node type.
  16472. case "Property":
  16473. if (n.method || n.kind === "get" || n.kind === "set") {
  16474. return printMethod(path$$1, options, print);
  16475. }
  16476. if (n.shorthand) {
  16477. parts.push(path$$1.call(print, "value"));
  16478. } else {
  16479. var printedLeft;
  16480. if (n.computed) {
  16481. printedLeft = concat$4(["[", path$$1.call(print, "key"), "]"]);
  16482. } else {
  16483. printedLeft = printPropertyKey(path$$1, options, print);
  16484. }
  16485. parts.push(printAssignment(n.key, printedLeft, ":", n.value, path$$1.call(print, "value"), options));
  16486. }
  16487. return concat$4(parts);
  16488. // Babel 6
  16489. case "ClassMethod":
  16490. if (n.static) {
  16491. parts.push("static ");
  16492. }
  16493. parts = parts.concat(printObjectMethod(path$$1, options, print));
  16494. return concat$4(parts);
  16495. // Babel 6
  16496. case "ObjectMethod":
  16497. return printObjectMethod(path$$1, options, print);
  16498. case "Decorator":
  16499. return concat$4(["@", path$$1.call(print, "expression"), path$$1.call(print, "callee")]);
  16500. case "ArrayExpression":
  16501. case "ArrayPattern":
  16502. if (n.elements.length === 0) {
  16503. if (!hasDanglingComments(n)) {
  16504. parts.push("[]");
  16505. } else {
  16506. parts.push(group$1(concat$4(["[", comments.printDanglingComments(path$$1, options), softline$1, "]"])));
  16507. }
  16508. } else {
  16509. var _lastElem = getLast$4(n.elements);
  16510. var canHaveTrailingComma = !(_lastElem && _lastElem.type === "RestElement"); // JavaScript allows you to have empty elements in an array which
  16511. // changes its length based on the number of commas. The algorithm
  16512. // is that if the last argument is null, we need to force insert
  16513. // a comma to ensure JavaScript recognizes it.
  16514. // [,].length === 1
  16515. // [1,].length === 1
  16516. // [1,,].length === 2
  16517. //
  16518. // Note that getLast returns null if the array is empty, but
  16519. // we already check for an empty array just above so we are safe
  16520. var needsForcedTrailingComma = canHaveTrailingComma && _lastElem === null;
  16521. parts.push(group$1(concat$4(["[", indent$2(concat$4([softline$1, printArrayItems(path$$1, options, "elements", print)])), needsForcedTrailingComma ? "," : "", ifBreak$1(canHaveTrailingComma && !needsForcedTrailingComma && shouldPrintComma(options) ? "," : ""), comments.printDanglingComments(path$$1, options,
  16522. /* sameIndent */
  16523. true), softline$1, "]"])));
  16524. }
  16525. parts.push(printOptionalToken(path$$1), printTypeAnnotation(path$$1, options, print));
  16526. return concat$4(parts);
  16527. case "SequenceExpression":
  16528. {
  16529. var _parent4 = path$$1.getParentNode(0);
  16530. if (_parent4.type === "ExpressionStatement" || _parent4.type === "ForStatement") {
  16531. // For ExpressionStatements and for-loop heads, which are among
  16532. // the few places a SequenceExpression appears unparenthesized, we want
  16533. // to indent expressions after the first.
  16534. var _parts2 = [];
  16535. path$$1.each(function (p) {
  16536. if (p.getName() === 0) {
  16537. _parts2.push(print(p));
  16538. } else {
  16539. _parts2.push(",", indent$2(concat$4([line$3, print(p)])));
  16540. }
  16541. }, "expressions");
  16542. return group$1(concat$4(_parts2));
  16543. }
  16544. return group$1(concat$4([join$2(concat$4([",", line$3]), path$$1.map(print, "expressions"))]));
  16545. }
  16546. case "ThisExpression":
  16547. return "this";
  16548. case "Super":
  16549. return "super";
  16550. case "NullLiteral":
  16551. // Babel 6 Literal split
  16552. return "null";
  16553. case "RegExpLiteral":
  16554. // Babel 6 Literal split
  16555. return printRegex(n);
  16556. case "NumericLiteral":
  16557. // Babel 6 Literal split
  16558. return printNumber$1(n.extra.raw);
  16559. case "BooleanLiteral": // Babel 6 Literal split
  16560. case "StringLiteral": // Babel 6 Literal split
  16561. case "Literal":
  16562. {
  16563. if (n.regex) {
  16564. return printRegex(n.regex);
  16565. }
  16566. if (typeof n.value === "number") {
  16567. return printNumber$1(n.raw);
  16568. }
  16569. if (typeof n.value !== "string") {
  16570. return "" + n.value;
  16571. } // TypeScript workaround for eslint/typescript-eslint-parser#267
  16572. // See corresponding workaround in needs-parens.js
  16573. var grandParent = path$$1.getParentNode(1);
  16574. var isTypeScriptDirective = options.parser === "typescript" && typeof n.value === "string" && grandParent && (grandParent.type === "Program" || grandParent.type === "BlockStatement");
  16575. return nodeStr(n, options, isTypeScriptDirective);
  16576. }
  16577. case "Directive":
  16578. return path$$1.call(print, "value");
  16579. // Babel 6
  16580. case "DirectiveLiteral":
  16581. return nodeStr(n, options);
  16582. case "UnaryExpression":
  16583. parts.push(n.operator);
  16584. if (/[a-z]$/.test(n.operator)) {
  16585. parts.push(" ");
  16586. }
  16587. parts.push(path$$1.call(print, "argument"));
  16588. return concat$4(parts);
  16589. case "UpdateExpression":
  16590. parts.push(path$$1.call(print, "argument"), n.operator);
  16591. if (n.prefix) {
  16592. parts.reverse();
  16593. }
  16594. return concat$4(parts);
  16595. case "ConditionalExpression":
  16596. return formatTernaryOperator(path$$1, options, print, {
  16597. beforeParts: function beforeParts() {
  16598. return [path$$1.call(print, "test")];
  16599. },
  16600. afterParts: function afterParts(breakClosingParen) {
  16601. return [breakClosingParen ? softline$1 : ""];
  16602. }
  16603. });
  16604. case "VariableDeclaration":
  16605. {
  16606. var printed = path$$1.map(function (childPath) {
  16607. return print(childPath);
  16608. }, "declarations"); // We generally want to terminate all variable declarations with a
  16609. // semicolon, except when they in the () part of for loops.
  16610. var parentNode = path$$1.getParentNode();
  16611. var isParentForLoop = parentNode.type === "ForStatement" || parentNode.type === "ForInStatement" || parentNode.type === "ForOfStatement" || parentNode.type === "ForAwaitStatement";
  16612. var hasValue = n.declarations.some(function (decl) {
  16613. return decl.init;
  16614. });
  16615. var firstVariable;
  16616. if (printed.length === 1) {
  16617. firstVariable = printed[0];
  16618. } else if (printed.length > 1) {
  16619. // Indent first var to comply with eslint one-var rule
  16620. firstVariable = indent$2(printed[0]);
  16621. }
  16622. parts = [isNodeStartingWithDeclare(n, options) ? "declare " : "", n.kind, firstVariable ? concat$4([" ", firstVariable]) : "", indent$2(concat$4(printed.slice(1).map(function (p) {
  16623. return concat$4([",", hasValue && !isParentForLoop ? hardline$3 : line$3, p]);
  16624. })))];
  16625. if (!(isParentForLoop && parentNode.body !== n)) {
  16626. parts.push(semi);
  16627. }
  16628. return group$1(concat$4(parts));
  16629. }
  16630. case "VariableDeclarator":
  16631. return printAssignment(n.id, concat$4([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]), " =", n.init, n.init && path$$1.call(print, "init"), options);
  16632. case "WithStatement":
  16633. return group$1(concat$4(["with (", path$$1.call(print, "object"), ")", adjustClause(n.body, path$$1.call(print, "body"))]));
  16634. case "IfStatement":
  16635. {
  16636. var con = adjustClause(n.consequent, path$$1.call(print, "consequent"));
  16637. var opening = group$1(concat$4(["if (", group$1(concat$4([indent$2(concat$4([softline$1, path$$1.call(print, "test")])), softline$1])), ")", con]));
  16638. parts.push(opening);
  16639. if (n.alternate) {
  16640. var commentOnOwnLine = hasTrailingComment(n.consequent) && n.consequent.comments.some(function (comment) {
  16641. return comment.trailing && !comments$3.isBlockComment(comment);
  16642. }) || needsHardlineAfterDanglingComment(n);
  16643. var elseOnSameLine = n.consequent.type === "BlockStatement" && !commentOnOwnLine;
  16644. parts.push(elseOnSameLine ? " " : hardline$3);
  16645. if (hasDanglingComments(n)) {
  16646. parts.push(comments.printDanglingComments(path$$1, options, true), commentOnOwnLine ? hardline$3 : " ");
  16647. }
  16648. parts.push("else", group$1(adjustClause(n.alternate, path$$1.call(print, "alternate"), n.alternate.type === "IfStatement")));
  16649. }
  16650. return concat$4(parts);
  16651. }
  16652. case "ForStatement":
  16653. {
  16654. var _body = adjustClause(n.body, path$$1.call(print, "body")); // We want to keep dangling comments above the loop to stay consistent.
  16655. // Any comment positioned between the for statement and the parentheses
  16656. // is going to be printed before the statement.
  16657. var _dangling = comments.printDanglingComments(path$$1, options,
  16658. /* sameLine */
  16659. true);
  16660. var printedComments = _dangling ? concat$4([_dangling, softline$1]) : "";
  16661. if (!n.init && !n.test && !n.update) {
  16662. return concat$4([printedComments, group$1(concat$4(["for (;;)", _body]))]);
  16663. }
  16664. return concat$4([printedComments, group$1(concat$4(["for (", group$1(concat$4([indent$2(concat$4([softline$1, path$$1.call(print, "init"), ";", line$3, path$$1.call(print, "test"), ";", line$3, path$$1.call(print, "update")])), softline$1])), ")", _body]))]);
  16665. }
  16666. case "WhileStatement":
  16667. return group$1(concat$4(["while (", group$1(concat$4([indent$2(concat$4([softline$1, path$$1.call(print, "test")])), softline$1])), ")", adjustClause(n.body, path$$1.call(print, "body"))]));
  16668. case "ForInStatement":
  16669. // Note: esprima can't actually parse "for each (".
  16670. return group$1(concat$4([n.each ? "for each (" : "for (", path$$1.call(print, "left"), " in ", path$$1.call(print, "right"), ")", adjustClause(n.body, path$$1.call(print, "body"))]));
  16671. case "ForOfStatement":
  16672. case "ForAwaitStatement":
  16673. {
  16674. // Babylon 7 removed ForAwaitStatement in favor of ForOfStatement
  16675. // with `"await": true`:
  16676. // https://github.com/estree/estree/pull/138
  16677. var isAwait = n.type === "ForAwaitStatement" || n.await;
  16678. return group$1(concat$4(["for", isAwait ? " await" : "", " (", path$$1.call(print, "left"), " of ", path$$1.call(print, "right"), ")", adjustClause(n.body, path$$1.call(print, "body"))]));
  16679. }
  16680. case "DoWhileStatement":
  16681. {
  16682. var clause = adjustClause(n.body, path$$1.call(print, "body"));
  16683. var doBody = group$1(concat$4(["do", clause]));
  16684. parts = [doBody];
  16685. if (n.body.type === "BlockStatement") {
  16686. parts.push(" ");
  16687. } else {
  16688. parts.push(hardline$3);
  16689. }
  16690. parts.push("while (");
  16691. parts.push(group$1(concat$4([indent$2(concat$4([softline$1, path$$1.call(print, "test")])), softline$1])), ")", semi);
  16692. return concat$4(parts);
  16693. }
  16694. case "DoExpression":
  16695. return concat$4(["do ", path$$1.call(print, "body")]);
  16696. case "BreakStatement":
  16697. parts.push("break");
  16698. if (n.label) {
  16699. parts.push(" ", path$$1.call(print, "label"));
  16700. }
  16701. parts.push(semi);
  16702. return concat$4(parts);
  16703. case "ContinueStatement":
  16704. parts.push("continue");
  16705. if (n.label) {
  16706. parts.push(" ", path$$1.call(print, "label"));
  16707. }
  16708. parts.push(semi);
  16709. return concat$4(parts);
  16710. case "LabeledStatement":
  16711. if (n.body.type === "EmptyStatement") {
  16712. return concat$4([path$$1.call(print, "label"), ":;"]);
  16713. }
  16714. return concat$4([path$$1.call(print, "label"), ": ", path$$1.call(print, "body")]);
  16715. case "TryStatement":
  16716. return concat$4(["try ", path$$1.call(print, "block"), n.handler ? concat$4([" ", path$$1.call(print, "handler")]) : "", n.finalizer ? concat$4([" finally ", path$$1.call(print, "finalizer")]) : ""]);
  16717. case "CatchClause":
  16718. return concat$4(["catch ", n.param ? concat$4(["(", path$$1.call(print, "param"), ") "]) : "", path$$1.call(print, "body")]);
  16719. case "ThrowStatement":
  16720. return concat$4(["throw ", path$$1.call(print, "argument"), semi]);
  16721. // Note: ignoring n.lexical because it has no printing consequences.
  16722. case "SwitchStatement":
  16723. return concat$4([group$1(concat$4(["switch (", indent$2(concat$4([softline$1, path$$1.call(print, "discriminant")])), softline$1, ")"])), " {", n.cases.length > 0 ? indent$2(concat$4([hardline$3, join$2(hardline$3, path$$1.map(function (casePath) {
  16724. var caseNode = casePath.getValue();
  16725. return concat$4([casePath.call(print), n.cases.indexOf(caseNode) !== n.cases.length - 1 && isNextLineEmpty$2(options.originalText, caseNode, options) ? hardline$3 : ""]);
  16726. }, "cases"))])) : "", hardline$3, "}"]);
  16727. case "SwitchCase":
  16728. {
  16729. if (n.test) {
  16730. parts.push("case ", path$$1.call(print, "test"), ":");
  16731. } else {
  16732. parts.push("default:");
  16733. }
  16734. var consequent = n.consequent.filter(function (node) {
  16735. return node.type !== "EmptyStatement";
  16736. });
  16737. if (consequent.length > 0) {
  16738. var cons = path$$1.call(function (consequentPath) {
  16739. return printStatementSequence(consequentPath, options, print);
  16740. }, "consequent");
  16741. parts.push(consequent.length === 1 && consequent[0].type === "BlockStatement" ? concat$4([" ", cons]) : indent$2(concat$4([hardline$3, cons])));
  16742. }
  16743. return concat$4(parts);
  16744. }
  16745. // JSX extensions below.
  16746. case "DebuggerStatement":
  16747. return concat$4(["debugger", semi]);
  16748. case "JSXAttribute":
  16749. parts.push(path$$1.call(print, "name"));
  16750. if (n.value) {
  16751. var res;
  16752. if (isStringLiteral(n.value)) {
  16753. var value = rawText(n.value);
  16754. res = '"' + value.slice(1, -1).replace(/"/g, "&quot;") + '"';
  16755. } else {
  16756. res = path$$1.call(print, "value");
  16757. }
  16758. parts.push("=", res);
  16759. }
  16760. return concat$4(parts);
  16761. case "JSXIdentifier":
  16762. // Can be removed when this is fixed:
  16763. // https://github.com/eslint/typescript-eslint-parser/issues/337
  16764. if (!n.name) {
  16765. return "this";
  16766. }
  16767. return "" + n.name;
  16768. case "JSXNamespacedName":
  16769. return join$2(":", [path$$1.call(print, "namespace"), path$$1.call(print, "name")]);
  16770. case "JSXMemberExpression":
  16771. return join$2(".", [path$$1.call(print, "object"), path$$1.call(print, "property")]);
  16772. case "TSQualifiedName":
  16773. return join$2(".", [path$$1.call(print, "left"), path$$1.call(print, "right")]);
  16774. case "JSXSpreadAttribute":
  16775. case "JSXSpreadChild":
  16776. {
  16777. return concat$4(["{", path$$1.call(function (p) {
  16778. var printed = concat$4(["...", print(p)]);
  16779. var n = p.getValue();
  16780. if (!n.comments || !n.comments.length) {
  16781. return printed;
  16782. }
  16783. return concat$4([indent$2(concat$4([softline$1, comments.printComments(p, function () {
  16784. return printed;
  16785. }, options)])), softline$1]);
  16786. }, n.type === "JSXSpreadAttribute" ? "argument" : "expression"), "}"]);
  16787. }
  16788. case "JSXExpressionContainer":
  16789. {
  16790. var _parent5 = path$$1.getParentNode(0);
  16791. var preventInline = _parent5.type === "JSXAttribute" && n.expression.comments && n.expression.comments.length > 0;
  16792. 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(_parent5) && (n.expression.type === "ConditionalExpression" || isBinaryish(n.expression)));
  16793. if (_shouldInline) {
  16794. return group$1(concat$4(["{", path$$1.call(print, "expression"), lineSuffixBoundary$1, "}"]));
  16795. }
  16796. return group$1(concat$4(["{", indent$2(concat$4([softline$1, path$$1.call(print, "expression")])), softline$1, lineSuffixBoundary$1, "}"]));
  16797. }
  16798. case "JSXFragment":
  16799. case "TSJsxFragment":
  16800. case "JSXElement":
  16801. {
  16802. var elem = comments.printComments(path$$1, function () {
  16803. return printJSXElement(path$$1, options, print);
  16804. }, options);
  16805. return maybeWrapJSXElementInParens(path$$1, elem);
  16806. }
  16807. case "JSXOpeningElement":
  16808. {
  16809. var _n = path$$1.getValue();
  16810. var nameHasComments = _n.name && _n.name.comments && _n.name.comments.length > 0; // Don't break self-closing elements with no attributes and no comments
  16811. if (_n.selfClosing && !_n.attributes.length && !nameHasComments) {
  16812. return concat$4(["<", path$$1.call(print, "name"), path$$1.call(print, "typeParameters"), " />"]);
  16813. } // don't break up opening elements with a single long text attribute
  16814. if (_n.attributes && _n.attributes.length === 1 && _n.attributes[0].value && isStringLiteral(_n.attributes[0].value) && !_n.attributes[0].value.value.includes("\n") && // We should break for the following cases:
  16815. // <div
  16816. // // comment
  16817. // attr="value"
  16818. // >
  16819. // <div
  16820. // attr="value"
  16821. // // comment
  16822. // >
  16823. !nameHasComments && (!_n.attributes[0].comments || !_n.attributes[0].comments.length)) {
  16824. return group$1(concat$4(["<", path$$1.call(print, "name"), path$$1.call(print, "typeParameters"), " ", concat$4(path$$1.map(print, "attributes")), _n.selfClosing ? " />" : ">"]));
  16825. }
  16826. var lastAttrHasTrailingComments = _n.attributes.length && hasTrailingComment(getLast$4(_n.attributes));
  16827. var bracketSameLine = options.jsxBracketSameLine && ( // We should print the bracket in a new line for the following cases:
  16828. // <div
  16829. // // comment
  16830. // >
  16831. // <div
  16832. // attr // comment
  16833. // >
  16834. !nameHasComments || _n.attributes.length) && !lastAttrHasTrailingComments; // We should print the opening element expanded if any prop value is a
  16835. // string literal with newlines
  16836. var _shouldBreak = _n.attributes && _n.attributes.some(function (attr) {
  16837. return attr.value && isStringLiteral(attr.value) && attr.value.value.includes("\n");
  16838. });
  16839. return group$1(concat$4(["<", path$$1.call(print, "name"), path$$1.call(print, "typeParameters"), concat$4([indent$2(concat$4(path$$1.map(function (attr) {
  16840. return concat$4([line$3, print(attr)]);
  16841. }, "attributes"))), _n.selfClosing ? line$3 : bracketSameLine ? ">" : softline$1]), _n.selfClosing ? "/>" : bracketSameLine ? "" : ">"]), {
  16842. shouldBreak: _shouldBreak
  16843. });
  16844. }
  16845. case "JSXClosingElement":
  16846. return concat$4(["</", path$$1.call(print, "name"), ">"]);
  16847. case "JSXOpeningFragment":
  16848. case "JSXClosingFragment":
  16849. case "TSJsxOpeningFragment":
  16850. case "TSJsxClosingFragment":
  16851. {
  16852. var hasComment = n.comments && n.comments.length;
  16853. var hasOwnLineComment = hasComment && !n.comments.every(comments$3.isBlockComment);
  16854. var isOpeningFragment = n.type === "JSXOpeningFragment" || n.type === "TSJsxOpeningFragment";
  16855. return concat$4([isOpeningFragment ? "<" : "</", indent$2(concat$4([hasOwnLineComment ? hardline$3 : hasComment && !isOpeningFragment ? " " : "", comments.printDanglingComments(path$$1, options, true)])), hasOwnLineComment ? hardline$3 : "", ">"]);
  16856. }
  16857. case "JSXText":
  16858. /* istanbul ignore next */
  16859. throw new Error("JSXTest should be handled by JSXElement");
  16860. case "JSXEmptyExpression":
  16861. {
  16862. var requiresHardline = n.comments && !n.comments.every(comments$3.isBlockComment);
  16863. return concat$4([comments.printDanglingComments(path$$1, options,
  16864. /* sameIndent */
  16865. !requiresHardline), requiresHardline ? hardline$3 : ""]);
  16866. }
  16867. case "ClassBody":
  16868. if (!n.comments && n.body.length === 0) {
  16869. return "{}";
  16870. }
  16871. return concat$4(["{", n.body.length > 0 ? indent$2(concat$4([hardline$3, path$$1.call(function (bodyPath) {
  16872. return printStatementSequence(bodyPath, options, print);
  16873. }, "body")])) : comments.printDanglingComments(path$$1, options), hardline$3, "}"]);
  16874. case "ClassProperty":
  16875. case "TSAbstractClassProperty":
  16876. case "ClassPrivateProperty":
  16877. {
  16878. if (n.accessibility) {
  16879. parts.push(n.accessibility + " ");
  16880. }
  16881. if (n.static) {
  16882. parts.push("static ");
  16883. }
  16884. if (n.type === "TSAbstractClassProperty") {
  16885. parts.push("abstract ");
  16886. }
  16887. if (n.readonly) {
  16888. parts.push("readonly ");
  16889. }
  16890. var variance = getFlowVariance(n);
  16891. if (variance) {
  16892. parts.push(variance);
  16893. }
  16894. if (n.computed) {
  16895. parts.push("[", path$$1.call(print, "key"), "]");
  16896. } else {
  16897. parts.push(printPropertyKey(path$$1, options, print));
  16898. }
  16899. parts.push(printTypeAnnotation(path$$1, options, print));
  16900. if (n.value) {
  16901. parts.push(" =", printAssignmentRight(n.key, n.value, path$$1.call(print, "value"), options));
  16902. }
  16903. parts.push(semi);
  16904. return group$1(concat$4(parts));
  16905. }
  16906. case "ClassDeclaration":
  16907. case "ClassExpression":
  16908. case "TSAbstractClassDeclaration":
  16909. if (isNodeStartingWithDeclare(n, options)) {
  16910. parts.push("declare ");
  16911. }
  16912. parts.push(concat$4(printClass(path$$1, options, print)));
  16913. return concat$4(parts);
  16914. case "TSInterfaceHeritage":
  16915. parts.push(path$$1.call(print, "id"));
  16916. if (n.typeParameters) {
  16917. parts.push(path$$1.call(print, "typeParameters"));
  16918. }
  16919. return concat$4(parts);
  16920. case "TemplateElement":
  16921. return join$2(literalline$1, n.value.raw.split(/\r?\n/g));
  16922. case "TemplateLiteral":
  16923. {
  16924. var expressions = path$$1.map(print, "expressions");
  16925. var _parentNode = path$$1.getParentNode();
  16926. /**
  16927. * describe.each`table`(name, fn)
  16928. * describe.only.each`table`(name, fn)
  16929. * describe.skip.each`table`(name, fn)
  16930. * test.each`table`(name, fn)
  16931. * test.only.each`table`(name, fn)
  16932. * test.skip.each`table`(name, fn)
  16933. *
  16934. * Ref: https://github.com/facebook/jest/pull/6102
  16935. */
  16936. var jestEachTriggerRegex = /^[xf]?(describe|it|test)$/;
  16937. if (_parentNode.type === "TaggedTemplateExpression" && _parentNode.quasi === n && _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))) {
  16938. /**
  16939. * a | b | expected
  16940. * ${1} | ${1} | ${2}
  16941. * ${1} | ${2} | ${3}
  16942. * ${2} | ${1} | ${3}
  16943. */
  16944. var headerNames = n.quasis[0].value.raw.trim().split(/\s*\|\s*/);
  16945. if (headerNames.length > 1 || headerNames.some(function (headerName) {
  16946. return headerName.length !== 0;
  16947. })) {
  16948. var stringifiedExpressions = expressions.map(function (doc$$2) {
  16949. return "${" + printDocToString$2(doc$$2, Object.assign({}, options, {
  16950. printWidth: Infinity
  16951. })).formatted + "}";
  16952. });
  16953. var tableBody = [{
  16954. hasLineBreak: false,
  16955. cells: []
  16956. }];
  16957. for (var _i = 1; _i < n.quasis.length; _i++) {
  16958. var row = tableBody[tableBody.length - 1];
  16959. var correspondingExpression = stringifiedExpressions[_i - 1];
  16960. row.cells.push(correspondingExpression);
  16961. if (correspondingExpression.indexOf("\n") !== -1) {
  16962. row.hasLineBreak = true;
  16963. }
  16964. if (n.quasis[_i].value.raw.indexOf("\n") !== -1) {
  16965. tableBody.push({
  16966. hasLineBreak: false,
  16967. cells: []
  16968. });
  16969. }
  16970. }
  16971. var maxColumnCount = tableBody.reduce(function (maxColumnCount, row) {
  16972. return Math.max(maxColumnCount, row.cells.length);
  16973. }, headerNames.length);
  16974. var maxColumnWidths = Array.from(new Array(maxColumnCount), function () {
  16975. return 0;
  16976. });
  16977. var table = [{
  16978. cells: headerNames
  16979. }].concat(tableBody.filter(function (row) {
  16980. return row.cells.length !== 0;
  16981. }));
  16982. table.filter(function (row) {
  16983. return !row.hasLineBreak;
  16984. }).forEach(function (row) {
  16985. row.cells.forEach(function (cell, index) {
  16986. maxColumnWidths[index] = Math.max(maxColumnWidths[index], getStringWidth$1(cell));
  16987. });
  16988. });
  16989. parts.push("`", indent$2(concat$4([hardline$3, join$2(hardline$3, table.map(function (row) {
  16990. return join$2(" | ", row.cells.map(function (cell, index) {
  16991. return row.hasLineBreak ? cell : cell + " ".repeat(maxColumnWidths[index] - getStringWidth$1(cell));
  16992. }));
  16993. }))])), hardline$3, "`");
  16994. return concat$4(parts);
  16995. }
  16996. }
  16997. parts.push("`");
  16998. path$$1.each(function (childPath) {
  16999. var i = childPath.getName();
  17000. parts.push(print(childPath));
  17001. if (i < expressions.length) {
  17002. // For a template literal of the following form:
  17003. // `someQuery {
  17004. // ${call({
  17005. // a,
  17006. // b,
  17007. // })}
  17008. // }`
  17009. // the expression is on its own line (there is a \n in the previous
  17010. // quasi literal), therefore we want to indent the JavaScript
  17011. // expression inside at the beginning of ${ instead of the beginning
  17012. // of the `.
  17013. var tabWidth = options.tabWidth;
  17014. var indentSize = getIndentSize$1(childPath.getValue().value.raw, tabWidth);
  17015. var _printed = expressions[i];
  17016. 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") {
  17017. _printed = concat$4([indent$2(concat$4([softline$1, _printed])), softline$1]);
  17018. }
  17019. var aligned = addAlignmentToDoc$2(_printed, indentSize, tabWidth);
  17020. parts.push(group$1(concat$4(["${", aligned, lineSuffixBoundary$1, "}"])));
  17021. }
  17022. }, "quasis");
  17023. parts.push("`");
  17024. return concat$4(parts);
  17025. }
  17026. // These types are unprintable because they serve as abstract
  17027. // supertypes for other (printable) types.
  17028. case "TaggedTemplateExpression":
  17029. return concat$4([path$$1.call(print, "tag"), path$$1.call(print, "typeParameters"), path$$1.call(print, "quasi")]);
  17030. case "Node":
  17031. case "Printable":
  17032. case "SourceLocation":
  17033. case "Position":
  17034. case "Statement":
  17035. case "Function":
  17036. case "Pattern":
  17037. case "Expression":
  17038. case "Declaration":
  17039. case "Specifier":
  17040. case "NamedSpecifier":
  17041. case "Comment":
  17042. case "MemberTypeAnnotation": // Flow
  17043. case "Type":
  17044. /* istanbul ignore next */
  17045. throw new Error("unprintable type: " + JSON.stringify(n.type));
  17046. // Type Annotations for Facebook Flow, typically stripped out or
  17047. // transformed away before printing.
  17048. case "TypeAnnotation":
  17049. case "TSTypeAnnotation":
  17050. if (n.typeAnnotation) {
  17051. return path$$1.call(print, "typeAnnotation");
  17052. }
  17053. /* istanbul ignore next */
  17054. return "";
  17055. case "TSTupleType":
  17056. case "TupleTypeAnnotation":
  17057. {
  17058. var typesField = n.type === "TSTupleType" ? "elementTypes" : "types";
  17059. return group$1(concat$4(["[", indent$2(concat$4([softline$1, printArrayItems(path$$1, options, typesField, print)])), // TypeScript doesn't support trailing commas in tuple types
  17060. n.type === "TSTupleType" ? "" : ifBreak$1(shouldPrintComma(options) ? "," : ""), comments.printDanglingComments(path$$1, options,
  17061. /* sameIndent */
  17062. true), softline$1, "]"]));
  17063. }
  17064. case "ExistsTypeAnnotation":
  17065. return "*";
  17066. case "EmptyTypeAnnotation":
  17067. return "empty";
  17068. case "AnyTypeAnnotation":
  17069. return "any";
  17070. case "MixedTypeAnnotation":
  17071. return "mixed";
  17072. case "ArrayTypeAnnotation":
  17073. return concat$4([path$$1.call(print, "elementType"), "[]"]);
  17074. case "BooleanTypeAnnotation":
  17075. return "boolean";
  17076. case "BooleanLiteralTypeAnnotation":
  17077. return "" + n.value;
  17078. case "DeclareClass":
  17079. return printFlowDeclaration(path$$1, printClass(path$$1, options, print));
  17080. case "DeclareFunction":
  17081. // For TypeScript the DeclareFunction node shares the AST
  17082. // structure with FunctionDeclaration
  17083. if (n.params) {
  17084. return concat$4(["declare ", printFunctionDeclaration(path$$1, print, options), semi]);
  17085. }
  17086. return printFlowDeclaration(path$$1, ["function ", path$$1.call(print, "id"), n.predicate ? " " : "", path$$1.call(print, "predicate"), semi]);
  17087. case "DeclareModule":
  17088. return printFlowDeclaration(path$$1, ["module ", path$$1.call(print, "id"), " ", path$$1.call(print, "body")]);
  17089. case "DeclareModuleExports":
  17090. return printFlowDeclaration(path$$1, ["module.exports", ": ", path$$1.call(print, "typeAnnotation"), semi]);
  17091. case "DeclareVariable":
  17092. return printFlowDeclaration(path$$1, ["var ", path$$1.call(print, "id"), semi]);
  17093. case "DeclareExportAllDeclaration":
  17094. return concat$4(["declare export * from ", path$$1.call(print, "source")]);
  17095. case "DeclareExportDeclaration":
  17096. return concat$4(["declare ", printExportDeclaration(path$$1, options, print)]);
  17097. case "DeclareOpaqueType":
  17098. case "OpaqueType":
  17099. {
  17100. parts.push("opaque type ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"));
  17101. if (n.supertype) {
  17102. parts.push(": ", path$$1.call(print, "supertype"));
  17103. }
  17104. if (n.impltype) {
  17105. parts.push(" = ", path$$1.call(print, "impltype"));
  17106. }
  17107. parts.push(semi);
  17108. if (n.type === "DeclareOpaqueType") {
  17109. return printFlowDeclaration(path$$1, parts);
  17110. }
  17111. return concat$4(parts);
  17112. }
  17113. case "FunctionTypeAnnotation":
  17114. case "TSFunctionType":
  17115. {
  17116. // FunctionTypeAnnotation is ambiguous:
  17117. // declare function foo(a: B): void; OR
  17118. // var A: (a: B) => void;
  17119. var _parent6 = path$$1.getParentNode(0);
  17120. var _parentParent2 = path$$1.getParentNode(1);
  17121. var _parentParentParent = path$$1.getParentNode(2);
  17122. var isArrowFunctionTypeAnnotation = n.type === "TSFunctionType" || !(_parent6.type === "ObjectTypeProperty" && !getFlowVariance(_parent6) && !_parent6.optional && options.locStart(_parent6) === options.locStart(n) || _parent6.type === "ObjectTypeCallProperty" || _parentParentParent && _parentParentParent.type === "DeclareFunction");
  17123. var needsColon = isArrowFunctionTypeAnnotation && (_parent6.type === "TypeAnnotation" || _parent6.type === "TSTypeAnnotation"); // Sadly we can't put it inside of FastPath::needsColon because we are
  17124. // printing ":" as part of the expression and it would put parenthesis
  17125. // around :(
  17126. var needsParens = needsColon && isArrowFunctionTypeAnnotation && (_parent6.type === "TypeAnnotation" || _parent6.type === "TSTypeAnnotation") && _parentParent2.type === "ArrowFunctionExpression";
  17127. if (isObjectTypePropertyAFunction(_parent6, options)) {
  17128. isArrowFunctionTypeAnnotation = true;
  17129. needsColon = true;
  17130. }
  17131. if (needsParens) {
  17132. parts.push("(");
  17133. }
  17134. parts.push(printFunctionParams(path$$1, print, options,
  17135. /* expandArg */
  17136. false,
  17137. /* printTypeParams */
  17138. true)); // The returnType is not wrapped in a TypeAnnotation, so the colon
  17139. // needs to be added separately.
  17140. if (n.returnType || n.predicate || n.typeAnnotation) {
  17141. parts.push(isArrowFunctionTypeAnnotation ? " => " : ": ", path$$1.call(print, "returnType"), path$$1.call(print, "predicate"), path$$1.call(print, "typeAnnotation"));
  17142. }
  17143. if (needsParens) {
  17144. parts.push(")");
  17145. }
  17146. return group$1(concat$4(parts));
  17147. }
  17148. case "FunctionTypeParam":
  17149. return concat$4([path$$1.call(print, "name"), printOptionalToken(path$$1), n.name ? ": " : "", path$$1.call(print, "typeAnnotation")]);
  17150. case "GenericTypeAnnotation":
  17151. return concat$4([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]);
  17152. case "DeclareInterface":
  17153. case "InterfaceDeclaration":
  17154. case "InterfaceTypeAnnotation":
  17155. {
  17156. if (n.type === "DeclareInterface" || isNodeStartingWithDeclare(n, options)) {
  17157. parts.push("declare ");
  17158. }
  17159. parts.push("interface");
  17160. if (n.type === "DeclareInterface" || n.type === "InterfaceDeclaration") {
  17161. parts.push(" ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"));
  17162. }
  17163. if (n["extends"].length > 0) {
  17164. parts.push(group$1(indent$2(concat$4([line$3, "extends ", join$2(", ", path$$1.map(print, "extends"))]))));
  17165. }
  17166. parts.push(" ", path$$1.call(print, "body"));
  17167. return group$1(concat$4(parts));
  17168. }
  17169. case "ClassImplements":
  17170. case "InterfaceExtends":
  17171. return concat$4([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]);
  17172. case "TSIntersectionType":
  17173. case "IntersectionTypeAnnotation":
  17174. {
  17175. var types = path$$1.map(print, "types");
  17176. var result = [];
  17177. var wasIndented = false;
  17178. for (var _i2 = 0; _i2 < types.length; ++_i2) {
  17179. if (_i2 === 0) {
  17180. result.push(types[_i2]);
  17181. } else if (isObjectType(n.types[_i2 - 1]) && isObjectType(n.types[_i2])) {
  17182. // If both are objects, don't indent
  17183. result.push(concat$4([" & ", wasIndented ? indent$2(types[_i2]) : types[_i2]]));
  17184. } else if (!isObjectType(n.types[_i2 - 1]) && !isObjectType(n.types[_i2])) {
  17185. // If no object is involved, go to the next line if it breaks
  17186. result.push(indent$2(concat$4([" &", line$3, types[_i2]])));
  17187. } else {
  17188. // If you go from object to non-object or vis-versa, then inline it
  17189. if (_i2 > 1) {
  17190. wasIndented = true;
  17191. }
  17192. result.push(" & ", _i2 > 1 ? indent$2(types[_i2]) : types[_i2]);
  17193. }
  17194. }
  17195. return group$1(concat$4(result));
  17196. }
  17197. case "TSUnionType":
  17198. case "UnionTypeAnnotation":
  17199. {
  17200. // single-line variation
  17201. // A | B | C
  17202. // multi-line variation
  17203. // | A
  17204. // | B
  17205. // | C
  17206. var _parent7 = path$$1.getParentNode();
  17207. var _parentParent3 = path$$1.getParentNode(1); // If there's a leading comment, the parent is doing the indentation
  17208. var shouldIndent = _parent7.type !== "TypeParameterInstantiation" && _parent7.type !== "TSTypeParameterInstantiation" && _parent7.type !== "GenericTypeAnnotation" && _parent7.type !== "TSTypeReference" && !(_parent7.type === "FunctionTypeParam" && !_parent7.name) && _parentParent3.type !== "TSTypeAssertionExpression" && !((_parent7.type === "TypeAlias" || _parent7.type === "VariableDeclarator") && hasLeadingOwnLineComment(options.originalText, n, options)); // {
  17209. // a: string
  17210. // } | null | void
  17211. // should be inlined and not be printed in the multi-line variant
  17212. var shouldHug = shouldHugType(n); // We want to align the children but without its comment, so it looks like
  17213. // | child1
  17214. // // comment
  17215. // | child2
  17216. var _printed2 = path$$1.map(function (typePath) {
  17217. var printedType = typePath.call(print);
  17218. if (!shouldHug) {
  17219. printedType = align$1(2, printedType);
  17220. }
  17221. return comments.printComments(typePath, function () {
  17222. return printedType;
  17223. }, options);
  17224. }, "types");
  17225. if (shouldHug) {
  17226. return join$2(" | ", _printed2);
  17227. }
  17228. var code = concat$4([ifBreak$1(concat$4([shouldIndent ? line$3 : "", "| "])), join$2(concat$4([line$3, "| "]), _printed2)]);
  17229. var hasParens;
  17230. if (n.type === "TSUnionType") {
  17231. var greatGrandParent = path$$1.getParentNode(2);
  17232. var greatGreatGrandParent = path$$1.getParentNode(3);
  17233. hasParens = greatGrandParent && greatGrandParent.type === "TSParenthesizedType" && greatGreatGrandParent && (greatGreatGrandParent.type === "TSUnionType" || greatGreatGrandParent.type === "TSIntersectionType");
  17234. } else {
  17235. hasParens = needsParens_1(path$$1, options);
  17236. }
  17237. if (hasParens) {
  17238. return group$1(concat$4([indent$2(code), softline$1]));
  17239. }
  17240. return group$1(shouldIndent ? indent$2(code) : code);
  17241. }
  17242. case "NullableTypeAnnotation":
  17243. return concat$4(["?", path$$1.call(print, "typeAnnotation")]);
  17244. case "TSNullKeyword":
  17245. case "NullLiteralTypeAnnotation":
  17246. return "null";
  17247. case "ThisTypeAnnotation":
  17248. return "this";
  17249. case "NumberTypeAnnotation":
  17250. return "number";
  17251. case "ObjectTypeCallProperty":
  17252. if (n.static) {
  17253. parts.push("static ");
  17254. }
  17255. parts.push(path$$1.call(print, "value"));
  17256. return concat$4(parts);
  17257. case "ObjectTypeIndexer":
  17258. {
  17259. var _variance = getFlowVariance(n);
  17260. return concat$4([_variance || "", "[", path$$1.call(print, "id"), n.id ? ": " : "", path$$1.call(print, "key"), "]: ", path$$1.call(print, "value")]);
  17261. }
  17262. case "ObjectTypeProperty":
  17263. {
  17264. var _variance2 = getFlowVariance(n);
  17265. var modifier = "";
  17266. if (n.proto) {
  17267. modifier = "proto ";
  17268. } else if (n.static) {
  17269. modifier = "static ";
  17270. }
  17271. return concat$4([modifier, isGetterOrSetter(n) ? n.kind + " " : "", _variance2 || "", printPropertyKey(path$$1, options, print), printOptionalToken(path$$1), isFunctionNotation(n, options) ? "" : ": ", path$$1.call(print, "value")]);
  17272. }
  17273. case "QualifiedTypeIdentifier":
  17274. return concat$4([path$$1.call(print, "qualification"), ".", path$$1.call(print, "id")]);
  17275. case "StringLiteralTypeAnnotation":
  17276. return nodeStr(n, options);
  17277. case "NumberLiteralTypeAnnotation":
  17278. assert.strictEqual(typeof n.value, "number");
  17279. if (n.extra != null) {
  17280. return printNumber$1(n.extra.raw);
  17281. }
  17282. return printNumber$1(n.raw);
  17283. case "StringTypeAnnotation":
  17284. return "string";
  17285. case "DeclareTypeAlias":
  17286. case "TypeAlias":
  17287. {
  17288. if (n.type === "DeclareTypeAlias" || isNodeStartingWithDeclare(n, options)) {
  17289. parts.push("declare ");
  17290. }
  17291. var _printed3 = printAssignmentRight(n.id, n.right, path$$1.call(print, "right"), options);
  17292. parts.push("type ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"), " =", _printed3, semi);
  17293. return group$1(concat$4(parts));
  17294. }
  17295. case "TypeCastExpression":
  17296. return concat$4(["(", path$$1.call(print, "expression"), ": ", path$$1.call(print, "typeAnnotation"), ")"]);
  17297. case "TypeParameterDeclaration":
  17298. case "TypeParameterInstantiation":
  17299. case "TSTypeParameterDeclaration":
  17300. case "TSTypeParameterInstantiation":
  17301. return printTypeParameters(path$$1, options, print, "params");
  17302. case "TSTypeParameter":
  17303. case "TypeParameter":
  17304. {
  17305. var _parent8 = path$$1.getParentNode();
  17306. if (_parent8.type === "TSMappedType") {
  17307. parts.push("[", path$$1.call(print, "name"));
  17308. if (n.constraint) {
  17309. parts.push(" in ", path$$1.call(print, "constraint"));
  17310. }
  17311. parts.push("]");
  17312. return concat$4(parts);
  17313. }
  17314. var _variance3 = getFlowVariance(n);
  17315. if (_variance3) {
  17316. parts.push(_variance3);
  17317. }
  17318. parts.push(path$$1.call(print, "name"));
  17319. if (n.bound) {
  17320. parts.push(": ");
  17321. parts.push(path$$1.call(print, "bound"));
  17322. }
  17323. if (n.constraint) {
  17324. parts.push(" extends ", path$$1.call(print, "constraint"));
  17325. }
  17326. if (n["default"]) {
  17327. parts.push(" = ", path$$1.call(print, "default"));
  17328. }
  17329. return concat$4(parts);
  17330. }
  17331. case "TypeofTypeAnnotation":
  17332. return concat$4(["typeof ", path$$1.call(print, "argument")]);
  17333. case "VoidTypeAnnotation":
  17334. return "void";
  17335. case "InferredPredicate":
  17336. return "%checks";
  17337. // Unhandled types below. If encountered, nodes of these types should
  17338. // be either left alone or desugared into AST types that are fully
  17339. // supported by the pretty-printer.
  17340. case "DeclaredPredicate":
  17341. return concat$4(["%checks(", path$$1.call(print, "value"), ")"]);
  17342. case "TSAbstractKeyword":
  17343. return "abstract";
  17344. case "TSAnyKeyword":
  17345. return "any";
  17346. case "TSAsyncKeyword":
  17347. return "async";
  17348. case "TSBooleanKeyword":
  17349. return "boolean";
  17350. case "TSConstKeyword":
  17351. return "const";
  17352. case "TSDeclareKeyword":
  17353. return "declare";
  17354. case "TSExportKeyword":
  17355. return "export";
  17356. case "TSNeverKeyword":
  17357. return "never";
  17358. case "TSNumberKeyword":
  17359. return "number";
  17360. case "TSObjectKeyword":
  17361. return "object";
  17362. case "TSProtectedKeyword":
  17363. return "protected";
  17364. case "TSPrivateKeyword":
  17365. return "private";
  17366. case "TSPublicKeyword":
  17367. return "public";
  17368. case "TSReadonlyKeyword":
  17369. return "readonly";
  17370. case "TSSymbolKeyword":
  17371. return "symbol";
  17372. case "TSStaticKeyword":
  17373. return "static";
  17374. case "TSStringKeyword":
  17375. return "string";
  17376. case "TSUndefinedKeyword":
  17377. return "undefined";
  17378. case "TSVoidKeyword":
  17379. return "void";
  17380. case "TSAsExpression":
  17381. return concat$4([path$$1.call(print, "expression"), " as ", path$$1.call(print, "typeAnnotation")]);
  17382. case "TSArrayType":
  17383. return concat$4([path$$1.call(print, "elementType"), "[]"]);
  17384. case "TSPropertySignature":
  17385. {
  17386. if (n.export) {
  17387. parts.push("export ");
  17388. }
  17389. if (n.accessibility) {
  17390. parts.push(n.accessibility + " ");
  17391. }
  17392. if (n.static) {
  17393. parts.push("static ");
  17394. }
  17395. if (n.readonly) {
  17396. parts.push("readonly ");
  17397. }
  17398. if (n.computed) {
  17399. parts.push("[");
  17400. }
  17401. parts.push(printPropertyKey(path$$1, options, print));
  17402. if (n.computed) {
  17403. parts.push("]");
  17404. }
  17405. parts.push(printOptionalToken(path$$1));
  17406. if (n.typeAnnotation) {
  17407. parts.push(": ");
  17408. parts.push(path$$1.call(print, "typeAnnotation"));
  17409. } // This isn't valid semantically, but it's in the AST so we can print it.
  17410. if (n.initializer) {
  17411. parts.push(" = ", path$$1.call(print, "initializer"));
  17412. }
  17413. return concat$4(parts);
  17414. }
  17415. case "TSParameterProperty":
  17416. if (n.accessibility) {
  17417. parts.push(n.accessibility + " ");
  17418. }
  17419. if (n.export) {
  17420. parts.push("export ");
  17421. }
  17422. if (n.static) {
  17423. parts.push("static ");
  17424. }
  17425. if (n.readonly) {
  17426. parts.push("readonly ");
  17427. }
  17428. parts.push(path$$1.call(print, "parameter"));
  17429. return concat$4(parts);
  17430. case "TSTypeReference":
  17431. return concat$4([path$$1.call(print, "typeName"), printTypeParameters(path$$1, options, print, "typeParameters")]);
  17432. case "TSTypeQuery":
  17433. return concat$4(["typeof ", path$$1.call(print, "exprName")]);
  17434. case "TSParenthesizedType":
  17435. {
  17436. return path$$1.call(print, "typeAnnotation");
  17437. }
  17438. case "TSIndexSignature":
  17439. {
  17440. var _parent9 = path$$1.getParentNode();
  17441. return concat$4([n.export ? "export " : "", n.accessibility ? concat$4([n.accessibility, " "]) : "", n.static ? "static " : "", n.readonly ? "readonly " : "", "[", path$$1.call(print, "index"), "]: ", path$$1.call(print, "typeAnnotation"), _parent9.type === "ClassBody" ? semi : ""]);
  17442. }
  17443. case "TSTypePredicate":
  17444. return concat$4([path$$1.call(print, "parameterName"), " is ", path$$1.call(print, "typeAnnotation")]);
  17445. case "TSNonNullExpression":
  17446. return concat$4([path$$1.call(print, "expression"), "!"]);
  17447. case "TSThisType":
  17448. return "this";
  17449. case "TSLastTypeNode":
  17450. // TSImportType
  17451. return concat$4([!n.isTypeOf ? "" : "typeof ", "import(", path$$1.call(print, "argument"), ")", !n.qualifier ? "" : concat$4([".", path$$1.call(print, "qualifier")]), printTypeParameters(path$$1, options, print, "typeParameters")]);
  17452. case "TSLiteralType":
  17453. return path$$1.call(print, "literal");
  17454. case "TSIndexedAccessType":
  17455. return concat$4([path$$1.call(print, "objectType"), "[", path$$1.call(print, "indexType"), "]"]);
  17456. case "TSConstructSignature":
  17457. case "TSConstructorType":
  17458. case "TSCallSignature":
  17459. {
  17460. if (n.type !== "TSCallSignature") {
  17461. parts.push("new ");
  17462. }
  17463. parts.push(group$1(printFunctionParams(path$$1, print, options,
  17464. /* expandArg */
  17465. false,
  17466. /* printTypeParams */
  17467. true)));
  17468. if (n.typeAnnotation) {
  17469. var isType = n.type === "TSConstructorType";
  17470. parts.push(isType ? " => " : ": ", path$$1.call(print, "typeAnnotation"));
  17471. }
  17472. return concat$4(parts);
  17473. }
  17474. case "TSTypeOperator":
  17475. return concat$4([n.operator, " ", path$$1.call(print, "typeAnnotation")]);
  17476. case "TSMappedType":
  17477. return group$1(concat$4(["{", indent$2(concat$4([options.bracketSpacing ? line$3 : softline$1, n.readonlyToken ? concat$4([getTypeScriptMappedTypeModifier(n.readonlyToken, "readonly"), " "]) : "", printTypeScriptModifiers(path$$1, options, print), path$$1.call(print, "typeParameter"), n.questionToken ? getTypeScriptMappedTypeModifier(n.questionToken, "?") : "", ": ", path$$1.call(print, "typeAnnotation")])), comments.printDanglingComments(path$$1, options,
  17478. /* sameIndent */
  17479. true), options.bracketSpacing ? line$3 : softline$1, "}"]));
  17480. case "TSMethodSignature":
  17481. parts.push(n.accessibility ? concat$4([n.accessibility, " "]) : "", n.export ? "export " : "", n.static ? "static " : "", n.readonly ? "readonly " : "", n.computed ? "[" : "", path$$1.call(print, "key"), n.computed ? "]" : "", printOptionalToken(path$$1), printFunctionParams(path$$1, print, options,
  17482. /* expandArg */
  17483. false,
  17484. /* printTypeParams */
  17485. true));
  17486. if (n.typeAnnotation) {
  17487. parts.push(": ", path$$1.call(print, "typeAnnotation"));
  17488. }
  17489. return group$1(concat$4(parts));
  17490. case "TSNamespaceExportDeclaration":
  17491. parts.push("export as namespace ", path$$1.call(print, "name"));
  17492. if (options.semi) {
  17493. parts.push(";");
  17494. }
  17495. return group$1(concat$4(parts));
  17496. case "TSEnumDeclaration":
  17497. if (isNodeStartingWithDeclare(n, options)) {
  17498. parts.push("declare ");
  17499. }
  17500. if (n.modifiers) {
  17501. parts.push(printTypeScriptModifiers(path$$1, options, print));
  17502. }
  17503. if (n.const) {
  17504. parts.push("const ");
  17505. }
  17506. parts.push("enum ", path$$1.call(print, "id"), " ");
  17507. if (n.members.length === 0) {
  17508. parts.push(group$1(concat$4(["{", comments.printDanglingComments(path$$1, options), softline$1, "}"])));
  17509. } else {
  17510. parts.push(group$1(concat$4(["{", indent$2(concat$4([hardline$3, printArrayItems(path$$1, options, "members", print), shouldPrintComma(options, "es5") ? "," : ""])), comments.printDanglingComments(path$$1, options,
  17511. /* sameIndent */
  17512. true), hardline$3, "}"])));
  17513. }
  17514. return concat$4(parts);
  17515. case "TSEnumMember":
  17516. parts.push(path$$1.call(print, "id"));
  17517. if (n.initializer) {
  17518. parts.push(" = ", path$$1.call(print, "initializer"));
  17519. }
  17520. return concat$4(parts);
  17521. case "TSImportEqualsDeclaration":
  17522. parts.push(printTypeScriptModifiers(path$$1, options, print), "import ", path$$1.call(print, "name"), " = ", path$$1.call(print, "moduleReference"));
  17523. if (options.semi) {
  17524. parts.push(";");
  17525. }
  17526. return group$1(concat$4(parts));
  17527. case "TSExternalModuleReference":
  17528. return concat$4(["require(", path$$1.call(print, "expression"), ")"]);
  17529. case "TSModuleDeclaration":
  17530. {
  17531. var _parent10 = path$$1.getParentNode();
  17532. var isExternalModule = isLiteral(n.id);
  17533. var parentIsDeclaration = _parent10.type === "TSModuleDeclaration";
  17534. var bodyIsDeclaration = n.body && n.body.type === "TSModuleDeclaration";
  17535. if (parentIsDeclaration) {
  17536. parts.push(".");
  17537. } else {
  17538. if (n.declare === true) {
  17539. parts.push("declare ");
  17540. }
  17541. parts.push(printTypeScriptModifiers(path$$1, options, print)); // Global declaration looks like this:
  17542. // (declare)? global { ... }
  17543. var isGlobalDeclaration = n.id.type === "Identifier" && n.id.name === "global" && !/namespace|module/.test(options.originalText.slice(options.locStart(n), options.locStart(n.id)));
  17544. if (!isGlobalDeclaration) {
  17545. parts.push(isExternalModule ? "module " : "namespace ");
  17546. }
  17547. }
  17548. parts.push(path$$1.call(print, "id"));
  17549. if (bodyIsDeclaration) {
  17550. parts.push(path$$1.call(print, "body"));
  17551. } else if (n.body) {
  17552. parts.push(" {", indent$2(concat$4([line$3, path$$1.call(function (bodyPath) {
  17553. return comments.printDanglingComments(bodyPath, options, true);
  17554. }, "body"), group$1(path$$1.call(print, "body"))])), line$3, "}");
  17555. } else {
  17556. parts.push(semi);
  17557. }
  17558. return concat$4(parts);
  17559. }
  17560. case "TSModuleBlock":
  17561. return path$$1.call(function (bodyPath) {
  17562. return printStatementSequence(bodyPath, options, print);
  17563. }, "body");
  17564. case "PrivateName":
  17565. return concat$4(["#", path$$1.call(print, "id")]);
  17566. case "TSConditionalType":
  17567. return formatTernaryOperator(path$$1, options, print, {
  17568. beforeParts: function beforeParts() {
  17569. return [path$$1.call(print, "checkType"), " ", "extends", " ", path$$1.call(print, "extendsType")];
  17570. },
  17571. shouldCheckJsx: false,
  17572. operatorName: "TSConditionalType",
  17573. consequentNode: "trueType",
  17574. alternateNode: "falseType",
  17575. testNode: "checkType",
  17576. breakNested: false
  17577. });
  17578. case "TSInferType":
  17579. return concat$4(["infer", " ", path$$1.call(print, "typeParameter")]);
  17580. case "InterpreterDirective":
  17581. parts.push("#!", n.value, hardline$3);
  17582. if (isNextLineEmpty$2(options.originalText, n, options)) {
  17583. parts.push(hardline$3);
  17584. }
  17585. return concat$4(parts);
  17586. default:
  17587. /* istanbul ignore next */
  17588. throw new Error("unknown type: " + JSON.stringify(n.type));
  17589. }
  17590. }
  17591. function printStatementSequence(path$$1, options, print) {
  17592. var printed = [];
  17593. var bodyNode = path$$1.getNode();
  17594. var isClass = bodyNode.type === "ClassBody";
  17595. path$$1.map(function (stmtPath, i) {
  17596. var stmt = stmtPath.getValue(); // Just in case the AST has been modified to contain falsy
  17597. // "statements," it's safer simply to skip them.
  17598. /* istanbul ignore if */
  17599. if (!stmt) {
  17600. return;
  17601. } // Skip printing EmptyStatement nodes to avoid leaving stray
  17602. // semicolons lying around.
  17603. if (stmt.type === "EmptyStatement") {
  17604. return;
  17605. }
  17606. var stmtPrinted = print(stmtPath);
  17607. var text = options.originalText;
  17608. var parts = []; // in no-semi mode, prepend statement with semicolon if it might break ASI
  17609. // don't prepend the only JSX element in a program with semicolon
  17610. if (!options.semi && !isClass && !isTheOnlyJSXElementInMarkdown(options, stmtPath) && stmtNeedsASIProtection(stmtPath, options)) {
  17611. if (stmt.comments && stmt.comments.some(function (comment) {
  17612. return comment.leading;
  17613. })) {
  17614. parts.push(print(stmtPath, {
  17615. needsSemi: true
  17616. }));
  17617. } else {
  17618. parts.push(";", stmtPrinted);
  17619. }
  17620. } else {
  17621. parts.push(stmtPrinted);
  17622. }
  17623. if (!options.semi && isClass) {
  17624. if (classPropMayCauseASIProblems(stmtPath)) {
  17625. parts.push(";");
  17626. } else if (stmt.type === "ClassProperty") {
  17627. var nextChild = bodyNode.body[i + 1];
  17628. if (classChildNeedsASIProtection(nextChild)) {
  17629. parts.push(";");
  17630. }
  17631. }
  17632. }
  17633. if (isNextLineEmpty$2(text, stmt, options) && !isLastStatement(stmtPath)) {
  17634. parts.push(hardline$3);
  17635. }
  17636. printed.push(concat$4(parts));
  17637. });
  17638. return join$2(hardline$3, printed);
  17639. }
  17640. function printPropertyKey(path$$1, options, print) {
  17641. var node = path$$1.getNode();
  17642. var key = node.key;
  17643. if (key.type === "Identifier" && !node.computed && options.parser === "json") {
  17644. // a -> "a"
  17645. return path$$1.call(function (keyPath) {
  17646. return comments.printComments(keyPath, function () {
  17647. return JSON.stringify(key.name);
  17648. }, options);
  17649. }, "key");
  17650. }
  17651. if (isStringLiteral(key) && isIdentifierName(key.value) && !node.computed && options.parser !== "json" && !(options.parser === "typescript" && node.type === "ClassProperty")) {
  17652. // 'a' -> a
  17653. return path$$1.call(function (keyPath) {
  17654. return comments.printComments(keyPath, function () {
  17655. return key.value;
  17656. }, options);
  17657. }, "key");
  17658. }
  17659. return path$$1.call(print, "key");
  17660. }
  17661. function printMethod(path$$1, options, print) {
  17662. var node = path$$1.getNode();
  17663. var semi = options.semi ? ";" : "";
  17664. var kind = node.kind;
  17665. var parts = [];
  17666. if (node.type === "ObjectMethod" || node.type === "ClassMethod") {
  17667. node.value = node;
  17668. }
  17669. if (node.value.async) {
  17670. parts.push("async ");
  17671. }
  17672. if (!kind || kind === "init" || kind === "method" || kind === "constructor") {
  17673. if (node.value.generator) {
  17674. parts.push("*");
  17675. }
  17676. } else {
  17677. assert.ok(kind === "get" || kind === "set");
  17678. parts.push(kind, " ");
  17679. }
  17680. var key = printPropertyKey(path$$1, options, print);
  17681. if (node.computed) {
  17682. key = concat$4(["[", key, "]"]);
  17683. }
  17684. parts.push(key, concat$4(path$$1.call(function (valuePath) {
  17685. return [printFunctionTypeParameters(valuePath, options, print), group$1(concat$4([printFunctionParams(valuePath, print, options), printReturnType(valuePath, print, options)]))];
  17686. }, "value")));
  17687. if (!node.value.body || node.value.body.length === 0) {
  17688. parts.push(semi);
  17689. } else {
  17690. parts.push(" ", path$$1.call(print, "value", "body"));
  17691. }
  17692. return concat$4(parts);
  17693. }
  17694. function couldGroupArg(arg) {
  17695. return arg.type === "ObjectExpression" && (arg.properties.length > 0 || arg.comments) || arg.type === "ArrayExpression" && (arg.elements.length > 0 || arg.comments) || arg.type === "TSTypeAssertionExpression" || arg.type === "TSAsExpression" || arg.type === "FunctionExpression" || arg.type === "ArrowFunctionExpression" && !arg.returnType && (arg.body.type === "BlockStatement" || arg.body.type === "ArrowFunctionExpression" || arg.body.type === "ObjectExpression" || arg.body.type === "ArrayExpression" || arg.body.type === "CallExpression" || arg.body.type === "OptionalCallExpression" || isJSXNode(arg.body));
  17696. }
  17697. function shouldGroupLastArg(args) {
  17698. var lastArg = getLast$4(args);
  17699. var penultimateArg = getPenultimate$1(args);
  17700. return !hasLeadingComment(lastArg) && !hasTrailingComment(lastArg) && couldGroupArg(lastArg) && ( // If the last two arguments are of the same type,
  17701. // disable last element expansion.
  17702. !penultimateArg || penultimateArg.type !== lastArg.type);
  17703. }
  17704. function shouldGroupFirstArg(args) {
  17705. if (args.length !== 2) {
  17706. return false;
  17707. }
  17708. var firstArg = args[0];
  17709. var secondArg = args[1];
  17710. return (!firstArg.comments || !firstArg.comments.length) && (firstArg.type === "FunctionExpression" || firstArg.type === "ArrowFunctionExpression" && firstArg.body.type === "BlockStatement") && !couldGroupArg(secondArg);
  17711. }
  17712. var functionCompositionFunctionNames = new Set(["pipe", // RxJS, Ramda
  17713. "pipeP", // Ramda
  17714. "pipeK", // Ramda
  17715. "compose", // Ramda, Redux
  17716. "composeFlipped", // Not from any library, but common in Haskell, so supported
  17717. "composeP", // Ramda
  17718. "composeK", // Ramda
  17719. "flow", // Lodash
  17720. "flowRight", // Lodash
  17721. "connect" // Redux
  17722. ]);
  17723. function isFunctionCompositionFunction(node) {
  17724. switch (node.type) {
  17725. case "OptionalMemberExpression":
  17726. case "MemberExpression":
  17727. {
  17728. return isFunctionCompositionFunction(node.property);
  17729. }
  17730. case "Identifier":
  17731. {
  17732. return functionCompositionFunctionNames.has(node.name);
  17733. }
  17734. case "StringLiteral":
  17735. case "Literal":
  17736. {
  17737. return functionCompositionFunctionNames.has(node.value);
  17738. }
  17739. }
  17740. }
  17741. function printArgumentsList(path$$1, options, print) {
  17742. var node = path$$1.getValue();
  17743. var args = node.arguments;
  17744. if (args.length === 0) {
  17745. return concat$4(["(", comments.printDanglingComments(path$$1, options,
  17746. /* sameIndent */
  17747. true), ")"]);
  17748. }
  17749. var anyArgEmptyLine = false;
  17750. var hasEmptyLineFollowingFirstArg = false;
  17751. var lastArgIndex = args.length - 1;
  17752. var printedArguments = path$$1.map(function (argPath, index) {
  17753. var arg = argPath.getNode();
  17754. var parts = [print(argPath)];
  17755. if (index === lastArgIndex) {// do nothing
  17756. } else if (isNextLineEmpty$2(options.originalText, arg, options)) {
  17757. if (index === 0) {
  17758. hasEmptyLineFollowingFirstArg = true;
  17759. }
  17760. anyArgEmptyLine = true;
  17761. parts.push(",", hardline$3, hardline$3);
  17762. } else {
  17763. parts.push(",", line$3);
  17764. }
  17765. return concat$4(parts);
  17766. }, "arguments");
  17767. var maybeTrailingComma = shouldPrintComma(options, "all") ? "," : "";
  17768. function allArgsBrokenOut() {
  17769. return group$1(concat$4(["(", indent$2(concat$4([line$3, concat$4(printedArguments)])), maybeTrailingComma, line$3, ")"]), {
  17770. shouldBreak: true
  17771. });
  17772. } // We want to get
  17773. // pipe(
  17774. // x => x + 1,
  17775. // x => x - 1
  17776. // )
  17777. // here, but not
  17778. // process.stdout.pipe(socket)
  17779. if (isFunctionCompositionFunction(node.callee) && args.length > 1) {
  17780. return allArgsBrokenOut();
  17781. }
  17782. var shouldGroupFirst = shouldGroupFirstArg(args);
  17783. var shouldGroupLast = shouldGroupLastArg(args);
  17784. if (shouldGroupFirst || shouldGroupLast) {
  17785. var shouldBreak = (shouldGroupFirst ? printedArguments.slice(1).some(willBreak$1) : printedArguments.slice(0, -1).some(willBreak$1)) || anyArgEmptyLine; // We want to print the last argument with a special flag
  17786. var printedExpanded;
  17787. var i = 0;
  17788. path$$1.each(function (argPath) {
  17789. if (shouldGroupFirst && i === 0) {
  17790. printedExpanded = [concat$4([argPath.call(function (p) {
  17791. return print(p, {
  17792. expandFirstArg: true
  17793. });
  17794. }), printedArguments.length > 1 ? "," : "", hasEmptyLineFollowingFirstArg ? hardline$3 : line$3, hasEmptyLineFollowingFirstArg ? hardline$3 : ""])].concat(printedArguments.slice(1));
  17795. }
  17796. if (shouldGroupLast && i === args.length - 1) {
  17797. printedExpanded = printedArguments.slice(0, -1).concat(argPath.call(function (p) {
  17798. return print(p, {
  17799. expandLastArg: true
  17800. });
  17801. }));
  17802. }
  17803. i++;
  17804. }, "arguments");
  17805. var somePrintedArgumentsWillBreak = printedArguments.some(willBreak$1);
  17806. return concat$4([somePrintedArgumentsWillBreak ? breakParent$2 : "", conditionalGroup$1([concat$4([ifBreak$1(indent$2(concat$4(["(", softline$1, concat$4(printedExpanded)])), concat$4(["(", concat$4(printedExpanded)])), somePrintedArgumentsWillBreak ? concat$4([ifBreak$1(maybeTrailingComma), softline$1]) : "", ")"]), shouldGroupFirst ? concat$4(["(", group$1(printedExpanded[0], {
  17807. shouldBreak: true
  17808. }), concat$4(printedExpanded.slice(1)), ")"]) : concat$4(["(", concat$4(printedArguments.slice(0, -1)), group$1(getLast$4(printedExpanded), {
  17809. shouldBreak: true
  17810. }), ")"]), allArgsBrokenOut()], {
  17811. shouldBreak
  17812. })]);
  17813. }
  17814. return group$1(concat$4(["(", indent$2(concat$4([softline$1, concat$4(printedArguments)])), ifBreak$1(shouldPrintComma(options, "all") ? "," : ""), softline$1, ")"]), {
  17815. shouldBreak: printedArguments.some(willBreak$1) || anyArgEmptyLine
  17816. });
  17817. }
  17818. function printTypeAnnotation(path$$1, options, print) {
  17819. var node = path$$1.getValue();
  17820. if (!node.typeAnnotation) {
  17821. return "";
  17822. }
  17823. var parentNode = path$$1.getParentNode();
  17824. var isDefinite = node.definite || parentNode && parentNode.type === "VariableDeclarator" && parentNode.definite;
  17825. var isFunctionDeclarationIdentifier = parentNode.type === "DeclareFunction" && parentNode.id === node;
  17826. if (isFlowAnnotationComment(options.originalText, node.typeAnnotation, options)) {
  17827. return concat$4([" /*: ", path$$1.call(print, "typeAnnotation"), " */"]);
  17828. }
  17829. return concat$4([isFunctionDeclarationIdentifier ? "" : isDefinite ? "!: " : ": ", path$$1.call(print, "typeAnnotation")]);
  17830. }
  17831. function printFunctionTypeParameters(path$$1, options, print) {
  17832. var fun = path$$1.getValue();
  17833. if (fun.typeArguments) {
  17834. return path$$1.call(print, "typeArguments");
  17835. }
  17836. if (fun.typeParameters) {
  17837. return path$$1.call(print, "typeParameters");
  17838. }
  17839. return "";
  17840. }
  17841. function printFunctionParams(path$$1, print, options, expandArg, printTypeParams) {
  17842. var fun = path$$1.getValue();
  17843. var paramsField = fun.parameters ? "parameters" : "params";
  17844. var typeParams = printTypeParams ? printFunctionTypeParameters(path$$1, options, print) : "";
  17845. var printed = [];
  17846. if (fun[paramsField]) {
  17847. printed = path$$1.map(print, paramsField);
  17848. }
  17849. if (fun.rest) {
  17850. printed.push(concat$4(["...", path$$1.call(print, "rest")]));
  17851. }
  17852. if (printed.length === 0) {
  17853. return concat$4([typeParams, "(", comments.printDanglingComments(path$$1, options,
  17854. /* sameIndent */
  17855. true, function (comment) {
  17856. return getNextNonSpaceNonCommentCharacter$1(options.originalText, comment, options.locEnd) === ")";
  17857. }), ")"]);
  17858. }
  17859. var lastParam = getLast$4(fun[paramsField]); // If the parent is a call with the first/last argument expansion and this is the
  17860. // params of the first/last argument, we dont want the arguments to break and instead
  17861. // want the whole expression to be on a new line.
  17862. //
  17863. // Good: Bad:
  17864. // verylongcall( verylongcall((
  17865. // (a, b) => { a,
  17866. // } b,
  17867. // }) ) => {
  17868. // })
  17869. if (expandArg && !(fun[paramsField] && fun[paramsField].some(function (n) {
  17870. return n.comments;
  17871. }))) {
  17872. return group$1(concat$4([removeLines$1(typeParams), "(", join$2(", ", printed.map(removeLines$1)), ")"]));
  17873. } // Single object destructuring should hug
  17874. //
  17875. // function({
  17876. // a,
  17877. // b,
  17878. // c
  17879. // }) {}
  17880. if (shouldHugArguments(fun)) {
  17881. return concat$4([typeParams, "(", join$2(", ", printed), ")"]);
  17882. }
  17883. var parent = path$$1.getParentNode(); // don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})`
  17884. if (isTestCall(parent)) {
  17885. return concat$4([typeParams, "(", join$2(", ", printed), ")"]);
  17886. }
  17887. var flowTypeAnnotations = ["AnyTypeAnnotation", "NullLiteralTypeAnnotation", "GenericTypeAnnotation", "ThisTypeAnnotation", "NumberTypeAnnotation", "VoidTypeAnnotation", "EmptyTypeAnnotation", "MixedTypeAnnotation", "BooleanTypeAnnotation", "BooleanLiteralTypeAnnotation", "StringTypeAnnotation"];
  17888. var isFlowShorthandWithOneArg = (isObjectTypePropertyAFunction(parent, options) || isTypeAnnotationAFunction(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 && flowTypeAnnotations.indexOf(fun[paramsField][0].typeAnnotation.type) !== -1 && !(fun[paramsField][0].typeAnnotation.type === "GenericTypeAnnotation" && fun[paramsField][0].typeAnnotation.typeParameters) && !fun.rest;
  17889. if (isFlowShorthandWithOneArg) {
  17890. if (options.arrowParens === "always") {
  17891. return concat$4(["(", concat$4(printed), ")"]);
  17892. }
  17893. return concat$4(printed);
  17894. }
  17895. var canHaveTrailingComma = !(lastParam && lastParam.type === "RestElement") && !fun.rest;
  17896. return concat$4([typeParams, "(", indent$2(concat$4([softline$1, join$2(concat$4([",", line$3]), printed)])), ifBreak$1(canHaveTrailingComma && shouldPrintComma(options, "all") ? "," : ""), softline$1, ")"]);
  17897. }
  17898. function shouldPrintParamsWithoutParens(path$$1, options) {
  17899. if (options.arrowParens === "always") {
  17900. return false;
  17901. }
  17902. if (options.arrowParens === "avoid") {
  17903. var node = path$$1.getValue();
  17904. return canPrintParamsWithoutParens(node);
  17905. } // Fallback default; should be unreachable
  17906. return false;
  17907. }
  17908. function canPrintParamsWithoutParens(node) {
  17909. return node.params.length === 1 && !node.rest && !node.typeParameters && !hasDanglingComments(node) && node.params[0].type === "Identifier" && !node.params[0].typeAnnotation && !node.params[0].comments && !node.params[0].optional && !node.predicate && !node.returnType;
  17910. }
  17911. function printFunctionDeclaration(path$$1, print, options) {
  17912. var n = path$$1.getValue();
  17913. var parts = [];
  17914. if (n.async) {
  17915. parts.push("async ");
  17916. }
  17917. parts.push("function");
  17918. if (n.generator) {
  17919. parts.push("*");
  17920. }
  17921. if (n.id) {
  17922. parts.push(" ", path$$1.call(print, "id"));
  17923. }
  17924. parts.push(printFunctionTypeParameters(path$$1, options, print), group$1(concat$4([printFunctionParams(path$$1, print, options), printReturnType(path$$1, print, options)])), n.body ? " " : "", path$$1.call(print, "body"));
  17925. return concat$4(parts);
  17926. }
  17927. function printObjectMethod(path$$1, options, print) {
  17928. var objMethod = path$$1.getValue();
  17929. var parts = [];
  17930. if (objMethod.async) {
  17931. parts.push("async ");
  17932. }
  17933. if (objMethod.generator) {
  17934. parts.push("*");
  17935. }
  17936. if (objMethod.method || objMethod.kind === "get" || objMethod.kind === "set") {
  17937. return printMethod(path$$1, options, print);
  17938. }
  17939. var key = printPropertyKey(path$$1, options, print);
  17940. if (objMethod.computed) {
  17941. parts.push("[", key, "]");
  17942. } else {
  17943. parts.push(key);
  17944. }
  17945. parts.push(printFunctionTypeParameters(path$$1, options, print), group$1(concat$4([printFunctionParams(path$$1, print, options), printReturnType(path$$1, print, options)])), " ", path$$1.call(print, "body"));
  17946. return concat$4(parts);
  17947. }
  17948. function printReturnType(path$$1, print, options) {
  17949. var n = path$$1.getValue();
  17950. var returnType = path$$1.call(print, "returnType");
  17951. if (n.returnType && isFlowAnnotationComment(options.originalText, n.returnType, options)) {
  17952. return concat$4([" /*: ", returnType, " */"]);
  17953. }
  17954. var parts = [returnType]; // prepend colon to TypeScript type annotation
  17955. if (n.returnType && n.returnType.typeAnnotation) {
  17956. parts.unshift(": ");
  17957. }
  17958. if (n.predicate) {
  17959. // The return type will already add the colon, but otherwise we
  17960. // need to do it ourselves
  17961. parts.push(n.returnType ? " " : ": ", path$$1.call(print, "predicate"));
  17962. }
  17963. return concat$4(parts);
  17964. }
  17965. function printExportDeclaration(path$$1, options, print) {
  17966. var decl = path$$1.getValue();
  17967. var semi = options.semi ? ";" : "";
  17968. var parts = ["export "];
  17969. var isDefault = decl["default"] || decl.type === "ExportDefaultDeclaration";
  17970. if (isDefault) {
  17971. parts.push("default ");
  17972. }
  17973. parts.push(comments.printDanglingComments(path$$1, options,
  17974. /* sameIndent */
  17975. true));
  17976. if (needsHardlineAfterDanglingComment(decl)) {
  17977. parts.push(hardline$3);
  17978. }
  17979. if (decl.declaration) {
  17980. parts.push(path$$1.call(print, "declaration"));
  17981. if (isDefault && decl.declaration.type !== "ClassDeclaration" && decl.declaration.type !== "FunctionDeclaration" && decl.declaration.type !== "TSAbstractClassDeclaration" && decl.declaration.type !== "TSInterfaceDeclaration" && decl.declaration.type !== "DeclareClass" && decl.declaration.type !== "DeclareFunction") {
  17982. parts.push(semi);
  17983. }
  17984. } else {
  17985. if (decl.specifiers && decl.specifiers.length > 0) {
  17986. var specifiers = [];
  17987. var defaultSpecifiers = [];
  17988. var namespaceSpecifiers = [];
  17989. path$$1.each(function (specifierPath) {
  17990. var specifierType = path$$1.getValue().type;
  17991. if (specifierType === "ExportSpecifier") {
  17992. specifiers.push(print(specifierPath));
  17993. } else if (specifierType === "ExportDefaultSpecifier") {
  17994. defaultSpecifiers.push(print(specifierPath));
  17995. } else if (specifierType === "ExportNamespaceSpecifier") {
  17996. namespaceSpecifiers.push(concat$4(["* as ", print(specifierPath)]));
  17997. }
  17998. }, "specifiers");
  17999. var isNamespaceFollowed = namespaceSpecifiers.length !== 0 && specifiers.length !== 0;
  18000. var isDefaultFollowed = defaultSpecifiers.length !== 0 && (namespaceSpecifiers.length !== 0 || specifiers.length !== 0);
  18001. parts.push(decl.exportKind === "type" ? "type " : "", concat$4(defaultSpecifiers), concat$4([isDefaultFollowed ? ", " : ""]), concat$4(namespaceSpecifiers), concat$4([isNamespaceFollowed ? ", " : ""]), specifiers.length !== 0 ? group$1(concat$4(["{", indent$2(concat$4([options.bracketSpacing ? line$3 : softline$1, join$2(concat$4([",", line$3]), specifiers)])), ifBreak$1(shouldPrintComma(options) ? "," : ""), options.bracketSpacing ? line$3 : softline$1, "}"])) : "");
  18002. } else {
  18003. parts.push("{}");
  18004. }
  18005. if (decl.source) {
  18006. parts.push(" from ", path$$1.call(print, "source"));
  18007. }
  18008. parts.push(semi);
  18009. }
  18010. return concat$4(parts);
  18011. }
  18012. function printFlowDeclaration(path$$1, parts) {
  18013. var parentExportDecl = getParentExportDeclaration$1(path$$1);
  18014. if (parentExportDecl) {
  18015. assert.strictEqual(parentExportDecl.type, "DeclareExportDeclaration");
  18016. } else {
  18017. // If the parent node has type DeclareExportDeclaration, then it
  18018. // will be responsible for printing the "declare" token. Otherwise
  18019. // it needs to be printed with this non-exported declaration node.
  18020. parts.unshift("declare ");
  18021. }
  18022. return concat$4(parts);
  18023. }
  18024. function getFlowVariance(path$$1) {
  18025. if (!path$$1.variance) {
  18026. return null;
  18027. } // Babylon 7.0 currently uses variance node type, and flow should
  18028. // follow suit soon:
  18029. // https://github.com/babel/babel/issues/4722
  18030. var variance = path$$1.variance.kind || path$$1.variance;
  18031. switch (variance) {
  18032. case "plus":
  18033. return "+";
  18034. case "minus":
  18035. return "-";
  18036. default:
  18037. /* istanbul ignore next */
  18038. return variance;
  18039. }
  18040. }
  18041. function printTypeScriptModifiers(path$$1, options, print) {
  18042. var n = path$$1.getValue();
  18043. if (!n.modifiers || !n.modifiers.length) {
  18044. return "";
  18045. }
  18046. return concat$4([join$2(" ", path$$1.map(print, "modifiers")), " "]);
  18047. }
  18048. function printTypeParameters(path$$1, options, print, paramsKey) {
  18049. var n = path$$1.getValue();
  18050. if (!n[paramsKey]) {
  18051. return "";
  18052. } // for TypeParameterDeclaration typeParameters is a single node
  18053. if (!Array.isArray(n[paramsKey])) {
  18054. return path$$1.call(print, paramsKey);
  18055. }
  18056. var grandparent = path$$1.getNode(2);
  18057. var isParameterInTestCall = grandparent != null && isTestCall(grandparent);
  18058. 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");
  18059. if (shouldInline) {
  18060. return concat$4(["<", join$2(", ", path$$1.map(print, paramsKey)), ">"]);
  18061. }
  18062. return group$1(concat$4(["<", indent$2(concat$4([softline$1, join$2(concat$4([",", line$3]), path$$1.map(print, paramsKey))])), ifBreak$1(options.parser !== "typescript" && shouldPrintComma(options, "all") ? "," : ""), softline$1, ">"]));
  18063. }
  18064. function printClass(path$$1, options, print) {
  18065. var n = path$$1.getValue();
  18066. var parts = [];
  18067. if (n.type === "TSAbstractClassDeclaration") {
  18068. parts.push("abstract ");
  18069. }
  18070. parts.push("class");
  18071. if (n.id) {
  18072. parts.push(" ", path$$1.call(print, "id"));
  18073. }
  18074. parts.push(path$$1.call(print, "typeParameters"));
  18075. var partsGroup = [];
  18076. if (n.superClass) {
  18077. var printed = concat$4(["extends ", path$$1.call(print, "superClass"), path$$1.call(print, "superTypeParameters")]); // Keep old behaviour of extends in same line
  18078. // If there is only on extends and there are not comments
  18079. if ((!n.implements || n.implements.length === 0) && (!n.superClass.comments || n.superClass.comments.length === 0)) {
  18080. parts.push(concat$4([" ", path$$1.call(function (superClass) {
  18081. return comments.printComments(superClass, function () {
  18082. return printed;
  18083. }, options);
  18084. }, "superClass")]));
  18085. } else {
  18086. partsGroup.push(group$1(concat$4([line$3, path$$1.call(function (superClass) {
  18087. return comments.printComments(superClass, function () {
  18088. return printed;
  18089. }, options);
  18090. }, "superClass")])));
  18091. }
  18092. } else if (n.extends && n.extends.length > 0) {
  18093. parts.push(" extends ", join$2(", ", path$$1.map(print, "extends")));
  18094. }
  18095. if (n["mixins"] && n["mixins"].length > 0) {
  18096. partsGroup.push(line$3, "mixins ", group$1(indent$2(join$2(concat$4([",", line$3]), path$$1.map(print, "mixins")))));
  18097. }
  18098. if (n["implements"] && n["implements"].length > 0) {
  18099. partsGroup.push(line$3, "implements", group$1(indent$2(concat$4([line$3, join$2(concat$4([",", line$3]), path$$1.map(print, "implements"))]))));
  18100. }
  18101. if (partsGroup.length > 0) {
  18102. parts.push(group$1(indent$2(concat$4(partsGroup))));
  18103. }
  18104. if (n.body && n.body.comments && hasLeadingOwnLineComment(options.originalText, n.body, options)) {
  18105. parts.push(hardline$3);
  18106. } else {
  18107. parts.push(" ");
  18108. }
  18109. parts.push(path$$1.call(print, "body"));
  18110. return parts;
  18111. }
  18112. function printOptionalToken(path$$1) {
  18113. var node = path$$1.getValue();
  18114. if (!node.optional) {
  18115. return "";
  18116. }
  18117. if (node.type === "OptionalCallExpression" || node.type === "OptionalMemberExpression" && node.computed) {
  18118. return "?.";
  18119. }
  18120. return "?";
  18121. }
  18122. function printMemberLookup(path$$1, options, print) {
  18123. var property = path$$1.call(print, "property");
  18124. var n = path$$1.getValue();
  18125. var optional = printOptionalToken(path$$1);
  18126. if (!n.computed) {
  18127. return concat$4([optional, ".", property]);
  18128. }
  18129. if (!n.property || isNumericLiteral(n.property)) {
  18130. return concat$4([optional, "[", property, "]"]);
  18131. }
  18132. return group$1(concat$4([optional, "[", indent$2(concat$4([softline$1, property])), softline$1, "]"]));
  18133. }
  18134. function printBindExpressionCallee(path$$1, options, print) {
  18135. return concat$4(["::", path$$1.call(print, "callee")]);
  18136. } // We detect calls on member expressions specially to format a
  18137. // common pattern better. The pattern we are looking for is this:
  18138. //
  18139. // arr
  18140. // .map(x => x + 1)
  18141. // .filter(x => x > 10)
  18142. // .some(x => x % 2)
  18143. //
  18144. // The way it is structured in the AST is via a nested sequence of
  18145. // MemberExpression and CallExpression. We need to traverse the AST
  18146. // and make groups out of it to print it in the desired way.
  18147. function printMemberChain(path$$1, options, print) {
  18148. // The first phase is to linearize the AST by traversing it down.
  18149. //
  18150. // a().b()
  18151. // has the following AST structure:
  18152. // CallExpression(MemberExpression(CallExpression(Identifier)))
  18153. // and we transform it into
  18154. // [Identifier, CallExpression, MemberExpression, CallExpression]
  18155. var printedNodes = []; // Here we try to retain one typed empty line after each call expression or
  18156. // the first group whether it is in parentheses or not
  18157. function shouldInsertEmptyLineAfter(node) {
  18158. var originalText = options.originalText;
  18159. var nextCharIndex = getNextNonSpaceNonCommentCharacterIndex$2(originalText, node, options);
  18160. var nextChar = originalText.charAt(nextCharIndex); // if it is cut off by a parenthesis, we only account for one typed empty
  18161. // line after that parenthesis
  18162. if (nextChar == ")") {
  18163. return isNextLineEmptyAfterIndex$1(originalText, nextCharIndex + 1, options);
  18164. }
  18165. return isNextLineEmpty$2(originalText, node, options);
  18166. }
  18167. function rec(path$$1) {
  18168. var node = path$$1.getValue();
  18169. if ((node.type === "CallExpression" || node.type === "OptionalCallExpression") && (isMemberish(node.callee) || node.callee.type === "CallExpression" || node.callee.type === "OptionalCallExpression")) {
  18170. printedNodes.unshift({
  18171. node: node,
  18172. printed: concat$4([comments.printComments(path$$1, function () {
  18173. return concat$4([printOptionalToken(path$$1), printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)]);
  18174. }, options), shouldInsertEmptyLineAfter(node) ? hardline$3 : ""])
  18175. });
  18176. path$$1.call(function (callee) {
  18177. return rec(callee);
  18178. }, "callee");
  18179. } else if (isMemberish(node)) {
  18180. printedNodes.unshift({
  18181. node: node,
  18182. needsParens: needsParens_1(path$$1, options),
  18183. printed: comments.printComments(path$$1, function () {
  18184. return node.type === "OptionalMemberExpression" || node.type === "MemberExpression" ? printMemberLookup(path$$1, options, print) : printBindExpressionCallee(path$$1, options, print);
  18185. }, options)
  18186. });
  18187. path$$1.call(function (object) {
  18188. return rec(object);
  18189. }, "object");
  18190. } else if (node.type === "TSNonNullExpression") {
  18191. printedNodes.unshift({
  18192. node: node,
  18193. printed: comments.printComments(path$$1, function () {
  18194. return "!";
  18195. }, options)
  18196. });
  18197. path$$1.call(function (expression) {
  18198. return rec(expression);
  18199. }, "expression");
  18200. } else {
  18201. printedNodes.unshift({
  18202. node: node,
  18203. printed: path$$1.call(print)
  18204. });
  18205. }
  18206. } // Note: the comments of the root node have already been printed, so we
  18207. // need to extract this first call without printing them as they would
  18208. // if handled inside of the recursive call.
  18209. var node = path$$1.getValue();
  18210. printedNodes.unshift({
  18211. node,
  18212. printed: concat$4([printOptionalToken(path$$1), printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)])
  18213. });
  18214. path$$1.call(function (callee) {
  18215. return rec(callee);
  18216. }, "callee"); // Once we have a linear list of printed nodes, we want to create groups out
  18217. // of it.
  18218. //
  18219. // a().b.c().d().e
  18220. // will be grouped as
  18221. // [
  18222. // [Identifier, CallExpression],
  18223. // [MemberExpression, MemberExpression, CallExpression],
  18224. // [MemberExpression, CallExpression],
  18225. // [MemberExpression],
  18226. // ]
  18227. // so that we can print it as
  18228. // a()
  18229. // .b.c()
  18230. // .d()
  18231. // .e
  18232. // The first group is the first node followed by
  18233. // - as many CallExpression as possible
  18234. // < fn()()() >.something()
  18235. // - as many array acessors as possible
  18236. // < fn()[0][1][2] >.something()
  18237. // - then, as many MemberExpression as possible but the last one
  18238. // < this.items >.something()
  18239. var groups = [];
  18240. var currentGroup = [printedNodes[0]];
  18241. var i = 1;
  18242. for (; i < printedNodes.length; ++i) {
  18243. 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(printedNodes[i].node.property)) {
  18244. currentGroup.push(printedNodes[i]);
  18245. } else {
  18246. break;
  18247. }
  18248. }
  18249. if (printedNodes[0].node.type !== "CallExpression" && printedNodes[0].node.type !== "OptionalCallExpression") {
  18250. for (; i + 1 < printedNodes.length; ++i) {
  18251. if (isMemberish(printedNodes[i].node) && isMemberish(printedNodes[i + 1].node)) {
  18252. currentGroup.push(printedNodes[i]);
  18253. } else {
  18254. break;
  18255. }
  18256. }
  18257. }
  18258. groups.push(currentGroup);
  18259. currentGroup = []; // Then, each following group is a sequence of MemberExpression followed by
  18260. // a sequence of CallExpression. To compute it, we keep adding things to the
  18261. // group until we has seen a CallExpression in the past and reach a
  18262. // MemberExpression
  18263. var hasSeenCallExpression = false;
  18264. for (; i < printedNodes.length; ++i) {
  18265. if (hasSeenCallExpression && isMemberish(printedNodes[i].node)) {
  18266. // [0] should be appended at the end of the group instead of the
  18267. // beginning of the next one
  18268. if (printedNodes[i].node.computed && isNumericLiteral(printedNodes[i].node.property)) {
  18269. currentGroup.push(printedNodes[i]);
  18270. continue;
  18271. }
  18272. groups.push(currentGroup);
  18273. currentGroup = [];
  18274. hasSeenCallExpression = false;
  18275. }
  18276. if (printedNodes[i].node.type === "CallExpression" || printedNodes[i].node.type === "OptionalCallExpression") {
  18277. hasSeenCallExpression = true;
  18278. }
  18279. currentGroup.push(printedNodes[i]);
  18280. if (printedNodes[i].node.comments && printedNodes[i].node.comments.some(function (comment) {
  18281. return comment.trailing;
  18282. })) {
  18283. groups.push(currentGroup);
  18284. currentGroup = [];
  18285. hasSeenCallExpression = false;
  18286. }
  18287. }
  18288. if (currentGroup.length > 0) {
  18289. groups.push(currentGroup);
  18290. } // There are cases like Object.keys(), Observable.of(), _.values() where
  18291. // they are the subject of all the chained calls and therefore should
  18292. // be kept on the same line:
  18293. //
  18294. // Object.keys(items)
  18295. // .filter(x => x)
  18296. // .map(x => x)
  18297. //
  18298. // In order to detect those cases, we use an heuristic: if the first
  18299. // node is an identifier with the name starting with a capital
  18300. // letter or just a sequence of _$. The rationale is that they are
  18301. // likely to be factories.
  18302. function isFactory(name) {
  18303. return /^[A-Z]|^[_$]+$/.test(name);
  18304. } // In case the Identifier is shorter than tab width, we can keep the
  18305. // first call in a single line, if it's an ExpressionStatement.
  18306. //
  18307. // d3.scaleLinear()
  18308. // .domain([0, 100])
  18309. // .range([0, width]);
  18310. //
  18311. function isShort(name) {
  18312. return name.length <= options.tabWidth;
  18313. }
  18314. function shouldNotWrap(groups) {
  18315. var parent = path$$1.getParentNode();
  18316. var isExpression = parent && parent.type === "ExpressionStatement";
  18317. var hasComputed = groups[1].length && groups[1][0].node.computed;
  18318. if (groups[0].length === 1) {
  18319. var firstNode = groups[0][0].node;
  18320. return firstNode.type === "ThisExpression" || firstNode.type === "Identifier" && (isFactory(firstNode.name) || isExpression && isShort(firstNode.name) || hasComputed);
  18321. }
  18322. var lastNode = getLast$4(groups[0]).node;
  18323. return (lastNode.type === "MemberExpression" || lastNode.type === "OptionalMemberExpression") && lastNode.property.type === "Identifier" && (isFactory(lastNode.property.name) || hasComputed);
  18324. }
  18325. var shouldMerge = groups.length >= 2 && !groups[1][0].node.comments && shouldNotWrap(groups);
  18326. function printGroup(printedGroup) {
  18327. var result = [];
  18328. for (var _i3 = 0; _i3 < printedGroup.length; _i3++) {
  18329. // Checks if the next node (i.e. the parent node) needs parens
  18330. // and print accordingl y
  18331. if (printedGroup[_i3 + 1] && printedGroup[_i3 + 1].needsParens) {
  18332. result.push("(", printedGroup[_i3].printed, printedGroup[_i3 + 1].printed, ")");
  18333. _i3++;
  18334. } else {
  18335. result.push(printedGroup[_i3].printed);
  18336. }
  18337. }
  18338. return concat$4(result);
  18339. }
  18340. function printIndentedGroup(groups) {
  18341. if (groups.length === 0) {
  18342. return "";
  18343. }
  18344. return indent$2(group$1(concat$4([hardline$3, join$2(hardline$3, groups.map(printGroup))])));
  18345. }
  18346. var printedGroups = groups.map(printGroup);
  18347. var oneLine = concat$4(printedGroups);
  18348. var cutoff = shouldMerge ? 3 : 2;
  18349. var flatGroups = groups.slice(0, cutoff).reduce(function (res, group) {
  18350. return res.concat(group);
  18351. }, []);
  18352. var hasComment = flatGroups.slice(1, -1).some(function (node) {
  18353. return hasLeadingComment(node.node);
  18354. }) || flatGroups.slice(0, -1).some(function (node) {
  18355. return hasTrailingComment(node.node);
  18356. }) || groups[cutoff] && hasLeadingComment(groups[cutoff][0].node); // If we only have a single `.`, we shouldn't do anything fancy and just
  18357. // render everything concatenated together.
  18358. if (groups.length <= cutoff && !hasComment) {
  18359. return group$1(oneLine);
  18360. } // Find out the last node in the first group and check if it has an
  18361. // empty line after
  18362. var lastNodeBeforeIndent = getLast$4(shouldMerge ? groups.slice(1, 2)[0] : groups[0]).node;
  18363. var shouldHaveEmptyLineBeforeIndent = lastNodeBeforeIndent.type !== "CallExpression" && lastNodeBeforeIndent.type !== "OptionalCallExpression" && shouldInsertEmptyLineAfter(lastNodeBeforeIndent);
  18364. var expanded = concat$4([printGroup(groups[0]), shouldMerge ? concat$4(groups.slice(1, 2).map(printGroup)) : "", shouldHaveEmptyLineBeforeIndent ? hardline$3 : "", printIndentedGroup(groups.slice(shouldMerge ? 2 : 1))]);
  18365. var callExpressionCount = printedNodes.filter(function (tuple) {
  18366. return tuple.node.type === "CallExpression" || tuple.node.type === "OptionalCallExpression";
  18367. }).length; // We don't want to print in one line if there's:
  18368. // * A comment.
  18369. // * 3 or more chained calls.
  18370. // * Any group but the last one has a hard line.
  18371. // If the last group is a function it's okay to inline if it fits.
  18372. if (hasComment || callExpressionCount >= 3 || printedGroups.slice(0, -1).some(willBreak$1)) {
  18373. return group$1(expanded);
  18374. }
  18375. return concat$4([// We only need to check `oneLine` because if `expanded` is chosen
  18376. // that means that the parent group has already been broken
  18377. // naturally
  18378. willBreak$1(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent$2 : "", conditionalGroup$1([oneLine, expanded])]);
  18379. }
  18380. function isJSXNode(node) {
  18381. return node.type === "JSXElement" || node.type === "JSXFragment" || node.type === "TSJsxFragment";
  18382. }
  18383. function isEmptyJSXElement(node) {
  18384. if (node.children.length === 0) {
  18385. return true;
  18386. }
  18387. if (node.children.length > 1) {
  18388. return false;
  18389. } // if there is one text child and does not contain any meaningful text
  18390. // we can treat the element as empty.
  18391. var child = node.children[0];
  18392. return isLiteral(child) && !isMeaningfulJSXText(child);
  18393. } // Only space, newline, carriage return, and tab are treated as whitespace
  18394. // inside JSX.
  18395. var jsxWhitespaceChars = " \n\r\t";
  18396. var containsNonJsxWhitespaceRegex = new RegExp("[^" + jsxWhitespaceChars + "]");
  18397. var matchJsxWhitespaceRegex = new RegExp("([" + jsxWhitespaceChars + "]+)"); // Meaningful if it contains non-whitespace characters,
  18398. // or it contains whitespace without a new line.
  18399. function isMeaningfulJSXText(node) {
  18400. return isLiteral(node) && (containsNonJsxWhitespaceRegex.test(rawText(node)) || !/\n/.test(rawText(node)));
  18401. }
  18402. function conditionalExpressionChainContainsJSX(node) {
  18403. return Boolean(getConditionalChainContents(node).find(isJSXNode));
  18404. } // If we have nested conditional expressions, we want to print them in JSX mode
  18405. // if there's at least one JSXElement somewhere in the tree.
  18406. //
  18407. // A conditional expression chain like this should be printed in normal mode,
  18408. // because there aren't JSXElements anywhere in it:
  18409. //
  18410. // isA ? "A" : isB ? "B" : isC ? "C" : "Unknown";
  18411. //
  18412. // But a conditional expression chain like this should be printed in JSX mode,
  18413. // because there is a JSXElement in the last ConditionalExpression:
  18414. //
  18415. // isA ? "A" : isB ? "B" : isC ? "C" : <span className="warning">Unknown</span>;
  18416. //
  18417. // This type of ConditionalExpression chain is structured like this in the AST:
  18418. //
  18419. // ConditionalExpression {
  18420. // test: ...,
  18421. // consequent: ...,
  18422. // alternate: ConditionalExpression {
  18423. // test: ...,
  18424. // consequent: ...,
  18425. // alternate: ConditionalExpression {
  18426. // test: ...,
  18427. // consequent: ...,
  18428. // alternate: ...,
  18429. // }
  18430. // }
  18431. // }
  18432. //
  18433. // We want to traverse over that shape and convert it into a flat structure so
  18434. // that we can find if there's a JSXElement somewhere inside.
  18435. function getConditionalChainContents(node) {
  18436. // Given this code:
  18437. //
  18438. // // Using a ConditionalExpression as the consequent is uncommon, but should
  18439. // // be handled.
  18440. // A ? B : C ? D : E ? F ? G : H : I
  18441. //
  18442. // which has this AST:
  18443. //
  18444. // ConditionalExpression {
  18445. // test: Identifier(A),
  18446. // consequent: Identifier(B),
  18447. // alternate: ConditionalExpression {
  18448. // test: Identifier(C),
  18449. // consequent: Identifier(D),
  18450. // alternate: ConditionalExpression {
  18451. // test: Identifier(E),
  18452. // consequent: ConditionalExpression {
  18453. // test: Identifier(F),
  18454. // consequent: Identifier(G),
  18455. // alternate: Identifier(H),
  18456. // },
  18457. // alternate: Identifier(I),
  18458. // }
  18459. // }
  18460. // }
  18461. //
  18462. // we should return this Array:
  18463. //
  18464. // [
  18465. // Identifier(A),
  18466. // Identifier(B),
  18467. // Identifier(C),
  18468. // Identifier(D),
  18469. // Identifier(E),
  18470. // Identifier(F),
  18471. // Identifier(G),
  18472. // Identifier(H),
  18473. // Identifier(I)
  18474. // ];
  18475. //
  18476. // This loses the information about whether each node was the test,
  18477. // consequent, or alternate, but we don't care about that here- we are only
  18478. // flattening this structure to find if there's any JSXElements inside.
  18479. var nonConditionalExpressions = [];
  18480. function recurse(node) {
  18481. if (node.type === "ConditionalExpression") {
  18482. recurse(node.test);
  18483. recurse(node.consequent);
  18484. recurse(node.alternate);
  18485. } else {
  18486. nonConditionalExpressions.push(node);
  18487. }
  18488. }
  18489. recurse(node);
  18490. return nonConditionalExpressions;
  18491. } // Detect an expression node representing `{" "}`
  18492. function isJSXWhitespaceExpression(node) {
  18493. return node.type === "JSXExpressionContainer" && isLiteral(node.expression) && node.expression.value === " " && !node.expression.comments;
  18494. } // JSX Children are strange, mostly for two reasons:
  18495. // 1. JSX reads newlines into string values, instead of skipping them like JS
  18496. // 2. up to one whitespace between elements within a line is significant,
  18497. // but not between lines.
  18498. //
  18499. // Leading, trailing, and lone whitespace all need to
  18500. // turn themselves into the rather ugly `{' '}` when breaking.
  18501. //
  18502. // We print JSX using the `fill` doc primitive.
  18503. // This requires that we give it an array of alternating
  18504. // content and whitespace elements.
  18505. // To ensure this we add dummy `""` content elements as needed.
  18506. function printJSXChildren(path$$1, options, print, jsxWhitespace) {
  18507. var n = path$$1.getValue();
  18508. var children = []; // using `map` instead of `each` because it provides `i`
  18509. path$$1.map(function (childPath, i) {
  18510. var child = childPath.getValue();
  18511. if (isLiteral(child)) {
  18512. var text = rawText(child); // Contains a non-whitespace character
  18513. if (isMeaningfulJSXText(child)) {
  18514. var words = text.split(matchJsxWhitespaceRegex); // Starts with whitespace
  18515. if (words[0] === "") {
  18516. children.push("");
  18517. words.shift();
  18518. if (/\n/.test(words[0])) {
  18519. children.push(hardline$3);
  18520. } else {
  18521. children.push(jsxWhitespace);
  18522. }
  18523. words.shift();
  18524. }
  18525. var endWhitespace; // Ends with whitespace
  18526. if (getLast$4(words) === "") {
  18527. words.pop();
  18528. endWhitespace = words.pop();
  18529. } // This was whitespace only without a new line.
  18530. if (words.length === 0) {
  18531. return;
  18532. }
  18533. words.forEach(function (word, i) {
  18534. if (i % 2 === 1) {
  18535. children.push(line$3);
  18536. } else {
  18537. children.push(word);
  18538. }
  18539. });
  18540. if (endWhitespace !== undefined) {
  18541. if (/\n/.test(endWhitespace)) {
  18542. children.push(hardline$3);
  18543. } else {
  18544. children.push(jsxWhitespace);
  18545. }
  18546. } else {
  18547. // Ideally this would be a `hardline` to allow a break between
  18548. // tags and text.
  18549. // Unfortunately Facebook have a custom translation pipeline
  18550. // (https://github.com/prettier/prettier/issues/1581#issuecomment-300975032)
  18551. // that uses the JSX syntax, but does not follow the React whitespace
  18552. // rules.
  18553. // Ensuring that we never have a break between tags and text in JSX
  18554. // will allow Facebook to adopt Prettier without too much of an
  18555. // adverse effect on formatting algorithm.
  18556. children.push("");
  18557. }
  18558. } else if (/\n/.test(text)) {
  18559. // Keep (up to one) blank line between tags/expressions/text.
  18560. // Note: We don't keep blank lines between text elements.
  18561. if (text.match(/\n/g).length > 1) {
  18562. children.push("");
  18563. children.push(hardline$3);
  18564. }
  18565. } else {
  18566. children.push("");
  18567. children.push(jsxWhitespace);
  18568. }
  18569. } else {
  18570. var printedChild = print(childPath);
  18571. children.push(printedChild);
  18572. var next = n.children[i + 1];
  18573. var directlyFollowedByMeaningfulText = next && isMeaningfulJSXText(next) && !/^[ \n\r\t]/.test(rawText(next));
  18574. if (directlyFollowedByMeaningfulText) {
  18575. // Potentially this could be a hardline as well.
  18576. // See the comment above about the Facebook translation pipeline as
  18577. // to why this is an empty string.
  18578. children.push("");
  18579. } else {
  18580. children.push(hardline$3);
  18581. }
  18582. }
  18583. }, "children");
  18584. return children;
  18585. } // JSX expands children from the inside-out, instead of the outside-in.
  18586. // This is both to break children before attributes,
  18587. // and to ensure that when children break, their parents do as well.
  18588. //
  18589. // Any element that is written without any newlines and fits on a single line
  18590. // is left that way.
  18591. // Not only that, any user-written-line containing multiple JSX siblings
  18592. // should also be kept on one line if possible,
  18593. // so each user-written-line is wrapped in its own group.
  18594. //
  18595. // Elements that contain newlines or don't fit on a single line (recursively)
  18596. // are fully-split, using hardline and shouldBreak: true.
  18597. //
  18598. // To support that case properly, all leading and trailing spaces
  18599. // are stripped from the list of children, and replaced with a single hardline.
  18600. function printJSXElement(path$$1, options, print) {
  18601. var n = path$$1.getValue(); // Turn <div></div> into <div />
  18602. if (n.type === "JSXElement" && isEmptyJSXElement(n)) {
  18603. n.openingElement.selfClosing = true;
  18604. return path$$1.call(print, "openingElement");
  18605. }
  18606. var openingLines = n.type === "JSXElement" ? path$$1.call(print, "openingElement") : path$$1.call(print, "openingFragment");
  18607. var closingLines = n.type === "JSXElement" ? path$$1.call(print, "closingElement") : path$$1.call(print, "closingFragment");
  18608. if (n.children.length === 1 && n.children[0].type === "JSXExpressionContainer" && (n.children[0].expression.type === "TemplateLiteral" || n.children[0].expression.type === "TaggedTemplateExpression")) {
  18609. return concat$4([openingLines, concat$4(path$$1.map(print, "children")), closingLines]);
  18610. } // Convert `{" "}` to text nodes containing a space.
  18611. // This makes it easy to turn them into `jsxWhitespace` which
  18612. // can then print as either a space or `{" "}` when breaking.
  18613. n.children = n.children.map(function (child) {
  18614. if (isJSXWhitespaceExpression(child)) {
  18615. return {
  18616. type: "JSXText",
  18617. value: " ",
  18618. raw: " "
  18619. };
  18620. }
  18621. return child;
  18622. });
  18623. var containsTag = n.children.filter(isJSXNode).length > 0;
  18624. var containsMultipleExpressions = n.children.filter(function (child) {
  18625. return child.type === "JSXExpressionContainer";
  18626. }).length > 1;
  18627. var containsMultipleAttributes = n.type === "JSXElement" && n.openingElement.attributes.length > 1; // Record any breaks. Should never go from true to false, only false to true.
  18628. var forcedBreak = willBreak$1(openingLines) || containsTag || containsMultipleAttributes || containsMultipleExpressions;
  18629. var rawJsxWhitespace = options.singleQuote ? "{' '}" : '{" "}';
  18630. var jsxWhitespace = ifBreak$1(concat$4([rawJsxWhitespace, softline$1]), " ");
  18631. var children = printJSXChildren(path$$1, options, print, jsxWhitespace);
  18632. var containsText = n.children.filter(function (child) {
  18633. return isMeaningfulJSXText(child);
  18634. }).length > 0; // We can end up we multiple whitespace elements with empty string
  18635. // content between them.
  18636. // We need to remove empty whitespace and softlines before JSX whitespace
  18637. // to get the correct output.
  18638. for (var i = children.length - 2; i >= 0; i--) {
  18639. var isPairOfEmptyStrings = children[i] === "" && children[i + 1] === "";
  18640. var isPairOfHardlines = children[i] === hardline$3 && children[i + 1] === "" && children[i + 2] === hardline$3;
  18641. var isLineFollowedByJSXWhitespace = (children[i] === softline$1 || children[i] === hardline$3) && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  18642. var isJSXWhitespaceFollowedByLine = children[i] === jsxWhitespace && children[i + 1] === "" && (children[i + 2] === softline$1 || children[i + 2] === hardline$3);
  18643. var isDoubleJSXWhitespace = children[i] === jsxWhitespace && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  18644. if (isPairOfHardlines && containsText || isPairOfEmptyStrings || isLineFollowedByJSXWhitespace || isDoubleJSXWhitespace) {
  18645. children.splice(i, 2);
  18646. } else if (isJSXWhitespaceFollowedByLine) {
  18647. children.splice(i + 1, 2);
  18648. }
  18649. } // Trim trailing lines (or empty strings)
  18650. while (children.length && (isLineNext$1(getLast$4(children)) || isEmpty$1(getLast$4(children)))) {
  18651. children.pop();
  18652. } // Trim leading lines (or empty strings)
  18653. while (children.length && (isLineNext$1(children[0]) || isEmpty$1(children[0])) && (isLineNext$1(children[1]) || isEmpty$1(children[1]))) {
  18654. children.shift();
  18655. children.shift();
  18656. } // Tweak how we format children if outputting this element over multiple lines.
  18657. // Also detect whether we will force this element to output over multiple lines.
  18658. var multilineChildren = [];
  18659. children.forEach(function (child, i) {
  18660. // There are a number of situations where we need to ensure we display
  18661. // whitespace as `{" "}` when outputting this element over multiple lines.
  18662. if (child === jsxWhitespace) {
  18663. if (i === 1 && children[i - 1] === "") {
  18664. if (children.length === 2) {
  18665. // Solitary whitespace
  18666. multilineChildren.push(rawJsxWhitespace);
  18667. return;
  18668. } // Leading whitespace
  18669. multilineChildren.push(concat$4([rawJsxWhitespace, hardline$3]));
  18670. return;
  18671. } else if (i === children.length - 1) {
  18672. // Trailing whitespace
  18673. multilineChildren.push(rawJsxWhitespace);
  18674. return;
  18675. } else if (children[i - 1] === "" && children[i - 2] === hardline$3) {
  18676. // Whitespace after line break
  18677. multilineChildren.push(rawJsxWhitespace);
  18678. return;
  18679. }
  18680. }
  18681. multilineChildren.push(child);
  18682. if (willBreak$1(child)) {
  18683. forcedBreak = true;
  18684. }
  18685. }); // If there is text we use `fill` to fit as much onto each line as possible.
  18686. // When there is no text (just tags and expressions) we use `group`
  18687. // to output each on a separate line.
  18688. var content = containsText ? fill$2(multilineChildren) : group$1(concat$4(multilineChildren), {
  18689. shouldBreak: true
  18690. });
  18691. var multiLineElem = group$1(concat$4([openingLines, indent$2(concat$4([hardline$3, content])), hardline$3, closingLines]));
  18692. if (forcedBreak) {
  18693. return multiLineElem;
  18694. }
  18695. return conditionalGroup$1([group$1(concat$4([openingLines, concat$4(children), closingLines])), multiLineElem]);
  18696. }
  18697. function maybeWrapJSXElementInParens(path$$1, elem) {
  18698. var parent = path$$1.getParentNode();
  18699. if (!parent) {
  18700. return elem;
  18701. }
  18702. var NO_WRAP_PARENTS = {
  18703. ArrayExpression: true,
  18704. JSXAttribute: true,
  18705. JSXElement: true,
  18706. JSXExpressionContainer: true,
  18707. JSXFragment: true,
  18708. TSJsxFragment: true,
  18709. ExpressionStatement: true,
  18710. CallExpression: true,
  18711. OptionalCallExpression: true,
  18712. ConditionalExpression: true
  18713. };
  18714. if (NO_WRAP_PARENTS[parent.type]) {
  18715. return elem;
  18716. }
  18717. return group$1(concat$4([ifBreak$1("("), indent$2(concat$4([softline$1, elem])), softline$1, ifBreak$1(")")]));
  18718. }
  18719. function isBinaryish(node) {
  18720. return node.type === "BinaryExpression" || node.type === "LogicalExpression";
  18721. }
  18722. function isMemberish(node) {
  18723. return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "BindExpression" && node.object;
  18724. }
  18725. function shouldInlineLogicalExpression(node) {
  18726. if (node.type !== "LogicalExpression") {
  18727. return false;
  18728. }
  18729. if (node.right.type === "ObjectExpression" && node.right.properties.length !== 0) {
  18730. return true;
  18731. }
  18732. if (node.right.type === "ArrayExpression" && node.right.elements.length !== 0) {
  18733. return true;
  18734. }
  18735. if (isJSXNode(node.right)) {
  18736. return true;
  18737. }
  18738. return false;
  18739. } // For binary expressions to be consistent, we need to group
  18740. // subsequent operators with the same precedence level under a single
  18741. // group. Otherwise they will be nested such that some of them break
  18742. // onto new lines but not all. Operators with the same precedence
  18743. // level should either all break or not. Because we group them by
  18744. // precedence level and the AST is structured based on precedence
  18745. // level, things are naturally broken up correctly, i.e. `&&` is
  18746. // broken before `+`.
  18747. function printBinaryishExpressions(path$$1, print, options, isNested, isInsideParenthesis) {
  18748. var parts = [];
  18749. var node = path$$1.getValue(); // We treat BinaryExpression and LogicalExpression nodes the same.
  18750. if (isBinaryish(node)) {
  18751. // Put all operators with the same precedence level in the same
  18752. // group. The reason we only need to do this with the `left`
  18753. // expression is because given an expression like `1 + 2 - 3`, it
  18754. // is always parsed like `((1 + 2) - 3)`, meaning the `left` side
  18755. // is where the rest of the expression will exist. Binary
  18756. // expressions on the right side mean they have a difference
  18757. // precedence level and should be treated as a separate group, so
  18758. // print them normally. (This doesn't hold for the `**` operator,
  18759. // which is unique in that it is right-associative.)
  18760. if (shouldFlatten$1(node.operator, node.left.operator)) {
  18761. // Flatten them out by recursively calling this function.
  18762. parts = parts.concat(path$$1.call(function (left) {
  18763. return printBinaryishExpressions(left, print, options,
  18764. /* isNested */
  18765. true, isInsideParenthesis);
  18766. }, "left"));
  18767. } else {
  18768. parts.push(path$$1.call(print, "left"));
  18769. }
  18770. var shouldInline = shouldInlineLogicalExpression(node);
  18771. var lineBeforeOperator = node.operator === "|>";
  18772. var right = shouldInline ? concat$4([node.operator, " ", path$$1.call(print, "right")]) : concat$4([lineBeforeOperator ? softline$1 : "", node.operator, lineBeforeOperator ? " " : line$3, path$$1.call(print, "right")]); // If there's only a single binary expression, we want to create a group
  18773. // in order to avoid having a small right part like -1 be on its own line.
  18774. var parent = path$$1.getParentNode();
  18775. var shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node.left.type !== node.type && node.right.type !== node.type;
  18776. parts.push(" ", shouldGroup ? group$1(right) : right); // The root comments are already printed, but we need to manually print
  18777. // the other ones since we don't call the normal print on BinaryExpression,
  18778. // only for the left and right parts
  18779. if (isNested && node.comments) {
  18780. parts = comments.printComments(path$$1, function () {
  18781. return concat$4(parts);
  18782. }, options);
  18783. }
  18784. } else {
  18785. // Our stopping case. Simply print the node normally.
  18786. parts.push(path$$1.call(print));
  18787. }
  18788. return parts;
  18789. }
  18790. function printAssignmentRight(leftNode, rightNode, printedRight, options) {
  18791. if (hasLeadingOwnLineComment(options.originalText, rightNode, options)) {
  18792. return indent$2(concat$4([hardline$3, printedRight]));
  18793. }
  18794. var canBreak = isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode) || rightNode.type === "ConditionalExpression" && isBinaryish(rightNode.test) && !shouldInlineLogicalExpression(rightNode.test) || rightNode.type === "StringLiteralTypeAnnotation" || (leftNode.type === "Identifier" || isStringLiteral(leftNode) || leftNode.type === "MemberExpression") && (isStringLiteral(rightNode) || isMemberExpressionChain(rightNode));
  18795. if (canBreak) {
  18796. return indent$2(concat$4([line$3, printedRight]));
  18797. }
  18798. return concat$4([" ", printedRight]);
  18799. }
  18800. function printAssignment(leftNode, printedLeft, operator, rightNode, printedRight, options) {
  18801. if (!rightNode) {
  18802. return printedLeft;
  18803. }
  18804. var printed = printAssignmentRight(leftNode, rightNode, printedRight, options);
  18805. return group$1(concat$4([printedLeft, operator, printed]));
  18806. }
  18807. function adjustClause(node, clause, forceSpace) {
  18808. if (node.type === "EmptyStatement") {
  18809. return ";";
  18810. }
  18811. if (node.type === "BlockStatement" || forceSpace) {
  18812. return concat$4([" ", clause]);
  18813. }
  18814. return indent$2(concat$4([line$3, clause]));
  18815. }
  18816. function nodeStr(node, options, isFlowOrTypeScriptDirectiveLiteral) {
  18817. var raw = rawText(node);
  18818. var isDirectiveLiteral = isFlowOrTypeScriptDirectiveLiteral || node.type === "DirectiveLiteral";
  18819. return printString$1(raw, options, isDirectiveLiteral);
  18820. }
  18821. function printRegex(node) {
  18822. var flags = node.flags.split("").sort().join("");
  18823. return `/${node.pattern}/${flags}`;
  18824. }
  18825. function isLastStatement(path$$1) {
  18826. var parent = path$$1.getParentNode();
  18827. if (!parent) {
  18828. return true;
  18829. }
  18830. var node = path$$1.getValue();
  18831. var body = (parent.body || parent.consequent).filter(function (stmt) {
  18832. return stmt.type !== "EmptyStatement";
  18833. });
  18834. return body && body[body.length - 1] === node;
  18835. }
  18836. function hasLeadingComment(node) {
  18837. return node.comments && node.comments.some(function (comment) {
  18838. return comment.leading;
  18839. });
  18840. }
  18841. function hasTrailingComment(node) {
  18842. return node.comments && node.comments.some(function (comment) {
  18843. return comment.trailing;
  18844. });
  18845. }
  18846. function hasLeadingOwnLineComment(text, node, options) {
  18847. if (isJSXNode(node)) {
  18848. return hasNodeIgnoreComment$1(node);
  18849. }
  18850. var res = node.comments && node.comments.some(function (comment) {
  18851. return comment.leading && hasNewline$2(text, options.locEnd(comment));
  18852. });
  18853. return res;
  18854. }
  18855. function hasNakedLeftSide(node) {
  18856. return node.type === "AssignmentExpression" || node.type === "BinaryExpression" || node.type === "LogicalExpression" || 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.object || node.type === "UpdateExpression" && !node.prefix;
  18857. }
  18858. function isFlowAnnotationComment(text, typeAnnotation, options) {
  18859. var start = options.locStart(typeAnnotation);
  18860. var end = skipWhitespace$1(text, options.locEnd(typeAnnotation));
  18861. return text.substr(start, 2) === "/*" && text.substr(end, 2) === "*/";
  18862. }
  18863. function getLeftSide(node) {
  18864. if (node.expressions) {
  18865. return node.expressions[0];
  18866. }
  18867. return node.left || node.test || node.callee || node.object || node.tag || node.argument || node.expression;
  18868. }
  18869. function getLeftSidePathName(path$$1, node) {
  18870. if (node.expressions) {
  18871. return ["expressions", 0];
  18872. }
  18873. if (node.left) {
  18874. return ["left"];
  18875. }
  18876. if (node.test) {
  18877. return ["test"];
  18878. }
  18879. if (node.callee) {
  18880. return ["callee"];
  18881. }
  18882. if (node.object) {
  18883. return ["object"];
  18884. }
  18885. if (node.tag) {
  18886. return ["tag"];
  18887. }
  18888. if (node.argument) {
  18889. return ["argument"];
  18890. }
  18891. if (node.expression) {
  18892. return ["expression"];
  18893. }
  18894. throw new Error("Unexpected node has no left side", node);
  18895. }
  18896. function exprNeedsASIProtection(path$$1, options) {
  18897. var node = path$$1.getValue();
  18898. var maybeASIProblem = needsParens_1(path$$1, options) || node.type === "ParenthesizedExpression" || node.type === "TypeCastExpression" || node.type === "ArrowFunctionExpression" && !shouldPrintParamsWithoutParens(path$$1, options) || node.type === "ArrayExpression" || node.type === "ArrayPattern" || node.type === "UnaryExpression" && node.prefix && (node.operator === "+" || node.operator === "-") || node.type === "TemplateLiteral" || node.type === "TemplateElement" || isJSXNode(node) || node.type === "BindExpression" || node.type === "RegExpLiteral" || node.type === "Literal" && node.pattern || node.type === "Literal" && node.regex;
  18899. if (maybeASIProblem) {
  18900. return true;
  18901. }
  18902. if (!hasNakedLeftSide(node)) {
  18903. return false;
  18904. }
  18905. return path$$1.call.apply(path$$1, [function (childPath) {
  18906. return exprNeedsASIProtection(childPath, options);
  18907. }].concat(getLeftSidePathName(path$$1, node)));
  18908. }
  18909. function stmtNeedsASIProtection(path$$1, options) {
  18910. var node = path$$1.getNode();
  18911. if (node.type !== "ExpressionStatement") {
  18912. return false;
  18913. }
  18914. return path$$1.call(function (childPath) {
  18915. return exprNeedsASIProtection(childPath, options);
  18916. }, "expression");
  18917. }
  18918. function classPropMayCauseASIProblems(path$$1) {
  18919. var node = path$$1.getNode();
  18920. if (node.type !== "ClassProperty") {
  18921. return false;
  18922. }
  18923. var name = node.key && node.key.name; // this isn't actually possible yet with most parsers available today
  18924. // so isn't properly tested yet.
  18925. if ((name === "static" || name === "get" || name === "set") && !node.value && !node.typeAnnotation) {
  18926. return true;
  18927. }
  18928. }
  18929. function classChildNeedsASIProtection(node) {
  18930. if (!node) {
  18931. return;
  18932. }
  18933. if (!node.computed) {
  18934. var name = node.key && node.key.name;
  18935. if (name === "in" || name === "instanceof") {
  18936. return true;
  18937. }
  18938. }
  18939. switch (node.type) {
  18940. case "ClassProperty":
  18941. case "TSAbstractClassProperty":
  18942. return node.computed;
  18943. case "MethodDefinition": // Flow
  18944. case "TSAbstractMethodDefinition": // TypeScript
  18945. case "ClassMethod":
  18946. {
  18947. // Babylon
  18948. var isAsync = node.value ? node.value.async : node.async;
  18949. var isGenerator = node.value ? node.value.generator : node.generator;
  18950. if (isAsync || node.static || node.kind === "get" || node.kind === "set") {
  18951. return false;
  18952. }
  18953. if (node.computed || isGenerator) {
  18954. return true;
  18955. }
  18956. return false;
  18957. }
  18958. default:
  18959. /* istanbul ignore next */
  18960. return false;
  18961. }
  18962. } // This recurses the return argument, looking for the first token
  18963. // (the leftmost leaf node) and, if it (or its parents) has any
  18964. // leadingComments, returns true (so it can be wrapped in parens).
  18965. function returnArgumentHasLeadingComment(options, argument) {
  18966. if (hasLeadingOwnLineComment(options.originalText, argument, options)) {
  18967. return true;
  18968. }
  18969. if (hasNakedLeftSide(argument)) {
  18970. var leftMost = argument;
  18971. var newLeftMost;
  18972. while (newLeftMost = getLeftSide(leftMost)) {
  18973. leftMost = newLeftMost;
  18974. if (hasLeadingOwnLineComment(options.originalText, leftMost, options)) {
  18975. return true;
  18976. }
  18977. }
  18978. }
  18979. return false;
  18980. }
  18981. function isMemberExpressionChain(node) {
  18982. if (node.type !== "MemberExpression" && node.type !== "OptionalMemberExpression") {
  18983. return false;
  18984. }
  18985. if (node.object.type === "Identifier") {
  18986. return true;
  18987. }
  18988. return isMemberExpressionChain(node.object);
  18989. } // Hack to differentiate between the following two which have the same ast
  18990. // type T = { method: () => void };
  18991. // type T = { method(): void };
  18992. function isObjectTypePropertyAFunction(node, options) {
  18993. return node.type === "ObjectTypeProperty" && node.value.type === "FunctionTypeAnnotation" && !node.static && !isFunctionNotation(node, options);
  18994. } // TODO: This is a bad hack and we need a better way to distinguish between
  18995. // arrow functions and otherwise
  18996. function isFunctionNotation(node, options) {
  18997. return isGetterOrSetter(node) || sameLocStart(node, node.value, options);
  18998. }
  18999. function isGetterOrSetter(node) {
  19000. return node.kind === "get" || node.kind === "set";
  19001. }
  19002. function sameLocStart(nodeA, nodeB, options) {
  19003. return options.locStart(nodeA) === options.locStart(nodeB);
  19004. } // Hack to differentiate between the following two which have the same ast
  19005. // declare function f(a): void;
  19006. // var f: (a) => void;
  19007. function isTypeAnnotationAFunction(node, options) {
  19008. return (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") && node.typeAnnotation.type === "FunctionTypeAnnotation" && !node.static && !sameLocStart(node, node.typeAnnotation, options);
  19009. }
  19010. function isNodeStartingWithDeclare(node, options) {
  19011. if (!(options.parser === "flow" || options.parser === "typescript")) {
  19012. return false;
  19013. }
  19014. return options.originalText.slice(0, options.locStart(node)).match(/declare[ \t]*$/) || options.originalText.slice(node.range[0], node.range[1]).startsWith("declare ");
  19015. }
  19016. function shouldHugType(node) {
  19017. if (isObjectType(node)) {
  19018. return true;
  19019. }
  19020. if (node.type === "UnionTypeAnnotation" || node.type === "TSUnionType") {
  19021. var voidCount = node.types.filter(function (n) {
  19022. return n.type === "VoidTypeAnnotation" || n.type === "TSVoidKeyword" || n.type === "NullLiteralTypeAnnotation" || n.type === "TSNullKeyword";
  19023. }).length;
  19024. var objectCount = node.types.filter(function (n) {
  19025. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral" || // This is a bit aggressive but captures Array<{x}>
  19026. n.type === "GenericTypeAnnotation" || n.type === "TSTypeReference";
  19027. }).length;
  19028. if (node.types.length - 1 === voidCount && objectCount > 0) {
  19029. return true;
  19030. }
  19031. }
  19032. return false;
  19033. }
  19034. function shouldHugArguments(fun) {
  19035. 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(fun.params[0].typeAnnotation.typeAnnotation) || fun.params[0].type === "FunctionTypeParam" && isObjectType(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;
  19036. }
  19037. function templateLiteralHasNewLines(template) {
  19038. return template.quasis.some(function (quasi) {
  19039. return quasi.value.raw.includes("\n");
  19040. });
  19041. }
  19042. function isTemplateOnItsOwnLine(n, text, options) {
  19043. return (n.type === "TemplateLiteral" && templateLiteralHasNewLines(n) || n.type === "TaggedTemplateExpression" && templateLiteralHasNewLines(n.quasi)) && !hasNewline$2(text, options.locStart(n), {
  19044. backwards: true
  19045. });
  19046. }
  19047. function printArrayItems(path$$1, options, printPath, print) {
  19048. var printedElements = [];
  19049. var separatorParts = [];
  19050. path$$1.each(function (childPath) {
  19051. printedElements.push(concat$4(separatorParts));
  19052. printedElements.push(group$1(print(childPath)));
  19053. separatorParts = [",", line$3];
  19054. if (childPath.getValue() && isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  19055. separatorParts.push(softline$1);
  19056. }
  19057. }, printPath);
  19058. return concat$4(printedElements);
  19059. }
  19060. function hasDanglingComments(node) {
  19061. return node.comments && node.comments.some(function (comment) {
  19062. return !comment.leading && !comment.trailing;
  19063. });
  19064. }
  19065. function needsHardlineAfterDanglingComment(node) {
  19066. if (!node.comments) {
  19067. return false;
  19068. }
  19069. var lastDanglingComment = getLast$4(node.comments.filter(function (comment) {
  19070. return !comment.leading && !comment.trailing;
  19071. }));
  19072. return lastDanglingComment && !comments$3.isBlockComment(lastDanglingComment);
  19073. }
  19074. function isLiteral(node) {
  19075. 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";
  19076. }
  19077. function isNumericLiteral(node) {
  19078. return node.type === "NumericLiteral" || node.type === "Literal" && typeof node.value === "number";
  19079. }
  19080. function isStringLiteral(node) {
  19081. return node.type === "StringLiteral" || node.type === "Literal" && typeof node.value === "string";
  19082. }
  19083. function isObjectType(n) {
  19084. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral";
  19085. }
  19086. var unitTestRe = /^(skip|[fx]?(it|describe|test))$/; // eg; `describe("some string", (done) => {})`
  19087. function isTestCall(n, parent) {
  19088. if (n.type !== "CallExpression") {
  19089. return false;
  19090. }
  19091. if (n.arguments.length === 1) {
  19092. if (isAngularTestWrapper(n) && parent && isTestCall(parent)) {
  19093. return isFunctionOrArrowExpression(n.arguments[0].type);
  19094. }
  19095. if (isUnitTestSetUp(n)) {
  19096. return isFunctionOrArrowExpression(n.arguments[0].type) || isAngularTestWrapper(n.arguments[0]);
  19097. }
  19098. } else if (n.arguments.length === 2) {
  19099. if ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name) || isSkipOrOnlyBlock(n)) && (isTemplateLiteral(n.arguments[0]) || isStringLiteral(n.arguments[0]))) {
  19100. return isFunctionOrArrowExpression(n.arguments[1].type) && n.arguments[1].params.length <= 1 || isAngularTestWrapper(n.arguments[1]);
  19101. }
  19102. }
  19103. return false;
  19104. }
  19105. function isSkipOrOnlyBlock(node) {
  19106. 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");
  19107. }
  19108. function isTemplateLiteral(node) {
  19109. return node.type === "TemplateLiteral";
  19110. } // `inject` is used in AngularJS 1.x, `async` in Angular 2+
  19111. // example: https://docs.angularjs.org/guide/unit-testing#using-beforeall-
  19112. function isAngularTestWrapper(node) {
  19113. return (node.type === "CallExpression" || node.type === "OptionalCallExpression") && node.callee.type === "Identifier" && (node.callee.name === "async" || node.callee.name === "inject");
  19114. }
  19115. function isFunctionOrArrowExpression(type) {
  19116. return type === "FunctionExpression" || type === "ArrowFunctionExpression";
  19117. }
  19118. function isUnitTestSetUp(n) {
  19119. var unitTestSetUpRe = /^(before|after)(Each|All)$/;
  19120. return n.callee.type === "Identifier" && unitTestSetUpRe.test(n.callee.name) && n.arguments.length === 1;
  19121. }
  19122. function isTheOnlyJSXElementInMarkdown(options, path$$1) {
  19123. if (options.parentParser !== "markdown") {
  19124. return false;
  19125. }
  19126. var node = path$$1.getNode();
  19127. if (!node.expression || !isJSXNode(node.expression)) {
  19128. return false;
  19129. }
  19130. var parent = path$$1.getParentNode();
  19131. return parent.type === "Program" && parent.body.length == 1;
  19132. }
  19133. function willPrintOwnComments(path$$1) {
  19134. var node = path$$1.getValue();
  19135. var parent = path$$1.getParentNode();
  19136. return (node && isJSXNode(node) || parent && (parent.type === "JSXSpreadAttribute" || parent.type === "JSXSpreadChild" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node)) && !hasIgnoreComment$1(path$$1);
  19137. }
  19138. function canAttachComment(node) {
  19139. return node.type && node.type !== "CommentBlock" && node.type !== "CommentLine" && node.type !== "Line" && node.type !== "Block" && node.type !== "EmptyStatement" && node.type !== "TemplateElement" && node.type !== "Import" && !(node.callee && node.callee.type === "Import");
  19140. }
  19141. function printComment$1(commentPath, options) {
  19142. var comment = commentPath.getValue();
  19143. switch (comment.type) {
  19144. case "CommentBlock":
  19145. case "Block":
  19146. {
  19147. if (isJsDocComment(comment)) {
  19148. var printed = printJsDocComment(comment); // We need to prevent an edge case of a previous trailing comment
  19149. // printed as a `lineSuffix` which causes the comments to be
  19150. // interleaved. See https://github.com/prettier/prettier/issues/4412
  19151. if (comment.trailing && !hasNewline$2(options.originalText, options.locStart(comment), {
  19152. backwards: true
  19153. })) {
  19154. return concat$4([hardline$3, printed]);
  19155. }
  19156. return printed;
  19157. }
  19158. var isInsideFlowComment = options.originalText.substr(options.locEnd(comment) - 3, 3) === "*-/";
  19159. return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
  19160. }
  19161. case "CommentLine":
  19162. case "Line":
  19163. // Print shebangs with the proper comment characters
  19164. if (options.originalText.slice(options.locStart(comment)).startsWith("#!")) {
  19165. return "#!" + comment.value.trimRight();
  19166. }
  19167. return "//" + comment.value.trimRight();
  19168. default:
  19169. throw new Error("Not a comment: " + JSON.stringify(comment));
  19170. }
  19171. }
  19172. function isJsDocComment(comment) {
  19173. var lines = comment.value.split("\n");
  19174. return lines.length > 1 && lines.slice(0, lines.length - 1).every(function (line) {
  19175. return line.trim()[0] === "*";
  19176. });
  19177. }
  19178. function printJsDocComment(comment) {
  19179. var lines = comment.value.split("\n");
  19180. return concat$4(["/*", join$2(hardline$3, lines.map(function (line, index) {
  19181. return (index > 0 ? " " : "") + (index < lines.length - 1 ? line.trim() : line.trimLeft());
  19182. })), "*/"]);
  19183. }
  19184. function rawText(node) {
  19185. return node.extra ? node.extra.raw : node.raw;
  19186. }
  19187. var printerEstree = {
  19188. print: genericPrint$1,
  19189. embed: embed_1,
  19190. insertPragma,
  19191. massageAstNode: clean_1,
  19192. hasPrettierIgnore,
  19193. willPrintOwnComments,
  19194. canAttachComment,
  19195. printComment: printComment$1,
  19196. isBlockComment: comments$3.isBlockComment,
  19197. handleComments: {
  19198. ownLine: comments$3.handleOwnLineComment,
  19199. endOfLine: comments$3.handleEndOfLineComment,
  19200. remaining: comments$3.handleRemainingComment
  19201. }
  19202. };
  19203. var _require$$0$builders$2 = doc.builders;
  19204. var concat$6 = _require$$0$builders$2.concat;
  19205. var hardline$5 = _require$$0$builders$2.hardline;
  19206. var indent$4 = _require$$0$builders$2.indent;
  19207. var join$4 = _require$$0$builders$2.join;
  19208. function genericPrint$2(path$$1, options, print) {
  19209. var node = path$$1.getValue();
  19210. switch (node.type) {
  19211. case "ArrayExpression":
  19212. return node.elements.length === 0 ? "[]" : concat$6(["[", indent$4(concat$6([hardline$5, join$4(concat$6([",", hardline$5]), path$$1.map(print, "elements"))])), hardline$5, "]"]);
  19213. case "ObjectExpression":
  19214. return node.properties.length === 0 ? "{}" : concat$6(["{", indent$4(concat$6([hardline$5, join$4(concat$6([",", hardline$5]), path$$1.map(print, "properties"))])), hardline$5, "}"]);
  19215. case "ObjectProperty":
  19216. return concat$6([path$$1.call(print, "key"), ": ", path$$1.call(print, "value")]);
  19217. case "UnaryExpression":
  19218. return concat$6([node.operator === "+" ? "" : node.operator, path$$1.call(print, "argument")]);
  19219. case "NullLiteral":
  19220. return "null";
  19221. case "BooleanLiteral":
  19222. return node.value ? "true" : "false";
  19223. case "StringLiteral":
  19224. case "NumericLiteral":
  19225. return JSON.stringify(node.value);
  19226. case "Identifier":
  19227. return JSON.stringify(node.name);
  19228. default:
  19229. /* istanbul ignore next */
  19230. throw new Error("unknown type: " + JSON.stringify(node.type));
  19231. }
  19232. }
  19233. function clean$2(node, newNode
  19234. /*, parent*/
  19235. ) {
  19236. delete newNode.start;
  19237. delete newNode.end;
  19238. delete newNode.extra;
  19239. delete newNode.loc;
  19240. delete newNode.comments;
  19241. if (node.type === "Identifier") {
  19242. return {
  19243. type: "StringLiteral",
  19244. value: node.name
  19245. };
  19246. }
  19247. if (node.type === "UnaryExpression" && node.operator === "+") {
  19248. return newNode.argument;
  19249. }
  19250. }
  19251. var printerEstreeJson = {
  19252. print: genericPrint$2,
  19253. massageAstNode: clean$2
  19254. };
  19255. var CATEGORY_COMMON = "Common"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  19256. var commonOptions = {
  19257. bracketSpacing: {
  19258. since: "0.0.0",
  19259. category: CATEGORY_COMMON,
  19260. type: "boolean",
  19261. default: true,
  19262. description: "Print spaces between brackets.",
  19263. oppositeDescription: "Do not print spaces between brackets."
  19264. },
  19265. singleQuote: {
  19266. since: "0.0.0",
  19267. category: CATEGORY_COMMON,
  19268. type: "boolean",
  19269. default: false,
  19270. description: "Use single quotes instead of double quotes."
  19271. }
  19272. };
  19273. var CATEGORY_JAVASCRIPT = "JavaScript"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  19274. var options$4 = {
  19275. arrowParens: {
  19276. since: "1.9.0",
  19277. category: CATEGORY_JAVASCRIPT,
  19278. type: "choice",
  19279. default: "avoid",
  19280. description: "Include parentheses around a sole arrow function parameter.",
  19281. choices: [{
  19282. value: "avoid",
  19283. description: "Omit parens when possible. Example: `x => x`"
  19284. }, {
  19285. value: "always",
  19286. description: "Always include parens. Example: `(x) => x`"
  19287. }]
  19288. },
  19289. bracketSpacing: commonOptions.bracketSpacing,
  19290. jsxBracketSameLine: {
  19291. since: "0.17.0",
  19292. category: CATEGORY_JAVASCRIPT,
  19293. type: "boolean",
  19294. default: false,
  19295. description: "Put > on the last line instead of at a new line."
  19296. },
  19297. semi: {
  19298. since: "1.0.0",
  19299. category: CATEGORY_JAVASCRIPT,
  19300. type: "boolean",
  19301. default: true,
  19302. description: "Print semicolons.",
  19303. oppositeDescription: "Do not print semicolons, except at the beginning of lines which may need them."
  19304. },
  19305. singleQuote: commonOptions.singleQuote,
  19306. trailingComma: {
  19307. since: "0.0.0",
  19308. category: CATEGORY_JAVASCRIPT,
  19309. type: "choice",
  19310. default: [{
  19311. since: "0.0.0",
  19312. value: false
  19313. }, {
  19314. since: "0.19.0",
  19315. value: "none"
  19316. }],
  19317. description: "Print trailing commas wherever possible when multi-line.",
  19318. choices: [{
  19319. value: "none",
  19320. description: "No trailing commas."
  19321. }, {
  19322. value: "es5",
  19323. description: "Trailing commas where valid in ES5 (objects, arrays, etc.)"
  19324. }, {
  19325. value: "all",
  19326. description: "Trailing commas wherever possible (including function arguments)."
  19327. }, {
  19328. value: true,
  19329. deprecated: "0.19.0",
  19330. redirect: "es5"
  19331. }, {
  19332. value: false,
  19333. deprecated: "0.19.0",
  19334. redirect: "none"
  19335. }]
  19336. }
  19337. };
  19338. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  19339. var languages = [{
  19340. name: "JavaScript",
  19341. since: "0.0.0",
  19342. parsers: ["babylon", "flow"],
  19343. group: "JavaScript",
  19344. tmScope: "source.js",
  19345. aceMode: "javascript",
  19346. codemirrorMode: "javascript",
  19347. codemirrorMimeType: "text/javascript",
  19348. aliases: ["js", "node"],
  19349. extensions: [".js", "._js", ".bones", ".es", ".es6", ".frag", ".gs", ".jake", ".jsb", ".jscad", ".jsfl", ".jsm", ".jss", ".mjs", ".njs", ".pac", ".sjs", ".ssjs", ".xsjs", ".xsjslib"],
  19350. filenames: ["Jakefile"],
  19351. linguistLanguageId: 183,
  19352. vscodeLanguageIds: ["javascript"]
  19353. }, {
  19354. name: "JSX",
  19355. since: "0.0.0",
  19356. parsers: ["babylon", "flow"],
  19357. group: "JavaScript",
  19358. extensions: [".jsx"],
  19359. tmScope: "source.js.jsx",
  19360. aceMode: "javascript",
  19361. codemirrorMode: "jsx",
  19362. codemirrorMimeType: "text/jsx",
  19363. liguistLanguageId: 178,
  19364. vscodeLanguageIds: ["javascriptreact"]
  19365. }, {
  19366. name: "TypeScript",
  19367. since: "1.4.0",
  19368. parsers: ["typescript-eslint"],
  19369. group: "JavaScript",
  19370. aliases: ["ts"],
  19371. extensions: [".ts", ".tsx"],
  19372. tmScope: "source.ts",
  19373. aceMode: "typescript",
  19374. codemirrorMode: "javascript",
  19375. codemirrorMimeType: "application/typescript",
  19376. liguistLanguageId: 378,
  19377. vscodeLanguageIds: ["typescript", "typescriptreact"]
  19378. }, {
  19379. name: "JSON.stringify",
  19380. since: "1.13.0",
  19381. parsers: ["json-stringify"],
  19382. group: "JavaScript",
  19383. tmScope: "source.json",
  19384. aceMode: "json",
  19385. codemirrorMode: "javascript",
  19386. codemirrorMimeType: "application/json",
  19387. extensions: [],
  19388. // .json file defaults to json instead of json-stringify
  19389. filenames: ["package.json", "package-lock.json", "composer.json"],
  19390. linguistLanguageId: 174,
  19391. vscodeLanguageIds: ["json"]
  19392. }, {
  19393. name: "JSON",
  19394. since: "1.5.0",
  19395. parsers: ["json"],
  19396. group: "JavaScript",
  19397. tmScope: "source.json",
  19398. aceMode: "json",
  19399. codemirrorMode: "javascript",
  19400. codemirrorMimeType: "application/json",
  19401. extensions: [".json", ".geojson", ".JSON-tmLanguage", ".topojson"],
  19402. filenames: [".arcconfig", ".jshintrc", ".eslintrc", ".prettierrc", "composer.lock", "mcmod.info"],
  19403. linguistLanguageId: 174,
  19404. vscodeLanguageIds: ["json", "jsonc"]
  19405. }, {
  19406. name: "JSON5",
  19407. since: "1.13.0",
  19408. parsers: ["json5"],
  19409. group: "JavaScript",
  19410. tmScope: "source.json",
  19411. aceMode: "json",
  19412. codemirrorMode: "javascript",
  19413. codemirrorMimeType: "application/json",
  19414. extensions: [".json5"],
  19415. filenames: [".babelrc"],
  19416. linguistLanguageId: 175,
  19417. vscodeLanguageIds: ["json5"]
  19418. }];
  19419. var printers = {
  19420. estree: printerEstree,
  19421. "estree-json": printerEstreeJson
  19422. };
  19423. var languageJs = {
  19424. languages,
  19425. options: options$4,
  19426. printers
  19427. };
  19428. var index$5 = ["a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "command", "content", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "element", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "iframe", "image", "img", "input", "ins", "isindex", "kbd", "keygen", "label", "legend", "li", "link", "listing", "main", "map", "mark", "marquee", "math", "menu", "menuitem", "meta", "meter", "multicol", "nav", "nextid", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "plaintext", "pre", "progress", "q", "rb", "rbc", "rp", "rt", "rtc", "ruby", "s", "samp", "script", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "svg", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp"];
  19429. var htmlTagNames = Object.freeze({
  19430. default: index$5
  19431. });
  19432. var htmlTagNames$1 = ( htmlTagNames && index$5 ) || htmlTagNames;
  19433. function clean$3(ast, newObj) {
  19434. ["raws", "sourceIndex", "source", "before", "after", "trailingComma"].forEach(function (name) {
  19435. delete newObj[name];
  19436. });
  19437. if (ast.type === "media-query" || ast.type === "media-query-list" || ast.type === "media-feature-expression") {
  19438. delete newObj.value;
  19439. }
  19440. if (ast.type === "css-rule") {
  19441. delete newObj.params;
  19442. }
  19443. if (ast.type === "selector-combinator") {
  19444. newObj.value = newObj.value.replace(/\s+/g, " ");
  19445. }
  19446. if (ast.type === "media-feature") {
  19447. newObj.value = newObj.value.replace(/ /g, "");
  19448. }
  19449. 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") {
  19450. newObj.value = newObj.value.toLowerCase();
  19451. }
  19452. if (ast.type === "css-decl") {
  19453. newObj.prop = newObj.prop.toLowerCase();
  19454. }
  19455. if (ast.type === "css-atrule" || ast.type === "css-import") {
  19456. newObj.name = newObj.name.toLowerCase();
  19457. }
  19458. if (ast.type === "value-number") {
  19459. newObj.unit = newObj.unit.toLowerCase();
  19460. }
  19461. 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) {
  19462. newObj.value = cleanCSSStrings(newObj.value);
  19463. }
  19464. if (ast.type === "selector-attribute") {
  19465. newObj.attribute = newObj.attribute.trim();
  19466. if (newObj.namespace) {
  19467. if (typeof newObj.namespace === "string") {
  19468. newObj.namespace = newObj.namespace.trim();
  19469. if (newObj.namespace.length === 0) {
  19470. newObj.namespace = true;
  19471. }
  19472. }
  19473. }
  19474. if (newObj.value) {
  19475. newObj.value = newObj.value.trim().replace(/^['"]|['"]$/g, "");
  19476. delete newObj.quoted;
  19477. }
  19478. }
  19479. 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) {
  19480. newObj.value = newObj.value.replace(/([\d.eE+-]+)([a-zA-Z]*)/g, function (match, numStr, unit) {
  19481. var num = Number(numStr);
  19482. return isNaN(num) ? match : num + unit.toLowerCase();
  19483. });
  19484. }
  19485. if (ast.type === "selector-tag") {
  19486. var lowercasedValue = ast.value.toLowerCase();
  19487. if (htmlTagNames$1.indexOf(lowercasedValue) !== -1) {
  19488. newObj.value = lowercasedValue;
  19489. }
  19490. if (["from", "to"].indexOf(lowercasedValue) !== -1) {
  19491. newObj.value = lowercasedValue;
  19492. }
  19493. } // Workaround when `postcss-values-parser` parse `not`, `and` or `or` keywords as `value-func`
  19494. if (ast.type === "css-atrule" && ast.name.toLowerCase() === "supports") {
  19495. delete newObj.value;
  19496. } // Workaround for SCSS nested properties
  19497. if (ast.type === "selector-unknown") {
  19498. delete newObj.value;
  19499. }
  19500. }
  19501. function cleanCSSStrings(value) {
  19502. return value.replace(/'/g, '"').replace(/\\([^a-fA-F\d])/g, "$1");
  19503. }
  19504. var clean_1$2 = clean$3;
  19505. 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"];
  19506. function getAncestorCounter(path$$1, typeOrTypes) {
  19507. var types = [].concat(typeOrTypes);
  19508. var counter = -1;
  19509. var ancestorNode;
  19510. while (ancestorNode = path$$1.getParentNode(++counter)) {
  19511. if (types.indexOf(ancestorNode.type) !== -1) {
  19512. return counter;
  19513. }
  19514. }
  19515. return -1;
  19516. }
  19517. function getAncestorNode$1(path$$1, typeOrTypes) {
  19518. var counter = getAncestorCounter(path$$1, typeOrTypes);
  19519. return counter === -1 ? null : path$$1.getParentNode(counter);
  19520. }
  19521. function getPropOfDeclNode$1(path$$1) {
  19522. var declAncestorNode = getAncestorNode$1(path$$1, "css-decl");
  19523. return declAncestorNode && declAncestorNode.prop && declAncestorNode.prop.toLowerCase();
  19524. }
  19525. function isSCSS$1(parser, text) {
  19526. var hasExplicitParserChoice = parser === "less" || parser === "scss";
  19527. var IS_POSSIBLY_SCSS = /(\w\s*: [^}:]+|#){|@import[^\n]+(url|,)/;
  19528. return hasExplicitParserChoice ? parser === "scss" : IS_POSSIBLY_SCSS.test(text);
  19529. }
  19530. function isWideKeywords$1(value) {
  19531. return ["initial", "inherit", "unset", "revert"].indexOf(value.toLowerCase()) !== -1;
  19532. }
  19533. function isKeyframeAtRuleKeywords$1(path$$1, value) {
  19534. var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
  19535. return atRuleAncestorNode && atRuleAncestorNode.name && atRuleAncestorNode.name.toLowerCase().endsWith("keyframes") && ["from", "to"].indexOf(value.toLowerCase()) !== -1;
  19536. }
  19537. function maybeToLowerCase$1(value) {
  19538. return value.includes("$") || value.includes("@") || value.includes("#") || value.startsWith("%") || value.startsWith("--") || value.startsWith(":--") || value.includes("(") && value.includes(")") ? value : value.toLowerCase();
  19539. }
  19540. function insideValueFunctionNode$1(path$$1, functionName) {
  19541. var funcAncestorNode = getAncestorNode$1(path$$1, "value-func");
  19542. return funcAncestorNode && funcAncestorNode.value && funcAncestorNode.value.toLowerCase() === functionName;
  19543. }
  19544. function insideICSSRuleNode$1(path$$1) {
  19545. var ruleAncestorNode = getAncestorNode$1(path$$1, "css-rule");
  19546. return ruleAncestorNode && ruleAncestorNode.raws && ruleAncestorNode.raws.selector && (ruleAncestorNode.raws.selector.startsWith(":import") || ruleAncestorNode.raws.selector.startsWith(":export"));
  19547. }
  19548. function insideAtRuleNode$1(path$$1, atRuleNameOrAtRuleNames) {
  19549. var atRuleNames = [].concat(atRuleNameOrAtRuleNames);
  19550. var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
  19551. return atRuleAncestorNode && atRuleNames.indexOf(atRuleAncestorNode.name.toLowerCase()) !== -1;
  19552. }
  19553. function insideURLFunctionInImportAtRuleNode$1(path$$1) {
  19554. var node = path$$1.getValue();
  19555. var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
  19556. return atRuleAncestorNode && atRuleAncestorNode.name === "import" && node.groups[0].value === "url" && node.groups.length === 2;
  19557. }
  19558. function isURLFunctionNode$1(node) {
  19559. return node.type === "value-func" && node.value.toLowerCase() === "url";
  19560. }
  19561. function isLastNode$1(path$$1, node) {
  19562. var parentNode = path$$1.getParentNode();
  19563. if (!parentNode) {
  19564. return false;
  19565. }
  19566. var nodes = parentNode.nodes;
  19567. return nodes && nodes.indexOf(node) === nodes.length - 1;
  19568. }
  19569. function isHTMLTag$1(value) {
  19570. return htmlTagNames$1.indexOf(value.toLowerCase()) !== -1;
  19571. }
  19572. function isDetachedRulesetDeclarationNode$1(node) {
  19573. // If a Less file ends up being parsed with the SCSS parser, Less
  19574. // variable declarations will be parsed as atrules with names ending
  19575. // with a colon, so keep the original case then.
  19576. if (!node.selector) {
  19577. return false;
  19578. }
  19579. return typeof node.selector === "string" && /^@.+:.*$/.test(node.selector) || node.selector.value && /^@.+:.*$/.test(node.selector.value);
  19580. }
  19581. function isForKeywordNode$1(node) {
  19582. return node.type === "value-word" && ["from", "through", "end"].indexOf(node.value) !== -1;
  19583. }
  19584. function isIfElseKeywordNode$1(node) {
  19585. return node.type === "value-word" && ["and", "or", "not"].indexOf(node.value) !== -1;
  19586. }
  19587. function isEachKeywordNode$1(node) {
  19588. return node.type === "value-word" && node.value === "in";
  19589. }
  19590. function isMultiplicationNode$1(node) {
  19591. return node.type === "value-operator" && node.value === "*";
  19592. }
  19593. function isDivisionNode$1(node) {
  19594. return node.type === "value-operator" && node.value === "/";
  19595. }
  19596. function isAdditionNode$1(node) {
  19597. return node.type === "value-operator" && node.value === "+";
  19598. }
  19599. function isSubtractionNode$1(node) {
  19600. return node.type === "value-operator" && node.value === "-";
  19601. }
  19602. function isModuloNode(node) {
  19603. return node.type === "value-operator" && node.value === "%";
  19604. }
  19605. function isMathOperatorNode$1(node) {
  19606. return isMultiplicationNode$1(node) || isDivisionNode$1(node) || isAdditionNode$1(node) || isSubtractionNode$1(node) || isModuloNode(node);
  19607. }
  19608. function isEqualityOperatorNode$1(node) {
  19609. return node.type === "value-word" && ["==", "!="].indexOf(node.value) !== -1;
  19610. }
  19611. function isRelationalOperatorNode$1(node) {
  19612. return node.type === "value-word" && ["<", ">", "<=", ">="].indexOf(node.value) !== -1;
  19613. }
  19614. function isSCSSControlDirectiveNode$1(node) {
  19615. return node.type === "css-atrule" && ["if", "else", "for", "each", "while"].indexOf(node.name) !== -1;
  19616. }
  19617. function isSCSSNestedPropertyNode(node) {
  19618. if (!node.selector) {
  19619. return false;
  19620. }
  19621. return node.selector.replace(/\/\*.*?\*\//, "").replace(/\/\/.*?\n/, "").trim().endsWith(":");
  19622. }
  19623. function isDetachedRulesetCallNode$1(node) {
  19624. return node.raws && node.raws.params && /^\(\s*\)$/.test(node.raws.params);
  19625. }
  19626. function isPostcssSimpleVarNode$1(currentNode, nextNode) {
  19627. return currentNode.value === "$$" && currentNode.type === "value-func" && nextNode && nextNode.type === "value-word" && !nextNode.raws.before;
  19628. }
  19629. function hasComposesNode$1(node) {
  19630. return node.value && node.value.type === "value-root" && node.value.group && node.value.group.type === "value-value" && node.prop.toLowerCase() === "composes";
  19631. }
  19632. function hasParensAroundNode$1(node) {
  19633. 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;
  19634. }
  19635. function hasEmptyRawBefore$1(node) {
  19636. return node.raws && node.raws.before === "";
  19637. }
  19638. function isKeyValuePairNode$1(node) {
  19639. return node.type === "value-comma_group" && node.groups && node.groups[1] && node.groups[1].type === "value-colon";
  19640. }
  19641. function isKeyValuePairInParenGroupNode(node) {
  19642. return node.type === "value-paren_group" && node.groups && node.groups[0] && isKeyValuePairNode$1(node.groups[0]);
  19643. }
  19644. function isSCSSMapItemNode$1(path$$1) {
  19645. var node = path$$1.getValue(); // Ignore empty item (i.e. `$key: ()`)
  19646. if (node.groups.length === 0) {
  19647. return false;
  19648. }
  19649. var parentParentNode = path$$1.getParentNode(1); // Check open parens contain key/value pair (i.e. `(key: value)` and `(key: (value, other-value)`)
  19650. if (!isKeyValuePairInParenGroupNode(node) && !(parentParentNode && isKeyValuePairInParenGroupNode(parentParentNode))) {
  19651. return false;
  19652. }
  19653. var declNode = getAncestorNode$1(path$$1, "css-decl"); // SCSS map declaration (i.e. `$map: (key: value, other-key: other-value)`)
  19654. if (declNode && declNode.prop && declNode.prop.startsWith("$")) {
  19655. return true;
  19656. } // List as value of key inside SCSS map (i.e. `$map: (key: (value other-value other-other-value))`)
  19657. if (isKeyValuePairInParenGroupNode(parentParentNode)) {
  19658. return true;
  19659. } // SCSS Map is argument of function (i.e. `func((key: value, other-key: other-value))`)
  19660. if (parentParentNode.type === "value-func") {
  19661. return true;
  19662. }
  19663. return false;
  19664. }
  19665. function isInlineValueCommentNode$1(node) {
  19666. return node.type === "value-comment" && node.inline;
  19667. }
  19668. function isHashNode$1(node) {
  19669. return node.type === "value-word" && node.value === "#";
  19670. }
  19671. function isLeftCurlyBraceNode$1(node) {
  19672. return node.type === "value-word" && node.value === "{";
  19673. }
  19674. function isRightCurlyBraceNode$1(node) {
  19675. return node.type === "value-word" && node.value === "}";
  19676. }
  19677. function isWordNode$1(node) {
  19678. return ["value-word", "value-atword"].indexOf(node.type) !== -1;
  19679. }
  19680. function isColonNode$1(node) {
  19681. return node.type === "value-colon";
  19682. }
  19683. function isMediaAndSupportsKeywords$1(node) {
  19684. return node.value && ["not", "and", "or"].indexOf(node.value.toLowerCase()) !== -1;
  19685. }
  19686. function isColorAdjusterFuncNode$1(node) {
  19687. if (node.type !== "value-func") {
  19688. return false;
  19689. }
  19690. return colorAdjusterFunctions.indexOf(node.value.toLowerCase()) !== -1;
  19691. }
  19692. var utils$4 = {
  19693. getAncestorCounter,
  19694. getAncestorNode: getAncestorNode$1,
  19695. getPropOfDeclNode: getPropOfDeclNode$1,
  19696. maybeToLowerCase: maybeToLowerCase$1,
  19697. insideValueFunctionNode: insideValueFunctionNode$1,
  19698. insideICSSRuleNode: insideICSSRuleNode$1,
  19699. insideAtRuleNode: insideAtRuleNode$1,
  19700. insideURLFunctionInImportAtRuleNode: insideURLFunctionInImportAtRuleNode$1,
  19701. isKeyframeAtRuleKeywords: isKeyframeAtRuleKeywords$1,
  19702. isHTMLTag: isHTMLTag$1,
  19703. isWideKeywords: isWideKeywords$1,
  19704. isSCSS: isSCSS$1,
  19705. isLastNode: isLastNode$1,
  19706. isSCSSControlDirectiveNode: isSCSSControlDirectiveNode$1,
  19707. isDetachedRulesetDeclarationNode: isDetachedRulesetDeclarationNode$1,
  19708. isRelationalOperatorNode: isRelationalOperatorNode$1,
  19709. isEqualityOperatorNode: isEqualityOperatorNode$1,
  19710. isMultiplicationNode: isMultiplicationNode$1,
  19711. isDivisionNode: isDivisionNode$1,
  19712. isAdditionNode: isAdditionNode$1,
  19713. isSubtractionNode: isSubtractionNode$1,
  19714. isModuloNode,
  19715. isMathOperatorNode: isMathOperatorNode$1,
  19716. isEachKeywordNode: isEachKeywordNode$1,
  19717. isForKeywordNode: isForKeywordNode$1,
  19718. isURLFunctionNode: isURLFunctionNode$1,
  19719. isIfElseKeywordNode: isIfElseKeywordNode$1,
  19720. hasComposesNode: hasComposesNode$1,
  19721. hasParensAroundNode: hasParensAroundNode$1,
  19722. hasEmptyRawBefore: hasEmptyRawBefore$1,
  19723. isSCSSNestedPropertyNode,
  19724. isDetachedRulesetCallNode: isDetachedRulesetCallNode$1,
  19725. isPostcssSimpleVarNode: isPostcssSimpleVarNode$1,
  19726. isKeyValuePairNode: isKeyValuePairNode$1,
  19727. isKeyValuePairInParenGroupNode,
  19728. isSCSSMapItemNode: isSCSSMapItemNode$1,
  19729. isInlineValueCommentNode: isInlineValueCommentNode$1,
  19730. isHashNode: isHashNode$1,
  19731. isLeftCurlyBraceNode: isLeftCurlyBraceNode$1,
  19732. isRightCurlyBraceNode: isRightCurlyBraceNode$1,
  19733. isWordNode: isWordNode$1,
  19734. isColonNode: isColonNode$1,
  19735. isMediaAndSupportsKeywords: isMediaAndSupportsKeywords$1,
  19736. isColorAdjusterFuncNode: isColorAdjusterFuncNode$1
  19737. };
  19738. var printNumber$2 = util$1.printNumber;
  19739. var printString$2 = util$1.printString;
  19740. var hasIgnoreComment$2 = util$1.hasIgnoreComment;
  19741. var hasNewline$3 = util$1.hasNewline;
  19742. var isNextLineEmpty$3 = utilShared.isNextLineEmpty;
  19743. var _require$$2$builders = doc.builders;
  19744. var concat$7 = _require$$2$builders.concat;
  19745. var join$5 = _require$$2$builders.join;
  19746. var line$4 = _require$$2$builders.line;
  19747. var hardline$6 = _require$$2$builders.hardline;
  19748. var softline$3 = _require$$2$builders.softline;
  19749. var group$2 = _require$$2$builders.group;
  19750. var fill$3 = _require$$2$builders.fill;
  19751. var indent$5 = _require$$2$builders.indent;
  19752. var dedent$3 = _require$$2$builders.dedent;
  19753. var ifBreak$2 = _require$$2$builders.ifBreak;
  19754. var removeLines$2 = doc.utils.removeLines;
  19755. var getAncestorNode = utils$4.getAncestorNode;
  19756. var getPropOfDeclNode = utils$4.getPropOfDeclNode;
  19757. var maybeToLowerCase = utils$4.maybeToLowerCase;
  19758. var insideValueFunctionNode = utils$4.insideValueFunctionNode;
  19759. var insideICSSRuleNode = utils$4.insideICSSRuleNode;
  19760. var insideAtRuleNode = utils$4.insideAtRuleNode;
  19761. var insideURLFunctionInImportAtRuleNode = utils$4.insideURLFunctionInImportAtRuleNode;
  19762. var isKeyframeAtRuleKeywords = utils$4.isKeyframeAtRuleKeywords;
  19763. var isHTMLTag = utils$4.isHTMLTag;
  19764. var isWideKeywords = utils$4.isWideKeywords;
  19765. var isSCSS = utils$4.isSCSS;
  19766. var isLastNode = utils$4.isLastNode;
  19767. var isSCSSControlDirectiveNode = utils$4.isSCSSControlDirectiveNode;
  19768. var isDetachedRulesetDeclarationNode = utils$4.isDetachedRulesetDeclarationNode;
  19769. var isRelationalOperatorNode = utils$4.isRelationalOperatorNode;
  19770. var isEqualityOperatorNode = utils$4.isEqualityOperatorNode;
  19771. var isMultiplicationNode = utils$4.isMultiplicationNode;
  19772. var isDivisionNode = utils$4.isDivisionNode;
  19773. var isAdditionNode = utils$4.isAdditionNode;
  19774. var isSubtractionNode = utils$4.isSubtractionNode;
  19775. var isMathOperatorNode = utils$4.isMathOperatorNode;
  19776. var isEachKeywordNode = utils$4.isEachKeywordNode;
  19777. var isForKeywordNode = utils$4.isForKeywordNode;
  19778. var isURLFunctionNode = utils$4.isURLFunctionNode;
  19779. var isIfElseKeywordNode = utils$4.isIfElseKeywordNode;
  19780. var hasComposesNode = utils$4.hasComposesNode;
  19781. var hasParensAroundNode = utils$4.hasParensAroundNode;
  19782. var hasEmptyRawBefore = utils$4.hasEmptyRawBefore;
  19783. var isKeyValuePairNode = utils$4.isKeyValuePairNode;
  19784. var isDetachedRulesetCallNode = utils$4.isDetachedRulesetCallNode;
  19785. var isPostcssSimpleVarNode = utils$4.isPostcssSimpleVarNode;
  19786. var isSCSSMapItemNode = utils$4.isSCSSMapItemNode;
  19787. var isInlineValueCommentNode = utils$4.isInlineValueCommentNode;
  19788. var isHashNode = utils$4.isHashNode;
  19789. var isLeftCurlyBraceNode = utils$4.isLeftCurlyBraceNode;
  19790. var isRightCurlyBraceNode = utils$4.isRightCurlyBraceNode;
  19791. var isWordNode = utils$4.isWordNode;
  19792. var isColonNode = utils$4.isColonNode;
  19793. var isMediaAndSupportsKeywords = utils$4.isMediaAndSupportsKeywords;
  19794. var isColorAdjusterFuncNode = utils$4.isColorAdjusterFuncNode;
  19795. function shouldPrintComma$1(options) {
  19796. switch (options.trailingComma) {
  19797. case "all":
  19798. case "es5":
  19799. return true;
  19800. case "none":
  19801. default:
  19802. return false;
  19803. }
  19804. }
  19805. function genericPrint$3(path$$1, options, print) {
  19806. var node = path$$1.getValue();
  19807. /* istanbul ignore if */
  19808. if (!node) {
  19809. return "";
  19810. }
  19811. if (typeof node === "string") {
  19812. return node;
  19813. }
  19814. switch (node.type) {
  19815. case "front-matter":
  19816. return concat$7([node.value, hardline$6]);
  19817. case "css-root":
  19818. {
  19819. var nodes = printNodeSequence(path$$1, options, print);
  19820. if (nodes.parts.length) {
  19821. return concat$7([nodes, hardline$6]);
  19822. }
  19823. return nodes;
  19824. }
  19825. case "css-comment":
  19826. {
  19827. if (node.raws.content) {
  19828. return node.raws.content;
  19829. }
  19830. var text = options.originalText.slice(options.locStart(node), options.locEnd(node));
  19831. var rawText = node.raws.text || node.text; // Workaround a bug where the location is off.
  19832. // https://github.com/postcss/postcss-scss/issues/63
  19833. if (text.indexOf(rawText) === -1) {
  19834. if (node.raws.inline) {
  19835. return concat$7(["// ", rawText]);
  19836. }
  19837. return concat$7(["/* ", rawText, " */"]);
  19838. }
  19839. return text;
  19840. }
  19841. case "css-rule":
  19842. {
  19843. return concat$7([path$$1.call(print, "selector"), node.important ? " !important" : "", node.nodes ? concat$7([" {", node.nodes.length > 0 ? indent$5(concat$7([hardline$6, printNodeSequence(path$$1, options, print)])) : "", hardline$6, "}", isDetachedRulesetDeclarationNode(node) ? ";" : ""]) : ";"]);
  19844. }
  19845. case "css-decl":
  19846. {
  19847. return concat$7([node.raws.before.replace(/[\s;]/g, ""), insideICSSRuleNode(path$$1) ? node.prop : maybeToLowerCase(node.prop), node.raws.between.trim() === ":" ? ":" : node.raws.between.trim(), node.extend ? "" : " ", hasComposesNode(node) ? removeLines$2(path$$1.call(print, "value")) : path$$1.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$7([" {", indent$5(concat$7([softline$3, printNodeSequence(path$$1, options, print)])), softline$3, "}"]) : ";"]);
  19848. }
  19849. case "css-atrule":
  19850. {
  19851. return concat$7(["@", // If a Less file ends up being parsed with the SCSS parser, Less
  19852. // variable declarations will be parsed as at-rules with names ending
  19853. // with a colon, so keep the original case then.
  19854. isDetachedRulesetCallNode(node) || node.name.endsWith(":") ? node.name : maybeToLowerCase(node.name), node.params ? concat$7([isDetachedRulesetCallNode(node) ? "" : " ", path$$1.call(print, "params")]) : "", node.selector ? indent$5(concat$7([" ", path$$1.call(print, "selector")])) : "", node.value ? group$2(concat$7([" ", path$$1.call(print, "value"), isSCSSControlDirectiveNode(node) ? hasParensAroundNode(node) ? " " : line$4 : ""])) : node.name === "else" ? " " : "", node.nodes ? concat$7([isSCSSControlDirectiveNode(node) ? "" : " ", "{", indent$5(concat$7([node.nodes.length > 0 ? softline$3 : "", printNodeSequence(path$$1, options, print)])), softline$3, "}"]) : ";"]);
  19855. }
  19856. // postcss-media-query-parser
  19857. case "media-query-list":
  19858. {
  19859. var parts = [];
  19860. path$$1.each(function (childPath) {
  19861. var node = childPath.getValue();
  19862. if (node.type === "media-query" && node.value === "") {
  19863. return;
  19864. }
  19865. parts.push(childPath.call(print));
  19866. }, "nodes");
  19867. return group$2(indent$5(join$5(line$4, parts)));
  19868. }
  19869. case "media-query":
  19870. {
  19871. return concat$7([join$5(" ", path$$1.map(print, "nodes")), isLastNode(path$$1, node) ? "" : ","]);
  19872. }
  19873. case "media-type":
  19874. {
  19875. return adjustNumbers(adjustStrings(node.value, options));
  19876. }
  19877. case "media-feature-expression":
  19878. {
  19879. if (!node.nodes) {
  19880. return node.value;
  19881. }
  19882. return concat$7(["(", concat$7(path$$1.map(print, "nodes")), ")"]);
  19883. }
  19884. case "media-feature":
  19885. {
  19886. return maybeToLowerCase(adjustStrings(node.value.replace(/ +/g, " "), options));
  19887. }
  19888. case "media-colon":
  19889. {
  19890. return concat$7([node.value, " "]);
  19891. }
  19892. case "media-value":
  19893. {
  19894. return adjustNumbers(adjustStrings(node.value, options));
  19895. }
  19896. case "media-keyword":
  19897. {
  19898. return adjustStrings(node.value, options);
  19899. }
  19900. case "media-url":
  19901. {
  19902. return adjustStrings(node.value.replace(/^url\(\s+/gi, "url(").replace(/\s+\)$/gi, ")"), options);
  19903. }
  19904. case "media-unknown":
  19905. {
  19906. return node.value;
  19907. }
  19908. // postcss-selector-parser
  19909. case "selector-root":
  19910. {
  19911. return group$2(concat$7([insideAtRuleNode(path$$1, "custom-selector") ? concat$7([getAncestorNode(path$$1, "css-atrule").customSelector, line$4]) : "", join$5(concat$7([",", insideAtRuleNode(path$$1, ["extend", "custom-selector", "nest"]) ? line$4 : hardline$6]), path$$1.map(print, "nodes"))]));
  19912. }
  19913. case "selector-selector":
  19914. {
  19915. return group$2(indent$5(concat$7(path$$1.map(print, "nodes"))));
  19916. }
  19917. case "selector-comment":
  19918. {
  19919. return node.value;
  19920. }
  19921. case "selector-string":
  19922. {
  19923. return adjustStrings(node.value, options);
  19924. }
  19925. case "selector-tag":
  19926. {
  19927. var parentNode = path$$1.getParentNode();
  19928. var index = parentNode && parentNode.nodes.indexOf(node);
  19929. var prevNode = index && parentNode.nodes[index - 1];
  19930. return concat$7([node.namespace ? concat$7([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", prevNode.type === "selector-nesting" ? node.value : adjustNumbers(isHTMLTag(node.value) || isKeyframeAtRuleKeywords(path$$1, node.value) ? node.value.toLowerCase() : node.value)]);
  19931. }
  19932. case "selector-id":
  19933. {
  19934. return concat$7(["#", node.value]);
  19935. }
  19936. case "selector-class":
  19937. {
  19938. return concat$7([".", adjustNumbers(adjustStrings(node.value, options))]);
  19939. }
  19940. case "selector-attribute":
  19941. {
  19942. return concat$7(["[", node.namespace ? concat$7([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" : "", "]"]);
  19943. }
  19944. case "selector-combinator":
  19945. {
  19946. if (node.value === "+" || node.value === ">" || node.value === "~" || node.value === ">>>") {
  19947. var _parentNode = path$$1.getParentNode();
  19948. var _leading = _parentNode.type === "selector-selector" && _parentNode.nodes[0] === node ? "" : line$4;
  19949. return concat$7([_leading, node.value, isLastNode(path$$1, node) ? "" : " "]);
  19950. }
  19951. var leading = node.value.trim().startsWith("(") ? line$4 : "";
  19952. var value = adjustNumbers(adjustStrings(node.value.trim(), options)) || line$4;
  19953. return concat$7([leading, value]);
  19954. }
  19955. case "selector-universal":
  19956. {
  19957. return concat$7([node.namespace ? concat$7([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", adjustNumbers(node.value)]);
  19958. }
  19959. case "selector-pseudo":
  19960. {
  19961. return concat$7([maybeToLowerCase(node.value), node.nodes && node.nodes.length > 0 ? concat$7(["(", join$5(", ", path$$1.map(print, "nodes")), ")"]) : ""]);
  19962. }
  19963. case "selector-nesting":
  19964. {
  19965. return node.value;
  19966. }
  19967. case "selector-unknown":
  19968. {
  19969. var ruleAncestorNode = getAncestorNode(path$$1, "css-rule"); // Nested SCSS property
  19970. if (ruleAncestorNode && ruleAncestorNode.isSCSSNesterProperty) {
  19971. return adjustNumbers(adjustStrings(maybeToLowerCase(node.value), options));
  19972. }
  19973. return node.value;
  19974. }
  19975. // postcss-values-parser
  19976. case "value-value":
  19977. case "value-root":
  19978. {
  19979. return path$$1.call(print, "group");
  19980. }
  19981. case "value-comment":
  19982. {
  19983. return concat$7([node.inline ? "//" : "/*", node.value, node.inline ? "" : "*/"]);
  19984. }
  19985. case "value-comma_group":
  19986. {
  19987. var _parentNode2 = path$$1.getParentNode();
  19988. var parentParentNode = path$$1.getParentNode(1);
  19989. var declAncestorProp = getPropOfDeclNode(path$$1);
  19990. var isGridValue = declAncestorProp && _parentNode2.type === "value-value" && (declAncestorProp === "grid" || declAncestorProp.startsWith("grid-template"));
  19991. var atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
  19992. var isControlDirective = atRuleAncestorNode && isSCSSControlDirectiveNode(atRuleAncestorNode);
  19993. var printed = path$$1.map(print, "groups");
  19994. var _parts = [];
  19995. var insideURLFunction = insideValueFunctionNode(path$$1, "url");
  19996. var insideSCSSInterpolationInString = false;
  19997. var didBreak = false;
  19998. for (var i = 0; i < node.groups.length; ++i) {
  19999. _parts.push(printed[i]); // Ignore value inside `url()`
  20000. if (insideURLFunction) {
  20001. continue;
  20002. }
  20003. var iPrevNode = node.groups[i - 1];
  20004. var iNode = node.groups[i];
  20005. var iNextNode = node.groups[i + 1];
  20006. var iNextNextNode = node.groups[i + 2]; // Ignore after latest node (i.e. before semicolon)
  20007. if (!iNextNode) {
  20008. continue;
  20009. } // Ignore spaces before/after string interpolation (i.e. `"#{my-fn("_")}"`)
  20010. var isStartSCSSinterpolationInString = iNode.type === "value-string" && iNode.value.startsWith("#{");
  20011. var isEndingSCSSinterpolationInString = insideSCSSInterpolationInString && iNextNode.type === "value-string" && iNextNode.value.endsWith("}");
  20012. if (isStartSCSSinterpolationInString || isEndingSCSSinterpolationInString) {
  20013. insideSCSSInterpolationInString = !insideSCSSInterpolationInString;
  20014. continue;
  20015. }
  20016. if (insideSCSSInterpolationInString) {
  20017. continue;
  20018. } // Ignore colon (i.e. `:`)
  20019. if (isColonNode(iNode) || isColonNode(iNextNode)) {
  20020. continue;
  20021. } // Ignore `@` in Less (i.e. `@@var;`)
  20022. if (iNode.type === "value-atword" && iNode.value === "") {
  20023. continue;
  20024. } // Ignore `~` in Less (i.e. `content: ~"^//* some horrible but needed css hack";`)
  20025. if (iNode.value === "~") {
  20026. continue;
  20027. } // Ignore `\` (i.e. `$variable: \@small;`)
  20028. if (iNode.value === "\\") {
  20029. continue;
  20030. } // Ignore `$$` (i.e. `background-color: $$(style)Color;`)
  20031. if (isPostcssSimpleVarNode(iNode, iNextNode)) {
  20032. continue;
  20033. } // Ignore spaces after `#` and after `{` and before `}` in SCSS interpolation (i.e. `#{variable}`)
  20034. if (isHashNode(iNode) || isLeftCurlyBraceNode(iNode) || isRightCurlyBraceNode(iNextNode) || isLeftCurlyBraceNode(iNextNode) && hasEmptyRawBefore(iNextNode) || isRightCurlyBraceNode(iNode) && hasEmptyRawBefore(iNextNode)) {
  20035. continue;
  20036. } // Ignore css variables and interpolation in SCSS (i.e. `--#{$var}`)
  20037. if (iNode.value === "--" && isHashNode(iNextNode)) {
  20038. continue;
  20039. } // Formatting math operations
  20040. var isMathOperator = isMathOperatorNode(iNode);
  20041. var isNextMathOperator = isMathOperatorNode(iNextNode); // Print spaces before and after math operators beside SCSS interpolation as is
  20042. // (i.e. `#{$var}+5`, `#{$var} +5`, `#{$var}+ 5`, `#{$var} + 5`)
  20043. // (i.e. `5+#{$var}`, `5 +#{$var}`, `5+ #{$var}`, `5 + #{$var}`)
  20044. if ((isMathOperator && isHashNode(iNextNode) || isNextMathOperator && isRightCurlyBraceNode(iNode)) && hasEmptyRawBefore(iNextNode)) {
  20045. continue;
  20046. } // Print spaces before and after addition and subtraction math operators as is in `calc` function
  20047. // due to the fact that it is not valid syntax
  20048. // (i.e. `calc(1px+1px)`, `calc(1px+ 1px)`, `calc(1px +1px)`, `calc(1px + 1px)`)
  20049. if (insideValueFunctionNode(path$$1, "calc") && (isAdditionNode(iNode) || isAdditionNode(iNextNode) || isSubtractionNode(iNode) || isSubtractionNode(iNextNode)) && hasEmptyRawBefore(iNextNode)) {
  20050. continue;
  20051. } // Print spaces after `+` and `-` in color adjuster functions as is (e.g. `color(red l(+ 20%))`)
  20052. // Adjusters with signed numbers (e.g. `color(red l(+20%))`) output as-is.
  20053. var isColorAdjusterNode = (isAdditionNode(iNode) || isSubtractionNode(iNode)) && i === 0 && (iNextNode.type === "value-number" || iNextNode.isHex) && parentParentNode && isColorAdjusterFuncNode(parentParentNode) && !hasEmptyRawBefore(iNextNode);
  20054. var requireSpaceBeforeOperator = iNextNextNode && iNextNextNode.type === "value-func" || iNextNextNode && isWordNode(iNextNextNode) || iNode.type === "value-func" || isWordNode(iNode);
  20055. var requireSpaceAfterOperator = iNextNode.type === "value-func" || isWordNode(iNextNode) || iPrevNode && iPrevNode.type === "value-func" || iPrevNode && isWordNode(iPrevNode); // Formatting `/`, `+`, `-` sign
  20056. if (!(isMultiplicationNode(iNextNode) || isMultiplicationNode(iNode)) && !insideValueFunctionNode(path$$1, "calc") && !isColorAdjusterNode && (isDivisionNode(iNextNode) && !requireSpaceBeforeOperator || isDivisionNode(iNode) && !requireSpaceAfterOperator || isAdditionNode(iNextNode) && !requireSpaceBeforeOperator || isAdditionNode(iNode) && !requireSpaceAfterOperator || isSubtractionNode(iNextNode) || isSubtractionNode(iNode)) && (hasEmptyRawBefore(iNextNode) || isMathOperator && (!iPrevNode || iPrevNode && isMathOperatorNode(iPrevNode)))) {
  20057. continue;
  20058. } // Ignore inline comment, they already contain newline at end (i.e. `// Comment`)
  20059. // Add `hardline` after inline comment (i.e. `// comment\n foo: bar;`)
  20060. var isInlineComment = isInlineValueCommentNode(iNode);
  20061. if (iPrevNode && isInlineValueCommentNode(iPrevNode) || isInlineComment || isInlineValueCommentNode(iNextNode)) {
  20062. if (isInlineComment) {
  20063. _parts.push(hardline$6);
  20064. }
  20065. continue;
  20066. } // Handle keywords in SCSS control directive
  20067. if (isControlDirective && (isEqualityOperatorNode(iNextNode) || isRelationalOperatorNode(iNextNode) || isIfElseKeywordNode(iNextNode) || isEachKeywordNode(iNode) || isForKeywordNode(iNode))) {
  20068. _parts.push(" ");
  20069. continue;
  20070. } // At-rule `namespace` should be in one line
  20071. if (atRuleAncestorNode && atRuleAncestorNode.name.toLowerCase() === "namespace") {
  20072. _parts.push(" ");
  20073. continue;
  20074. } // Formatting `grid` property
  20075. if (isGridValue) {
  20076. if (iNode.source.start.line !== iNextNode.source.start.line) {
  20077. _parts.push(hardline$6);
  20078. didBreak = true;
  20079. } else {
  20080. _parts.push(" ");
  20081. }
  20082. continue;
  20083. } // Add `space` before next math operation
  20084. // Note: `grip` property have `/` delimiter and it is not math operation, so
  20085. // `grid` property handles above
  20086. if (isNextMathOperator) {
  20087. _parts.push(" ");
  20088. continue;
  20089. } // Be default all values go through `line`
  20090. _parts.push(line$4);
  20091. }
  20092. if (didBreak) {
  20093. _parts.unshift(hardline$6);
  20094. }
  20095. if (isControlDirective) {
  20096. return group$2(indent$5(concat$7(_parts)));
  20097. } // Indent is not needed for import url when url is very long
  20098. // and node has two groups
  20099. // when type is value-comma_group
  20100. // example @import url("verylongurl") projection,tv
  20101. if (insideURLFunctionInImportAtRuleNode(path$$1)) {
  20102. return group$2(fill$3(_parts));
  20103. }
  20104. return group$2(indent$5(fill$3(_parts)));
  20105. }
  20106. case "value-paren_group":
  20107. {
  20108. var _parentNode3 = path$$1.getParentNode();
  20109. if (_parentNode3 && isURLFunctionNode(_parentNode3) && (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:"))) {
  20110. return concat$7([node.open ? path$$1.call(print, "open") : "", join$5(",", path$$1.map(print, "groups")), node.close ? path$$1.call(print, "close") : ""]);
  20111. }
  20112. if (!node.open) {
  20113. var _printed = path$$1.map(print, "groups");
  20114. var res = [];
  20115. for (var _i = 0; _i < _printed.length; _i++) {
  20116. if (_i !== 0) {
  20117. res.push(concat$7([",", line$4]));
  20118. }
  20119. res.push(_printed[_i]);
  20120. }
  20121. return group$2(indent$5(fill$3(res)));
  20122. }
  20123. var isSCSSMapItem = isSCSSMapItemNode(path$$1);
  20124. return group$2(concat$7([node.open ? path$$1.call(print, "open") : "", indent$5(concat$7([softline$3, join$5(concat$7([",", line$4]), path$$1.map(function (childPath) {
  20125. var node = childPath.getValue();
  20126. var printed = print(childPath); // Key/Value pair in open paren already indented
  20127. if (isKeyValuePairNode(node) && node.type === "value-comma_group" && node.groups && node.groups[2] && node.groups[2].type === "value-paren_group") {
  20128. printed.contents.contents.parts[1] = group$2(printed.contents.contents.parts[1]);
  20129. return group$2(dedent$3(printed));
  20130. }
  20131. return printed;
  20132. }, "groups"))])), ifBreak$2(isSCSS(options.parser, options.originalText) && isSCSSMapItem && shouldPrintComma$1(options) ? "," : ""), softline$3, node.close ? path$$1.call(print, "close") : ""]), {
  20133. shouldBreak: isSCSSMapItem
  20134. });
  20135. }
  20136. case "value-func":
  20137. {
  20138. return concat$7([node.value, insideAtRuleNode(path$$1, "supports") && isMediaAndSupportsKeywords(node) ? " " : "", path$$1.call(print, "group")]);
  20139. }
  20140. case "value-paren":
  20141. {
  20142. return node.value;
  20143. }
  20144. case "value-number":
  20145. {
  20146. return concat$7([printCssNumber(node.value), maybeToLowerCase(node.unit)]);
  20147. }
  20148. case "value-operator":
  20149. {
  20150. return node.value;
  20151. }
  20152. case "value-word":
  20153. {
  20154. if (node.isColor && node.isHex || isWideKeywords(node.value)) {
  20155. return node.value.toLowerCase();
  20156. }
  20157. return node.value;
  20158. }
  20159. case "value-colon":
  20160. {
  20161. return concat$7([node.value, // Don't add spaces on `:` in `url` function (i.e. `url(fbglyph: cross-outline, fig-white)`)
  20162. insideValueFunctionNode(path$$1, "url") ? "" : line$4]);
  20163. }
  20164. case "value-comma":
  20165. {
  20166. return concat$7([node.value, " "]);
  20167. }
  20168. case "value-string":
  20169. {
  20170. return printString$2(node.raws.quote + node.value + node.raws.quote, options);
  20171. }
  20172. case "value-atword":
  20173. {
  20174. return concat$7(["@", node.value]);
  20175. }
  20176. case "value-unicode-range":
  20177. {
  20178. return node.value;
  20179. }
  20180. case "value-unknown":
  20181. {
  20182. return node.value;
  20183. }
  20184. default:
  20185. /* istanbul ignore next */
  20186. throw new Error(`Unknown postcss type ${JSON.stringify(node.type)}`);
  20187. }
  20188. }
  20189. function printNodeSequence(path$$1, options, print) {
  20190. var node = path$$1.getValue();
  20191. var parts = [];
  20192. var i = 0;
  20193. path$$1.map(function (pathChild) {
  20194. var prevNode = node.nodes[i - 1];
  20195. if (prevNode && prevNode.type === "css-comment" && prevNode.text.trim() === "prettier-ignore") {
  20196. var childNode = pathChild.getValue();
  20197. parts.push(options.originalText.slice(options.locStart(childNode), options.locEnd(childNode)));
  20198. } else {
  20199. parts.push(pathChild.call(print));
  20200. }
  20201. if (i !== node.nodes.length - 1) {
  20202. if (node.nodes[i + 1].type === "css-comment" && !hasNewline$3(options.originalText, options.locStart(node.nodes[i + 1]), {
  20203. backwards: true
  20204. }) || node.nodes[i + 1].type === "css-atrule" && node.nodes[i + 1].name === "else" && node.nodes[i].type !== "css-comment") {
  20205. parts.push(" ");
  20206. } else {
  20207. parts.push(hardline$6);
  20208. if (isNextLineEmpty$3(options.originalText, pathChild.getValue(), options)) {
  20209. parts.push(hardline$6);
  20210. }
  20211. }
  20212. }
  20213. i++;
  20214. }, "nodes");
  20215. return concat$7(parts);
  20216. }
  20217. var STRING_REGEX = /(['"])(?:(?!\1)[^\\]|\\[\s\S])*\1/g;
  20218. var NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g;
  20219. var STANDARD_UNIT_REGEX = /[a-zA-Z]+/g;
  20220. var WORD_PART_REGEX = /[$@]?[a-zA-Z_\u0080-\uFFFF][\w\-\u0080-\uFFFF]*/g;
  20221. var ADJUST_NUMBERS_REGEX = RegExp(STRING_REGEX.source + `|` + `(${WORD_PART_REGEX.source})?` + `(${NUMBER_REGEX.source})` + `(${STANDARD_UNIT_REGEX.source})?`, "g");
  20222. function adjustStrings(value, options) {
  20223. return value.replace(STRING_REGEX, function (match) {
  20224. return printString$2(match, options);
  20225. });
  20226. }
  20227. function quoteAttributeValue(value, options) {
  20228. var quote = options.singleQuote ? "'" : '"';
  20229. return value.includes('"') || value.includes("'") ? value : quote + value + quote;
  20230. }
  20231. function adjustNumbers(value) {
  20232. return value.replace(ADJUST_NUMBERS_REGEX, function (match, quote, wordPart, number, unit) {
  20233. return !wordPart && number ? (wordPart || "") + printCssNumber(number) + maybeToLowerCase(unit || "") : match;
  20234. });
  20235. }
  20236. function printCssNumber(rawNumber) {
  20237. return printNumber$2(rawNumber) // Remove trailing `.0`.
  20238. .replace(/\.0(?=$|e)/, "");
  20239. }
  20240. var printerPostcss = {
  20241. print: genericPrint$3,
  20242. hasPrettierIgnore: hasIgnoreComment$2,
  20243. massageAstNode: clean_1$2
  20244. };
  20245. var options$7 = {
  20246. singleQuote: commonOptions.singleQuote
  20247. };
  20248. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  20249. var languages$1 = [{
  20250. name: "CSS",
  20251. since: "1.4.0",
  20252. parsers: ["css"],
  20253. group: "CSS",
  20254. tmScope: "source.css",
  20255. aceMode: "css",
  20256. codemirrorMode: "css",
  20257. codemirrorMimeType: "text/css",
  20258. extensions: [".css", ".pcss", ".postcss"],
  20259. liguistLanguageId: 50,
  20260. vscodeLanguageIds: ["css", "postcss"]
  20261. }, {
  20262. name: "Less",
  20263. since: "1.4.0",
  20264. parsers: ["less"],
  20265. group: "CSS",
  20266. extensions: [".less"],
  20267. tmScope: "source.css.less",
  20268. aceMode: "less",
  20269. codemirrorMode: "css",
  20270. codemirrorMimeType: "text/css",
  20271. liguistLanguageId: 198,
  20272. vscodeLanguageIds: ["less"]
  20273. }, {
  20274. name: "SCSS",
  20275. since: "1.4.0",
  20276. parsers: ["scss"],
  20277. group: "CSS",
  20278. tmScope: "source.scss",
  20279. aceMode: "scss",
  20280. codemirrorMode: "css",
  20281. codemirrorMimeType: "text/x-scss",
  20282. extensions: [".scss"],
  20283. liguistLanguageId: 329,
  20284. vscodeLanguageIds: ["scss"]
  20285. }];
  20286. var printers$1 = {
  20287. postcss: printerPostcss
  20288. };
  20289. var languageCss = {
  20290. languages: languages$1,
  20291. options: options$7,
  20292. printers: printers$1
  20293. };
  20294. var _require$$0$builders$3 = doc.builders;
  20295. var concat$8 = _require$$0$builders$3.concat;
  20296. var join$6 = _require$$0$builders$3.join;
  20297. var softline$4 = _require$$0$builders$3.softline;
  20298. var hardline$7 = _require$$0$builders$3.hardline;
  20299. var line$5 = _require$$0$builders$3.line;
  20300. var group$3 = _require$$0$builders$3.group;
  20301. var indent$6 = _require$$0$builders$3.indent;
  20302. var ifBreak$3 = _require$$0$builders$3.ifBreak; // http://w3c.github.io/html/single-page.html#void-elements
  20303. 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:
  20304. // https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts
  20305. function print(path$$1, options, print) {
  20306. var n = path$$1.getValue();
  20307. /* istanbul ignore if*/
  20308. if (!n) {
  20309. return "";
  20310. }
  20311. switch (n.type) {
  20312. case "Program":
  20313. {
  20314. return group$3(join$6(softline$4, path$$1.map(print, "body").filter(function (text) {
  20315. return text !== "";
  20316. })));
  20317. }
  20318. case "ElementNode":
  20319. {
  20320. var isVoid = voidTags.indexOf(n.tag) !== -1;
  20321. var closeTag = isVoid ? concat$8([" />", softline$4]) : ">";
  20322. var hasChildren = n.children.length > 0;
  20323. var _getParams = function _getParams(path$$1, print) {
  20324. return indent$6(concat$8([n.attributes.length ? line$5 : "", join$6(line$5, path$$1.map(print, "attributes")), n.modifiers.length ? line$5 : "", join$6(line$5, path$$1.map(print, "modifiers")), n.comments.length ? line$5 : "", join$6(line$5, path$$1.map(print, "comments"))]));
  20325. }; // The problem here is that I want to not break at all if the children
  20326. // would not break but I need to force an indent, so I use a hardline.
  20327. /**
  20328. * What happens now:
  20329. * <div>
  20330. * Hello
  20331. * </div>
  20332. * ==>
  20333. * <div>Hello</div>
  20334. * This is due to me using hasChildren to decide to put the hardline in.
  20335. * I would rather use a {DOES THE WHOLE THING NEED TO BREAK}
  20336. */
  20337. return concat$8([group$3(concat$8(["<", n.tag, _getParams(path$$1, print), ifBreak$3(softline$4, ""), closeTag])), group$3(concat$8([indent$6(join$6(softline$4, [""].concat(path$$1.map(print, "children")))), ifBreak$3(hasChildren ? hardline$7 : "", ""), !isVoid ? concat$8(["</", n.tag, ">"]) : ""]))]);
  20338. }
  20339. case "BlockStatement":
  20340. {
  20341. var pp = path$$1.getParentNode(1);
  20342. var isElseIf = pp && pp.inverse && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
  20343. var hasElseIf = n.inverse && n.inverse.body[0] && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
  20344. var indentElse = hasElseIf ? function (a) {
  20345. return a;
  20346. } : indent$6;
  20347. if (n.inverse) {
  20348. return concat$8([isElseIf ? concat$8(["{{else ", printPathParams(path$$1, print), "}}"]) : printOpenBlock(path$$1, print), indent$6(concat$8([hardline$7, path$$1.call(print, "program")])), n.inverse && !hasElseIf ? concat$8([hardline$7, "{{else}}"]) : "", n.inverse ? indentElse(concat$8([hardline$7, path$$1.call(print, "inverse")])) : "", isElseIf ? "" : concat$8([hardline$7, printCloseBlock(path$$1, print)])]);
  20349. } else if (isElseIf) {
  20350. return concat$8([concat$8(["{{else ", printPathParams(path$$1, print), "}}"]), indent$6(concat$8([hardline$7, path$$1.call(print, "program")]))]);
  20351. }
  20352. /**
  20353. * I want this boolean to be: if params are going to cause a break,
  20354. * not that it has params.
  20355. */
  20356. var hasParams = n.params.length > 0 || n.hash.pairs.length > 0;
  20357. var _hasChildren = n.program.body.length > 0;
  20358. return concat$8([printOpenBlock(path$$1, print), group$3(concat$8([indent$6(concat$8([softline$4, path$$1.call(print, "program")])), hasParams && _hasChildren ? hardline$7 : "", printCloseBlock(path$$1, print)]))]);
  20359. }
  20360. case "ElementModifierStatement":
  20361. case "MustacheStatement":
  20362. {
  20363. var _pp = path$$1.getParentNode(1);
  20364. var isConcat = _pp && _pp.type === "ConcatStatement";
  20365. return group$3(concat$8([n.escaped === false ? "{{{" : "{{", printPathParams(path$$1, print), isConcat ? "" : softline$4, n.escaped === false ? "}}}" : "}}"]));
  20366. }
  20367. case "SubExpression":
  20368. {
  20369. return group$3(concat$8(["(", printPath(path$$1, print), indent$6(concat$8([line$5, group$3(join$6(line$5, getParams(path$$1, print)))])), softline$4, ")"]));
  20370. }
  20371. case "AttrNode":
  20372. {
  20373. var quote = n.value.type === "TextNode" ? '"' : "";
  20374. return concat$8([n.name, "=", quote, path$$1.call(print, "value"), quote]);
  20375. }
  20376. case "ConcatStatement":
  20377. {
  20378. return concat$8(['"', group$3(indent$6(join$6(softline$4, path$$1.map(function (partPath) {
  20379. return print(partPath);
  20380. }, "parts").filter(function (a) {
  20381. return a !== "";
  20382. })))), '"']);
  20383. }
  20384. case "Hash":
  20385. {
  20386. return concat$8([join$6(line$5, path$$1.map(print, "pairs"))]);
  20387. }
  20388. case "HashPair":
  20389. {
  20390. return concat$8([n.key, "=", path$$1.call(print, "value")]);
  20391. }
  20392. case "TextNode":
  20393. {
  20394. var leadingSpace = "";
  20395. var trailingSpace = ""; // preserve a space inside of an attribute node where whitespace present, when next to mustache statement.
  20396. var inAttrNode = path$$1.stack.indexOf("attributes") >= 0;
  20397. if (inAttrNode) {
  20398. var parentNode = path$$1.getParentNode(0);
  20399. var _isConcat = parentNode.type === "ConcatStatement";
  20400. if (_isConcat) {
  20401. var parts = parentNode.parts;
  20402. var partIndex = parts.indexOf(n);
  20403. if (partIndex > 0) {
  20404. var partType = parts[partIndex - 1].type;
  20405. var isMustache = partType === "MustacheStatement";
  20406. if (isMustache) {
  20407. leadingSpace = " ";
  20408. }
  20409. }
  20410. if (partIndex < parts.length - 1) {
  20411. var _partType = parts[partIndex + 1].type;
  20412. var _isMustache = _partType === "MustacheStatement";
  20413. if (_isMustache) {
  20414. trailingSpace = " ";
  20415. }
  20416. }
  20417. }
  20418. }
  20419. return n.chars.replace(/^\s+/, leadingSpace).replace(/\s+$/, trailingSpace);
  20420. }
  20421. case "MustacheCommentStatement":
  20422. {
  20423. var dashes = n.value.indexOf("}}") > -1 ? "--" : "";
  20424. return concat$8(["{{!", dashes, n.value, dashes, "}}"]);
  20425. }
  20426. case "PathExpression":
  20427. {
  20428. return n.original;
  20429. }
  20430. case "BooleanLiteral":
  20431. {
  20432. return String(n.value);
  20433. }
  20434. case "CommentStatement":
  20435. {
  20436. return concat$8(["<!--", n.value, "-->"]);
  20437. }
  20438. case "StringLiteral":
  20439. {
  20440. return `"${n.value}"`;
  20441. }
  20442. case "NumberLiteral":
  20443. {
  20444. return String(n.value);
  20445. }
  20446. case "UndefinedLiteral":
  20447. {
  20448. return "undefined";
  20449. }
  20450. case "NullLiteral":
  20451. {
  20452. return "null";
  20453. }
  20454. /* istanbul ignore next */
  20455. default:
  20456. throw new Error("unknown glimmer type: " + JSON.stringify(n.type));
  20457. }
  20458. }
  20459. function printPath(path$$1, print) {
  20460. return path$$1.call(print, "path");
  20461. }
  20462. function getParams(path$$1, print) {
  20463. var node = path$$1.getValue();
  20464. var parts = [];
  20465. if (node.params.length > 0) {
  20466. parts = parts.concat(path$$1.map(print, "params"));
  20467. }
  20468. if (node.hash && node.hash.pairs.length > 0) {
  20469. parts.push(path$$1.call(print, "hash"));
  20470. }
  20471. return parts;
  20472. }
  20473. function printPathParams(path$$1, print) {
  20474. var parts = [];
  20475. parts.push(printPath(path$$1, print));
  20476. parts = parts.concat(getParams(path$$1, print));
  20477. return indent$6(group$3(join$6(line$5, parts)));
  20478. }
  20479. function printBlockParams(path$$1) {
  20480. var block = path$$1.getValue();
  20481. if (!block.program || !block.program.blockParams.length) {
  20482. return "";
  20483. }
  20484. return concat$8([" as |", block.program.blockParams.join(" "), "|"]);
  20485. }
  20486. function printOpenBlock(path$$1, print) {
  20487. return group$3(concat$8(["{{#", printPathParams(path$$1, print), printBlockParams(path$$1, print), softline$4, "}}"]));
  20488. }
  20489. function printCloseBlock(path$$1, print) {
  20490. return concat$8(["{{/", path$$1.call(print, "path"), "}}"]);
  20491. }
  20492. function clean$5(ast, newObj) {
  20493. delete newObj.loc; // (Glimmer/HTML) ignore TextNode whitespace
  20494. if (ast.type === "TextNode") {
  20495. if (ast.chars.replace(/\s+/, "") === "") {
  20496. return null;
  20497. }
  20498. newObj.chars = ast.chars.replace(/^\s+/, "").replace(/\s+$/, "");
  20499. }
  20500. }
  20501. var printerGlimmer = {
  20502. print,
  20503. massageAstNode: clean$5
  20504. };
  20505. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  20506. var languages$2 = [{
  20507. type: "markup",
  20508. group: "HTML",
  20509. aliases: ["hbs", "htmlbars"],
  20510. extensions: [".handlebars", ".hbs"],
  20511. tm_scope: "text.html.handlebars",
  20512. ace_mode: "handlebars",
  20513. language_id: 155,
  20514. since: null // unreleased
  20515. }];
  20516. var printers$2 = {
  20517. glimmer: printerGlimmer
  20518. };
  20519. var languageHandlebars = {
  20520. languages: languages$2,
  20521. printers: printers$2
  20522. };
  20523. var _require$$0$builders$4 = doc.builders;
  20524. var concat$9 = _require$$0$builders$4.concat;
  20525. var join$7 = _require$$0$builders$4.join;
  20526. var hardline$8 = _require$$0$builders$4.hardline;
  20527. var line$6 = _require$$0$builders$4.line;
  20528. var softline$5 = _require$$0$builders$4.softline;
  20529. var group$4 = _require$$0$builders$4.group;
  20530. var indent$7 = _require$$0$builders$4.indent;
  20531. var ifBreak$4 = _require$$0$builders$4.ifBreak;
  20532. var hasIgnoreComment$3 = util$1.hasIgnoreComment;
  20533. var isNextLineEmpty$4 = utilShared.isNextLineEmpty;
  20534. function genericPrint$4(path$$1, options, print) {
  20535. var n = path$$1.getValue();
  20536. if (!n) {
  20537. return "";
  20538. }
  20539. if (typeof n === "string") {
  20540. return n;
  20541. }
  20542. switch (n.kind) {
  20543. case "Document":
  20544. {
  20545. var parts = [];
  20546. path$$1.map(function (pathChild, index) {
  20547. parts.push(concat$9([pathChild.call(print)]));
  20548. if (index !== n.definitions.length - 1) {
  20549. parts.push(hardline$8);
  20550. if (isNextLineEmpty$4(options.originalText, pathChild.getValue(), options)) {
  20551. parts.push(hardline$8);
  20552. }
  20553. }
  20554. }, "definitions");
  20555. return concat$9([concat$9(parts), hardline$8]);
  20556. }
  20557. case "OperationDefinition":
  20558. {
  20559. var hasOperation = options.originalText[options.locStart(n)] !== "{";
  20560. var hasName = !!n.name;
  20561. return concat$9([hasOperation ? n.operation : "", hasOperation && hasName ? concat$9([" ", path$$1.call(print, "name")]) : "", n.variableDefinitions && n.variableDefinitions.length ? group$4(concat$9(["(", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.map(print, "variableDefinitions"))])), softline$5, ")"])) : "", printDirectives(path$$1, print, n), n.selectionSet ? !hasOperation && !hasName ? "" : " " : "", path$$1.call(print, "selectionSet")]);
  20562. }
  20563. case "FragmentDefinition":
  20564. {
  20565. return concat$9(["fragment ", path$$1.call(print, "name"), " on ", path$$1.call(print, "typeCondition"), printDirectives(path$$1, print, n), " ", path$$1.call(print, "selectionSet")]);
  20566. }
  20567. case "SelectionSet":
  20568. {
  20569. return concat$9(["{", indent$7(concat$9([hardline$8, join$7(hardline$8, path$$1.call(function (selectionsPath) {
  20570. return printSequence(selectionsPath, options, print);
  20571. }, "selections"))])), hardline$8, "}"]);
  20572. }
  20573. case "Field":
  20574. {
  20575. return group$4(concat$9([n.alias ? concat$9([path$$1.call(print, "alias"), ": "]) : "", path$$1.call(print, "name"), n.arguments.length > 0 ? group$4(concat$9(["(", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
  20576. return printSequence(argsPath, options, print);
  20577. }, "arguments"))])), softline$5, ")"])) : "", printDirectives(path$$1, print, n), n.selectionSet ? " " : "", path$$1.call(print, "selectionSet")]));
  20578. }
  20579. case "Name":
  20580. {
  20581. return n.value;
  20582. }
  20583. case "StringValue":
  20584. {
  20585. if (n.block) {
  20586. return concat$9(['"""', hardline$8, join$7(hardline$8, n.value.replace(/"""/g, "\\$&").split("\n")), hardline$8, '"""']);
  20587. }
  20588. return concat$9(['"', n.value.replace(/["\\]/g, "\\$&"), '"']);
  20589. }
  20590. case "IntValue":
  20591. case "FloatValue":
  20592. case "EnumValue":
  20593. {
  20594. return n.value;
  20595. }
  20596. case "BooleanValue":
  20597. {
  20598. return n.value ? "true" : "false";
  20599. }
  20600. case "NullValue":
  20601. {
  20602. return "null";
  20603. }
  20604. case "Variable":
  20605. {
  20606. return concat$9(["$", path$$1.call(print, "name")]);
  20607. }
  20608. case "ListValue":
  20609. {
  20610. return group$4(concat$9(["[", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.map(print, "values"))])), softline$5, "]"]));
  20611. }
  20612. case "ObjectValue":
  20613. {
  20614. return group$4(concat$9(["{", options.bracketSpacing && n.fields.length > 0 ? " " : "", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.map(print, "fields"))])), softline$5, ifBreak$4("", options.bracketSpacing && n.fields.length > 0 ? " " : ""), "}"]));
  20615. }
  20616. case "ObjectField":
  20617. case "Argument":
  20618. {
  20619. return concat$9([path$$1.call(print, "name"), ": ", path$$1.call(print, "value")]);
  20620. }
  20621. case "Directive":
  20622. {
  20623. return concat$9(["@", path$$1.call(print, "name"), n.arguments.length > 0 ? group$4(concat$9(["(", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
  20624. return printSequence(argsPath, options, print);
  20625. }, "arguments"))])), softline$5, ")"])) : ""]);
  20626. }
  20627. case "NamedType":
  20628. {
  20629. return path$$1.call(print, "name");
  20630. }
  20631. case "VariableDefinition":
  20632. {
  20633. return concat$9([path$$1.call(print, "variable"), ": ", path$$1.call(print, "type"), n.defaultValue ? concat$9([" = ", path$$1.call(print, "defaultValue")]) : ""]);
  20634. }
  20635. case "TypeExtensionDefinition":
  20636. {
  20637. return concat$9(["extend ", path$$1.call(print, "definition")]);
  20638. }
  20639. case "ObjectTypeExtension":
  20640. case "ObjectTypeDefinition":
  20641. {
  20642. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", n.kind === "ObjectTypeExtension" ? "extend " : "", "type ", path$$1.call(print, "name"), n.interfaces.length > 0 ? concat$9([" implements ", join$7(determineInterfaceSeparator(options.originalText.substr(options.locStart(n), options.locEnd(n))), path$$1.map(print, "interfaces"))]) : "", printDirectives(path$$1, print, n), n.fields.length > 0 ? concat$9([" {", indent$7(concat$9([hardline$8, join$7(hardline$8, path$$1.call(function (fieldsPath) {
  20643. return printSequence(fieldsPath, options, print);
  20644. }, "fields"))])), hardline$8, "}"]) : ""]);
  20645. }
  20646. case "FieldDefinition":
  20647. {
  20648. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", path$$1.call(print, "name"), n.arguments.length > 0 ? group$4(concat$9(["(", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
  20649. return printSequence(argsPath, options, print);
  20650. }, "arguments"))])), softline$5, ")"])) : "", ": ", path$$1.call(print, "type"), printDirectives(path$$1, print, n)]);
  20651. }
  20652. case "DirectiveDefinition":
  20653. {
  20654. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", "directive ", "@", path$$1.call(print, "name"), n.arguments.length > 0 ? group$4(concat$9(["(", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
  20655. return printSequence(argsPath, options, print);
  20656. }, "arguments"))])), softline$5, ")"])) : "", concat$9([" on ", join$7(" | ", path$$1.map(print, "locations"))])]);
  20657. }
  20658. case "EnumTypeExtension":
  20659. case "EnumTypeDefinition":
  20660. {
  20661. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", n.kind === "EnumTypeExtension" ? "extend " : "", "enum ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.values.length > 0 ? concat$9([" {", indent$7(concat$9([hardline$8, join$7(hardline$8, path$$1.call(function (valuesPath) {
  20662. return printSequence(valuesPath, options, print);
  20663. }, "values"))])), hardline$8, "}"]) : ""]);
  20664. }
  20665. case "EnumValueDefinition":
  20666. {
  20667. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
  20668. }
  20669. case "InputValueDefinition":
  20670. {
  20671. return concat$9([path$$1.call(print, "description"), n.description ? n.description.block ? hardline$8 : line$6 : "", path$$1.call(print, "name"), ": ", path$$1.call(print, "type"), n.defaultValue ? concat$9([" = ", path$$1.call(print, "defaultValue")]) : "", printDirectives(path$$1, print, n)]);
  20672. }
  20673. case "InputObjectTypeExtension":
  20674. case "InputObjectTypeDefinition":
  20675. {
  20676. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", n.kind === "InputObjectTypeExtension" ? "extend " : "", "input ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.fields.length > 0 ? concat$9([" {", indent$7(concat$9([hardline$8, join$7(hardline$8, path$$1.call(function (fieldsPath) {
  20677. return printSequence(fieldsPath, options, print);
  20678. }, "fields"))])), hardline$8, "}"]) : ""]);
  20679. }
  20680. case "SchemaDefinition":
  20681. {
  20682. return concat$9(["schema", printDirectives(path$$1, print, n), " {", n.operationTypes.length > 0 ? indent$7(concat$9([hardline$8, join$7(hardline$8, path$$1.call(function (opsPath) {
  20683. return printSequence(opsPath, options, print);
  20684. }, "operationTypes"))])) : "", hardline$8, "}"]);
  20685. }
  20686. case "OperationTypeDefinition":
  20687. {
  20688. return concat$9([path$$1.call(print, "operation"), ": ", path$$1.call(print, "type")]);
  20689. }
  20690. case "InterfaceTypeExtension":
  20691. case "InterfaceTypeDefinition":
  20692. {
  20693. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", n.kind === "InterfaceTypeExtension" ? "extend " : "", "interface ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.fields.length > 0 ? concat$9([" {", indent$7(concat$9([hardline$8, join$7(hardline$8, path$$1.call(function (fieldsPath) {
  20694. return printSequence(fieldsPath, options, print);
  20695. }, "fields"))])), hardline$8, "}"]) : ""]);
  20696. }
  20697. case "FragmentSpread":
  20698. {
  20699. return concat$9(["...", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
  20700. }
  20701. case "InlineFragment":
  20702. {
  20703. return concat$9(["...", n.typeCondition ? concat$9([" on ", path$$1.call(print, "typeCondition")]) : "", printDirectives(path$$1, print, n), " ", path$$1.call(print, "selectionSet")]);
  20704. }
  20705. case "UnionTypeExtension":
  20706. case "UnionTypeDefinition":
  20707. {
  20708. return group$4(concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", group$4(concat$9([n.kind === "UnionTypeExtension" ? "extend " : "", "union ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.types.length > 0 ? concat$9([" =", ifBreak$4("", " "), indent$7(concat$9([ifBreak$4(concat$9([line$6, " "])), join$7(concat$9([line$6, "| "]), path$$1.map(print, "types"))]))]) : ""]))]));
  20709. }
  20710. case "ScalarTypeExtension":
  20711. case "ScalarTypeDefinition":
  20712. {
  20713. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", n.kind === "ScalarTypeExtension" ? "extend " : "", "scalar ", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
  20714. }
  20715. case "NonNullType":
  20716. {
  20717. return concat$9([path$$1.call(print, "type"), "!"]);
  20718. }
  20719. case "ListType":
  20720. {
  20721. return concat$9(["[", path$$1.call(print, "type"), "]"]);
  20722. }
  20723. default:
  20724. /* istanbul ignore next */
  20725. throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
  20726. }
  20727. }
  20728. function printDirectives(path$$1, print, n) {
  20729. if (n.directives.length === 0) {
  20730. return "";
  20731. }
  20732. return concat$9([" ", group$4(indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", " "), softline$5]), path$$1.map(print, "directives"))])))]);
  20733. }
  20734. function printSequence(sequencePath, options, print) {
  20735. var count = sequencePath.getValue().length;
  20736. return sequencePath.map(function (path$$1, i) {
  20737. var printed = print(path$$1);
  20738. if (isNextLineEmpty$4(options.originalText, path$$1.getValue(), options) && i < count - 1) {
  20739. return concat$9([printed, hardline$8]);
  20740. }
  20741. return printed;
  20742. });
  20743. }
  20744. function canAttachComment$1(node) {
  20745. return node.kind && node.kind !== "Comment";
  20746. }
  20747. function printComment$2(commentPath) {
  20748. var comment = commentPath.getValue();
  20749. switch (comment.kind) {
  20750. case "Comment":
  20751. return "#" + comment.value.trimRight();
  20752. default:
  20753. throw new Error("Not a comment: " + JSON.stringify(comment));
  20754. }
  20755. }
  20756. function determineInterfaceSeparator(originalSource) {
  20757. var start = originalSource.indexOf("implements");
  20758. if (start === -1) {
  20759. throw new Error("Must implement interfaces: " + originalSource);
  20760. }
  20761. var end = originalSource.indexOf("{");
  20762. if (end === -1) {
  20763. end = originalSource.length;
  20764. }
  20765. return originalSource.substr(start, end).includes("&") ? " & " : ", ";
  20766. }
  20767. function clean$6(node, newNode
  20768. /*, parent*/
  20769. ) {
  20770. delete newNode.loc;
  20771. delete newNode.comments;
  20772. }
  20773. var printerGraphql = {
  20774. print: genericPrint$4,
  20775. massageAstNode: clean$6,
  20776. hasPrettierIgnore: hasIgnoreComment$3,
  20777. printComment: printComment$2,
  20778. canAttachComment: canAttachComment$1
  20779. };
  20780. var options$10 = {
  20781. bracketSpacing: commonOptions.bracketSpacing
  20782. };
  20783. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  20784. var languages$3 = [{
  20785. name: "GraphQL",
  20786. since: "1.5.0",
  20787. parsers: ["graphql"],
  20788. extensions: [".graphql", ".gql"],
  20789. tmScope: "source.graphql",
  20790. aceMode: "text",
  20791. liguistLanguageId: 139,
  20792. vscodeLanguageIds: ["graphql"]
  20793. }];
  20794. var printers$3 = {
  20795. graphql: printerGraphql
  20796. };
  20797. var languageGraphql = {
  20798. languages: languages$3,
  20799. options: options$10,
  20800. printers: printers$3
  20801. };
  20802. var _require$$0$builders$6 = doc.builders;
  20803. var hardline$10 = _require$$0$builders$6.hardline;
  20804. var literalline$4 = _require$$0$builders$6.literalline;
  20805. var concat$11 = _require$$0$builders$6.concat;
  20806. var markAsRoot$2 = _require$$0$builders$6.markAsRoot;
  20807. var mapDoc$4 = doc.utils.mapDoc;
  20808. function embed$2(path$$1, print, textToDoc, options) {
  20809. var node = path$$1.getValue();
  20810. if (node.type === "code" && node.lang !== null) {
  20811. // only look for the first string so as to support [markdown-preview-enhanced](https://shd101wyy.github.io/markdown-preview-enhanced/#/code-chunk)
  20812. var lang = node.lang.split(/\s/, 1)[0];
  20813. var parser = getParserName(lang);
  20814. if (parser) {
  20815. var styleUnit = options.__inJsTemplate ? "~" : "`";
  20816. var style = styleUnit.repeat(Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1));
  20817. var doc$$2 = textToDoc(node.value, {
  20818. parser
  20819. });
  20820. return markAsRoot$2(concat$11([style, node.lang, hardline$10, replaceNewlinesWithLiterallines(doc$$2), style]));
  20821. }
  20822. }
  20823. return null;
  20824. function getParserName(lang) {
  20825. var supportInfo = support.getSupportInfo(null, {
  20826. plugins: options.plugins
  20827. });
  20828. var language = supportInfo.languages.find(function (language) {
  20829. return language.name.toLowerCase() === lang || language.extensions && language.extensions.find(function (ext) {
  20830. return ext.substring(1) === lang;
  20831. });
  20832. });
  20833. if (language) {
  20834. return language.parsers[0];
  20835. }
  20836. return null;
  20837. }
  20838. function replaceNewlinesWithLiterallines(doc$$2) {
  20839. return mapDoc$4(doc$$2, function (currentDoc) {
  20840. return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$11(currentDoc.split(/(\n)/g).map(function (v, i) {
  20841. return i % 2 === 0 ? v : literalline$4;
  20842. })) : currentDoc;
  20843. });
  20844. }
  20845. }
  20846. var embed_1$2 = embed$2;
  20847. function parse$5(text) {
  20848. var delimiter;
  20849. if (text.indexOf("---") === 0) {
  20850. delimiter = "---";
  20851. } else if (text.indexOf("+++") === 0) {
  20852. delimiter = "+++";
  20853. }
  20854. var end = -1;
  20855. if (!delimiter || (end = text.indexOf(`\n${delimiter}`, 3)) === -1) {
  20856. return {
  20857. frontMatter: null,
  20858. content: text
  20859. };
  20860. }
  20861. end = end + 4;
  20862. return {
  20863. frontMatter: text.slice(0, end),
  20864. content: text.slice(end)
  20865. };
  20866. }
  20867. var frontMatter = parse$5;
  20868. var pragma$2 = createCommonjsModule(function (module) {
  20869. "use strict";
  20870. var pragmas = ["format", "prettier"];
  20871. function startWithPragma(text) {
  20872. var pragma = `@(${pragmas.join("|")})`;
  20873. var regex = new RegExp([`<!--\\s*${pragma}\\s*-->`, `<!--.*\n[\\s\\S]*(^|\n)[^\\S\n]*${pragma}[^\\S\n]*($|\n)[\\s\\S]*\n.*-->`].join("|"), "m");
  20874. var matched = text.match(regex);
  20875. return matched && matched.index === 0;
  20876. }
  20877. module.exports = {
  20878. startWithPragma,
  20879. hasPragma: function hasPragma(text) {
  20880. return startWithPragma(frontMatter(text).content.trimLeft());
  20881. },
  20882. insertPragma: function insertPragma(text) {
  20883. var extracted = frontMatter(text);
  20884. var pragma = `<!-- @${pragmas[0]} -->`;
  20885. return extracted.frontMatter ? `${extracted.frontMatter}\n\n${pragma}\n\n${extracted.content}` : `${pragma}\n\n${extracted.content}`;
  20886. }
  20887. };
  20888. });
  20889. var _require$$0$builders$5 = doc.builders;
  20890. var concat$10 = _require$$0$builders$5.concat;
  20891. var join$8 = _require$$0$builders$5.join;
  20892. var line$7 = _require$$0$builders$5.line;
  20893. var literalline$3 = _require$$0$builders$5.literalline;
  20894. var markAsRoot$1 = _require$$0$builders$5.markAsRoot;
  20895. var hardline$9 = _require$$0$builders$5.hardline;
  20896. var softline$6 = _require$$0$builders$5.softline;
  20897. var fill$4 = _require$$0$builders$5.fill;
  20898. var align$2 = _require$$0$builders$5.align;
  20899. var indent$8 = _require$$0$builders$5.indent;
  20900. var group$5 = _require$$0$builders$5.group;
  20901. var mapDoc$3 = doc.utils.mapDoc;
  20902. var printDocToString$3 = doc.printer.printDocToString;
  20903. var SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link"];
  20904. var SIBLING_NODE_TYPES = ["listItem", "definition", "footnoteDefinition"];
  20905. var INLINE_NODE_TYPES = ["liquidNode", "inlineCode", "emphasis", "strong", "delete", "link", "linkReference", "image", "imageReference", "footnote", "footnoteReference", "sentence", "whitespace", "word", "break"];
  20906. var INLINE_NODE_WRAPPER_TYPES = INLINE_NODE_TYPES.concat(["tableCell", "paragraph", "heading"]);
  20907. function genericPrint$5(path$$1, options, print) {
  20908. var node = path$$1.getValue();
  20909. if (shouldRemainTheSameContent(path$$1)) {
  20910. return concat$10(util$1.splitText(options.originalText.slice(node.position.start.offset, node.position.end.offset), options).map(function (node) {
  20911. return node.type === "word" ? node.value : node.value === "" ? "" : printLine(path$$1, node.value, options);
  20912. }));
  20913. }
  20914. switch (node.type) {
  20915. case "root":
  20916. if (node.children.length === 0) {
  20917. return "";
  20918. }
  20919. return concat$10([normalizeDoc(printRoot(path$$1, options, print)), hardline$9]);
  20920. case "paragraph":
  20921. return printChildren(path$$1, options, print, {
  20922. postprocessor: fill$4
  20923. });
  20924. case "sentence":
  20925. return printChildren(path$$1, options, print);
  20926. case "word":
  20927. return node.value.replace(/[*]/g, "\\*") // escape all `*`
  20928. .replace(new RegExp([`(^|[${util$1.punctuationCharRange}])(_+)`, `(_+)([${util$1.punctuationCharRange}]|$)`].join("|"), "g"), function (_, text1, underscore1, underscore2, text2) {
  20929. return (underscore1 ? `${text1}${underscore1}` : `${underscore2}${text2}`).replace(/_/g, "\\_");
  20930. });
  20931. // escape all `_` except concating with non-punctuation, e.g. `1_2_3` is not considered emphasis
  20932. case "whitespace":
  20933. {
  20934. var parentNode = path$$1.getParentNode();
  20935. var index = parentNode.children.indexOf(node);
  20936. var nextNode = parentNode.children[index + 1];
  20937. var proseWrap = // leading char that may cause different syntax
  20938. nextNode && /^>|^([-+*]|#{1,6}|[0-9]+[.)])$/.test(nextNode.value) ? "never" : options.proseWrap;
  20939. return printLine(path$$1, node.value, {
  20940. proseWrap
  20941. });
  20942. }
  20943. case "emphasis":
  20944. {
  20945. var _parentNode = path$$1.getParentNode();
  20946. var _index = _parentNode.children.indexOf(node);
  20947. var prevNode = _parentNode.children[_index - 1];
  20948. var _nextNode = _parentNode.children[_index + 1];
  20949. var hasPrevOrNextWord = // `1*2*3` is considered emphais but `1_2_3` is not
  20950. prevNode && prevNode.type === "sentence" && prevNode.children.length > 0 && util$1.getLast(prevNode.children).type === "word" && !util$1.getLast(prevNode.children).hasTrailingPunctuation || _nextNode && _nextNode.type === "sentence" && _nextNode.children.length > 0 && _nextNode.children[0].type === "word" && !_nextNode.children[0].hasLeadingPunctuation;
  20951. var style = hasPrevOrNextWord || getAncestorNode$2(path$$1, "emphasis") ? "*" : "_";
  20952. return concat$10([style, printChildren(path$$1, options, print), style]);
  20953. }
  20954. case "strong":
  20955. return concat$10(["**", printChildren(path$$1, options, print), "**"]);
  20956. case "delete":
  20957. return concat$10(["~~", printChildren(path$$1, options, print), "~~"]);
  20958. case "inlineCode":
  20959. {
  20960. var backtickCount = util$1.getMaxContinuousCount(node.value, "`");
  20961. var _style = backtickCount === 1 ? "``" : "`";
  20962. var gap = backtickCount ? " " : "";
  20963. return concat$10([_style, gap, node.value, gap, _style]);
  20964. }
  20965. case "link":
  20966. switch (options.originalText[node.position.start.offset]) {
  20967. case "<":
  20968. return concat$10(["<", node.url, ">"]);
  20969. case "[":
  20970. return concat$10(["[", printChildren(path$$1, options, print), "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  20971. default:
  20972. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  20973. }
  20974. case "image":
  20975. return concat$10(["![", node.alt || "", "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  20976. case "blockquote":
  20977. return concat$10(["> ", align$2("> ", printChildren(path$$1, options, print))]);
  20978. case "heading":
  20979. return concat$10(["#".repeat(node.depth) + " ", printChildren(path$$1, options, print)]);
  20980. case "code":
  20981. {
  20982. if ( // the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it
  20983. /^\n?( {4,}|\t)/.test(options.originalText.slice(node.position.start.offset, node.position.end.offset))) {
  20984. // indented code block
  20985. var alignment = " ".repeat(4);
  20986. return align$2(alignment, concat$10([alignment, join$8(hardline$9, node.value.split("\n"))]));
  20987. } // fenced code block
  20988. var styleUnit = options.__inJsTemplate ? "~" : "`";
  20989. var _style2 = styleUnit.repeat(Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1));
  20990. return concat$10([_style2, node.lang || "", hardline$9, join$8(hardline$9, node.value.split("\n")), hardline$9, _style2]);
  20991. }
  20992. case "front-matter":
  20993. return node.value;
  20994. case "html":
  20995. {
  20996. var _parentNode2 = path$$1.getParentNode();
  20997. var value = _parentNode2.type === "root" && util$1.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value;
  20998. var isHtmlComment = /^<!--[\s\S]*-->$/.test(value);
  20999. return replaceNewlinesWith(value, isHtmlComment ? hardline$9 : markAsRoot$1(literalline$3));
  21000. }
  21001. case "list":
  21002. {
  21003. var nthSiblingIndex = getNthListSiblingIndex(node, path$$1.getParentNode());
  21004. var isGitDiffFriendlyOrderedList = node.ordered && node.children.length > 1 && /^\s*1(\.|\))/.test(options.originalText.slice(node.children[1].position.start.offset, node.children[1].position.end.offset));
  21005. return printChildren(path$$1, options, print, {
  21006. processor: function processor(childPath, index) {
  21007. var prefix = getPrefix();
  21008. return concat$10([prefix, align$2(" ".repeat(prefix.length), printListItem(childPath, options, print, prefix))]);
  21009. function getPrefix() {
  21010. var rawPrefix = node.ordered ? (index === 0 ? node.start : isGitDiffFriendlyOrderedList ? 1 : node.start + index) + (nthSiblingIndex % 2 === 0 ? ". " : ") ") : nthSiblingIndex % 2 === 0 ? "- " : "* "; // do not print trailing spaces for empty list item since it might be treated as `break` node
  21011. // by [doc-printer](https://github.com/prettier/prettier/blob/1.10.2/src/doc/doc-printer.js#L395-L405),
  21012. // we don't want to preserve unnecessary trailing spaces.
  21013. var listItem = childPath.getValue();
  21014. return listItem.children.length ? alignListPrefix(rawPrefix, options) : rawPrefix;
  21015. }
  21016. }
  21017. });
  21018. }
  21019. case "thematicBreak":
  21020. {
  21021. var counter = getAncestorCounter$1(path$$1, "list");
  21022. if (counter === -1) {
  21023. return "---";
  21024. }
  21025. var _nthSiblingIndex = getNthListSiblingIndex(path$$1.getParentNode(counter), path$$1.getParentNode(counter + 1));
  21026. return _nthSiblingIndex % 2 === 0 ? "***" : "---";
  21027. }
  21028. case "linkReference":
  21029. return concat$10(["[", printChildren(path$$1, options, print), "]", node.referenceType === "full" ? concat$10(["[", node.identifier, "]"]) : node.referenceType === "collapsed" ? "[]" : ""]);
  21030. case "imageReference":
  21031. switch (node.referenceType) {
  21032. case "full":
  21033. return concat$10(["![", node.alt || "", "][", node.identifier, "]"]);
  21034. default:
  21035. return concat$10(["![", node.alt, "]", node.referenceType === "collapsed" ? "[]" : ""]);
  21036. }
  21037. case "definition":
  21038. {
  21039. var lineOrSpace = options.proseWrap === "always" ? line$7 : " ";
  21040. return group$5(concat$10([concat$10(["[", node.identifier, "]:"]), indent$8(concat$10([lineOrSpace, printUrl(node.url), node.title === null ? "" : concat$10([lineOrSpace, printTitle(node.title, options, false)])]))]));
  21041. }
  21042. case "footnote":
  21043. return concat$10(["[^", printChildren(path$$1, options, print), "]"]);
  21044. case "footnoteReference":
  21045. return concat$10(["[^", node.identifier, "]"]);
  21046. case "footnoteDefinition":
  21047. {
  21048. var _nextNode2 = path$$1.getParentNode().children[path$$1.getName() + 1];
  21049. return concat$10(["[^", node.identifier, "]: ", group$5(concat$10([align$2(" ".repeat(options.tabWidth), printChildren(path$$1, options, print, {
  21050. processor: function processor(childPath, index) {
  21051. return index === 0 ? group$5(concat$10([softline$6, softline$6, childPath.call(print)])) : childPath.call(print);
  21052. }
  21053. })), _nextNode2 && _nextNode2.type === "footnoteDefinition" ? softline$6 : ""]))]);
  21054. }
  21055. case "table":
  21056. return printTable(path$$1, options, print);
  21057. case "tableCell":
  21058. return printChildren(path$$1, options, print);
  21059. case "break":
  21060. return /\s/.test(options.originalText[node.position.start.offset]) ? concat$10([" ", markAsRoot$1(literalline$3)]) : concat$10(["\\", hardline$9]);
  21061. case "liquidNode":
  21062. return replaceNewlinesWith(node.value, hardline$9);
  21063. case "tableRow": // handled in "table"
  21064. case "listItem": // handled in "list"
  21065. default:
  21066. throw new Error(`Unknown markdown type ${JSON.stringify(node.type)}`);
  21067. }
  21068. }
  21069. function printListItem(path$$1, options, print, listPrefix) {
  21070. var node = path$$1.getValue();
  21071. var prefix = node.checked === null ? "" : node.checked ? "[x] " : "[ ] ";
  21072. return concat$10([prefix, printChildren(path$$1, options, print, {
  21073. processor: function processor(childPath, index) {
  21074. if (index === 0 && childPath.getValue().type !== "list") {
  21075. return align$2(" ".repeat(prefix.length), childPath.call(print));
  21076. }
  21077. var alignment = " ".repeat(clamp(options.tabWidth - listPrefix.length, 0, 3) // 4+ will cause indented code block
  21078. );
  21079. return concat$10([alignment, align$2(alignment, childPath.call(print))]);
  21080. }
  21081. })]);
  21082. }
  21083. function alignListPrefix(prefix, options) {
  21084. var additionalSpaces = getAdditionalSpaces();
  21085. return prefix + " ".repeat(additionalSpaces >= 4 ? 0 : additionalSpaces // 4+ will cause indented code block
  21086. );
  21087. function getAdditionalSpaces() {
  21088. var restSpaces = prefix.length % options.tabWidth;
  21089. return restSpaces === 0 ? 0 : options.tabWidth - restSpaces;
  21090. }
  21091. }
  21092. function getNthListSiblingIndex(node, parentNode) {
  21093. return getNthSiblingIndex(node, parentNode, function (siblingNode) {
  21094. return siblingNode.ordered === node.ordered;
  21095. });
  21096. }
  21097. function replaceNewlinesWith(str, doc$$2) {
  21098. return join$8(doc$$2, str.split("\n"));
  21099. }
  21100. function getNthSiblingIndex(node, parentNode, condition) {
  21101. condition = condition || function () {
  21102. return true;
  21103. };
  21104. var index = -1;
  21105. var _iteratorNormalCompletion = true;
  21106. var _didIteratorError = false;
  21107. var _iteratorError = undefined;
  21108. try {
  21109. for (var _iterator = parentNode.children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  21110. var childNode = _step.value;
  21111. if (childNode.type === node.type && condition(childNode)) {
  21112. index++;
  21113. } else {
  21114. index = -1;
  21115. }
  21116. if (childNode === node) {
  21117. return index;
  21118. }
  21119. }
  21120. } catch (err) {
  21121. _didIteratorError = true;
  21122. _iteratorError = err;
  21123. } finally {
  21124. try {
  21125. if (!_iteratorNormalCompletion && _iterator.return != null) {
  21126. _iterator.return();
  21127. }
  21128. } finally {
  21129. if (_didIteratorError) {
  21130. throw _iteratorError;
  21131. }
  21132. }
  21133. }
  21134. }
  21135. function getAncestorCounter$1(path$$1, typeOrTypes) {
  21136. var types = [].concat(typeOrTypes);
  21137. var counter = -1;
  21138. var ancestorNode;
  21139. while (ancestorNode = path$$1.getParentNode(++counter)) {
  21140. if (types.indexOf(ancestorNode.type) !== -1) {
  21141. return counter;
  21142. }
  21143. }
  21144. return -1;
  21145. }
  21146. function getAncestorNode$2(path$$1, typeOrTypes) {
  21147. var counter = getAncestorCounter$1(path$$1, typeOrTypes);
  21148. return counter === -1 ? null : path$$1.getParentNode(counter);
  21149. }
  21150. function printLine(path$$1, value, options) {
  21151. if (options.proseWrap === "preserve" && value === "\n") {
  21152. return hardline$9;
  21153. }
  21154. var isBreakable = options.proseWrap === "always" && !getAncestorNode$2(path$$1, SINGLE_LINE_NODE_TYPES);
  21155. return value !== "" ? isBreakable ? line$7 : " " : isBreakable ? softline$6 : "";
  21156. }
  21157. function printTable(path$$1, options, print) {
  21158. var node = path$$1.getValue();
  21159. var contents = []; // { [rowIndex: number]: { [columnIndex: number]: string } }
  21160. path$$1.map(function (rowPath) {
  21161. var rowContents = [];
  21162. rowPath.map(function (cellPath) {
  21163. rowContents.push(printDocToString$3(cellPath.call(print), options).formatted);
  21164. }, "children");
  21165. contents.push(rowContents);
  21166. }, "children");
  21167. var columnMaxWidths = contents.reduce(function (currentWidths, rowContents) {
  21168. return currentWidths.map(function (width, columnIndex) {
  21169. return Math.max(width, util$1.getStringWidth(rowContents[columnIndex]));
  21170. });
  21171. }, contents[0].map(function () {
  21172. return 3;
  21173. }) // minimum width = 3 (---, :--, :-:, --:)
  21174. );
  21175. return join$8(hardline$9, [printRow(contents[0]), printSeparator(), join$8(hardline$9, contents.slice(1).map(printRow))]);
  21176. function printSeparator() {
  21177. return concat$10(["| ", join$8(" | ", columnMaxWidths.map(function (width, index) {
  21178. switch (node.align[index]) {
  21179. case "left":
  21180. return ":" + "-".repeat(width - 1);
  21181. case "right":
  21182. return "-".repeat(width - 1) + ":";
  21183. case "center":
  21184. return ":" + "-".repeat(width - 2) + ":";
  21185. default:
  21186. return "-".repeat(width);
  21187. }
  21188. })), " |"]);
  21189. }
  21190. function printRow(rowContents) {
  21191. return concat$10(["| ", join$8(" | ", rowContents.map(function (rowContent, columnIndex) {
  21192. switch (node.align[columnIndex]) {
  21193. case "right":
  21194. return alignRight(rowContent, columnMaxWidths[columnIndex]);
  21195. case "center":
  21196. return alignCenter(rowContent, columnMaxWidths[columnIndex]);
  21197. default:
  21198. return alignLeft(rowContent, columnMaxWidths[columnIndex]);
  21199. }
  21200. })), " |"]);
  21201. }
  21202. function alignLeft(text, width) {
  21203. return concat$10([text, " ".repeat(width - util$1.getStringWidth(text))]);
  21204. }
  21205. function alignRight(text, width) {
  21206. return concat$10([" ".repeat(width - util$1.getStringWidth(text)), text]);
  21207. }
  21208. function alignCenter(text, width) {
  21209. var spaces = width - util$1.getStringWidth(text);
  21210. var left = Math.floor(spaces / 2);
  21211. var right = spaces - left;
  21212. return concat$10([" ".repeat(left), text, " ".repeat(right)]);
  21213. }
  21214. }
  21215. function printRoot(path$$1, options, print) {
  21216. /** @typedef {{ index: number, offset: number }} IgnorePosition */
  21217. /** @type {Array<{start: IgnorePosition, end: IgnorePosition}>} */
  21218. var ignoreRanges = [];
  21219. /** @type {IgnorePosition | null} */
  21220. var ignoreStart = null;
  21221. var children = path$$1.getValue().children;
  21222. children.forEach(function (childNode, index) {
  21223. switch (isPrettierIgnore(childNode)) {
  21224. case "start":
  21225. if (ignoreStart === null) {
  21226. ignoreStart = {
  21227. index,
  21228. offset: childNode.position.end.offset
  21229. };
  21230. }
  21231. break;
  21232. case "end":
  21233. if (ignoreStart !== null) {
  21234. ignoreRanges.push({
  21235. start: ignoreStart,
  21236. end: {
  21237. index,
  21238. offset: childNode.position.start.offset
  21239. }
  21240. });
  21241. ignoreStart = null;
  21242. }
  21243. break;
  21244. default:
  21245. // do nothing
  21246. break;
  21247. }
  21248. });
  21249. return printChildren(path$$1, options, print, {
  21250. processor: function processor(childPath, index) {
  21251. if (ignoreRanges.length !== 0) {
  21252. var ignoreRange = ignoreRanges[0];
  21253. if (index === ignoreRange.start.index) {
  21254. return concat$10([children[ignoreRange.start.index].value, options.originalText.slice(ignoreRange.start.offset, ignoreRange.end.offset), children[ignoreRange.end.index].value]);
  21255. }
  21256. if (ignoreRange.start.index < index && index < ignoreRange.end.index) {
  21257. return false;
  21258. }
  21259. if (index === ignoreRange.end.index) {
  21260. ignoreRanges.shift();
  21261. return false;
  21262. }
  21263. }
  21264. return childPath.call(print);
  21265. }
  21266. });
  21267. }
  21268. function printChildren(path$$1, options, print, events$$1) {
  21269. events$$1 = events$$1 || {};
  21270. var postprocessor = events$$1.postprocessor || concat$10;
  21271. var processor = events$$1.processor || function (childPath) {
  21272. return childPath.call(print);
  21273. };
  21274. var node = path$$1.getValue();
  21275. var parts = [];
  21276. var lastChildNode;
  21277. path$$1.map(function (childPath, index) {
  21278. var childNode = childPath.getValue();
  21279. var result = processor(childPath, index);
  21280. if (result !== false) {
  21281. var data = {
  21282. parts,
  21283. prevNode: lastChildNode,
  21284. parentNode: node,
  21285. options
  21286. };
  21287. if (!shouldNotPrePrintHardline(childNode, data)) {
  21288. parts.push(hardline$9);
  21289. if (shouldPrePrintDoubleHardline(childNode, data) || shouldPrePrintTripleHardline(childNode, data)) {
  21290. parts.push(hardline$9);
  21291. }
  21292. if (shouldPrePrintTripleHardline(childNode, data)) {
  21293. parts.push(hardline$9);
  21294. }
  21295. }
  21296. parts.push(result);
  21297. lastChildNode = childNode;
  21298. }
  21299. }, "children");
  21300. return postprocessor(parts);
  21301. }
  21302. /** @return {false | 'next' | 'start' | 'end'} */
  21303. function isPrettierIgnore(node) {
  21304. if (node.type !== "html") {
  21305. return false;
  21306. }
  21307. var match = node.value.match(/^<!--\s*prettier-ignore(?:-(start|end))?\s*-->$/);
  21308. return match === null ? false : match[1] ? match[1] : "next";
  21309. }
  21310. function shouldNotPrePrintHardline(node, data) {
  21311. var isFirstNode = data.parts.length === 0;
  21312. var isInlineNode = INLINE_NODE_TYPES.indexOf(node.type) !== -1;
  21313. var isInlineHTML = node.type === "html" && INLINE_NODE_WRAPPER_TYPES.indexOf(data.parentNode.type) !== -1;
  21314. return isFirstNode || isInlineNode || isInlineHTML;
  21315. }
  21316. function shouldPrePrintDoubleHardline(node, data) {
  21317. var isSequence = (data.prevNode && data.prevNode.type) === node.type;
  21318. var isSiblingNode = isSequence && SIBLING_NODE_TYPES.indexOf(node.type) !== -1;
  21319. var isInTightListItem = data.parentNode.type === "listItem" && !data.parentNode.loose;
  21320. var isPrevNodeLooseListItem = data.prevNode && data.prevNode.type === "listItem" && data.prevNode.loose;
  21321. var isPrevNodePrettierIgnore = isPrettierIgnore(data.prevNode) === "next";
  21322. var isBlockHtmlWithoutBlankLineBetweenPrevHtml = node.type === "html" && data.prevNode && data.prevNode.type === "html" && data.prevNode.position.end.line + 1 === node.position.start.line;
  21323. return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore || isBlockHtmlWithoutBlankLineBetweenPrevHtml);
  21324. }
  21325. function shouldPrePrintTripleHardline(node, data) {
  21326. var isPrevNodeList = data.prevNode && data.prevNode.type === "list";
  21327. var isIndentedCode = node.type === "code" && /\s/.test(data.options.originalText[node.position.start.offset]);
  21328. return isPrevNodeList && isIndentedCode;
  21329. }
  21330. function shouldRemainTheSameContent(path$$1) {
  21331. var ancestorNode = getAncestorNode$2(path$$1, ["linkReference", "imageReference"]);
  21332. return ancestorNode && (ancestorNode.type !== "linkReference" || ancestorNode.referenceType !== "full");
  21333. }
  21334. function normalizeDoc(doc$$2) {
  21335. return mapDoc$3(doc$$2, function (currentDoc) {
  21336. if (!currentDoc.parts) {
  21337. return currentDoc;
  21338. }
  21339. if (currentDoc.type === "concat" && currentDoc.parts.length === 1) {
  21340. return currentDoc.parts[0];
  21341. }
  21342. var parts = [];
  21343. currentDoc.parts.forEach(function (part) {
  21344. if (part.type === "concat") {
  21345. parts.push.apply(parts, part.parts);
  21346. } else if (part !== "") {
  21347. parts.push(part);
  21348. }
  21349. });
  21350. return Object.assign({}, currentDoc, {
  21351. parts: normalizeParts(parts)
  21352. });
  21353. });
  21354. }
  21355. function printUrl(url, dangerousCharOrChars) {
  21356. var dangerousChars = [" "].concat(dangerousCharOrChars || []);
  21357. return new RegExp(dangerousChars.map(function (x) {
  21358. return `\\${x}`;
  21359. }).join("|")).test(url) ? `<${url}>` : url;
  21360. }
  21361. function printTitle(title, options, printSpace) {
  21362. if (printSpace == null) {
  21363. printSpace = true;
  21364. }
  21365. if (!title) {
  21366. return "";
  21367. }
  21368. if (printSpace) {
  21369. return " " + printTitle(title, options, false);
  21370. }
  21371. if (title.includes('"') && title.includes("'") && !title.includes(")")) {
  21372. return `(${title})`; // avoid escaped quotes
  21373. } // faster than using RegExps: https://jsperf.com/performance-of-match-vs-split
  21374. var singleCount = title.split("'").length - 1;
  21375. var doubleCount = title.split('"').length - 1;
  21376. var quote = singleCount > doubleCount ? '"' : doubleCount > singleCount ? "'" : options.singleQuote ? "'" : '"';
  21377. title = title.replace(new RegExp(`(${quote})`, "g"), "\\$1");
  21378. return `${quote}${title}${quote}`;
  21379. }
  21380. function normalizeParts(parts) {
  21381. return parts.reduce(function (current, part) {
  21382. var lastPart = util$1.getLast(current);
  21383. if (typeof lastPart === "string" && typeof part === "string") {
  21384. current.splice(-1, 1, lastPart + part);
  21385. } else {
  21386. current.push(part);
  21387. }
  21388. return current;
  21389. }, []);
  21390. }
  21391. function clamp(value, min, max) {
  21392. return value < min ? min : value > max ? max : value;
  21393. }
  21394. function clean$7(ast, newObj, parent) {
  21395. delete newObj.position; // for codeblock
  21396. if (ast.type === "code") {
  21397. delete newObj.value;
  21398. } // for whitespace: "\n" and " " are considered the same
  21399. if (ast.type === "whitespace" && ast.value === "\n") {
  21400. newObj.value = " ";
  21401. } // for insert pragma
  21402. if (parent && parent.type === "root" && parent.children.length > 0 && (parent.children[0] === ast || parent.children[0].type === "front-matter" && parent.children[1] === ast) && ast.type === "html" && pragma$2.startWithPragma(ast.value)) {
  21403. return null;
  21404. }
  21405. }
  21406. function hasPrettierIgnore$1(path$$1) {
  21407. var index = +path$$1.getName();
  21408. if (index === 0) {
  21409. return false;
  21410. }
  21411. var prevNode = path$$1.getParentNode().children[index - 1];
  21412. return isPrettierIgnore(prevNode) === "next";
  21413. }
  21414. var printerMarkdown = {
  21415. print: genericPrint$5,
  21416. embed: embed_1$2,
  21417. massageAstNode: clean$7,
  21418. hasPrettierIgnore: hasPrettierIgnore$1,
  21419. insertPragma: pragma$2.insertPragma
  21420. };
  21421. var CATEGORY_MARKDOWN = "Markdown"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  21422. var options$13 = {
  21423. proseWrap: {
  21424. since: "1.8.2",
  21425. category: CATEGORY_MARKDOWN,
  21426. type: "choice",
  21427. default: [{
  21428. since: "1.8.2",
  21429. value: true
  21430. }, {
  21431. since: "1.9.0",
  21432. value: "preserve"
  21433. }],
  21434. description: "How to wrap prose. (markdown)",
  21435. choices: [{
  21436. since: "1.9.0",
  21437. value: "always",
  21438. description: "Wrap prose if it exceeds the print width."
  21439. }, {
  21440. since: "1.9.0",
  21441. value: "never",
  21442. description: "Do not wrap prose."
  21443. }, {
  21444. since: "1.9.0",
  21445. value: "preserve",
  21446. description: "Wrap prose as-is."
  21447. }, {
  21448. value: false,
  21449. deprecated: "1.9.0",
  21450. redirect: "never"
  21451. }, {
  21452. value: true,
  21453. deprecated: "1.9.0",
  21454. redirect: "always"
  21455. }]
  21456. },
  21457. singleQuote: commonOptions.singleQuote
  21458. };
  21459. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  21460. var languages$4 = [{
  21461. name: "Markdown",
  21462. since: "1.8.0",
  21463. parsers: ["remark"],
  21464. aliases: ["pandoc"],
  21465. aceMode: "markdown",
  21466. codemirrorMode: "gfm",
  21467. codemirrorMimeType: "text/x-gfm",
  21468. wrap: true,
  21469. extensions: [".md", ".markdown", ".mdown", ".mdwn", ".mkd", ".mkdn", ".mkdown", ".ron", ".workbook"],
  21470. filenames: ["README"],
  21471. tmScope: "source.gfm",
  21472. linguistLanguageId: 222,
  21473. vscodeLanguageIds: ["markdown"]
  21474. }];
  21475. var printers$4 = {
  21476. mdast: printerMarkdown
  21477. };
  21478. var languageMarkdown = {
  21479. languages: languages$4,
  21480. options: options$13,
  21481. printers: printers$4
  21482. };
  21483. var hasNewlineInRange$3 = util$1.hasNewlineInRange;
  21484. var _require$$1$builders$1 = doc.builders;
  21485. var hardline$12 = _require$$1$builders$1.hardline;
  21486. var concat$13 = _require$$1$builders$1.concat;
  21487. var _require$$1$utils = doc.utils;
  21488. var stripTrailingHardline$2 = _require$$1$utils.stripTrailingHardline;
  21489. var removeLines$3 = _require$$1$utils.removeLines;
  21490. function embed$4(path$$1, print, textToDoc, options) {
  21491. var node = path$$1.getValue();
  21492. switch (node.type) {
  21493. case "text":
  21494. {
  21495. var parent = path$$1.getParentNode(); // Inline JavaScript
  21496. if (parent.type === "script" && (!parent.attribs.lang && !parent.attribs.lang || parent.attribs.type === "text/javascript" || parent.attribs.type === "application/javascript")) {
  21497. var parser = options.parser === "flow" ? "flow" : "babylon";
  21498. var doc$$2 = textToDoc(getText(options, node), {
  21499. parser
  21500. });
  21501. return concat$13([hardline$12, doc$$2]);
  21502. } // Inline TypeScript
  21503. if (parent.type === "script" && (parent.attribs.type === "application/x-typescript" || parent.attribs.lang === "ts")) {
  21504. var _doc = textToDoc(getText(options, node), {
  21505. parser: "typescript"
  21506. }, options);
  21507. return concat$13([hardline$12, _doc]);
  21508. } // Inline Styles
  21509. if (parent.type === "style") {
  21510. var _doc2 = textToDoc(getText(options, node), {
  21511. parser: "css"
  21512. });
  21513. return concat$13([hardline$12, stripTrailingHardline$2(_doc2)]);
  21514. }
  21515. break;
  21516. }
  21517. case "attribute":
  21518. {
  21519. /*
  21520. * Vue binding sytax: JS expressions
  21521. * :class="{ 'some-key': value }"
  21522. * v-bind:id="'list-' + id"
  21523. * v-if="foo && !bar"
  21524. * @click="someFunction()"
  21525. */
  21526. if (/(^@)|(^v-)|:/.test(node.key) && !/^\w+$/.test(node.value)) {
  21527. var _doc3 = textToDoc(node.value, {
  21528. parser: parseJavaScriptExpression,
  21529. // Use singleQuote since HTML attributes use double-quotes.
  21530. // TODO(azz): We still need to do an entity escape on the attribute.
  21531. singleQuote: true
  21532. });
  21533. return concat$13([node.key, '="', hasNewlineInRange$3(node.value, 0, node.value.length) ? _doc3 : removeLines$3(_doc3), '"']);
  21534. }
  21535. }
  21536. }
  21537. }
  21538. function parseJavaScriptExpression(text, parsers) {
  21539. // Force parsing as an expression
  21540. var ast = parsers.babylon(`(${text})`); // Extract expression from the declaration
  21541. return {
  21542. type: "File",
  21543. program: ast.program.body[0].expression
  21544. };
  21545. }
  21546. function getText(options, node) {
  21547. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  21548. }
  21549. var embed_1$4 = embed$4;
  21550. var clean$8 = function clean(ast, newNode) {
  21551. delete newNode.__location;
  21552. if (ast.type === "text") {
  21553. return null;
  21554. }
  21555. };
  21556. var hasNewlineInRange$2 = util$1.hasNewlineInRange;
  21557. var hasIgnoreComment$4 = util$1.hasIgnoreComment;
  21558. var _require$$1$builders = doc.builders;
  21559. var concat$12 = _require$$1$builders.concat;
  21560. var join$9 = _require$$1$builders.join;
  21561. var hardline$11 = _require$$1$builders.hardline;
  21562. var line$8 = _require$$1$builders.line;
  21563. var softline$7 = _require$$1$builders.softline;
  21564. var group$6 = _require$$1$builders.group;
  21565. var indent$9 = _require$$1$builders.indent; // http://w3c.github.io/html/single-page.html#void-elements
  21566. var voidTags$1 = {
  21567. area: true,
  21568. base: true,
  21569. br: true,
  21570. col: true,
  21571. embed: true,
  21572. hr: true,
  21573. img: true,
  21574. input: true,
  21575. link: true,
  21576. meta: true,
  21577. param: true,
  21578. source: true,
  21579. track: true,
  21580. wbr: true
  21581. };
  21582. function genericPrint$6(path$$1, options, print) {
  21583. var n = path$$1.getValue();
  21584. if (!n) {
  21585. return "";
  21586. }
  21587. if (typeof n === "string") {
  21588. return n;
  21589. }
  21590. switch (n.type) {
  21591. case "root":
  21592. {
  21593. return printChildren$1(path$$1, print);
  21594. }
  21595. case "directive":
  21596. {
  21597. return concat$12(["<", n.data, ">", hardline$11]);
  21598. }
  21599. case "text":
  21600. {
  21601. return n.data.replace(/\s+/g, " ").trim();
  21602. }
  21603. case "script":
  21604. case "style":
  21605. case "tag":
  21606. {
  21607. var selfClose = voidTags$1[n.name] ? ">" : " />";
  21608. var children = printChildren$1(path$$1, print);
  21609. var hasNewline = hasNewlineInRange$2(options.originalText, options.locStart(n), options.locEnd(n));
  21610. return group$6(concat$12([hasNewline ? hardline$11 : "", "<", n.name, printAttributes(path$$1, print), n.children.length ? ">" : selfClose, n.name.toLowerCase() === "html" ? concat$12([hardline$11, children]) : indent$9(children), n.children.length ? concat$12([softline$7, "</", n.name, ">"]) : hardline$11]));
  21611. }
  21612. case "comment":
  21613. {
  21614. return concat$12(["<!-- ", n.data.trim(), " -->"]);
  21615. }
  21616. case "attribute":
  21617. {
  21618. if (!n.value) {
  21619. return n.key;
  21620. }
  21621. return concat$12([n.key, '="', n.value, '"']);
  21622. }
  21623. default:
  21624. /* istanbul ignore next */
  21625. throw new Error("unknown htmlparser2 type: " + n.type);
  21626. }
  21627. }
  21628. function printAttributes(path$$1, print) {
  21629. var node = path$$1.getValue();
  21630. return concat$12([node.attributes.length ? " " : "", indent$9(join$9(line$8, path$$1.map(print, "attributes")))]);
  21631. }
  21632. function printChildren$1(path$$1, print) {
  21633. var children = [];
  21634. path$$1.each(function (childPath) {
  21635. var child = childPath.getValue();
  21636. if (child.type !== "text") {
  21637. children.push(hardline$11);
  21638. }
  21639. children.push(childPath.call(print));
  21640. }, "children");
  21641. return concat$12(children);
  21642. }
  21643. var printerHtmlparser2 = {
  21644. print: genericPrint$6,
  21645. massageAstNode: clean$8,
  21646. embed: embed_1$4,
  21647. hasPrettierIgnore: hasIgnoreComment$4
  21648. };
  21649. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  21650. var languages$5 = [{
  21651. name: "HTML",
  21652. since: null,
  21653. // unreleased
  21654. parsers: ["parse5"],
  21655. group: "HTML",
  21656. tmScope: "text.html.basic",
  21657. aceMode: "html",
  21658. codemirrorMode: "htmlmixed",
  21659. codemirrorMimeType: "text/html",
  21660. aliases: ["xhtml"],
  21661. extensions: [".html", ".htm", ".html.hl", ".inc", ".st", ".xht", ".xhtml"],
  21662. linguistLanguageId: 146,
  21663. vscodeLanguageIds: ["html"]
  21664. }];
  21665. var printers$5 = {
  21666. htmlparser2: printerHtmlparser2
  21667. };
  21668. var languageHtml = {
  21669. languages: languages$5,
  21670. printers: printers$5
  21671. };
  21672. var _require$$0$builders$8 = doc.builders;
  21673. var concat$15 = _require$$0$builders$8.concat;
  21674. var hardline$14 = _require$$0$builders$8.hardline;
  21675. function embed$6(path$$1, print, textToDoc, options) {
  21676. var node = path$$1.getValue();
  21677. var parent = path$$1.getParentNode();
  21678. if (!parent || parent.tag !== "root" || node.unary) {
  21679. return null;
  21680. }
  21681. var parser;
  21682. if (node.tag === "style") {
  21683. var langAttr = node.attrs.find(function (attr) {
  21684. return attr.name === "lang";
  21685. });
  21686. if (!langAttr || langAttr.value === "postcss") {
  21687. parser = "css";
  21688. } else if (langAttr.value === "scss") {
  21689. parser = "scss";
  21690. } else if (langAttr.value === "less") {
  21691. parser = "less";
  21692. }
  21693. }
  21694. if (node.tag === "script") {
  21695. var _langAttr = node.attrs.find(function (attr) {
  21696. return attr.name === "lang";
  21697. });
  21698. if (!_langAttr) {
  21699. parser = "babylon";
  21700. } else if (_langAttr.value === "ts" || _langAttr.value === "tsx") {
  21701. parser = "typescript";
  21702. }
  21703. }
  21704. if (!parser) {
  21705. return null;
  21706. }
  21707. return concat$15([options.originalText.slice(node.start, node.contentStart), hardline$14, textToDoc(options.originalText.slice(node.contentStart, node.contentEnd), {
  21708. parser
  21709. }), options.originalText.slice(node.contentEnd, node.end)]);
  21710. }
  21711. var embed_1$6 = embed$6;
  21712. var _require$$0$builders$7 = doc.builders;
  21713. var concat$14 = _require$$0$builders$7.concat;
  21714. var hardline$13 = _require$$0$builders$7.hardline;
  21715. function genericPrint$7(path$$1, options, print) {
  21716. var n = path$$1.getValue();
  21717. var res = [];
  21718. var index = n.start;
  21719. path$$1.each(function (childPath) {
  21720. var child = childPath.getValue();
  21721. res.push(options.originalText.slice(index, child.start));
  21722. res.push(childPath.call(print));
  21723. index = child.end;
  21724. }, "children"); // If there are no children, we just print the node from start to end.
  21725. // Otherwise, index should point to the end of the last child, and we
  21726. // need to print the closing tag.
  21727. res.push(options.originalText.slice(index, n.end)); // Only force a trailing newline if there were any contents.
  21728. if (n.tag === "root" && n.children.length) {
  21729. res.push(hardline$13);
  21730. }
  21731. return concat$14(res);
  21732. }
  21733. var clean$11 = function clean(ast, newObj) {
  21734. delete newObj.start;
  21735. delete newObj.end;
  21736. delete newObj.contentStart;
  21737. delete newObj.contentEnd;
  21738. };
  21739. var printerVue = {
  21740. print: genericPrint$7,
  21741. embed: embed_1$6,
  21742. massageAstNode: clean$11
  21743. };
  21744. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  21745. var languages$6 = [{
  21746. name: "Vue",
  21747. since: "1.10.0",
  21748. parsers: ["vue"],
  21749. group: "HTML",
  21750. tmScope: "text.html.vue",
  21751. aceMode: "html",
  21752. codemirrorMode: "htmlmixed",
  21753. codemirrorMimeType: "text/html",
  21754. extensions: [".vue"],
  21755. linguistLanguageId: 146,
  21756. vscodeLanguageIds: ["vue"]
  21757. }];
  21758. var printers$6 = {
  21759. vue: printerVue
  21760. };
  21761. var languageVue = {
  21762. languages: languages$6,
  21763. printers: printers$6
  21764. };
  21765. // plugin will look for `eval("require")()` and transform to `require()` in the bundle,
  21766. // and rewrite the paths to require from the top-level.
  21767. // We need to list the parsers and getters so we can load them only when necessary.
  21768. var internalPlugins = [// JS
  21769. languageJs, {
  21770. parsers: {
  21771. // JS - Babylon
  21772. get babylon() {
  21773. return require("./parser-babylon").parsers.babylon;
  21774. },
  21775. get json() {
  21776. return require("./parser-babylon").parsers.json;
  21777. },
  21778. get json5() {
  21779. return require("./parser-babylon").parsers.json5;
  21780. },
  21781. get "json-stringify"() {
  21782. return require("./parser-babylon").parsers["json-stringify"];
  21783. },
  21784. // JS - Flow
  21785. get flow() {
  21786. return require("./parser-flow").parsers.flow;
  21787. },
  21788. // JS - TypeScript
  21789. get typescript() {
  21790. return require("./parser-typescript").parsers.typescript;
  21791. },
  21792. get "typescript-eslint"() {
  21793. return require("./parser-typescript").parsers["typescript-eslint"];
  21794. }
  21795. }
  21796. }, // CSS
  21797. languageCss, {
  21798. parsers: {
  21799. // TODO: switch these to just `postcss` and use `language` instead.
  21800. get css() {
  21801. return require("./parser-postcss").parsers.css;
  21802. },
  21803. get less() {
  21804. return require("./parser-postcss").parsers.css;
  21805. },
  21806. get scss() {
  21807. return require("./parser-postcss").parsers.css;
  21808. }
  21809. }
  21810. }, // Handlebars
  21811. languageHandlebars, {
  21812. parsers: {
  21813. get glimmer() {
  21814. return require("./parser-glimmer").parsers.glimmer;
  21815. }
  21816. }
  21817. }, // GraphQL
  21818. languageGraphql, {
  21819. parsers: {
  21820. get graphql() {
  21821. return require("./parser-graphql").parsers.graphql;
  21822. }
  21823. }
  21824. }, // Markdown
  21825. languageMarkdown, {
  21826. parsers: {
  21827. get remark() {
  21828. return require("./parser-markdown").parsers.remark;
  21829. },
  21830. // TODO: Delete this in 2.0
  21831. get markdown() {
  21832. return require("./parser-markdown").parsers.remark;
  21833. }
  21834. }
  21835. }, // HTML
  21836. languageHtml, {
  21837. parsers: {
  21838. get parse5() {
  21839. return require("./parser-parse5").parsers.parse5;
  21840. }
  21841. }
  21842. }, // Vue
  21843. languageVue, {
  21844. parsers: {
  21845. get vue() {
  21846. return require("./parser-vue").parsers.vue;
  21847. }
  21848. }
  21849. }];
  21850. var thirdParty$1 = ( thirdParty && thirdParty__default ) || thirdParty;
  21851. function loadPlugins(plugins, pluginSearchDirs) {
  21852. if (!plugins) {
  21853. plugins = [];
  21854. }
  21855. if (!pluginSearchDirs) {
  21856. pluginSearchDirs = [];
  21857. } // unless pluginSearchDirs are provided, auto-load plugins from node_modules that are parent to Prettier
  21858. if (!pluginSearchDirs.length) {
  21859. var autoLoadDir = thirdParty$1.findParentDir(thirdParty$1.findParentDir(__dirname, "prettier"), "node_modules");
  21860. if (autoLoadDir) {
  21861. pluginSearchDirs = [autoLoadDir];
  21862. }
  21863. }
  21864. var externalManualLoadPluginInfos = plugins.map(function (pluginName) {
  21865. var requirePath;
  21866. try {
  21867. // try local files
  21868. requirePath = resolve$1.sync(path.resolve(process.cwd(), pluginName));
  21869. } catch (e) {
  21870. // try node modules
  21871. requirePath = resolve$1.sync(pluginName, {
  21872. basedir: process.cwd()
  21873. });
  21874. }
  21875. return {
  21876. name: pluginName,
  21877. requirePath
  21878. };
  21879. });
  21880. var externalAutoLoadPluginInfos = pluginSearchDirs.map(function (pluginSearchDir) {
  21881. var resolvedPluginSearchDir = path.resolve(process.cwd(), pluginSearchDir);
  21882. if (!isDirectory(resolvedPluginSearchDir)) {
  21883. throw new Error(`${pluginSearchDir} does not exist or is not a directory`);
  21884. }
  21885. var nodeModulesDir = path.resolve(resolvedPluginSearchDir, "node_modules");
  21886. return findPluginsInNodeModules(nodeModulesDir).map(function (pluginName) {
  21887. return {
  21888. name: pluginName,
  21889. requirePath: resolve$1.sync(pluginName, {
  21890. basedir: resolvedPluginSearchDir
  21891. })
  21892. };
  21893. });
  21894. }).reduce(function (a, b) {
  21895. return a.concat(b);
  21896. }, []);
  21897. var externalPlugins = lodash_uniqby(externalManualLoadPluginInfos.concat(externalAutoLoadPluginInfos), "requirePath").map(function (externalPluginInfo) {
  21898. return Object.assign({
  21899. name: externalPluginInfo.name
  21900. }, require(externalPluginInfo.requirePath));
  21901. });
  21902. return internalPlugins.concat(externalPlugins);
  21903. }
  21904. function findPluginsInNodeModules(nodeModulesDir) {
  21905. var pluginPackageJsonPaths = globby.sync(["prettier-plugin-*/package.json", "@prettier/plugin-*/package.json"], {
  21906. cwd: nodeModulesDir
  21907. });
  21908. return pluginPackageJsonPaths.map(path.dirname);
  21909. }
  21910. function isDirectory(dir) {
  21911. try {
  21912. return fs.statSync(dir).isDirectory();
  21913. } catch (e) {
  21914. return false;
  21915. }
  21916. }
  21917. var loadPlugins_1 = loadPlugins;
  21918. var mimicFn = function mimicFn(to, from) {
  21919. // TODO: use `Reflect.ownKeys()` when targeting Node.js 6
  21920. var _iteratorNormalCompletion = true;
  21921. var _didIteratorError = false;
  21922. var _iteratorError = undefined;
  21923. try {
  21924. for (var _iterator = Object.getOwnPropertyNames(from).concat(Object.getOwnPropertySymbols(from))[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  21925. var prop = _step.value;
  21926. Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
  21927. }
  21928. } catch (err) {
  21929. _didIteratorError = true;
  21930. _iteratorError = err;
  21931. } finally {
  21932. try {
  21933. if (!_iteratorNormalCompletion && _iterator.return != null) {
  21934. _iterator.return();
  21935. }
  21936. } finally {
  21937. if (_didIteratorError) {
  21938. throw _iteratorError;
  21939. }
  21940. }
  21941. }
  21942. };
  21943. var mem = createCommonjsModule(function (module) {
  21944. 'use strict';
  21945. var cacheStore = new WeakMap();
  21946. var defaultCacheKey = function defaultCacheKey(x) {
  21947. if (arguments.length === 1 && (x === null || x === undefined || typeof x !== 'function' && typeof x !== 'object')) {
  21948. return x;
  21949. }
  21950. return JSON.stringify(arguments);
  21951. };
  21952. module.exports = function (fn, opts) {
  21953. opts = Object.assign({
  21954. cacheKey: defaultCacheKey,
  21955. cache: new Map()
  21956. }, opts);
  21957. var memoized = function memoized() {
  21958. var cache = cacheStore.get(memoized);
  21959. var key = opts.cacheKey.apply(null, arguments);
  21960. if (cache.has(key)) {
  21961. var c = cache.get(key);
  21962. if (typeof opts.maxAge !== 'number' || Date.now() < c.maxAge) {
  21963. return c.data;
  21964. }
  21965. }
  21966. var ret = fn.apply(null, arguments);
  21967. cache.set(key, {
  21968. data: ret,
  21969. maxAge: Date.now() + (opts.maxAge || 0)
  21970. });
  21971. return ret;
  21972. };
  21973. mimicFn(memoized, fn);
  21974. cacheStore.set(memoized, opts.cache);
  21975. return memoized;
  21976. };
  21977. module.exports.clear = function (fn) {
  21978. var cache = cacheStore.get(fn);
  21979. if (cache && typeof cache.clear === 'function') {
  21980. cache.clear();
  21981. }
  21982. };
  21983. });
  21984. var semver$3 = createCommonjsModule(function (module, exports) {
  21985. exports = module.exports = SemVer; // The debug function is excluded entirely from the minified version.
  21986. /* nomin */
  21987. var debug;
  21988. /* nomin */
  21989. if (typeof process === 'object' &&
  21990. /* nomin */
  21991. process.env &&
  21992. /* nomin */
  21993. process.env.NODE_DEBUG &&
  21994. /* nomin */
  21995. /\bsemver\b/i.test(process.env.NODE_DEBUG))
  21996. /* nomin */
  21997. debug = function debug() {
  21998. /* nomin */
  21999. var args = Array.prototype.slice.call(arguments, 0);
  22000. /* nomin */
  22001. args.unshift('SEMVER');
  22002. /* nomin */
  22003. console.log.apply(console, args);
  22004. /* nomin */
  22005. };
  22006. /* nomin */
  22007. else
  22008. /* nomin */
  22009. debug = function debug() {}; // Note: this is the semver.org version of the spec that it implements
  22010. // Not necessarily the package version of this code.
  22011. exports.SEMVER_SPEC_VERSION = '2.0.0';
  22012. var MAX_LENGTH = 256;
  22013. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // Max safe segment length for coercion.
  22014. var MAX_SAFE_COMPONENT_LENGTH = 16; // The actual regexps go on exports.re
  22015. var re = exports.re = [];
  22016. var src = exports.src = [];
  22017. var R = 0; // The following Regular Expressions can be used for tokenizing,
  22018. // validating, and parsing SemVer version strings.
  22019. // ## Numeric Identifier
  22020. // A single `0`, or a non-zero digit followed by zero or more digits.
  22021. var NUMERICIDENTIFIER = R++;
  22022. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  22023. var NUMERICIDENTIFIERLOOSE = R++;
  22024. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
  22025. // Zero or more digits, followed by a letter or hyphen, and then zero or
  22026. // more letters, digits, or hyphens.
  22027. var NONNUMERICIDENTIFIER = R++;
  22028. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
  22029. // Three dot-separated numeric identifiers.
  22030. var MAINVERSION = R++;
  22031. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')';
  22032. var MAINVERSIONLOOSE = R++;
  22033. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
  22034. // A numeric identifier, or a non-numeric identifier.
  22035. var PRERELEASEIDENTIFIER = R++;
  22036. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + '|' + src[NONNUMERICIDENTIFIER] + ')';
  22037. var PRERELEASEIDENTIFIERLOOSE = R++;
  22038. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + '|' + src[NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
  22039. // Hyphen, followed by one or more dot-separated pre-release version
  22040. // identifiers.
  22041. var PRERELEASE = R++;
  22042. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  22043. var PRERELEASELOOSE = R++;
  22044. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
  22045. // Any combination of digits, letters, or hyphens.
  22046. var BUILDIDENTIFIER = R++;
  22047. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
  22048. // Plus sign, followed by one or more period-separated build metadata
  22049. // identifiers.
  22050. var BUILD = R++;
  22051. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'; // ## Full Version String
  22052. // A main version, followed optionally by a pre-release version and
  22053. // build metadata.
  22054. // Note that the only major, minor, patch, and pre-release sections of
  22055. // the version string are capturing groups. The build metadata is not a
  22056. // capturing group, because it should not ever be used in version
  22057. // comparison.
  22058. var FULL = R++;
  22059. var FULLPLAIN = 'v?' + src[MAINVERSION] + src[PRERELEASE] + '?' + src[BUILD] + '?';
  22060. src[FULL] = '^' + FULLPLAIN + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  22061. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  22062. // common in the npm registry.
  22063. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + src[PRERELEASELOOSE] + '?' + src[BUILD] + '?';
  22064. var LOOSE = R++;
  22065. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  22066. var GTLT = R++;
  22067. src[GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
  22068. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  22069. // Only the first item is strictly required.
  22070. var XRANGEIDENTIFIERLOOSE = R++;
  22071. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  22072. var XRANGEIDENTIFIER = R++;
  22073. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  22074. var XRANGEPLAIN = R++;
  22075. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:' + src[PRERELEASE] + ')?' + src[BUILD] + '?' + ')?)?';
  22076. var XRANGEPLAINLOOSE = R++;
  22077. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[PRERELEASELOOSE] + ')?' + src[BUILD] + '?' + ')?)?';
  22078. var XRANGE = R++;
  22079. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  22080. var XRANGELOOSE = R++;
  22081. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'; // Coercion.
  22082. // Extract anything that could conceivably be a part of a valid semver
  22083. var COERCE = R++;
  22084. src[COERCE] = '(?:^|[^\\d])' + '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:$|[^\\d])'; // Tilde ranges.
  22085. // Meaning is "reasonably at or greater than"
  22086. var LONETILDE = R++;
  22087. src[LONETILDE] = '(?:~>?)';
  22088. var TILDETRIM = R++;
  22089. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  22090. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  22091. var tildeTrimReplace = '$1~';
  22092. var TILDE = R++;
  22093. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  22094. var TILDELOOSE = R++;
  22095. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'; // Caret ranges.
  22096. // Meaning is "at least and backwards compatible with"
  22097. var LONECARET = R++;
  22098. src[LONECARET] = '(?:\\^)';
  22099. var CARETTRIM = R++;
  22100. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  22101. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  22102. var caretTrimReplace = '$1^';
  22103. var CARET = R++;
  22104. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  22105. var CARETLOOSE = R++;
  22106. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
  22107. var COMPARATORLOOSE = R++;
  22108. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  22109. var COMPARATOR = R++;
  22110. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
  22111. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  22112. var COMPARATORTRIM = R++;
  22113. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'; // this one has to use the /g flag
  22114. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  22115. var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  22116. // Note that these all use the loose form, because they'll be
  22117. // checked against either the strict or loose comparator form
  22118. // later.
  22119. var HYPHENRANGE = R++;
  22120. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAIN] + ')' + '\\s*$';
  22121. var HYPHENRANGELOOSE = R++;
  22122. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
  22123. var STAR = R++;
  22124. src[STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
  22125. // All are flag-free, unless they were created above with a flag.
  22126. for (var i = 0; i < R; i++) {
  22127. debug(i, src[i]);
  22128. if (!re[i]) re[i] = new RegExp(src[i]);
  22129. }
  22130. exports.parse = parse;
  22131. function parse(version, loose) {
  22132. if (version instanceof SemVer) return version;
  22133. if (typeof version !== 'string') return null;
  22134. if (version.length > MAX_LENGTH) return null;
  22135. var r = loose ? re[LOOSE] : re[FULL];
  22136. if (!r.test(version)) return null;
  22137. try {
  22138. return new SemVer(version, loose);
  22139. } catch (er) {
  22140. return null;
  22141. }
  22142. }
  22143. exports.valid = valid;
  22144. function valid(version, loose) {
  22145. var v = parse(version, loose);
  22146. return v ? v.version : null;
  22147. }
  22148. exports.clean = clean;
  22149. function clean(version, loose) {
  22150. var s = parse(version.trim().replace(/^[=v]+/, ''), loose);
  22151. return s ? s.version : null;
  22152. }
  22153. exports.SemVer = SemVer;
  22154. function SemVer(version, loose) {
  22155. if (version instanceof SemVer) {
  22156. if (version.loose === loose) return version;else version = version.version;
  22157. } else if (typeof version !== 'string') {
  22158. throw new TypeError('Invalid Version: ' + version);
  22159. }
  22160. if (version.length > MAX_LENGTH) throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
  22161. if (!(this instanceof SemVer)) return new SemVer(version, loose);
  22162. debug('SemVer', version, loose);
  22163. this.loose = loose;
  22164. var m = version.trim().match(loose ? re[LOOSE] : re[FULL]);
  22165. if (!m) throw new TypeError('Invalid Version: ' + version);
  22166. this.raw = version; // these are actually numbers
  22167. this.major = +m[1];
  22168. this.minor = +m[2];
  22169. this.patch = +m[3];
  22170. if (this.major > MAX_SAFE_INTEGER || this.major < 0) throw new TypeError('Invalid major version');
  22171. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) throw new TypeError('Invalid minor version');
  22172. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) throw new TypeError('Invalid patch version'); // numberify any prerelease numeric ids
  22173. if (!m[4]) this.prerelease = [];else this.prerelease = m[4].split('.').map(function (id) {
  22174. if (/^[0-9]+$/.test(id)) {
  22175. var num = +id;
  22176. if (num >= 0 && num < MAX_SAFE_INTEGER) return num;
  22177. }
  22178. return id;
  22179. });
  22180. this.build = m[5] ? m[5].split('.') : [];
  22181. this.format();
  22182. }
  22183. SemVer.prototype.format = function () {
  22184. this.version = this.major + '.' + this.minor + '.' + this.patch;
  22185. if (this.prerelease.length) this.version += '-' + this.prerelease.join('.');
  22186. return this.version;
  22187. };
  22188. SemVer.prototype.toString = function () {
  22189. return this.version;
  22190. };
  22191. SemVer.prototype.compare = function (other) {
  22192. debug('SemVer.compare', this.version, this.loose, other);
  22193. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose);
  22194. return this.compareMain(other) || this.comparePre(other);
  22195. };
  22196. SemVer.prototype.compareMain = function (other) {
  22197. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose);
  22198. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  22199. };
  22200. SemVer.prototype.comparePre = function (other) {
  22201. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose); // NOT having a prerelease is > having one
  22202. 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;
  22203. var i = 0;
  22204. do {
  22205. var a = this.prerelease[i];
  22206. var b = other.prerelease[i];
  22207. debug('prerelease compare', i, a, b);
  22208. 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);
  22209. } while (++i);
  22210. }; // preminor will bump the version up to the next minor release, and immediately
  22211. // down to pre-release. premajor and prepatch work the same way.
  22212. SemVer.prototype.inc = function (release, identifier) {
  22213. switch (release) {
  22214. case 'premajor':
  22215. this.prerelease.length = 0;
  22216. this.patch = 0;
  22217. this.minor = 0;
  22218. this.major++;
  22219. this.inc('pre', identifier);
  22220. break;
  22221. case 'preminor':
  22222. this.prerelease.length = 0;
  22223. this.patch = 0;
  22224. this.minor++;
  22225. this.inc('pre', identifier);
  22226. break;
  22227. case 'prepatch':
  22228. // If this is already a prerelease, it will bump to the next version
  22229. // drop any prereleases that might already exist, since they are not
  22230. // relevant at this point.
  22231. this.prerelease.length = 0;
  22232. this.inc('patch', identifier);
  22233. this.inc('pre', identifier);
  22234. break;
  22235. // If the input is a non-prerelease version, this acts the same as
  22236. // prepatch.
  22237. case 'prerelease':
  22238. if (this.prerelease.length === 0) this.inc('patch', identifier);
  22239. this.inc('pre', identifier);
  22240. break;
  22241. case 'major':
  22242. // If this is a pre-major version, bump up to the same major version.
  22243. // Otherwise increment major.
  22244. // 1.0.0-5 bumps to 1.0.0
  22245. // 1.1.0 bumps to 2.0.0
  22246. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) this.major++;
  22247. this.minor = 0;
  22248. this.patch = 0;
  22249. this.prerelease = [];
  22250. break;
  22251. case 'minor':
  22252. // If this is a pre-minor version, bump up to the same minor version.
  22253. // Otherwise increment minor.
  22254. // 1.2.0-5 bumps to 1.2.0
  22255. // 1.2.1 bumps to 1.3.0
  22256. if (this.patch !== 0 || this.prerelease.length === 0) this.minor++;
  22257. this.patch = 0;
  22258. this.prerelease = [];
  22259. break;
  22260. case 'patch':
  22261. // If this is not a pre-release version, it will increment the patch.
  22262. // If it is a pre-release it will bump up to the same patch version.
  22263. // 1.2.0-5 patches to 1.2.0
  22264. // 1.2.0 patches to 1.2.1
  22265. if (this.prerelease.length === 0) this.patch++;
  22266. this.prerelease = [];
  22267. break;
  22268. // This probably shouldn't be used publicly.
  22269. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  22270. case 'pre':
  22271. if (this.prerelease.length === 0) this.prerelease = [0];else {
  22272. var i = this.prerelease.length;
  22273. while (--i >= 0) {
  22274. if (typeof this.prerelease[i] === 'number') {
  22275. this.prerelease[i]++;
  22276. i = -2;
  22277. }
  22278. }
  22279. if (i === -1) // didn't increment anything
  22280. this.prerelease.push(0);
  22281. }
  22282. if (identifier) {
  22283. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  22284. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  22285. if (this.prerelease[0] === identifier) {
  22286. if (isNaN(this.prerelease[1])) this.prerelease = [identifier, 0];
  22287. } else this.prerelease = [identifier, 0];
  22288. }
  22289. break;
  22290. default:
  22291. throw new Error('invalid increment argument: ' + release);
  22292. }
  22293. this.format();
  22294. this.raw = this.version;
  22295. return this;
  22296. };
  22297. exports.inc = inc;
  22298. function inc(version, release, loose, identifier) {
  22299. if (typeof loose === 'string') {
  22300. identifier = loose;
  22301. loose = undefined;
  22302. }
  22303. try {
  22304. return new SemVer(version, loose).inc(release, identifier).version;
  22305. } catch (er) {
  22306. return null;
  22307. }
  22308. }
  22309. exports.diff = diff;
  22310. function diff(version1, version2) {
  22311. if (eq(version1, version2)) {
  22312. return null;
  22313. } else {
  22314. var v1 = parse(version1);
  22315. var v2 = parse(version2);
  22316. if (v1.prerelease.length || v2.prerelease.length) {
  22317. for (var key in v1) {
  22318. if (key === 'major' || key === 'minor' || key === 'patch') {
  22319. if (v1[key] !== v2[key]) {
  22320. return 'pre' + key;
  22321. }
  22322. }
  22323. }
  22324. return 'prerelease';
  22325. }
  22326. for (var key in v1) {
  22327. if (key === 'major' || key === 'minor' || key === 'patch') {
  22328. if (v1[key] !== v2[key]) {
  22329. return key;
  22330. }
  22331. }
  22332. }
  22333. }
  22334. }
  22335. exports.compareIdentifiers = compareIdentifiers;
  22336. var numeric = /^[0-9]+$/;
  22337. function compareIdentifiers(a, b) {
  22338. var anum = numeric.test(a);
  22339. var bnum = numeric.test(b);
  22340. if (anum && bnum) {
  22341. a = +a;
  22342. b = +b;
  22343. }
  22344. return anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : a > b ? 1 : 0;
  22345. }
  22346. exports.rcompareIdentifiers = rcompareIdentifiers;
  22347. function rcompareIdentifiers(a, b) {
  22348. return compareIdentifiers(b, a);
  22349. }
  22350. exports.major = major;
  22351. function major(a, loose) {
  22352. return new SemVer(a, loose).major;
  22353. }
  22354. exports.minor = minor;
  22355. function minor(a, loose) {
  22356. return new SemVer(a, loose).minor;
  22357. }
  22358. exports.patch = patch;
  22359. function patch(a, loose) {
  22360. return new SemVer(a, loose).patch;
  22361. }
  22362. exports.compare = compare;
  22363. function compare(a, b, loose) {
  22364. return new SemVer(a, loose).compare(new SemVer(b, loose));
  22365. }
  22366. exports.compareLoose = compareLoose;
  22367. function compareLoose(a, b) {
  22368. return compare(a, b, true);
  22369. }
  22370. exports.rcompare = rcompare;
  22371. function rcompare(a, b, loose) {
  22372. return compare(b, a, loose);
  22373. }
  22374. exports.sort = sort;
  22375. function sort(list, loose) {
  22376. return list.sort(function (a, b) {
  22377. return exports.compare(a, b, loose);
  22378. });
  22379. }
  22380. exports.rsort = rsort;
  22381. function rsort(list, loose) {
  22382. return list.sort(function (a, b) {
  22383. return exports.rcompare(a, b, loose);
  22384. });
  22385. }
  22386. exports.gt = gt;
  22387. function gt(a, b, loose) {
  22388. return compare(a, b, loose) > 0;
  22389. }
  22390. exports.lt = lt;
  22391. function lt(a, b, loose) {
  22392. return compare(a, b, loose) < 0;
  22393. }
  22394. exports.eq = eq;
  22395. function eq(a, b, loose) {
  22396. return compare(a, b, loose) === 0;
  22397. }
  22398. exports.neq = neq;
  22399. function neq(a, b, loose) {
  22400. return compare(a, b, loose) !== 0;
  22401. }
  22402. exports.gte = gte;
  22403. function gte(a, b, loose) {
  22404. return compare(a, b, loose) >= 0;
  22405. }
  22406. exports.lte = lte;
  22407. function lte(a, b, loose) {
  22408. return compare(a, b, loose) <= 0;
  22409. }
  22410. exports.cmp = cmp;
  22411. function cmp(a, op, b, loose) {
  22412. var ret;
  22413. switch (op) {
  22414. case '===':
  22415. if (typeof a === 'object') a = a.version;
  22416. if (typeof b === 'object') b = b.version;
  22417. ret = a === b;
  22418. break;
  22419. case '!==':
  22420. if (typeof a === 'object') a = a.version;
  22421. if (typeof b === 'object') b = b.version;
  22422. ret = a !== b;
  22423. break;
  22424. case '':
  22425. case '=':
  22426. case '==':
  22427. ret = eq(a, b, loose);
  22428. break;
  22429. case '!=':
  22430. ret = neq(a, b, loose);
  22431. break;
  22432. case '>':
  22433. ret = gt(a, b, loose);
  22434. break;
  22435. case '>=':
  22436. ret = gte(a, b, loose);
  22437. break;
  22438. case '<':
  22439. ret = lt(a, b, loose);
  22440. break;
  22441. case '<=':
  22442. ret = lte(a, b, loose);
  22443. break;
  22444. default:
  22445. throw new TypeError('Invalid operator: ' + op);
  22446. }
  22447. return ret;
  22448. }
  22449. exports.Comparator = Comparator;
  22450. function Comparator(comp, loose) {
  22451. if (comp instanceof Comparator) {
  22452. if (comp.loose === loose) return comp;else comp = comp.value;
  22453. }
  22454. if (!(this instanceof Comparator)) return new Comparator(comp, loose);
  22455. debug('comparator', comp, loose);
  22456. this.loose = loose;
  22457. this.parse(comp);
  22458. if (this.semver === ANY) this.value = '';else this.value = this.operator + this.semver.version;
  22459. debug('comp', this);
  22460. }
  22461. var ANY = {};
  22462. Comparator.prototype.parse = function (comp) {
  22463. var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  22464. var m = comp.match(r);
  22465. if (!m) throw new TypeError('Invalid comparator: ' + comp);
  22466. this.operator = m[1];
  22467. if (this.operator === '=') this.operator = ''; // if it literally is just '>' or '' then allow anything.
  22468. if (!m[2]) this.semver = ANY;else this.semver = new SemVer(m[2], this.loose);
  22469. };
  22470. Comparator.prototype.toString = function () {
  22471. return this.value;
  22472. };
  22473. Comparator.prototype.test = function (version) {
  22474. debug('Comparator.test', version, this.loose);
  22475. if (this.semver === ANY) return true;
  22476. if (typeof version === 'string') version = new SemVer(version, this.loose);
  22477. return cmp(version, this.operator, this.semver, this.loose);
  22478. };
  22479. Comparator.prototype.intersects = function (comp, loose) {
  22480. if (!(comp instanceof Comparator)) {
  22481. throw new TypeError('a Comparator is required');
  22482. }
  22483. var rangeTmp;
  22484. if (this.operator === '') {
  22485. rangeTmp = new Range(comp.value, loose);
  22486. return satisfies(this.value, rangeTmp, loose);
  22487. } else if (comp.operator === '') {
  22488. rangeTmp = new Range(this.value, loose);
  22489. return satisfies(comp.semver, rangeTmp, loose);
  22490. }
  22491. var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
  22492. var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
  22493. var sameSemVer = this.semver.version === comp.semver.version;
  22494. var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
  22495. var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, loose) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
  22496. var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, loose) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
  22497. return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  22498. };
  22499. exports.Range = Range;
  22500. function Range(range, loose) {
  22501. if (range instanceof Range) {
  22502. if (range.loose === loose) {
  22503. return range;
  22504. } else {
  22505. return new Range(range.raw, loose);
  22506. }
  22507. }
  22508. if (range instanceof Comparator) {
  22509. return new Range(range.value, loose);
  22510. }
  22511. if (!(this instanceof Range)) return new Range(range, loose);
  22512. this.loose = loose; // First, split based on boolean or ||
  22513. this.raw = range;
  22514. this.set = range.split(/\s*\|\|\s*/).map(function (range) {
  22515. return this.parseRange(range.trim());
  22516. }, this).filter(function (c) {
  22517. // throw out any that are not relevant for whatever reason
  22518. return c.length;
  22519. });
  22520. if (!this.set.length) {
  22521. throw new TypeError('Invalid SemVer Range: ' + range);
  22522. }
  22523. this.format();
  22524. }
  22525. Range.prototype.format = function () {
  22526. this.range = this.set.map(function (comps) {
  22527. return comps.join(' ').trim();
  22528. }).join('||').trim();
  22529. return this.range;
  22530. };
  22531. Range.prototype.toString = function () {
  22532. return this.range;
  22533. };
  22534. Range.prototype.parseRange = function (range) {
  22535. var loose = this.loose;
  22536. range = range.trim();
  22537. debug('range', range, loose); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  22538. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  22539. range = range.replace(hr, hyphenReplace);
  22540. debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  22541. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  22542. debug('comparator trim', range, re[COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
  22543. range = range.replace(re[TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
  22544. range = range.replace(re[CARETTRIM], caretTrimReplace); // normalize spaces
  22545. range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
  22546. // ready to be split into comparators.
  22547. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  22548. var set = range.split(' ').map(function (comp) {
  22549. return parseComparator(comp, loose);
  22550. }).join(' ').split(/\s+/);
  22551. if (this.loose) {
  22552. // in loose mode, throw out any that are not valid comparators
  22553. set = set.filter(function (comp) {
  22554. return !!comp.match(compRe);
  22555. });
  22556. }
  22557. set = set.map(function (comp) {
  22558. return new Comparator(comp, loose);
  22559. });
  22560. return set;
  22561. };
  22562. Range.prototype.intersects = function (range, loose) {
  22563. if (!(range instanceof Range)) {
  22564. throw new TypeError('a Range is required');
  22565. }
  22566. return this.set.some(function (thisComparators) {
  22567. return thisComparators.every(function (thisComparator) {
  22568. return range.set.some(function (rangeComparators) {
  22569. return rangeComparators.every(function (rangeComparator) {
  22570. return thisComparator.intersects(rangeComparator, loose);
  22571. });
  22572. });
  22573. });
  22574. });
  22575. }; // Mostly just for testing and legacy API reasons
  22576. exports.toComparators = toComparators;
  22577. function toComparators(range, loose) {
  22578. return new Range(range, loose).set.map(function (comp) {
  22579. return comp.map(function (c) {
  22580. return c.value;
  22581. }).join(' ').trim().split(' ');
  22582. });
  22583. } // comprised of xranges, tildes, stars, and gtlt's at this point.
  22584. // already replaced the hyphen ranges
  22585. // turn into a set of JUST comparators.
  22586. function parseComparator(comp, loose) {
  22587. debug('comp', comp);
  22588. comp = replaceCarets(comp, loose);
  22589. debug('caret', comp);
  22590. comp = replaceTildes(comp, loose);
  22591. debug('tildes', comp);
  22592. comp = replaceXRanges(comp, loose);
  22593. debug('xrange', comp);
  22594. comp = replaceStars(comp, loose);
  22595. debug('stars', comp);
  22596. return comp;
  22597. }
  22598. function isX(id) {
  22599. return !id || id.toLowerCase() === 'x' || id === '*';
  22600. } // ~, ~> --> * (any, kinda silly)
  22601. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  22602. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  22603. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  22604. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  22605. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  22606. function replaceTildes(comp, loose) {
  22607. return comp.trim().split(/\s+/).map(function (comp) {
  22608. return replaceTilde(comp, loose);
  22609. }).join(' ');
  22610. }
  22611. function replaceTilde(comp, loose) {
  22612. var r = loose ? re[TILDELOOSE] : re[TILDE];
  22613. return comp.replace(r, function (_, M, m, p, pr) {
  22614. debug('tilde', comp, _, M, m, p, pr);
  22615. var ret;
  22616. 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
  22617. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else if (pr) {
  22618. debug('replaceTilde pr', pr);
  22619. if (pr.charAt(0) !== '-') pr = '-' + pr;
  22620. ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  22621. } else // ~1.2.3 == >=1.2.3 <1.3.0
  22622. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  22623. debug('tilde return', ret);
  22624. return ret;
  22625. });
  22626. } // ^ --> * (any, kinda silly)
  22627. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  22628. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  22629. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  22630. // ^1.2.3 --> >=1.2.3 <2.0.0
  22631. // ^1.2.0 --> >=1.2.0 <2.0.0
  22632. function replaceCarets(comp, loose) {
  22633. return comp.trim().split(/\s+/).map(function (comp) {
  22634. return replaceCaret(comp, loose);
  22635. }).join(' ');
  22636. }
  22637. function replaceCaret(comp, loose) {
  22638. debug('caret', comp, loose);
  22639. var r = loose ? re[CARETLOOSE] : re[CARET];
  22640. return comp.replace(r, function (_, M, m, p, pr) {
  22641. debug('caret', comp, _, M, m, p, pr);
  22642. var ret;
  22643. if (isX(M)) ret = '';else if (isX(m)) ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';else if (isX(p)) {
  22644. if (M === '0') ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  22645. } else if (pr) {
  22646. debug('replaceCaret pr', pr);
  22647. if (pr.charAt(0) !== '-') pr = '-' + pr;
  22648. if (M === '0') {
  22649. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  22650. } else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + (+M + 1) + '.0.0';
  22651. } else {
  22652. debug('no pr');
  22653. if (M === '0') {
  22654. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  22655. } else ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
  22656. }
  22657. debug('caret return', ret);
  22658. return ret;
  22659. });
  22660. }
  22661. function replaceXRanges(comp, loose) {
  22662. debug('replaceXRanges', comp, loose);
  22663. return comp.split(/\s+/).map(function (comp) {
  22664. return replaceXRange(comp, loose);
  22665. }).join(' ');
  22666. }
  22667. function replaceXRange(comp, loose) {
  22668. comp = comp.trim();
  22669. var r = loose ? re[XRANGELOOSE] : re[XRANGE];
  22670. return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
  22671. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  22672. var xM = isX(M);
  22673. var xm = xM || isX(m);
  22674. var xp = xm || isX(p);
  22675. var anyX = xp;
  22676. if (gtlt === '=' && anyX) gtlt = '';
  22677. if (xM) {
  22678. if (gtlt === '>' || gtlt === '<') {
  22679. // nothing is allowed
  22680. ret = '<0.0.0';
  22681. } else {
  22682. // nothing is forbidden
  22683. ret = '*';
  22684. }
  22685. } else if (gtlt && anyX) {
  22686. // replace X with 0
  22687. if (xm) m = 0;
  22688. if (xp) p = 0;
  22689. if (gtlt === '>') {
  22690. // >1 => >=2.0.0
  22691. // >1.2 => >=1.3.0
  22692. // >1.2.3 => >= 1.2.4
  22693. gtlt = '>=';
  22694. if (xm) {
  22695. M = +M + 1;
  22696. m = 0;
  22697. p = 0;
  22698. } else if (xp) {
  22699. m = +m + 1;
  22700. p = 0;
  22701. }
  22702. } else if (gtlt === '<=') {
  22703. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  22704. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  22705. gtlt = '<';
  22706. if (xm) M = +M + 1;else m = +m + 1;
  22707. }
  22708. ret = gtlt + M + '.' + m + '.' + p;
  22709. } else if (xm) {
  22710. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  22711. } else if (xp) {
  22712. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  22713. }
  22714. debug('xRange return', ret);
  22715. return ret;
  22716. });
  22717. } // Because * is AND-ed with everything else in the comparator,
  22718. // and '' means "any version", just remove the *s entirely.
  22719. function replaceStars(comp, loose) {
  22720. debug('replaceStars', comp, loose); // Looseness is ignored here. star is always as loose as it gets!
  22721. return comp.trim().replace(re[STAR], '');
  22722. } // This function is passed to string.replace(re[HYPHENRANGE])
  22723. // M, m, patch, prerelease, build
  22724. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  22725. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  22726. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  22727. function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
  22728. if (isX(fM)) from = '';else if (isX(fm)) from = '>=' + fM + '.0.0';else if (isX(fp)) from = '>=' + fM + '.' + fm + '.0';else from = '>=' + from;
  22729. 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;
  22730. return (from + ' ' + to).trim();
  22731. } // if ANY of the sets match ALL of its comparators, then pass
  22732. Range.prototype.test = function (version) {
  22733. if (!version) return false;
  22734. if (typeof version === 'string') version = new SemVer(version, this.loose);
  22735. for (var i = 0; i < this.set.length; i++) {
  22736. if (testSet(this.set[i], version)) return true;
  22737. }
  22738. return false;
  22739. };
  22740. function testSet(set, version) {
  22741. for (var i = 0; i < set.length; i++) {
  22742. if (!set[i].test(version)) return false;
  22743. }
  22744. if (version.prerelease.length) {
  22745. // Find the set of versions that are allowed to have prereleases
  22746. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  22747. // That should allow `1.2.3-pr.2` to pass.
  22748. // However, `1.2.4-alpha.notready` should NOT be allowed,
  22749. // even though it's within the range set by the comparators.
  22750. for (var i = 0; i < set.length; i++) {
  22751. debug(set[i].semver);
  22752. if (set[i].semver === ANY) continue;
  22753. if (set[i].semver.prerelease.length > 0) {
  22754. var allowed = set[i].semver;
  22755. if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) return true;
  22756. }
  22757. } // Version has a -pre, but it's not one of the ones we like.
  22758. return false;
  22759. }
  22760. return true;
  22761. }
  22762. exports.satisfies = satisfies;
  22763. function satisfies(version, range, loose) {
  22764. try {
  22765. range = new Range(range, loose);
  22766. } catch (er) {
  22767. return false;
  22768. }
  22769. return range.test(version);
  22770. }
  22771. exports.maxSatisfying = maxSatisfying;
  22772. function maxSatisfying(versions, range, loose) {
  22773. var max = null;
  22774. var maxSV = null;
  22775. try {
  22776. var rangeObj = new Range(range, loose);
  22777. } catch (er) {
  22778. return null;
  22779. }
  22780. versions.forEach(function (v) {
  22781. if (rangeObj.test(v)) {
  22782. // satisfies(v, range, loose)
  22783. if (!max || maxSV.compare(v) === -1) {
  22784. // compare(max, v, true)
  22785. max = v;
  22786. maxSV = new SemVer(max, loose);
  22787. }
  22788. }
  22789. });
  22790. return max;
  22791. }
  22792. exports.minSatisfying = minSatisfying;
  22793. function minSatisfying(versions, range, loose) {
  22794. var min = null;
  22795. var minSV = null;
  22796. try {
  22797. var rangeObj = new Range(range, loose);
  22798. } catch (er) {
  22799. return null;
  22800. }
  22801. versions.forEach(function (v) {
  22802. if (rangeObj.test(v)) {
  22803. // satisfies(v, range, loose)
  22804. if (!min || minSV.compare(v) === 1) {
  22805. // compare(min, v, true)
  22806. min = v;
  22807. minSV = new SemVer(min, loose);
  22808. }
  22809. }
  22810. });
  22811. return min;
  22812. }
  22813. exports.validRange = validRange;
  22814. function validRange(range, loose) {
  22815. try {
  22816. // Return '*' instead of '' so that truthiness works.
  22817. // This will throw if it's invalid anyway
  22818. return new Range(range, loose).range || '*';
  22819. } catch (er) {
  22820. return null;
  22821. }
  22822. } // Determine if version is less than all the versions possible in the range
  22823. exports.ltr = ltr;
  22824. function ltr(version, range, loose) {
  22825. return outside(version, range, '<', loose);
  22826. } // Determine if version is greater than all the versions possible in the range.
  22827. exports.gtr = gtr;
  22828. function gtr(version, range, loose) {
  22829. return outside(version, range, '>', loose);
  22830. }
  22831. exports.outside = outside;
  22832. function outside(version, range, hilo, loose) {
  22833. version = new SemVer(version, loose);
  22834. range = new Range(range, loose);
  22835. var gtfn, ltefn, ltfn, comp, ecomp;
  22836. switch (hilo) {
  22837. case '>':
  22838. gtfn = gt;
  22839. ltefn = lte;
  22840. ltfn = lt;
  22841. comp = '>';
  22842. ecomp = '>=';
  22843. break;
  22844. case '<':
  22845. gtfn = lt;
  22846. ltefn = gte;
  22847. ltfn = gt;
  22848. comp = '<';
  22849. ecomp = '<=';
  22850. break;
  22851. default:
  22852. throw new TypeError('Must provide a hilo val of "<" or ">"');
  22853. } // If it satisifes the range it is not outside
  22854. if (satisfies(version, range, loose)) {
  22855. return false;
  22856. } // From now on, variable terms are as if we're in "gtr" mode.
  22857. // but note that everything is flipped for the "ltr" function.
  22858. for (var i = 0; i < range.set.length; ++i) {
  22859. var comparators = range.set[i];
  22860. var high = null;
  22861. var low = null;
  22862. comparators.forEach(function (comparator) {
  22863. if (comparator.semver === ANY) {
  22864. comparator = new Comparator('>=0.0.0');
  22865. }
  22866. high = high || comparator;
  22867. low = low || comparator;
  22868. if (gtfn(comparator.semver, high.semver, loose)) {
  22869. high = comparator;
  22870. } else if (ltfn(comparator.semver, low.semver, loose)) {
  22871. low = comparator;
  22872. }
  22873. }); // If the edge version comparator has a operator then our version
  22874. // isn't outside it
  22875. if (high.operator === comp || high.operator === ecomp) {
  22876. return false;
  22877. } // If the lowest version comparator has an operator and our version
  22878. // is less than it then it isn't higher than the range
  22879. if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
  22880. return false;
  22881. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  22882. return false;
  22883. }
  22884. }
  22885. return true;
  22886. }
  22887. exports.prerelease = prerelease;
  22888. function prerelease(version, loose) {
  22889. var parsed = parse(version, loose);
  22890. return parsed && parsed.prerelease.length ? parsed.prerelease : null;
  22891. }
  22892. exports.intersects = intersects;
  22893. function intersects(r1, r2, loose) {
  22894. r1 = new Range(r1, loose);
  22895. r2 = new Range(r2, loose);
  22896. return r1.intersects(r2);
  22897. }
  22898. exports.coerce = coerce;
  22899. function coerce(version) {
  22900. if (version instanceof SemVer) return version;
  22901. if (typeof version !== 'string') return null;
  22902. var match = version.match(re[COERCE]);
  22903. if (match == null) return null;
  22904. return parse((match[1] || '0') + '.' + (match[2] || '0') + '.' + (match[3] || '0'));
  22905. }
  22906. });
  22907. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  22908. var pseudomap = PseudoMap;
  22909. function PseudoMap(set) {
  22910. if (!(this instanceof PseudoMap)) // whyyyyyyy
  22911. throw new TypeError("Constructor PseudoMap requires 'new'");
  22912. this.clear();
  22913. if (set) {
  22914. if (set instanceof PseudoMap || typeof Map === 'function' && set instanceof Map) set.forEach(function (value, key) {
  22915. this.set(key, value);
  22916. }, this);else if (Array.isArray(set)) set.forEach(function (kv) {
  22917. this.set(kv[0], kv[1]);
  22918. }, this);else throw new TypeError('invalid argument');
  22919. }
  22920. }
  22921. PseudoMap.prototype.forEach = function (fn, thisp) {
  22922. thisp = thisp || this;
  22923. Object.keys(this._data).forEach(function (k) {
  22924. if (k !== 'size') fn.call(thisp, this._data[k].value, this._data[k].key);
  22925. }, this);
  22926. };
  22927. PseudoMap.prototype.has = function (k) {
  22928. return !!find(this._data, k);
  22929. };
  22930. PseudoMap.prototype.get = function (k) {
  22931. var res = find(this._data, k);
  22932. return res && res.value;
  22933. };
  22934. PseudoMap.prototype.set = function (k, v) {
  22935. set$1(this._data, k, v);
  22936. };
  22937. PseudoMap.prototype.delete = function (k) {
  22938. var res = find(this._data, k);
  22939. if (res) {
  22940. delete this._data[res._index];
  22941. this._data.size--;
  22942. }
  22943. };
  22944. PseudoMap.prototype.clear = function () {
  22945. var data = Object.create(null);
  22946. data.size = 0;
  22947. Object.defineProperty(this, '_data', {
  22948. value: data,
  22949. enumerable: false,
  22950. configurable: true,
  22951. writable: false
  22952. });
  22953. };
  22954. Object.defineProperty(PseudoMap.prototype, 'size', {
  22955. get: function get() {
  22956. return this._data.size;
  22957. },
  22958. set: function set(n) {},
  22959. enumerable: true,
  22960. configurable: true
  22961. });
  22962. PseudoMap.prototype.values = PseudoMap.prototype.keys = PseudoMap.prototype.entries = function () {
  22963. throw new Error('iterators are not implemented in this version');
  22964. }; // Either identical, or both NaN
  22965. function same(a, b) {
  22966. return a === b || a !== a && b !== b;
  22967. }
  22968. function Entry$1(k, v, i) {
  22969. this.key = k;
  22970. this.value = v;
  22971. this._index = i;
  22972. }
  22973. function find(data, k) {
  22974. for (var i = 0, s = '_' + k, key = s; hasOwnProperty$1.call(data, key); key = s + i++) {
  22975. if (same(data[key].key, k)) return data[key];
  22976. }
  22977. }
  22978. function set$1(data, k, v) {
  22979. for (var i = 0, s = '_' + k, key = s; hasOwnProperty$1.call(data, key); key = s + i++) {
  22980. if (same(data[key].key, k)) {
  22981. data[key].value = v;
  22982. return;
  22983. }
  22984. }
  22985. data.size++;
  22986. data[key] = new Entry$1(k, v, key);
  22987. }
  22988. var map = createCommonjsModule(function (module) {
  22989. if (process.env.npm_package_name === 'pseudomap' && process.env.npm_lifecycle_script === 'test') process.env.TEST_PSEUDOMAP = 'true';
  22990. if (typeof Map === 'function' && !process.env.TEST_PSEUDOMAP) {
  22991. module.exports = Map;
  22992. } else {
  22993. module.exports = pseudomap;
  22994. }
  22995. });
  22996. var yallist = Yallist;
  22997. Yallist.Node = Node;
  22998. Yallist.create = Yallist;
  22999. function Yallist(list) {
  23000. var self = this;
  23001. if (!(self instanceof Yallist)) {
  23002. self = new Yallist();
  23003. }
  23004. self.tail = null;
  23005. self.head = null;
  23006. self.length = 0;
  23007. if (list && typeof list.forEach === 'function') {
  23008. list.forEach(function (item) {
  23009. self.push(item);
  23010. });
  23011. } else if (arguments.length > 0) {
  23012. for (var i = 0, l = arguments.length; i < l; i++) {
  23013. self.push(arguments[i]);
  23014. }
  23015. }
  23016. return self;
  23017. }
  23018. Yallist.prototype.removeNode = function (node) {
  23019. if (node.list !== this) {
  23020. throw new Error('removing node which does not belong to this list');
  23021. }
  23022. var next = node.next;
  23023. var prev = node.prev;
  23024. if (next) {
  23025. next.prev = prev;
  23026. }
  23027. if (prev) {
  23028. prev.next = next;
  23029. }
  23030. if (node === this.head) {
  23031. this.head = next;
  23032. }
  23033. if (node === this.tail) {
  23034. this.tail = prev;
  23035. }
  23036. node.list.length--;
  23037. node.next = null;
  23038. node.prev = null;
  23039. node.list = null;
  23040. };
  23041. Yallist.prototype.unshiftNode = function (node) {
  23042. if (node === this.head) {
  23043. return;
  23044. }
  23045. if (node.list) {
  23046. node.list.removeNode(node);
  23047. }
  23048. var head = this.head;
  23049. node.list = this;
  23050. node.next = head;
  23051. if (head) {
  23052. head.prev = node;
  23053. }
  23054. this.head = node;
  23055. if (!this.tail) {
  23056. this.tail = node;
  23057. }
  23058. this.length++;
  23059. };
  23060. Yallist.prototype.pushNode = function (node) {
  23061. if (node === this.tail) {
  23062. return;
  23063. }
  23064. if (node.list) {
  23065. node.list.removeNode(node);
  23066. }
  23067. var tail = this.tail;
  23068. node.list = this;
  23069. node.prev = tail;
  23070. if (tail) {
  23071. tail.next = node;
  23072. }
  23073. this.tail = node;
  23074. if (!this.head) {
  23075. this.head = node;
  23076. }
  23077. this.length++;
  23078. };
  23079. Yallist.prototype.push = function () {
  23080. for (var i = 0, l = arguments.length; i < l; i++) {
  23081. push(this, arguments[i]);
  23082. }
  23083. return this.length;
  23084. };
  23085. Yallist.prototype.unshift = function () {
  23086. for (var i = 0, l = arguments.length; i < l; i++) {
  23087. unshift(this, arguments[i]);
  23088. }
  23089. return this.length;
  23090. };
  23091. Yallist.prototype.pop = function () {
  23092. if (!this.tail) {
  23093. return undefined;
  23094. }
  23095. var res = this.tail.value;
  23096. this.tail = this.tail.prev;
  23097. if (this.tail) {
  23098. this.tail.next = null;
  23099. } else {
  23100. this.head = null;
  23101. }
  23102. this.length--;
  23103. return res;
  23104. };
  23105. Yallist.prototype.shift = function () {
  23106. if (!this.head) {
  23107. return undefined;
  23108. }
  23109. var res = this.head.value;
  23110. this.head = this.head.next;
  23111. if (this.head) {
  23112. this.head.prev = null;
  23113. } else {
  23114. this.tail = null;
  23115. }
  23116. this.length--;
  23117. return res;
  23118. };
  23119. Yallist.prototype.forEach = function (fn, thisp) {
  23120. thisp = thisp || this;
  23121. for (var walker = this.head, i = 0; walker !== null; i++) {
  23122. fn.call(thisp, walker.value, i, this);
  23123. walker = walker.next;
  23124. }
  23125. };
  23126. Yallist.prototype.forEachReverse = function (fn, thisp) {
  23127. thisp = thisp || this;
  23128. for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
  23129. fn.call(thisp, walker.value, i, this);
  23130. walker = walker.prev;
  23131. }
  23132. };
  23133. Yallist.prototype.get = function (n) {
  23134. for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
  23135. // abort out of the list early if we hit a cycle
  23136. walker = walker.next;
  23137. }
  23138. if (i === n && walker !== null) {
  23139. return walker.value;
  23140. }
  23141. };
  23142. Yallist.prototype.getReverse = function (n) {
  23143. for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
  23144. // abort out of the list early if we hit a cycle
  23145. walker = walker.prev;
  23146. }
  23147. if (i === n && walker !== null) {
  23148. return walker.value;
  23149. }
  23150. };
  23151. Yallist.prototype.map = function (fn, thisp) {
  23152. thisp = thisp || this;
  23153. var res = new Yallist();
  23154. for (var walker = this.head; walker !== null;) {
  23155. res.push(fn.call(thisp, walker.value, this));
  23156. walker = walker.next;
  23157. }
  23158. return res;
  23159. };
  23160. Yallist.prototype.mapReverse = function (fn, thisp) {
  23161. thisp = thisp || this;
  23162. var res = new Yallist();
  23163. for (var walker = this.tail; walker !== null;) {
  23164. res.push(fn.call(thisp, walker.value, this));
  23165. walker = walker.prev;
  23166. }
  23167. return res;
  23168. };
  23169. Yallist.prototype.reduce = function (fn, initial) {
  23170. var acc;
  23171. var walker = this.head;
  23172. if (arguments.length > 1) {
  23173. acc = initial;
  23174. } else if (this.head) {
  23175. walker = this.head.next;
  23176. acc = this.head.value;
  23177. } else {
  23178. throw new TypeError('Reduce of empty list with no initial value');
  23179. }
  23180. for (var i = 0; walker !== null; i++) {
  23181. acc = fn(acc, walker.value, i);
  23182. walker = walker.next;
  23183. }
  23184. return acc;
  23185. };
  23186. Yallist.prototype.reduceReverse = function (fn, initial) {
  23187. var acc;
  23188. var walker = this.tail;
  23189. if (arguments.length > 1) {
  23190. acc = initial;
  23191. } else if (this.tail) {
  23192. walker = this.tail.prev;
  23193. acc = this.tail.value;
  23194. } else {
  23195. throw new TypeError('Reduce of empty list with no initial value');
  23196. }
  23197. for (var i = this.length - 1; walker !== null; i--) {
  23198. acc = fn(acc, walker.value, i);
  23199. walker = walker.prev;
  23200. }
  23201. return acc;
  23202. };
  23203. Yallist.prototype.toArray = function () {
  23204. var arr = new Array(this.length);
  23205. for (var i = 0, walker = this.head; walker !== null; i++) {
  23206. arr[i] = walker.value;
  23207. walker = walker.next;
  23208. }
  23209. return arr;
  23210. };
  23211. Yallist.prototype.toArrayReverse = function () {
  23212. var arr = new Array(this.length);
  23213. for (var i = 0, walker = this.tail; walker !== null; i++) {
  23214. arr[i] = walker.value;
  23215. walker = walker.prev;
  23216. }
  23217. return arr;
  23218. };
  23219. Yallist.prototype.slice = function (from, to) {
  23220. to = to || this.length;
  23221. if (to < 0) {
  23222. to += this.length;
  23223. }
  23224. from = from || 0;
  23225. if (from < 0) {
  23226. from += this.length;
  23227. }
  23228. var ret = new Yallist();
  23229. if (to < from || to < 0) {
  23230. return ret;
  23231. }
  23232. if (from < 0) {
  23233. from = 0;
  23234. }
  23235. if (to > this.length) {
  23236. to = this.length;
  23237. }
  23238. for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
  23239. walker = walker.next;
  23240. }
  23241. for (; walker !== null && i < to; i++, walker = walker.next) {
  23242. ret.push(walker.value);
  23243. }
  23244. return ret;
  23245. };
  23246. Yallist.prototype.sliceReverse = function (from, to) {
  23247. to = to || this.length;
  23248. if (to < 0) {
  23249. to += this.length;
  23250. }
  23251. from = from || 0;
  23252. if (from < 0) {
  23253. from += this.length;
  23254. }
  23255. var ret = new Yallist();
  23256. if (to < from || to < 0) {
  23257. return ret;
  23258. }
  23259. if (from < 0) {
  23260. from = 0;
  23261. }
  23262. if (to > this.length) {
  23263. to = this.length;
  23264. }
  23265. for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
  23266. walker = walker.prev;
  23267. }
  23268. for (; walker !== null && i > from; i--, walker = walker.prev) {
  23269. ret.push(walker.value);
  23270. }
  23271. return ret;
  23272. };
  23273. Yallist.prototype.reverse = function () {
  23274. var head = this.head;
  23275. var tail = this.tail;
  23276. for (var walker = head; walker !== null; walker = walker.prev) {
  23277. var p = walker.prev;
  23278. walker.prev = walker.next;
  23279. walker.next = p;
  23280. }
  23281. this.head = tail;
  23282. this.tail = head;
  23283. return this;
  23284. };
  23285. function push(self, item) {
  23286. self.tail = new Node(item, self.tail, null, self);
  23287. if (!self.head) {
  23288. self.head = self.tail;
  23289. }
  23290. self.length++;
  23291. }
  23292. function unshift(self, item) {
  23293. self.head = new Node(item, null, self.head, self);
  23294. if (!self.tail) {
  23295. self.tail = self.head;
  23296. }
  23297. self.length++;
  23298. }
  23299. function Node(value, prev, next, list) {
  23300. if (!(this instanceof Node)) {
  23301. return new Node(value, prev, next, list);
  23302. }
  23303. this.list = list;
  23304. this.value = value;
  23305. if (prev) {
  23306. prev.next = this;
  23307. this.prev = prev;
  23308. } else {
  23309. this.prev = null;
  23310. }
  23311. if (next) {
  23312. next.prev = this;
  23313. this.next = next;
  23314. } else {
  23315. this.next = null;
  23316. }
  23317. }
  23318. var lruCache = LRUCache; // This will be a proper iterable 'Map' in engines that support it,
  23319. // or a fakey-fake PseudoMap in older versions.
  23320. // A linked list to keep track of recently-used-ness
  23321. // use symbols if possible, otherwise just _props
  23322. var hasSymbol = typeof Symbol === 'function';
  23323. var makeSymbol;
  23324. if (hasSymbol) {
  23325. makeSymbol = function makeSymbol(key) {
  23326. return Symbol.for(key);
  23327. };
  23328. } else {
  23329. makeSymbol = function makeSymbol(key) {
  23330. return '_' + key;
  23331. };
  23332. }
  23333. var MAX = makeSymbol('max');
  23334. var LENGTH = makeSymbol('length');
  23335. var LENGTH_CALCULATOR = makeSymbol('lengthCalculator');
  23336. var ALLOW_STALE = makeSymbol('allowStale');
  23337. var MAX_AGE = makeSymbol('maxAge');
  23338. var DISPOSE = makeSymbol('dispose');
  23339. var NO_DISPOSE_ON_SET = makeSymbol('noDisposeOnSet');
  23340. var LRU_LIST = makeSymbol('lruList');
  23341. var CACHE = makeSymbol('cache');
  23342. function naiveLength() {
  23343. return 1;
  23344. } // lruList is a yallist where the head is the youngest
  23345. // item, and the tail is the oldest. the list contains the Hit
  23346. // objects as the entries.
  23347. // Each Hit object has a reference to its Yallist.Node. This
  23348. // never changes.
  23349. //
  23350. // cache is a Map (or PseudoMap) that matches the keys to
  23351. // the Yallist.Node object.
  23352. function LRUCache(options) {
  23353. if (!(this instanceof LRUCache)) {
  23354. return new LRUCache(options);
  23355. }
  23356. if (typeof options === 'number') {
  23357. options = {
  23358. max: options
  23359. };
  23360. }
  23361. if (!options) {
  23362. options = {};
  23363. }
  23364. var max = this[MAX] = options.max; // Kind of weird to have a default max of Infinity, but oh well.
  23365. if (!max || !(typeof max === 'number') || max <= 0) {
  23366. this[MAX] = Infinity;
  23367. }
  23368. var lc = options.length || naiveLength;
  23369. if (typeof lc !== 'function') {
  23370. lc = naiveLength;
  23371. }
  23372. this[LENGTH_CALCULATOR] = lc;
  23373. this[ALLOW_STALE] = options.stale || false;
  23374. this[MAX_AGE] = options.maxAge || 0;
  23375. this[DISPOSE] = options.dispose;
  23376. this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
  23377. this.reset();
  23378. } // resize the cache when the max changes.
  23379. Object.defineProperty(LRUCache.prototype, 'max', {
  23380. set: function set(mL) {
  23381. if (!mL || !(typeof mL === 'number') || mL <= 0) {
  23382. mL = Infinity;
  23383. }
  23384. this[MAX] = mL;
  23385. trim(this);
  23386. },
  23387. get: function get() {
  23388. return this[MAX];
  23389. },
  23390. enumerable: true
  23391. });
  23392. Object.defineProperty(LRUCache.prototype, 'allowStale', {
  23393. set: function set(allowStale) {
  23394. this[ALLOW_STALE] = !!allowStale;
  23395. },
  23396. get: function get() {
  23397. return this[ALLOW_STALE];
  23398. },
  23399. enumerable: true
  23400. });
  23401. Object.defineProperty(LRUCache.prototype, 'maxAge', {
  23402. set: function set(mA) {
  23403. if (!mA || !(typeof mA === 'number') || mA < 0) {
  23404. mA = 0;
  23405. }
  23406. this[MAX_AGE] = mA;
  23407. trim(this);
  23408. },
  23409. get: function get() {
  23410. return this[MAX_AGE];
  23411. },
  23412. enumerable: true
  23413. }); // resize the cache when the lengthCalculator changes.
  23414. Object.defineProperty(LRUCache.prototype, 'lengthCalculator', {
  23415. set: function set(lC) {
  23416. if (typeof lC !== 'function') {
  23417. lC = naiveLength;
  23418. }
  23419. if (lC !== this[LENGTH_CALCULATOR]) {
  23420. this[LENGTH_CALCULATOR] = lC;
  23421. this[LENGTH] = 0;
  23422. this[LRU_LIST].forEach(function (hit) {
  23423. hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
  23424. this[LENGTH] += hit.length;
  23425. }, this);
  23426. }
  23427. trim(this);
  23428. },
  23429. get: function get() {
  23430. return this[LENGTH_CALCULATOR];
  23431. },
  23432. enumerable: true
  23433. });
  23434. Object.defineProperty(LRUCache.prototype, 'length', {
  23435. get: function get() {
  23436. return this[LENGTH];
  23437. },
  23438. enumerable: true
  23439. });
  23440. Object.defineProperty(LRUCache.prototype, 'itemCount', {
  23441. get: function get() {
  23442. return this[LRU_LIST].length;
  23443. },
  23444. enumerable: true
  23445. });
  23446. LRUCache.prototype.rforEach = function (fn, thisp) {
  23447. thisp = thisp || this;
  23448. for (var walker = this[LRU_LIST].tail; walker !== null;) {
  23449. var prev = walker.prev;
  23450. forEachStep(this, fn, walker, thisp);
  23451. walker = prev;
  23452. }
  23453. };
  23454. function forEachStep(self, fn, node, thisp) {
  23455. var hit = node.value;
  23456. if (isStale(self, hit)) {
  23457. del(self, node);
  23458. if (!self[ALLOW_STALE]) {
  23459. hit = undefined;
  23460. }
  23461. }
  23462. if (hit) {
  23463. fn.call(thisp, hit.value, hit.key, self);
  23464. }
  23465. }
  23466. LRUCache.prototype.forEach = function (fn, thisp) {
  23467. thisp = thisp || this;
  23468. for (var walker = this[LRU_LIST].head; walker !== null;) {
  23469. var next = walker.next;
  23470. forEachStep(this, fn, walker, thisp);
  23471. walker = next;
  23472. }
  23473. };
  23474. LRUCache.prototype.keys = function () {
  23475. return this[LRU_LIST].toArray().map(function (k) {
  23476. return k.key;
  23477. }, this);
  23478. };
  23479. LRUCache.prototype.values = function () {
  23480. return this[LRU_LIST].toArray().map(function (k) {
  23481. return k.value;
  23482. }, this);
  23483. };
  23484. LRUCache.prototype.reset = function () {
  23485. if (this[DISPOSE] && this[LRU_LIST] && this[LRU_LIST].length) {
  23486. this[LRU_LIST].forEach(function (hit) {
  23487. this[DISPOSE](hit.key, hit.value);
  23488. }, this);
  23489. }
  23490. this[CACHE] = new map(); // hash of items by key
  23491. this[LRU_LIST] = new yallist(); // list of items in order of use recency
  23492. this[LENGTH] = 0; // length of items in the list
  23493. };
  23494. LRUCache.prototype.dump = function () {
  23495. return this[LRU_LIST].map(function (hit) {
  23496. if (!isStale(this, hit)) {
  23497. return {
  23498. k: hit.key,
  23499. v: hit.value,
  23500. e: hit.now + (hit.maxAge || 0)
  23501. };
  23502. }
  23503. }, this).toArray().filter(function (h) {
  23504. return h;
  23505. });
  23506. };
  23507. LRUCache.prototype.dumpLru = function () {
  23508. return this[LRU_LIST];
  23509. };
  23510. LRUCache.prototype.inspect = function (n, opts) {
  23511. var str = 'LRUCache {';
  23512. var extras = false;
  23513. var as = this[ALLOW_STALE];
  23514. if (as) {
  23515. str += '\n allowStale: true';
  23516. extras = true;
  23517. }
  23518. var max = this[MAX];
  23519. if (max && max !== Infinity) {
  23520. if (extras) {
  23521. str += ',';
  23522. }
  23523. str += '\n max: ' + util.inspect(max, opts);
  23524. extras = true;
  23525. }
  23526. var maxAge = this[MAX_AGE];
  23527. if (maxAge) {
  23528. if (extras) {
  23529. str += ',';
  23530. }
  23531. str += '\n maxAge: ' + util.inspect(maxAge, opts);
  23532. extras = true;
  23533. }
  23534. var lc = this[LENGTH_CALCULATOR];
  23535. if (lc && lc !== naiveLength) {
  23536. if (extras) {
  23537. str += ',';
  23538. }
  23539. str += '\n length: ' + util.inspect(this[LENGTH], opts);
  23540. extras = true;
  23541. }
  23542. var didFirst = false;
  23543. this[LRU_LIST].forEach(function (item) {
  23544. if (didFirst) {
  23545. str += ',\n ';
  23546. } else {
  23547. if (extras) {
  23548. str += ',\n';
  23549. }
  23550. didFirst = true;
  23551. str += '\n ';
  23552. }
  23553. var key = util.inspect(item.key).split('\n').join('\n ');
  23554. var val = {
  23555. value: item.value
  23556. };
  23557. if (item.maxAge !== maxAge) {
  23558. val.maxAge = item.maxAge;
  23559. }
  23560. if (lc !== naiveLength) {
  23561. val.length = item.length;
  23562. }
  23563. if (isStale(this, item)) {
  23564. val.stale = true;
  23565. }
  23566. val = util.inspect(val, opts).split('\n').join('\n ');
  23567. str += key + ' => ' + val;
  23568. });
  23569. if (didFirst || extras) {
  23570. str += '\n';
  23571. }
  23572. str += '}';
  23573. return str;
  23574. };
  23575. LRUCache.prototype.set = function (key, value, maxAge) {
  23576. maxAge = maxAge || this[MAX_AGE];
  23577. var now = maxAge ? Date.now() : 0;
  23578. var len = this[LENGTH_CALCULATOR](value, key);
  23579. if (this[CACHE].has(key)) {
  23580. if (len > this[MAX]) {
  23581. del(this, this[CACHE].get(key));
  23582. return false;
  23583. }
  23584. var node = this[CACHE].get(key);
  23585. var item = node.value; // dispose of the old one before overwriting
  23586. // split out into 2 ifs for better coverage tracking
  23587. if (this[DISPOSE]) {
  23588. if (!this[NO_DISPOSE_ON_SET]) {
  23589. this[DISPOSE](key, item.value);
  23590. }
  23591. }
  23592. item.now = now;
  23593. item.maxAge = maxAge;
  23594. item.value = value;
  23595. this[LENGTH] += len - item.length;
  23596. item.length = len;
  23597. this.get(key);
  23598. trim(this);
  23599. return true;
  23600. }
  23601. var hit = new Entry(key, value, len, now, maxAge); // oversized objects fall out of cache automatically.
  23602. if (hit.length > this[MAX]) {
  23603. if (this[DISPOSE]) {
  23604. this[DISPOSE](key, value);
  23605. }
  23606. return false;
  23607. }
  23608. this[LENGTH] += hit.length;
  23609. this[LRU_LIST].unshift(hit);
  23610. this[CACHE].set(key, this[LRU_LIST].head);
  23611. trim(this);
  23612. return true;
  23613. };
  23614. LRUCache.prototype.has = function (key) {
  23615. if (!this[CACHE].has(key)) return false;
  23616. var hit = this[CACHE].get(key).value;
  23617. if (isStale(this, hit)) {
  23618. return false;
  23619. }
  23620. return true;
  23621. };
  23622. LRUCache.prototype.get = function (key) {
  23623. return get(this, key, true);
  23624. };
  23625. LRUCache.prototype.peek = function (key) {
  23626. return get(this, key, false);
  23627. };
  23628. LRUCache.prototype.pop = function () {
  23629. var node = this[LRU_LIST].tail;
  23630. if (!node) return null;
  23631. del(this, node);
  23632. return node.value;
  23633. };
  23634. LRUCache.prototype.del = function (key) {
  23635. del(this, this[CACHE].get(key));
  23636. };
  23637. LRUCache.prototype.load = function (arr) {
  23638. // reset the cache
  23639. this.reset();
  23640. var now = Date.now(); // A previous serialized cache has the most recent items first
  23641. for (var l = arr.length - 1; l >= 0; l--) {
  23642. var hit = arr[l];
  23643. var expiresAt = hit.e || 0;
  23644. if (expiresAt === 0) {
  23645. // the item was created without expiration in a non aged cache
  23646. this.set(hit.k, hit.v);
  23647. } else {
  23648. var maxAge = expiresAt - now; // dont add already expired items
  23649. if (maxAge > 0) {
  23650. this.set(hit.k, hit.v, maxAge);
  23651. }
  23652. }
  23653. }
  23654. };
  23655. LRUCache.prototype.prune = function () {
  23656. var self = this;
  23657. this[CACHE].forEach(function (value, key) {
  23658. get(self, key, false);
  23659. });
  23660. };
  23661. function get(self, key, doUse) {
  23662. var node = self[CACHE].get(key);
  23663. if (node) {
  23664. var hit = node.value;
  23665. if (isStale(self, hit)) {
  23666. del(self, node);
  23667. if (!self[ALLOW_STALE]) hit = undefined;
  23668. } else {
  23669. if (doUse) {
  23670. self[LRU_LIST].unshiftNode(node);
  23671. }
  23672. }
  23673. if (hit) hit = hit.value;
  23674. }
  23675. return hit;
  23676. }
  23677. function isStale(self, hit) {
  23678. if (!hit || !hit.maxAge && !self[MAX_AGE]) {
  23679. return false;
  23680. }
  23681. var stale = false;
  23682. var diff = Date.now() - hit.now;
  23683. if (hit.maxAge) {
  23684. stale = diff > hit.maxAge;
  23685. } else {
  23686. stale = self[MAX_AGE] && diff > self[MAX_AGE];
  23687. }
  23688. return stale;
  23689. }
  23690. function trim(self) {
  23691. if (self[LENGTH] > self[MAX]) {
  23692. for (var walker = self[LRU_LIST].tail; self[LENGTH] > self[MAX] && walker !== null;) {
  23693. // We know that we're about to delete this one, and also
  23694. // what the next least recently used key will be, so just
  23695. // go ahead and set it now.
  23696. var prev = walker.prev;
  23697. del(self, walker);
  23698. walker = prev;
  23699. }
  23700. }
  23701. }
  23702. function del(self, node) {
  23703. if (node) {
  23704. var hit = node.value;
  23705. if (self[DISPOSE]) {
  23706. self[DISPOSE](hit.key, hit.value);
  23707. }
  23708. self[LENGTH] -= hit.length;
  23709. self[CACHE].delete(hit.key);
  23710. self[LRU_LIST].removeNode(node);
  23711. }
  23712. } // classy, since V8 prefers predictable objects.
  23713. function Entry(key, value, length, now, maxAge) {
  23714. this.key = key;
  23715. this.value = value;
  23716. this.length = length;
  23717. this.now = now;
  23718. this.maxAge = maxAge || 0;
  23719. }
  23720. var sigmund_1 = sigmund;
  23721. function sigmund(subject, maxSessions) {
  23722. maxSessions = maxSessions || 10;
  23723. var notes = [];
  23724. var analysis = '';
  23725. var RE = RegExp;
  23726. function psychoAnalyze(subject, session) {
  23727. if (session > maxSessions) return;
  23728. if (typeof subject === 'function' || typeof subject === 'undefined') {
  23729. return;
  23730. }
  23731. if (typeof subject !== 'object' || !subject || subject instanceof RE) {
  23732. analysis += subject;
  23733. return;
  23734. }
  23735. if (notes.indexOf(subject) !== -1 || session === maxSessions) return;
  23736. notes.push(subject);
  23737. analysis += '{';
  23738. Object.keys(subject).forEach(function (issue, _, __) {
  23739. // pseudo-private values. skip those.
  23740. if (issue.charAt(0) === '_') return;
  23741. var to = typeof subject[issue];
  23742. if (to === 'function' || to === 'undefined') return;
  23743. analysis += issue;
  23744. psychoAnalyze(subject[issue], session + 1);
  23745. });
  23746. }
  23747. psychoAnalyze(subject, 0);
  23748. return analysis;
  23749. } // vim: set softtabstop=4 shiftwidth=4:
  23750. var fnmatch = createCommonjsModule(function (module, exports) {
  23751. // Based on minimatch.js by isaacs <https://npmjs.org/package/minimatch>
  23752. var platform = typeof process === "object" ? process.platform : "win32";
  23753. if (module) module.exports = minimatch;else exports.minimatch = minimatch;
  23754. minimatch.Minimatch = Minimatch;
  23755. var cache = minimatch.cache = new lruCache({
  23756. max: 100
  23757. }),
  23758. GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
  23759. var qmark = "[^/]" // * => any number of characters
  23760. ,
  23761. star = qmark + "*?" // ** when dots are allowed. Anything goes, except .. and .
  23762. // not (^ or / followed by one or two dots followed by $ or /),
  23763. // followed by anything, any number of times.
  23764. ,
  23765. twoStarDot = "(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?" // not a ^ or / followed by a dot,
  23766. // followed by anything, any number of times.
  23767. ,
  23768. twoStarNoDot = "(?:(?!(?:\\\/|^)\\.).)*?" // characters that need to be escaped in RegExp.
  23769. ,
  23770. reSpecials = charSet("().*{}+?[]^$\\!"); // "abc" -> { a:true, b:true, c:true }
  23771. function charSet(s) {
  23772. return s.split("").reduce(function (set, c) {
  23773. set[c] = true;
  23774. return set;
  23775. }, {});
  23776. } // normalizes slashes.
  23777. var slashSplit = /\/+/;
  23778. minimatch.monkeyPatch = monkeyPatch;
  23779. function monkeyPatch() {
  23780. var desc = Object.getOwnPropertyDescriptor(String.prototype, "match");
  23781. var orig = desc.value;
  23782. desc.value = function (p) {
  23783. if (p instanceof Minimatch) return p.match(this);
  23784. return orig.call(this, p);
  23785. };
  23786. Object.defineProperty(String.prototype, desc);
  23787. }
  23788. minimatch.filter = filter;
  23789. function filter(pattern, options) {
  23790. options = options || {};
  23791. return function (p, i, list) {
  23792. return minimatch(p, pattern, options);
  23793. };
  23794. }
  23795. function ext(a, b) {
  23796. a = a || {};
  23797. b = b || {};
  23798. var t = {};
  23799. Object.keys(b).forEach(function (k) {
  23800. t[k] = b[k];
  23801. });
  23802. Object.keys(a).forEach(function (k) {
  23803. t[k] = a[k];
  23804. });
  23805. return t;
  23806. }
  23807. minimatch.defaults = function (def) {
  23808. if (!def || !Object.keys(def).length) return minimatch;
  23809. var orig = minimatch;
  23810. var m = function minimatch(p, pattern, options) {
  23811. return orig.minimatch(p, pattern, ext(def, options));
  23812. };
  23813. m.Minimatch = function Minimatch(pattern, options) {
  23814. return new orig.Minimatch(pattern, ext(def, options));
  23815. };
  23816. return m;
  23817. };
  23818. Minimatch.defaults = function (def) {
  23819. if (!def || !Object.keys(def).length) return Minimatch;
  23820. return minimatch.defaults(def).Minimatch;
  23821. };
  23822. function minimatch(p, pattern, options) {
  23823. if (typeof pattern !== "string") {
  23824. throw new TypeError("glob pattern string required");
  23825. }
  23826. if (!options) options = {}; // shortcut: comments match nothing.
  23827. if (!options.nocomment && pattern.charAt(0) === "#") {
  23828. return false;
  23829. } // "" only matches ""
  23830. if (pattern.trim() === "") return p === "";
  23831. return new Minimatch(pattern, options).match(p);
  23832. }
  23833. function Minimatch(pattern, options) {
  23834. if (!(this instanceof Minimatch)) {
  23835. return new Minimatch(pattern, options, cache);
  23836. }
  23837. if (typeof pattern !== "string") {
  23838. throw new TypeError("glob pattern string required");
  23839. }
  23840. if (!options) options = {}; // windows: need to use /, not \
  23841. // On other platforms, \ is a valid (albeit bad) filename char.
  23842. if (platform === "win32") {
  23843. pattern = pattern.split("\\").join("/");
  23844. } // lru storage.
  23845. // these things aren't particularly big, but walking down the string
  23846. // and turning it into a regexp can get pretty costly.
  23847. var cacheKey = pattern + "\n" + sigmund_1(options);
  23848. var cached = minimatch.cache.get(cacheKey);
  23849. if (cached) return cached;
  23850. minimatch.cache.set(cacheKey, this);
  23851. this.options = options;
  23852. this.set = [];
  23853. this.pattern = pattern;
  23854. this.regexp = null;
  23855. this.negate = false;
  23856. this.comment = false;
  23857. this.empty = false; // make the set of regexps etc.
  23858. this.make();
  23859. }
  23860. Minimatch.prototype.make = make;
  23861. function make() {
  23862. // don't do it more than once.
  23863. if (this._made) return;
  23864. var pattern = this.pattern;
  23865. var options = this.options; // empty patterns and comments match nothing.
  23866. if (!options.nocomment && pattern.charAt(0) === "#") {
  23867. this.comment = true;
  23868. return;
  23869. }
  23870. if (!pattern) {
  23871. this.empty = true;
  23872. return;
  23873. } // step 1: figure out negation, etc.
  23874. this.parseNegate(); // step 2: expand braces
  23875. var set = this.globSet = this.braceExpand();
  23876. 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
  23877. // matching patterns.
  23878. // These will be regexps, except in the case of "**", which is
  23879. // set to the GLOBSTAR object for globstar behavior,
  23880. // and will not contain any / characters
  23881. set = this.globParts = set.map(function (s) {
  23882. return s.split(slashSplit);
  23883. });
  23884. if (options.debug) console.error(this.pattern, set); // glob --> regexps
  23885. set = set.map(function (s, si, set) {
  23886. return s.map(this.parse, this);
  23887. }, this);
  23888. if (options.debug) console.error(this.pattern, set); // filter out everything that didn't compile properly.
  23889. set = set.filter(function (s) {
  23890. return -1 === s.indexOf(false);
  23891. });
  23892. if (options.debug) console.error(this.pattern, set);
  23893. this.set = set;
  23894. }
  23895. Minimatch.prototype.parseNegate = parseNegate;
  23896. function parseNegate() {
  23897. var pattern = this.pattern,
  23898. negate = false,
  23899. options = this.options,
  23900. negateOffset = 0;
  23901. if (options.nonegate) return;
  23902. for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === "!"; i++) {
  23903. negate = !negate;
  23904. negateOffset++;
  23905. }
  23906. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  23907. this.negate = negate;
  23908. } // Brace expansion:
  23909. // a{b,c}d -> abd acd
  23910. // a{b,}c -> abc ac
  23911. // a{0..3}d -> a0d a1d a2d a3d
  23912. // a{b,c{d,e}f}g -> abg acdfg acefg
  23913. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  23914. //
  23915. // Invalid sets are not expanded.
  23916. // a{2..}b -> a{2..}b
  23917. // a{b}c -> a{b}c
  23918. minimatch.braceExpand = function (pattern, options) {
  23919. return new Minimatch(pattern, options).braceExpand();
  23920. };
  23921. Minimatch.prototype.braceExpand = braceExpand;
  23922. function braceExpand(pattern, options) {
  23923. options = options || this.options;
  23924. pattern = typeof pattern === "undefined" ? this.pattern : pattern;
  23925. if (typeof pattern === "undefined") {
  23926. throw new Error("undefined pattern");
  23927. }
  23928. if (options.nobrace || !pattern.match(/\{.*\}/)) {
  23929. // shortcut. no need to expand.
  23930. return [pattern];
  23931. }
  23932. var escaping = false; // examples and comments refer to this crazy pattern:
  23933. // a{b,c{d,e},{f,g}h}x{y,z}
  23934. // expected:
  23935. // abxy
  23936. // abxz
  23937. // acdxy
  23938. // acdxz
  23939. // acexy
  23940. // acexz
  23941. // afhxy
  23942. // afhxz
  23943. // aghxy
  23944. // aghxz
  23945. // everything before the first \{ is just a prefix.
  23946. // So, we pluck that off, and work with the rest,
  23947. // and then prepend it to everything we find.
  23948. if (pattern.charAt(0) !== "{") {
  23949. // console.error(pattern)
  23950. var prefix = null;
  23951. for (var i = 0, l = pattern.length; i < l; i++) {
  23952. var c = pattern.charAt(i); // console.error(i, c)
  23953. if (c === "\\") {
  23954. escaping = !escaping;
  23955. } else if (c === "{" && !escaping) {
  23956. prefix = pattern.substr(0, i);
  23957. break;
  23958. }
  23959. } // actually no sets, all { were escaped.
  23960. if (prefix === null) {
  23961. // console.error("no sets")
  23962. return [pattern];
  23963. }
  23964. var tail = braceExpand(pattern.substr(i), options);
  23965. return tail.map(function (t) {
  23966. return prefix + t;
  23967. });
  23968. } // now we have something like:
  23969. // {b,c{d,e},{f,g}h}x{y,z}
  23970. // walk through the set, expanding each part, until
  23971. // the set ends. then, we'll expand the suffix.
  23972. // If the set only has a single member, then'll put the {} back
  23973. // first, handle numeric sets, since they're easier
  23974. var numset = pattern.match(/^\{(-?[0-9]+)\.\.(-?[0-9]+)\}/);
  23975. if (numset) {
  23976. // console.error("numset", numset[1], numset[2])
  23977. var suf = braceExpand(pattern.substr(numset[0].length), options),
  23978. start = +numset[1],
  23979. end = +numset[2],
  23980. inc = start > end ? -1 : 1,
  23981. set = [];
  23982. for (var i = start; i != end + inc; i += inc) {
  23983. // append all the suffixes
  23984. for (var ii = 0, ll = suf.length; ii < ll; ii++) {
  23985. set.push(i + suf[ii]);
  23986. }
  23987. }
  23988. return set;
  23989. } // ok, walk through the set
  23990. // We hope, somewhat optimistically, that there
  23991. // will be a } at the end.
  23992. // If the closing brace isn't found, then the pattern is
  23993. // interpreted as braceExpand("\\" + pattern) so that
  23994. // the leading \{ will be interpreted literally.
  23995. var i = 1 // skip the \{
  23996. ,
  23997. depth = 1,
  23998. set = [],
  23999. member = "",
  24000. sawEnd = false,
  24001. escaping = false;
  24002. function addMember() {
  24003. set.push(member);
  24004. member = "";
  24005. } // console.error("Entering for")
  24006. FOR: for (i = 1, l = pattern.length; i < l; i++) {
  24007. var c = pattern.charAt(i); // console.error("", i, c)
  24008. if (escaping) {
  24009. escaping = false;
  24010. member += "\\" + c;
  24011. } else {
  24012. switch (c) {
  24013. case "\\":
  24014. escaping = true;
  24015. continue;
  24016. case "{":
  24017. depth++;
  24018. member += "{";
  24019. continue;
  24020. case "}":
  24021. depth--; // if this closes the actual set, then we're done
  24022. if (depth === 0) {
  24023. addMember(); // pluck off the close-brace
  24024. i++;
  24025. break FOR;
  24026. } else {
  24027. member += c;
  24028. continue;
  24029. }
  24030. case ",":
  24031. if (depth === 1) {
  24032. addMember();
  24033. } else {
  24034. member += c;
  24035. }
  24036. continue;
  24037. default:
  24038. member += c;
  24039. continue;
  24040. } // switch
  24041. } // else
  24042. } // for
  24043. // now we've either finished the set, and the suffix is
  24044. // pattern.substr(i), or we have *not* closed the set,
  24045. // and need to escape the leading brace
  24046. if (depth !== 0) {
  24047. // console.error("didn't close", pattern)
  24048. return braceExpand("\\" + pattern, options);
  24049. } // x{y,z} -> ["xy", "xz"]
  24050. // console.error("set", set)
  24051. // console.error("suffix", pattern.substr(i))
  24052. var suf = braceExpand(pattern.substr(i), options); // ["b", "c{d,e}","{f,g}h"] ->
  24053. // [["b"], ["cd", "ce"], ["fh", "gh"]]
  24054. var addBraces = set.length === 1; // console.error("set pre-expanded", set)
  24055. set = set.map(function (p) {
  24056. return braceExpand(p, options);
  24057. }); // console.error("set expanded", set)
  24058. // [["b"], ["cd", "ce"], ["fh", "gh"]] ->
  24059. // ["b", "cd", "ce", "fh", "gh"]
  24060. set = set.reduce(function (l, r) {
  24061. return l.concat(r);
  24062. });
  24063. if (addBraces) {
  24064. set = set.map(function (s) {
  24065. return "{" + s + "}";
  24066. });
  24067. } // now attach the suffixes.
  24068. var ret = [];
  24069. for (var i = 0, l = set.length; i < l; i++) {
  24070. for (var ii = 0, ll = suf.length; ii < ll; ii++) {
  24071. ret.push(set[i] + suf[ii]);
  24072. }
  24073. }
  24074. return ret;
  24075. } // parse a component of the expanded set.
  24076. // At this point, no pattern may contain "/" in it
  24077. // so we're going to return a 2d array, where each entry is the full
  24078. // pattern, split on '/', and then turned into a regular expression.
  24079. // A regexp is made at the end which joins each array with an
  24080. // escaped /, and another full one which joins each regexp with |.
  24081. //
  24082. // Following the lead of Bash 4.1, note that "**" only has special meaning
  24083. // when it is the *only* thing in a path portion. Otherwise, any series
  24084. // of * is equivalent to a single *. Globstar behavior is enabled by
  24085. // default, and can be disabled by setting options.noglobstar.
  24086. Minimatch.prototype.parse = parse;
  24087. var SUBPARSE = {};
  24088. function parse(pattern, isSub) {
  24089. var options = this.options; // shortcuts
  24090. if (!options.noglobstar && pattern === "**") return GLOBSTAR;
  24091. if (pattern === "") return "";
  24092. var re = "",
  24093. hasMagic = !!options.nocase,
  24094. escaping = false // ? => one single character
  24095. ,
  24096. patternListStack = [],
  24097. plType,
  24098. stateChar,
  24099. inClass = false,
  24100. reClassStart = -1,
  24101. classStart = -1 // . and .. never match anything that doesn't start with .,
  24102. // even when options.dot is set.
  24103. ,
  24104. patternStart = pattern.charAt(0) === "." ? "" // anything
  24105. // not (start or / followed by . or .. followed by / or end)
  24106. : options.dot ? "(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))" : "(?!\\.)";
  24107. function clearStateChar() {
  24108. if (stateChar) {
  24109. // we had some state-tracking character
  24110. // that wasn't consumed by this pass.
  24111. switch (stateChar) {
  24112. case "*":
  24113. re += star;
  24114. hasMagic = true;
  24115. break;
  24116. case "?":
  24117. re += qmark;
  24118. hasMagic = true;
  24119. break;
  24120. default:
  24121. re += "\\" + stateChar;
  24122. break;
  24123. }
  24124. stateChar = false;
  24125. }
  24126. }
  24127. for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
  24128. if (options.debug) {
  24129. console.error("%s\t%s %s %j", pattern, i, re, c);
  24130. } // skip over any that are escaped.
  24131. if (escaping && reSpecials[c]) {
  24132. re += "\\" + c;
  24133. escaping = false;
  24134. continue;
  24135. }
  24136. SWITCH: switch (c) {
  24137. case "/":
  24138. // completely not allowed, even escaped.
  24139. // Should already be path-split by now.
  24140. return false;
  24141. case "\\":
  24142. clearStateChar();
  24143. escaping = true;
  24144. continue;
  24145. // the various stateChar values
  24146. // for the "extglob" stuff.
  24147. case "?":
  24148. case "*":
  24149. case "+":
  24150. case "@":
  24151. case "!":
  24152. if (options.debug) {
  24153. console.error("%s\t%s %s %j <-- stateChar", pattern, i, re, c);
  24154. } // all of those are literals inside a class, except that
  24155. // the glob [!a] means [^a] in regexp
  24156. if (inClass) {
  24157. if (c === "!" && i === classStart + 1) c = "^";
  24158. re += c;
  24159. continue;
  24160. } // if we already have a stateChar, then it means
  24161. // that there was something like ** or +? in there.
  24162. // Handle the stateChar, then proceed with this one.
  24163. clearStateChar();
  24164. stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
  24165. // just clear the statechar *now*, rather than even diving into
  24166. // the patternList stuff.
  24167. if (options.noext) clearStateChar();
  24168. continue;
  24169. case "(":
  24170. if (inClass) {
  24171. re += "(";
  24172. continue;
  24173. }
  24174. if (!stateChar) {
  24175. re += "\\(";
  24176. continue;
  24177. }
  24178. plType = stateChar;
  24179. patternListStack.push({
  24180. type: plType,
  24181. start: i - 1,
  24182. reStart: re.length
  24183. }); // negation is (?:(?!js)[^/]*)
  24184. re += stateChar === "!" ? "(?:(?!" : "(?:";
  24185. stateChar = false;
  24186. continue;
  24187. case ")":
  24188. if (inClass || !patternListStack.length) {
  24189. re += "\\)";
  24190. continue;
  24191. }
  24192. hasMagic = true;
  24193. re += ")";
  24194. plType = patternListStack.pop().type; // negation is (?:(?!js)[^/]*)
  24195. // The others are (?:<pattern>)<type>
  24196. switch (plType) {
  24197. case "!":
  24198. re += "[^/]*?)";
  24199. break;
  24200. case "?":
  24201. case "+":
  24202. case "*":
  24203. re += plType;
  24204. case "@":
  24205. break;
  24206. // the default anyway
  24207. }
  24208. continue;
  24209. case "|":
  24210. if (inClass || !patternListStack.length || escaping) {
  24211. re += "\\|";
  24212. escaping = false;
  24213. continue;
  24214. }
  24215. re += "|";
  24216. continue;
  24217. // these are mostly the same in regexp and glob
  24218. case "[":
  24219. // swallow any state-tracking char before the [
  24220. clearStateChar();
  24221. if (inClass) {
  24222. re += "\\" + c;
  24223. continue;
  24224. }
  24225. inClass = true;
  24226. classStart = i;
  24227. reClassStart = re.length;
  24228. re += c;
  24229. continue;
  24230. case "]":
  24231. // a right bracket shall lose its special
  24232. // meaning and represent itself in
  24233. // a bracket expression if it occurs
  24234. // first in the list. -- POSIX.2 2.8.3.2
  24235. if (i === classStart + 1 || !inClass) {
  24236. re += "\\" + c;
  24237. escaping = false;
  24238. continue;
  24239. } // finish up the class.
  24240. hasMagic = true;
  24241. inClass = false;
  24242. re += c;
  24243. continue;
  24244. default:
  24245. // swallow any state char that wasn't consumed
  24246. clearStateChar();
  24247. if (escaping) {
  24248. // no need
  24249. escaping = false;
  24250. } else if (reSpecials[c] && !(c === "^" && inClass)) {
  24251. re += "\\";
  24252. }
  24253. re += c;
  24254. } // switch
  24255. } // for
  24256. // handle the case where we left a class open.
  24257. // "[abc" is valid, equivalent to "\[abc"
  24258. if (inClass) {
  24259. // split where the last [ was, and escape it
  24260. // this is a huge pita. We now have to re-walk
  24261. // the contents of the would-be class to re-translate
  24262. // any characters that were passed through as-is
  24263. var cs = pattern.substr(classStart + 1),
  24264. sp = this.parse(cs, SUBPARSE);
  24265. re = re.substr(0, reClassStart) + "\\[" + sp[0];
  24266. hasMagic = hasMagic || sp[1];
  24267. } // handle the case where we had a +( thing at the *end*
  24268. // of the pattern.
  24269. // each pattern list stack adds 3 chars, and we need to go through
  24270. // and escape any | chars that were passed through as-is for the regexp.
  24271. // Go through and escape them, taking care not to double-escape any
  24272. // | chars that were already escaped.
  24273. var pl;
  24274. while (pl = patternListStack.pop()) {
  24275. var tail = re.slice(pl.reStart + 3); // maybe some even number of \, then maybe 1 \, followed by a |
  24276. tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
  24277. if (!$2) {
  24278. // the | isn't already escaped, so escape it.
  24279. $2 = "\\";
  24280. } // need to escape all those slashes *again*, without escaping the
  24281. // one that we need for escaping the | character. As it works out,
  24282. // escaping an even number of slashes can be done by simply repeating
  24283. // it exactly after itself. That's why this trick works.
  24284. //
  24285. // I am sorry that you have to see this.
  24286. return $1 + $1 + $2 + "|";
  24287. }); // console.error("tail=%j\n %s", tail, tail)
  24288. var t = pl.type === "*" ? star : pl.type === "?" ? qmark : "\\" + pl.type;
  24289. hasMagic = true;
  24290. re = re.slice(0, pl.reStart) + t + "\\(" + tail;
  24291. } // handle trailing things that only matter at the very end.
  24292. clearStateChar();
  24293. if (escaping) {
  24294. // trailing \\
  24295. re += "\\\\";
  24296. } // only need to apply the nodot start if the re starts with
  24297. // something that could conceivably capture a dot
  24298. var addPatternStart = false;
  24299. switch (re.charAt(0)) {
  24300. case ".":
  24301. case "[":
  24302. case "(":
  24303. addPatternStart = true;
  24304. } // if the re is not "" at this point, then we need to make sure
  24305. // it doesn't match against an empty path part.
  24306. // Otherwise a/* will match a/, which it should not.
  24307. if (re !== "" && hasMagic) re = "(?=.)" + re;
  24308. if (addPatternStart) re = patternStart + re; // parsing just a piece of a larger pattern.
  24309. if (isSub === SUBPARSE) {
  24310. return [re, hasMagic];
  24311. } // skip the regexp for non-magical patterns
  24312. // unescape anything in it, though, so that it'll be
  24313. // an exact match against a file etc.
  24314. if (!hasMagic) {
  24315. return globUnescape(pattern);
  24316. }
  24317. var flags = options.nocase ? "i" : "",
  24318. regExp = new RegExp("^" + re + "$", flags);
  24319. regExp._glob = pattern;
  24320. regExp._src = re;
  24321. return regExp;
  24322. }
  24323. minimatch.makeRe = function (pattern, options) {
  24324. return new Minimatch(pattern, options || {}).makeRe();
  24325. };
  24326. Minimatch.prototype.makeRe = makeRe;
  24327. function makeRe() {
  24328. if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
  24329. // pattern strings, or "**".
  24330. //
  24331. // It's better to use .match(). This function shouldn't
  24332. // be used, really, but it's pretty convenient sometimes,
  24333. // when you just want to work with a regex.
  24334. var set = this.set;
  24335. if (!set.length) return this.regexp = false;
  24336. var options = this.options;
  24337. var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot,
  24338. flags = options.nocase ? "i" : "";
  24339. var re = set.map(function (pattern) {
  24340. return pattern.map(function (p) {
  24341. return p === GLOBSTAR ? twoStar : typeof p === "string" ? regExpEscape(p) : p._src;
  24342. }).join("\\\/");
  24343. }).join("|"); // must match entire pattern
  24344. // ending in a * or ** will make it less strict.
  24345. re = "^(?:" + re + ")$"; // can match anything, as long as it's not this.
  24346. if (this.negate) re = "^(?!" + re + ").*$";
  24347. try {
  24348. return this.regexp = new RegExp(re, flags);
  24349. } catch (ex) {
  24350. return this.regexp = false;
  24351. }
  24352. }
  24353. minimatch.match = function (list, pattern, options) {
  24354. var mm = new Minimatch(pattern, options);
  24355. list = list.filter(function (f) {
  24356. return mm.match(f);
  24357. });
  24358. if (options.nonull && !list.length) {
  24359. list.push(pattern);
  24360. }
  24361. return list;
  24362. };
  24363. Minimatch.prototype.match = match;
  24364. function match(f, partial) {
  24365. // console.error("match", f, this.pattern)
  24366. // short-circuit in the case of busted things.
  24367. // comments, etc.
  24368. if (this.comment) return false;
  24369. if (this.empty) return f === "";
  24370. if (f === "/" && partial) return true;
  24371. var options = this.options; // windows: need to use /, not \
  24372. // On other platforms, \ is a valid (albeit bad) filename char.
  24373. if (platform === "win32") {
  24374. f = f.split("\\").join("/");
  24375. } // treat the test path as a set of pathparts.
  24376. f = f.split(slashSplit);
  24377. if (options.debug) {
  24378. console.error(this.pattern, "split", f);
  24379. } // just ONE of the pattern sets in this.set needs to match
  24380. // in order for it to be valid. If negating, then just one
  24381. // match means that we have failed.
  24382. // Either way, return on the first hit.
  24383. var set = this.set; // console.error(this.pattern, "set", set)
  24384. for (var i = 0, l = set.length; i < l; i++) {
  24385. var pattern = set[i];
  24386. var hit = this.matchOne(f, pattern, partial);
  24387. if (hit) {
  24388. if (options.flipNegate) return true;
  24389. return !this.negate;
  24390. }
  24391. } // didn't get any hits. this is success if it's a negative
  24392. // pattern, failure otherwise.
  24393. if (options.flipNegate) return false;
  24394. return this.negate;
  24395. } // set partial to true to test if, for example,
  24396. // "/a/b" matches the start of "/*/b/*/d"
  24397. // Partial means, if you run out of file before you run
  24398. // out of pattern, then that's fine, as long as all
  24399. // the parts match.
  24400. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  24401. var options = this.options;
  24402. if (options.debug) {
  24403. console.error("matchOne", {
  24404. "this": this,
  24405. file: file,
  24406. pattern: pattern
  24407. });
  24408. }
  24409. if (options.matchBase && pattern.length === 1) {
  24410. file = path.basename(file.join("/")).split("/");
  24411. }
  24412. if (options.debug) {
  24413. console.error("matchOne", file.length, pattern.length);
  24414. }
  24415. for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
  24416. if (options.debug) {
  24417. console.error("matchOne loop");
  24418. }
  24419. var p = pattern[pi],
  24420. f = file[fi];
  24421. if (options.debug) {
  24422. console.error(pattern, p, f);
  24423. } // should be impossible.
  24424. // some invalid regexp stuff in the set.
  24425. if (p === false) return false;
  24426. if (p === GLOBSTAR) {
  24427. if (options.debug) console.error('GLOBSTAR', [pattern, p, f]); // "**"
  24428. // a/**/b/**/c would match the following:
  24429. // a/b/x/y/z/c
  24430. // a/x/y/z/b/c
  24431. // a/b/x/b/x/c
  24432. // a/b/c
  24433. // To do this, take the rest of the pattern after
  24434. // the **, and see if it would match the file remainder.
  24435. // If so, return success.
  24436. // If not, the ** "swallows" a segment, and try again.
  24437. // This is recursively awful.
  24438. //
  24439. // a/**/b/**/c matching a/b/x/y/z/c
  24440. // - a matches a
  24441. // - doublestar
  24442. // - matchOne(b/x/y/z/c, b/**/c)
  24443. // - b matches b
  24444. // - doublestar
  24445. // - matchOne(x/y/z/c, c) -> no
  24446. // - matchOne(y/z/c, c) -> no
  24447. // - matchOne(z/c, c) -> no
  24448. // - matchOne(c, c) yes, hit
  24449. var fr = fi,
  24450. pr = pi + 1;
  24451. if (pr === pl) {
  24452. if (options.debug) console.error('** at the end'); // a ** at the end will just swallow the rest.
  24453. // We have found a match.
  24454. // however, it will not swallow /.x, unless
  24455. // options.dot is set.
  24456. // . and .. are *never* matched by **, for explosively
  24457. // exponential reasons.
  24458. for (; fi < fl; fi++) {
  24459. if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".") return false;
  24460. }
  24461. return true;
  24462. } // ok, let's see if we can swallow whatever we can.
  24463. WHILE: while (fr < fl) {
  24464. var swallowee = file[fr];
  24465. if (options.debug) {
  24466. console.error('\nglobstar while', file, fr, pattern, pr, swallowee);
  24467. } // XXX remove this slice. Just pass the start index.
  24468. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  24469. if (options.debug) console.error('globstar found match!', fr, fl, swallowee); // found a match.
  24470. return true;
  24471. } else {
  24472. // can't swallow "." or ".." ever.
  24473. // can only swallow ".foo" when explicitly asked.
  24474. if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
  24475. if (options.debug) console.error("dot detected!", file, fr, pattern, pr);
  24476. break WHILE;
  24477. } // ** swallows a segment, and continue.
  24478. if (options.debug) console.error('globstar swallow a segment, and continue');
  24479. fr++;
  24480. }
  24481. } // no match was found.
  24482. // However, in partial mode, we can't say this is necessarily over.
  24483. // If there's more *pattern* left, then
  24484. if (partial) {
  24485. // ran out of file
  24486. // console.error("\n>>> no match, partial?", file, fr, pattern, pr)
  24487. if (fr === fl) return true;
  24488. }
  24489. return false;
  24490. } // something other than **
  24491. // non-magic patterns just have to match exactly
  24492. // patterns with magic have been turned into regexps.
  24493. var hit;
  24494. if (typeof p === "string") {
  24495. if (options.nocase) {
  24496. hit = f.toLowerCase() === p.toLowerCase();
  24497. } else {
  24498. hit = f === p;
  24499. }
  24500. if (options.debug) {
  24501. console.error("string match", p, f, hit);
  24502. }
  24503. } else {
  24504. hit = f.match(p);
  24505. if (options.debug) {
  24506. console.error("pattern match", p, f, hit);
  24507. }
  24508. }
  24509. if (!hit) return false;
  24510. } // Note: ending in / means that we'll get a final ""
  24511. // at the end of the pattern. This can only match a
  24512. // corresponding "" at the end of the file.
  24513. // If the file ends in /, then it can only match a
  24514. // a pattern that ends in /, unless the pattern just
  24515. // doesn't have any more for it. But, a/b/ should *not*
  24516. // match "a/b/*", even though "" matches against the
  24517. // [^/]*? pattern, except in partial mode, where it might
  24518. // simply not be reached yet.
  24519. // However, a/b/ should still satisfy a/*
  24520. // now either we fell off the end of the pattern, or we're done.
  24521. if (fi === fl && pi === pl) {
  24522. // ran out of pattern and filename at the same time.
  24523. // an exact hit!
  24524. return true;
  24525. } else if (fi === fl) {
  24526. // ran out of file, but still had pattern left.
  24527. // this is ok if we're doing the match as part of
  24528. // a glob fs traversal.
  24529. return partial;
  24530. } else if (pi === pl) {
  24531. // ran out of pattern, still have file left.
  24532. // this is only acceptable if we're on the very last
  24533. // empty segment of a file with a trailing slash.
  24534. // a/* should match a/b/
  24535. var emptyFileEnd = fi === fl - 1 && file[fi] === "";
  24536. return emptyFileEnd;
  24537. } // should be unreachable.
  24538. throw new Error("wtf?");
  24539. }; // replace stuff like \* with *
  24540. function globUnescape(s) {
  24541. return s.replace(/\\(.)/g, "$1");
  24542. }
  24543. function regExpEscape(s) {
  24544. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
  24545. }
  24546. });
  24547. var ini = createCommonjsModule(function (module, exports) {
  24548. "use strict"; // Based on iniparser by shockie <https://npmjs.org/package/iniparser>
  24549. var __awaiter = commonjsGlobal && commonjsGlobal.__awaiter || function (thisArg, _arguments, P, generator) {
  24550. return new (P || (P = Promise))(function (resolve, reject) {
  24551. function fulfilled(value) {
  24552. try {
  24553. step(generator.next(value));
  24554. } catch (e) {
  24555. reject(e);
  24556. }
  24557. }
  24558. function rejected(value) {
  24559. try {
  24560. step(generator["throw"](value));
  24561. } catch (e) {
  24562. reject(e);
  24563. }
  24564. }
  24565. function step(result) {
  24566. result.done ? resolve(result.value) : new P(function (resolve) {
  24567. resolve(result.value);
  24568. }).then(fulfilled, rejected);
  24569. }
  24570. step((generator = generator.apply(thisArg, _arguments || [])).next());
  24571. });
  24572. };
  24573. var __generator = commonjsGlobal && commonjsGlobal.__generator || function (thisArg, body) {
  24574. var _ = {
  24575. label: 0,
  24576. sent: function sent() {
  24577. if (t[0] & 1) throw t[1];
  24578. return t[1];
  24579. },
  24580. trys: [],
  24581. ops: []
  24582. },
  24583. f,
  24584. y,
  24585. t,
  24586. g;
  24587. return g = {
  24588. next: verb(0),
  24589. "throw": verb(1),
  24590. "return": verb(2)
  24591. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  24592. return this;
  24593. }), g;
  24594. function verb(n) {
  24595. return function (v) {
  24596. return step([n, v]);
  24597. };
  24598. }
  24599. function step(op) {
  24600. if (f) throw new TypeError("Generator is already executing.");
  24601. while (_) {
  24602. try {
  24603. if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
  24604. if (y = 0, t) op = [0, t.value];
  24605. switch (op[0]) {
  24606. case 0:
  24607. case 1:
  24608. t = op;
  24609. break;
  24610. case 4:
  24611. _.label++;
  24612. return {
  24613. value: op[1],
  24614. done: false
  24615. };
  24616. case 5:
  24617. _.label++;
  24618. y = op[1];
  24619. op = [0];
  24620. continue;
  24621. case 7:
  24622. op = _.ops.pop();
  24623. _.trys.pop();
  24624. continue;
  24625. default:
  24626. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  24627. _ = 0;
  24628. continue;
  24629. }
  24630. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  24631. _.label = op[1];
  24632. break;
  24633. }
  24634. if (op[0] === 6 && _.label < t[1]) {
  24635. _.label = t[1];
  24636. t = op;
  24637. break;
  24638. }
  24639. if (t && _.label < t[2]) {
  24640. _.label = t[2];
  24641. _.ops.push(op);
  24642. break;
  24643. }
  24644. if (t[2]) _.ops.pop();
  24645. _.trys.pop();
  24646. continue;
  24647. }
  24648. op = body.call(thisArg, _);
  24649. } catch (e) {
  24650. op = [6, e];
  24651. y = 0;
  24652. } finally {
  24653. f = t = 0;
  24654. }
  24655. }
  24656. if (op[0] & 5) throw op[1];
  24657. return {
  24658. value: op[0] ? op[1] : void 0,
  24659. done: true
  24660. };
  24661. }
  24662. };
  24663. Object.defineProperty(exports, "__esModule", {
  24664. value: true
  24665. });
  24666. /**
  24667. * define the possible values:
  24668. * section: [section]
  24669. * param: key=value
  24670. * comment: ;this is a comment
  24671. */
  24672. var regex = {
  24673. section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
  24674. param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
  24675. comment: /^\s*[#;].*$/
  24676. };
  24677. /**
  24678. * Parses an .ini file
  24679. * @param file The location of the .ini file
  24680. */
  24681. function parse(file) {
  24682. return __awaiter(this, void 0, void 0, function () {
  24683. return __generator(this, function (_a) {
  24684. return [2
  24685. /*return*/
  24686. , new Promise(function (resolve, reject) {
  24687. fs.readFile(file, 'utf8', function (err, data) {
  24688. if (err) {
  24689. reject(err);
  24690. return;
  24691. }
  24692. resolve(parseString(data));
  24693. });
  24694. })];
  24695. });
  24696. });
  24697. }
  24698. exports.parse = parse;
  24699. function parseSync(file) {
  24700. return parseString(fs.readFileSync(file, 'utf8'));
  24701. }
  24702. exports.parseSync = parseSync;
  24703. function parseString(data) {
  24704. var sectionBody = {};
  24705. var sectionName = null;
  24706. var value = [[sectionName, sectionBody]];
  24707. var lines = data.split(/\r\n|\r|\n/);
  24708. lines.forEach(function (line) {
  24709. var match;
  24710. if (regex.comment.test(line)) {
  24711. return;
  24712. }
  24713. if (regex.param.test(line)) {
  24714. match = line.match(regex.param);
  24715. sectionBody[match[1]] = match[2];
  24716. } else if (regex.section.test(line)) {
  24717. match = line.match(regex.section);
  24718. sectionName = match[1];
  24719. sectionBody = {};
  24720. value.push([sectionName, sectionBody]);
  24721. }
  24722. });
  24723. return value;
  24724. }
  24725. exports.parseString = parseString;
  24726. });
  24727. unwrapExports(ini);
  24728. var name$1 = "editorconfig";
  24729. var version$3 = "0.15.0";
  24730. var description$1 = "EditorConfig File Locator and Interpreter for Node.js";
  24731. var keywords = ["editorconfig", "core"];
  24732. var main$1 = "index.js";
  24733. var bin$1 = {
  24734. "editorconfig": "bin/editorconfig"
  24735. };
  24736. var contributors = ["Hong Xu (topbug.net)", "Jed Mao (https://github.com/jedmao/)", "Trey Hunner (http://treyhunner.com)"];
  24737. var directories = {
  24738. "bin": "./bin",
  24739. "lib": "./lib"
  24740. };
  24741. var scripts$1 = {
  24742. "clean": "rimraf dist",
  24743. "prebuild": "npm run clean",
  24744. "build": "tsc",
  24745. "pretest": "npm run lint && npm run build && npm run copy && cmake .",
  24746. "test": "ctest .",
  24747. "pretest:ci": "npm run pretest",
  24748. "test:ci": "ctest -VV --output-on-failure .",
  24749. "lint": "npm run eclint && npm run tslint",
  24750. "eclint": "eclint check --indent_size ignore \"src/**\"",
  24751. "tslint": "tslint --project tslint.json",
  24752. "copy": "cpy package.json .npmignore LICENSE README.md CHANGELOG.md dist && cpy src/bin/* dist/bin && cpy src/lib/fnmatch*.* dist/lib",
  24753. "prepub": "npm run lint && npm run build && npm run copy",
  24754. "pub": "npm publish ./dist"
  24755. };
  24756. var repository$1 = {
  24757. "type": "git",
  24758. "url": "git://github.com/editorconfig/editorconfig-core-js.git"
  24759. };
  24760. var bugs = "https://github.com/editorconfig/editorconfig-core-js/issues";
  24761. var author$1 = "EditorConfig Team";
  24762. var license$1 = "MIT";
  24763. var dependencies$1 = {
  24764. "@types/commander": "^2.11.0",
  24765. "@types/semver": "^5.4.0",
  24766. "commander": "^2.11.0",
  24767. "lru-cache": "^4.1.1",
  24768. "semver": "^5.4.1",
  24769. "sigmund": "^1.0.1"
  24770. };
  24771. var devDependencies$1 = {
  24772. "@types/mocha": "^2.2.43",
  24773. "cpy-cli": "^1.0.1",
  24774. "eclint": "^2.4.3",
  24775. "mocha": "^4.0.1",
  24776. "rimraf": "^2.6.2",
  24777. "should": "^13.1.2",
  24778. "tslint": "^5.7.0",
  24779. "typescript": "^2.5.3"
  24780. };
  24781. var _package$2 = {
  24782. name: name$1,
  24783. version: version$3,
  24784. description: description$1,
  24785. keywords: keywords,
  24786. main: main$1,
  24787. bin: bin$1,
  24788. contributors: contributors,
  24789. directories: directories,
  24790. scripts: scripts$1,
  24791. repository: repository$1,
  24792. bugs: bugs,
  24793. author: author$1,
  24794. license: license$1,
  24795. dependencies: dependencies$1,
  24796. devDependencies: devDependencies$1
  24797. };
  24798. var _package$3 = Object.freeze({
  24799. name: name$1,
  24800. version: version$3,
  24801. description: description$1,
  24802. keywords: keywords,
  24803. main: main$1,
  24804. bin: bin$1,
  24805. contributors: contributors,
  24806. directories: directories,
  24807. scripts: scripts$1,
  24808. repository: repository$1,
  24809. bugs: bugs,
  24810. author: author$1,
  24811. license: license$1,
  24812. dependencies: dependencies$1,
  24813. devDependencies: devDependencies$1,
  24814. default: _package$2
  24815. });
  24816. var pkg = ( _package$3 && _package$2 ) || _package$3;
  24817. var editorconfig = createCommonjsModule(function (module, exports) {
  24818. "use strict";
  24819. var __awaiter = commonjsGlobal && commonjsGlobal.__awaiter || function (thisArg, _arguments, P, generator) {
  24820. return new (P || (P = Promise))(function (resolve, reject) {
  24821. function fulfilled(value) {
  24822. try {
  24823. step(generator.next(value));
  24824. } catch (e) {
  24825. reject(e);
  24826. }
  24827. }
  24828. function rejected(value) {
  24829. try {
  24830. step(generator["throw"](value));
  24831. } catch (e) {
  24832. reject(e);
  24833. }
  24834. }
  24835. function step(result) {
  24836. result.done ? resolve(result.value) : new P(function (resolve) {
  24837. resolve(result.value);
  24838. }).then(fulfilled, rejected);
  24839. }
  24840. step((generator = generator.apply(thisArg, _arguments || [])).next());
  24841. });
  24842. };
  24843. var __generator = commonjsGlobal && commonjsGlobal.__generator || function (thisArg, body) {
  24844. var _ = {
  24845. label: 0,
  24846. sent: function sent() {
  24847. if (t[0] & 1) throw t[1];
  24848. return t[1];
  24849. },
  24850. trys: [],
  24851. ops: []
  24852. },
  24853. f,
  24854. y,
  24855. t,
  24856. g;
  24857. return g = {
  24858. next: verb(0),
  24859. "throw": verb(1),
  24860. "return": verb(2)
  24861. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  24862. return this;
  24863. }), g;
  24864. function verb(n) {
  24865. return function (v) {
  24866. return step([n, v]);
  24867. };
  24868. }
  24869. function step(op) {
  24870. if (f) throw new TypeError("Generator is already executing.");
  24871. while (_) {
  24872. try {
  24873. if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
  24874. if (y = 0, t) op = [0, t.value];
  24875. switch (op[0]) {
  24876. case 0:
  24877. case 1:
  24878. t = op;
  24879. break;
  24880. case 4:
  24881. _.label++;
  24882. return {
  24883. value: op[1],
  24884. done: false
  24885. };
  24886. case 5:
  24887. _.label++;
  24888. y = op[1];
  24889. op = [0];
  24890. continue;
  24891. case 7:
  24892. op = _.ops.pop();
  24893. _.trys.pop();
  24894. continue;
  24895. default:
  24896. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  24897. _ = 0;
  24898. continue;
  24899. }
  24900. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  24901. _.label = op[1];
  24902. break;
  24903. }
  24904. if (op[0] === 6 && _.label < t[1]) {
  24905. _.label = t[1];
  24906. t = op;
  24907. break;
  24908. }
  24909. if (t && _.label < t[2]) {
  24910. _.label = t[2];
  24911. _.ops.push(op);
  24912. break;
  24913. }
  24914. if (t[2]) _.ops.pop();
  24915. _.trys.pop();
  24916. continue;
  24917. }
  24918. op = body.call(thisArg, _);
  24919. } catch (e) {
  24920. op = [6, e];
  24921. y = 0;
  24922. } finally {
  24923. f = t = 0;
  24924. }
  24925. }
  24926. if (op[0] & 5) throw op[1];
  24927. return {
  24928. value: op[0] ? op[1] : void 0,
  24929. done: true
  24930. };
  24931. }
  24932. };
  24933. Object.defineProperty(exports, "__esModule", {
  24934. value: true
  24935. });
  24936. exports.parseString = ini.parseString; // tslint:disable-next-line:no-var-requires
  24937. var knownProps = {
  24938. end_of_line: true,
  24939. indent_style: true,
  24940. indent_size: true,
  24941. insert_final_newline: true,
  24942. trim_trailing_whitespace: true,
  24943. charset: true
  24944. };
  24945. function fnmatch$$1(filepath, glob) {
  24946. var matchOptions = {
  24947. matchBase: true,
  24948. dot: true,
  24949. noext: true
  24950. };
  24951. glob = glob.replace(/\*\*/g, '{*,**/**/**}');
  24952. return fnmatch(filepath, glob, matchOptions);
  24953. }
  24954. function getConfigFileNames(filepath, options) {
  24955. var paths = [];
  24956. do {
  24957. filepath = path.dirname(filepath);
  24958. paths.push(path.join(filepath, options.config));
  24959. } while (filepath !== options.root);
  24960. return paths;
  24961. }
  24962. function processMatches(matches, version) {
  24963. // Set indent_size to 'tab' if indent_size is unspecified and
  24964. // indent_style is set to 'tab'.
  24965. if ('indent_style' in matches && matches.indent_style === 'tab' && !('indent_size' in matches) && semver$3.gte(version, '0.10.0')) {
  24966. matches.indent_size = 'tab';
  24967. } // Set tab_width to indent_size if indent_size is specified and
  24968. // tab_width is unspecified
  24969. if ('indent_size' in matches && !('tab_width' in matches) && matches.indent_size !== 'tab') {
  24970. matches.tab_width = matches.indent_size;
  24971. } // Set indent_size to tab_width if indent_size is 'tab'
  24972. if ('indent_size' in matches && 'tab_width' in matches && matches.indent_size === 'tab') {
  24973. matches.indent_size = matches.tab_width;
  24974. }
  24975. return matches;
  24976. }
  24977. function processOptions(options, filepath) {
  24978. if (options === void 0) {
  24979. options = {};
  24980. }
  24981. return {
  24982. config: options.config || '.editorconfig',
  24983. version: options.version || pkg.version,
  24984. root: path.resolve(options.root || path.parse(filepath).root)
  24985. };
  24986. }
  24987. function buildFullGlob(pathPrefix, glob) {
  24988. switch (glob.indexOf('/')) {
  24989. case -1:
  24990. glob = '**/' + glob;
  24991. break;
  24992. case 0:
  24993. glob = glob.substring(1);
  24994. break;
  24995. default:
  24996. break;
  24997. }
  24998. return path.join(pathPrefix, glob);
  24999. }
  25000. function extendProps(props, options) {
  25001. if (props === void 0) {
  25002. props = {};
  25003. }
  25004. if (options === void 0) {
  25005. options = {};
  25006. }
  25007. for (var key in options) {
  25008. if (options.hasOwnProperty(key)) {
  25009. var value = options[key];
  25010. var key2 = key.toLowerCase();
  25011. var value2 = value;
  25012. if (knownProps[key2]) {
  25013. value2 = value.toLowerCase();
  25014. }
  25015. try {
  25016. value2 = JSON.parse(value);
  25017. } catch (e) {}
  25018. if (typeof value === 'undefined' || value === null) {
  25019. // null and undefined are values specific to JSON (no special meaning
  25020. // in editorconfig) & should just be returned as regular strings.
  25021. value2 = String(value);
  25022. }
  25023. props[key2] = value2;
  25024. }
  25025. }
  25026. return props;
  25027. }
  25028. function parseFromConfigs(configs, filepath, options) {
  25029. return processMatches(configs.reverse().reduce(function (matches, file) {
  25030. var pathPrefix = path.dirname(file.name);
  25031. file.contents.forEach(function (section) {
  25032. var glob = section[0];
  25033. var options2 = section[1];
  25034. if (!glob) {
  25035. return;
  25036. }
  25037. var fullGlob = buildFullGlob(pathPrefix, glob);
  25038. if (!fnmatch$$1(filepath, fullGlob)) {
  25039. return;
  25040. }
  25041. matches = extendProps(matches, options2);
  25042. });
  25043. return matches;
  25044. }, {}), options.version);
  25045. }
  25046. function getConfigsForFiles(files) {
  25047. var configs = [];
  25048. for (var i in files) {
  25049. if (files.hasOwnProperty(i)) {
  25050. var file = files[i];
  25051. var contents = ini.parseString(file.contents);
  25052. configs.push({
  25053. name: file.name,
  25054. contents: contents
  25055. });
  25056. if ((contents[0][1].root || '').toLowerCase() === 'true') {
  25057. break;
  25058. }
  25059. }
  25060. }
  25061. return configs;
  25062. }
  25063. function readConfigFiles(filepaths) {
  25064. return __awaiter(this, void 0, void 0, function () {
  25065. return __generator(this, function (_a) {
  25066. return [2
  25067. /*return*/
  25068. , Promise.all(filepaths.map(function (name) {
  25069. return new Promise(function (resolve) {
  25070. fs.readFile(name, 'utf8', function (err, data) {
  25071. resolve({
  25072. name: name,
  25073. contents: err ? '' : data
  25074. });
  25075. });
  25076. });
  25077. }))];
  25078. });
  25079. });
  25080. }
  25081. function readConfigFilesSync(filepaths) {
  25082. var files = [];
  25083. var file;
  25084. filepaths.forEach(function (filepath) {
  25085. try {
  25086. file = fs.readFileSync(filepath, 'utf8');
  25087. } catch (e) {
  25088. file = '';
  25089. }
  25090. files.push({
  25091. name: filepath,
  25092. contents: file
  25093. });
  25094. });
  25095. return files;
  25096. }
  25097. function opts(filepath, options) {
  25098. if (options === void 0) {
  25099. options = {};
  25100. }
  25101. var resolvedFilePath = path.resolve(filepath);
  25102. return [resolvedFilePath, processOptions(options, resolvedFilePath)];
  25103. }
  25104. function parseFromFiles(filepath, files, options) {
  25105. if (options === void 0) {
  25106. options = {};
  25107. }
  25108. return __awaiter(this, void 0, void 0, function () {
  25109. var _a, resolvedFilePath, processedOptions;
  25110. return __generator(this, function (_b) {
  25111. _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
  25112. return [2
  25113. /*return*/
  25114. , files.then(getConfigsForFiles).then(function (configs) {
  25115. return parseFromConfigs(configs, resolvedFilePath, processedOptions);
  25116. })];
  25117. });
  25118. });
  25119. }
  25120. exports.parseFromFiles = parseFromFiles;
  25121. function parseFromFilesSync(filepath, files, options) {
  25122. if (options === void 0) {
  25123. options = {};
  25124. }
  25125. var _a = opts(filepath, options),
  25126. resolvedFilePath = _a[0],
  25127. processedOptions = _a[1];
  25128. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  25129. }
  25130. exports.parseFromFilesSync = parseFromFilesSync;
  25131. function parse(_filepath, _options) {
  25132. if (_options === void 0) {
  25133. _options = {};
  25134. }
  25135. return __awaiter(this, void 0, void 0, function () {
  25136. var _a, resolvedFilePath, processedOptions, filepaths;
  25137. return __generator(this, function (_b) {
  25138. _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
  25139. filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  25140. return [2
  25141. /*return*/
  25142. , readConfigFiles(filepaths).then(getConfigsForFiles).then(function (configs) {
  25143. return parseFromConfigs(configs, resolvedFilePath, processedOptions);
  25144. })];
  25145. });
  25146. });
  25147. }
  25148. exports.parse = parse;
  25149. function parseSync(_filepath, _options) {
  25150. if (_options === void 0) {
  25151. _options = {};
  25152. }
  25153. var _a = opts(_filepath, _options),
  25154. resolvedFilePath = _a[0],
  25155. processedOptions = _a[1];
  25156. var filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  25157. var files = readConfigFilesSync(filepaths);
  25158. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  25159. }
  25160. exports.parseSync = parseSync;
  25161. });
  25162. unwrapExports(editorconfig);
  25163. var editorconfigToPrettier = editorConfigToPrettier;
  25164. function editorConfigToPrettier(editorConfig) {
  25165. if (!editorConfig || Object.keys(editorConfig).length === 0) {
  25166. return null;
  25167. }
  25168. var result = {};
  25169. if (editorConfig.indent_style) {
  25170. result.useTabs = editorConfig.indent_style === "tab";
  25171. }
  25172. if (editorConfig.indent_size === "tab") {
  25173. result.useTabs = true;
  25174. }
  25175. if (result.useTabs && editorConfig.tab_width) {
  25176. result.tabWidth = editorConfig.tab_width;
  25177. } else if (editorConfig.indent_style === "space" && editorConfig.indent_size && editorConfig.indent_size !== "tab") {
  25178. result.tabWidth = editorConfig.indent_size;
  25179. } else if (editorConfig.tab_width !== undefined) {
  25180. result.tabWidth = editorConfig.tab_width;
  25181. }
  25182. if (editorConfig.max_line_length && editorConfig.max_line_length !== "off") {
  25183. result.printWidth = editorConfig.max_line_length;
  25184. }
  25185. if (editorConfig.quote_type === "single") {
  25186. result.singleQuote = true;
  25187. } else if (editorConfig.quote_type === "double") {
  25188. result.singleQuote = false;
  25189. }
  25190. return result;
  25191. }
  25192. function markerExists(files, markers) {
  25193. return markers.some(function (marker) {
  25194. return files.some(function (file) {
  25195. return file === marker;
  25196. });
  25197. });
  25198. }
  25199. function traverseFolder(directory, levels, markers) {
  25200. var files = fs.readdirSync(directory);
  25201. if (levels === 0) {
  25202. return null;
  25203. } else if (markerExists(files, markers)) {
  25204. return directory;
  25205. } else {
  25206. return traverseFolder(path.resolve(directory, '..'), levels - 1, markers);
  25207. }
  25208. }
  25209. var findProjectRoot = function findRoot(dir, opts) {
  25210. if (!dir) throw new Error("Directory not defined");
  25211. opts = opts || {};
  25212. var levels = opts.maxDepth || findRoot.MAX_DEPTH;
  25213. var markers = opts.markers || findRoot.MARKERS;
  25214. return traverseFolder(dir, levels, markers);
  25215. };
  25216. var MAX_DEPTH = 9;
  25217. var MARKERS = ['.git', '.hg'];
  25218. findProjectRoot.MAX_DEPTH = MAX_DEPTH;
  25219. findProjectRoot.MARKERS = MARKERS;
  25220. var resolveConfigEditorconfig = createCommonjsModule(function (module) {
  25221. "use strict";
  25222. var maybeParse = function maybeParse(filePath, config, parse) {
  25223. var root = findProjectRoot(path.dirname(path.resolve(filePath)));
  25224. return filePath && parse(filePath, {
  25225. root
  25226. });
  25227. };
  25228. var editorconfigAsyncNoCache = function editorconfigAsyncNoCache(filePath, config) {
  25229. return Promise.resolve(maybeParse(filePath, config, editorconfig.parse)).then(editorconfigToPrettier);
  25230. };
  25231. var editorconfigAsyncWithCache = mem(editorconfigAsyncNoCache);
  25232. var editorconfigSyncNoCache = function editorconfigSyncNoCache(filePath, config) {
  25233. return editorconfigToPrettier(maybeParse(filePath, config, editorconfig.parseSync));
  25234. };
  25235. var editorconfigSyncWithCache = mem(editorconfigSyncNoCache);
  25236. function getLoadFunction(opts) {
  25237. if (!opts.editorconfig) {
  25238. return function () {
  25239. return null;
  25240. };
  25241. }
  25242. if (opts.sync) {
  25243. return opts.cache ? editorconfigSyncWithCache : editorconfigSyncNoCache;
  25244. }
  25245. return opts.cache ? editorconfigAsyncWithCache : editorconfigAsyncNoCache;
  25246. }
  25247. function clearCache() {
  25248. mem.clear(editorconfigSyncWithCache);
  25249. mem.clear(editorconfigAsyncWithCache);
  25250. }
  25251. module.exports = {
  25252. getLoadFunction,
  25253. clearCache
  25254. };
  25255. });
  25256. var resolveConfig_1 = createCommonjsModule(function (module) {
  25257. "use strict";
  25258. var getExplorerMemoized = mem(function (opts) {
  25259. return thirdParty$1.cosmiconfig("prettier", {
  25260. sync: opts.sync,
  25261. cache: opts.cache,
  25262. rcExtensions: true,
  25263. transform: function transform(result) {
  25264. if (result && result.config) {
  25265. delete result.config.$schema;
  25266. }
  25267. return result;
  25268. }
  25269. });
  25270. });
  25271. /** @param {{ cache: boolean, sync: boolean }} opts */
  25272. function getLoadFunction(opts) {
  25273. // Normalize opts before passing to a memoized function
  25274. opts = Object.assign({
  25275. sync: false,
  25276. cache: false
  25277. }, opts);
  25278. return getExplorerMemoized(opts).load;
  25279. }
  25280. function _resolveConfig(filePath, opts, sync) {
  25281. opts = Object.assign({
  25282. useCache: true
  25283. }, opts);
  25284. var loadOpts = {
  25285. cache: !!opts.useCache,
  25286. sync: !!sync,
  25287. editorconfig: !!opts.editorconfig
  25288. };
  25289. var load = getLoadFunction(loadOpts);
  25290. var loadEditorConfig = resolveConfigEditorconfig.getLoadFunction(loadOpts);
  25291. var arr = [load, loadEditorConfig].map(function (l) {
  25292. return l(filePath, opts.config);
  25293. });
  25294. var unwrapAndMerge = function unwrapAndMerge(arr) {
  25295. var result = arr[0];
  25296. var editorConfigured = arr[1];
  25297. var merged = Object.assign({}, editorConfigured, mergeOverrides(Object.assign({}, result), filePath));
  25298. if (!result && !editorConfigured) {
  25299. return null;
  25300. }
  25301. return merged;
  25302. };
  25303. if (loadOpts.sync) {
  25304. return unwrapAndMerge(arr);
  25305. }
  25306. return Promise.all(arr).then(unwrapAndMerge);
  25307. }
  25308. var resolveConfig = function resolveConfig(filePath, opts) {
  25309. return _resolveConfig(filePath, opts, false);
  25310. };
  25311. resolveConfig.sync = function (filePath, opts) {
  25312. return _resolveConfig(filePath, opts, true);
  25313. };
  25314. function clearCache() {
  25315. mem.clear(getExplorerMemoized);
  25316. resolveConfigEditorconfig.clearCache();
  25317. }
  25318. function resolveConfigFile(filePath) {
  25319. var load = getLoadFunction({
  25320. sync: false
  25321. });
  25322. return load(filePath).then(function (result) {
  25323. return result ? result.filepath : null;
  25324. });
  25325. }
  25326. resolveConfigFile.sync = function (filePath) {
  25327. var load = getLoadFunction({
  25328. sync: true
  25329. });
  25330. var result = load(filePath);
  25331. return result ? result.filepath : null;
  25332. };
  25333. function mergeOverrides(configResult, filePath) {
  25334. var options = Object.assign({}, configResult.config);
  25335. if (filePath && options.overrides) {
  25336. var relativeFilePath = path.relative(path.dirname(configResult.filepath), filePath);
  25337. var _iteratorNormalCompletion = true;
  25338. var _didIteratorError = false;
  25339. var _iteratorError = undefined;
  25340. try {
  25341. for (var _iterator = options.overrides[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  25342. var override = _step.value;
  25343. if (pathMatchesGlobs(relativeFilePath, override.files, override.excludeFiles)) {
  25344. Object.assign(options, override.options);
  25345. }
  25346. }
  25347. } catch (err) {
  25348. _didIteratorError = true;
  25349. _iteratorError = err;
  25350. } finally {
  25351. try {
  25352. if (!_iteratorNormalCompletion && _iterator.return != null) {
  25353. _iterator.return();
  25354. }
  25355. } finally {
  25356. if (_didIteratorError) {
  25357. throw _iteratorError;
  25358. }
  25359. }
  25360. }
  25361. }
  25362. delete options.overrides;
  25363. return options;
  25364. } // Based on eslint: https://github.com/eslint/eslint/blob/master/lib/config/config-ops.js
  25365. function pathMatchesGlobs(filePath, patterns, excludedPatterns) {
  25366. var patternList = [].concat(patterns);
  25367. var excludedPatternList = [].concat(excludedPatterns || []);
  25368. var opts = {
  25369. matchBase: true
  25370. };
  25371. return patternList.some(function (pattern) {
  25372. return minimatch_1(filePath, pattern, opts);
  25373. }) && !excludedPatternList.some(function (excludedPattern) {
  25374. return minimatch_1(filePath, excludedPattern, opts);
  25375. });
  25376. }
  25377. module.exports = {
  25378. resolveConfig,
  25379. resolveConfigFile,
  25380. clearCache
  25381. };
  25382. });
  25383. var version = require$$0.version;
  25384. var getSupportInfo = support.getSupportInfo; // Luckily `opts` is always the 2nd argument
  25385. function _withPlugins(fn) {
  25386. return function () {
  25387. var args = Array.from(arguments);
  25388. var opts = args[1] || {};
  25389. args[1] = Object.assign({}, opts, {
  25390. plugins: loadPlugins_1(opts.plugins, opts.pluginSearchDirs)
  25391. });
  25392. return fn.apply(null, args);
  25393. };
  25394. }
  25395. function withPlugins(fn) {
  25396. var resultingFn = _withPlugins(fn);
  25397. if (fn.sync) {
  25398. resultingFn.sync = _withPlugins(fn.sync);
  25399. }
  25400. return resultingFn;
  25401. }
  25402. var formatWithCursor = withPlugins(core.formatWithCursor);
  25403. var prettier = {
  25404. formatWithCursor,
  25405. format(text, opts) {
  25406. return formatWithCursor(text, opts).formatted;
  25407. },
  25408. check: function check(text, opts) {
  25409. var formatted = formatWithCursor(text, opts).formatted;
  25410. return formatted === text;
  25411. },
  25412. doc,
  25413. resolveConfig: resolveConfig_1.resolveConfig,
  25414. resolveConfigFile: resolveConfig_1.resolveConfigFile,
  25415. clearConfigCache: resolveConfig_1.clearCache,
  25416. getFileInfo: withPlugins(getFileInfo_1),
  25417. getSupportInfo: withPlugins(getSupportInfo),
  25418. version,
  25419. util: utilShared,
  25420. /* istanbul ignore next */
  25421. __debug: {
  25422. parse: withPlugins(core.parse),
  25423. formatAST: withPlugins(core.formatAST),
  25424. formatDoc: withPlugins(core.formatDoc),
  25425. printToDoc: withPlugins(core.printToDoc),
  25426. printDocToString: withPlugins(core.printDocToString)
  25427. }
  25428. };
  25429. module.exports = prettier;