index.js 858 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708
  1. 'use strict';
  2. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  3. var fs = _interopDefault(require('fs'));
  4. var path = _interopDefault(require('path'));
  5. var util = _interopDefault(require('util'));
  6. var url = _interopDefault(require('url'));
  7. var assert = _interopDefault(require('assert'));
  8. var os = _interopDefault(require('os'));
  9. var thirdParty = require('./third-party');
  10. var thirdParty__default = thirdParty['default'];
  11. var name = "prettier";
  12. var version$1 = "1.12.1";
  13. var description = "Prettier is an opinionated code formatter";
  14. var bin = {"prettier":"./bin/prettier.js"};
  15. var repository = "prettier/prettier";
  16. var homepage = "https://prettier.io";
  17. var author = "James Long";
  18. var license = "MIT";
  19. var main = "./index.js";
  20. var engines = {"node":">=4"};
  21. var dependencies = {"@babel/code-frame":"7.0.0-beta.40","@glimmer/syntax":"0.30.3","babylon":"7.0.0-beta.34","camelcase":"4.1.0","chalk":"2.1.0","cjk-regex":"1.0.2","cosmiconfig":"3.1.0","dashify":"0.2.2","dedent":"0.7.0","diff":"3.2.0","editorconfig":"0.15.0","editorconfig-to-prettier":"0.0.6","emoji-regex":"6.5.1","escape-string-regexp":"1.0.5","esutils":"2.0.2","find-project-root":"1.1.1","flow-parser":"0.69","get-stream":"3.0.0","globby":"6.1.0","graphql":"0.13.2","gray-matter":"3.1.1","html-tag-names":"1.1.2","ignore":"3.3.7","jest-docblock":"22.2.2","json-stable-stringify":"1.0.1","leven":"2.1.0","mem":"1.1.0","minimatch":"3.0.4","minimist":"1.2.0","parse5":"3.0.3","postcss-less":"1.1.5","postcss-media-query-parser":"0.2.3","postcss-scss":"1.0.5","postcss-selector-parser":"2.2.3","postcss-values-parser":"1.5.0","read-pkg-up":"3.0.0","remark-frontmatter":"1.1.0","remark-parse":"5.0.0","resolve":"1.5.0","semver":"5.4.1","string-width":"2.1.1","typescript":"2.8.0-rc","typescript-eslint-parser":"14.0.0","unicode-regex":"1.0.1","unified":"6.1.6"};
  22. var devDependencies = {"babel-cli":"6.24.1","babel-preset-es2015":"6.24.1","codecov":"2.2.0","cross-env":"5.0.5","eslint":"4.18.2","eslint-config-prettier":"2.9.0","eslint-friendly-formatter":"3.0.0","eslint-plugin-import":"2.9.0","eslint-plugin-prettier":"2.6.0","eslint-plugin-react":"7.7.0","jest":"21.1.0","mkdirp":"0.5.1","prettier":"1.12.0","prettylint":"1.0.0","rimraf":"2.6.2","rollup":"0.47.6","rollup-plugin-commonjs":"8.2.6","rollup-plugin-json":"2.1.1","rollup-plugin-node-builtins":"2.0.0","rollup-plugin-node-globals":"1.1.0","rollup-plugin-node-resolve":"2.0.0","rollup-plugin-replace":"1.2.1","shelljs":"0.8.1","snapshot-diff":"0.2.2","strip-ansi":"4.0.0","tempy":"0.2.1","uglify-es":"3.3.9","webpack":"2.6.1"};
  23. var scripts = {"prepublishOnly":"echo \"Error: must publish from dist/\" && exit 1","prepare-release":"yarn && yarn build && yarn test:dist","test":"jest","test:dist":"node ./scripts/test-dist.js","test-integration":"jest tests_integration","lint":"cross-env EFF_NO_LINK_RULES=true eslint . --format node_modules/eslint-friendly-formatter","lint-docs":"prettylint {.,docs,website,website/blog}/*.md","build":"node ./scripts/build/build.js","build-docs":"node ./scripts/build/build-docs.js","check-deps":"node ./scripts/check-deps.js"};
  24. var _package = {
  25. name: name,
  26. version: version$1,
  27. description: description,
  28. bin: bin,
  29. repository: repository,
  30. homepage: homepage,
  31. author: author,
  32. license: license,
  33. main: main,
  34. engines: engines,
  35. dependencies: dependencies,
  36. devDependencies: devDependencies,
  37. scripts: scripts
  38. };
  39. var _package$1 = Object.freeze({
  40. name: name,
  41. version: version$1,
  42. description: description,
  43. bin: bin,
  44. repository: repository,
  45. homepage: homepage,
  46. author: author,
  47. license: license,
  48. main: main,
  49. engines: engines,
  50. dependencies: dependencies,
  51. devDependencies: devDependencies,
  52. scripts: scripts,
  53. default: _package
  54. });
  55. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  56. function commonjsRequire () {
  57. throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
  58. }
  59. function unwrapExports (x) {
  60. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  61. }
  62. function createCommonjsModule(fn, module) {
  63. return module = { exports: {} }, fn(module, module.exports), module.exports;
  64. }
  65. var ansiRegex = createCommonjsModule(function (module) {
  66. 'use strict';
  67. module.exports = () => {
  68. const pattern = [
  69. '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)',
  70. '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))'
  71. ].join('|');
  72. return new RegExp(pattern, 'g');
  73. };
  74. });
  75. var stripAnsi = input => typeof input === 'string' ? input.replace(ansiRegex(), '') : input;
  76. var isFullwidthCodePoint = createCommonjsModule(function (module) {
  77. 'use strict';
  78. /* eslint-disable yoda */
  79. module.exports = x => {
  80. if (Number.isNaN(x)) {
  81. return false;
  82. }
  83. // code points are derived from:
  84. // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
  85. if (
  86. x >= 0x1100 && (
  87. x <= 0x115f || // Hangul Jamo
  88. x === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  89. x === 0x232a || // RIGHT-POINTING ANGLE BRACKET
  90. // CJK Radicals Supplement .. Enclosed CJK Letters and Months
  91. (0x2e80 <= x && x <= 0x3247 && x !== 0x303f) ||
  92. // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
  93. (0x3250 <= x && x <= 0x4dbf) ||
  94. // CJK Unified Ideographs .. Yi Radicals
  95. (0x4e00 <= x && x <= 0xa4c6) ||
  96. // Hangul Jamo Extended-A
  97. (0xa960 <= x && x <= 0xa97c) ||
  98. // Hangul Syllables
  99. (0xac00 <= x && x <= 0xd7a3) ||
  100. // CJK Compatibility Ideographs
  101. (0xf900 <= x && x <= 0xfaff) ||
  102. // Vertical Forms
  103. (0xfe10 <= x && x <= 0xfe19) ||
  104. // CJK Compatibility Forms .. Small Form Variants
  105. (0xfe30 <= x && x <= 0xfe6b) ||
  106. // Halfwidth and Fullwidth Forms
  107. (0xff01 <= x && x <= 0xff60) ||
  108. (0xffe0 <= x && x <= 0xffe6) ||
  109. // Kana Supplement
  110. (0x1b000 <= x && x <= 0x1b001) ||
  111. // Enclosed Ideographic Supplement
  112. (0x1f200 <= x && x <= 0x1f251) ||
  113. // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
  114. (0x20000 <= x && x <= 0x3fffd)
  115. )
  116. ) {
  117. return true;
  118. }
  119. return false;
  120. };
  121. });
  122. var stringWidth = createCommonjsModule(function (module) {
  123. 'use strict';
  124. module.exports = str => {
  125. if (typeof str !== 'string' || str.length === 0) {
  126. return 0;
  127. }
  128. str = stripAnsi(str);
  129. let width = 0;
  130. for (let i = 0; i < str.length; i++) {
  131. const code = str.codePointAt(i);
  132. // Ignore control characters
  133. if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
  134. continue;
  135. }
  136. // Ignore combining characters
  137. if (code >= 0x300 && code <= 0x36F) {
  138. continue;
  139. }
  140. // Surrogates
  141. if (code > 0xFFFF) {
  142. i++;
  143. }
  144. width += isFullwidthCodePoint(code) ? 2 : 1;
  145. }
  146. return width;
  147. };
  148. });
  149. var emojiRegex$1 = function () {
  150. // https://mathiasbynens.be/notes/es-unicode-property-escapes#emoji
  151. 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
  152. );
  153. };
  154. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  155. var escapeStringRegexp = function (str) {
  156. if (typeof str !== 'string') {
  157. throw new TypeError('Expected a string');
  158. }
  159. return str.replace(matchOperatorsRe, '\\$&');
  160. };
  161. var punctuation_ranges = [
  162. // http://www.unicode.org/charts/PDF/U3000.pdf CJK Symbols and Punctuation
  163. [0x3000, 0x303f],
  164. // http://www.unicode.org/charts/PDF/UAC00.pdf Hangul Syllables
  165. [0xac00, 0xd7af],
  166. // http://www.unicode.org/charts/PDF/UFE10.pdf Vertical Forms
  167. [0xfe10, 0xfe1f],
  168. // http://www.unicode.org/charts/PDF/UFE30.pdf CJK Compatibility Forms
  169. // http://www.unicode.org/charts/PDF/UFE50.pdf Small Form Variants
  170. [0xfe30, 0xfe6f],
  171. // http://www.unicode.org/charts/PDF/UFF00.pdf Halfwidth and Fullwidth Forms
  172. [0xff00, 0xff60],
  173. [0xffe0, 0xffef],
  174. ];
  175. var character_ranges = [
  176. // http://www.unicode.org/charts/PDF/U1100.pdf Hangul Jamo
  177. [0x1100, 0x11ff],
  178. // http://www.unicode.org/charts/PDF/U2E80.pdf CJK Radicals Supplement
  179. // http://www.unicode.org/charts/PDF/U2F00.pdf Kangxi Radicals
  180. [0x2e80, 0x2fdf],
  181. // http://www.unicode.org/charts/PDF/U3040.pdf Hiragana
  182. // http://www.unicode.org/charts/PDF/U30A0.pdf Katakana
  183. // http://www.unicode.org/charts/PDF/U3100.pdf Bopomofo
  184. // http://www.unicode.org/charts/PDF/U3130.pdf Hangul Compatibility Jamo
  185. [0x3040, 0x318f],
  186. // http://www.unicode.org/charts/PDF/U3200.pdf Enclosed CJK Letters and Months
  187. // http://www.unicode.org/charts/PDF/U3300.pdf CJK Compatibility
  188. // http://www.unicode.org/charts/PDF/U3400.pdf CJK Unified Ideographs Extension A
  189. [0x3200, 0x4dbf],
  190. // http://www.unicode.org/charts/PDF/U4E00.pdf CJK Unified Ideographs (Han)
  191. [0x4e00, 0x9fff],
  192. // http://www.unicode.org/charts/PDF/UA960.pdf Hangul Jamo Extended-A
  193. [0xa960, 0xa97f],
  194. // http://www.unicode.org/charts/PDF/UF900.pdf CJK Compatibility Ideographs
  195. [0xf900, 0xfaff],
  196. ];
  197. function get_regex() {
  198. return create_regex(character_ranges.concat(punctuation_ranges));
  199. }
  200. // istanbul ignore next
  201. // tslint:disable-next-line:no-namespace
  202. (function (get_regex) {
  203. function punctuations() {
  204. return create_regex(punctuation_ranges);
  205. }
  206. get_regex.punctuations = punctuations;
  207. function characters() {
  208. return create_regex(character_ranges);
  209. }
  210. get_regex.characters = characters;
  211. })(get_regex || (get_regex = {}));
  212. function create_regex(ranges) {
  213. return new RegExp("[" + ranges.map(get_bracket_content).reduce(function (a, b) { return a + b; }) + "]", 'g');
  214. }
  215. function get_bracket_content(range) {
  216. return get_escaped_unicode(range[0]) + "-" + get_escaped_unicode(range[1]);
  217. }
  218. function get_escaped_unicode(num) {
  219. return "\\u" + num.toString(16);
  220. }
  221. var lib = get_regex;
  222. var data_generated = createCommonjsModule(function (module, exports) {
  223. "use strict";
  224. exports.__esModule = true;
  225. exports.get_data = function () { return ({ "Pc": [[95, 95], [8255, 8256], [8276, 8276], [65075, 65076], [65101, 65103], [65343, 65343]], "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]], "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]], "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]], "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]], "Zp": [[8233, 8233]], "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]], "Me": [[1160, 1161], [6846, 6846], [8413, 8416], [8418, 8420], [42608, 42610]], "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]], "Cs": [[55296, 55296], [56191, 56192], [56319, 56320], [57343, 57343]], "Nl": [[5870, 5872], [8544, 8578], [8581, 8584], [12295, 12295], [12321, 12329], [12344, 12346], [42726, 42735]], "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]], "Lt": [[453, 453], [456, 456], [459, 459], [498, 498], [8072, 8079], [8088, 8095], [8104, 8111], [8124, 8124], [8140, 8140], [8188, 8188]], "Zl": [[8232, 8232]], "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]], "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]], "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]], "Co": [[57344, 57344], [63743, 63743]], "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]], "Pf": [[187, 187], [8217, 8217], [8221, 8221], [8250, 8250], [11779, 11779], [11781, 11781], [11786, 11786], [11789, 11789], [11805, 11805], [11809, 11809]], "Cc": [[0, 31], [127, 159]], "Pi": [[171, 171], [8216, 8216], [8219, 8220], [8223, 8223], [8249, 8249], [11778, 11778], [11780, 11780], [11785, 11785], [11788, 11788], [11804, 11804], [11808, 11808]], "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]], "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]], "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]], "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]], "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]], "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]], "Zs": [[32, 32], [160, 160], [5760, 5760], [8192, 8202], [8239, 8239], [8287, 8287], [12288, 12288]] }); };
  226. });
  227. unwrapExports(data_generated);
  228. var utils = createCommonjsModule(function (module, exports) {
  229. "use strict";
  230. exports.__esModule = true;
  231. function normalize_ranges(ranges) {
  232. return ranges
  233. .sort(function (_a, _b) {
  234. var start1 = _a[0];
  235. var start2 = _b[0];
  236. return start1 - start2;
  237. })
  238. .reduce(function (current, tuple, index) {
  239. if (index === 0) {
  240. return [tuple];
  241. }
  242. var _a = current[current.length - 1], last_start = _a[0], last_end = _a[1];
  243. var start = tuple[0], end = tuple[1];
  244. return last_end + 1 === start
  245. ? current.slice(0, -1).concat([[last_start, end]]) : current.concat([tuple]);
  246. }, []);
  247. }
  248. exports.normalize_ranges = normalize_ranges;
  249. function build_regex(ranges, flag) {
  250. var pattern = ranges
  251. .map(function (_a) {
  252. var start = _a[0], end = _a[1];
  253. return start === end
  254. ? "\\u" + get_hex(start)
  255. : "\\u" + get_hex(start) + "-\\u" + get_hex(end);
  256. })
  257. .join('');
  258. return new RegExp("[" + pattern + "]", flag);
  259. }
  260. exports.build_regex = build_regex;
  261. function get_hex(char_code) {
  262. var hex = char_code.toString(16);
  263. while (hex.length < 4) {
  264. hex = "0" + hex;
  265. }
  266. return hex;
  267. }
  268. });
  269. unwrapExports(utils);
  270. var lib$2 = function (categories, flag) {
  271. var data = data_generated.get_data();
  272. var ranges = categories.reduce(function (current, category) { return current.concat(data[category]); }, []);
  273. return utils.build_regex(utils.normalize_ranges(ranges), flag);
  274. };
  275. const emojiRegex = emojiRegex$1();
  276. const cjkPattern = lib().source;
  277. // http://spec.commonmark.org/0.25/#ascii-punctuation-character
  278. const asciiPunctuationCharRange = escapeStringRegexp(
  279. "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
  280. );
  281. // http://spec.commonmark.org/0.25/#punctuation-character
  282. const punctuationCharRange = `${asciiPunctuationCharRange}${lib$2([
  283. "Pc",
  284. "Pd",
  285. "Pe",
  286. "Pf",
  287. "Pi",
  288. "Po",
  289. "Ps"
  290. ]).source.slice(1, -1)}`; // remove bracket expression `[` and `]`
  291. const punctuationRegex = new RegExp(`[${punctuationCharRange}]`);
  292. function isExportDeclaration(node) {
  293. if (node) {
  294. switch (node.type) {
  295. case "ExportDefaultDeclaration":
  296. case "ExportDefaultSpecifier":
  297. case "DeclareExportDeclaration":
  298. case "ExportNamedDeclaration":
  299. case "ExportAllDeclaration":
  300. return true;
  301. }
  302. }
  303. return false;
  304. }
  305. function getParentExportDeclaration(path$$1) {
  306. const parentNode = path$$1.getParentNode();
  307. if (path$$1.getName() === "declaration" && isExportDeclaration(parentNode)) {
  308. return parentNode;
  309. }
  310. return null;
  311. }
  312. function getPenultimate(arr) {
  313. if (arr.length > 1) {
  314. return arr[arr.length - 2];
  315. }
  316. return null;
  317. }
  318. function getLast(arr) {
  319. if (arr.length > 0) {
  320. return arr[arr.length - 1];
  321. }
  322. return null;
  323. }
  324. function skip(chars) {
  325. return (text, index, opts) => {
  326. const backwards = opts && opts.backwards;
  327. // Allow `skip` functions to be threaded together without having
  328. // to check for failures (did someone say monads?).
  329. if (index === false) {
  330. return false;
  331. }
  332. const length = text.length;
  333. let cursor = index;
  334. while (cursor >= 0 && cursor < length) {
  335. const c = text.charAt(cursor);
  336. if (chars instanceof RegExp) {
  337. if (!chars.test(c)) {
  338. return cursor;
  339. }
  340. } else if (chars.indexOf(c) === -1) {
  341. return cursor;
  342. }
  343. backwards ? cursor-- : cursor++;
  344. }
  345. if (cursor === -1 || cursor === length) {
  346. // If we reached the beginning or end of the file, return the
  347. // out-of-bounds cursor. It's up to the caller to handle this
  348. // correctly. We don't want to indicate `false` though if it
  349. // actually skipped valid characters.
  350. return cursor;
  351. }
  352. return false;
  353. };
  354. }
  355. const skipWhitespace = skip(/\s/);
  356. const skipSpaces = skip(" \t");
  357. const skipToLineEnd = skip(",; \t");
  358. const skipEverythingButNewLine = skip(/[^\r\n]/);
  359. function skipInlineComment(text, index) {
  360. if (index === false) {
  361. return false;
  362. }
  363. if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
  364. for (let i = index + 2; i < text.length; ++i) {
  365. if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
  366. return i + 2;
  367. }
  368. }
  369. }
  370. return index;
  371. }
  372. function skipTrailingComment(text, index) {
  373. if (index === false) {
  374. return false;
  375. }
  376. if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
  377. return skipEverythingButNewLine(text, index);
  378. }
  379. return index;
  380. }
  381. // This one doesn't use the above helper function because it wants to
  382. // test \r\n in order and `skip` doesn't support ordering and we only
  383. // want to skip one newline. It's simple to implement.
  384. function skipNewline(text, index, opts) {
  385. const backwards = opts && opts.backwards;
  386. if (index === false) {
  387. return false;
  388. }
  389. const atIndex = text.charAt(index);
  390. if (backwards) {
  391. if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
  392. return index - 2;
  393. }
  394. if (
  395. atIndex === "\n" ||
  396. atIndex === "\r" ||
  397. atIndex === "\u2028" ||
  398. atIndex === "\u2029"
  399. ) {
  400. return index - 1;
  401. }
  402. } else {
  403. if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
  404. return index + 2;
  405. }
  406. if (
  407. atIndex === "\n" ||
  408. atIndex === "\r" ||
  409. atIndex === "\u2028" ||
  410. atIndex === "\u2029"
  411. ) {
  412. return index + 1;
  413. }
  414. }
  415. return index;
  416. }
  417. function hasNewline(text, index, opts) {
  418. opts = opts || {};
  419. const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  420. const idx2 = skipNewline(text, idx, opts);
  421. return idx !== idx2;
  422. }
  423. function hasNewlineInRange(text, start, end) {
  424. for (let i = start; i < end; ++i) {
  425. if (text.charAt(i) === "\n") {
  426. return true;
  427. }
  428. }
  429. return false;
  430. }
  431. // Note: this function doesn't ignore leading comments unlike isNextLineEmpty
  432. function isPreviousLineEmpty(text, node, locStart) {
  433. let idx = locStart(node) - 1;
  434. idx = skipSpaces(text, idx, { backwards: true });
  435. idx = skipNewline(text, idx, { backwards: true });
  436. idx = skipSpaces(text, idx, { backwards: true });
  437. const idx2 = skipNewline(text, idx, { backwards: true });
  438. return idx !== idx2;
  439. }
  440. function isNextLineEmptyAfterIndex(text, index) {
  441. let oldIdx = null;
  442. let idx = index;
  443. while (idx !== oldIdx) {
  444. // We need to skip all the potential trailing inline comments
  445. oldIdx = idx;
  446. idx = skipToLineEnd(text, idx);
  447. idx = skipInlineComment(text, idx);
  448. idx = skipSpaces(text, idx);
  449. }
  450. idx = skipTrailingComment(text, idx);
  451. idx = skipNewline(text, idx);
  452. return hasNewline(text, idx);
  453. }
  454. function isNextLineEmpty(text, node, locEnd) {
  455. return isNextLineEmptyAfterIndex(text, locEnd(node));
  456. }
  457. function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
  458. let oldIdx = null;
  459. let idx = locEnd(node);
  460. while (idx !== oldIdx) {
  461. oldIdx = idx;
  462. idx = skipSpaces(text, idx);
  463. idx = skipInlineComment(text, idx);
  464. idx = skipTrailingComment(text, idx);
  465. idx = skipNewline(text, idx);
  466. }
  467. return idx;
  468. }
  469. function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
  470. return text.charAt(
  471. getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
  472. );
  473. }
  474. function hasSpaces(text, index, opts) {
  475. opts = opts || {};
  476. const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  477. return idx !== index;
  478. }
  479. // Super inefficient, needs to be cached.
  480. function lineColumnToIndex(lineColumn, text) {
  481. let index = 0;
  482. for (let i = 0; i < lineColumn.line - 1; ++i) {
  483. index = text.indexOf("\n", index) + 1;
  484. if (index === -1) {
  485. return -1;
  486. }
  487. }
  488. return index + lineColumn.column;
  489. }
  490. function setLocStart(node, index) {
  491. if (node.range) {
  492. node.range[0] = index;
  493. } else {
  494. node.start = index;
  495. }
  496. }
  497. function setLocEnd(node, index) {
  498. if (node.range) {
  499. node.range[1] = index;
  500. } else {
  501. node.end = index;
  502. }
  503. }
  504. const PRECEDENCE = {};
  505. [
  506. ["|>"],
  507. ["||", "??"],
  508. ["&&"],
  509. ["|"],
  510. ["^"],
  511. ["&"],
  512. ["==", "===", "!=", "!=="],
  513. ["<", ">", "<=", ">=", "in", "instanceof"],
  514. [">>", "<<", ">>>"],
  515. ["+", "-"],
  516. ["*", "/", "%"],
  517. ["**"]
  518. ].forEach((tier, i) => {
  519. tier.forEach(op => {
  520. PRECEDENCE[op] = i;
  521. });
  522. });
  523. function getPrecedence(op) {
  524. return PRECEDENCE[op];
  525. }
  526. const equalityOperators = {
  527. "==": true,
  528. "!=": true,
  529. "===": true,
  530. "!==": true
  531. };
  532. const multiplicativeOperators = {
  533. "*": true,
  534. "/": true,
  535. "%": true
  536. };
  537. const bitshiftOperators = {
  538. ">>": true,
  539. ">>>": true,
  540. "<<": true
  541. };
  542. function shouldFlatten(parentOp, nodeOp) {
  543. if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) {
  544. return false;
  545. }
  546. // ** is right-associative
  547. // x ** y ** z --> x ** (y ** z)
  548. if (parentOp === "**") {
  549. return false;
  550. }
  551. // x == y == z --> (x == y) == z
  552. if (equalityOperators[parentOp] && equalityOperators[nodeOp]) {
  553. return false;
  554. }
  555. // x * y % z --> (x * y) % z
  556. if (
  557. (nodeOp === "%" && multiplicativeOperators[parentOp]) ||
  558. (parentOp === "%" && multiplicativeOperators[nodeOp])
  559. ) {
  560. return false;
  561. }
  562. // x << y << z --> (x << y) << z
  563. if (bitshiftOperators[parentOp] && bitshiftOperators[nodeOp]) {
  564. return false;
  565. }
  566. return true;
  567. }
  568. function isBitwiseOperator(operator) {
  569. return (
  570. !!bitshiftOperators[operator] ||
  571. operator === "|" ||
  572. operator === "^" ||
  573. operator === "&"
  574. );
  575. }
  576. // Tests if an expression starts with `{`, or (if forbidFunctionAndClass holds) `function` or `class`.
  577. // Will be overzealous if there's already necessary grouping parentheses.
  578. function startsWithNoLookaheadToken(node, forbidFunctionAndClass) {
  579. node = getLeftMost(node);
  580. switch (node.type) {
  581. // Hack. Remove after https://github.com/eslint/typescript-eslint-parser/issues/331
  582. case "ObjectPattern":
  583. return !forbidFunctionAndClass;
  584. case "FunctionExpression":
  585. case "ClassExpression":
  586. return forbidFunctionAndClass;
  587. case "ObjectExpression":
  588. return true;
  589. case "MemberExpression":
  590. return startsWithNoLookaheadToken(node.object, forbidFunctionAndClass);
  591. case "TaggedTemplateExpression":
  592. if (node.tag.type === "FunctionExpression") {
  593. // IIFEs are always already parenthesized
  594. return false;
  595. }
  596. return startsWithNoLookaheadToken(node.tag, forbidFunctionAndClass);
  597. case "CallExpression":
  598. if (node.callee.type === "FunctionExpression") {
  599. // IIFEs are always already parenthesized
  600. return false;
  601. }
  602. return startsWithNoLookaheadToken(node.callee, forbidFunctionAndClass);
  603. case "ConditionalExpression":
  604. return startsWithNoLookaheadToken(node.test, forbidFunctionAndClass);
  605. case "UpdateExpression":
  606. return (
  607. !node.prefix &&
  608. startsWithNoLookaheadToken(node.argument, forbidFunctionAndClass)
  609. );
  610. case "BindExpression":
  611. return (
  612. node.object &&
  613. startsWithNoLookaheadToken(node.object, forbidFunctionAndClass)
  614. );
  615. case "SequenceExpression":
  616. return startsWithNoLookaheadToken(
  617. node.expressions[0],
  618. forbidFunctionAndClass
  619. );
  620. case "TSAsExpression":
  621. return startsWithNoLookaheadToken(
  622. node.expression,
  623. forbidFunctionAndClass
  624. );
  625. default:
  626. return false;
  627. }
  628. }
  629. function getLeftMost(node) {
  630. if (node.left) {
  631. return getLeftMost(node.left);
  632. }
  633. return node;
  634. }
  635. function hasBlockComments(node) {
  636. return node.comments && node.comments.some(isBlockComment);
  637. }
  638. function isBlockComment(comment) {
  639. return comment.type === "Block" || comment.type === "CommentBlock";
  640. }
  641. function hasClosureCompilerTypeCastComment(text, node, locEnd) {
  642. // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
  643. // Syntax example: var x = /** @type {string} */ (fruit);
  644. return (
  645. node.comments &&
  646. node.comments.some(
  647. comment =>
  648. comment.leading &&
  649. isBlockComment(comment) &&
  650. comment.value.match(/^\*\s*@type\s*{[^}]+}\s*$/) &&
  651. getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "("
  652. )
  653. );
  654. }
  655. function getAlignmentSize(value, tabWidth, startIndex) {
  656. startIndex = startIndex || 0;
  657. let size = 0;
  658. for (let i = startIndex; i < value.length; ++i) {
  659. if (value[i] === "\t") {
  660. // Tabs behave in a way that they are aligned to the nearest
  661. // multiple of tabWidth:
  662. // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
  663. // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
  664. size = size + tabWidth - size % tabWidth;
  665. } else {
  666. size++;
  667. }
  668. }
  669. return size;
  670. }
  671. function getIndentSize(value, tabWidth) {
  672. const lastNewlineIndex = value.lastIndexOf("\n");
  673. if (lastNewlineIndex === -1) {
  674. return 0;
  675. }
  676. return getAlignmentSize(
  677. // All the leading whitespaces
  678. value.slice(lastNewlineIndex + 1).match(/^[ \t]*/)[0],
  679. tabWidth
  680. );
  681. }
  682. function printString(raw, options, isDirectiveLiteral) {
  683. // `rawContent` is the string exactly like it appeared in the input source
  684. // code, without its enclosing quotes.
  685. const rawContent = raw.slice(1, -1);
  686. const double = { quote: '"', regex: /"/g };
  687. const single = { quote: "'", regex: /'/g };
  688. const preferred = options.singleQuote ? single : double;
  689. const alternate = preferred === single ? double : single;
  690. let shouldUseAlternateQuote = false;
  691. let canChangeDirectiveQuotes = false;
  692. // If `rawContent` contains at least one of the quote preferred for enclosing
  693. // the string, we might want to enclose with the alternate quote instead, to
  694. // minimize the number of escaped quotes.
  695. // Also check for the alternate quote, to determine if we're allowed to swap
  696. // the quotes on a DirectiveLiteral.
  697. if (
  698. rawContent.includes(preferred.quote) ||
  699. rawContent.includes(alternate.quote)
  700. ) {
  701. const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
  702. const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
  703. shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes;
  704. } else {
  705. canChangeDirectiveQuotes = true;
  706. }
  707. const enclosingQuote =
  708. options.parser === "json"
  709. ? double.quote
  710. : shouldUseAlternateQuote
  711. ? alternate.quote
  712. : preferred.quote;
  713. // Directives are exact code unit sequences, which means that you can't
  714. // change the escape sequences they use.
  715. // See https://github.com/prettier/prettier/issues/1555
  716. // and https://tc39.github.io/ecma262/#directive-prologue
  717. if (isDirectiveLiteral) {
  718. if (canChangeDirectiveQuotes) {
  719. return enclosingQuote + rawContent + enclosingQuote;
  720. }
  721. return raw;
  722. }
  723. // It might sound unnecessary to use `makeString` even if the string already
  724. // is enclosed with `enclosingQuote`, but it isn't. The string could contain
  725. // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
  726. // sure that we consistently output the minimum amount of escaped quotes.
  727. return makeString(
  728. rawContent,
  729. enclosingQuote,
  730. !(
  731. options.parser === "css" ||
  732. options.parser === "less" ||
  733. options.parser === "scss"
  734. )
  735. );
  736. }
  737. function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
  738. const otherQuote = enclosingQuote === '"' ? "'" : '"';
  739. // Matches _any_ escape and unescaped quotes (both single and double).
  740. const regex = /\\([\s\S])|(['"])/g;
  741. // Escape and unescape single and double quotes as needed to be able to
  742. // enclose `rawContent` with `enclosingQuote`.
  743. const newContent = rawContent.replace(regex, (match, escaped, quote) => {
  744. // If we matched an escape, and the escaped character is a quote of the
  745. // other type than we intend to enclose the string with, there's no need for
  746. // it to be escaped, so return it _without_ the backslash.
  747. if (escaped === otherQuote) {
  748. return escaped;
  749. }
  750. // If we matched an unescaped quote and it is of the _same_ type as we
  751. // intend to enclose the string with, it must be escaped, so return it with
  752. // a backslash.
  753. if (quote === enclosingQuote) {
  754. return "\\" + quote;
  755. }
  756. if (quote) {
  757. return quote;
  758. }
  759. // Unescape any unnecessarily escaped character.
  760. // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
  761. return unescapeUnnecessaryEscapes &&
  762. /^[^\\nrvtbfux\r\n\u2028\u2029"'0-7]$/.test(escaped)
  763. ? escaped
  764. : "\\" + escaped;
  765. });
  766. return enclosingQuote + newContent + enclosingQuote;
  767. }
  768. function printNumber(rawNumber) {
  769. return (
  770. rawNumber
  771. .toLowerCase()
  772. // Remove unnecessary plus and zeroes from scientific notation.
  773. .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3")
  774. // Remove unnecessary scientific notation (1e0).
  775. .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1")
  776. // Make sure numbers always start with a digit.
  777. .replace(/^([+-])?\./, "$10.")
  778. // Remove extraneous trailing decimal zeroes.
  779. .replace(/(\.\d+?)0+(?=e|$)/, "$1")
  780. // Remove trailing dot.
  781. .replace(/\.(?=e|$)/, "")
  782. );
  783. }
  784. function getMaxContinuousCount(str, target) {
  785. const results = str.match(
  786. new RegExp(`(${escapeStringRegexp(target)})+`, "g")
  787. );
  788. if (results === null) {
  789. return 0;
  790. }
  791. return results.reduce(
  792. (maxCount, result) => Math.max(maxCount, result.length / target.length),
  793. 0
  794. );
  795. }
  796. /**
  797. * split text into whitespaces and words
  798. * @param {string} text
  799. * @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
  800. */
  801. function splitText(text) {
  802. const KIND_NON_CJK = "non-cjk";
  803. const KIND_CJK_CHARACTER = "cjk-character";
  804. const KIND_CJK_PUNCTUATION = "cjk-punctuation";
  805. const nodes = [];
  806. text
  807. .replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")
  808. .split(/([ \t\n]+)/)
  809. .forEach((token, index, tokens) => {
  810. // whitespace
  811. if (index % 2 === 1) {
  812. nodes.push({
  813. type: "whitespace",
  814. value: /\n/.test(token) ? "\n" : " "
  815. });
  816. return;
  817. }
  818. // word separated by whitespace
  819. if ((index === 0 || index === tokens.length - 1) && token === "") {
  820. return;
  821. }
  822. token
  823. .split(new RegExp(`(${cjkPattern})`))
  824. .forEach((innerToken, innerIndex, innerTokens) => {
  825. if (
  826. (innerIndex === 0 || innerIndex === innerTokens.length - 1) &&
  827. innerToken === ""
  828. ) {
  829. return;
  830. }
  831. // non-CJK word
  832. if (innerIndex % 2 === 0) {
  833. if (innerToken !== "") {
  834. appendNode({
  835. type: "word",
  836. value: innerToken,
  837. kind: KIND_NON_CJK,
  838. hasLeadingPunctuation: punctuationRegex.test(innerToken[0]),
  839. hasTrailingPunctuation: punctuationRegex.test(
  840. getLast(innerToken)
  841. )
  842. });
  843. }
  844. return;
  845. }
  846. // CJK character
  847. appendNode(
  848. punctuationRegex.test(innerToken)
  849. ? {
  850. type: "word",
  851. value: innerToken,
  852. kind: KIND_CJK_PUNCTUATION,
  853. hasLeadingPunctuation: true,
  854. hasTrailingPunctuation: true
  855. }
  856. : {
  857. type: "word",
  858. value: innerToken,
  859. kind: KIND_CJK_CHARACTER,
  860. hasLeadingPunctuation: false,
  861. hasTrailingPunctuation: false
  862. }
  863. );
  864. });
  865. });
  866. return nodes;
  867. function appendNode(node) {
  868. const lastNode = getLast(nodes);
  869. if (lastNode && lastNode.type === "word") {
  870. if (
  871. (lastNode.kind === KIND_NON_CJK &&
  872. node.kind === KIND_CJK_CHARACTER &&
  873. !lastNode.hasTrailingPunctuation) ||
  874. (lastNode.kind === KIND_CJK_CHARACTER &&
  875. node.kind === KIND_NON_CJK &&
  876. !node.hasLeadingPunctuation)
  877. ) {
  878. nodes.push({ type: "whitespace", value: " " });
  879. } else if (
  880. !isBetween(KIND_NON_CJK, KIND_CJK_PUNCTUATION) &&
  881. // disallow leading/trailing full-width whitespace
  882. ![lastNode.value, node.value].some(value => /\u3000/.test(value))
  883. ) {
  884. nodes.push({ type: "whitespace", value: "" });
  885. }
  886. }
  887. nodes.push(node);
  888. function isBetween(kind1, kind2) {
  889. return (
  890. (lastNode.kind === kind1 && node.kind === kind2) ||
  891. (lastNode.kind === kind2 && node.kind === kind1)
  892. );
  893. }
  894. }
  895. }
  896. function getStringWidth(text) {
  897. if (!text) {
  898. return 0;
  899. }
  900. // emojis are considered 2-char width for consistency
  901. // see https://github.com/sindresorhus/string-width/issues/11
  902. // for the reason why not implemented in `string-width`
  903. return stringWidth(text.replace(emojiRegex, " "));
  904. }
  905. function hasIgnoreComment(path$$1) {
  906. const node = path$$1.getValue();
  907. return hasNodeIgnoreComment(node);
  908. }
  909. function hasNodeIgnoreComment(node) {
  910. return (
  911. node &&
  912. node.comments &&
  913. node.comments.length > 0 &&
  914. node.comments.some(comment => comment.value.trim() === "prettier-ignore")
  915. );
  916. }
  917. function arrayify(object, keyName) {
  918. return Object.keys(object).reduce(
  919. (array, key) =>
  920. array.concat(Object.assign({ [keyName]: key }, object[key])),
  921. []
  922. );
  923. }
  924. function addCommentHelper(node, comment) {
  925. const comments = node.comments || (node.comments = []);
  926. comments.push(comment);
  927. comment.printed = false;
  928. // For some reason, TypeScript parses `// x` inside of JSXText as a comment
  929. // We already "print" it via the raw text, we don't need to re-print it as a
  930. // comment
  931. if (node.type === "JSXText") {
  932. comment.printed = true;
  933. }
  934. }
  935. function addLeadingComment(node, comment) {
  936. comment.leading = true;
  937. comment.trailing = false;
  938. addCommentHelper(node, comment);
  939. }
  940. function addDanglingComment(node, comment) {
  941. comment.leading = false;
  942. comment.trailing = false;
  943. addCommentHelper(node, comment);
  944. }
  945. function addTrailingComment(node, comment) {
  946. comment.leading = false;
  947. comment.trailing = true;
  948. addCommentHelper(node, comment);
  949. }
  950. var util$1 = {
  951. arrayify,
  952. punctuationRegex,
  953. punctuationCharRange,
  954. getStringWidth,
  955. splitText,
  956. getMaxContinuousCount,
  957. getPrecedence,
  958. shouldFlatten,
  959. isBitwiseOperator,
  960. isExportDeclaration,
  961. getParentExportDeclaration,
  962. getPenultimate,
  963. getLast,
  964. getNextNonSpaceNonCommentCharacterIndex,
  965. getNextNonSpaceNonCommentCharacter,
  966. skipWhitespace,
  967. skipSpaces,
  968. skipNewline,
  969. isNextLineEmptyAfterIndex,
  970. isNextLineEmpty,
  971. isPreviousLineEmpty,
  972. hasNewline,
  973. hasNewlineInRange,
  974. hasSpaces,
  975. setLocStart,
  976. setLocEnd,
  977. startsWithNoLookaheadToken,
  978. hasBlockComments,
  979. isBlockComment,
  980. hasClosureCompilerTypeCastComment,
  981. getAlignmentSize,
  982. getIndentSize,
  983. printString,
  984. printNumber,
  985. hasIgnoreComment,
  986. hasNodeIgnoreComment,
  987. lineColumnToIndex,
  988. makeString,
  989. addLeadingComment,
  990. addDanglingComment,
  991. addTrailingComment
  992. };
  993. function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
  994. function traverseDocRec(doc) {
  995. let shouldRecurse = true;
  996. if (onEnter) {
  997. if (onEnter(doc) === false) {
  998. shouldRecurse = false;
  999. }
  1000. }
  1001. if (shouldRecurse) {
  1002. if (doc.type === "concat" || doc.type === "fill") {
  1003. for (let i = 0; i < doc.parts.length; i++) {
  1004. traverseDocRec(doc.parts[i]);
  1005. }
  1006. } else if (doc.type === "if-break") {
  1007. if (doc.breakContents) {
  1008. traverseDocRec(doc.breakContents);
  1009. }
  1010. if (doc.flatContents) {
  1011. traverseDocRec(doc.flatContents);
  1012. }
  1013. } else if (doc.type === "group" && doc.expandedStates) {
  1014. if (shouldTraverseConditionalGroups) {
  1015. doc.expandedStates.forEach(traverseDocRec);
  1016. } else {
  1017. traverseDocRec(doc.contents);
  1018. }
  1019. } else if (doc.contents) {
  1020. traverseDocRec(doc.contents);
  1021. }
  1022. }
  1023. if (onExit) {
  1024. onExit(doc);
  1025. }
  1026. }
  1027. traverseDocRec(doc);
  1028. }
  1029. function mapDoc(doc, cb) {
  1030. if (doc.type === "concat" || doc.type === "fill") {
  1031. const parts = doc.parts.map(part => mapDoc(part, cb));
  1032. return cb(Object.assign({}, doc, { parts }));
  1033. } else if (doc.type === "if-break") {
  1034. const breakContents = doc.breakContents && mapDoc(doc.breakContents, cb);
  1035. const flatContents = doc.flatContents && mapDoc(doc.flatContents, cb);
  1036. return cb(Object.assign({}, doc, { breakContents, flatContents }));
  1037. } else if (doc.contents) {
  1038. const contents = mapDoc(doc.contents, cb);
  1039. return cb(Object.assign({}, doc, { contents }));
  1040. }
  1041. return cb(doc);
  1042. }
  1043. function findInDoc(doc, fn, defaultValue) {
  1044. let result = defaultValue;
  1045. let hasStopped = false;
  1046. traverseDoc(doc, doc => {
  1047. const maybeResult = fn(doc);
  1048. if (maybeResult !== undefined) {
  1049. hasStopped = true;
  1050. result = maybeResult;
  1051. }
  1052. if (hasStopped) {
  1053. return false;
  1054. }
  1055. });
  1056. return result;
  1057. }
  1058. function isEmpty(n) {
  1059. return typeof n === "string" && n.length === 0;
  1060. }
  1061. function isLineNext(doc) {
  1062. return findInDoc(
  1063. doc,
  1064. doc => {
  1065. if (typeof doc === "string") {
  1066. return false;
  1067. }
  1068. if (doc.type === "line") {
  1069. return true;
  1070. }
  1071. },
  1072. false
  1073. );
  1074. }
  1075. function willBreak(doc) {
  1076. return findInDoc(
  1077. doc,
  1078. doc => {
  1079. if (doc.type === "group" && doc.break) {
  1080. return true;
  1081. }
  1082. if (doc.type === "line" && doc.hard) {
  1083. return true;
  1084. }
  1085. if (doc.type === "break-parent") {
  1086. return true;
  1087. }
  1088. },
  1089. false
  1090. );
  1091. }
  1092. function breakParentGroup(groupStack) {
  1093. if (groupStack.length > 0) {
  1094. const parentGroup = groupStack[groupStack.length - 1];
  1095. // Breaks are not propagated through conditional groups because
  1096. // the user is expected to manually handle what breaks.
  1097. if (!parentGroup.expandedStates) {
  1098. parentGroup.break = true;
  1099. }
  1100. }
  1101. return null;
  1102. }
  1103. function propagateBreaks(doc) {
  1104. const alreadyVisited = new Map();
  1105. const groupStack = [];
  1106. traverseDoc(
  1107. doc,
  1108. doc => {
  1109. if (doc.type === "break-parent") {
  1110. breakParentGroup(groupStack);
  1111. }
  1112. if (doc.type === "group") {
  1113. groupStack.push(doc);
  1114. if (alreadyVisited.has(doc)) {
  1115. return false;
  1116. }
  1117. alreadyVisited.set(doc, true);
  1118. }
  1119. },
  1120. doc => {
  1121. if (doc.type === "group") {
  1122. const group = groupStack.pop();
  1123. if (group.break) {
  1124. breakParentGroup(groupStack);
  1125. }
  1126. }
  1127. },
  1128. /* shouldTraverseConditionalGroups */ true
  1129. );
  1130. }
  1131. function removeLines(doc) {
  1132. // Force this doc into flat mode by statically converting all
  1133. // lines into spaces (or soft lines into nothing). Hard lines
  1134. // should still output because there's too great of a chance
  1135. // of breaking existing assumptions otherwise.
  1136. return mapDoc(doc, d => {
  1137. if (d.type === "line" && !d.hard) {
  1138. return d.soft ? "" : " ";
  1139. } else if (d.type === "if-break") {
  1140. return d.flatContents || "";
  1141. }
  1142. return d;
  1143. });
  1144. }
  1145. function stripTrailingHardline(doc) {
  1146. // HACK remove ending hardline, original PR: #1984
  1147. if (
  1148. doc.type === "concat" &&
  1149. doc.parts.length === 2 &&
  1150. doc.parts[1].type === "concat" &&
  1151. doc.parts[1].parts.length === 2 &&
  1152. doc.parts[1].parts[0].hard &&
  1153. doc.parts[1].parts[1].type === "break-parent"
  1154. ) {
  1155. return doc.parts[0];
  1156. }
  1157. return doc;
  1158. }
  1159. var docUtils = {
  1160. isEmpty,
  1161. willBreak,
  1162. isLineNext,
  1163. traverseDoc,
  1164. mapDoc,
  1165. propagateBreaks,
  1166. removeLines,
  1167. stripTrailingHardline
  1168. };
  1169. function isNextLineEmpty$1(text, node, options) {
  1170. return util$1.isNextLineEmpty(text, node, options.locEnd);
  1171. }
  1172. function getNextNonSpaceNonCommentCharacterIndex$1(text, node, options) {
  1173. return util$1.getNextNonSpaceNonCommentCharacterIndex(
  1174. text,
  1175. node,
  1176. options.locEnd
  1177. );
  1178. }
  1179. var utilShared = {
  1180. isNextLineEmpty: isNextLineEmpty$1,
  1181. isNextLineEmptyAfterIndex: util$1.isNextLineEmptyAfterIndex,
  1182. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$1,
  1183. mapDoc: docUtils.mapDoc, // TODO: remove in 2.0, we already exposed it in docUtils
  1184. makeString: util$1.makeString,
  1185. addLeadingComment: util$1.addLeadingComment,
  1186. addDanglingComment: util$1.addDanglingComment,
  1187. addTrailingComment: util$1.addTrailingComment
  1188. };
  1189. var dedent_1 = createCommonjsModule(function (module) {
  1190. "use strict";
  1191. function dedent(strings) {
  1192. var raw = void 0;
  1193. if (typeof strings === "string") {
  1194. // dedent can be used as a plain function
  1195. raw = [strings];
  1196. } else {
  1197. raw = strings.raw;
  1198. }
  1199. // first, perform interpolation
  1200. var result = "";
  1201. for (var i = 0; i < raw.length; i++) {
  1202. result += raw[i].
  1203. // join lines when there is a suppressed newline
  1204. replace(/\\\n[ \t]*/g, "").
  1205. // handle escaped backticks
  1206. replace(/\\`/g, "`");
  1207. if (i < (arguments.length <= 1 ? 0 : arguments.length - 1)) {
  1208. result += arguments.length <= i + 1 ? undefined : arguments[i + 1];
  1209. }
  1210. }
  1211. // now strip indentation
  1212. var lines = result.split("\n");
  1213. var mindent = null;
  1214. lines.forEach(function (l) {
  1215. var m = l.match(/^(\s+)\S+/);
  1216. if (m) {
  1217. var indent = m[1].length;
  1218. if (!mindent) {
  1219. // this is the first indented line
  1220. mindent = indent;
  1221. } else {
  1222. mindent = Math.min(mindent, indent);
  1223. }
  1224. }
  1225. });
  1226. if (mindent !== null) {
  1227. result = lines.map(function (l) {
  1228. return l[0] === " " ? l.slice(mindent) : l;
  1229. }).join("\n");
  1230. }
  1231. // dedent eats leading and trailing whitespace too
  1232. result = result.trim();
  1233. // handle escaped newlines at the end to ensure they don't get stripped too
  1234. return result.replace(/\\n/g, "\n");
  1235. }
  1236. {
  1237. module.exports = dedent;
  1238. }
  1239. });
  1240. var semver = createCommonjsModule(function (module, exports) {
  1241. exports = module.exports = SemVer;
  1242. // The debug function is excluded entirely from the minified version.
  1243. /* nomin */ var debug;
  1244. /* nomin */ if (typeof process === 'object' &&
  1245. /* nomin */ process.env &&
  1246. /* nomin */ process.env.NODE_DEBUG &&
  1247. /* nomin */ /\bsemver\b/i.test(process.env.NODE_DEBUG))
  1248. /* nomin */ debug = function() {
  1249. /* nomin */ var args = Array.prototype.slice.call(arguments, 0);
  1250. /* nomin */ args.unshift('SEMVER');
  1251. /* nomin */ console.log.apply(console, args);
  1252. /* nomin */ };
  1253. /* nomin */ else
  1254. /* nomin */ debug = function() {};
  1255. // Note: this is the semver.org version of the spec that it implements
  1256. // Not necessarily the package version of this code.
  1257. exports.SEMVER_SPEC_VERSION = '2.0.0';
  1258. var MAX_LENGTH = 256;
  1259. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
  1260. // The actual regexps go on exports.re
  1261. var re = exports.re = [];
  1262. var src = exports.src = [];
  1263. var R = 0;
  1264. // The following Regular Expressions can be used for tokenizing,
  1265. // validating, and parsing SemVer version strings.
  1266. // ## Numeric Identifier
  1267. // A single `0`, or a non-zero digit followed by zero or more digits.
  1268. var NUMERICIDENTIFIER = R++;
  1269. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  1270. var NUMERICIDENTIFIERLOOSE = R++;
  1271. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+';
  1272. // ## Non-numeric Identifier
  1273. // Zero or more digits, followed by a letter or hyphen, and then zero or
  1274. // more letters, digits, or hyphens.
  1275. var NONNUMERICIDENTIFIER = R++;
  1276. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*';
  1277. // ## Main Version
  1278. // Three dot-separated numeric identifiers.
  1279. var MAINVERSION = R++;
  1280. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' +
  1281. '(' + src[NUMERICIDENTIFIER] + ')\\.' +
  1282. '(' + src[NUMERICIDENTIFIER] + ')';
  1283. var MAINVERSIONLOOSE = R++;
  1284. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
  1285. '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
  1286. '(' + src[NUMERICIDENTIFIERLOOSE] + ')';
  1287. // ## Pre-release Version Identifier
  1288. // A numeric identifier, or a non-numeric identifier.
  1289. var PRERELEASEIDENTIFIER = R++;
  1290. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] +
  1291. '|' + src[NONNUMERICIDENTIFIER] + ')';
  1292. var PRERELEASEIDENTIFIERLOOSE = R++;
  1293. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] +
  1294. '|' + src[NONNUMERICIDENTIFIER] + ')';
  1295. // ## Pre-release Version
  1296. // Hyphen, followed by one or more dot-separated pre-release version
  1297. // identifiers.
  1298. var PRERELEASE = R++;
  1299. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] +
  1300. '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  1301. var PRERELEASELOOSE = R++;
  1302. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] +
  1303. '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))';
  1304. // ## Build Metadata Identifier
  1305. // Any combination of digits, letters, or hyphens.
  1306. var BUILDIDENTIFIER = R++;
  1307. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+';
  1308. // ## Build Metadata
  1309. // Plus sign, followed by one or more period-separated build metadata
  1310. // identifiers.
  1311. var BUILD = R++;
  1312. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] +
  1313. '(?:\\.' + src[BUILDIDENTIFIER] + ')*))';
  1314. // ## Full Version String
  1315. // A main version, followed optionally by a pre-release version and
  1316. // build metadata.
  1317. // Note that the only major, minor, patch, and pre-release sections of
  1318. // the version string are capturing groups. The build metadata is not a
  1319. // capturing group, because it should not ever be used in version
  1320. // comparison.
  1321. var FULL = R++;
  1322. var FULLPLAIN = 'v?' + src[MAINVERSION] +
  1323. src[PRERELEASE] + '?' +
  1324. src[BUILD] + '?';
  1325. src[FULL] = '^' + FULLPLAIN + '$';
  1326. // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  1327. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  1328. // common in the npm registry.
  1329. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] +
  1330. src[PRERELEASELOOSE] + '?' +
  1331. src[BUILD] + '?';
  1332. var LOOSE = R++;
  1333. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  1334. var GTLT = R++;
  1335. src[GTLT] = '((?:<|>)?=?)';
  1336. // Something like "2.*" or "1.2.x".
  1337. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  1338. // Only the first item is strictly required.
  1339. var XRANGEIDENTIFIERLOOSE = R++;
  1340. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  1341. var XRANGEIDENTIFIER = R++;
  1342. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  1343. var XRANGEPLAIN = R++;
  1344. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' +
  1345. '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
  1346. '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
  1347. '(?:' + src[PRERELEASE] + ')?' +
  1348. src[BUILD] + '?' +
  1349. ')?)?';
  1350. var XRANGEPLAINLOOSE = R++;
  1351. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
  1352. '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
  1353. '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
  1354. '(?:' + src[PRERELEASELOOSE] + ')?' +
  1355. src[BUILD] + '?' +
  1356. ')?)?';
  1357. var XRANGE = R++;
  1358. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  1359. var XRANGELOOSE = R++;
  1360. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$';
  1361. // Tilde ranges.
  1362. // Meaning is "reasonably at or greater than"
  1363. var LONETILDE = R++;
  1364. src[LONETILDE] = '(?:~>?)';
  1365. var TILDETRIM = R++;
  1366. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  1367. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  1368. var tildeTrimReplace = '$1~';
  1369. var TILDE = R++;
  1370. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  1371. var TILDELOOSE = R++;
  1372. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$';
  1373. // Caret ranges.
  1374. // Meaning is "at least and backwards compatible with"
  1375. var LONECARET = R++;
  1376. src[LONECARET] = '(?:\\^)';
  1377. var CARETTRIM = R++;
  1378. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  1379. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  1380. var caretTrimReplace = '$1^';
  1381. var CARET = R++;
  1382. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  1383. var CARETLOOSE = R++;
  1384. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$';
  1385. // A simple gt/lt/eq thing, or just "" to indicate "any version"
  1386. var COMPARATORLOOSE = R++;
  1387. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  1388. var COMPARATOR = R++;
  1389. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$';
  1390. // An expression to strip any whitespace between the gtlt and the thing
  1391. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  1392. var COMPARATORTRIM = R++;
  1393. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] +
  1394. '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')';
  1395. // this one has to use the /g flag
  1396. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  1397. var comparatorTrimReplace = '$1$2$3';
  1398. // Something like `1.2.3 - 1.2.4`
  1399. // Note that these all use the loose form, because they'll be
  1400. // checked against either the strict or loose comparator form
  1401. // later.
  1402. var HYPHENRANGE = R++;
  1403. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' +
  1404. '\\s+-\\s+' +
  1405. '(' + src[XRANGEPLAIN] + ')' +
  1406. '\\s*$';
  1407. var HYPHENRANGELOOSE = R++;
  1408. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' +
  1409. '\\s+-\\s+' +
  1410. '(' + src[XRANGEPLAINLOOSE] + ')' +
  1411. '\\s*$';
  1412. // Star ranges basically just allow anything at all.
  1413. var STAR = R++;
  1414. src[STAR] = '(<|>)?=?\\s*\\*';
  1415. // Compile to actual regexp objects.
  1416. // All are flag-free, unless they were created above with a flag.
  1417. for (var i = 0; i < R; i++) {
  1418. debug(i, src[i]);
  1419. if (!re[i])
  1420. re[i] = new RegExp(src[i]);
  1421. }
  1422. exports.parse = parse;
  1423. function parse(version, loose) {
  1424. if (version instanceof SemVer)
  1425. return version;
  1426. if (typeof version !== 'string')
  1427. return null;
  1428. if (version.length > MAX_LENGTH)
  1429. return null;
  1430. var r = loose ? re[LOOSE] : re[FULL];
  1431. if (!r.test(version))
  1432. return null;
  1433. try {
  1434. return new SemVer(version, loose);
  1435. } catch (er) {
  1436. return null;
  1437. }
  1438. }
  1439. exports.valid = valid;
  1440. function valid(version, loose) {
  1441. var v = parse(version, loose);
  1442. return v ? v.version : null;
  1443. }
  1444. exports.clean = clean;
  1445. function clean(version, loose) {
  1446. var s = parse(version.trim().replace(/^[=v]+/, ''), loose);
  1447. return s ? s.version : null;
  1448. }
  1449. exports.SemVer = SemVer;
  1450. function SemVer(version, loose) {
  1451. if (version instanceof SemVer) {
  1452. if (version.loose === loose)
  1453. return version;
  1454. else
  1455. version = version.version;
  1456. } else if (typeof version !== 'string') {
  1457. throw new TypeError('Invalid Version: ' + version);
  1458. }
  1459. if (version.length > MAX_LENGTH)
  1460. throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters')
  1461. if (!(this instanceof SemVer))
  1462. return new SemVer(version, loose);
  1463. debug('SemVer', version, loose);
  1464. this.loose = loose;
  1465. var m = version.trim().match(loose ? re[LOOSE] : re[FULL]);
  1466. if (!m)
  1467. throw new TypeError('Invalid Version: ' + version);
  1468. this.raw = version;
  1469. // these are actually numbers
  1470. this.major = +m[1];
  1471. this.minor = +m[2];
  1472. this.patch = +m[3];
  1473. if (this.major > MAX_SAFE_INTEGER || this.major < 0)
  1474. throw new TypeError('Invalid major version')
  1475. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0)
  1476. throw new TypeError('Invalid minor version')
  1477. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0)
  1478. throw new TypeError('Invalid patch version')
  1479. // numberify any prerelease numeric ids
  1480. if (!m[4])
  1481. this.prerelease = [];
  1482. else
  1483. this.prerelease = m[4].split('.').map(function(id) {
  1484. if (/^[0-9]+$/.test(id)) {
  1485. var num = +id;
  1486. if (num >= 0 && num < MAX_SAFE_INTEGER)
  1487. return num;
  1488. }
  1489. return id;
  1490. });
  1491. this.build = m[5] ? m[5].split('.') : [];
  1492. this.format();
  1493. }
  1494. SemVer.prototype.format = function() {
  1495. this.version = this.major + '.' + this.minor + '.' + this.patch;
  1496. if (this.prerelease.length)
  1497. this.version += '-' + this.prerelease.join('.');
  1498. return this.version;
  1499. };
  1500. SemVer.prototype.toString = function() {
  1501. return this.version;
  1502. };
  1503. SemVer.prototype.compare = function(other) {
  1504. debug('SemVer.compare', this.version, this.loose, other);
  1505. if (!(other instanceof SemVer))
  1506. other = new SemVer(other, this.loose);
  1507. return this.compareMain(other) || this.comparePre(other);
  1508. };
  1509. SemVer.prototype.compareMain = function(other) {
  1510. if (!(other instanceof SemVer))
  1511. other = new SemVer(other, this.loose);
  1512. return compareIdentifiers(this.major, other.major) ||
  1513. compareIdentifiers(this.minor, other.minor) ||
  1514. compareIdentifiers(this.patch, other.patch);
  1515. };
  1516. SemVer.prototype.comparePre = function(other) {
  1517. if (!(other instanceof SemVer))
  1518. other = new SemVer(other, this.loose);
  1519. // NOT having a prerelease is > having one
  1520. if (this.prerelease.length && !other.prerelease.length)
  1521. return -1;
  1522. else if (!this.prerelease.length && other.prerelease.length)
  1523. return 1;
  1524. else if (!this.prerelease.length && !other.prerelease.length)
  1525. return 0;
  1526. var i = 0;
  1527. do {
  1528. var a = this.prerelease[i];
  1529. var b = other.prerelease[i];
  1530. debug('prerelease compare', i, a, b);
  1531. if (a === undefined && b === undefined)
  1532. return 0;
  1533. else if (b === undefined)
  1534. return 1;
  1535. else if (a === undefined)
  1536. return -1;
  1537. else if (a === b)
  1538. continue;
  1539. else
  1540. return compareIdentifiers(a, b);
  1541. } while (++i);
  1542. };
  1543. // preminor will bump the version up to the next minor release, and immediately
  1544. // down to pre-release. premajor and prepatch work the same way.
  1545. SemVer.prototype.inc = function(release, identifier) {
  1546. switch (release) {
  1547. case 'premajor':
  1548. this.prerelease.length = 0;
  1549. this.patch = 0;
  1550. this.minor = 0;
  1551. this.major++;
  1552. this.inc('pre', identifier);
  1553. break;
  1554. case 'preminor':
  1555. this.prerelease.length = 0;
  1556. this.patch = 0;
  1557. this.minor++;
  1558. this.inc('pre', identifier);
  1559. break;
  1560. case 'prepatch':
  1561. // If this is already a prerelease, it will bump to the next version
  1562. // drop any prereleases that might already exist, since they are not
  1563. // relevant at this point.
  1564. this.prerelease.length = 0;
  1565. this.inc('patch', identifier);
  1566. this.inc('pre', identifier);
  1567. break;
  1568. // If the input is a non-prerelease version, this acts the same as
  1569. // prepatch.
  1570. case 'prerelease':
  1571. if (this.prerelease.length === 0)
  1572. this.inc('patch', identifier);
  1573. this.inc('pre', identifier);
  1574. break;
  1575. case 'major':
  1576. // If this is a pre-major version, bump up to the same major version.
  1577. // Otherwise increment major.
  1578. // 1.0.0-5 bumps to 1.0.0
  1579. // 1.1.0 bumps to 2.0.0
  1580. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0)
  1581. this.major++;
  1582. this.minor = 0;
  1583. this.patch = 0;
  1584. this.prerelease = [];
  1585. break;
  1586. case 'minor':
  1587. // If this is a pre-minor version, bump up to the same minor version.
  1588. // Otherwise increment minor.
  1589. // 1.2.0-5 bumps to 1.2.0
  1590. // 1.2.1 bumps to 1.3.0
  1591. if (this.patch !== 0 || this.prerelease.length === 0)
  1592. this.minor++;
  1593. this.patch = 0;
  1594. this.prerelease = [];
  1595. break;
  1596. case 'patch':
  1597. // If this is not a pre-release version, it will increment the patch.
  1598. // If it is a pre-release it will bump up to the same patch version.
  1599. // 1.2.0-5 patches to 1.2.0
  1600. // 1.2.0 patches to 1.2.1
  1601. if (this.prerelease.length === 0)
  1602. this.patch++;
  1603. this.prerelease = [];
  1604. break;
  1605. // This probably shouldn't be used publicly.
  1606. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  1607. case 'pre':
  1608. if (this.prerelease.length === 0)
  1609. this.prerelease = [0];
  1610. else {
  1611. var i = this.prerelease.length;
  1612. while (--i >= 0) {
  1613. if (typeof this.prerelease[i] === 'number') {
  1614. this.prerelease[i]++;
  1615. i = -2;
  1616. }
  1617. }
  1618. if (i === -1) // didn't increment anything
  1619. this.prerelease.push(0);
  1620. }
  1621. if (identifier) {
  1622. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  1623. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  1624. if (this.prerelease[0] === identifier) {
  1625. if (isNaN(this.prerelease[1]))
  1626. this.prerelease = [identifier, 0];
  1627. } else
  1628. this.prerelease = [identifier, 0];
  1629. }
  1630. break;
  1631. default:
  1632. throw new Error('invalid increment argument: ' + release);
  1633. }
  1634. this.format();
  1635. this.raw = this.version;
  1636. return this;
  1637. };
  1638. exports.inc = inc;
  1639. function inc(version, release, loose, identifier) {
  1640. if (typeof(loose) === 'string') {
  1641. identifier = loose;
  1642. loose = undefined;
  1643. }
  1644. try {
  1645. return new SemVer(version, loose).inc(release, identifier).version;
  1646. } catch (er) {
  1647. return null;
  1648. }
  1649. }
  1650. exports.diff = diff;
  1651. function diff(version1, version2) {
  1652. if (eq(version1, version2)) {
  1653. return null;
  1654. } else {
  1655. var v1 = parse(version1);
  1656. var v2 = parse(version2);
  1657. if (v1.prerelease.length || v2.prerelease.length) {
  1658. for (var key in v1) {
  1659. if (key === 'major' || key === 'minor' || key === 'patch') {
  1660. if (v1[key] !== v2[key]) {
  1661. return 'pre'+key;
  1662. }
  1663. }
  1664. }
  1665. return 'prerelease';
  1666. }
  1667. for (var key in v1) {
  1668. if (key === 'major' || key === 'minor' || key === 'patch') {
  1669. if (v1[key] !== v2[key]) {
  1670. return key;
  1671. }
  1672. }
  1673. }
  1674. }
  1675. }
  1676. exports.compareIdentifiers = compareIdentifiers;
  1677. var numeric = /^[0-9]+$/;
  1678. function compareIdentifiers(a, b) {
  1679. var anum = numeric.test(a);
  1680. var bnum = numeric.test(b);
  1681. if (anum && bnum) {
  1682. a = +a;
  1683. b = +b;
  1684. }
  1685. return (anum && !bnum) ? -1 :
  1686. (bnum && !anum) ? 1 :
  1687. a < b ? -1 :
  1688. a > b ? 1 :
  1689. 0;
  1690. }
  1691. exports.rcompareIdentifiers = rcompareIdentifiers;
  1692. function rcompareIdentifiers(a, b) {
  1693. return compareIdentifiers(b, a);
  1694. }
  1695. exports.major = major;
  1696. function major(a, loose) {
  1697. return new SemVer(a, loose).major;
  1698. }
  1699. exports.minor = minor;
  1700. function minor(a, loose) {
  1701. return new SemVer(a, loose).minor;
  1702. }
  1703. exports.patch = patch;
  1704. function patch(a, loose) {
  1705. return new SemVer(a, loose).patch;
  1706. }
  1707. exports.compare = compare;
  1708. function compare(a, b, loose) {
  1709. return new SemVer(a, loose).compare(new SemVer(b, loose));
  1710. }
  1711. exports.compareLoose = compareLoose;
  1712. function compareLoose(a, b) {
  1713. return compare(a, b, true);
  1714. }
  1715. exports.rcompare = rcompare;
  1716. function rcompare(a, b, loose) {
  1717. return compare(b, a, loose);
  1718. }
  1719. exports.sort = sort;
  1720. function sort(list, loose) {
  1721. return list.sort(function(a, b) {
  1722. return exports.compare(a, b, loose);
  1723. });
  1724. }
  1725. exports.rsort = rsort;
  1726. function rsort(list, loose) {
  1727. return list.sort(function(a, b) {
  1728. return exports.rcompare(a, b, loose);
  1729. });
  1730. }
  1731. exports.gt = gt;
  1732. function gt(a, b, loose) {
  1733. return compare(a, b, loose) > 0;
  1734. }
  1735. exports.lt = lt;
  1736. function lt(a, b, loose) {
  1737. return compare(a, b, loose) < 0;
  1738. }
  1739. exports.eq = eq;
  1740. function eq(a, b, loose) {
  1741. return compare(a, b, loose) === 0;
  1742. }
  1743. exports.neq = neq;
  1744. function neq(a, b, loose) {
  1745. return compare(a, b, loose) !== 0;
  1746. }
  1747. exports.gte = gte;
  1748. function gte(a, b, loose) {
  1749. return compare(a, b, loose) >= 0;
  1750. }
  1751. exports.lte = lte;
  1752. function lte(a, b, loose) {
  1753. return compare(a, b, loose) <= 0;
  1754. }
  1755. exports.cmp = cmp;
  1756. function cmp(a, op, b, loose) {
  1757. var ret;
  1758. switch (op) {
  1759. case '===':
  1760. if (typeof a === 'object') a = a.version;
  1761. if (typeof b === 'object') b = b.version;
  1762. ret = a === b;
  1763. break;
  1764. case '!==':
  1765. if (typeof a === 'object') a = a.version;
  1766. if (typeof b === 'object') b = b.version;
  1767. ret = a !== b;
  1768. break;
  1769. case '': case '=': case '==': ret = eq(a, b, loose); break;
  1770. case '!=': ret = neq(a, b, loose); break;
  1771. case '>': ret = gt(a, b, loose); break;
  1772. case '>=': ret = gte(a, b, loose); break;
  1773. case '<': ret = lt(a, b, loose); break;
  1774. case '<=': ret = lte(a, b, loose); break;
  1775. default: throw new TypeError('Invalid operator: ' + op);
  1776. }
  1777. return ret;
  1778. }
  1779. exports.Comparator = Comparator;
  1780. function Comparator(comp, loose) {
  1781. if (comp instanceof Comparator) {
  1782. if (comp.loose === loose)
  1783. return comp;
  1784. else
  1785. comp = comp.value;
  1786. }
  1787. if (!(this instanceof Comparator))
  1788. return new Comparator(comp, loose);
  1789. debug('comparator', comp, loose);
  1790. this.loose = loose;
  1791. this.parse(comp);
  1792. if (this.semver === ANY)
  1793. this.value = '';
  1794. else
  1795. this.value = this.operator + this.semver.version;
  1796. debug('comp', this);
  1797. }
  1798. var ANY = {};
  1799. Comparator.prototype.parse = function(comp) {
  1800. var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  1801. var m = comp.match(r);
  1802. if (!m)
  1803. throw new TypeError('Invalid comparator: ' + comp);
  1804. this.operator = m[1];
  1805. if (this.operator === '=')
  1806. this.operator = '';
  1807. // if it literally is just '>' or '' then allow anything.
  1808. if (!m[2])
  1809. this.semver = ANY;
  1810. else
  1811. this.semver = new SemVer(m[2], this.loose);
  1812. };
  1813. Comparator.prototype.toString = function() {
  1814. return this.value;
  1815. };
  1816. Comparator.prototype.test = function(version) {
  1817. debug('Comparator.test', version, this.loose);
  1818. if (this.semver === ANY)
  1819. return true;
  1820. if (typeof version === 'string')
  1821. version = new SemVer(version, this.loose);
  1822. return cmp(version, this.operator, this.semver, this.loose);
  1823. };
  1824. Comparator.prototype.intersects = function(comp, loose) {
  1825. if (!(comp instanceof Comparator)) {
  1826. throw new TypeError('a Comparator is required');
  1827. }
  1828. var rangeTmp;
  1829. if (this.operator === '') {
  1830. rangeTmp = new Range(comp.value, loose);
  1831. return satisfies(this.value, rangeTmp, loose);
  1832. } else if (comp.operator === '') {
  1833. rangeTmp = new Range(this.value, loose);
  1834. return satisfies(comp.semver, rangeTmp, loose);
  1835. }
  1836. var sameDirectionIncreasing =
  1837. (this.operator === '>=' || this.operator === '>') &&
  1838. (comp.operator === '>=' || comp.operator === '>');
  1839. var sameDirectionDecreasing =
  1840. (this.operator === '<=' || this.operator === '<') &&
  1841. (comp.operator === '<=' || comp.operator === '<');
  1842. var sameSemVer = this.semver.version === comp.semver.version;
  1843. var differentDirectionsInclusive =
  1844. (this.operator === '>=' || this.operator === '<=') &&
  1845. (comp.operator === '>=' || comp.operator === '<=');
  1846. var oppositeDirectionsLessThan =
  1847. cmp(this.semver, '<', comp.semver, loose) &&
  1848. ((this.operator === '>=' || this.operator === '>') &&
  1849. (comp.operator === '<=' || comp.operator === '<'));
  1850. var oppositeDirectionsGreaterThan =
  1851. cmp(this.semver, '>', comp.semver, loose) &&
  1852. ((this.operator === '<=' || this.operator === '<') &&
  1853. (comp.operator === '>=' || comp.operator === '>'));
  1854. return sameDirectionIncreasing || sameDirectionDecreasing ||
  1855. (sameSemVer && differentDirectionsInclusive) ||
  1856. oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  1857. };
  1858. exports.Range = Range;
  1859. function Range(range, loose) {
  1860. if (range instanceof Range) {
  1861. if (range.loose === loose) {
  1862. return range;
  1863. } else {
  1864. return new Range(range.raw, loose);
  1865. }
  1866. }
  1867. if (range instanceof Comparator) {
  1868. return new Range(range.value, loose);
  1869. }
  1870. if (!(this instanceof Range))
  1871. return new Range(range, loose);
  1872. this.loose = loose;
  1873. // First, split based on boolean or ||
  1874. this.raw = range;
  1875. this.set = range.split(/\s*\|\|\s*/).map(function(range) {
  1876. return this.parseRange(range.trim());
  1877. }, this).filter(function(c) {
  1878. // throw out any that are not relevant for whatever reason
  1879. return c.length;
  1880. });
  1881. if (!this.set.length) {
  1882. throw new TypeError('Invalid SemVer Range: ' + range);
  1883. }
  1884. this.format();
  1885. }
  1886. Range.prototype.format = function() {
  1887. this.range = this.set.map(function(comps) {
  1888. return comps.join(' ').trim();
  1889. }).join('||').trim();
  1890. return this.range;
  1891. };
  1892. Range.prototype.toString = function() {
  1893. return this.range;
  1894. };
  1895. Range.prototype.parseRange = function(range) {
  1896. var loose = this.loose;
  1897. range = range.trim();
  1898. debug('range', range, loose);
  1899. // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  1900. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  1901. range = range.replace(hr, hyphenReplace);
  1902. debug('hyphen replace', range);
  1903. // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  1904. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  1905. debug('comparator trim', range, re[COMPARATORTRIM]);
  1906. // `~ 1.2.3` => `~1.2.3`
  1907. range = range.replace(re[TILDETRIM], tildeTrimReplace);
  1908. // `^ 1.2.3` => `^1.2.3`
  1909. range = range.replace(re[CARETTRIM], caretTrimReplace);
  1910. // normalize spaces
  1911. range = range.split(/\s+/).join(' ');
  1912. // At this point, the range is completely trimmed and
  1913. // ready to be split into comparators.
  1914. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  1915. var set = range.split(' ').map(function(comp) {
  1916. return parseComparator(comp, loose);
  1917. }).join(' ').split(/\s+/);
  1918. if (this.loose) {
  1919. // in loose mode, throw out any that are not valid comparators
  1920. set = set.filter(function(comp) {
  1921. return !!comp.match(compRe);
  1922. });
  1923. }
  1924. set = set.map(function(comp) {
  1925. return new Comparator(comp, loose);
  1926. });
  1927. return set;
  1928. };
  1929. Range.prototype.intersects = function(range, loose) {
  1930. if (!(range instanceof Range)) {
  1931. throw new TypeError('a Range is required');
  1932. }
  1933. return this.set.some(function(thisComparators) {
  1934. return thisComparators.every(function(thisComparator) {
  1935. return range.set.some(function(rangeComparators) {
  1936. return rangeComparators.every(function(rangeComparator) {
  1937. return thisComparator.intersects(rangeComparator, loose);
  1938. });
  1939. });
  1940. });
  1941. });
  1942. };
  1943. // Mostly just for testing and legacy API reasons
  1944. exports.toComparators = toComparators;
  1945. function toComparators(range, loose) {
  1946. return new Range(range, loose).set.map(function(comp) {
  1947. return comp.map(function(c) {
  1948. return c.value;
  1949. }).join(' ').trim().split(' ');
  1950. });
  1951. }
  1952. // comprised of xranges, tildes, stars, and gtlt's at this point.
  1953. // already replaced the hyphen ranges
  1954. // turn into a set of JUST comparators.
  1955. function parseComparator(comp, loose) {
  1956. debug('comp', comp);
  1957. comp = replaceCarets(comp, loose);
  1958. debug('caret', comp);
  1959. comp = replaceTildes(comp, loose);
  1960. debug('tildes', comp);
  1961. comp = replaceXRanges(comp, loose);
  1962. debug('xrange', comp);
  1963. comp = replaceStars(comp, loose);
  1964. debug('stars', comp);
  1965. return comp;
  1966. }
  1967. function isX(id) {
  1968. return !id || id.toLowerCase() === 'x' || id === '*';
  1969. }
  1970. // ~, ~> --> * (any, kinda silly)
  1971. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  1972. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  1973. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  1974. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  1975. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  1976. function replaceTildes(comp, loose) {
  1977. return comp.trim().split(/\s+/).map(function(comp) {
  1978. return replaceTilde(comp, loose);
  1979. }).join(' ');
  1980. }
  1981. function replaceTilde(comp, loose) {
  1982. var r = loose ? re[TILDELOOSE] : re[TILDE];
  1983. return comp.replace(r, function(_, M, m, p, pr) {
  1984. debug('tilde', comp, _, M, m, p, pr);
  1985. var ret;
  1986. if (isX(M))
  1987. ret = '';
  1988. else if (isX(m))
  1989. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  1990. else if (isX(p))
  1991. // ~1.2 == >=1.2.0 <1.3.0
  1992. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  1993. else if (pr) {
  1994. debug('replaceTilde pr', pr);
  1995. if (pr.charAt(0) !== '-')
  1996. pr = '-' + pr;
  1997. ret = '>=' + M + '.' + m + '.' + p + pr +
  1998. ' <' + M + '.' + (+m + 1) + '.0';
  1999. } else
  2000. // ~1.2.3 == >=1.2.3 <1.3.0
  2001. ret = '>=' + M + '.' + m + '.' + p +
  2002. ' <' + M + '.' + (+m + 1) + '.0';
  2003. debug('tilde return', ret);
  2004. return ret;
  2005. });
  2006. }
  2007. // ^ --> * (any, kinda silly)
  2008. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  2009. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  2010. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  2011. // ^1.2.3 --> >=1.2.3 <2.0.0
  2012. // ^1.2.0 --> >=1.2.0 <2.0.0
  2013. function replaceCarets(comp, loose) {
  2014. return comp.trim().split(/\s+/).map(function(comp) {
  2015. return replaceCaret(comp, loose);
  2016. }).join(' ');
  2017. }
  2018. function replaceCaret(comp, loose) {
  2019. debug('caret', comp, loose);
  2020. var r = loose ? re[CARETLOOSE] : re[CARET];
  2021. return comp.replace(r, function(_, M, m, p, pr) {
  2022. debug('caret', comp, _, M, m, p, pr);
  2023. var ret;
  2024. if (isX(M))
  2025. ret = '';
  2026. else if (isX(m))
  2027. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  2028. else if (isX(p)) {
  2029. if (M === '0')
  2030. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  2031. else
  2032. ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  2033. } else if (pr) {
  2034. debug('replaceCaret pr', pr);
  2035. if (pr.charAt(0) !== '-')
  2036. pr = '-' + pr;
  2037. if (M === '0') {
  2038. if (m === '0')
  2039. ret = '>=' + M + '.' + m + '.' + p + pr +
  2040. ' <' + M + '.' + m + '.' + (+p + 1);
  2041. else
  2042. ret = '>=' + M + '.' + m + '.' + p + pr +
  2043. ' <' + M + '.' + (+m + 1) + '.0';
  2044. } else
  2045. ret = '>=' + M + '.' + m + '.' + p + pr +
  2046. ' <' + (+M + 1) + '.0.0';
  2047. } else {
  2048. debug('no pr');
  2049. if (M === '0') {
  2050. if (m === '0')
  2051. ret = '>=' + M + '.' + m + '.' + p +
  2052. ' <' + M + '.' + m + '.' + (+p + 1);
  2053. else
  2054. ret = '>=' + M + '.' + m + '.' + p +
  2055. ' <' + M + '.' + (+m + 1) + '.0';
  2056. } else
  2057. ret = '>=' + M + '.' + m + '.' + p +
  2058. ' <' + (+M + 1) + '.0.0';
  2059. }
  2060. debug('caret return', ret);
  2061. return ret;
  2062. });
  2063. }
  2064. function replaceXRanges(comp, loose) {
  2065. debug('replaceXRanges', comp, loose);
  2066. return comp.split(/\s+/).map(function(comp) {
  2067. return replaceXRange(comp, loose);
  2068. }).join(' ');
  2069. }
  2070. function replaceXRange(comp, loose) {
  2071. comp = comp.trim();
  2072. var r = loose ? re[XRANGELOOSE] : re[XRANGE];
  2073. return comp.replace(r, function(ret, gtlt, M, m, p, pr) {
  2074. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  2075. var xM = isX(M);
  2076. var xm = xM || isX(m);
  2077. var xp = xm || isX(p);
  2078. var anyX = xp;
  2079. if (gtlt === '=' && anyX)
  2080. gtlt = '';
  2081. if (xM) {
  2082. if (gtlt === '>' || gtlt === '<') {
  2083. // nothing is allowed
  2084. ret = '<0.0.0';
  2085. } else {
  2086. // nothing is forbidden
  2087. ret = '*';
  2088. }
  2089. } else if (gtlt && anyX) {
  2090. // replace X with 0
  2091. if (xm)
  2092. m = 0;
  2093. if (xp)
  2094. p = 0;
  2095. if (gtlt === '>') {
  2096. // >1 => >=2.0.0
  2097. // >1.2 => >=1.3.0
  2098. // >1.2.3 => >= 1.2.4
  2099. gtlt = '>=';
  2100. if (xm) {
  2101. M = +M + 1;
  2102. m = 0;
  2103. p = 0;
  2104. } else if (xp) {
  2105. m = +m + 1;
  2106. p = 0;
  2107. }
  2108. } else if (gtlt === '<=') {
  2109. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  2110. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  2111. gtlt = '<';
  2112. if (xm)
  2113. M = +M + 1;
  2114. else
  2115. m = +m + 1;
  2116. }
  2117. ret = gtlt + M + '.' + m + '.' + p;
  2118. } else if (xm) {
  2119. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  2120. } else if (xp) {
  2121. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  2122. }
  2123. debug('xRange return', ret);
  2124. return ret;
  2125. });
  2126. }
  2127. // Because * is AND-ed with everything else in the comparator,
  2128. // and '' means "any version", just remove the *s entirely.
  2129. function replaceStars(comp, loose) {
  2130. debug('replaceStars', comp, loose);
  2131. // Looseness is ignored here. star is always as loose as it gets!
  2132. return comp.trim().replace(re[STAR], '');
  2133. }
  2134. // This function is passed to string.replace(re[HYPHENRANGE])
  2135. // M, m, patch, prerelease, build
  2136. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  2137. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  2138. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  2139. function hyphenReplace($0,
  2140. from, fM, fm, fp, fpr, fb,
  2141. to, tM, tm, tp, tpr, tb) {
  2142. if (isX(fM))
  2143. from = '';
  2144. else if (isX(fm))
  2145. from = '>=' + fM + '.0.0';
  2146. else if (isX(fp))
  2147. from = '>=' + fM + '.' + fm + '.0';
  2148. else
  2149. from = '>=' + from;
  2150. if (isX(tM))
  2151. to = '';
  2152. else if (isX(tm))
  2153. to = '<' + (+tM + 1) + '.0.0';
  2154. else if (isX(tp))
  2155. to = '<' + tM + '.' + (+tm + 1) + '.0';
  2156. else if (tpr)
  2157. to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
  2158. else
  2159. to = '<=' + to;
  2160. return (from + ' ' + to).trim();
  2161. }
  2162. // if ANY of the sets match ALL of its comparators, then pass
  2163. Range.prototype.test = function(version) {
  2164. if (!version)
  2165. return false;
  2166. if (typeof version === 'string')
  2167. version = new SemVer(version, this.loose);
  2168. for (var i = 0; i < this.set.length; i++) {
  2169. if (testSet(this.set[i], version))
  2170. return true;
  2171. }
  2172. return false;
  2173. };
  2174. function testSet(set, version) {
  2175. for (var i = 0; i < set.length; i++) {
  2176. if (!set[i].test(version))
  2177. return false;
  2178. }
  2179. if (version.prerelease.length) {
  2180. // Find the set of versions that are allowed to have prereleases
  2181. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  2182. // That should allow `1.2.3-pr.2` to pass.
  2183. // However, `1.2.4-alpha.notready` should NOT be allowed,
  2184. // even though it's within the range set by the comparators.
  2185. for (var i = 0; i < set.length; i++) {
  2186. debug(set[i].semver);
  2187. if (set[i].semver === ANY)
  2188. continue;
  2189. if (set[i].semver.prerelease.length > 0) {
  2190. var allowed = set[i].semver;
  2191. if (allowed.major === version.major &&
  2192. allowed.minor === version.minor &&
  2193. allowed.patch === version.patch)
  2194. return true;
  2195. }
  2196. }
  2197. // Version has a -pre, but it's not one of the ones we like.
  2198. return false;
  2199. }
  2200. return true;
  2201. }
  2202. exports.satisfies = satisfies;
  2203. function satisfies(version, range, loose) {
  2204. try {
  2205. range = new Range(range, loose);
  2206. } catch (er) {
  2207. return false;
  2208. }
  2209. return range.test(version);
  2210. }
  2211. exports.maxSatisfying = maxSatisfying;
  2212. function maxSatisfying(versions, range, loose) {
  2213. var max = null;
  2214. var maxSV = null;
  2215. try {
  2216. var rangeObj = new Range(range, loose);
  2217. } catch (er) {
  2218. return null;
  2219. }
  2220. versions.forEach(function (v) {
  2221. if (rangeObj.test(v)) { // satisfies(v, range, loose)
  2222. if (!max || maxSV.compare(v) === -1) { // compare(max, v, true)
  2223. max = v;
  2224. maxSV = new SemVer(max, loose);
  2225. }
  2226. }
  2227. });
  2228. return max;
  2229. }
  2230. exports.minSatisfying = minSatisfying;
  2231. function minSatisfying(versions, range, loose) {
  2232. var min = null;
  2233. var minSV = null;
  2234. try {
  2235. var rangeObj = new Range(range, loose);
  2236. } catch (er) {
  2237. return null;
  2238. }
  2239. versions.forEach(function (v) {
  2240. if (rangeObj.test(v)) { // satisfies(v, range, loose)
  2241. if (!min || minSV.compare(v) === 1) { // compare(min, v, true)
  2242. min = v;
  2243. minSV = new SemVer(min, loose);
  2244. }
  2245. }
  2246. });
  2247. return min;
  2248. }
  2249. exports.validRange = validRange;
  2250. function validRange(range, loose) {
  2251. try {
  2252. // Return '*' instead of '' so that truthiness works.
  2253. // This will throw if it's invalid anyway
  2254. return new Range(range, loose).range || '*';
  2255. } catch (er) {
  2256. return null;
  2257. }
  2258. }
  2259. // Determine if version is less than all the versions possible in the range
  2260. exports.ltr = ltr;
  2261. function ltr(version, range, loose) {
  2262. return outside(version, range, '<', loose);
  2263. }
  2264. // Determine if version is greater than all the versions possible in the range.
  2265. exports.gtr = gtr;
  2266. function gtr(version, range, loose) {
  2267. return outside(version, range, '>', loose);
  2268. }
  2269. exports.outside = outside;
  2270. function outside(version, range, hilo, loose) {
  2271. version = new SemVer(version, loose);
  2272. range = new Range(range, loose);
  2273. var gtfn, ltefn, ltfn, comp, ecomp;
  2274. switch (hilo) {
  2275. case '>':
  2276. gtfn = gt;
  2277. ltefn = lte;
  2278. ltfn = lt;
  2279. comp = '>';
  2280. ecomp = '>=';
  2281. break;
  2282. case '<':
  2283. gtfn = lt;
  2284. ltefn = gte;
  2285. ltfn = gt;
  2286. comp = '<';
  2287. ecomp = '<=';
  2288. break;
  2289. default:
  2290. throw new TypeError('Must provide a hilo val of "<" or ">"');
  2291. }
  2292. // If it satisifes the range it is not outside
  2293. if (satisfies(version, range, loose)) {
  2294. return false;
  2295. }
  2296. // From now on, variable terms are as if we're in "gtr" mode.
  2297. // but note that everything is flipped for the "ltr" function.
  2298. for (var i = 0; i < range.set.length; ++i) {
  2299. var comparators = range.set[i];
  2300. var high = null;
  2301. var low = null;
  2302. comparators.forEach(function(comparator) {
  2303. if (comparator.semver === ANY) {
  2304. comparator = new Comparator('>=0.0.0');
  2305. }
  2306. high = high || comparator;
  2307. low = low || comparator;
  2308. if (gtfn(comparator.semver, high.semver, loose)) {
  2309. high = comparator;
  2310. } else if (ltfn(comparator.semver, low.semver, loose)) {
  2311. low = comparator;
  2312. }
  2313. });
  2314. // If the edge version comparator has a operator then our version
  2315. // isn't outside it
  2316. if (high.operator === comp || high.operator === ecomp) {
  2317. return false;
  2318. }
  2319. // If the lowest version comparator has an operator and our version
  2320. // is less than it then it isn't higher than the range
  2321. if ((!low.operator || low.operator === comp) &&
  2322. ltefn(version, low.semver)) {
  2323. return false;
  2324. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  2325. return false;
  2326. }
  2327. }
  2328. return true;
  2329. }
  2330. exports.prerelease = prerelease;
  2331. function prerelease(version, loose) {
  2332. var parsed = parse(version, loose);
  2333. return (parsed && parsed.prerelease.length) ? parsed.prerelease : null;
  2334. }
  2335. exports.intersects = intersects;
  2336. function intersects(r1, r2, loose) {
  2337. r1 = new Range(r1, loose);
  2338. r2 = new Range(r2, loose);
  2339. return r1.intersects(r2)
  2340. }
  2341. });
  2342. var assert$1 = true;
  2343. var buffer_ieee754 = "< 0.9.7";
  2344. var buffer = true;
  2345. var child_process = true;
  2346. var cluster = true;
  2347. var console$1 = true;
  2348. var constants = true;
  2349. var crypto = true;
  2350. var _debugger = "< 8";
  2351. var dgram = true;
  2352. var dns = true;
  2353. var domain = true;
  2354. var events = true;
  2355. var freelist = "< 6";
  2356. var fs$1 = true;
  2357. var http = true;
  2358. var http2 = ">= 8.8";
  2359. var https = true;
  2360. var _http_server = ">= 0.11";
  2361. var _linklist = "< 8";
  2362. var module$1 = true;
  2363. var net = true;
  2364. var os$1 = true;
  2365. var path$1 = true;
  2366. var perf_hooks = ">= 8.5";
  2367. var process$1 = ">= 1";
  2368. var punycode = true;
  2369. var querystring = true;
  2370. var readline = true;
  2371. var repl = true;
  2372. var stream = true;
  2373. var string_decoder = true;
  2374. var sys = true;
  2375. var timers = true;
  2376. var tls = true;
  2377. var tty = true;
  2378. var url$1 = true;
  2379. var util$3 = true;
  2380. var v8 = ">= 1";
  2381. var vm = true;
  2382. var zlib = true;
  2383. var core$1 = {
  2384. assert: assert$1,
  2385. buffer_ieee754: buffer_ieee754,
  2386. buffer: buffer,
  2387. child_process: child_process,
  2388. cluster: cluster,
  2389. console: console$1,
  2390. constants: constants,
  2391. crypto: crypto,
  2392. _debugger: _debugger,
  2393. dgram: dgram,
  2394. dns: dns,
  2395. domain: domain,
  2396. events: events,
  2397. freelist: freelist,
  2398. fs: fs$1,
  2399. http: http,
  2400. http2: http2,
  2401. https: https,
  2402. _http_server: _http_server,
  2403. _linklist: _linklist,
  2404. module: module$1,
  2405. net: net,
  2406. os: os$1,
  2407. path: path$1,
  2408. perf_hooks: perf_hooks,
  2409. process: process$1,
  2410. punycode: punycode,
  2411. querystring: querystring,
  2412. readline: readline,
  2413. repl: repl,
  2414. stream: stream,
  2415. string_decoder: string_decoder,
  2416. sys: sys,
  2417. timers: timers,
  2418. tls: tls,
  2419. tty: tty,
  2420. url: url$1,
  2421. util: util$3,
  2422. v8: v8,
  2423. vm: vm,
  2424. zlib: zlib
  2425. };
  2426. var core$2 = Object.freeze({
  2427. assert: assert$1,
  2428. buffer_ieee754: buffer_ieee754,
  2429. buffer: buffer,
  2430. child_process: child_process,
  2431. cluster: cluster,
  2432. console: console$1,
  2433. constants: constants,
  2434. crypto: crypto,
  2435. _debugger: _debugger,
  2436. dgram: dgram,
  2437. dns: dns,
  2438. domain: domain,
  2439. events: events,
  2440. freelist: freelist,
  2441. fs: fs$1,
  2442. http: http,
  2443. http2: http2,
  2444. https: https,
  2445. _http_server: _http_server,
  2446. _linklist: _linklist,
  2447. module: module$1,
  2448. net: net,
  2449. os: os$1,
  2450. path: path$1,
  2451. perf_hooks: perf_hooks,
  2452. process: process$1,
  2453. punycode: punycode,
  2454. querystring: querystring,
  2455. readline: readline,
  2456. repl: repl,
  2457. stream: stream,
  2458. string_decoder: string_decoder,
  2459. sys: sys,
  2460. timers: timers,
  2461. tls: tls,
  2462. tty: tty,
  2463. url: url$1,
  2464. util: util$3,
  2465. v8: v8,
  2466. vm: vm,
  2467. zlib: zlib,
  2468. default: core$1
  2469. });
  2470. var data = ( core$2 && core$1 ) || core$2;
  2471. var current = (process.versions && process.versions.node && process.versions.node.split('.')) || [];
  2472. function versionIncluded(specifier) {
  2473. if (specifier === true) { return true; }
  2474. var parts = specifier.split(' ');
  2475. var op = parts[0];
  2476. var versionParts = parts[1].split('.');
  2477. for (var i = 0; i < 3; ++i) {
  2478. var cur = Number(current[i] || 0);
  2479. var ver = Number(versionParts[i] || 0);
  2480. if (cur === ver) {
  2481. continue; // eslint-disable-line no-restricted-syntax, no-continue
  2482. }
  2483. if (op === '<') {
  2484. return cur < ver;
  2485. } else if (op === '>=') {
  2486. return cur >= ver;
  2487. } else {
  2488. return false;
  2489. }
  2490. }
  2491. return false;
  2492. }
  2493. var core = {};
  2494. for (var mod in data) { // eslint-disable-line no-restricted-syntax
  2495. if (Object.prototype.hasOwnProperty.call(data, mod)) {
  2496. core[mod] = versionIncluded(data[mod]);
  2497. }
  2498. }
  2499. var core_1 = core;
  2500. var caller = function () {
  2501. // see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
  2502. var origPrepareStackTrace = Error.prepareStackTrace;
  2503. Error.prepareStackTrace = function (_, stack) { return stack; };
  2504. var stack = (new Error()).stack;
  2505. Error.prepareStackTrace = origPrepareStackTrace;
  2506. return stack[2].getFileName();
  2507. };
  2508. var pathParse = createCommonjsModule(function (module) {
  2509. 'use strict';
  2510. var isWindows = process.platform === 'win32';
  2511. // Regex to split a windows path into three parts: [*, device, slash,
  2512. // tail] windows-only
  2513. var splitDeviceRe =
  2514. /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
  2515. // Regex to split the tail part of the above into [*, dir, basename, ext]
  2516. var splitTailRe =
  2517. /^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
  2518. var win32 = {};
  2519. // Function to split a filename into [root, dir, basename, ext]
  2520. function win32SplitPath(filename) {
  2521. // Separate device+slash from tail
  2522. var result = splitDeviceRe.exec(filename),
  2523. device = (result[1] || '') + (result[2] || ''),
  2524. tail = result[3] || '';
  2525. // Split the tail into dir, basename and extension
  2526. var result2 = splitTailRe.exec(tail),
  2527. dir = result2[1],
  2528. basename = result2[2],
  2529. ext = result2[3];
  2530. return [device, dir, basename, ext];
  2531. }
  2532. win32.parse = function(pathString) {
  2533. if (typeof pathString !== 'string') {
  2534. throw new TypeError(
  2535. "Parameter 'pathString' must be a string, not " + typeof pathString
  2536. );
  2537. }
  2538. var allParts = win32SplitPath(pathString);
  2539. if (!allParts || allParts.length !== 4) {
  2540. throw new TypeError("Invalid path '" + pathString + "'");
  2541. }
  2542. return {
  2543. root: allParts[0],
  2544. dir: allParts[0] + allParts[1].slice(0, -1),
  2545. base: allParts[2],
  2546. ext: allParts[3],
  2547. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  2548. };
  2549. };
  2550. // Split a filename into [root, dir, basename, ext], unix version
  2551. // 'root' is just a slash, or nothing.
  2552. var splitPathRe =
  2553. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  2554. var posix = {};
  2555. function posixSplitPath(filename) {
  2556. return splitPathRe.exec(filename).slice(1);
  2557. }
  2558. posix.parse = function(pathString) {
  2559. if (typeof pathString !== 'string') {
  2560. throw new TypeError(
  2561. "Parameter 'pathString' must be a string, not " + typeof pathString
  2562. );
  2563. }
  2564. var allParts = posixSplitPath(pathString);
  2565. if (!allParts || allParts.length !== 4) {
  2566. throw new TypeError("Invalid path '" + pathString + "'");
  2567. }
  2568. allParts[1] = allParts[1] || '';
  2569. allParts[2] = allParts[2] || '';
  2570. allParts[3] = allParts[3] || '';
  2571. return {
  2572. root: allParts[0],
  2573. dir: allParts[0] + allParts[1].slice(0, -1),
  2574. base: allParts[2],
  2575. ext: allParts[3],
  2576. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  2577. };
  2578. };
  2579. if (isWindows)
  2580. module.exports = win32.parse;
  2581. else /* posix */
  2582. module.exports = posix.parse;
  2583. module.exports.posix = posix.parse;
  2584. module.exports.win32 = win32.parse;
  2585. });
  2586. var parse = path.parse || pathParse;
  2587. var nodeModulesPaths = function nodeModulesPaths(start, opts) {
  2588. var modules = opts && opts.moduleDirectory
  2589. ? [].concat(opts.moduleDirectory)
  2590. : ['node_modules'];
  2591. // ensure that `start` is an absolute path at this point,
  2592. // resolving against the process' current working directory
  2593. var absoluteStart = path.resolve(start);
  2594. if (opts && opts.preserveSymlinks === false) {
  2595. try {
  2596. absoluteStart = fs.realpathSync(absoluteStart);
  2597. } catch (err) {
  2598. if (err.code !== 'ENOENT') {
  2599. throw err;
  2600. }
  2601. }
  2602. }
  2603. var prefix = '/';
  2604. if (/^([A-Za-z]:)/.test(absoluteStart)) {
  2605. prefix = '';
  2606. } else if (/^\\\\/.test(absoluteStart)) {
  2607. prefix = '\\\\';
  2608. }
  2609. var paths = [absoluteStart];
  2610. var parsed = parse(absoluteStart);
  2611. while (parsed.dir !== paths[paths.length - 1]) {
  2612. paths.push(parsed.dir);
  2613. parsed = parse(parsed.dir);
  2614. }
  2615. var dirs = paths.reduce(function (dirs, aPath) {
  2616. return dirs.concat(modules.map(function (moduleDir) {
  2617. return path.join(prefix, aPath, moduleDir);
  2618. }));
  2619. }, []);
  2620. return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
  2621. };
  2622. var async = function resolve(x, options, callback) {
  2623. var cb = callback;
  2624. var opts = options || {};
  2625. if (typeof opts === 'function') {
  2626. cb = opts;
  2627. opts = {};
  2628. }
  2629. if (typeof x !== 'string') {
  2630. var err = new TypeError('Path must be a string.');
  2631. return process.nextTick(function () {
  2632. cb(err);
  2633. });
  2634. }
  2635. var isFile = opts.isFile || function (file, cb) {
  2636. fs.stat(file, function (err, stat) {
  2637. if (!err) {
  2638. return cb(null, stat.isFile() || stat.isFIFO());
  2639. }
  2640. if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
  2641. return cb(err);
  2642. });
  2643. };
  2644. var readFile = opts.readFile || fs.readFile;
  2645. var extensions = opts.extensions || ['.js'];
  2646. var y = opts.basedir || path.dirname(caller());
  2647. opts.paths = opts.paths || [];
  2648. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  2649. var res = path.resolve(y, x);
  2650. if (x === '..' || x.slice(-1) === '/') res += '/';
  2651. if (/\/$/.test(x) && res === y) {
  2652. loadAsDirectory(res, opts.package, onfile);
  2653. } else loadAsFile(res, opts.package, onfile);
  2654. } else loadNodeModules(x, y, function (err, n, pkg) {
  2655. if (err) cb(err);
  2656. else if (n) cb(null, n, pkg);
  2657. else if (core_1[x]) return cb(null, x);
  2658. else {
  2659. var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
  2660. moduleError.code = 'MODULE_NOT_FOUND';
  2661. cb(moduleError);
  2662. }
  2663. });
  2664. function onfile(err, m, pkg) {
  2665. if (err) cb(err);
  2666. else if (m) cb(null, m, pkg);
  2667. else loadAsDirectory(res, function (err, d, pkg) {
  2668. if (err) cb(err);
  2669. else if (d) cb(null, d, pkg);
  2670. else {
  2671. var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
  2672. moduleError.code = 'MODULE_NOT_FOUND';
  2673. cb(moduleError);
  2674. }
  2675. });
  2676. }
  2677. function loadAsFile(x, thePackage, callback) {
  2678. var loadAsFilePackage = thePackage;
  2679. var cb = callback;
  2680. if (typeof loadAsFilePackage === 'function') {
  2681. cb = loadAsFilePackage;
  2682. loadAsFilePackage = undefined;
  2683. }
  2684. var exts = [''].concat(extensions);
  2685. load(exts, x, loadAsFilePackage);
  2686. function load(exts, x, loadPackage) {
  2687. if (exts.length === 0) return cb(null, undefined, loadPackage);
  2688. var file = x + exts[0];
  2689. var pkg = loadPackage;
  2690. if (pkg) onpkg(null, pkg);
  2691. else loadpkg(path.dirname(file), onpkg);
  2692. function onpkg(err, pkg_, dir) {
  2693. pkg = pkg_;
  2694. if (err) return cb(err);
  2695. if (dir && pkg && opts.pathFilter) {
  2696. var rfile = path.relative(dir, file);
  2697. var rel = rfile.slice(0, rfile.length - exts[0].length);
  2698. var r = opts.pathFilter(pkg, x, rel);
  2699. if (r) return load(
  2700. [''].concat(extensions.slice()),
  2701. path.resolve(dir, r),
  2702. pkg
  2703. );
  2704. }
  2705. isFile(file, onex);
  2706. }
  2707. function onex(err, ex) {
  2708. if (err) return cb(err);
  2709. if (ex) return cb(null, file, pkg);
  2710. load(exts.slice(1), x, pkg);
  2711. }
  2712. }
  2713. }
  2714. function loadpkg(dir, cb) {
  2715. if (dir === '' || dir === '/') return cb(null);
  2716. if (process.platform === 'win32' && (/^\w:[/\\]*$/).test(dir)) {
  2717. return cb(null);
  2718. }
  2719. if (/[/\\]node_modules[/\\]*$/.test(dir)) return cb(null);
  2720. var pkgfile = path.join(dir, 'package.json');
  2721. isFile(pkgfile, function (err, ex) {
  2722. // on err, ex is false
  2723. if (!ex) return loadpkg(path.dirname(dir), cb);
  2724. readFile(pkgfile, function (err, body) {
  2725. if (err) cb(err);
  2726. try { var pkg = JSON.parse(body); } catch (jsonErr) {}
  2727. if (pkg && opts.packageFilter) {
  2728. pkg = opts.packageFilter(pkg, pkgfile);
  2729. }
  2730. cb(null, pkg, dir);
  2731. });
  2732. });
  2733. }
  2734. function loadAsDirectory(x, loadAsDirectoryPackage, callback) {
  2735. var cb = callback;
  2736. var fpkg = loadAsDirectoryPackage;
  2737. if (typeof fpkg === 'function') {
  2738. cb = fpkg;
  2739. fpkg = opts.package;
  2740. }
  2741. var pkgfile = path.join(x, 'package.json');
  2742. isFile(pkgfile, function (err, ex) {
  2743. if (err) return cb(err);
  2744. if (!ex) return loadAsFile(path.join(x, 'index'), fpkg, cb);
  2745. readFile(pkgfile, function (err, body) {
  2746. if (err) return cb(err);
  2747. try {
  2748. var pkg = JSON.parse(body);
  2749. } catch (jsonErr) {}
  2750. if (opts.packageFilter) {
  2751. pkg = opts.packageFilter(pkg, pkgfile);
  2752. }
  2753. if (pkg.main) {
  2754. if (pkg.main === '.' || pkg.main === './') {
  2755. pkg.main = 'index';
  2756. }
  2757. loadAsFile(path.resolve(x, pkg.main), pkg, function (err, m, pkg) {
  2758. if (err) return cb(err);
  2759. if (m) return cb(null, m, pkg);
  2760. if (!pkg) return loadAsFile(path.join(x, 'index'), pkg, cb);
  2761. var dir = path.resolve(x, pkg.main);
  2762. loadAsDirectory(dir, pkg, function (err, n, pkg) {
  2763. if (err) return cb(err);
  2764. if (n) return cb(null, n, pkg);
  2765. loadAsFile(path.join(x, 'index'), pkg, cb);
  2766. });
  2767. });
  2768. return;
  2769. }
  2770. loadAsFile(path.join(x, '/index'), pkg, cb);
  2771. });
  2772. });
  2773. }
  2774. function processDirs(cb, dirs) {
  2775. if (dirs.length === 0) return cb(null, undefined);
  2776. var dir = dirs[0];
  2777. var file = path.join(dir, x);
  2778. loadAsFile(file, undefined, onfile);
  2779. function onfile(err, m, pkg) {
  2780. if (err) return cb(err);
  2781. if (m) return cb(null, m, pkg);
  2782. loadAsDirectory(path.join(dir, x), undefined, ondir);
  2783. }
  2784. function ondir(err, n, pkg) {
  2785. if (err) return cb(err);
  2786. if (n) return cb(null, n, pkg);
  2787. processDirs(cb, dirs.slice(1));
  2788. }
  2789. }
  2790. function loadNodeModules(x, start, cb) {
  2791. processDirs(cb, nodeModulesPaths(start, opts));
  2792. }
  2793. };
  2794. var sync = function (x, options) {
  2795. if (typeof x !== 'string') {
  2796. throw new TypeError('Path must be a string.');
  2797. }
  2798. var opts = options || {};
  2799. var isFile = opts.isFile || function (file) {
  2800. try {
  2801. var stat = fs.statSync(file);
  2802. } catch (e) {
  2803. if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
  2804. throw e;
  2805. }
  2806. return stat.isFile() || stat.isFIFO();
  2807. };
  2808. var readFileSync = opts.readFileSync || fs.readFileSync;
  2809. var extensions = opts.extensions || ['.js'];
  2810. var y = opts.basedir || path.dirname(caller());
  2811. opts.paths = opts.paths || [];
  2812. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  2813. var res = path.resolve(y, x);
  2814. if (x === '..' || x.slice(-1) === '/') res += '/';
  2815. var m = loadAsFileSync(res) || loadAsDirectorySync(res);
  2816. if (m) return m;
  2817. } else {
  2818. var n = loadNodeModulesSync(x, y);
  2819. if (n) return n;
  2820. }
  2821. if (core_1[x]) return x;
  2822. var err = new Error("Cannot find module '" + x + "' from '" + y + "'");
  2823. err.code = 'MODULE_NOT_FOUND';
  2824. throw err;
  2825. function loadAsFileSync(x) {
  2826. if (isFile(x)) {
  2827. return x;
  2828. }
  2829. for (var i = 0; i < extensions.length; i++) {
  2830. var file = x + extensions[i];
  2831. if (isFile(file)) {
  2832. return file;
  2833. }
  2834. }
  2835. }
  2836. function loadAsDirectorySync(x) {
  2837. var pkgfile = path.join(x, '/package.json');
  2838. if (isFile(pkgfile)) {
  2839. try {
  2840. var body = readFileSync(pkgfile, 'UTF8');
  2841. var pkg = JSON.parse(body);
  2842. if (opts.packageFilter) {
  2843. pkg = opts.packageFilter(pkg, x);
  2844. }
  2845. if (pkg.main) {
  2846. if (pkg.main === '.' || pkg.main === './') {
  2847. pkg.main = 'index';
  2848. }
  2849. var m = loadAsFileSync(path.resolve(x, pkg.main));
  2850. if (m) return m;
  2851. var n = loadAsDirectorySync(path.resolve(x, pkg.main));
  2852. if (n) return n;
  2853. }
  2854. } catch (e) {}
  2855. }
  2856. return loadAsFileSync(path.join(x, '/index'));
  2857. }
  2858. function loadNodeModulesSync(x, start) {
  2859. var dirs = nodeModulesPaths(start, opts);
  2860. for (var i = 0; i < dirs.length; i++) {
  2861. var dir = dirs[i];
  2862. var m = loadAsFileSync(path.join(dir, '/', x));
  2863. if (m) return m;
  2864. var n = loadAsDirectorySync(path.join(dir, '/', x));
  2865. if (n) return n;
  2866. }
  2867. }
  2868. };
  2869. var resolve = createCommonjsModule(function (module, exports) {
  2870. async.core = core_1;
  2871. async.isCore = function isCore(x) { return core_1[x]; };
  2872. async.sync = sync;
  2873. exports = async;
  2874. module.exports = async;
  2875. });
  2876. var pathExists = createCommonjsModule(function (module) {
  2877. 'use strict';
  2878. module.exports = fp => new Promise(resolve => {
  2879. fs.access(fp, err => {
  2880. resolve(!err);
  2881. });
  2882. });
  2883. module.exports.sync = fp => {
  2884. try {
  2885. fs.accessSync(fp);
  2886. return true;
  2887. } catch (err) {
  2888. return false;
  2889. }
  2890. };
  2891. });
  2892. var pLimit = createCommonjsModule(function (module) {
  2893. 'use strict';
  2894. module.exports = concurrency => {
  2895. if (concurrency < 1) {
  2896. throw new TypeError('Expected `concurrency` to be a number from 1 and up');
  2897. }
  2898. const queue = [];
  2899. let activeCount = 0;
  2900. const next = () => {
  2901. activeCount--;
  2902. if (queue.length > 0) {
  2903. queue.shift()();
  2904. }
  2905. };
  2906. return fn => new Promise((resolve, reject) => {
  2907. const run = () => {
  2908. activeCount++;
  2909. fn().then(
  2910. val => {
  2911. resolve(val);
  2912. next();
  2913. },
  2914. err => {
  2915. reject(err);
  2916. next();
  2917. }
  2918. );
  2919. };
  2920. if (activeCount < concurrency) {
  2921. run();
  2922. } else {
  2923. queue.push(run);
  2924. }
  2925. });
  2926. };
  2927. });
  2928. var pLocate = createCommonjsModule(function (module) {
  2929. 'use strict';
  2930. class EndError extends Error {
  2931. constructor(value) {
  2932. super();
  2933. this.value = value;
  2934. }
  2935. }
  2936. // the input can also be a promise, so we `Promise.all()` them both
  2937. const finder = el => Promise.all(el).then(val => val[1] === true && Promise.reject(new EndError(val[0])));
  2938. module.exports = (iterable, tester, opts) => {
  2939. opts = Object.assign({
  2940. concurrency: Infinity,
  2941. preserveOrder: true
  2942. }, opts);
  2943. const limit = pLimit(opts.concurrency);
  2944. // start all the promises concurrently with optional limit
  2945. const items = Array.from(iterable).map(el => [el, limit(() => Promise.resolve(el).then(tester))]);
  2946. // check the promises either serially or concurrently
  2947. const checkLimit = pLimit(opts.preserveOrder ? 1 : Infinity);
  2948. return Promise.all(items.map(el => checkLimit(() => finder(el))))
  2949. .then(() => {})
  2950. .catch(err => err instanceof EndError ? err.value : Promise.reject(err));
  2951. };
  2952. });
  2953. var locatePath = createCommonjsModule(function (module) {
  2954. 'use strict';
  2955. module.exports = (iterable, opts) => {
  2956. opts = Object.assign({
  2957. cwd: process.cwd()
  2958. }, opts);
  2959. return pLocate(iterable, el => pathExists(path.resolve(opts.cwd, el)), opts);
  2960. };
  2961. module.exports.sync = (iterable, opts) => {
  2962. opts = Object.assign({
  2963. cwd: process.cwd()
  2964. }, opts);
  2965. for (const el of iterable) {
  2966. if (pathExists.sync(path.resolve(opts.cwd, el))) {
  2967. return el;
  2968. }
  2969. }
  2970. };
  2971. });
  2972. var findUp = createCommonjsModule(function (module) {
  2973. 'use strict';
  2974. module.exports = (filename, opts) => {
  2975. opts = opts || {};
  2976. const startDir = path.resolve(opts.cwd || '');
  2977. const root = path.parse(startDir).root;
  2978. const filenames = [].concat(filename);
  2979. return new Promise(resolve => {
  2980. (function find(dir) {
  2981. locatePath(filenames, {cwd: dir}).then(file => {
  2982. if (file) {
  2983. resolve(path.join(dir, file));
  2984. } else if (dir === root) {
  2985. resolve(null);
  2986. } else {
  2987. find(path.dirname(dir));
  2988. }
  2989. });
  2990. })(startDir);
  2991. });
  2992. };
  2993. module.exports.sync = (filename, opts) => {
  2994. opts = opts || {};
  2995. let dir = path.resolve(opts.cwd || '');
  2996. const root = path.parse(dir).root;
  2997. const filenames = [].concat(filename);
  2998. // eslint-disable-next-line no-constant-condition
  2999. while (true) {
  3000. const file = locatePath.sync(filenames, {cwd: dir});
  3001. if (file) {
  3002. return path.join(dir, file);
  3003. } else if (dir === root) {
  3004. return null;
  3005. }
  3006. dir = path.dirname(dir);
  3007. }
  3008. };
  3009. });
  3010. var stripBom = createCommonjsModule(function (module) {
  3011. 'use strict';
  3012. module.exports = x => {
  3013. if (typeof x !== 'string') {
  3014. throw new TypeError('Expected a string, got ' + typeof x);
  3015. }
  3016. // Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
  3017. // conversion translates it to FEFF (UTF-16 BOM)
  3018. if (x.charCodeAt(0) === 0xFEFF) {
  3019. return x.slice(1);
  3020. }
  3021. return x;
  3022. };
  3023. });
  3024. var isArrayish = function isArrayish(obj) {
  3025. if (!obj) {
  3026. return false;
  3027. }
  3028. return obj instanceof Array || Array.isArray(obj) ||
  3029. (obj.length >= 0 && obj.splice instanceof Function);
  3030. };
  3031. var errorEx = function errorEx(name, properties) {
  3032. if (!name || name.constructor !== String) {
  3033. properties = name || {};
  3034. name = Error.name;
  3035. }
  3036. var errorExError = function ErrorEXError(message) {
  3037. if (!this) {
  3038. return new ErrorEXError(message);
  3039. }
  3040. message = message instanceof Error
  3041. ? message.message
  3042. : (message || this.message);
  3043. Error.call(this, message);
  3044. Error.captureStackTrace(this, errorExError);
  3045. this.name = name;
  3046. Object.defineProperty(this, 'message', {
  3047. configurable: true,
  3048. enumerable: false,
  3049. get: function () {
  3050. var newMessage = message.split(/\r?\n/g);
  3051. for (var key in properties) {
  3052. if (!properties.hasOwnProperty(key)) {
  3053. continue;
  3054. }
  3055. var modifier = properties[key];
  3056. if ('message' in modifier) {
  3057. newMessage = modifier.message(this[key], newMessage) || newMessage;
  3058. if (!isArrayish(newMessage)) {
  3059. newMessage = [newMessage];
  3060. }
  3061. }
  3062. }
  3063. return newMessage.join('\n');
  3064. },
  3065. set: function (v) {
  3066. message = v;
  3067. }
  3068. });
  3069. var stackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack');
  3070. var stackGetter = stackDescriptor.get;
  3071. var stackValue = stackDescriptor.value;
  3072. delete stackDescriptor.value;
  3073. delete stackDescriptor.writable;
  3074. stackDescriptor.get = function () {
  3075. var stack = (stackGetter)
  3076. ? stackGetter.call(this).split(/\r?\n+/g)
  3077. : stackValue.split(/\r?\n+/g);
  3078. // starting in Node 7, the stack builder caches the message.
  3079. // just replace it.
  3080. stack[0] = this.name + ': ' + this.message;
  3081. var lineCount = 1;
  3082. for (var key in properties) {
  3083. if (!properties.hasOwnProperty(key)) {
  3084. continue;
  3085. }
  3086. var modifier = properties[key];
  3087. if ('line' in modifier) {
  3088. var line = modifier.line(this[key]);
  3089. if (line) {
  3090. stack.splice(lineCount++, 0, ' ' + line);
  3091. }
  3092. }
  3093. if ('stack' in modifier) {
  3094. modifier.stack(this[key], stack);
  3095. }
  3096. }
  3097. return stack.join('\n');
  3098. };
  3099. Object.defineProperty(this, 'stack', stackDescriptor);
  3100. };
  3101. if (Object.setPrototypeOf) {
  3102. Object.setPrototypeOf(errorExError.prototype, Error.prototype);
  3103. Object.setPrototypeOf(errorExError, Error);
  3104. } else {
  3105. util.inherits(errorExError, Error);
  3106. }
  3107. return errorExError;
  3108. };
  3109. errorEx.append = function (str, def) {
  3110. return {
  3111. message: function (v, message) {
  3112. v = v || def;
  3113. if (v) {
  3114. message[0] += ' ' + str.replace('%s', v.toString());
  3115. }
  3116. return message;
  3117. }
  3118. };
  3119. };
  3120. errorEx.line = function (str, def) {
  3121. return {
  3122. line: function (v) {
  3123. v = v || def;
  3124. if (v) {
  3125. return str.replace('%s', v.toString());
  3126. }
  3127. return null;
  3128. }
  3129. };
  3130. };
  3131. var errorEx_1 = errorEx;
  3132. var jsonParseBetterErrors = parseJson$2;
  3133. function parseJson$2 (txt, reviver, context) {
  3134. context = context || 20;
  3135. try {
  3136. return JSON.parse(txt, reviver)
  3137. } catch (e) {
  3138. const syntaxErr = e.message.match(/^Unexpected token.*position\s+(\d+)/i);
  3139. const errIdx = syntaxErr
  3140. ? +syntaxErr[1]
  3141. : e.message.match(/^Unexpected end of JSON.*/i)
  3142. ? txt.length - 1
  3143. : null;
  3144. if (errIdx != null) {
  3145. const start = errIdx <= context
  3146. ? 0
  3147. : errIdx - context;
  3148. const end = errIdx + context >= txt.length
  3149. ? txt.length
  3150. : errIdx + context;
  3151. e.message += ` while parsing near '${
  3152. start === 0 ? '' : '...'
  3153. }${txt.slice(start, end)}${
  3154. end === txt.length ? '' : '...'
  3155. }'`;
  3156. } else {
  3157. e.message += ` while parsing '${txt.slice(0, context * 2)}'`;
  3158. }
  3159. throw e
  3160. }
  3161. }
  3162. var parseJson = createCommonjsModule(function (module) {
  3163. 'use strict';
  3164. const JSONError = errorEx_1('JSONError', {
  3165. fileName: errorEx_1.append('in %s')
  3166. });
  3167. module.exports = (input, reviver, filename) => {
  3168. if (typeof reviver === 'string') {
  3169. filename = reviver;
  3170. reviver = null;
  3171. }
  3172. try {
  3173. try {
  3174. return JSON.parse(input, reviver);
  3175. } catch (err) {
  3176. jsonParseBetterErrors(input, reviver);
  3177. throw err;
  3178. }
  3179. } catch (err) {
  3180. err.message = err.message.replace(/\n/g, '');
  3181. const jsonErr = new JSONError(err);
  3182. if (filename) {
  3183. jsonErr.fileName = filename;
  3184. }
  3185. throw jsonErr;
  3186. }
  3187. };
  3188. });
  3189. var pify = createCommonjsModule(function (module) {
  3190. 'use strict';
  3191. const processFn = (fn, opts) => function () {
  3192. const P = opts.promiseModule;
  3193. const args = new Array(arguments.length);
  3194. for (let i = 0; i < arguments.length; i++) {
  3195. args[i] = arguments[i];
  3196. }
  3197. return new P((resolve, reject) => {
  3198. if (opts.errorFirst) {
  3199. args.push(function (err, result) {
  3200. if (opts.multiArgs) {
  3201. const results = new Array(arguments.length - 1);
  3202. for (let i = 1; i < arguments.length; i++) {
  3203. results[i - 1] = arguments[i];
  3204. }
  3205. if (err) {
  3206. results.unshift(err);
  3207. reject(results);
  3208. } else {
  3209. resolve(results);
  3210. }
  3211. } else if (err) {
  3212. reject(err);
  3213. } else {
  3214. resolve(result);
  3215. }
  3216. });
  3217. } else {
  3218. args.push(function (result) {
  3219. if (opts.multiArgs) {
  3220. const results = new Array(arguments.length - 1);
  3221. for (let i = 0; i < arguments.length; i++) {
  3222. results[i] = arguments[i];
  3223. }
  3224. resolve(results);
  3225. } else {
  3226. resolve(result);
  3227. }
  3228. });
  3229. }
  3230. fn.apply(this, args);
  3231. });
  3232. };
  3233. module.exports = (obj, opts) => {
  3234. opts = Object.assign({
  3235. exclude: [/.+(Sync|Stream)$/],
  3236. errorFirst: true,
  3237. promiseModule: Promise
  3238. }, opts);
  3239. const filter = key => {
  3240. const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);
  3241. return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
  3242. };
  3243. let ret;
  3244. if (typeof obj === 'function') {
  3245. ret = function () {
  3246. if (opts.excludeMain) {
  3247. return obj.apply(this, arguments);
  3248. }
  3249. return processFn(obj, opts).apply(this, arguments);
  3250. };
  3251. } else {
  3252. ret = Object.create(Object.getPrototypeOf(obj));
  3253. }
  3254. for (const key in obj) { // eslint-disable-line guard-for-in
  3255. const x = obj[key];
  3256. ret[key] = typeof x === 'function' && filter(key) ? processFn(x, opts) : x;
  3257. }
  3258. return ret;
  3259. };
  3260. });
  3261. const parse$1 = (data, fp) => parseJson(stripBom(data), path.relative('.', fp));
  3262. var loadJsonFile = fp => pify(fs.readFile)(fp, 'utf8').then(data => parse$1(data, fp));
  3263. var sync$2 = fp => parse$1(fs.readFileSync(fp, 'utf8'), fp);
  3264. loadJsonFile.sync = sync$2;
  3265. var pify$3 = createCommonjsModule(function (module) {
  3266. 'use strict';
  3267. const processFn = (fn, opts) => function () {
  3268. const P = opts.promiseModule;
  3269. const args = new Array(arguments.length);
  3270. for (let i = 0; i < arguments.length; i++) {
  3271. args[i] = arguments[i];
  3272. }
  3273. return new P((resolve, reject) => {
  3274. if (opts.errorFirst) {
  3275. args.push(function (err, result) {
  3276. if (opts.multiArgs) {
  3277. const results = new Array(arguments.length - 1);
  3278. for (let i = 1; i < arguments.length; i++) {
  3279. results[i - 1] = arguments[i];
  3280. }
  3281. if (err) {
  3282. results.unshift(err);
  3283. reject(results);
  3284. } else {
  3285. resolve(results);
  3286. }
  3287. } else if (err) {
  3288. reject(err);
  3289. } else {
  3290. resolve(result);
  3291. }
  3292. });
  3293. } else {
  3294. args.push(function (result) {
  3295. if (opts.multiArgs) {
  3296. const results = new Array(arguments.length - 1);
  3297. for (let i = 0; i < arguments.length; i++) {
  3298. results[i] = arguments[i];
  3299. }
  3300. resolve(results);
  3301. } else {
  3302. resolve(result);
  3303. }
  3304. });
  3305. }
  3306. fn.apply(this, args);
  3307. });
  3308. };
  3309. module.exports = (obj, opts) => {
  3310. opts = Object.assign({
  3311. exclude: [/.+(Sync|Stream)$/],
  3312. errorFirst: true,
  3313. promiseModule: Promise
  3314. }, opts);
  3315. const filter = key => {
  3316. const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);
  3317. return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
  3318. };
  3319. let ret;
  3320. if (typeof obj === 'function') {
  3321. ret = function () {
  3322. if (opts.excludeMain) {
  3323. return obj.apply(this, arguments);
  3324. }
  3325. return processFn(obj, opts).apply(this, arguments);
  3326. };
  3327. } else {
  3328. ret = Object.create(Object.getPrototypeOf(obj));
  3329. }
  3330. for (const key in obj) { // eslint-disable-line guard-for-in
  3331. const x = obj[key];
  3332. ret[key] = typeof x === 'function' && filter(key) ? processFn(x, opts) : x;
  3333. }
  3334. return ret;
  3335. };
  3336. });
  3337. function type(fn, fn2, fp) {
  3338. if (typeof fp !== 'string') {
  3339. return Promise.reject(new TypeError(`Expected a string, got ${typeof fp}`));
  3340. }
  3341. return pify$3(fs[fn])(fp)
  3342. .then(stats => stats[fn2]())
  3343. .catch(err => {
  3344. if (err.code === 'ENOENT') {
  3345. return false;
  3346. }
  3347. throw err;
  3348. });
  3349. }
  3350. function typeSync(fn, fn2, fp) {
  3351. if (typeof fp !== 'string') {
  3352. throw new TypeError(`Expected a string, got ${typeof fp}`);
  3353. }
  3354. try {
  3355. return fs[fn](fp)[fn2]();
  3356. } catch (err) {
  3357. if (err.code === 'ENOENT') {
  3358. return false;
  3359. }
  3360. throw err;
  3361. }
  3362. }
  3363. var file = type.bind(null, 'stat', 'isFile');
  3364. var dir = type.bind(null, 'stat', 'isDirectory');
  3365. var symlink = type.bind(null, 'lstat', 'isSymbolicLink');
  3366. var fileSync = typeSync.bind(null, 'statSync', 'isFile');
  3367. var dirSync = typeSync.bind(null, 'statSync', 'isDirectory');
  3368. var symlinkSync = typeSync.bind(null, 'lstatSync', 'isSymbolicLink');
  3369. var pathType = {
  3370. file: file,
  3371. dir: dir,
  3372. symlink: symlink,
  3373. fileSync: fileSync,
  3374. dirSync: dirSync,
  3375. symlinkSync: symlinkSync
  3376. };
  3377. var parser$1 = createCommonjsModule(function (module, exports) {
  3378. /* parser generated by jison 0.4.17 */
  3379. /*
  3380. Returns a Parser object of the following structure:
  3381. Parser: {
  3382. yy: {}
  3383. }
  3384. Parser.prototype: {
  3385. yy: {},
  3386. trace: function(),
  3387. symbols_: {associative list: name ==> number},
  3388. terminals_: {associative list: number ==> name},
  3389. productions_: [...],
  3390. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  3391. table: [...],
  3392. defaultActions: {...},
  3393. parseError: function(str, hash),
  3394. parse: function(input),
  3395. lexer: {
  3396. EOF: 1,
  3397. parseError: function(str, hash),
  3398. setInput: function(input),
  3399. input: function(),
  3400. unput: function(str),
  3401. more: function(),
  3402. less: function(n),
  3403. pastInput: function(),
  3404. upcomingInput: function(),
  3405. showPosition: function(),
  3406. test_match: function(regex_match_array, rule_index),
  3407. next: function(),
  3408. lex: function(),
  3409. begin: function(condition),
  3410. popState: function(),
  3411. _currentRules: function(),
  3412. topState: function(),
  3413. pushState: function(condition),
  3414. options: {
  3415. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  3416. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  3417. backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
  3418. },
  3419. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  3420. rules: [...],
  3421. conditions: {associative list: name ==> set},
  3422. }
  3423. }
  3424. token location info (@$, _$, etc.): {
  3425. first_line: n,
  3426. last_line: n,
  3427. first_column: n,
  3428. last_column: n,
  3429. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  3430. }
  3431. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  3432. text: (matched text)
  3433. token: (the produced terminal token, if any)
  3434. line: (yylineno)
  3435. }
  3436. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  3437. loc: (yylloc)
  3438. expected: (string describing the set of expected tokens)
  3439. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  3440. }
  3441. */
  3442. var spdxparse = (function(){
  3443. var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,5],$V1=[1,6],$V2=[1,7],$V3=[1,4],$V4=[1,9],$V5=[1,10],$V6=[5,14,15,17],$V7=[5,12,14,15,17];
  3444. var parser = {trace: function trace() { },
  3445. yy: {},
  3446. symbols_: {"error":2,"start":3,"expression":4,"EOS":5,"simpleExpression":6,"LICENSE":7,"PLUS":8,"LICENSEREF":9,"DOCUMENTREF":10,"COLON":11,"WITH":12,"EXCEPTION":13,"AND":14,"OR":15,"OPEN":16,"CLOSE":17,"$accept":0,"$end":1},
  3447. terminals_: {2:"error",5:"EOS",7:"LICENSE",8:"PLUS",9:"LICENSEREF",10:"DOCUMENTREF",11:"COLON",12:"WITH",13:"EXCEPTION",14:"AND",15:"OR",16:"OPEN",17:"CLOSE"},
  3448. productions_: [0,[3,2],[6,1],[6,2],[6,1],[6,3],[4,1],[4,3],[4,3],[4,3],[4,3]],
  3449. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
  3450. /* this == yyval */
  3451. var $0 = $$.length - 1;
  3452. switch (yystate) {
  3453. case 1:
  3454. return this.$ = $$[$0-1]
  3455. break;
  3456. case 2: case 4: case 5:
  3457. this.$ = {license: yytext};
  3458. break;
  3459. case 3:
  3460. this.$ = {license: $$[$0-1], plus: true};
  3461. break;
  3462. case 6:
  3463. this.$ = $$[$0];
  3464. break;
  3465. case 7:
  3466. this.$ = {exception: $$[$0]};
  3467. this.$.license = $$[$0-2].license;
  3468. if ($$[$0-2].hasOwnProperty('plus')) {
  3469. this.$.plus = $$[$0-2].plus;
  3470. }
  3471. break;
  3472. case 8:
  3473. this.$ = {conjunction: 'and', left: $$[$0-2], right: $$[$0]};
  3474. break;
  3475. case 9:
  3476. this.$ = {conjunction: 'or', left: $$[$0-2], right: $$[$0]};
  3477. break;
  3478. case 10:
  3479. this.$ = $$[$0-1];
  3480. break;
  3481. }
  3482. },
  3483. table: [{3:1,4:2,6:3,7:$V0,9:$V1,10:$V2,16:$V3},{1:[3]},{5:[1,8],14:$V4,15:$V5},o($V6,[2,6],{12:[1,11]}),{4:12,6:3,7:$V0,9:$V1,10:$V2,16:$V3},o($V7,[2,2],{8:[1,13]}),o($V7,[2,4]),{11:[1,14]},{1:[2,1]},{4:15,6:3,7:$V0,9:$V1,10:$V2,16:$V3},{4:16,6:3,7:$V0,9:$V1,10:$V2,16:$V3},{13:[1,17]},{14:$V4,15:$V5,17:[1,18]},o($V7,[2,3]),{9:[1,19]},o($V6,[2,8]),o([5,15,17],[2,9],{14:$V4}),o($V6,[2,7]),o($V6,[2,10]),o($V7,[2,5])],
  3484. defaultActions: {8:[2,1]},
  3485. parseError: function parseError(str, hash) {
  3486. if (hash.recoverable) {
  3487. this.trace(str);
  3488. } else {
  3489. function _parseError (msg, hash) {
  3490. this.message = msg;
  3491. this.hash = hash;
  3492. }
  3493. _parseError.prototype = Error;
  3494. throw new _parseError(str, hash);
  3495. }
  3496. },
  3497. parse: function parse(input) {
  3498. var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
  3499. var args = lstack.slice.call(arguments, 1);
  3500. var lexer = Object.create(this.lexer);
  3501. var sharedState = { yy: {} };
  3502. for (var k in this.yy) {
  3503. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  3504. sharedState.yy[k] = this.yy[k];
  3505. }
  3506. }
  3507. lexer.setInput(input, sharedState.yy);
  3508. sharedState.yy.lexer = lexer;
  3509. sharedState.yy.parser = this;
  3510. if (typeof lexer.yylloc == 'undefined') {
  3511. lexer.yylloc = {};
  3512. }
  3513. var yyloc = lexer.yylloc;
  3514. lstack.push(yyloc);
  3515. var ranges = lexer.options && lexer.options.ranges;
  3516. if (typeof sharedState.yy.parseError === 'function') {
  3517. this.parseError = sharedState.yy.parseError;
  3518. } else {
  3519. this.parseError = Object.getPrototypeOf(this).parseError;
  3520. }
  3521. _token_stack:
  3522. var lex = function () {
  3523. var token;
  3524. token = lexer.lex() || EOF;
  3525. if (typeof token !== 'number') {
  3526. token = self.symbols_[token] || token;
  3527. }
  3528. return token;
  3529. };
  3530. var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
  3531. while (true) {
  3532. state = stack[stack.length - 1];
  3533. if (this.defaultActions[state]) {
  3534. action = this.defaultActions[state];
  3535. } else {
  3536. if (symbol === null || typeof symbol == 'undefined') {
  3537. symbol = lex();
  3538. }
  3539. action = table[state] && table[state][symbol];
  3540. }
  3541. if (typeof action === 'undefined' || !action.length || !action[0]) {
  3542. var errStr = '';
  3543. expected = [];
  3544. for (p in table[state]) {
  3545. if (this.terminals_[p] && p > TERROR) {
  3546. expected.push('\'' + this.terminals_[p] + '\'');
  3547. }
  3548. }
  3549. if (lexer.showPosition) {
  3550. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  3551. } else {
  3552. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  3553. }
  3554. this.parseError(errStr, {
  3555. text: lexer.match,
  3556. token: this.terminals_[symbol] || symbol,
  3557. line: lexer.yylineno,
  3558. loc: yyloc,
  3559. expected: expected
  3560. });
  3561. }
  3562. if (action[0] instanceof Array && action.length > 1) {
  3563. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  3564. }
  3565. switch (action[0]) {
  3566. case 1:
  3567. stack.push(symbol);
  3568. vstack.push(lexer.yytext);
  3569. lstack.push(lexer.yylloc);
  3570. stack.push(action[1]);
  3571. symbol = null;
  3572. if (!preErrorSymbol) {
  3573. yyleng = lexer.yyleng;
  3574. yytext = lexer.yytext;
  3575. yylineno = lexer.yylineno;
  3576. yyloc = lexer.yylloc;
  3577. if (recovering > 0) {
  3578. recovering--;
  3579. }
  3580. } else {
  3581. symbol = preErrorSymbol;
  3582. preErrorSymbol = null;
  3583. }
  3584. break;
  3585. case 2:
  3586. len = this.productions_[action[1]][1];
  3587. yyval.$ = vstack[vstack.length - len];
  3588. yyval._$ = {
  3589. first_line: lstack[lstack.length - (len || 1)].first_line,
  3590. last_line: lstack[lstack.length - 1].last_line,
  3591. first_column: lstack[lstack.length - (len || 1)].first_column,
  3592. last_column: lstack[lstack.length - 1].last_column
  3593. };
  3594. if (ranges) {
  3595. yyval._$.range = [
  3596. lstack[lstack.length - (len || 1)].range[0],
  3597. lstack[lstack.length - 1].range[1]
  3598. ];
  3599. }
  3600. r = this.performAction.apply(yyval, [
  3601. yytext,
  3602. yyleng,
  3603. yylineno,
  3604. sharedState.yy,
  3605. action[1],
  3606. vstack,
  3607. lstack
  3608. ].concat(args));
  3609. if (typeof r !== 'undefined') {
  3610. return r;
  3611. }
  3612. if (len) {
  3613. stack = stack.slice(0, -1 * len * 2);
  3614. vstack = vstack.slice(0, -1 * len);
  3615. lstack = lstack.slice(0, -1 * len);
  3616. }
  3617. stack.push(this.productions_[action[1]][0]);
  3618. vstack.push(yyval.$);
  3619. lstack.push(yyval._$);
  3620. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  3621. stack.push(newState);
  3622. break;
  3623. case 3:
  3624. return true;
  3625. }
  3626. }
  3627. return true;
  3628. }};
  3629. /* generated by jison-lex 0.3.4 */
  3630. var lexer = (function(){
  3631. var lexer = ({
  3632. EOF:1,
  3633. parseError:function parseError(str, hash) {
  3634. if (this.yy.parser) {
  3635. this.yy.parser.parseError(str, hash);
  3636. } else {
  3637. throw new Error(str);
  3638. }
  3639. },
  3640. // resets the lexer, sets new input
  3641. setInput:function (input, yy) {
  3642. this.yy = yy || this.yy || {};
  3643. this._input = input;
  3644. this._more = this._backtrack = this.done = false;
  3645. this.yylineno = this.yyleng = 0;
  3646. this.yytext = this.matched = this.match = '';
  3647. this.conditionStack = ['INITIAL'];
  3648. this.yylloc = {
  3649. first_line: 1,
  3650. first_column: 0,
  3651. last_line: 1,
  3652. last_column: 0
  3653. };
  3654. if (this.options.ranges) {
  3655. this.yylloc.range = [0,0];
  3656. }
  3657. this.offset = 0;
  3658. return this;
  3659. },
  3660. // consumes and returns one char from the input
  3661. input:function () {
  3662. var ch = this._input[0];
  3663. this.yytext += ch;
  3664. this.yyleng++;
  3665. this.offset++;
  3666. this.match += ch;
  3667. this.matched += ch;
  3668. var lines = ch.match(/(?:\r\n?|\n).*/g);
  3669. if (lines) {
  3670. this.yylineno++;
  3671. this.yylloc.last_line++;
  3672. } else {
  3673. this.yylloc.last_column++;
  3674. }
  3675. if (this.options.ranges) {
  3676. this.yylloc.range[1]++;
  3677. }
  3678. this._input = this._input.slice(1);
  3679. return ch;
  3680. },
  3681. // unshifts one char (or a string) into the input
  3682. unput:function (ch) {
  3683. var len = ch.length;
  3684. var lines = ch.split(/(?:\r\n?|\n)/g);
  3685. this._input = ch + this._input;
  3686. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  3687. //this.yyleng -= len;
  3688. this.offset -= len;
  3689. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  3690. this.match = this.match.substr(0, this.match.length - 1);
  3691. this.matched = this.matched.substr(0, this.matched.length - 1);
  3692. if (lines.length - 1) {
  3693. this.yylineno -= lines.length - 1;
  3694. }
  3695. var r = this.yylloc.range;
  3696. this.yylloc = {
  3697. first_line: this.yylloc.first_line,
  3698. last_line: this.yylineno + 1,
  3699. first_column: this.yylloc.first_column,
  3700. last_column: lines ?
  3701. (lines.length === oldLines.length ? this.yylloc.first_column : 0)
  3702. + oldLines[oldLines.length - lines.length].length - lines[0].length :
  3703. this.yylloc.first_column - len
  3704. };
  3705. if (this.options.ranges) {
  3706. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  3707. }
  3708. this.yyleng = this.yytext.length;
  3709. return this;
  3710. },
  3711. // When called from action, caches matched text and appends it on next action
  3712. more:function () {
  3713. this._more = true;
  3714. return this;
  3715. },
  3716. // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
  3717. reject:function () {
  3718. if (this.options.backtrack_lexer) {
  3719. this._backtrack = true;
  3720. } else {
  3721. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
  3722. text: "",
  3723. token: null,
  3724. line: this.yylineno
  3725. });
  3726. }
  3727. return this;
  3728. },
  3729. // retain first n characters of the match
  3730. less:function (n) {
  3731. this.unput(this.match.slice(n));
  3732. },
  3733. // displays already matched input, i.e. for error messages
  3734. pastInput:function () {
  3735. var past = this.matched.substr(0, this.matched.length - this.match.length);
  3736. return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
  3737. },
  3738. // displays upcoming input, i.e. for error messages
  3739. upcomingInput:function () {
  3740. var next = this.match;
  3741. if (next.length < 20) {
  3742. next += this._input.substr(0, 20-next.length);
  3743. }
  3744. return (next.substr(0,20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  3745. },
  3746. // displays the character position where the lexing error occurred, i.e. for error messages
  3747. showPosition:function () {
  3748. var pre = this.pastInput();
  3749. var c = new Array(pre.length + 1).join("-");
  3750. return pre + this.upcomingInput() + "\n" + c + "^";
  3751. },
  3752. // test the lexed token: return FALSE when not a match, otherwise return token
  3753. test_match:function (match, indexed_rule) {
  3754. var token,
  3755. lines,
  3756. backup;
  3757. if (this.options.backtrack_lexer) {
  3758. // save context
  3759. backup = {
  3760. yylineno: this.yylineno,
  3761. yylloc: {
  3762. first_line: this.yylloc.first_line,
  3763. last_line: this.last_line,
  3764. first_column: this.yylloc.first_column,
  3765. last_column: this.yylloc.last_column
  3766. },
  3767. yytext: this.yytext,
  3768. match: this.match,
  3769. matches: this.matches,
  3770. matched: this.matched,
  3771. yyleng: this.yyleng,
  3772. offset: this.offset,
  3773. _more: this._more,
  3774. _input: this._input,
  3775. yy: this.yy,
  3776. conditionStack: this.conditionStack.slice(0),
  3777. done: this.done
  3778. };
  3779. if (this.options.ranges) {
  3780. backup.yylloc.range = this.yylloc.range.slice(0);
  3781. }
  3782. }
  3783. lines = match[0].match(/(?:\r\n?|\n).*/g);
  3784. if (lines) {
  3785. this.yylineno += lines.length;
  3786. }
  3787. this.yylloc = {
  3788. first_line: this.yylloc.last_line,
  3789. last_line: this.yylineno + 1,
  3790. first_column: this.yylloc.last_column,
  3791. last_column: lines ?
  3792. lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length :
  3793. this.yylloc.last_column + match[0].length
  3794. };
  3795. this.yytext += match[0];
  3796. this.match += match[0];
  3797. this.matches = match;
  3798. this.yyleng = this.yytext.length;
  3799. if (this.options.ranges) {
  3800. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  3801. }
  3802. this._more = false;
  3803. this._backtrack = false;
  3804. this._input = this._input.slice(match[0].length);
  3805. this.matched += match[0];
  3806. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  3807. if (this.done && this._input) {
  3808. this.done = false;
  3809. }
  3810. if (token) {
  3811. return token;
  3812. } else if (this._backtrack) {
  3813. // recover context
  3814. for (var k in backup) {
  3815. this[k] = backup[k];
  3816. }
  3817. return false; // rule action called reject() implying the next rule should be tested instead.
  3818. }
  3819. return false;
  3820. },
  3821. // return next match in input
  3822. next:function () {
  3823. if (this.done) {
  3824. return this.EOF;
  3825. }
  3826. if (!this._input) {
  3827. this.done = true;
  3828. }
  3829. var token,
  3830. match,
  3831. tempMatch,
  3832. index;
  3833. if (!this._more) {
  3834. this.yytext = '';
  3835. this.match = '';
  3836. }
  3837. var rules = this._currentRules();
  3838. for (var i = 0; i < rules.length; i++) {
  3839. tempMatch = this._input.match(this.rules[rules[i]]);
  3840. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  3841. match = tempMatch;
  3842. index = i;
  3843. if (this.options.backtrack_lexer) {
  3844. token = this.test_match(tempMatch, rules[i]);
  3845. if (token !== false) {
  3846. return token;
  3847. } else if (this._backtrack) {
  3848. match = false;
  3849. continue; // rule action called reject() implying a rule MISmatch.
  3850. } else {
  3851. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  3852. return false;
  3853. }
  3854. } else if (!this.options.flex) {
  3855. break;
  3856. }
  3857. }
  3858. }
  3859. if (match) {
  3860. token = this.test_match(match, rules[index]);
  3861. if (token !== false) {
  3862. return token;
  3863. }
  3864. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  3865. return false;
  3866. }
  3867. if (this._input === "") {
  3868. return this.EOF;
  3869. } else {
  3870. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  3871. text: "",
  3872. token: null,
  3873. line: this.yylineno
  3874. });
  3875. }
  3876. },
  3877. // return next match that has a token
  3878. lex:function lex() {
  3879. var r = this.next();
  3880. if (r) {
  3881. return r;
  3882. } else {
  3883. return this.lex();
  3884. }
  3885. },
  3886. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  3887. begin:function begin(condition) {
  3888. this.conditionStack.push(condition);
  3889. },
  3890. // pop the previously active lexer condition state off the condition stack
  3891. popState:function popState() {
  3892. var n = this.conditionStack.length - 1;
  3893. if (n > 0) {
  3894. return this.conditionStack.pop();
  3895. } else {
  3896. return this.conditionStack[0];
  3897. }
  3898. },
  3899. // produce the lexer rule set which is active for the currently active lexer condition state
  3900. _currentRules:function _currentRules() {
  3901. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  3902. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  3903. } else {
  3904. return this.conditions["INITIAL"].rules;
  3905. }
  3906. },
  3907. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  3908. topState:function topState(n) {
  3909. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  3910. if (n >= 0) {
  3911. return this.conditionStack[n];
  3912. } else {
  3913. return "INITIAL";
  3914. }
  3915. },
  3916. // alias for begin(condition)
  3917. pushState:function pushState(condition) {
  3918. this.begin(condition);
  3919. },
  3920. // return the number of states currently on the stack
  3921. stateStackSize:function stateStackSize() {
  3922. return this.conditionStack.length;
  3923. },
  3924. options: {},
  3925. performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
  3926. var YYSTATE=YY_START;
  3927. switch($avoiding_name_collisions) {
  3928. case 0:return 5
  3929. break;
  3930. case 1:/* skip whitespace */
  3931. break;
  3932. case 2:return 8
  3933. break;
  3934. case 3:return 16
  3935. break;
  3936. case 4:return 17
  3937. break;
  3938. case 5:return 11
  3939. break;
  3940. case 6:return 10
  3941. break;
  3942. case 7:return 9
  3943. break;
  3944. case 8:return 14
  3945. break;
  3946. case 9:return 15
  3947. break;
  3948. case 10:return 12
  3949. break;
  3950. case 11:return 7
  3951. break;
  3952. case 12:return 7
  3953. break;
  3954. case 13:return 7
  3955. break;
  3956. case 14:return 7
  3957. break;
  3958. case 15:return 7
  3959. break;
  3960. case 16:return 7
  3961. break;
  3962. case 17:return 7
  3963. break;
  3964. case 18:return 7
  3965. break;
  3966. case 19:return 7
  3967. break;
  3968. case 20:return 7
  3969. break;
  3970. case 21:return 7
  3971. break;
  3972. case 22:return 7
  3973. break;
  3974. case 23:return 7
  3975. break;
  3976. case 24:return 13
  3977. break;
  3978. case 25:return 13
  3979. break;
  3980. case 26:return 13
  3981. break;
  3982. case 27:return 13
  3983. break;
  3984. case 28:return 13
  3985. break;
  3986. case 29:return 13
  3987. break;
  3988. case 30:return 13
  3989. break;
  3990. case 31:return 13
  3991. break;
  3992. case 32:return 7
  3993. break;
  3994. case 33:return 13
  3995. break;
  3996. case 34:return 7
  3997. break;
  3998. case 35:return 13
  3999. break;
  4000. case 36:return 7
  4001. break;
  4002. case 37:return 13
  4003. break;
  4004. case 38:return 13
  4005. break;
  4006. case 39:return 7
  4007. break;
  4008. case 40:return 13
  4009. break;
  4010. case 41:return 13
  4011. break;
  4012. case 42:return 13
  4013. break;
  4014. case 43:return 13
  4015. break;
  4016. case 44:return 13
  4017. break;
  4018. case 45:return 7
  4019. break;
  4020. case 46:return 13
  4021. break;
  4022. case 47:return 7
  4023. break;
  4024. case 48:return 7
  4025. break;
  4026. case 49:return 7
  4027. break;
  4028. case 50:return 7
  4029. break;
  4030. case 51:return 7
  4031. break;
  4032. case 52:return 7
  4033. break;
  4034. case 53:return 7
  4035. break;
  4036. case 54:return 7
  4037. break;
  4038. case 55:return 7
  4039. break;
  4040. case 56:return 7
  4041. break;
  4042. case 57:return 7
  4043. break;
  4044. case 58:return 7
  4045. break;
  4046. case 59:return 7
  4047. break;
  4048. case 60:return 7
  4049. break;
  4050. case 61:return 7
  4051. break;
  4052. case 62:return 7
  4053. break;
  4054. case 63:return 13
  4055. break;
  4056. case 64:return 7
  4057. break;
  4058. case 65:return 7
  4059. break;
  4060. case 66:return 13
  4061. break;
  4062. case 67:return 7
  4063. break;
  4064. case 68:return 7
  4065. break;
  4066. case 69:return 7
  4067. break;
  4068. case 70:return 7
  4069. break;
  4070. case 71:return 7
  4071. break;
  4072. case 72:return 7
  4073. break;
  4074. case 73:return 13
  4075. break;
  4076. case 74:return 7
  4077. break;
  4078. case 75:return 13
  4079. break;
  4080. case 76:return 7
  4081. break;
  4082. case 77:return 7
  4083. break;
  4084. case 78:return 7
  4085. break;
  4086. case 79:return 7
  4087. break;
  4088. case 80:return 7
  4089. break;
  4090. case 81:return 7
  4091. break;
  4092. case 82:return 7
  4093. break;
  4094. case 83:return 7
  4095. break;
  4096. case 84:return 7
  4097. break;
  4098. case 85:return 7
  4099. break;
  4100. case 86:return 7
  4101. break;
  4102. case 87:return 7
  4103. break;
  4104. case 88:return 7
  4105. break;
  4106. case 89:return 7
  4107. break;
  4108. case 90:return 7
  4109. break;
  4110. case 91:return 7
  4111. break;
  4112. case 92:return 7
  4113. break;
  4114. case 93:return 7
  4115. break;
  4116. case 94:return 7
  4117. break;
  4118. case 95:return 7
  4119. break;
  4120. case 96:return 7
  4121. break;
  4122. case 97:return 7
  4123. break;
  4124. case 98:return 7
  4125. break;
  4126. case 99:return 7
  4127. break;
  4128. case 100:return 7
  4129. break;
  4130. case 101:return 7
  4131. break;
  4132. case 102:return 7
  4133. break;
  4134. case 103:return 7
  4135. break;
  4136. case 104:return 7
  4137. break;
  4138. case 105:return 7
  4139. break;
  4140. case 106:return 7
  4141. break;
  4142. case 107:return 7
  4143. break;
  4144. case 108:return 7
  4145. break;
  4146. case 109:return 7
  4147. break;
  4148. case 110:return 7
  4149. break;
  4150. case 111:return 7
  4151. break;
  4152. case 112:return 7
  4153. break;
  4154. case 113:return 7
  4155. break;
  4156. case 114:return 7
  4157. break;
  4158. case 115:return 7
  4159. break;
  4160. case 116:return 7
  4161. break;
  4162. case 117:return 7
  4163. break;
  4164. case 118:return 7
  4165. break;
  4166. case 119:return 7
  4167. break;
  4168. case 120:return 7
  4169. break;
  4170. case 121:return 7
  4171. break;
  4172. case 122:return 7
  4173. break;
  4174. case 123:return 7
  4175. break;
  4176. case 124:return 7
  4177. break;
  4178. case 125:return 7
  4179. break;
  4180. case 126:return 7
  4181. break;
  4182. case 127:return 7
  4183. break;
  4184. case 128:return 7
  4185. break;
  4186. case 129:return 7
  4187. break;
  4188. case 130:return 7
  4189. break;
  4190. case 131:return 7
  4191. break;
  4192. case 132:return 7
  4193. break;
  4194. case 133:return 7
  4195. break;
  4196. case 134:return 7
  4197. break;
  4198. case 135:return 7
  4199. break;
  4200. case 136:return 7
  4201. break;
  4202. case 137:return 7
  4203. break;
  4204. case 138:return 7
  4205. break;
  4206. case 139:return 7
  4207. break;
  4208. case 140:return 7
  4209. break;
  4210. case 141:return 7
  4211. break;
  4212. case 142:return 7
  4213. break;
  4214. case 143:return 7
  4215. break;
  4216. case 144:return 7
  4217. break;
  4218. case 145:return 7
  4219. break;
  4220. case 146:return 7
  4221. break;
  4222. case 147:return 7
  4223. break;
  4224. case 148:return 7
  4225. break;
  4226. case 149:return 7
  4227. break;
  4228. case 150:return 7
  4229. break;
  4230. case 151:return 7
  4231. break;
  4232. case 152:return 7
  4233. break;
  4234. case 153:return 7
  4235. break;
  4236. case 154:return 7
  4237. break;
  4238. case 155:return 7
  4239. break;
  4240. case 156:return 7
  4241. break;
  4242. case 157:return 7
  4243. break;
  4244. case 158:return 7
  4245. break;
  4246. case 159:return 7
  4247. break;
  4248. case 160:return 7
  4249. break;
  4250. case 161:return 7
  4251. break;
  4252. case 162:return 7
  4253. break;
  4254. case 163:return 7
  4255. break;
  4256. case 164:return 7
  4257. break;
  4258. case 165:return 7
  4259. break;
  4260. case 166:return 7
  4261. break;
  4262. case 167:return 7
  4263. break;
  4264. case 168:return 7
  4265. break;
  4266. case 169:return 7
  4267. break;
  4268. case 170:return 7
  4269. break;
  4270. case 171:return 7
  4271. break;
  4272. case 172:return 7
  4273. break;
  4274. case 173:return 7
  4275. break;
  4276. case 174:return 7
  4277. break;
  4278. case 175:return 7
  4279. break;
  4280. case 176:return 7
  4281. break;
  4282. case 177:return 7
  4283. break;
  4284. case 178:return 7
  4285. break;
  4286. case 179:return 7
  4287. break;
  4288. case 180:return 7
  4289. break;
  4290. case 181:return 7
  4291. break;
  4292. case 182:return 7
  4293. break;
  4294. case 183:return 7
  4295. break;
  4296. case 184:return 7
  4297. break;
  4298. case 185:return 7
  4299. break;
  4300. case 186:return 7
  4301. break;
  4302. case 187:return 7
  4303. break;
  4304. case 188:return 7
  4305. break;
  4306. case 189:return 7
  4307. break;
  4308. case 190:return 7
  4309. break;
  4310. case 191:return 7
  4311. break;
  4312. case 192:return 7
  4313. break;
  4314. case 193:return 7
  4315. break;
  4316. case 194:return 7
  4317. break;
  4318. case 195:return 7
  4319. break;
  4320. case 196:return 7
  4321. break;
  4322. case 197:return 7
  4323. break;
  4324. case 198:return 7
  4325. break;
  4326. case 199:return 7
  4327. break;
  4328. case 200:return 7
  4329. break;
  4330. case 201:return 7
  4331. break;
  4332. case 202:return 7
  4333. break;
  4334. case 203:return 7
  4335. break;
  4336. case 204:return 7
  4337. break;
  4338. case 205:return 7
  4339. break;
  4340. case 206:return 7
  4341. break;
  4342. case 207:return 7
  4343. break;
  4344. case 208:return 7
  4345. break;
  4346. case 209:return 7
  4347. break;
  4348. case 210:return 7
  4349. break;
  4350. case 211:return 7
  4351. break;
  4352. case 212:return 7
  4353. break;
  4354. case 213:return 7
  4355. break;
  4356. case 214:return 7
  4357. break;
  4358. case 215:return 7
  4359. break;
  4360. case 216:return 7
  4361. break;
  4362. case 217:return 7
  4363. break;
  4364. case 218:return 7
  4365. break;
  4366. case 219:return 7
  4367. break;
  4368. case 220:return 7
  4369. break;
  4370. case 221:return 7
  4371. break;
  4372. case 222:return 7
  4373. break;
  4374. case 223:return 7
  4375. break;
  4376. case 224:return 7
  4377. break;
  4378. case 225:return 7
  4379. break;
  4380. case 226:return 7
  4381. break;
  4382. case 227:return 7
  4383. break;
  4384. case 228:return 7
  4385. break;
  4386. case 229:return 7
  4387. break;
  4388. case 230:return 7
  4389. break;
  4390. case 231:return 7
  4391. break;
  4392. case 232:return 7
  4393. break;
  4394. case 233:return 7
  4395. break;
  4396. case 234:return 7
  4397. break;
  4398. case 235:return 7
  4399. break;
  4400. case 236:return 7
  4401. break;
  4402. case 237:return 7
  4403. break;
  4404. case 238:return 7
  4405. break;
  4406. case 239:return 7
  4407. break;
  4408. case 240:return 7
  4409. break;
  4410. case 241:return 7
  4411. break;
  4412. case 242:return 7
  4413. break;
  4414. case 243:return 7
  4415. break;
  4416. case 244:return 7
  4417. break;
  4418. case 245:return 7
  4419. break;
  4420. case 246:return 7
  4421. break;
  4422. case 247:return 7
  4423. break;
  4424. case 248:return 7
  4425. break;
  4426. case 249:return 7
  4427. break;
  4428. case 250:return 7
  4429. break;
  4430. case 251:return 7
  4431. break;
  4432. case 252:return 7
  4433. break;
  4434. case 253:return 7
  4435. break;
  4436. case 254:return 7
  4437. break;
  4438. case 255:return 7
  4439. break;
  4440. case 256:return 7
  4441. break;
  4442. case 257:return 7
  4443. break;
  4444. case 258:return 7
  4445. break;
  4446. case 259:return 7
  4447. break;
  4448. case 260:return 7
  4449. break;
  4450. case 261:return 7
  4451. break;
  4452. case 262:return 7
  4453. break;
  4454. case 263:return 7
  4455. break;
  4456. case 264:return 7
  4457. break;
  4458. case 265:return 7
  4459. break;
  4460. case 266:return 7
  4461. break;
  4462. case 267:return 7
  4463. break;
  4464. case 268:return 7
  4465. break;
  4466. case 269:return 7
  4467. break;
  4468. case 270:return 7
  4469. break;
  4470. case 271:return 7
  4471. break;
  4472. case 272:return 7
  4473. break;
  4474. case 273:return 7
  4475. break;
  4476. case 274:return 7
  4477. break;
  4478. case 275:return 7
  4479. break;
  4480. case 276:return 7
  4481. break;
  4482. case 277:return 7
  4483. break;
  4484. case 278:return 7
  4485. break;
  4486. case 279:return 7
  4487. break;
  4488. case 280:return 7
  4489. break;
  4490. case 281:return 7
  4491. break;
  4492. case 282:return 7
  4493. break;
  4494. case 283:return 7
  4495. break;
  4496. case 284:return 7
  4497. break;
  4498. case 285:return 7
  4499. break;
  4500. case 286:return 7
  4501. break;
  4502. case 287:return 7
  4503. break;
  4504. case 288:return 7
  4505. break;
  4506. case 289:return 7
  4507. break;
  4508. case 290:return 7
  4509. break;
  4510. case 291:return 7
  4511. break;
  4512. case 292:return 7
  4513. break;
  4514. case 293:return 7
  4515. break;
  4516. case 294:return 7
  4517. break;
  4518. case 295:return 7
  4519. break;
  4520. case 296:return 7
  4521. break;
  4522. case 297:return 7
  4523. break;
  4524. case 298:return 7
  4525. break;
  4526. case 299:return 7
  4527. break;
  4528. case 300:return 7
  4529. break;
  4530. case 301:return 7
  4531. break;
  4532. case 302:return 7
  4533. break;
  4534. case 303:return 7
  4535. break;
  4536. case 304:return 7
  4537. break;
  4538. case 305:return 7
  4539. break;
  4540. case 306:return 7
  4541. break;
  4542. case 307:return 7
  4543. break;
  4544. case 308:return 7
  4545. break;
  4546. case 309:return 7
  4547. break;
  4548. case 310:return 7
  4549. break;
  4550. case 311:return 7
  4551. break;
  4552. case 312:return 7
  4553. break;
  4554. case 313:return 7
  4555. break;
  4556. case 314:return 7
  4557. break;
  4558. case 315:return 7
  4559. break;
  4560. case 316:return 7
  4561. break;
  4562. case 317:return 7
  4563. break;
  4564. case 318:return 7
  4565. break;
  4566. case 319:return 7
  4567. break;
  4568. case 320:return 7
  4569. break;
  4570. case 321:return 7
  4571. break;
  4572. case 322:return 7
  4573. break;
  4574. case 323:return 7
  4575. break;
  4576. case 324:return 7
  4577. break;
  4578. case 325:return 7
  4579. break;
  4580. case 326:return 7
  4581. break;
  4582. case 327:return 7
  4583. break;
  4584. case 328:return 7
  4585. break;
  4586. case 329:return 7
  4587. break;
  4588. case 330:return 7
  4589. break;
  4590. case 331:return 7
  4591. break;
  4592. case 332:return 7
  4593. break;
  4594. case 333:return 7
  4595. break;
  4596. case 334:return 7
  4597. break;
  4598. case 335:return 7
  4599. break;
  4600. case 336:return 7
  4601. break;
  4602. case 337:return 7
  4603. break;
  4604. case 338:return 7
  4605. break;
  4606. case 339:return 7
  4607. break;
  4608. case 340:return 7
  4609. break;
  4610. case 341:return 7
  4611. break;
  4612. case 342:return 7
  4613. break;
  4614. case 343:return 7
  4615. break;
  4616. case 344:return 7
  4617. break;
  4618. case 345:return 7
  4619. break;
  4620. case 346:return 7
  4621. break;
  4622. case 347:return 7
  4623. break;
  4624. case 348:return 7
  4625. break;
  4626. case 349:return 7
  4627. break;
  4628. case 350:return 7
  4629. break;
  4630. case 351:return 7
  4631. break;
  4632. case 352:return 7
  4633. break;
  4634. case 353:return 7
  4635. break;
  4636. case 354:return 7
  4637. break;
  4638. case 355:return 7
  4639. break;
  4640. case 356:return 7
  4641. break;
  4642. case 357:return 7
  4643. break;
  4644. case 358:return 7
  4645. break;
  4646. case 359:return 7
  4647. break;
  4648. case 360:return 7
  4649. break;
  4650. case 361:return 7
  4651. break;
  4652. case 362:return 7
  4653. break;
  4654. case 363:return 7
  4655. break;
  4656. case 364:return 7
  4657. break;
  4658. }
  4659. },
  4660. rules: [/^(?:$)/,/^(?:\s+)/,/^(?:\+)/,/^(?:\()/,/^(?:\))/,/^(?::)/,/^(?:DocumentRef-([0-9A-Za-z-+.]+))/,/^(?:LicenseRef-([0-9A-Za-z-+.]+))/,/^(?:AND)/,/^(?:OR)/,/^(?:WITH)/,/^(?:BSD-3-Clause-No-Nuclear-License-2014)/,/^(?:BSD-3-Clause-No-Nuclear-Warranty)/,/^(?:GPL-2\.0-with-classpath-exception)/,/^(?:GPL-3\.0-with-autoconf-exception)/,/^(?:GPL-2\.0-with-autoconf-exception)/,/^(?:BSD-3-Clause-No-Nuclear-License)/,/^(?:MPL-2\.0-no-copyleft-exception)/,/^(?:GPL-2\.0-with-bison-exception)/,/^(?:GPL-2\.0-with-font-exception)/,/^(?:GPL-2\.0-with-GCC-exception)/,/^(?:CNRI-Python-GPL-Compatible)/,/^(?:GPL-3\.0-with-GCC-exception)/,/^(?:BSD-3-Clause-Attribution)/,/^(?:Classpath-exception-2\.0)/,/^(?:WxWindows-exception-3\.1)/,/^(?:freertos-exception-2\.0)/,/^(?:Autoconf-exception-3\.0)/,/^(?:i2p-gpl-java-exception)/,/^(?:gnu-javamail-exception)/,/^(?:Nokia-Qt-exception-1\.1)/,/^(?:Autoconf-exception-2\.0)/,/^(?:BSD-2-Clause-FreeBSD)/,/^(?:u-boot-exception-2\.0)/,/^(?:zlib-acknowledgement)/,/^(?:Bison-exception-2\.2)/,/^(?:BSD-2-Clause-NetBSD)/,/^(?:CLISP-exception-2\.0)/,/^(?:eCos-exception-2\.0)/,/^(?:BSD-3-Clause-Clear)/,/^(?:Font-exception-2\.0)/,/^(?:FLTK-exception-2\.0)/,/^(?:GCC-exception-2\.0)/,/^(?:Qwt-exception-1\.0)/,/^(?:Libtool-exception)/,/^(?:BSD-3-Clause-LBNL)/,/^(?:GCC-exception-3\.1)/,/^(?:Artistic-1\.0-Perl)/,/^(?:Artistic-1\.0-cl8)/,/^(?:CC-BY-NC-SA-2\.5)/,/^(?:MIT-advertising)/,/^(?:BSD-Source-Code)/,/^(?:CC-BY-NC-SA-4\.0)/,/^(?:LiLiQ-Rplus-1\.1)/,/^(?:CC-BY-NC-SA-3\.0)/,/^(?:BSD-4-Clause-UC)/,/^(?:CC-BY-NC-SA-2\.0)/,/^(?:CC-BY-NC-SA-1\.0)/,/^(?:CC-BY-NC-ND-4\.0)/,/^(?:CC-BY-NC-ND-3\.0)/,/^(?:CC-BY-NC-ND-2\.5)/,/^(?:CC-BY-NC-ND-2\.0)/,/^(?:CC-BY-NC-ND-1\.0)/,/^(?:LZMA-exception)/,/^(?:BitTorrent-1\.1)/,/^(?:CrystalStacker)/,/^(?:FLTK-exception)/,/^(?:SugarCRM-1\.1\.3)/,/^(?:BSD-Protection)/,/^(?:BitTorrent-1\.0)/,/^(?:HaskellReport)/,/^(?:Interbase-1\.0)/,/^(?:StandardML-NJ)/,/^(?:mif-exception)/,/^(?:Frameworx-1\.0)/,/^(?:389-exception)/,/^(?:CC-BY-NC-2\.0)/,/^(?:CC-BY-NC-2\.5)/,/^(?:CC-BY-NC-3\.0)/,/^(?:CC-BY-NC-4\.0)/,/^(?:W3C-19980720)/,/^(?:CC-BY-SA-1\.0)/,/^(?:CC-BY-SA-2\.0)/,/^(?:CC-BY-SA-2\.5)/,/^(?:CC-BY-ND-2\.0)/,/^(?:CC-BY-SA-4\.0)/,/^(?:CC-BY-SA-3\.0)/,/^(?:Artistic-1\.0)/,/^(?:Artistic-2\.0)/,/^(?:CC-BY-ND-2\.5)/,/^(?:CC-BY-ND-3\.0)/,/^(?:CC-BY-ND-4\.0)/,/^(?:CC-BY-ND-1\.0)/,/^(?:BSD-4-Clause)/,/^(?:BSD-3-Clause)/,/^(?:BSD-2-Clause)/,/^(?:CC-BY-NC-1\.0)/,/^(?:bzip2-1\.0\.6)/,/^(?:Unicode-TOU)/,/^(?:CNRI-Jython)/,/^(?:ImageMagick)/,/^(?:Adobe-Glyph)/,/^(?:CUA-OPL-1\.0)/,/^(?:OLDAP-2\.2\.2)/,/^(?:LiLiQ-R-1\.1)/,/^(?:bzip2-1\.0\.5)/,/^(?:LiLiQ-P-1\.1)/,/^(?:OLDAP-2\.0\.1)/,/^(?:OLDAP-2\.2\.1)/,/^(?:CNRI-Python)/,/^(?:XFree86-1\.1)/,/^(?:OSET-PL-2\.1)/,/^(?:Apache-2\.0)/,/^(?:Watcom-1\.0)/,/^(?:PostgreSQL)/,/^(?:Python-2\.0)/,/^(?:RHeCos-1\.1)/,/^(?:EUDatagrid)/,/^(?:Spencer-99)/,/^(?:Intel-ACPI)/,/^(?:CECILL-1\.0)/,/^(?:CECILL-1\.1)/,/^(?:JasPer-2\.0)/,/^(?:CECILL-2\.0)/,/^(?:CECILL-2\.1)/,/^(?:gSOAP-1\.3b)/,/^(?:Spencer-94)/,/^(?:Apache-1\.1)/,/^(?:Spencer-86)/,/^(?:Apache-1\.0)/,/^(?:ClArtistic)/,/^(?:TORQUE-1\.1)/,/^(?:CATOSL-1\.1)/,/^(?:Adobe-2006)/,/^(?:Zimbra-1\.4)/,/^(?:Zimbra-1\.3)/,/^(?:Condor-1\.1)/,/^(?:CC-BY-3\.0)/,/^(?:CC-BY-2\.5)/,/^(?:OLDAP-2\.4)/,/^(?:SGI-B-1\.1)/,/^(?:SISSL-1\.2)/,/^(?:SGI-B-1\.0)/,/^(?:OLDAP-2\.3)/,/^(?:CC-BY-4\.0)/,/^(?:Crossword)/,/^(?:SimPL-2\.0)/,/^(?:OLDAP-2\.2)/,/^(?:OLDAP-2\.1)/,/^(?:ErlPL-1\.1)/,/^(?:LPPL-1\.3a)/,/^(?:LPPL-1\.3c)/,/^(?:OLDAP-2\.0)/,/^(?:Leptonica)/,/^(?:CPOL-1\.02)/,/^(?:OLDAP-1\.4)/,/^(?:OLDAP-1\.3)/,/^(?:CC-BY-2\.0)/,/^(?:Unlicense)/,/^(?:OLDAP-2\.8)/,/^(?:OLDAP-1\.2)/,/^(?:MakeIndex)/,/^(?:OLDAP-2\.7)/,/^(?:OLDAP-1\.1)/,/^(?:Sleepycat)/,/^(?:D-FSL-1\.0)/,/^(?:CC-BY-1\.0)/,/^(?:OLDAP-2\.6)/,/^(?:WXwindows)/,/^(?:NPOSL-3\.0)/,/^(?:FreeImage)/,/^(?:SGI-B-2\.0)/,/^(?:OLDAP-2\.5)/,/^(?:Beerware)/,/^(?:Newsletr)/,/^(?:NBPL-1\.0)/,/^(?:NASA-1\.3)/,/^(?:NLOD-1\.0)/,/^(?:AGPL-1\.0)/,/^(?:OCLC-2\.0)/,/^(?:ODbL-1\.0)/,/^(?:PDDL-1\.0)/,/^(?:Motosoto)/,/^(?:Afmparse)/,/^(?:ANTLR-PD)/,/^(?:LPL-1\.02)/,/^(?:Abstyles)/,/^(?:eCos-2\.0)/,/^(?:APSL-1\.0)/,/^(?:LPPL-1\.2)/,/^(?:LPPL-1\.1)/,/^(?:LPPL-1\.0)/,/^(?:APSL-1\.1)/,/^(?:APSL-2\.0)/,/^(?:Info-ZIP)/,/^(?:Zend-2\.0)/,/^(?:IBM-pibs)/,/^(?:LGPL-2\.0)/,/^(?:LGPL-3\.0)/,/^(?:LGPL-2\.1)/,/^(?:GFDL-1\.3)/,/^(?:PHP-3\.01)/,/^(?:GFDL-1\.2)/,/^(?:GFDL-1\.1)/,/^(?:AGPL-3\.0)/,/^(?:Giftware)/,/^(?:EUPL-1\.1)/,/^(?:RPSL-1\.0)/,/^(?:EUPL-1\.0)/,/^(?:MIT-enna)/,/^(?:CECILL-B)/,/^(?:diffmark)/,/^(?:CECILL-C)/,/^(?:CDDL-1\.0)/,/^(?:Sendmail)/,/^(?:CDDL-1\.1)/,/^(?:CPAL-1\.0)/,/^(?:APSL-1\.2)/,/^(?:NPL-1\.1)/,/^(?:AFL-1\.2)/,/^(?:Caldera)/,/^(?:AFL-2\.0)/,/^(?:FSFULLR)/,/^(?:AFL-2\.1)/,/^(?:VSL-1\.0)/,/^(?:VOSTROM)/,/^(?:UPL-1\.0)/,/^(?:Dotseqn)/,/^(?:CPL-1\.0)/,/^(?:dvipdfm)/,/^(?:EPL-1\.0)/,/^(?:OCCT-PL)/,/^(?:ECL-1\.0)/,/^(?:Latex2e)/,/^(?:ECL-2\.0)/,/^(?:GPL-1\.0)/,/^(?:GPL-2\.0)/,/^(?:GPL-3\.0)/,/^(?:AFL-3\.0)/,/^(?:LAL-1\.2)/,/^(?:LAL-1\.3)/,/^(?:EFL-1\.0)/,/^(?:EFL-2\.0)/,/^(?:gnuplot)/,/^(?:Aladdin)/,/^(?:LPL-1\.0)/,/^(?:libtiff)/,/^(?:Entessa)/,/^(?:AMDPLPA)/,/^(?:IPL-1\.0)/,/^(?:OPL-1\.0)/,/^(?:OSL-1\.0)/,/^(?:OSL-1\.1)/,/^(?:OSL-2\.0)/,/^(?:OSL-2\.1)/,/^(?:OSL-3\.0)/,/^(?:OpenSSL)/,/^(?:ZPL-2\.1)/,/^(?:PHP-3\.0)/,/^(?:ZPL-2\.0)/,/^(?:ZPL-1\.1)/,/^(?:CC0-1\.0)/,/^(?:SPL-1\.0)/,/^(?:psutils)/,/^(?:MPL-1\.0)/,/^(?:QPL-1\.0)/,/^(?:MPL-1\.1)/,/^(?:MPL-2\.0)/,/^(?:APL-1\.0)/,/^(?:RPL-1\.1)/,/^(?:RPL-1\.5)/,/^(?:MIT-CMU)/,/^(?:Multics)/,/^(?:Eurosym)/,/^(?:BSL-1\.0)/,/^(?:MIT-feh)/,/^(?:Saxpath)/,/^(?:Borceux)/,/^(?:OFL-1\.1)/,/^(?:OFL-1\.0)/,/^(?:AFL-1\.1)/,/^(?:YPL-1\.1)/,/^(?:YPL-1\.0)/,/^(?:NPL-1\.0)/,/^(?:iMatix)/,/^(?:mpich2)/,/^(?:APAFML)/,/^(?:Bahyph)/,/^(?:RSA-MD)/,/^(?:psfrag)/,/^(?:Plexus)/,/^(?:eGenix)/,/^(?:Glulxe)/,/^(?:SAX-PD)/,/^(?:Imlib2)/,/^(?:Wsuipa)/,/^(?:LGPLLR)/,/^(?:Libpng)/,/^(?:xinetd)/,/^(?:MITNFA)/,/^(?:NetCDF)/,/^(?:Naumen)/,/^(?:SMPPL)/,/^(?:Nunit)/,/^(?:FSFUL)/,/^(?:GL2PS)/,/^(?:SMLNJ)/,/^(?:Rdisc)/,/^(?:Noweb)/,/^(?:Nokia)/,/^(?:SISSL)/,/^(?:Qhull)/,/^(?:Intel)/,/^(?:Glide)/,/^(?:Xerox)/,/^(?:AMPAS)/,/^(?:WTFPL)/,/^(?:MS-PL)/,/^(?:XSkat)/,/^(?:MS-RL)/,/^(?:MirOS)/,/^(?:RSCPL)/,/^(?:TMate)/,/^(?:OGTSL)/,/^(?:FSFAP)/,/^(?:NCSA)/,/^(?:Zlib)/,/^(?:SCEA)/,/^(?:SNIA)/,/^(?:NGPL)/,/^(?:NOSL)/,/^(?:ADSL)/,/^(?:MTLL)/,/^(?:NLPL)/,/^(?:Ruby)/,/^(?:JSON)/,/^(?:Barr)/,/^(?:0BSD)/,/^(?:Xnet)/,/^(?:Cube)/,/^(?:curl)/,/^(?:DSDP)/,/^(?:Fair)/,/^(?:HPND)/,/^(?:TOSL)/,/^(?:IJG)/,/^(?:SWL)/,/^(?:Vim)/,/^(?:FTL)/,/^(?:ICU)/,/^(?:OML)/,/^(?:NRL)/,/^(?:DOC)/,/^(?:TCL)/,/^(?:W3C)/,/^(?:NTP)/,/^(?:IPA)/,/^(?:ISC)/,/^(?:X11)/,/^(?:AAL)/,/^(?:AML)/,/^(?:xpp)/,/^(?:Zed)/,/^(?:MIT)/,/^(?:Mup)/],
  4661. conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364],"inclusive":true}}
  4662. });
  4663. return lexer;
  4664. })();
  4665. parser.lexer = lexer;
  4666. function Parser () {
  4667. this.yy = {};
  4668. }
  4669. Parser.prototype = parser;parser.Parser = Parser;
  4670. return new Parser;
  4671. })();
  4672. if (typeof commonjsRequire !== 'undefined' && 'object' !== 'undefined') {
  4673. exports.parser = spdxparse;
  4674. exports.Parser = spdxparse.Parser;
  4675. exports.parse = function () { return spdxparse.parse.apply(spdxparse, arguments); };
  4676. exports.main = function commonjsMain(args) {
  4677. if (!args[1]) {
  4678. console.log('Usage: '+args[0]+' FILE');
  4679. process.exit(1);
  4680. }
  4681. var source = fs.readFileSync(path.normalize(args[1]), "utf8");
  4682. return exports.parser.parse(source);
  4683. };
  4684. if ('object' !== 'undefined' && commonjsRequire.main === module) {
  4685. exports.main(process.argv.slice(1));
  4686. }
  4687. }
  4688. });
  4689. var parser = parser$1.parser;
  4690. var spdxExpressionParse = function (argument) {
  4691. return parser.parse(argument)
  4692. };
  4693. var spdxLicenseIds = [
  4694. "Glide",
  4695. "Abstyles",
  4696. "AFL-1.1",
  4697. "AFL-1.2",
  4698. "AFL-2.0",
  4699. "AFL-2.1",
  4700. "AFL-3.0",
  4701. "AMPAS",
  4702. "APL-1.0",
  4703. "Adobe-Glyph",
  4704. "APAFML",
  4705. "Adobe-2006",
  4706. "AGPL-1.0",
  4707. "Afmparse",
  4708. "Aladdin",
  4709. "ADSL",
  4710. "AMDPLPA",
  4711. "ANTLR-PD",
  4712. "Apache-1.0",
  4713. "Apache-1.1",
  4714. "Apache-2.0",
  4715. "AML",
  4716. "APSL-1.0",
  4717. "APSL-1.1",
  4718. "APSL-1.2",
  4719. "APSL-2.0",
  4720. "Artistic-1.0",
  4721. "Artistic-1.0-Perl",
  4722. "Artistic-1.0-cl8",
  4723. "Artistic-2.0",
  4724. "AAL",
  4725. "Bahyph",
  4726. "Barr",
  4727. "Beerware",
  4728. "BitTorrent-1.0",
  4729. "BitTorrent-1.1",
  4730. "BSL-1.0",
  4731. "Borceux",
  4732. "BSD-2-Clause",
  4733. "BSD-2-Clause-FreeBSD",
  4734. "BSD-2-Clause-NetBSD",
  4735. "BSD-3-Clause",
  4736. "BSD-3-Clause-Clear",
  4737. "BSD-4-Clause",
  4738. "BSD-Protection",
  4739. "BSD-Source-Code",
  4740. "BSD-3-Clause-Attribution",
  4741. "0BSD",
  4742. "BSD-4-Clause-UC",
  4743. "bzip2-1.0.5",
  4744. "bzip2-1.0.6",
  4745. "Caldera",
  4746. "CECILL-1.0",
  4747. "CECILL-1.1",
  4748. "CECILL-2.0",
  4749. "CECILL-2.1",
  4750. "CECILL-B",
  4751. "CECILL-C",
  4752. "ClArtistic",
  4753. "MIT-CMU",
  4754. "CNRI-Jython",
  4755. "CNRI-Python",
  4756. "CNRI-Python-GPL-Compatible",
  4757. "CPOL-1.02",
  4758. "CDDL-1.0",
  4759. "CDDL-1.1",
  4760. "CPAL-1.0",
  4761. "CPL-1.0",
  4762. "CATOSL-1.1",
  4763. "Condor-1.1",
  4764. "CC-BY-1.0",
  4765. "CC-BY-2.0",
  4766. "CC-BY-2.5",
  4767. "CC-BY-3.0",
  4768. "CC-BY-4.0",
  4769. "CC-BY-ND-1.0",
  4770. "CC-BY-ND-2.0",
  4771. "CC-BY-ND-2.5",
  4772. "CC-BY-ND-3.0",
  4773. "CC-BY-ND-4.0",
  4774. "CC-BY-NC-1.0",
  4775. "CC-BY-NC-2.0",
  4776. "CC-BY-NC-2.5",
  4777. "CC-BY-NC-3.0",
  4778. "CC-BY-NC-4.0",
  4779. "CC-BY-NC-ND-1.0",
  4780. "CC-BY-NC-ND-2.0",
  4781. "CC-BY-NC-ND-2.5",
  4782. "CC-BY-NC-ND-3.0",
  4783. "CC-BY-NC-ND-4.0",
  4784. "CC-BY-NC-SA-1.0",
  4785. "CC-BY-NC-SA-2.0",
  4786. "CC-BY-NC-SA-2.5",
  4787. "CC-BY-NC-SA-3.0",
  4788. "CC-BY-NC-SA-4.0",
  4789. "CC-BY-SA-1.0",
  4790. "CC-BY-SA-2.0",
  4791. "CC-BY-SA-2.5",
  4792. "CC-BY-SA-3.0",
  4793. "CC-BY-SA-4.0",
  4794. "CC0-1.0",
  4795. "Crossword",
  4796. "CrystalStacker",
  4797. "CUA-OPL-1.0",
  4798. "Cube",
  4799. "curl",
  4800. "D-FSL-1.0",
  4801. "diffmark",
  4802. "WTFPL",
  4803. "DOC",
  4804. "Dotseqn",
  4805. "DSDP",
  4806. "dvipdfm",
  4807. "EPL-1.0",
  4808. "ECL-1.0",
  4809. "ECL-2.0",
  4810. "eGenix",
  4811. "EFL-1.0",
  4812. "EFL-2.0",
  4813. "MIT-advertising",
  4814. "MIT-enna",
  4815. "Entessa",
  4816. "ErlPL-1.1",
  4817. "EUDatagrid",
  4818. "EUPL-1.0",
  4819. "EUPL-1.1",
  4820. "Eurosym",
  4821. "Fair",
  4822. "MIT-feh",
  4823. "Frameworx-1.0",
  4824. "FreeImage",
  4825. "FTL",
  4826. "FSFAP",
  4827. "FSFUL",
  4828. "FSFULLR",
  4829. "Giftware",
  4830. "GL2PS",
  4831. "Glulxe",
  4832. "AGPL-3.0",
  4833. "GFDL-1.1",
  4834. "GFDL-1.2",
  4835. "GFDL-1.3",
  4836. "GPL-1.0",
  4837. "GPL-2.0",
  4838. "GPL-3.0",
  4839. "LGPL-2.1",
  4840. "LGPL-3.0",
  4841. "LGPL-2.0",
  4842. "gnuplot",
  4843. "gSOAP-1.3b",
  4844. "HaskellReport",
  4845. "HPND",
  4846. "IBM-pibs",
  4847. "IPL-1.0",
  4848. "ICU",
  4849. "ImageMagick",
  4850. "iMatix",
  4851. "Imlib2",
  4852. "IJG",
  4853. "Info-ZIP",
  4854. "Intel-ACPI",
  4855. "Intel",
  4856. "Interbase-1.0",
  4857. "IPA",
  4858. "ISC",
  4859. "JasPer-2.0",
  4860. "JSON",
  4861. "LPPL-1.0",
  4862. "LPPL-1.1",
  4863. "LPPL-1.2",
  4864. "LPPL-1.3a",
  4865. "LPPL-1.3c",
  4866. "Latex2e",
  4867. "BSD-3-Clause-LBNL",
  4868. "Leptonica",
  4869. "LGPLLR",
  4870. "Libpng",
  4871. "libtiff",
  4872. "LAL-1.2",
  4873. "LAL-1.3",
  4874. "LiLiQ-P-1.1",
  4875. "LiLiQ-Rplus-1.1",
  4876. "LiLiQ-R-1.1",
  4877. "LPL-1.02",
  4878. "LPL-1.0",
  4879. "MakeIndex",
  4880. "MTLL",
  4881. "MS-PL",
  4882. "MS-RL",
  4883. "MirOS",
  4884. "MITNFA",
  4885. "MIT",
  4886. "Motosoto",
  4887. "MPL-1.0",
  4888. "MPL-1.1",
  4889. "MPL-2.0",
  4890. "MPL-2.0-no-copyleft-exception",
  4891. "mpich2",
  4892. "Multics",
  4893. "Mup",
  4894. "NASA-1.3",
  4895. "Naumen",
  4896. "NBPL-1.0",
  4897. "NetCDF",
  4898. "NGPL",
  4899. "NOSL",
  4900. "NPL-1.0",
  4901. "NPL-1.1",
  4902. "Newsletr",
  4903. "NLPL",
  4904. "Nokia",
  4905. "NPOSL-3.0",
  4906. "NLOD-1.0",
  4907. "Noweb",
  4908. "NRL",
  4909. "NTP",
  4910. "Nunit",
  4911. "OCLC-2.0",
  4912. "ODbL-1.0",
  4913. "PDDL-1.0",
  4914. "OCCT-PL",
  4915. "OGTSL",
  4916. "OLDAP-2.2.2",
  4917. "OLDAP-1.1",
  4918. "OLDAP-1.2",
  4919. "OLDAP-1.3",
  4920. "OLDAP-1.4",
  4921. "OLDAP-2.0",
  4922. "OLDAP-2.0.1",
  4923. "OLDAP-2.1",
  4924. "OLDAP-2.2",
  4925. "OLDAP-2.2.1",
  4926. "OLDAP-2.3",
  4927. "OLDAP-2.4",
  4928. "OLDAP-2.5",
  4929. "OLDAP-2.6",
  4930. "OLDAP-2.7",
  4931. "OLDAP-2.8",
  4932. "OML",
  4933. "OPL-1.0",
  4934. "OSL-1.0",
  4935. "OSL-1.1",
  4936. "OSL-2.0",
  4937. "OSL-2.1",
  4938. "OSL-3.0",
  4939. "OpenSSL",
  4940. "OSET-PL-2.1",
  4941. "PHP-3.0",
  4942. "PHP-3.01",
  4943. "Plexus",
  4944. "PostgreSQL",
  4945. "psfrag",
  4946. "psutils",
  4947. "Python-2.0",
  4948. "QPL-1.0",
  4949. "Qhull",
  4950. "Rdisc",
  4951. "RPSL-1.0",
  4952. "RPL-1.1",
  4953. "RPL-1.5",
  4954. "RHeCos-1.1",
  4955. "RSCPL",
  4956. "RSA-MD",
  4957. "Ruby",
  4958. "SAX-PD",
  4959. "Saxpath",
  4960. "SCEA",
  4961. "SWL",
  4962. "SMPPL",
  4963. "Sendmail",
  4964. "SGI-B-1.0",
  4965. "SGI-B-1.1",
  4966. "SGI-B-2.0",
  4967. "OFL-1.0",
  4968. "OFL-1.1",
  4969. "SimPL-2.0",
  4970. "Sleepycat",
  4971. "SNIA",
  4972. "Spencer-86",
  4973. "Spencer-94",
  4974. "Spencer-99",
  4975. "SMLNJ",
  4976. "SugarCRM-1.1.3",
  4977. "SISSL",
  4978. "SISSL-1.2",
  4979. "SPL-1.0",
  4980. "Watcom-1.0",
  4981. "TCL",
  4982. "Unlicense",
  4983. "TMate",
  4984. "TORQUE-1.1",
  4985. "TOSL",
  4986. "Unicode-TOU",
  4987. "UPL-1.0",
  4988. "NCSA",
  4989. "Vim",
  4990. "VOSTROM",
  4991. "VSL-1.0",
  4992. "W3C-19980720",
  4993. "W3C",
  4994. "Wsuipa",
  4995. "Xnet",
  4996. "X11",
  4997. "Xerox",
  4998. "XFree86-1.1",
  4999. "xinetd",
  5000. "xpp",
  5001. "XSkat",
  5002. "YPL-1.0",
  5003. "YPL-1.1",
  5004. "Zed",
  5005. "Zend-2.0",
  5006. "Zimbra-1.3",
  5007. "Zimbra-1.4",
  5008. "Zlib",
  5009. "zlib-acknowledgement",
  5010. "ZPL-1.1",
  5011. "ZPL-2.0",
  5012. "ZPL-2.1",
  5013. "BSD-3-Clause-No-Nuclear-License",
  5014. "BSD-3-Clause-No-Nuclear-Warranty",
  5015. "BSD-3-Clause-No-Nuclear-License-2014",
  5016. "eCos-2.0",
  5017. "GPL-2.0-with-autoconf-exception",
  5018. "GPL-2.0-with-bison-exception",
  5019. "GPL-2.0-with-classpath-exception",
  5020. "GPL-2.0-with-font-exception",
  5021. "GPL-2.0-with-GCC-exception",
  5022. "GPL-3.0-with-autoconf-exception",
  5023. "GPL-3.0-with-GCC-exception",
  5024. "StandardML-NJ",
  5025. "WXwindows"
  5026. ]
  5027. ;
  5028. var spdxLicenseIds$1 = Object.freeze({
  5029. default: spdxLicenseIds
  5030. });
  5031. var licenseIDs = ( spdxLicenseIds$1 && spdxLicenseIds ) || spdxLicenseIds$1;
  5032. function valid(string) {
  5033. return licenseIDs.indexOf(string) > -1;
  5034. }
  5035. // Common transpositions of license identifier acronyms
  5036. var transpositions = [
  5037. ['APGL', 'AGPL'],
  5038. ['Gpl', 'GPL'],
  5039. ['GLP', 'GPL'],
  5040. ['APL', 'Apache'],
  5041. ['ISD', 'ISC'],
  5042. ['GLP', 'GPL'],
  5043. ['IST', 'ISC'],
  5044. ['Claude', 'Clause'],
  5045. [' or later', '+'],
  5046. [' International', ''],
  5047. ['GNU', 'GPL'],
  5048. ['GUN', 'GPL'],
  5049. ['+', ''],
  5050. ['GNU GPL', 'GPL'],
  5051. ['GNU/GPL', 'GPL'],
  5052. ['GNU GLP', 'GPL'],
  5053. ['GNU General Public License', 'GPL'],
  5054. ['Gnu public license', 'GPL'],
  5055. ['GNU Public License', 'GPL'],
  5056. ['GNU GENERAL PUBLIC LICENSE', 'GPL'],
  5057. ['MTI', 'MIT'],
  5058. ['Mozilla Public License', 'MPL'],
  5059. ['WTH', 'WTF'],
  5060. ['-License', '']
  5061. ];
  5062. var TRANSPOSED = 0;
  5063. var CORRECT = 1;
  5064. // Simple corrections to nearly valid identifiers.
  5065. var transforms = [
  5066. // e.g. 'mit'
  5067. function(argument) {
  5068. return argument.toUpperCase();
  5069. },
  5070. // e.g. 'MIT '
  5071. function(argument) {
  5072. return argument.trim();
  5073. },
  5074. // e.g. 'M.I.T.'
  5075. function(argument) {
  5076. return argument.replace(/\./g, '');
  5077. },
  5078. // e.g. 'Apache- 2.0'
  5079. function(argument) {
  5080. return argument.replace(/\s+/g, '');
  5081. },
  5082. // e.g. 'CC BY 4.0''
  5083. function(argument) {
  5084. return argument.replace(/\s+/g, '-');
  5085. },
  5086. // e.g. 'LGPLv2.1'
  5087. function(argument) {
  5088. return argument.replace('v', '-');
  5089. },
  5090. // e.g. 'Apache 2.0'
  5091. function(argument) {
  5092. return argument.replace(/,?\s*(\d)/, '-$1');
  5093. },
  5094. // e.g. 'GPL 2'
  5095. function(argument) {
  5096. return argument.replace(/,?\s*(\d)/, '-$1.0');
  5097. },
  5098. // e.g. 'Apache Version 2.0'
  5099. function(argument) {
  5100. return argument.replace(/,?\s*(V\.|v\.|V|v|Version|version)\s*(\d)/, '-$2');
  5101. },
  5102. // e.g. 'Apache Version 2'
  5103. function(argument) {
  5104. return argument.replace(/,?\s*(V\.|v\.|V|v|Version|version)\s*(\d)/, '-$2.0');
  5105. },
  5106. // e.g. 'ZLIB'
  5107. function(argument) {
  5108. return argument[0].toUpperCase() + argument.slice(1);
  5109. },
  5110. // e.g. 'MPL/2.0'
  5111. function(argument) {
  5112. return argument.replace('/', '-');
  5113. },
  5114. // e.g. 'Apache 2'
  5115. function(argument) {
  5116. return argument
  5117. .replace(/\s*V\s*(\d)/, '-$1')
  5118. .replace(/(\d)$/, '$1.0');
  5119. },
  5120. // e.g. 'GPL-2.0-'
  5121. function(argument) {
  5122. return argument.slice(0, argument.length - 1);
  5123. },
  5124. // e.g. 'GPL2'
  5125. function(argument) {
  5126. return argument.replace(/(\d)$/, '-$1.0');
  5127. },
  5128. // e.g. 'BSD 3'
  5129. function(argument) {
  5130. return argument.replace(/(-| )?(\d)$/, '-$2-Clause');
  5131. },
  5132. // e.g. 'BSD clause 3'
  5133. function(argument) {
  5134. return argument.replace(/(-| )clause(-| )(\d)/, '-$3-Clause');
  5135. },
  5136. // e.g. 'BY-NC-4.0'
  5137. function(argument) {
  5138. return 'CC-' + argument;
  5139. },
  5140. // e.g. 'BY-NC'
  5141. function(argument) {
  5142. return 'CC-' + argument + '-4.0';
  5143. },
  5144. // e.g. 'Attribution-NonCommercial'
  5145. function(argument) {
  5146. return argument
  5147. .replace('Attribution', 'BY')
  5148. .replace('NonCommercial', 'NC')
  5149. .replace('NoDerivatives', 'ND')
  5150. .replace(/ (\d)/, '-$1')
  5151. .replace(/ ?International/, '');
  5152. },
  5153. // e.g. 'Attribution-NonCommercial'
  5154. function(argument) {
  5155. return 'CC-' +
  5156. argument
  5157. .replace('Attribution', 'BY')
  5158. .replace('NonCommercial', 'NC')
  5159. .replace('NoDerivatives', 'ND')
  5160. .replace(/ (\d)/, '-$1')
  5161. .replace(/ ?International/, '') +
  5162. '-4.0';
  5163. }
  5164. ];
  5165. // If all else fails, guess that strings containing certain substrings
  5166. // meant to identify certain licenses.
  5167. var lastResorts = [
  5168. ['UNLI', 'Unlicense'],
  5169. ['WTF', 'WTFPL'],
  5170. ['2 CLAUSE', 'BSD-2-Clause'],
  5171. ['2-CLAUSE', 'BSD-2-Clause'],
  5172. ['3 CLAUSE', 'BSD-3-Clause'],
  5173. ['3-CLAUSE', 'BSD-3-Clause'],
  5174. ['AFFERO', 'AGPL-3.0'],
  5175. ['AGPL', 'AGPL-3.0'],
  5176. ['APACHE', 'Apache-2.0'],
  5177. ['ARTISTIC', 'Artistic-2.0'],
  5178. ['Affero', 'AGPL-3.0'],
  5179. ['BEER', 'Beerware'],
  5180. ['BOOST', 'BSL-1.0'],
  5181. ['BSD', 'BSD-2-Clause'],
  5182. ['ECLIPSE', 'EPL-1.0'],
  5183. ['FUCK', 'WTFPL'],
  5184. ['GNU', 'GPL-3.0'],
  5185. ['LGPL', 'LGPL-3.0'],
  5186. ['GPL', 'GPL-3.0'],
  5187. ['MIT', 'MIT'],
  5188. ['MPL', 'MPL-2.0'],
  5189. ['X11', 'X11'],
  5190. ['ZLIB', 'Zlib']
  5191. ];
  5192. var SUBSTRING = 0;
  5193. var IDENTIFIER = 1;
  5194. var validTransformation = function(identifier) {
  5195. for (var i = 0; i < transforms.length; i++) {
  5196. var transformed = transforms[i](identifier);
  5197. if (transformed !== identifier && valid(transformed)) {
  5198. return transformed;
  5199. }
  5200. }
  5201. return null;
  5202. };
  5203. var validLastResort = function(identifier) {
  5204. var upperCased = identifier.toUpperCase();
  5205. for (var i = 0; i < lastResorts.length; i++) {
  5206. var lastResort = lastResorts[i];
  5207. if (upperCased.indexOf(lastResort[SUBSTRING]) > -1) {
  5208. return lastResort[IDENTIFIER];
  5209. }
  5210. }
  5211. return null;
  5212. };
  5213. var anyCorrection = function(identifier, check) {
  5214. for (var i = 0; i < transpositions.length; i++) {
  5215. var transposition = transpositions[i];
  5216. var transposed = transposition[TRANSPOSED];
  5217. if (identifier.indexOf(transposed) > -1) {
  5218. var corrected = identifier.replace(
  5219. transposed,
  5220. transposition[CORRECT]
  5221. );
  5222. var checked = check(corrected);
  5223. if (checked !== null) {
  5224. return checked;
  5225. }
  5226. }
  5227. }
  5228. return null;
  5229. };
  5230. var spdxCorrect = function(identifier) {
  5231. identifier = identifier.replace(/\+$/, '');
  5232. if (valid(identifier)) {
  5233. return identifier;
  5234. }
  5235. var transformed = validTransformation(identifier);
  5236. if (transformed !== null) {
  5237. return transformed;
  5238. }
  5239. transformed = anyCorrection(identifier, function(argument) {
  5240. if (valid(argument)) {
  5241. return argument;
  5242. }
  5243. return validTransformation(argument);
  5244. });
  5245. if (transformed !== null) {
  5246. return transformed;
  5247. }
  5248. transformed = validLastResort(identifier);
  5249. if (transformed !== null) {
  5250. return transformed;
  5251. }
  5252. transformed = anyCorrection(identifier, validLastResort);
  5253. if (transformed !== null) {
  5254. return transformed;
  5255. }
  5256. return null;
  5257. };
  5258. var genericWarning = (
  5259. 'license should be ' +
  5260. 'a valid SPDX license expression (without "LicenseRef"), ' +
  5261. '"UNLICENSED", or ' +
  5262. '"SEE LICENSE IN <filename>"'
  5263. );
  5264. var fileReferenceRE = /^SEE LICEN[CS]E IN (.+)$/;
  5265. function startsWith(prefix, string) {
  5266. return string.slice(0, prefix.length) === prefix;
  5267. }
  5268. function usesLicenseRef(ast) {
  5269. if (ast.hasOwnProperty('license')) {
  5270. var license = ast.license;
  5271. return (
  5272. startsWith('LicenseRef', license) ||
  5273. startsWith('DocumentRef', license)
  5274. );
  5275. } else {
  5276. return (
  5277. usesLicenseRef(ast.left) ||
  5278. usesLicenseRef(ast.right)
  5279. );
  5280. }
  5281. }
  5282. var validateNpmPackageLicense = function(argument) {
  5283. var ast;
  5284. try {
  5285. ast = spdxExpressionParse(argument);
  5286. } catch (e) {
  5287. var match;
  5288. if (
  5289. argument === 'UNLICENSED' ||
  5290. argument === 'UNLICENCED'
  5291. ) {
  5292. return {
  5293. validForOldPackages: true,
  5294. validForNewPackages: true,
  5295. unlicensed: true
  5296. };
  5297. } else if (match = fileReferenceRE.exec(argument)) {
  5298. return {
  5299. validForOldPackages: true,
  5300. validForNewPackages: true,
  5301. inFile: match[1]
  5302. };
  5303. } else {
  5304. var result = {
  5305. validForOldPackages: false,
  5306. validForNewPackages: false,
  5307. warnings: [genericWarning]
  5308. };
  5309. var corrected = spdxCorrect(argument);
  5310. if (corrected) {
  5311. result.warnings.push(
  5312. 'license is similar to the valid expression "' + corrected + '"'
  5313. );
  5314. }
  5315. return result;
  5316. }
  5317. }
  5318. if (usesLicenseRef(ast)) {
  5319. return {
  5320. validForNewPackages: false,
  5321. validForOldPackages: false,
  5322. spdx: true,
  5323. warnings: [genericWarning]
  5324. };
  5325. } else {
  5326. return {
  5327. validForNewPackages: true,
  5328. validForOldPackages: true,
  5329. spdx: true
  5330. };
  5331. }
  5332. };
  5333. var gitHostInfo = createCommonjsModule(function (module) {
  5334. 'use strict';
  5335. var gitHosts = module.exports = {
  5336. github: {
  5337. // First two are insecure and generally shouldn't be used any more, but
  5338. // they are still supported.
  5339. 'protocols': [ 'git', 'http', 'git+ssh', 'git+https', 'ssh', 'https' ],
  5340. 'domain': 'github.com',
  5341. 'treepath': 'tree',
  5342. 'filetemplate': 'https://{auth@}raw.githubusercontent.com/{user}/{project}/{committish}/{path}',
  5343. 'bugstemplate': 'https://{domain}/{user}/{project}/issues',
  5344. 'gittemplate': 'git://{auth@}{domain}/{user}/{project}.git{#committish}',
  5345. 'tarballtemplate': 'https://{domain}/{user}/{project}/archive/{committish}.tar.gz'
  5346. },
  5347. bitbucket: {
  5348. 'protocols': [ 'git+ssh', 'git+https', 'ssh', 'https' ],
  5349. 'domain': 'bitbucket.org',
  5350. 'treepath': 'src',
  5351. 'tarballtemplate': 'https://{domain}/{user}/{project}/get/{committish}.tar.gz'
  5352. },
  5353. gitlab: {
  5354. 'protocols': [ 'git+ssh', 'git+https', 'ssh', 'https' ],
  5355. 'domain': 'gitlab.com',
  5356. 'treepath': 'tree',
  5357. 'docstemplate': 'https://{domain}/{user}/{project}{/tree/committish}#README',
  5358. 'bugstemplate': 'https://{domain}/{user}/{project}/issues',
  5359. 'tarballtemplate': 'https://{domain}/{user}/{project}/repository/archive.tar.gz?ref={committish}'
  5360. },
  5361. gist: {
  5362. 'protocols': [ 'git', 'git+ssh', 'git+https', 'ssh', 'https' ],
  5363. 'domain': 'gist.github.com',
  5364. 'pathmatch': /^[/](?:([^/]+)[/])?([a-z0-9]+)(?:[.]git)?$/,
  5365. 'filetemplate': 'https://gist.githubusercontent.com/{user}/{project}/raw{/committish}/{path}',
  5366. 'bugstemplate': 'https://{domain}/{project}',
  5367. 'gittemplate': 'git://{domain}/{project}.git{#committish}',
  5368. 'sshtemplate': 'git@{domain}:/{project}.git{#committish}',
  5369. 'sshurltemplate': 'git+ssh://git@{domain}/{project}.git{#committish}',
  5370. 'browsetemplate': 'https://{domain}/{project}{/committish}',
  5371. 'docstemplate': 'https://{domain}/{project}{/committish}',
  5372. 'httpstemplate': 'git+https://{domain}/{project}.git{#committish}',
  5373. 'shortcuttemplate': '{type}:{project}{#committish}',
  5374. 'pathtemplate': '{project}{#committish}',
  5375. 'tarballtemplate': 'https://{domain}/{user}/{project}/archive/{committish}.tar.gz'
  5376. }
  5377. };
  5378. var gitHostDefaults = {
  5379. 'sshtemplate': 'git@{domain}:{user}/{project}.git{#committish}',
  5380. 'sshurltemplate': 'git+ssh://git@{domain}/{user}/{project}.git{#committish}',
  5381. 'browsetemplate': 'https://{domain}/{user}/{project}{/tree/committish}',
  5382. 'docstemplate': 'https://{domain}/{user}/{project}{/tree/committish}#readme',
  5383. 'httpstemplate': 'git+https://{auth@}{domain}/{user}/{project}.git{#committish}',
  5384. 'filetemplate': 'https://{domain}/{user}/{project}/raw/{committish}/{path}',
  5385. 'shortcuttemplate': '{type}:{user}/{project}{#committish}',
  5386. 'pathtemplate': '{user}/{project}{#committish}',
  5387. 'pathmatch': /^[/]([^/]+)[/]([^/]+?)(?:[.]git|[/])?$/
  5388. };
  5389. Object.keys(gitHosts).forEach(function (name) {
  5390. Object.keys(gitHostDefaults).forEach(function (key) {
  5391. if (gitHosts[name][key]) return
  5392. gitHosts[name][key] = gitHostDefaults[key];
  5393. });
  5394. gitHosts[name].protocols_re = RegExp('^(' +
  5395. gitHosts[name].protocols.map(function (protocol) {
  5396. return protocol.replace(/([\\+*{}()[\]$^|])/g, '\\$1')
  5397. }).join('|') + '):$');
  5398. });
  5399. });
  5400. var gitHost = createCommonjsModule(function (module) {
  5401. 'use strict';
  5402. var extend = Object.assign || util._extend;
  5403. var GitHost = module.exports = function (type, user, auth, project, committish, defaultRepresentation, opts) {
  5404. var gitHostInfo$$1 = this;
  5405. gitHostInfo$$1.type = type;
  5406. Object.keys(gitHostInfo[type]).forEach(function (key) {
  5407. gitHostInfo$$1[key] = gitHostInfo[type][key];
  5408. });
  5409. gitHostInfo$$1.user = user;
  5410. gitHostInfo$$1.auth = auth;
  5411. gitHostInfo$$1.project = project;
  5412. gitHostInfo$$1.committish = committish;
  5413. gitHostInfo$$1.default = defaultRepresentation;
  5414. gitHostInfo$$1.opts = opts || {};
  5415. };
  5416. GitHost.prototype = {};
  5417. GitHost.prototype.hash = function () {
  5418. return this.committish ? '#' + this.committish : ''
  5419. };
  5420. GitHost.prototype._fill = function (template, opts) {
  5421. if (!template) return
  5422. var vars = extend({}, opts);
  5423. opts = extend(extend({}, this.opts), opts);
  5424. var self = this;
  5425. Object.keys(this).forEach(function (key) {
  5426. if (self[key] != null && vars[key] == null) vars[key] = self[key];
  5427. });
  5428. var rawAuth = vars.auth;
  5429. var rawComittish = vars.committish;
  5430. Object.keys(vars).forEach(function (key) {
  5431. vars[key] = encodeURIComponent(vars[key]);
  5432. });
  5433. vars['auth@'] = rawAuth ? rawAuth + '@' : '';
  5434. if (opts.noCommittish) {
  5435. vars['#committish'] = '';
  5436. vars['/tree/committish'] = '';
  5437. vars['/comittish'] = '';
  5438. vars.comittish = '';
  5439. } else {
  5440. vars['#committish'] = rawComittish ? '#' + rawComittish : '';
  5441. vars['/tree/committish'] = vars.committish
  5442. ? '/' + vars.treepath + '/' + vars.committish
  5443. : '';
  5444. vars['/committish'] = vars.committish ? '/' + vars.committish : '';
  5445. vars.committish = vars.committish || 'master';
  5446. }
  5447. var res = template;
  5448. Object.keys(vars).forEach(function (key) {
  5449. res = res.replace(new RegExp('[{]' + key + '[}]', 'g'), vars[key]);
  5450. });
  5451. if (opts.noGitPlus) {
  5452. return res.replace(/^git[+]/, '')
  5453. } else {
  5454. return res
  5455. }
  5456. };
  5457. GitHost.prototype.ssh = function (opts) {
  5458. return this._fill(this.sshtemplate, opts)
  5459. };
  5460. GitHost.prototype.sshurl = function (opts) {
  5461. return this._fill(this.sshurltemplate, opts)
  5462. };
  5463. GitHost.prototype.browse = function (opts) {
  5464. return this._fill(this.browsetemplate, opts)
  5465. };
  5466. GitHost.prototype.docs = function (opts) {
  5467. return this._fill(this.docstemplate, opts)
  5468. };
  5469. GitHost.prototype.bugs = function (opts) {
  5470. return this._fill(this.bugstemplate, opts)
  5471. };
  5472. GitHost.prototype.https = function (opts) {
  5473. return this._fill(this.httpstemplate, opts)
  5474. };
  5475. GitHost.prototype.git = function (opts) {
  5476. return this._fill(this.gittemplate, opts)
  5477. };
  5478. GitHost.prototype.shortcut = function (opts) {
  5479. return this._fill(this.shortcuttemplate, opts)
  5480. };
  5481. GitHost.prototype.path = function (opts) {
  5482. return this._fill(this.pathtemplate, opts)
  5483. };
  5484. GitHost.prototype.tarball = function (opts) {
  5485. return this._fill(this.tarballtemplate, opts)
  5486. };
  5487. GitHost.prototype.file = function (P, opts) {
  5488. return this._fill(this.filetemplate, extend({
  5489. path: P.replace(/^[/]+/g, '')
  5490. }, opts))
  5491. };
  5492. GitHost.prototype.getDefaultRepresentation = function () {
  5493. return this.default
  5494. };
  5495. GitHost.prototype.toString = function (opts) {
  5496. return (this[this.default] || this.sshurl).call(this, opts)
  5497. };
  5498. });
  5499. var hostedGitInfo = createCommonjsModule(function (module) {
  5500. 'use strict';
  5501. var GitHost = module.exports = gitHost;
  5502. var protocolToRepresentationMap = {
  5503. 'git+ssh': 'sshurl',
  5504. 'git+https': 'https',
  5505. 'ssh': 'sshurl',
  5506. 'git': 'git'
  5507. };
  5508. function protocolToRepresentation (protocol) {
  5509. if (protocol.substr(-1) === ':') protocol = protocol.slice(0, -1);
  5510. return protocolToRepresentationMap[protocol] || protocol
  5511. }
  5512. var authProtocols = {
  5513. 'git:': true,
  5514. 'https:': true,
  5515. 'git+https:': true,
  5516. 'http:': true,
  5517. 'git+http:': true
  5518. };
  5519. module.exports.fromUrl = function (giturl, opts) {
  5520. if (giturl == null || giturl === '') return
  5521. var url$$1 = fixupUnqualifiedGist(
  5522. isGitHubShorthand(giturl) ? 'github:' + giturl : giturl
  5523. );
  5524. var parsed = parseGitUrl(url$$1);
  5525. var shortcutMatch = url$$1.match(new RegExp('^([^:]+):(?:(?:[^@:]+(?:[^@]+)?@)?([^/]*))[/](.+?)(?:[.]git)?($|#)'));
  5526. var matches = Object.keys(gitHostInfo).map(function (gitHostName) {
  5527. try {
  5528. var gitHostInfo$$1 = gitHostInfo[gitHostName];
  5529. var auth = null;
  5530. if (parsed.auth && authProtocols[parsed.protocol]) {
  5531. auth = decodeURIComponent(parsed.auth);
  5532. }
  5533. var committish = parsed.hash ? decodeURIComponent(parsed.hash.substr(1)) : null;
  5534. var user = null;
  5535. var project = null;
  5536. var defaultRepresentation = null;
  5537. if (shortcutMatch && shortcutMatch[1] === gitHostName) {
  5538. user = shortcutMatch[2] && decodeURIComponent(shortcutMatch[2]);
  5539. project = decodeURIComponent(shortcutMatch[3]);
  5540. defaultRepresentation = 'shortcut';
  5541. } else {
  5542. if (parsed.host !== gitHostInfo$$1.domain) return
  5543. if (!gitHostInfo$$1.protocols_re.test(parsed.protocol)) return
  5544. if (!parsed.path) return
  5545. var pathmatch = gitHostInfo$$1.pathmatch;
  5546. var matched = parsed.path.match(pathmatch);
  5547. if (!matched) return
  5548. if (matched[1] != null) user = decodeURIComponent(matched[1].replace(/^:/, ''));
  5549. if (matched[2] != null) project = decodeURIComponent(matched[2]);
  5550. defaultRepresentation = protocolToRepresentation(parsed.protocol);
  5551. }
  5552. return new GitHost(gitHostName, user, auth, project, committish, defaultRepresentation, opts)
  5553. } catch (ex) {
  5554. if (!(ex instanceof URIError)) throw ex
  5555. }
  5556. }).filter(function (gitHostInfo$$1) { return gitHostInfo$$1 });
  5557. if (matches.length !== 1) return
  5558. return matches[0]
  5559. };
  5560. function isGitHubShorthand (arg) {
  5561. // Note: This does not fully test the git ref format.
  5562. // See https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
  5563. //
  5564. // The only way to do this properly would be to shell out to
  5565. // git-check-ref-format, and as this is a fast sync function,
  5566. // we don't want to do that. Just let git fail if it turns
  5567. // out that the commit-ish is invalid.
  5568. // GH usernames cannot start with . or -
  5569. return /^[^:@%/\s.-][^:@%/\s]*[/][^:@\s/%]+(?:#.*)?$/.test(arg)
  5570. }
  5571. function fixupUnqualifiedGist (giturl) {
  5572. // necessary for round-tripping gists
  5573. var parsed = url.parse(giturl);
  5574. if (parsed.protocol === 'gist:' && parsed.host && !parsed.path) {
  5575. return parsed.protocol + '/' + parsed.host
  5576. } else {
  5577. return giturl
  5578. }
  5579. }
  5580. function parseGitUrl (giturl) {
  5581. if (typeof giturl !== 'string') giturl = '' + giturl;
  5582. var matched = giturl.match(/^([^@]+)@([^:/]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/);
  5583. if (!matched) return url.parse(giturl)
  5584. return {
  5585. protocol: 'git+ssh:',
  5586. slashes: true,
  5587. auth: matched[1],
  5588. host: matched[2],
  5589. port: null,
  5590. hostname: matched[2],
  5591. hash: matched[4],
  5592. search: null,
  5593. query: null,
  5594. pathname: '/' + matched[3],
  5595. path: '/' + matched[3],
  5596. href: 'git+ssh://' + matched[1] + '@' + matched[2] +
  5597. '/' + matched[3] + (matched[4] || '')
  5598. }
  5599. }
  5600. });
  5601. var blacklist = [
  5602. 'freelist',
  5603. 'sys'
  5604. ];
  5605. var builtinModules = Object.keys(process.binding('natives')).filter(function (el) {
  5606. return !/^_|^internal|\//.test(el) && blacklist.indexOf(el) === -1;
  5607. }).sort();
  5608. var isBuiltinModule = function (str) {
  5609. if (typeof str !== 'string') {
  5610. throw new TypeError('Expected a string');
  5611. }
  5612. return builtinModules.indexOf(str) !== -1;
  5613. };
  5614. var extract_description = extractDescription;
  5615. // Extracts description from contents of a readme file in markdown format
  5616. function extractDescription (d) {
  5617. if (!d) return;
  5618. if (d === "ERROR: No README data found!") return;
  5619. // the first block of text before the first heading
  5620. // that isn't the first line heading
  5621. d = d.trim().split('\n');
  5622. for (var s = 0; d[s] && d[s].trim().match(/^(#|$)/); s ++);
  5623. var l = d.length;
  5624. for (var e = s + 1; e < l && d[e].trim(); e ++);
  5625. return d.slice(s, e).join(' ').trim()
  5626. }
  5627. var topLevel = {"dependancies":"dependencies","dependecies":"dependencies","depdenencies":"dependencies","devEependencies":"devDependencies","depends":"dependencies","dev-dependencies":"devDependencies","devDependences":"devDependencies","devDepenencies":"devDependencies","devdependencies":"devDependencies","repostitory":"repository","repo":"repository","prefereGlobal":"preferGlobal","hompage":"homepage","hampage":"homepage","autohr":"author","autor":"author","contributers":"contributors","publicationConfig":"publishConfig","script":"scripts"};
  5628. var bugs = {"web":"url","name":"url"};
  5629. var script = {"server":"start","tests":"test"};
  5630. var typos = {
  5631. topLevel: topLevel,
  5632. bugs: bugs,
  5633. script: script
  5634. };
  5635. var typos$1 = Object.freeze({
  5636. topLevel: topLevel,
  5637. bugs: bugs,
  5638. script: script,
  5639. default: typos
  5640. });
  5641. var typos$2 = ( typos$1 && typos ) || typos$1;
  5642. var fixer_1 = createCommonjsModule(function (module) {
  5643. var depTypes = ["dependencies","devDependencies","optionalDependencies"];
  5644. var fixer = module.exports = {
  5645. // default warning function
  5646. warn: function() {},
  5647. fixRepositoryField: function(data) {
  5648. if (data.repositories) {
  5649. this.warn("repositories");
  5650. data.repository = data.repositories[0];
  5651. }
  5652. if (!data.repository) return this.warn("missingRepository")
  5653. if (typeof data.repository === "string") {
  5654. data.repository = {
  5655. type: "git",
  5656. url: data.repository
  5657. };
  5658. }
  5659. var r = data.repository.url || "";
  5660. if (r) {
  5661. var hosted = hostedGitInfo.fromUrl(r);
  5662. if (hosted) {
  5663. r = data.repository.url
  5664. = hosted.getDefaultRepresentation() == "shortcut" ? hosted.https() : hosted.toString();
  5665. }
  5666. }
  5667. if (r.match(/github.com\/[^\/]+\/[^\/]+\.git\.git$/)) {
  5668. this.warn("brokenGitUrl", r);
  5669. }
  5670. }
  5671. , fixTypos: function(data) {
  5672. Object.keys(typos$2.topLevel).forEach(function (d) {
  5673. if (data.hasOwnProperty(d)) {
  5674. this.warn("typo", d, typos$2.topLevel[d]);
  5675. }
  5676. }, this);
  5677. }
  5678. , fixScriptsField: function(data) {
  5679. if (!data.scripts) return
  5680. if (typeof data.scripts !== "object") {
  5681. this.warn("nonObjectScripts");
  5682. delete data.scripts;
  5683. return
  5684. }
  5685. Object.keys(data.scripts).forEach(function (k) {
  5686. if (typeof data.scripts[k] !== "string") {
  5687. this.warn("nonStringScript");
  5688. delete data.scripts[k];
  5689. } else if (typos$2.script[k] && !data.scripts[typos$2.script[k]]) {
  5690. this.warn("typo", k, typos$2.script[k], "scripts");
  5691. }
  5692. }, this);
  5693. }
  5694. , fixFilesField: function(data) {
  5695. var files = data.files;
  5696. if (files && !Array.isArray(files)) {
  5697. this.warn("nonArrayFiles");
  5698. delete data.files;
  5699. } else if (data.files) {
  5700. data.files = data.files.filter(function(file) {
  5701. if (!file || typeof file !== "string") {
  5702. this.warn("invalidFilename", file);
  5703. return false
  5704. } else {
  5705. return true
  5706. }
  5707. }, this);
  5708. }
  5709. }
  5710. , fixBinField: function(data) {
  5711. if (!data.bin) return;
  5712. if (typeof data.bin === "string") {
  5713. var b = {};
  5714. var match;
  5715. if (match = data.name.match(/^@[^/]+[/](.*)$/)) {
  5716. b[match[1]] = data.bin;
  5717. } else {
  5718. b[data.name] = data.bin;
  5719. }
  5720. data.bin = b;
  5721. }
  5722. }
  5723. , fixManField: function(data) {
  5724. if (!data.man) return;
  5725. if (typeof data.man === "string") {
  5726. data.man = [ data.man ];
  5727. }
  5728. }
  5729. , fixBundleDependenciesField: function(data) {
  5730. var bdd = "bundledDependencies";
  5731. var bd = "bundleDependencies";
  5732. if (data[bdd] && !data[bd]) {
  5733. data[bd] = data[bdd];
  5734. delete data[bdd];
  5735. }
  5736. if (data[bd] && !Array.isArray(data[bd])) {
  5737. this.warn("nonArrayBundleDependencies");
  5738. delete data[bd];
  5739. } else if (data[bd]) {
  5740. data[bd] = data[bd].filter(function(bd) {
  5741. if (!bd || typeof bd !== 'string') {
  5742. this.warn("nonStringBundleDependency", bd);
  5743. return false
  5744. } else {
  5745. if (!data.dependencies) {
  5746. data.dependencies = {};
  5747. }
  5748. if (!data.dependencies.hasOwnProperty(bd)) {
  5749. this.warn("nonDependencyBundleDependency", bd);
  5750. data.dependencies[bd] = "*";
  5751. }
  5752. return true
  5753. }
  5754. }, this);
  5755. }
  5756. }
  5757. , fixDependencies: function(data, strict) {
  5758. var loose = !strict;
  5759. objectifyDeps(data, this.warn);
  5760. addOptionalDepsToDeps(data, this.warn);
  5761. this.fixBundleDependenciesField(data)
  5762. ;['dependencies','devDependencies'].forEach(function(deps) {
  5763. if (!(deps in data)) return
  5764. if (!data[deps] || typeof data[deps] !== "object") {
  5765. this.warn("nonObjectDependencies", deps);
  5766. delete data[deps];
  5767. return
  5768. }
  5769. Object.keys(data[deps]).forEach(function (d) {
  5770. var r = data[deps][d];
  5771. if (typeof r !== 'string') {
  5772. this.warn("nonStringDependency", d, JSON.stringify(r));
  5773. delete data[deps][d];
  5774. }
  5775. var hosted = hostedGitInfo.fromUrl(data[deps][d]);
  5776. if (hosted) data[deps][d] = hosted.toString();
  5777. }, this);
  5778. }, this);
  5779. }
  5780. , fixModulesField: function (data) {
  5781. if (data.modules) {
  5782. this.warn("deprecatedModules");
  5783. delete data.modules;
  5784. }
  5785. }
  5786. , fixKeywordsField: function (data) {
  5787. if (typeof data.keywords === "string") {
  5788. data.keywords = data.keywords.split(/,\s+/);
  5789. }
  5790. if (data.keywords && !Array.isArray(data.keywords)) {
  5791. delete data.keywords;
  5792. this.warn("nonArrayKeywords");
  5793. } else if (data.keywords) {
  5794. data.keywords = data.keywords.filter(function(kw) {
  5795. if (typeof kw !== "string" || !kw) {
  5796. this.warn("nonStringKeyword");
  5797. return false
  5798. } else {
  5799. return true
  5800. }
  5801. }, this);
  5802. }
  5803. }
  5804. , fixVersionField: function(data, strict) {
  5805. // allow "loose" semver 1.0 versions in non-strict mode
  5806. // enforce strict semver 2.0 compliance in strict mode
  5807. var loose = !strict;
  5808. if (!data.version) {
  5809. data.version = "";
  5810. return true
  5811. }
  5812. if (!semver.valid(data.version, loose)) {
  5813. throw new Error('Invalid version: "'+ data.version + '"')
  5814. }
  5815. data.version = semver.clean(data.version, loose);
  5816. return true
  5817. }
  5818. , fixPeople: function(data) {
  5819. modifyPeople(data, unParsePerson);
  5820. modifyPeople(data, parsePerson);
  5821. }
  5822. , fixNameField: function(data, options) {
  5823. if (typeof options === "boolean") options = {strict: options};
  5824. else if (typeof options === "undefined") options = {};
  5825. var strict = options.strict;
  5826. if (!data.name && !strict) {
  5827. data.name = "";
  5828. return
  5829. }
  5830. if (typeof data.name !== "string") {
  5831. throw new Error("name field must be a string.")
  5832. }
  5833. if (!strict)
  5834. data.name = data.name.trim();
  5835. ensureValidName(data.name, strict, options.allowLegacyCase);
  5836. if (isBuiltinModule(data.name))
  5837. this.warn("conflictingName", data.name);
  5838. }
  5839. , fixDescriptionField: function (data) {
  5840. if (data.description && typeof data.description !== 'string') {
  5841. this.warn("nonStringDescription");
  5842. delete data.description;
  5843. }
  5844. if (data.readme && !data.description)
  5845. data.description = extract_description(data.readme);
  5846. if(data.description === undefined) delete data.description;
  5847. if (!data.description) this.warn("missingDescription");
  5848. }
  5849. , fixReadmeField: function (data) {
  5850. if (!data.readme) {
  5851. this.warn("missingReadme");
  5852. data.readme = "ERROR: No README data found!";
  5853. }
  5854. }
  5855. , fixBugsField: function(data) {
  5856. if (!data.bugs && data.repository && data.repository.url) {
  5857. var hosted = hostedGitInfo.fromUrl(data.repository.url);
  5858. if(hosted && hosted.bugs()) {
  5859. data.bugs = {url: hosted.bugs()};
  5860. }
  5861. }
  5862. else if(data.bugs) {
  5863. var emailRe = /^.+@.*\..+$/;
  5864. if(typeof data.bugs == "string") {
  5865. if(emailRe.test(data.bugs))
  5866. data.bugs = {email:data.bugs};
  5867. else if(url.parse(data.bugs).protocol)
  5868. data.bugs = {url: data.bugs};
  5869. else
  5870. this.warn("nonEmailUrlBugsString");
  5871. }
  5872. else {
  5873. bugsTypos(data.bugs, this.warn);
  5874. var oldBugs = data.bugs;
  5875. data.bugs = {};
  5876. if(oldBugs.url) {
  5877. if(typeof(oldBugs.url) == "string" && url.parse(oldBugs.url).protocol)
  5878. data.bugs.url = oldBugs.url;
  5879. else
  5880. this.warn("nonUrlBugsUrlField");
  5881. }
  5882. if(oldBugs.email) {
  5883. if(typeof(oldBugs.email) == "string" && emailRe.test(oldBugs.email))
  5884. data.bugs.email = oldBugs.email;
  5885. else
  5886. this.warn("nonEmailBugsEmailField");
  5887. }
  5888. }
  5889. if(!data.bugs.email && !data.bugs.url) {
  5890. delete data.bugs;
  5891. this.warn("emptyNormalizedBugs");
  5892. }
  5893. }
  5894. }
  5895. , fixHomepageField: function(data) {
  5896. if (!data.homepage && data.repository && data.repository.url) {
  5897. var hosted = hostedGitInfo.fromUrl(data.repository.url);
  5898. if (hosted && hosted.docs()) data.homepage = hosted.docs();
  5899. }
  5900. if (!data.homepage) return
  5901. if(typeof data.homepage !== "string") {
  5902. this.warn("nonUrlHomepage");
  5903. return delete data.homepage
  5904. }
  5905. if(!url.parse(data.homepage).protocol) {
  5906. this.warn("missingProtocolHomepage");
  5907. data.homepage = "http://" + data.homepage;
  5908. }
  5909. }
  5910. , fixLicenseField: function(data) {
  5911. if (!data.license) {
  5912. return this.warn("missingLicense")
  5913. } else{
  5914. if (
  5915. typeof(data.license) !== 'string' ||
  5916. data.license.length < 1
  5917. ) {
  5918. this.warn("invalidLicense");
  5919. } else {
  5920. if (!validateNpmPackageLicense(data.license).validForNewPackages)
  5921. this.warn("invalidLicense");
  5922. }
  5923. }
  5924. }
  5925. };
  5926. function isValidScopedPackageName(spec) {
  5927. if (spec.charAt(0) !== '@') return false
  5928. var rest = spec.slice(1).split('/');
  5929. if (rest.length !== 2) return false
  5930. return rest[0] && rest[1] &&
  5931. rest[0] === encodeURIComponent(rest[0]) &&
  5932. rest[1] === encodeURIComponent(rest[1])
  5933. }
  5934. function isCorrectlyEncodedName(spec) {
  5935. return !spec.match(/[\/@\s\+%:]/) &&
  5936. spec === encodeURIComponent(spec)
  5937. }
  5938. function ensureValidName (name, strict, allowLegacyCase) {
  5939. if (name.charAt(0) === "." ||
  5940. !(isValidScopedPackageName(name) || isCorrectlyEncodedName(name)) ||
  5941. (strict && (!allowLegacyCase) && name !== name.toLowerCase()) ||
  5942. name.toLowerCase() === "node_modules" ||
  5943. name.toLowerCase() === "favicon.ico") {
  5944. throw new Error("Invalid name: " + JSON.stringify(name))
  5945. }
  5946. }
  5947. function modifyPeople (data, fn) {
  5948. if (data.author) data.author = fn(data.author)
  5949. ;["maintainers", "contributors"].forEach(function (set) {
  5950. if (!Array.isArray(data[set])) return;
  5951. data[set] = data[set].map(fn);
  5952. });
  5953. return data
  5954. }
  5955. function unParsePerson (person) {
  5956. if (typeof person === "string") return person
  5957. var name = person.name || "";
  5958. var u = person.url || person.web;
  5959. var url$$1 = u ? (" ("+u+")") : "";
  5960. var e = person.email || person.mail;
  5961. var email = e ? (" <"+e+">") : "";
  5962. return name+email+url$$1
  5963. }
  5964. function parsePerson (person) {
  5965. if (typeof person !== "string") return person
  5966. var name = person.match(/^([^\(<]+)/);
  5967. var url$$1 = person.match(/\(([^\)]+)\)/);
  5968. var email = person.match(/<([^>]+)>/);
  5969. var obj = {};
  5970. if (name && name[0].trim()) obj.name = name[0].trim();
  5971. if (email) obj.email = email[1];
  5972. if (url$$1) obj.url = url$$1[1];
  5973. return obj
  5974. }
  5975. function addOptionalDepsToDeps (data, warn) {
  5976. var o = data.optionalDependencies;
  5977. if (!o) return;
  5978. var d = data.dependencies || {};
  5979. Object.keys(o).forEach(function (k) {
  5980. d[k] = o[k];
  5981. });
  5982. data.dependencies = d;
  5983. }
  5984. function depObjectify (deps, type, warn) {
  5985. if (!deps) return {}
  5986. if (typeof deps === "string") {
  5987. deps = deps.trim().split(/[\n\r\s\t ,]+/);
  5988. }
  5989. if (!Array.isArray(deps)) return deps
  5990. warn("deprecatedArrayDependencies", type);
  5991. var o = {};
  5992. deps.filter(function (d) {
  5993. return typeof d === "string"
  5994. }).forEach(function(d) {
  5995. d = d.trim().split(/(:?[@\s><=])/);
  5996. var dn = d.shift();
  5997. var dv = d.join("");
  5998. dv = dv.trim();
  5999. dv = dv.replace(/^@/, "");
  6000. o[dn] = dv;
  6001. });
  6002. return o
  6003. }
  6004. function objectifyDeps (data, warn) {
  6005. depTypes.forEach(function (type) {
  6006. if (!data[type]) return;
  6007. data[type] = depObjectify(data[type], type, warn);
  6008. });
  6009. }
  6010. function bugsTypos(bugs, warn) {
  6011. if (!bugs) return
  6012. Object.keys(bugs).forEach(function (k) {
  6013. if (typos$2.bugs[k]) {
  6014. warn("typo", k, typos$2.bugs[k], "bugs");
  6015. bugs[typos$2.bugs[k]] = bugs[k];
  6016. delete bugs[k];
  6017. }
  6018. });
  6019. }
  6020. });
  6021. var repositories = "'repositories' (plural) Not supported. Please pick one as the 'repository' field";
  6022. var missingRepository = "No repository field.";
  6023. var brokenGitUrl = "Probably broken git url: %s";
  6024. var nonObjectScripts = "scripts must be an object";
  6025. var nonStringScript = "script values must be string commands";
  6026. var nonArrayFiles = "Invalid 'files' member";
  6027. var invalidFilename = "Invalid filename in 'files' list: %s";
  6028. var nonArrayBundleDependencies = "Invalid 'bundleDependencies' list. Must be array of package names";
  6029. var nonStringBundleDependency = "Invalid bundleDependencies member: %s";
  6030. var nonDependencyBundleDependency = "Non-dependency in bundleDependencies: %s";
  6031. var nonObjectDependencies = "%s field must be an object";
  6032. var nonStringDependency = "Invalid dependency: %s %s";
  6033. var deprecatedArrayDependencies = "specifying %s as array is deprecated";
  6034. var deprecatedModules = "modules field is deprecated";
  6035. var nonArrayKeywords = "keywords should be an array of strings";
  6036. var nonStringKeyword = "keywords should be an array of strings";
  6037. var conflictingName = "%s is also the name of a node core module.";
  6038. var nonStringDescription = "'description' field should be a string";
  6039. var missingDescription = "No description";
  6040. var missingReadme = "No README data";
  6041. var missingLicense = "No license field.";
  6042. var nonEmailUrlBugsString = "Bug string field must be url, email, or {email,url}";
  6043. var nonUrlBugsUrlField = "bugs.url field must be a string url. Deleted.";
  6044. var nonEmailBugsEmailField = "bugs.email field must be a string email. Deleted.";
  6045. var emptyNormalizedBugs = "Normalized value of bugs field is an empty object. Deleted.";
  6046. var nonUrlHomepage = "homepage field must be a string url. Deleted.";
  6047. var invalidLicense = "license should be a valid SPDX license expression";
  6048. var missingProtocolHomepage = "homepage field must start with a protocol.";
  6049. var typo = "%s should probably be %s.";
  6050. var warning_messages = {
  6051. repositories: repositories,
  6052. missingRepository: missingRepository,
  6053. brokenGitUrl: brokenGitUrl,
  6054. nonObjectScripts: nonObjectScripts,
  6055. nonStringScript: nonStringScript,
  6056. nonArrayFiles: nonArrayFiles,
  6057. invalidFilename: invalidFilename,
  6058. nonArrayBundleDependencies: nonArrayBundleDependencies,
  6059. nonStringBundleDependency: nonStringBundleDependency,
  6060. nonDependencyBundleDependency: nonDependencyBundleDependency,
  6061. nonObjectDependencies: nonObjectDependencies,
  6062. nonStringDependency: nonStringDependency,
  6063. deprecatedArrayDependencies: deprecatedArrayDependencies,
  6064. deprecatedModules: deprecatedModules,
  6065. nonArrayKeywords: nonArrayKeywords,
  6066. nonStringKeyword: nonStringKeyword,
  6067. conflictingName: conflictingName,
  6068. nonStringDescription: nonStringDescription,
  6069. missingDescription: missingDescription,
  6070. missingReadme: missingReadme,
  6071. missingLicense: missingLicense,
  6072. nonEmailUrlBugsString: nonEmailUrlBugsString,
  6073. nonUrlBugsUrlField: nonUrlBugsUrlField,
  6074. nonEmailBugsEmailField: nonEmailBugsEmailField,
  6075. emptyNormalizedBugs: emptyNormalizedBugs,
  6076. nonUrlHomepage: nonUrlHomepage,
  6077. invalidLicense: invalidLicense,
  6078. missingProtocolHomepage: missingProtocolHomepage,
  6079. typo: typo
  6080. };
  6081. var warning_messages$1 = Object.freeze({
  6082. repositories: repositories,
  6083. missingRepository: missingRepository,
  6084. brokenGitUrl: brokenGitUrl,
  6085. nonObjectScripts: nonObjectScripts,
  6086. nonStringScript: nonStringScript,
  6087. nonArrayFiles: nonArrayFiles,
  6088. invalidFilename: invalidFilename,
  6089. nonArrayBundleDependencies: nonArrayBundleDependencies,
  6090. nonStringBundleDependency: nonStringBundleDependency,
  6091. nonDependencyBundleDependency: nonDependencyBundleDependency,
  6092. nonObjectDependencies: nonObjectDependencies,
  6093. nonStringDependency: nonStringDependency,
  6094. deprecatedArrayDependencies: deprecatedArrayDependencies,
  6095. deprecatedModules: deprecatedModules,
  6096. nonArrayKeywords: nonArrayKeywords,
  6097. nonStringKeyword: nonStringKeyword,
  6098. conflictingName: conflictingName,
  6099. nonStringDescription: nonStringDescription,
  6100. missingDescription: missingDescription,
  6101. missingReadme: missingReadme,
  6102. missingLicense: missingLicense,
  6103. nonEmailUrlBugsString: nonEmailUrlBugsString,
  6104. nonUrlBugsUrlField: nonUrlBugsUrlField,
  6105. nonEmailBugsEmailField: nonEmailBugsEmailField,
  6106. emptyNormalizedBugs: emptyNormalizedBugs,
  6107. nonUrlHomepage: nonUrlHomepage,
  6108. invalidLicense: invalidLicense,
  6109. missingProtocolHomepage: missingProtocolHomepage,
  6110. typo: typo,
  6111. default: warning_messages
  6112. });
  6113. var messages = ( warning_messages$1 && warning_messages ) || warning_messages$1;
  6114. var make_warning = function() {
  6115. var args = Array.prototype.slice.call(arguments, 0);
  6116. var warningName = args.shift();
  6117. if (warningName == "typo") {
  6118. return makeTypoWarning.apply(null,args)
  6119. }
  6120. else {
  6121. var msgTemplate = messages[warningName] ? messages[warningName] : warningName + ": '%s'";
  6122. args.unshift(msgTemplate);
  6123. return util.format.apply(null, args)
  6124. }
  6125. };
  6126. function makeTypoWarning (providedName, probableName, field) {
  6127. if (field) {
  6128. providedName = field + "['" + providedName + "']";
  6129. probableName = field + "['" + probableName + "']";
  6130. }
  6131. return util.format(messages.typo, providedName, probableName)
  6132. }
  6133. var normalize_1 = normalize;
  6134. normalize.fixer = fixer_1;
  6135. var fieldsToFix = ['name','version','description','repository','modules','scripts'
  6136. ,'files','bin','man','bugs','keywords','readme','homepage','license'];
  6137. var otherThingsToFix = ['dependencies','people', 'typos'];
  6138. var thingsToFix = fieldsToFix.map(function(fieldName) {
  6139. return ucFirst(fieldName) + "Field"
  6140. });
  6141. // two ways to do this in CoffeeScript on only one line, sub-70 chars:
  6142. // thingsToFix = fieldsToFix.map (name) -> ucFirst(name) + "Field"
  6143. // thingsToFix = (ucFirst(name) + "Field" for name in fieldsToFix)
  6144. thingsToFix = thingsToFix.concat(otherThingsToFix);
  6145. function normalize (data, warn, strict) {
  6146. if(warn === true) warn = null, strict = true;
  6147. if(!strict) strict = false;
  6148. if(!warn || data.private) warn = function(msg) { /* noop */ };
  6149. if (data.scripts &&
  6150. data.scripts.install === "node-gyp rebuild" &&
  6151. !data.scripts.preinstall) {
  6152. data.gypfile = true;
  6153. }
  6154. fixer_1.warn = function() { warn(make_warning.apply(null, arguments)); };
  6155. thingsToFix.forEach(function(thingName) {
  6156. fixer_1["fix" + ucFirst(thingName)](data, strict);
  6157. });
  6158. data._id = data.name + "@" + data.version;
  6159. }
  6160. function ucFirst (string) {
  6161. return string.charAt(0).toUpperCase() + string.slice(1);
  6162. }
  6163. var readPkg = createCommonjsModule(function (module) {
  6164. 'use strict';
  6165. module.exports = (fp, opts) => {
  6166. if (typeof fp !== 'string') {
  6167. opts = fp;
  6168. fp = '.';
  6169. }
  6170. opts = opts || {};
  6171. return pathType.dir(fp)
  6172. .then(isDir => {
  6173. if (isDir) {
  6174. fp = path.join(fp, 'package.json');
  6175. }
  6176. return loadJsonFile(fp);
  6177. })
  6178. .then(x => {
  6179. if (opts.normalize !== false) {
  6180. normalize_1(x);
  6181. }
  6182. return x;
  6183. });
  6184. };
  6185. module.exports.sync = (fp, opts) => {
  6186. if (typeof fp !== 'string') {
  6187. opts = fp;
  6188. fp = '.';
  6189. }
  6190. opts = opts || {};
  6191. fp = pathType.dirSync(fp) ? path.join(fp, 'package.json') : fp;
  6192. const x = loadJsonFile.sync(fp);
  6193. if (opts.normalize !== false) {
  6194. normalize_1(x);
  6195. }
  6196. return x;
  6197. };
  6198. });
  6199. var readPkgUp = createCommonjsModule(function (module) {
  6200. 'use strict';
  6201. module.exports = opts => {
  6202. return findUp('package.json', opts).then(fp => {
  6203. if (!fp) {
  6204. return {};
  6205. }
  6206. return readPkg(fp, opts).then(pkg => ({pkg, path: fp}));
  6207. });
  6208. };
  6209. module.exports.sync = opts => {
  6210. const fp = findUp.sync('package.json', opts);
  6211. if (!fp) {
  6212. return {};
  6213. }
  6214. return {
  6215. pkg: readPkg.sync(fp, opts),
  6216. path: fp
  6217. };
  6218. };
  6219. });
  6220. function concat$2(parts) {
  6221. return { type: "concat", parts };
  6222. }
  6223. function indent$2(contents) {
  6224. return { type: "indent", contents };
  6225. }
  6226. function align$1(n, contents) {
  6227. return { type: "align", contents, n };
  6228. }
  6229. function group$1(contents, opts) {
  6230. opts = opts || {};
  6231. return {
  6232. type: "group",
  6233. contents: contents,
  6234. break: !!opts.shouldBreak,
  6235. expandedStates: opts.expandedStates
  6236. };
  6237. }
  6238. function dedentToRoot(contents) {
  6239. return align$1(-Infinity, contents);
  6240. }
  6241. function markAsRoot(contents) {
  6242. return align$1({ type: "root" }, contents);
  6243. }
  6244. function dedent$1(contents) {
  6245. return align$1(-1, contents);
  6246. }
  6247. function conditionalGroup$1(states, opts) {
  6248. return group$1(
  6249. states[0],
  6250. Object.assign(opts || {}, { expandedStates: states })
  6251. );
  6252. }
  6253. function fill$1(parts) {
  6254. return { type: "fill", parts };
  6255. }
  6256. function ifBreak$1(breakContents, flatContents) {
  6257. return { type: "if-break", breakContents, flatContents };
  6258. }
  6259. function lineSuffix$1(contents) {
  6260. return { type: "line-suffix", contents };
  6261. }
  6262. const lineSuffixBoundary$1 = { type: "line-suffix-boundary" };
  6263. const breakParent$2 = { type: "break-parent" };
  6264. const line$1 = { type: "line" };
  6265. const softline$1 = { type: "line", soft: true };
  6266. const hardline$2 = concat$2([{ type: "line", hard: true }, breakParent$2]);
  6267. const literalline$1 = concat$2([
  6268. { type: "line", hard: true, literal: true },
  6269. breakParent$2
  6270. ]);
  6271. const cursor$1 = { type: "cursor", placeholder: Symbol("cursor") };
  6272. function join$2(sep, arr) {
  6273. const res = [];
  6274. for (let i = 0; i < arr.length; i++) {
  6275. if (i !== 0) {
  6276. res.push(sep);
  6277. }
  6278. res.push(arr[i]);
  6279. }
  6280. return concat$2(res);
  6281. }
  6282. function addAlignmentToDoc$1(doc, size, tabWidth) {
  6283. let aligned = doc;
  6284. if (size > 0) {
  6285. // Use indent to add tabs for all the levels of tabs we need
  6286. for (let i = 0; i < Math.floor(size / tabWidth); ++i) {
  6287. aligned = indent$2(aligned);
  6288. }
  6289. // Use align for all the spaces that are needed
  6290. aligned = align$1(size % tabWidth, aligned);
  6291. // size is absolute from 0 and not relative to the current
  6292. // indentation, so we use -Infinity to reset the indentation to 0
  6293. aligned = align$1(-Infinity, aligned);
  6294. }
  6295. return aligned;
  6296. }
  6297. var docBuilders$2 = {
  6298. concat: concat$2,
  6299. join: join$2,
  6300. line: line$1,
  6301. softline: softline$1,
  6302. hardline: hardline$2,
  6303. literalline: literalline$1,
  6304. group: group$1,
  6305. conditionalGroup: conditionalGroup$1,
  6306. fill: fill$1,
  6307. lineSuffix: lineSuffix$1,
  6308. lineSuffixBoundary: lineSuffixBoundary$1,
  6309. cursor: cursor$1,
  6310. breakParent: breakParent$2,
  6311. ifBreak: ifBreak$1,
  6312. indent: indent$2,
  6313. align: align$1,
  6314. addAlignmentToDoc: addAlignmentToDoc$1,
  6315. markAsRoot,
  6316. dedentToRoot,
  6317. dedent: dedent$1
  6318. };
  6319. const concat$3 = docBuilders$2.concat;
  6320. const fill$2 = docBuilders$2.fill;
  6321. const cursor$2 = docBuilders$2.cursor;
  6322. const MODE_BREAK = 1;
  6323. const MODE_FLAT = 2;
  6324. function rootIndent() {
  6325. return { value: "", length: 0, queue: [] };
  6326. }
  6327. function makeIndent(ind, options) {
  6328. return generateInd(ind, { type: "indent" }, options);
  6329. }
  6330. function makeAlign(ind, n, options) {
  6331. return n === -Infinity
  6332. ? ind.root || rootIndent()
  6333. : n < 0
  6334. ? generateInd(ind, { type: "dedent" }, options)
  6335. : !n
  6336. ? ind
  6337. : n.type === "root"
  6338. ? Object.assign({}, ind, { root: ind })
  6339. : typeof n === "string"
  6340. ? generateInd(ind, { type: "stringAlign", n }, options)
  6341. : generateInd(ind, { type: "numberAlign", n }, options);
  6342. }
  6343. function generateInd(ind, newPart, options) {
  6344. const queue =
  6345. newPart.type === "dedent"
  6346. ? ind.queue.slice(0, -1)
  6347. : ind.queue.concat(newPart);
  6348. let value = "";
  6349. let length = 0;
  6350. let lastTabs = 0;
  6351. let lastSpaces = 0;
  6352. for (const part of queue) {
  6353. switch (part.type) {
  6354. case "indent":
  6355. flush();
  6356. if (options.useTabs) {
  6357. addTabs(1);
  6358. } else {
  6359. addSpaces(options.tabWidth);
  6360. }
  6361. break;
  6362. case "stringAlign":
  6363. flush();
  6364. value += part.n;
  6365. length += part.n.length;
  6366. break;
  6367. case "numberAlign":
  6368. lastTabs += 1;
  6369. lastSpaces += part.n;
  6370. break;
  6371. /* istanbul ignore next */
  6372. default:
  6373. throw new Error(`Unexpected type '${part.type}'`);
  6374. }
  6375. }
  6376. flushSpaces();
  6377. return Object.assign({}, ind, { value, length, queue });
  6378. function addTabs(count) {
  6379. value += "\t".repeat(count);
  6380. length += options.tabWidth * count;
  6381. }
  6382. function addSpaces(count) {
  6383. value += " ".repeat(count);
  6384. length += count;
  6385. }
  6386. function flush() {
  6387. if (options.useTabs) {
  6388. flushTabs();
  6389. } else {
  6390. flushSpaces();
  6391. }
  6392. }
  6393. function flushTabs() {
  6394. if (lastTabs > 0) {
  6395. addTabs(lastTabs);
  6396. }
  6397. resetLast();
  6398. }
  6399. function flushSpaces() {
  6400. if (lastSpaces > 0) {
  6401. addSpaces(lastSpaces);
  6402. }
  6403. resetLast();
  6404. }
  6405. function resetLast() {
  6406. lastTabs = 0;
  6407. lastSpaces = 0;
  6408. }
  6409. }
  6410. function fits(next, restCommands, width, options, mustBeFlat) {
  6411. let restIdx = restCommands.length;
  6412. const cmds = [next];
  6413. while (width >= 0) {
  6414. if (cmds.length === 0) {
  6415. if (restIdx === 0) {
  6416. return true;
  6417. }
  6418. cmds.push(restCommands[restIdx - 1]);
  6419. restIdx--;
  6420. continue;
  6421. }
  6422. const x = cmds.pop();
  6423. const ind = x[0];
  6424. const mode = x[1];
  6425. const doc = x[2];
  6426. if (typeof doc === "string") {
  6427. width -= util$1.getStringWidth(doc);
  6428. } else {
  6429. switch (doc.type) {
  6430. case "concat":
  6431. for (let i = doc.parts.length - 1; i >= 0; i--) {
  6432. cmds.push([ind, mode, doc.parts[i]]);
  6433. }
  6434. break;
  6435. case "indent":
  6436. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  6437. break;
  6438. case "align":
  6439. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  6440. break;
  6441. case "group":
  6442. if (mustBeFlat && doc.break) {
  6443. return false;
  6444. }
  6445. cmds.push([ind, doc.break ? MODE_BREAK : mode, doc.contents]);
  6446. break;
  6447. case "fill":
  6448. for (let i = doc.parts.length - 1; i >= 0; i--) {
  6449. cmds.push([ind, mode, doc.parts[i]]);
  6450. }
  6451. break;
  6452. case "if-break":
  6453. if (mode === MODE_BREAK) {
  6454. if (doc.breakContents) {
  6455. cmds.push([ind, mode, doc.breakContents]);
  6456. }
  6457. }
  6458. if (mode === MODE_FLAT) {
  6459. if (doc.flatContents) {
  6460. cmds.push([ind, mode, doc.flatContents]);
  6461. }
  6462. }
  6463. break;
  6464. case "line":
  6465. switch (mode) {
  6466. // fallthrough
  6467. case MODE_FLAT:
  6468. if (!doc.hard) {
  6469. if (!doc.soft) {
  6470. width -= 1;
  6471. }
  6472. break;
  6473. }
  6474. return true;
  6475. case MODE_BREAK:
  6476. return true;
  6477. }
  6478. break;
  6479. }
  6480. }
  6481. }
  6482. return false;
  6483. }
  6484. function printDocToString$1(doc, options) {
  6485. const width = options.printWidth;
  6486. const newLine = options.newLine || "\n";
  6487. let pos = 0;
  6488. // cmds is basically a stack. We've turned a recursive call into a
  6489. // while loop which is much faster. The while loop below adds new
  6490. // cmds to the array instead of recursively calling `print`.
  6491. const cmds = [[rootIndent(), MODE_BREAK, doc]];
  6492. const out = [];
  6493. let shouldRemeasure = false;
  6494. let lineSuffix = [];
  6495. while (cmds.length !== 0) {
  6496. const x = cmds.pop();
  6497. const ind = x[0];
  6498. const mode = x[1];
  6499. const doc = x[2];
  6500. if (typeof doc === "string") {
  6501. out.push(doc);
  6502. pos += util$1.getStringWidth(doc);
  6503. } else {
  6504. switch (doc.type) {
  6505. case "cursor":
  6506. out.push(cursor$2.placeholder);
  6507. break;
  6508. case "concat":
  6509. for (let i = doc.parts.length - 1; i >= 0; i--) {
  6510. cmds.push([ind, mode, doc.parts[i]]);
  6511. }
  6512. break;
  6513. case "indent":
  6514. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  6515. break;
  6516. case "align":
  6517. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  6518. break;
  6519. case "group":
  6520. switch (mode) {
  6521. case MODE_FLAT:
  6522. if (!shouldRemeasure) {
  6523. cmds.push([
  6524. ind,
  6525. doc.break ? MODE_BREAK : MODE_FLAT,
  6526. doc.contents
  6527. ]);
  6528. break;
  6529. }
  6530. // fallthrough
  6531. case MODE_BREAK: {
  6532. shouldRemeasure = false;
  6533. const next = [ind, MODE_FLAT, doc.contents];
  6534. const rem = width - pos;
  6535. if (!doc.break && fits(next, cmds, rem, options)) {
  6536. cmds.push(next);
  6537. } else {
  6538. // Expanded states are a rare case where a document
  6539. // can manually provide multiple representations of
  6540. // itself. It provides an array of documents
  6541. // going from the least expanded (most flattened)
  6542. // representation first to the most expanded. If a
  6543. // group has these, we need to manually go through
  6544. // these states and find the first one that fits.
  6545. if (doc.expandedStates) {
  6546. const mostExpanded =
  6547. doc.expandedStates[doc.expandedStates.length - 1];
  6548. if (doc.break) {
  6549. cmds.push([ind, MODE_BREAK, mostExpanded]);
  6550. break;
  6551. } else {
  6552. for (let i = 1; i < doc.expandedStates.length + 1; i++) {
  6553. if (i >= doc.expandedStates.length) {
  6554. cmds.push([ind, MODE_BREAK, mostExpanded]);
  6555. break;
  6556. } else {
  6557. const state = doc.expandedStates[i];
  6558. const cmd = [ind, MODE_FLAT, state];
  6559. if (fits(cmd, cmds, rem, options)) {
  6560. cmds.push(cmd);
  6561. break;
  6562. }
  6563. }
  6564. }
  6565. }
  6566. } else {
  6567. cmds.push([ind, MODE_BREAK, doc.contents]);
  6568. }
  6569. }
  6570. break;
  6571. }
  6572. }
  6573. break;
  6574. // Fills each line with as much code as possible before moving to a new
  6575. // line with the same indentation.
  6576. //
  6577. // Expects doc.parts to be an array of alternating content and
  6578. // whitespace. The whitespace contains the linebreaks.
  6579. //
  6580. // For example:
  6581. // ["I", line, "love", line, "monkeys"]
  6582. // or
  6583. // [{ type: group, ... }, softline, { type: group, ... }]
  6584. //
  6585. // It uses this parts structure to handle three main layout cases:
  6586. // * The first two content items fit on the same line without
  6587. // breaking
  6588. // -> output the first content item and the whitespace "flat".
  6589. // * Only the first content item fits on the line without breaking
  6590. // -> output the first content item "flat" and the whitespace with
  6591. // "break".
  6592. // * Neither content item fits on the line without breaking
  6593. // -> output the first content item and the whitespace with "break".
  6594. case "fill": {
  6595. const rem = width - pos;
  6596. const parts = doc.parts;
  6597. if (parts.length === 0) {
  6598. break;
  6599. }
  6600. const content = parts[0];
  6601. const contentFlatCmd = [ind, MODE_FLAT, content];
  6602. const contentBreakCmd = [ind, MODE_BREAK, content];
  6603. const contentFits = fits(contentFlatCmd, [], rem, options, true);
  6604. if (parts.length === 1) {
  6605. if (contentFits) {
  6606. cmds.push(contentFlatCmd);
  6607. } else {
  6608. cmds.push(contentBreakCmd);
  6609. }
  6610. break;
  6611. }
  6612. const whitespace = parts[1];
  6613. const whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
  6614. const whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
  6615. if (parts.length === 2) {
  6616. if (contentFits) {
  6617. cmds.push(whitespaceFlatCmd);
  6618. cmds.push(contentFlatCmd);
  6619. } else {
  6620. cmds.push(whitespaceBreakCmd);
  6621. cmds.push(contentBreakCmd);
  6622. }
  6623. break;
  6624. }
  6625. // At this point we've handled the first pair (context, separator)
  6626. // and will create a new fill doc for the rest of the content.
  6627. // Ideally we wouldn't mutate the array here but coping all the
  6628. // elements to a new array would make this algorithm quadratic,
  6629. // which is unusable for large arrays (e.g. large texts in JSX).
  6630. parts.splice(0, 2);
  6631. const remainingCmd = [ind, mode, fill$2(parts)];
  6632. const secondContent = parts[0];
  6633. const firstAndSecondContentFlatCmd = [
  6634. ind,
  6635. MODE_FLAT,
  6636. concat$3([content, whitespace, secondContent])
  6637. ];
  6638. const firstAndSecondContentFits = fits(
  6639. firstAndSecondContentFlatCmd,
  6640. [],
  6641. rem,
  6642. options,
  6643. true
  6644. );
  6645. if (firstAndSecondContentFits) {
  6646. cmds.push(remainingCmd);
  6647. cmds.push(whitespaceFlatCmd);
  6648. cmds.push(contentFlatCmd);
  6649. } else if (contentFits) {
  6650. cmds.push(remainingCmd);
  6651. cmds.push(whitespaceBreakCmd);
  6652. cmds.push(contentFlatCmd);
  6653. } else {
  6654. cmds.push(remainingCmd);
  6655. cmds.push(whitespaceBreakCmd);
  6656. cmds.push(contentBreakCmd);
  6657. }
  6658. break;
  6659. }
  6660. case "if-break":
  6661. if (mode === MODE_BREAK) {
  6662. if (doc.breakContents) {
  6663. cmds.push([ind, mode, doc.breakContents]);
  6664. }
  6665. }
  6666. if (mode === MODE_FLAT) {
  6667. if (doc.flatContents) {
  6668. cmds.push([ind, mode, doc.flatContents]);
  6669. }
  6670. }
  6671. break;
  6672. case "line-suffix":
  6673. lineSuffix.push([ind, mode, doc.contents]);
  6674. break;
  6675. case "line-suffix-boundary":
  6676. if (lineSuffix.length > 0) {
  6677. cmds.push([ind, mode, { type: "line", hard: true }]);
  6678. }
  6679. break;
  6680. case "line":
  6681. switch (mode) {
  6682. case MODE_FLAT:
  6683. if (!doc.hard) {
  6684. if (!doc.soft) {
  6685. out.push(" ");
  6686. pos += 1;
  6687. }
  6688. break;
  6689. } else {
  6690. // This line was forced into the output even if we
  6691. // were in flattened mode, so we need to tell the next
  6692. // group that no matter what, it needs to remeasure
  6693. // because the previous measurement didn't accurately
  6694. // capture the entire expression (this is necessary
  6695. // for nested groups)
  6696. shouldRemeasure = true;
  6697. }
  6698. // fallthrough
  6699. case MODE_BREAK:
  6700. if (lineSuffix.length) {
  6701. cmds.push([ind, mode, doc]);
  6702. [].push.apply(cmds, lineSuffix.reverse());
  6703. lineSuffix = [];
  6704. break;
  6705. }
  6706. if (doc.literal) {
  6707. if (ind.root) {
  6708. out.push(newLine, ind.root.value);
  6709. pos = ind.root.length;
  6710. } else {
  6711. out.push(newLine);
  6712. pos = 0;
  6713. }
  6714. } else {
  6715. if (out.length > 0) {
  6716. // Trim whitespace at the end of line
  6717. while (
  6718. out.length > 0 &&
  6719. out[out.length - 1].match(/^[^\S\n]*$/)
  6720. ) {
  6721. out.pop();
  6722. }
  6723. if (
  6724. out.length &&
  6725. (options.parser !== "markdown" ||
  6726. // preserve markdown's `break` node (two trailing spaces)
  6727. !/\S {2}$/.test(out[out.length - 1]))
  6728. ) {
  6729. out[out.length - 1] = out[out.length - 1].replace(
  6730. /[^\S\n]*$/,
  6731. ""
  6732. );
  6733. }
  6734. }
  6735. out.push(newLine + ind.value);
  6736. pos = ind.length;
  6737. }
  6738. break;
  6739. }
  6740. break;
  6741. default:
  6742. }
  6743. }
  6744. }
  6745. const cursorPlaceholderIndex = out.indexOf(cursor$2.placeholder);
  6746. if (cursorPlaceholderIndex !== -1) {
  6747. const beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
  6748. const afterCursor = out.slice(cursorPlaceholderIndex + 1).join("");
  6749. return {
  6750. formatted: beforeCursor + afterCursor,
  6751. cursor: beforeCursor.length
  6752. };
  6753. }
  6754. return { formatted: out.join("") };
  6755. }
  6756. var docPrinter = { printDocToString: printDocToString$1 };
  6757. function flattenDoc(doc) {
  6758. if (doc.type === "concat") {
  6759. const res = [];
  6760. for (let i = 0; i < doc.parts.length; ++i) {
  6761. const doc2 = doc.parts[i];
  6762. if (typeof doc2 !== "string" && doc2.type === "concat") {
  6763. [].push.apply(res, flattenDoc(doc2).parts);
  6764. } else {
  6765. const flattened = flattenDoc(doc2);
  6766. if (flattened !== "") {
  6767. res.push(flattened);
  6768. }
  6769. }
  6770. }
  6771. return Object.assign({}, doc, { parts: res });
  6772. } else if (doc.type === "if-break") {
  6773. return Object.assign({}, doc, {
  6774. breakContents:
  6775. doc.breakContents != null ? flattenDoc(doc.breakContents) : null,
  6776. flatContents:
  6777. doc.flatContents != null ? flattenDoc(doc.flatContents) : null
  6778. });
  6779. } else if (doc.type === "group") {
  6780. return Object.assign({}, doc, {
  6781. contents: flattenDoc(doc.contents),
  6782. expandedStates: doc.expandedStates
  6783. ? doc.expandedStates.map(flattenDoc)
  6784. : doc.expandedStates
  6785. });
  6786. } else if (doc.contents) {
  6787. return Object.assign({}, doc, { contents: flattenDoc(doc.contents) });
  6788. }
  6789. return doc;
  6790. }
  6791. function printDoc(doc) {
  6792. if (typeof doc === "string") {
  6793. return JSON.stringify(doc);
  6794. }
  6795. if (doc.type === "line") {
  6796. if (doc.literalline) {
  6797. return "literalline";
  6798. }
  6799. if (doc.hard) {
  6800. return "hardline";
  6801. }
  6802. if (doc.soft) {
  6803. return "softline";
  6804. }
  6805. return "line";
  6806. }
  6807. if (doc.type === "break-parent") {
  6808. return "breakParent";
  6809. }
  6810. if (doc.type === "concat") {
  6811. return "[" + doc.parts.map(printDoc).join(", ") + "]";
  6812. }
  6813. if (doc.type === "indent") {
  6814. return "indent(" + printDoc(doc.contents) + ")";
  6815. }
  6816. if (doc.type === "align") {
  6817. return doc.n === -Infinity
  6818. ? "dedentToRoot(" + printDoc(doc.contents) + ")"
  6819. : doc.n < 0
  6820. ? "dedent(" + printDoc(doc.contents) + ")"
  6821. : doc.n.type === "root"
  6822. ? "markAsRoot(" + printDoc(doc.contents) + ")"
  6823. : "align(" +
  6824. JSON.stringify(doc.n) +
  6825. ", " +
  6826. printDoc(doc.contents) +
  6827. ")";
  6828. }
  6829. if (doc.type === "if-break") {
  6830. return (
  6831. "ifBreak(" +
  6832. printDoc(doc.breakContents) +
  6833. (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") +
  6834. ")"
  6835. );
  6836. }
  6837. if (doc.type === "group") {
  6838. if (doc.expandedStates) {
  6839. return (
  6840. "conditionalGroup(" +
  6841. "[" +
  6842. doc.expandedStates.map(printDoc).join(",") +
  6843. "])"
  6844. );
  6845. }
  6846. return (
  6847. (doc.break ? "wrappedGroup" : "group") +
  6848. "(" +
  6849. printDoc(doc.contents) +
  6850. ")"
  6851. );
  6852. }
  6853. if (doc.type === "fill") {
  6854. return "fill" + "(" + doc.parts.map(printDoc).join(", ") + ")";
  6855. }
  6856. if (doc.type === "line-suffix") {
  6857. return "lineSuffix(" + printDoc(doc.contents) + ")";
  6858. }
  6859. if (doc.type === "line-suffix-boundary") {
  6860. return "lineSuffixBoundary";
  6861. }
  6862. throw new Error("Unknown doc type " + doc.type);
  6863. }
  6864. var docDebug = {
  6865. printDocToDebug: function(doc) {
  6866. return printDoc(flattenDoc(doc));
  6867. }
  6868. };
  6869. var doc = {
  6870. builders: docBuilders$2,
  6871. printer: docPrinter,
  6872. utils: docUtils,
  6873. debug: docDebug
  6874. };
  6875. const docBuilders$1 = doc.builders;
  6876. const concat$1 = docBuilders$1.concat;
  6877. const hardline$1 = docBuilders$1.hardline;
  6878. const breakParent$1 = docBuilders$1.breakParent;
  6879. const indent$1 = docBuilders$1.indent;
  6880. const lineSuffix = docBuilders$1.lineSuffix;
  6881. const join$1 = docBuilders$1.join;
  6882. const cursor = docBuilders$1.cursor;
  6883. const childNodesCacheKey = Symbol("child-nodes");
  6884. const addLeadingComment$1 = utilShared.addLeadingComment;
  6885. const addTrailingComment$1 = utilShared.addTrailingComment;
  6886. const addDanglingComment$1 = utilShared.addDanglingComment;
  6887. function getSortedChildNodes(node, text, options, resultArray) {
  6888. if (!node) {
  6889. return;
  6890. }
  6891. const printer = options.printer;
  6892. const locStart = options.locStart;
  6893. const locEnd = options.locEnd;
  6894. if (resultArray) {
  6895. if (node && printer.canAttachComment && printer.canAttachComment(node)) {
  6896. // This reverse insertion sort almost always takes constant
  6897. // time because we almost always (maybe always?) append the
  6898. // nodes in order anyway.
  6899. let i;
  6900. for (i = resultArray.length - 1; i >= 0; --i) {
  6901. if (
  6902. locStart(resultArray[i]) <= locStart(node) &&
  6903. locEnd(resultArray[i]) <= locEnd(node)
  6904. ) {
  6905. break;
  6906. }
  6907. }
  6908. resultArray.splice(i + 1, 0, node);
  6909. return;
  6910. }
  6911. } else if (node[childNodesCacheKey]) {
  6912. return node[childNodesCacheKey];
  6913. }
  6914. let childNodes;
  6915. if (printer.getCommentChildNodes) {
  6916. childNodes = printer.getCommentChildNodes(node);
  6917. } else if (node && typeof node === "object") {
  6918. childNodes = Object.keys(node)
  6919. .filter(
  6920. n =>
  6921. n !== "enclosingNode" &&
  6922. n !== "precedingNode" &&
  6923. n !== "followingNode"
  6924. )
  6925. .map(n => node[n]);
  6926. }
  6927. if (!childNodes) {
  6928. return;
  6929. }
  6930. if (!resultArray) {
  6931. Object.defineProperty(node, childNodesCacheKey, {
  6932. value: (resultArray = []),
  6933. enumerable: false
  6934. });
  6935. }
  6936. childNodes.forEach(childNode => {
  6937. getSortedChildNodes(childNode, text, options, resultArray);
  6938. });
  6939. return resultArray;
  6940. }
  6941. // As efficiently as possible, decorate the comment object with
  6942. // .precedingNode, .enclosingNode, and/or .followingNode properties, at
  6943. // least one of which is guaranteed to be defined.
  6944. function decorateComment(node, comment, text, options) {
  6945. const locStart = options.locStart;
  6946. const locEnd = options.locEnd;
  6947. const childNodes = getSortedChildNodes(node, text, options);
  6948. let precedingNode;
  6949. let followingNode;
  6950. // Time to dust off the old binary search robes and wizard hat.
  6951. let left = 0;
  6952. let right = childNodes.length;
  6953. while (left < right) {
  6954. const middle = (left + right) >> 1;
  6955. const child = childNodes[middle];
  6956. if (
  6957. locStart(child) - locStart(comment) <= 0 &&
  6958. locEnd(comment) - locEnd(child) <= 0
  6959. ) {
  6960. // The comment is completely contained by this child node.
  6961. comment.enclosingNode = child;
  6962. decorateComment(child, comment, text, options);
  6963. return; // Abandon the binary search at this level.
  6964. }
  6965. if (locEnd(child) - locStart(comment) <= 0) {
  6966. // This child node falls completely before the comment.
  6967. // Because we will never consider this node or any nodes
  6968. // before it again, this node must be the closest preceding
  6969. // node we have encountered so far.
  6970. precedingNode = child;
  6971. left = middle + 1;
  6972. continue;
  6973. }
  6974. if (locEnd(comment) - locStart(child) <= 0) {
  6975. // This child node falls completely after the comment.
  6976. // Because we will never consider this node or any nodes after
  6977. // it again, this node must be the closest following node we
  6978. // have encountered so far.
  6979. followingNode = child;
  6980. right = middle;
  6981. continue;
  6982. }
  6983. /* istanbul ignore next */
  6984. throw new Error("Comment location overlaps with node location");
  6985. }
  6986. // We don't want comments inside of different expressions inside of the same
  6987. // template literal to move to another expression.
  6988. if (
  6989. comment.enclosingNode &&
  6990. comment.enclosingNode.type === "TemplateLiteral"
  6991. ) {
  6992. const quasis = comment.enclosingNode.quasis;
  6993. const commentIndex = findExpressionIndexForComment(
  6994. quasis,
  6995. comment,
  6996. options
  6997. );
  6998. if (
  6999. precedingNode &&
  7000. findExpressionIndexForComment(quasis, precedingNode, options) !==
  7001. commentIndex
  7002. ) {
  7003. precedingNode = null;
  7004. }
  7005. if (
  7006. followingNode &&
  7007. findExpressionIndexForComment(quasis, followingNode, options) !==
  7008. commentIndex
  7009. ) {
  7010. followingNode = null;
  7011. }
  7012. }
  7013. if (precedingNode) {
  7014. comment.precedingNode = precedingNode;
  7015. }
  7016. if (followingNode) {
  7017. comment.followingNode = followingNode;
  7018. }
  7019. }
  7020. function attach(comments, ast, text, options) {
  7021. if (!Array.isArray(comments)) {
  7022. return;
  7023. }
  7024. const tiesToBreak = [];
  7025. const locStart = options.locStart;
  7026. const locEnd = options.locEnd;
  7027. comments.forEach((comment, i) => {
  7028. if (options.parser === "json" && locStart(comment) - locStart(ast) <= 0) {
  7029. addLeadingComment$1(ast, comment);
  7030. return;
  7031. }
  7032. decorateComment(ast, comment, text, options);
  7033. const precedingNode = comment.precedingNode;
  7034. const enclosingNode = comment.enclosingNode;
  7035. const followingNode = comment.followingNode;
  7036. const pluginHandleOwnLineComment =
  7037. options.printer.handleComments && options.printer.handleComments.ownLine
  7038. ? options.printer.handleComments.ownLine
  7039. : () => false;
  7040. const pluginHandleEndOfLineComment =
  7041. options.printer.handleComments && options.printer.handleComments.endOfLine
  7042. ? options.printer.handleComments.endOfLine
  7043. : () => false;
  7044. const pluginHandleRemainingComment =
  7045. options.printer.handleComments && options.printer.handleComments.remaining
  7046. ? options.printer.handleComments.remaining
  7047. : () => false;
  7048. const isLastComment = comments.length - 1 === i;
  7049. if (util$1.hasNewline(text, locStart(comment), { backwards: true })) {
  7050. // If a comment exists on its own line, prefer a leading comment.
  7051. // We also need to check if it's the first line of the file.
  7052. if (
  7053. pluginHandleOwnLineComment(comment, text, options, ast, isLastComment)
  7054. ) {
  7055. // We're good
  7056. } else if (followingNode) {
  7057. // Always a leading comment.
  7058. addLeadingComment$1(followingNode, comment);
  7059. } else if (precedingNode) {
  7060. addTrailingComment$1(precedingNode, comment);
  7061. } else if (enclosingNode) {
  7062. addDanglingComment$1(enclosingNode, comment);
  7063. } else {
  7064. // There are no nodes, let's attach it to the root of the ast
  7065. /* istanbul ignore next */
  7066. addDanglingComment$1(ast, comment);
  7067. }
  7068. } else if (util$1.hasNewline(text, locEnd(comment))) {
  7069. if (
  7070. pluginHandleEndOfLineComment(comment, text, options, ast, isLastComment)
  7071. ) {
  7072. // We're good
  7073. } else if (precedingNode) {
  7074. // There is content before this comment on the same line, but
  7075. // none after it, so prefer a trailing comment of the previous node.
  7076. addTrailingComment$1(precedingNode, comment);
  7077. } else if (followingNode) {
  7078. addLeadingComment$1(followingNode, comment);
  7079. } else if (enclosingNode) {
  7080. addDanglingComment$1(enclosingNode, comment);
  7081. } else {
  7082. // There are no nodes, let's attach it to the root of the ast
  7083. /* istanbul ignore next */
  7084. addDanglingComment$1(ast, comment);
  7085. }
  7086. } else {
  7087. if (
  7088. pluginHandleRemainingComment(comment, text, options, ast, isLastComment)
  7089. ) {
  7090. // We're good
  7091. } else if (precedingNode && followingNode) {
  7092. // Otherwise, text exists both before and after the comment on
  7093. // the same line. If there is both a preceding and following
  7094. // node, use a tie-breaking algorithm to determine if it should
  7095. // be attached to the next or previous node. In the last case,
  7096. // simply attach the right node;
  7097. const tieCount = tiesToBreak.length;
  7098. if (tieCount > 0) {
  7099. const lastTie = tiesToBreak[tieCount - 1];
  7100. if (lastTie.followingNode !== comment.followingNode) {
  7101. breakTies(tiesToBreak, text, options);
  7102. }
  7103. }
  7104. tiesToBreak.push(comment);
  7105. } else if (precedingNode) {
  7106. addTrailingComment$1(precedingNode, comment);
  7107. } else if (followingNode) {
  7108. addLeadingComment$1(followingNode, comment);
  7109. } else if (enclosingNode) {
  7110. addDanglingComment$1(enclosingNode, comment);
  7111. } else {
  7112. // There are no nodes, let's attach it to the root of the ast
  7113. /* istanbul ignore next */
  7114. addDanglingComment$1(ast, comment);
  7115. }
  7116. }
  7117. });
  7118. breakTies(tiesToBreak, text, options);
  7119. comments.forEach(comment => {
  7120. // These node references were useful for breaking ties, but we
  7121. // don't need them anymore, and they create cycles in the AST that
  7122. // may lead to infinite recursion if we don't delete them here.
  7123. delete comment.precedingNode;
  7124. delete comment.enclosingNode;
  7125. delete comment.followingNode;
  7126. });
  7127. }
  7128. function breakTies(tiesToBreak, text, options) {
  7129. const tieCount = tiesToBreak.length;
  7130. if (tieCount === 0) {
  7131. return;
  7132. }
  7133. const precedingNode = tiesToBreak[0].precedingNode;
  7134. const followingNode = tiesToBreak[0].followingNode;
  7135. let gapEndPos = options.locStart(followingNode);
  7136. // Iterate backwards through tiesToBreak, examining the gaps
  7137. // between the tied comments. In order to qualify as leading, a
  7138. // comment must be separated from followingNode by an unbroken series of
  7139. // gaps (or other comments). Gaps should only contain whitespace or open
  7140. // parentheses.
  7141. let indexOfFirstLeadingComment;
  7142. for (
  7143. indexOfFirstLeadingComment = tieCount;
  7144. indexOfFirstLeadingComment > 0;
  7145. --indexOfFirstLeadingComment
  7146. ) {
  7147. const comment = tiesToBreak[indexOfFirstLeadingComment - 1];
  7148. assert.strictEqual(comment.precedingNode, precedingNode);
  7149. assert.strictEqual(comment.followingNode, followingNode);
  7150. const gap = text.slice(options.locEnd(comment), gapEndPos).trim();
  7151. if (gap === "" || /^\(+$/.test(gap)) {
  7152. gapEndPos = options.locStart(comment);
  7153. } else {
  7154. // The gap string contained something other than whitespace or open
  7155. // parentheses.
  7156. break;
  7157. }
  7158. }
  7159. tiesToBreak.forEach((comment, i) => {
  7160. if (i < indexOfFirstLeadingComment) {
  7161. addTrailingComment$1(precedingNode, comment);
  7162. } else {
  7163. addLeadingComment$1(followingNode, comment);
  7164. }
  7165. });
  7166. tiesToBreak.length = 0;
  7167. }
  7168. function printComment$1(commentPath, options) {
  7169. const comment = commentPath.getValue();
  7170. comment.printed = true;
  7171. return options.printer.printComment(commentPath, options);
  7172. }
  7173. function findExpressionIndexForComment(quasis, comment, options) {
  7174. const startPos = options.locStart(comment) - 1;
  7175. for (let i = 1; i < quasis.length; ++i) {
  7176. if (startPos < getQuasiRange(quasis[i]).start) {
  7177. return i - 1;
  7178. }
  7179. }
  7180. // We haven't found it, it probably means that some of the locations are off.
  7181. // Let's just return the first one.
  7182. /* istanbul ignore next */
  7183. return 0;
  7184. }
  7185. function getQuasiRange(expr) {
  7186. if (expr.start !== undefined) {
  7187. // Babylon
  7188. return { start: expr.start, end: expr.end };
  7189. }
  7190. // Flow
  7191. return { start: expr.range[0], end: expr.range[1] };
  7192. }
  7193. function printLeadingComment(commentPath, print, options) {
  7194. const comment = commentPath.getValue();
  7195. const contents = printComment$1(commentPath, options);
  7196. if (!contents) {
  7197. return "";
  7198. }
  7199. const isBlock = util$1.isBlockComment(comment);
  7200. // Leading block comments should see if they need to stay on the
  7201. // same line or not.
  7202. if (isBlock) {
  7203. return concat$1([
  7204. contents,
  7205. util$1.hasNewline(options.originalText, options.locEnd(comment))
  7206. ? hardline$1
  7207. : " "
  7208. ]);
  7209. }
  7210. return concat$1([contents, hardline$1]);
  7211. }
  7212. function printTrailingComment(commentPath, print, options) {
  7213. const comment = commentPath.getValue();
  7214. const contents = printComment$1(commentPath, options);
  7215. if (!contents) {
  7216. return "";
  7217. }
  7218. const isBlock = util$1.isBlockComment(comment);
  7219. // We don't want the line to break
  7220. // when the parentParentNode is a ClassDeclaration/-Expression
  7221. // And the parentNode is in the superClass property
  7222. const parentNode = commentPath.getNode(1);
  7223. const parentParentNode = commentPath.getNode(2);
  7224. const isParentSuperClass =
  7225. parentParentNode &&
  7226. (parentParentNode.type === "ClassDeclaration" ||
  7227. parentParentNode.type === "ClassExpression") &&
  7228. parentParentNode.superClass === parentNode;
  7229. if (
  7230. util$1.hasNewline(options.originalText, options.locStart(comment), {
  7231. backwards: true
  7232. })
  7233. ) {
  7234. // This allows comments at the end of nested structures:
  7235. // {
  7236. // x: 1,
  7237. // y: 2
  7238. // // A comment
  7239. // }
  7240. // Those kinds of comments are almost always leading comments, but
  7241. // here it doesn't go "outside" the block and turns it into a
  7242. // trailing comment for `2`. We can simulate the above by checking
  7243. // if this a comment on its own line; normal trailing comments are
  7244. // always at the end of another expression.
  7245. const isLineBeforeEmpty = util$1.isPreviousLineEmpty(
  7246. options.originalText,
  7247. comment,
  7248. options.locStart
  7249. );
  7250. return lineSuffix(
  7251. concat$1([hardline$1, isLineBeforeEmpty ? hardline$1 : "", contents])
  7252. );
  7253. } else if (isBlock || isParentSuperClass) {
  7254. // Trailing block comments never need a newline
  7255. return concat$1([" ", contents]);
  7256. }
  7257. return concat$1([lineSuffix(" " + contents), !isBlock ? breakParent$1 : ""]);
  7258. }
  7259. function printDanglingComments(path$$1, options, sameIndent, filter) {
  7260. const parts = [];
  7261. const node = path$$1.getValue();
  7262. if (!node || !node.comments) {
  7263. return "";
  7264. }
  7265. path$$1.each(commentPath => {
  7266. const comment = commentPath.getValue();
  7267. if (
  7268. comment &&
  7269. !comment.leading &&
  7270. !comment.trailing &&
  7271. (!filter || filter(comment))
  7272. ) {
  7273. parts.push(printComment$1(commentPath, options));
  7274. }
  7275. }, "comments");
  7276. if (parts.length === 0) {
  7277. return "";
  7278. }
  7279. if (sameIndent) {
  7280. return join$1(hardline$1, parts);
  7281. }
  7282. return indent$1(concat$1([hardline$1, join$1(hardline$1, parts)]));
  7283. }
  7284. function prependCursorPlaceholder(path$$1, options, printed) {
  7285. if (path$$1.getNode() === options.cursorNode && path$$1.getValue()) {
  7286. return concat$1([cursor, printed]);
  7287. }
  7288. return printed;
  7289. }
  7290. function printComments(path$$1, print, options, needsSemi) {
  7291. const value = path$$1.getValue();
  7292. const printed = print(path$$1);
  7293. const comments = value && value.comments;
  7294. if (!comments || comments.length === 0) {
  7295. return prependCursorPlaceholder(path$$1, options, printed);
  7296. }
  7297. const leadingParts = [];
  7298. const trailingParts = [needsSemi ? ";" : "", printed];
  7299. path$$1.each(commentPath => {
  7300. const comment = commentPath.getValue();
  7301. const leading = comment.leading;
  7302. const trailing = comment.trailing;
  7303. if (leading) {
  7304. const contents = printLeadingComment(commentPath, print, options);
  7305. if (!contents) {
  7306. return;
  7307. }
  7308. leadingParts.push(contents);
  7309. const text = options.originalText;
  7310. if (
  7311. util$1.hasNewline(
  7312. text,
  7313. util$1.skipNewline(text, options.locEnd(comment))
  7314. )
  7315. ) {
  7316. leadingParts.push(hardline$1);
  7317. }
  7318. } else if (trailing) {
  7319. trailingParts.push(printTrailingComment(commentPath, print, options));
  7320. }
  7321. }, "comments");
  7322. return prependCursorPlaceholder(
  7323. path$$1,
  7324. options,
  7325. concat$1(leadingParts.concat(trailingParts))
  7326. );
  7327. }
  7328. var comments = {
  7329. attach,
  7330. printComments,
  7331. printDanglingComments,
  7332. getSortedChildNodes
  7333. };
  7334. var ast = createCommonjsModule(function (module) {
  7335. /*
  7336. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7337. Redistribution and use in source and binary forms, with or without
  7338. modification, are permitted provided that the following conditions are met:
  7339. * Redistributions of source code must retain the above copyright
  7340. notice, this list of conditions and the following disclaimer.
  7341. * Redistributions in binary form must reproduce the above copyright
  7342. notice, this list of conditions and the following disclaimer in the
  7343. documentation and/or other materials provided with the distribution.
  7344. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
  7345. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7346. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7347. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7348. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7349. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7350. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7351. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7352. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7353. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7354. */
  7355. (function () {
  7356. 'use strict';
  7357. function isExpression(node) {
  7358. if (node == null) { return false; }
  7359. switch (node.type) {
  7360. case 'ArrayExpression':
  7361. case 'AssignmentExpression':
  7362. case 'BinaryExpression':
  7363. case 'CallExpression':
  7364. case 'ConditionalExpression':
  7365. case 'FunctionExpression':
  7366. case 'Identifier':
  7367. case 'Literal':
  7368. case 'LogicalExpression':
  7369. case 'MemberExpression':
  7370. case 'NewExpression':
  7371. case 'ObjectExpression':
  7372. case 'SequenceExpression':
  7373. case 'ThisExpression':
  7374. case 'UnaryExpression':
  7375. case 'UpdateExpression':
  7376. return true;
  7377. }
  7378. return false;
  7379. }
  7380. function isIterationStatement(node) {
  7381. if (node == null) { return false; }
  7382. switch (node.type) {
  7383. case 'DoWhileStatement':
  7384. case 'ForInStatement':
  7385. case 'ForStatement':
  7386. case 'WhileStatement':
  7387. return true;
  7388. }
  7389. return false;
  7390. }
  7391. function isStatement(node) {
  7392. if (node == null) { return false; }
  7393. switch (node.type) {
  7394. case 'BlockStatement':
  7395. case 'BreakStatement':
  7396. case 'ContinueStatement':
  7397. case 'DebuggerStatement':
  7398. case 'DoWhileStatement':
  7399. case 'EmptyStatement':
  7400. case 'ExpressionStatement':
  7401. case 'ForInStatement':
  7402. case 'ForStatement':
  7403. case 'IfStatement':
  7404. case 'LabeledStatement':
  7405. case 'ReturnStatement':
  7406. case 'SwitchStatement':
  7407. case 'ThrowStatement':
  7408. case 'TryStatement':
  7409. case 'VariableDeclaration':
  7410. case 'WhileStatement':
  7411. case 'WithStatement':
  7412. return true;
  7413. }
  7414. return false;
  7415. }
  7416. function isSourceElement(node) {
  7417. return isStatement(node) || node != null && node.type === 'FunctionDeclaration';
  7418. }
  7419. function trailingStatement(node) {
  7420. switch (node.type) {
  7421. case 'IfStatement':
  7422. if (node.alternate != null) {
  7423. return node.alternate;
  7424. }
  7425. return node.consequent;
  7426. case 'LabeledStatement':
  7427. case 'ForStatement':
  7428. case 'ForInStatement':
  7429. case 'WhileStatement':
  7430. case 'WithStatement':
  7431. return node.body;
  7432. }
  7433. return null;
  7434. }
  7435. function isProblematicIfStatement(node) {
  7436. var current;
  7437. if (node.type !== 'IfStatement') {
  7438. return false;
  7439. }
  7440. if (node.alternate == null) {
  7441. return false;
  7442. }
  7443. current = node.consequent;
  7444. do {
  7445. if (current.type === 'IfStatement') {
  7446. if (current.alternate == null) {
  7447. return true;
  7448. }
  7449. }
  7450. current = trailingStatement(current);
  7451. } while (current);
  7452. return false;
  7453. }
  7454. module.exports = {
  7455. isExpression: isExpression,
  7456. isStatement: isStatement,
  7457. isIterationStatement: isIterationStatement,
  7458. isSourceElement: isSourceElement,
  7459. isProblematicIfStatement: isProblematicIfStatement,
  7460. trailingStatement: trailingStatement
  7461. };
  7462. }());
  7463. /* vim: set sw=4 ts=4 et tw=80 : */
  7464. });
  7465. var code = createCommonjsModule(function (module) {
  7466. /*
  7467. Copyright (C) 2013-2014 Yusuke Suzuki <utatane.tea@gmail.com>
  7468. Copyright (C) 2014 Ivan Nikulin <ifaaan@gmail.com>
  7469. Redistribution and use in source and binary forms, with or without
  7470. modification, are permitted provided that the following conditions are met:
  7471. * Redistributions of source code must retain the above copyright
  7472. notice, this list of conditions and the following disclaimer.
  7473. * Redistributions in binary form must reproduce the above copyright
  7474. notice, this list of conditions and the following disclaimer in the
  7475. documentation and/or other materials provided with the distribution.
  7476. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7477. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7478. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7479. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7480. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7481. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7482. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7483. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7484. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7485. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7486. */
  7487. (function () {
  7488. 'use strict';
  7489. var ES6Regex, ES5Regex, NON_ASCII_WHITESPACES, IDENTIFIER_START, IDENTIFIER_PART, ch;
  7490. // See `tools/generate-identifier-regex.js`.
  7491. ES5Regex = {
  7492. // ECMAScript 5.1/Unicode v7.0.0 NonAsciiIdentifierStart:
  7493. 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]/,
  7494. // ECMAScript 5.1/Unicode v7.0.0 NonAsciiIdentifierPart:
  7495. 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]/
  7496. };
  7497. ES6Regex = {
  7498. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierStart:
  7499. 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]/,
  7500. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierPart:
  7501. 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]/
  7502. };
  7503. function isDecimalDigit(ch) {
  7504. return 0x30 <= ch && ch <= 0x39; // 0..9
  7505. }
  7506. function isHexDigit(ch) {
  7507. return 0x30 <= ch && ch <= 0x39 || // 0..9
  7508. 0x61 <= ch && ch <= 0x66 || // a..f
  7509. 0x41 <= ch && ch <= 0x46; // A..F
  7510. }
  7511. function isOctalDigit(ch) {
  7512. return ch >= 0x30 && ch <= 0x37; // 0..7
  7513. }
  7514. // 7.2 White Space
  7515. NON_ASCII_WHITESPACES = [
  7516. 0x1680, 0x180E,
  7517. 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A,
  7518. 0x202F, 0x205F,
  7519. 0x3000,
  7520. 0xFEFF
  7521. ];
  7522. function isWhiteSpace(ch) {
  7523. return ch === 0x20 || ch === 0x09 || ch === 0x0B || ch === 0x0C || ch === 0xA0 ||
  7524. ch >= 0x1680 && NON_ASCII_WHITESPACES.indexOf(ch) >= 0;
  7525. }
  7526. // 7.3 Line Terminators
  7527. function isLineTerminator(ch) {
  7528. return ch === 0x0A || ch === 0x0D || ch === 0x2028 || ch === 0x2029;
  7529. }
  7530. // 7.6 Identifier Names and Identifiers
  7531. function fromCodePoint(cp) {
  7532. if (cp <= 0xFFFF) { return String.fromCharCode(cp); }
  7533. var cu1 = String.fromCharCode(Math.floor((cp - 0x10000) / 0x400) + 0xD800);
  7534. var cu2 = String.fromCharCode(((cp - 0x10000) % 0x400) + 0xDC00);
  7535. return cu1 + cu2;
  7536. }
  7537. IDENTIFIER_START = new Array(0x80);
  7538. for(ch = 0; ch < 0x80; ++ch) {
  7539. IDENTIFIER_START[ch] =
  7540. ch >= 0x61 && ch <= 0x7A || // a..z
  7541. ch >= 0x41 && ch <= 0x5A || // A..Z
  7542. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  7543. }
  7544. IDENTIFIER_PART = new Array(0x80);
  7545. for(ch = 0; ch < 0x80; ++ch) {
  7546. IDENTIFIER_PART[ch] =
  7547. ch >= 0x61 && ch <= 0x7A || // a..z
  7548. ch >= 0x41 && ch <= 0x5A || // A..Z
  7549. ch >= 0x30 && ch <= 0x39 || // 0..9
  7550. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  7551. }
  7552. function isIdentifierStartES5(ch) {
  7553. return ch < 0x80 ? IDENTIFIER_START[ch] : ES5Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  7554. }
  7555. function isIdentifierPartES5(ch) {
  7556. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES5Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  7557. }
  7558. function isIdentifierStartES6(ch) {
  7559. return ch < 0x80 ? IDENTIFIER_START[ch] : ES6Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  7560. }
  7561. function isIdentifierPartES6(ch) {
  7562. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES6Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  7563. }
  7564. module.exports = {
  7565. isDecimalDigit: isDecimalDigit,
  7566. isHexDigit: isHexDigit,
  7567. isOctalDigit: isOctalDigit,
  7568. isWhiteSpace: isWhiteSpace,
  7569. isLineTerminator: isLineTerminator,
  7570. isIdentifierStartES5: isIdentifierStartES5,
  7571. isIdentifierPartES5: isIdentifierPartES5,
  7572. isIdentifierStartES6: isIdentifierStartES6,
  7573. isIdentifierPartES6: isIdentifierPartES6
  7574. };
  7575. }());
  7576. /* vim: set sw=4 ts=4 et tw=80 : */
  7577. });
  7578. var keyword = createCommonjsModule(function (module) {
  7579. /*
  7580. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7581. Redistribution and use in source and binary forms, with or without
  7582. modification, are permitted provided that the following conditions are met:
  7583. * Redistributions of source code must retain the above copyright
  7584. notice, this list of conditions and the following disclaimer.
  7585. * Redistributions in binary form must reproduce the above copyright
  7586. notice, this list of conditions and the following disclaimer in the
  7587. documentation and/or other materials provided with the distribution.
  7588. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7589. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7590. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7591. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7592. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7593. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7594. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7595. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7596. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7597. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7598. */
  7599. (function () {
  7600. 'use strict';
  7601. var code$$1 = code;
  7602. function isStrictModeReservedWordES6(id) {
  7603. switch (id) {
  7604. case 'implements':
  7605. case 'interface':
  7606. case 'package':
  7607. case 'private':
  7608. case 'protected':
  7609. case 'public':
  7610. case 'static':
  7611. case 'let':
  7612. return true;
  7613. default:
  7614. return false;
  7615. }
  7616. }
  7617. function isKeywordES5(id, strict) {
  7618. // yield should not be treated as keyword under non-strict mode.
  7619. if (!strict && id === 'yield') {
  7620. return false;
  7621. }
  7622. return isKeywordES6(id, strict);
  7623. }
  7624. function isKeywordES6(id, strict) {
  7625. if (strict && isStrictModeReservedWordES6(id)) {
  7626. return true;
  7627. }
  7628. switch (id.length) {
  7629. case 2:
  7630. return (id === 'if') || (id === 'in') || (id === 'do');
  7631. case 3:
  7632. return (id === 'var') || (id === 'for') || (id === 'new') || (id === 'try');
  7633. case 4:
  7634. return (id === 'this') || (id === 'else') || (id === 'case') ||
  7635. (id === 'void') || (id === 'with') || (id === 'enum');
  7636. case 5:
  7637. return (id === 'while') || (id === 'break') || (id === 'catch') ||
  7638. (id === 'throw') || (id === 'const') || (id === 'yield') ||
  7639. (id === 'class') || (id === 'super');
  7640. case 6:
  7641. return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
  7642. (id === 'switch') || (id === 'export') || (id === 'import');
  7643. case 7:
  7644. return (id === 'default') || (id === 'finally') || (id === 'extends');
  7645. case 8:
  7646. return (id === 'function') || (id === 'continue') || (id === 'debugger');
  7647. case 10:
  7648. return (id === 'instanceof');
  7649. default:
  7650. return false;
  7651. }
  7652. }
  7653. function isReservedWordES5(id, strict) {
  7654. return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);
  7655. }
  7656. function isReservedWordES6(id, strict) {
  7657. return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);
  7658. }
  7659. function isRestrictedWord(id) {
  7660. return id === 'eval' || id === 'arguments';
  7661. }
  7662. function isIdentifierNameES5(id) {
  7663. var i, iz, ch;
  7664. if (id.length === 0) { return false; }
  7665. ch = id.charCodeAt(0);
  7666. if (!code$$1.isIdentifierStartES5(ch)) {
  7667. return false;
  7668. }
  7669. for (i = 1, iz = id.length; i < iz; ++i) {
  7670. ch = id.charCodeAt(i);
  7671. if (!code$$1.isIdentifierPartES5(ch)) {
  7672. return false;
  7673. }
  7674. }
  7675. return true;
  7676. }
  7677. function decodeUtf16(lead, trail) {
  7678. return (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  7679. }
  7680. function isIdentifierNameES6(id) {
  7681. var i, iz, ch, lowCh, check;
  7682. if (id.length === 0) { return false; }
  7683. check = code$$1.isIdentifierStartES6;
  7684. for (i = 0, iz = id.length; i < iz; ++i) {
  7685. ch = id.charCodeAt(i);
  7686. if (0xD800 <= ch && ch <= 0xDBFF) {
  7687. ++i;
  7688. if (i >= iz) { return false; }
  7689. lowCh = id.charCodeAt(i);
  7690. if (!(0xDC00 <= lowCh && lowCh <= 0xDFFF)) {
  7691. return false;
  7692. }
  7693. ch = decodeUtf16(ch, lowCh);
  7694. }
  7695. if (!check(ch)) {
  7696. return false;
  7697. }
  7698. check = code$$1.isIdentifierPartES6;
  7699. }
  7700. return true;
  7701. }
  7702. function isIdentifierES5(id, strict) {
  7703. return isIdentifierNameES5(id) && !isReservedWordES5(id, strict);
  7704. }
  7705. function isIdentifierES6(id, strict) {
  7706. return isIdentifierNameES6(id) && !isReservedWordES6(id, strict);
  7707. }
  7708. module.exports = {
  7709. isKeywordES5: isKeywordES5,
  7710. isKeywordES6: isKeywordES6,
  7711. isReservedWordES5: isReservedWordES5,
  7712. isReservedWordES6: isReservedWordES6,
  7713. isRestrictedWord: isRestrictedWord,
  7714. isIdentifierNameES5: isIdentifierNameES5,
  7715. isIdentifierNameES6: isIdentifierNameES6,
  7716. isIdentifierES5: isIdentifierES5,
  7717. isIdentifierES6: isIdentifierES6
  7718. };
  7719. }());
  7720. /* vim: set sw=4 ts=4 et tw=80 : */
  7721. });
  7722. var utils$2 = createCommonjsModule(function (module, exports) {
  7723. /*
  7724. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7725. Redistribution and use in source and binary forms, with or without
  7726. modification, are permitted provided that the following conditions are met:
  7727. * Redistributions of source code must retain the above copyright
  7728. notice, this list of conditions and the following disclaimer.
  7729. * Redistributions in binary form must reproduce the above copyright
  7730. notice, this list of conditions and the following disclaimer in the
  7731. documentation and/or other materials provided with the distribution.
  7732. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7733. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7734. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7735. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7736. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7737. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7738. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7739. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7740. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7741. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7742. */
  7743. (function () {
  7744. 'use strict';
  7745. exports.ast = ast;
  7746. exports.code = code;
  7747. exports.keyword = keyword;
  7748. }());
  7749. /* vim: set sw=4 ts=4 et tw=80 : */
  7750. });
  7751. const doc$2 = doc;
  7752. const docUtils$4 = doc$2.utils;
  7753. const docBuilders$5 = doc$2.builders;
  7754. const indent$3 = docBuilders$5.indent;
  7755. const join$3 = docBuilders$5.join;
  7756. const hardline$3 = docBuilders$5.hardline;
  7757. const softline$2 = docBuilders$5.softline;
  7758. const literalline$2 = docBuilders$5.literalline;
  7759. const concat$4 = docBuilders$5.concat;
  7760. const dedentToRoot$1 = docBuilders$5.dedentToRoot;
  7761. function embed(path$$1, print, textToDoc /*, options */) {
  7762. const node = path$$1.getValue();
  7763. const parent = path$$1.getParentNode();
  7764. const parentParent = path$$1.getParentNode(1);
  7765. switch (node.type) {
  7766. case "TemplateLiteral": {
  7767. const isCss = [isStyledJsx, isStyledComponents, isCssProp].some(isIt =>
  7768. isIt(path$$1)
  7769. );
  7770. if (isCss) {
  7771. // Get full template literal with expressions replaced by placeholders
  7772. const rawQuasis = node.quasis.map(q => q.value.raw);
  7773. let placeholderID = 0;
  7774. const text = rawQuasis.reduce((prevVal, currVal, idx) => {
  7775. return idx == 0
  7776. ? currVal
  7777. : prevVal +
  7778. "@prettier-placeholder-" +
  7779. placeholderID++ +
  7780. "-id" +
  7781. currVal;
  7782. }, "");
  7783. const doc$$2 = textToDoc(text, { parser: "css" });
  7784. return transformCssDoc(doc$$2, path$$1, print);
  7785. }
  7786. /*
  7787. * react-relay and graphql-tag
  7788. * graphql`...`
  7789. * graphql.experimental`...`
  7790. * gql`...`
  7791. *
  7792. * This intentionally excludes Relay Classic tags, as Prettier does not
  7793. * support Relay Classic formatting.
  7794. */
  7795. if (
  7796. parent &&
  7797. ((parent.type === "TaggedTemplateExpression" &&
  7798. ((parent.tag.type === "MemberExpression" &&
  7799. parent.tag.object.name === "graphql" &&
  7800. parent.tag.property.name === "experimental") ||
  7801. (parent.tag.type === "Identifier" &&
  7802. (parent.tag.name === "gql" || parent.tag.name === "graphql")))) ||
  7803. (parent.type === "CallExpression" &&
  7804. parent.callee.type === "Identifier" &&
  7805. parent.callee.name === "graphql"))
  7806. ) {
  7807. const expressionDocs = node.expressions
  7808. ? path$$1.map(print, "expressions")
  7809. : [];
  7810. const numQuasis = node.quasis.length;
  7811. if (numQuasis === 1 && node.quasis[0].value.raw.trim() === "") {
  7812. return "``";
  7813. }
  7814. const parts = [];
  7815. for (let i = 0; i < numQuasis; i++) {
  7816. const templateElement = node.quasis[i];
  7817. const isFirst = i === 0;
  7818. const isLast = i === numQuasis - 1;
  7819. const text = templateElement.value.cooked;
  7820. // Bail out if any of the quasis have an invalid escape sequence
  7821. // (which would make the `cooked` value be `null` or `undefined`)
  7822. if (typeof text !== "string") {
  7823. return null;
  7824. }
  7825. const lines = text.split("\n");
  7826. const numLines = lines.length;
  7827. const expressionDoc = expressionDocs[i];
  7828. const startsWithBlankLine =
  7829. numLines > 2 && lines[0].trim() === "" && lines[1].trim() === "";
  7830. const endsWithBlankLine =
  7831. numLines > 2 &&
  7832. lines[numLines - 1].trim() === "" &&
  7833. lines[numLines - 2].trim() === "";
  7834. const commentsAndWhitespaceOnly = lines.every(line =>
  7835. /^\s*(?:#[^\r\n]*)?$/.test(line)
  7836. );
  7837. // Bail out if an interpolation occurs within a comment.
  7838. if (!isLast && /#[^\r\n]*$/.test(lines[numLines - 1])) {
  7839. return null;
  7840. }
  7841. let doc$$2 = null;
  7842. if (commentsAndWhitespaceOnly) {
  7843. doc$$2 = printGraphqlComments(lines);
  7844. } else {
  7845. try {
  7846. doc$$2 = docUtils$4.stripTrailingHardline(
  7847. textToDoc(text, { parser: "graphql" })
  7848. );
  7849. } catch (error) {
  7850. if (process.env.PRETTIER_DEBUG) {
  7851. throw error;
  7852. }
  7853. // Bail if any part fails to parse.
  7854. return null;
  7855. }
  7856. }
  7857. if (doc$$2) {
  7858. doc$$2 = escapeBackticks(doc$$2);
  7859. if (!isFirst && startsWithBlankLine) {
  7860. parts.push("");
  7861. }
  7862. parts.push(doc$$2);
  7863. if (!isLast && endsWithBlankLine) {
  7864. parts.push("");
  7865. }
  7866. } else if (!isFirst && !isLast && startsWithBlankLine) {
  7867. parts.push("");
  7868. }
  7869. if (expressionDoc) {
  7870. parts.push(concat$4(["${", expressionDoc, "}"]));
  7871. }
  7872. }
  7873. return concat$4([
  7874. "`",
  7875. indent$3(concat$4([hardline$3, join$3(hardline$3, parts)])),
  7876. hardline$3,
  7877. "`"
  7878. ]);
  7879. }
  7880. break;
  7881. }
  7882. case "TemplateElement": {
  7883. /**
  7884. * md`...`
  7885. * markdown`...`
  7886. */
  7887. if (
  7888. parentParent &&
  7889. (parentParent.type === "TaggedTemplateExpression" &&
  7890. parent.quasis.length === 1 &&
  7891. (parentParent.tag.type === "Identifier" &&
  7892. (parentParent.tag.name === "md" ||
  7893. parentParent.tag.name === "markdown")))
  7894. ) {
  7895. const text = parent.quasis[0].value.cooked;
  7896. const indentation = getIndentation(text);
  7897. const hasIndent = indentation !== "";
  7898. return concat$4([
  7899. hasIndent
  7900. ? indent$3(
  7901. concat$4([
  7902. softline$2,
  7903. printMarkdown(
  7904. text.replace(new RegExp(`^${indentation}`, "gm"), "")
  7905. )
  7906. ])
  7907. )
  7908. : concat$4([literalline$2, dedentToRoot$1(printMarkdown(text))]),
  7909. softline$2
  7910. ]);
  7911. }
  7912. break;
  7913. }
  7914. }
  7915. function printMarkdown(text) {
  7916. const doc$$2 = textToDoc(text, { parser: "markdown", __inJsTemplate: true });
  7917. return docUtils$4.stripTrailingHardline(escapeBackticks(doc$$2));
  7918. }
  7919. }
  7920. function getIndentation(str) {
  7921. const firstMatchedIndent = str.match(/^([^\S\n]*)\S/m);
  7922. return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
  7923. }
  7924. function escapeBackticks(doc$$2) {
  7925. return docUtils$4.mapDoc(doc$$2, currentDoc => {
  7926. if (!currentDoc.parts) {
  7927. return currentDoc;
  7928. }
  7929. const parts = [];
  7930. currentDoc.parts.forEach(part => {
  7931. if (typeof part === "string") {
  7932. parts.push(part.replace(/`/g, "\\`"));
  7933. } else {
  7934. parts.push(part);
  7935. }
  7936. });
  7937. return Object.assign({}, currentDoc, { parts });
  7938. });
  7939. }
  7940. function transformCssDoc(quasisDoc, path$$1, print) {
  7941. const parentNode = path$$1.getValue();
  7942. const isEmpty =
  7943. parentNode.quasis.length === 1 && !parentNode.quasis[0].value.raw.trim();
  7944. if (isEmpty) {
  7945. return "``";
  7946. }
  7947. const expressionDocs = parentNode.expressions
  7948. ? path$$1.map(print, "expressions")
  7949. : [];
  7950. const newDoc = replacePlaceholders(quasisDoc, expressionDocs);
  7951. /* istanbul ignore if */
  7952. if (!newDoc) {
  7953. throw new Error("Couldn't insert all the expressions");
  7954. }
  7955. return concat$4([
  7956. "`",
  7957. indent$3(concat$4([hardline$3, docUtils$4.stripTrailingHardline(newDoc)])),
  7958. softline$2,
  7959. "`"
  7960. ]);
  7961. }
  7962. // Search all the placeholders in the quasisDoc tree
  7963. // and replace them with the expression docs one by one
  7964. // returns a new doc with all the placeholders replaced,
  7965. // or null if it couldn't replace any expression
  7966. function replacePlaceholders(quasisDoc, expressionDocs) {
  7967. if (!expressionDocs || !expressionDocs.length) {
  7968. return quasisDoc;
  7969. }
  7970. const expressions = expressionDocs.slice();
  7971. let replaceCounter = 0;
  7972. const newDoc = docUtils$4.mapDoc(quasisDoc, doc$$2 => {
  7973. if (!doc$$2 || !doc$$2.parts || !doc$$2.parts.length) {
  7974. return doc$$2;
  7975. }
  7976. let parts = doc$$2.parts;
  7977. const atIndex = parts.indexOf("@");
  7978. const placeholderIndex = atIndex + 1;
  7979. if (
  7980. atIndex > -1 &&
  7981. typeof parts[placeholderIndex] === "string" &&
  7982. parts[placeholderIndex].startsWith("prettier-placeholder")
  7983. ) {
  7984. // If placeholder is split, join it
  7985. const at = parts[atIndex];
  7986. const placeholder = parts[placeholderIndex];
  7987. const rest = parts.slice(placeholderIndex + 1);
  7988. parts = parts
  7989. .slice(0, atIndex)
  7990. .concat([at + placeholder])
  7991. .concat(rest);
  7992. }
  7993. const atPlaceholderIndex = parts.findIndex(
  7994. part =>
  7995. typeof part === "string" && part.startsWith("@prettier-placeholder")
  7996. );
  7997. if (atPlaceholderIndex > -1) {
  7998. const placeholder = parts[atPlaceholderIndex];
  7999. const rest = parts.slice(atPlaceholderIndex + 1);
  8000. const placeholderMatch = placeholder.match(
  8001. /@prettier-placeholder-(.+)-id([\s\S]*)/
  8002. );
  8003. const placeholderID = placeholderMatch[1];
  8004. // When the expression has a suffix appended, like:
  8005. // animation: linear ${time}s ease-out;
  8006. const suffix = placeholderMatch[2];
  8007. const expression = expressions[placeholderID];
  8008. replaceCounter++;
  8009. parts = parts
  8010. .slice(0, atPlaceholderIndex)
  8011. .concat(["${", expression, "}" + suffix])
  8012. .concat(rest);
  8013. }
  8014. return Object.assign({}, doc$$2, {
  8015. parts: parts
  8016. });
  8017. });
  8018. return expressions.length === replaceCounter ? newDoc : null;
  8019. }
  8020. function printGraphqlComments(lines) {
  8021. const parts = [];
  8022. let seenComment = false;
  8023. lines.map(textLine => textLine.trim()).forEach((textLine, i, array) => {
  8024. // Lines are either whitespace only, or a comment (with poential whitespace
  8025. // around it). Drop whitespace-only lines.
  8026. if (textLine === "") {
  8027. return;
  8028. }
  8029. if (array[i - 1] === "" && seenComment) {
  8030. // If a non-first comment is preceded by a blank (whitespace only) line,
  8031. // add in a blank line.
  8032. parts.push(concat$4([hardline$3, textLine]));
  8033. } else {
  8034. parts.push(textLine);
  8035. }
  8036. seenComment = true;
  8037. });
  8038. // If `lines` was whitespace only, return `null`.
  8039. return parts.length === 0 ? null : join$3(hardline$3, parts);
  8040. }
  8041. /**
  8042. * Template literal in this context:
  8043. * <style jsx>{`div{color:red}`}</style>
  8044. */
  8045. function isStyledJsx(path$$1) {
  8046. const node = path$$1.getValue();
  8047. const parent = path$$1.getParentNode();
  8048. const parentParent = path$$1.getParentNode(1);
  8049. return (
  8050. parentParent &&
  8051. node.quasis &&
  8052. parent.type === "JSXExpressionContainer" &&
  8053. parentParent.type === "JSXElement" &&
  8054. parentParent.openingElement.name.name === "style" &&
  8055. parentParent.openingElement.attributes.some(
  8056. attribute => attribute.name.name === "jsx"
  8057. )
  8058. );
  8059. }
  8060. /**
  8061. * styled-components template literals
  8062. */
  8063. function isStyledComponents(path$$1) {
  8064. const parent = path$$1.getParentNode();
  8065. if (!parent || parent.type !== "TaggedTemplateExpression") {
  8066. return false;
  8067. }
  8068. const tag = parent.tag;
  8069. switch (tag.type) {
  8070. case "MemberExpression":
  8071. return (
  8072. // styled.foo``
  8073. isStyledIdentifier(tag.object) ||
  8074. // Component.extend``
  8075. (/^[A-Z]/.test(tag.object.name) && tag.property.name === "extend")
  8076. );
  8077. case "CallExpression":
  8078. return (
  8079. // styled(Component)``
  8080. isStyledIdentifier(tag.callee) ||
  8081. (tag.callee.type === "MemberExpression" &&
  8082. // styled.foo.attr({})``
  8083. ((tag.callee.object.type === "MemberExpression" &&
  8084. isStyledIdentifier(tag.callee.object.object)) ||
  8085. // styled(Component).attr({})``
  8086. (tag.callee.object.type === "CallExpression" &&
  8087. isStyledIdentifier(tag.callee.object.callee))))
  8088. );
  8089. case "Identifier":
  8090. // css``
  8091. return tag.name === "css";
  8092. default:
  8093. return false;
  8094. }
  8095. }
  8096. /**
  8097. * JSX element with CSS prop
  8098. */
  8099. function isCssProp(path$$1) {
  8100. const parent = path$$1.getParentNode();
  8101. const parentParent = path$$1.getParentNode(1);
  8102. return (
  8103. parentParent &&
  8104. parent.type === "JSXExpressionContainer" &&
  8105. parentParent.type === "JSXAttribute" &&
  8106. parentParent.name.type === "JSXIdentifier" &&
  8107. parentParent.name.name === "css"
  8108. );
  8109. }
  8110. function isStyledIdentifier(node) {
  8111. return node.type === "Identifier" && node.name === "styled";
  8112. }
  8113. var embed_1 = embed;
  8114. function clean(ast, newObj, parent) {
  8115. // We remove extra `;` and add them when needed
  8116. if (ast.type === "EmptyStatement") {
  8117. return null;
  8118. }
  8119. // We move text around, including whitespaces and add {" "}
  8120. if (ast.type === "JSXText") {
  8121. return null;
  8122. }
  8123. if (
  8124. ast.type === "JSXExpressionContainer" &&
  8125. ast.expression.type === "Literal" &&
  8126. ast.expression.value === " "
  8127. ) {
  8128. return null;
  8129. }
  8130. // (TypeScript) Ignore `static` in `constructor(static p) {}`
  8131. // and `export` in `constructor(export p) {}`
  8132. if (
  8133. ast.type === "TSParameterProperty" &&
  8134. ast.accessibility === null &&
  8135. !ast.readonly
  8136. ) {
  8137. return {
  8138. type: "Identifier",
  8139. name: ast.parameter.name,
  8140. typeAnnotation: newObj.parameter.typeAnnotation,
  8141. decorators: newObj.decorators
  8142. };
  8143. }
  8144. // (TypeScript) ignore empty `specifiers` array
  8145. if (
  8146. ast.type === "TSNamespaceExportDeclaration" &&
  8147. ast.specifiers &&
  8148. ast.specifiers.length === 0
  8149. ) {
  8150. delete newObj.specifiers;
  8151. }
  8152. // (TypeScript) bypass TSParenthesizedType
  8153. if (
  8154. ast.type === "TSParenthesizedType" &&
  8155. ast.typeAnnotation.type === "TSTypeAnnotation"
  8156. ) {
  8157. return newObj.typeAnnotation.typeAnnotation;
  8158. }
  8159. // We convert <div></div> to <div />
  8160. if (ast.type === "JSXOpeningElement") {
  8161. delete newObj.selfClosing;
  8162. }
  8163. if (ast.type === "JSXElement") {
  8164. delete newObj.closingElement;
  8165. }
  8166. // We change {'key': value} into {key: value}
  8167. if (
  8168. (ast.type === "Property" ||
  8169. ast.type === "MethodDefinition" ||
  8170. ast.type === "ClassProperty" ||
  8171. ast.type === "TSPropertySignature" ||
  8172. ast.type === "ObjectTypeProperty") &&
  8173. typeof ast.key === "object" &&
  8174. ast.key &&
  8175. (ast.key.type === "Literal" || ast.key.type === "Identifier")
  8176. ) {
  8177. delete newObj.key;
  8178. }
  8179. // Remove raw and cooked values from TemplateElement when it's CSS
  8180. // styled-jsx
  8181. if (
  8182. ast.type === "JSXElement" &&
  8183. ast.openingElement.name.name === "style" &&
  8184. ast.openingElement.attributes.some(attr => attr.name.name === "jsx")
  8185. ) {
  8186. const templateLiterals = newObj.children
  8187. .filter(
  8188. child =>
  8189. child.type === "JSXExpressionContainer" &&
  8190. child.expression.type === "TemplateLiteral"
  8191. )
  8192. .map(container => container.expression);
  8193. const quasis = templateLiterals.reduce(
  8194. (quasis, templateLiteral) => quasis.concat(templateLiteral.quasis),
  8195. []
  8196. );
  8197. quasis.forEach(q => delete q.value);
  8198. }
  8199. // CSS template literals in css prop
  8200. if (
  8201. ast.type === "JSXAttribute" &&
  8202. ast.name.name === "css" &&
  8203. ast.value.type === "JSXExpressionContainer" &&
  8204. ast.value.expression.type === "TemplateLiteral"
  8205. ) {
  8206. newObj.value.expression.quasis.forEach(q => delete q.value);
  8207. }
  8208. // styled-components, graphql, markdown
  8209. if (
  8210. ast.type === "TaggedTemplateExpression" &&
  8211. (ast.tag.type === "MemberExpression" ||
  8212. (ast.tag.type === "Identifier" &&
  8213. (ast.tag.name === "gql" ||
  8214. ast.tag.name === "graphql" ||
  8215. ast.tag.name === "css" ||
  8216. ast.tag.name === "md" ||
  8217. ast.tag.name === "markdown")) ||
  8218. ast.tag.type === "CallExpression")
  8219. ) {
  8220. newObj.quasi.quasis.forEach(quasi => delete quasi.value);
  8221. }
  8222. if (
  8223. ast.type === "TemplateLiteral" &&
  8224. parent.type === "CallExpression" &&
  8225. parent.callee.name === "graphql"
  8226. ) {
  8227. newObj.quasis.forEach(quasi => delete quasi.value);
  8228. }
  8229. }
  8230. var clean_1 = clean;
  8231. var detectNewline = createCommonjsModule(function (module) {
  8232. 'use strict';
  8233. module.exports = function (str) {
  8234. if (typeof str !== 'string') {
  8235. throw new TypeError('Expected a string');
  8236. }
  8237. var newlines = (str.match(/(?:\r?\n)/g) || []);
  8238. if (newlines.length === 0) {
  8239. return null;
  8240. }
  8241. var crlf = newlines.filter(function (el) {
  8242. return el === '\r\n';
  8243. }).length;
  8244. var lf = newlines.length - crlf;
  8245. return crlf > lf ? '\r\n' : '\n';
  8246. };
  8247. module.exports.graceful = function (str) {
  8248. return module.exports(str) || '\n';
  8249. };
  8250. });
  8251. var build = createCommonjsModule(function (module, exports) {
  8252. 'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.
  8253. extract = extract;exports.
  8254. strip = strip;exports.
  8255. parse = parse;exports.
  8256. parseWithComments = parseWithComments;exports.
  8257. print = print;var _detectNewline;function _load_detectNewline() {return _detectNewline = _interopRequireDefault(detectNewline);}var _os;function _load_os() {return _os = os;}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /**
  8258. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  8259. *
  8260. * This source code is licensed under the MIT license found in the
  8261. * LICENSE file in the root directory of this source tree.
  8262. *
  8263. *
  8264. */const commentEndRe = /\*\/$/;const commentStartRe = /^\/\*\*/;const docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;const lineCommentRe = /(^|\s+)\/\/([^\r\n]*)/g;const ltrimRe = /^\s*/;const rtrimRe = /\s*$/;const ltrimNewlineRe = /^(\r?\n)+/;const multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *(?![^@\r\n]*\/\/[^]*)([^@\r\n\s][^@\r\n]+?) *\r?\n/g;const propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;const stringStartRe = /(\r?\n|^) *\* ?/g;function extract(contents) {const match = contents.match(docblockRe);return match ? match[0].replace(ltrimRe, '') || '' : '';}function strip(contents) {const match = contents.match(docblockRe);return match && match[0] ? contents.substring(match[0].length) : contents;}function parse(docblock) {return parseWithComments(docblock).pragmas;}function parseWithComments(docblock) {const line = (0, (_detectNewline || _load_detectNewline()).default)(docblock) || (_os || _load_os()).EOL;docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replace(stringStartRe, '$1'); // Normalize multi-line directives
  8265. let prev = '';while (prev !== docblock) {prev = docblock;docblock = docblock.replace(multilineRe, `${line}$1 $2${line}`);}docblock = docblock.replace(ltrimNewlineRe, '').replace(rtrimRe, '');const result = Object.create(null);const comments = docblock.replace(propertyRe, '').replace(ltrimNewlineRe, '').replace(rtrimRe, '');let match;while (match = propertyRe.exec(docblock)) {// strip linecomments from pragmas
  8266. const nextPragma = match[2].replace(lineCommentRe, '');if (typeof result[match[1]] === 'string' || Array.isArray(result[match[1]])) {result[match[1]] = [].concat(result[match[1]], nextPragma);} else {result[match[1]] = nextPragma;}}return { comments, pragmas: result };}function print(_ref) {var _ref$comments = _ref.comments;let comments = _ref$comments === undefined ? '' : _ref$comments;var _ref$pragmas = _ref.pragmas;let pragmas = _ref$pragmas === undefined ? {} : _ref$pragmas;const line = (0, (_detectNewline || _load_detectNewline()).default)(comments) || (_os || _load_os()).EOL;const head = '/**';
  8267. const start = ' *';
  8268. const tail = ' */';
  8269. const keys = Object.keys(pragmas);
  8270. const printedObject = keys.
  8271. map(key => printKeyValues(key, pragmas[key])).
  8272. reduce((arr, next) => arr.concat(next), []).
  8273. map(keyValue => start + ' ' + keyValue + line).
  8274. join('');
  8275. if (!comments) {
  8276. if (keys.length === 0) {
  8277. return '';
  8278. }
  8279. if (keys.length === 1 && !Array.isArray(pragmas[keys[0]])) {
  8280. const value = pragmas[keys[0]];
  8281. return `${head} ${printKeyValues(keys[0], value)[0]}${tail}`;
  8282. }
  8283. }
  8284. const printedComments =
  8285. comments.
  8286. split(line).
  8287. map(textLine => `${start} ${textLine}`).
  8288. join(line) + line;
  8289. return (
  8290. head +
  8291. line + (
  8292. comments ? printedComments : '') + (
  8293. comments && keys.length ? start + line : '') +
  8294. printedObject +
  8295. tail);
  8296. }
  8297. function printKeyValues(key, valueOrArray) {
  8298. return [].concat(valueOrArray).map(value => `@${key} ${value}`.trim());
  8299. }
  8300. });
  8301. unwrapExports(build);
  8302. function hasPragma$1(text) {
  8303. const pragmas = Object.keys(build.parse(build.extract(text)));
  8304. return pragmas.indexOf("prettier") !== -1 || pragmas.indexOf("format") !== -1;
  8305. }
  8306. function insertPragma$1(text) {
  8307. const parsedDocblock = build.parseWithComments(build.extract(text));
  8308. const pragmas = Object.assign({ format: "" }, parsedDocblock.pragmas);
  8309. const newDocblock = build.print({
  8310. pragmas,
  8311. comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, "") // remove leading newlines
  8312. });
  8313. const strippedText = build.strip(text);
  8314. const separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n";
  8315. return newDocblock + separatingNewlines + strippedText;
  8316. }
  8317. var pragma = {
  8318. hasPragma: hasPragma$1,
  8319. insertPragma: insertPragma$1
  8320. };
  8321. const addLeadingComment$2 = utilShared.addLeadingComment;
  8322. const addTrailingComment$2 = utilShared.addTrailingComment;
  8323. const addDanglingComment$2 = utilShared.addDanglingComment;
  8324. function handleOwnLineComment(comment, text, options, ast, isLastComment) {
  8325. const precedingNode = comment.precedingNode;
  8326. const enclosingNode = comment.enclosingNode;
  8327. const followingNode = comment.followingNode;
  8328. if (
  8329. handleLastFunctionArgComments(
  8330. text,
  8331. precedingNode,
  8332. enclosingNode,
  8333. followingNode,
  8334. comment,
  8335. options
  8336. ) ||
  8337. handleMemberExpressionComments(enclosingNode, followingNode, comment) ||
  8338. handleIfStatementComments(
  8339. text,
  8340. precedingNode,
  8341. enclosingNode,
  8342. followingNode,
  8343. comment,
  8344. options
  8345. ) ||
  8346. handleTryStatementComments(enclosingNode, followingNode, comment) ||
  8347. handleClassComments(enclosingNode, precedingNode, followingNode, comment) ||
  8348. handleImportSpecifierComments(enclosingNode, comment) ||
  8349. handleForComments(enclosingNode, precedingNode, comment) ||
  8350. handleUnionTypeComments(
  8351. precedingNode,
  8352. enclosingNode,
  8353. followingNode,
  8354. comment
  8355. ) ||
  8356. handleOnlyComments(enclosingNode, ast, comment, isLastComment) ||
  8357. handleImportDeclarationComments(
  8358. text,
  8359. enclosingNode,
  8360. precedingNode,
  8361. comment,
  8362. options
  8363. ) ||
  8364. handleAssignmentPatternComments(enclosingNode, comment) ||
  8365. handleMethodNameComments(
  8366. text,
  8367. enclosingNode,
  8368. precedingNode,
  8369. comment,
  8370. options
  8371. )
  8372. ) {
  8373. return true;
  8374. }
  8375. return false;
  8376. }
  8377. function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
  8378. const precedingNode = comment.precedingNode;
  8379. const enclosingNode = comment.enclosingNode;
  8380. const followingNode = comment.followingNode;
  8381. if (
  8382. handleLastFunctionArgComments(
  8383. text,
  8384. precedingNode,
  8385. enclosingNode,
  8386. followingNode,
  8387. comment,
  8388. options
  8389. ) ||
  8390. handleConditionalExpressionComments(
  8391. enclosingNode,
  8392. precedingNode,
  8393. followingNode,
  8394. comment,
  8395. text,
  8396. options
  8397. ) ||
  8398. handleImportSpecifierComments(enclosingNode, comment) ||
  8399. handleIfStatementComments(
  8400. text,
  8401. precedingNode,
  8402. enclosingNode,
  8403. followingNode,
  8404. comment,
  8405. options
  8406. ) ||
  8407. handleClassComments(enclosingNode, precedingNode, followingNode, comment) ||
  8408. handleLabeledStatementComments(enclosingNode, comment) ||
  8409. handleCallExpressionComments(precedingNode, enclosingNode, comment) ||
  8410. handlePropertyComments(enclosingNode, comment) ||
  8411. handleOnlyComments(enclosingNode, ast, comment, isLastComment) ||
  8412. handleTypeAliasComments(enclosingNode, followingNode, comment) ||
  8413. handleVariableDeclaratorComments(enclosingNode, followingNode, comment)
  8414. ) {
  8415. return true;
  8416. }
  8417. return false;
  8418. }
  8419. function handleRemainingComment(comment, text, options, ast, isLastComment) {
  8420. const precedingNode = comment.precedingNode;
  8421. const enclosingNode = comment.enclosingNode;
  8422. const followingNode = comment.followingNode;
  8423. if (
  8424. handleIfStatementComments(
  8425. text,
  8426. precedingNode,
  8427. enclosingNode,
  8428. followingNode,
  8429. comment,
  8430. options
  8431. ) ||
  8432. handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) ||
  8433. handleCommentInEmptyParens(text, enclosingNode, comment, options) ||
  8434. handleMethodNameComments(
  8435. text,
  8436. enclosingNode,
  8437. precedingNode,
  8438. comment,
  8439. options
  8440. ) ||
  8441. handleOnlyComments(enclosingNode, ast, comment, isLastComment) ||
  8442. handleCommentAfterArrowParams(text, enclosingNode, comment, options) ||
  8443. handleFunctionNameComments(
  8444. text,
  8445. enclosingNode,
  8446. precedingNode,
  8447. comment,
  8448. options
  8449. ) ||
  8450. handleBreakAndContinueStatementComments(enclosingNode, comment)
  8451. ) {
  8452. return true;
  8453. }
  8454. return false;
  8455. }
  8456. function addBlockStatementFirstComment(node, comment) {
  8457. const body = node.body.filter(n => n.type !== "EmptyStatement");
  8458. if (body.length === 0) {
  8459. addDanglingComment$2(node, comment);
  8460. } else {
  8461. addLeadingComment$2(body[0], comment);
  8462. }
  8463. }
  8464. function addBlockOrNotComment(node, comment) {
  8465. if (node.type === "BlockStatement") {
  8466. addBlockStatementFirstComment(node, comment);
  8467. } else {
  8468. addLeadingComment$2(node, comment);
  8469. }
  8470. }
  8471. // There are often comments before the else clause of if statements like
  8472. //
  8473. // if (1) { ... }
  8474. // // comment
  8475. // else { ... }
  8476. //
  8477. // They are being attached as leading comments of the BlockExpression which
  8478. // is not well printed. What we want is to instead move the comment inside
  8479. // of the block and make it leadingComment of the first element of the block
  8480. // or dangling comment of the block if there is nothing inside
  8481. //
  8482. // if (1) { ... }
  8483. // else {
  8484. // // comment
  8485. // ...
  8486. // }
  8487. function handleIfStatementComments(
  8488. text,
  8489. precedingNode,
  8490. enclosingNode,
  8491. followingNode,
  8492. comment,
  8493. options
  8494. ) {
  8495. if (
  8496. !enclosingNode ||
  8497. enclosingNode.type !== "IfStatement" ||
  8498. !followingNode
  8499. ) {
  8500. return false;
  8501. }
  8502. // We unfortunately have no way using the AST or location of nodes to know
  8503. // if the comment is positioned before the condition parenthesis:
  8504. // if (a /* comment */) {}
  8505. // The only workaround I found is to look at the next character to see if
  8506. // it is a ).
  8507. const nextCharacter = util$1.getNextNonSpaceNonCommentCharacter(
  8508. text,
  8509. comment,
  8510. options.locEnd
  8511. );
  8512. if (nextCharacter === ")") {
  8513. addTrailingComment$2(precedingNode, comment);
  8514. return true;
  8515. }
  8516. // Comments before `else`:
  8517. // - treat as trailing comments of the consequent, if it's a BlockStatement
  8518. // - treat as a dangling comment otherwise
  8519. if (
  8520. precedingNode === enclosingNode.consequent &&
  8521. followingNode === enclosingNode.alternate
  8522. ) {
  8523. if (precedingNode.type === "BlockStatement") {
  8524. addTrailingComment$2(precedingNode, comment);
  8525. } else {
  8526. addDanglingComment$2(enclosingNode, comment);
  8527. }
  8528. return true;
  8529. }
  8530. if (followingNode.type === "BlockStatement") {
  8531. addBlockStatementFirstComment(followingNode, comment);
  8532. return true;
  8533. }
  8534. if (followingNode.type === "IfStatement") {
  8535. addBlockOrNotComment(followingNode.consequent, comment);
  8536. return true;
  8537. }
  8538. // For comments positioned after the condition parenthesis in an if statement
  8539. // before the consequent with or without brackets on, such as
  8540. // if (a) /* comment */ {} or if (a) /* comment */ true,
  8541. // we look at the next character to see if it is a { or if the following node
  8542. // is the consequent for the if statement
  8543. if (nextCharacter === "{" || enclosingNode.consequent === followingNode) {
  8544. addLeadingComment$2(followingNode, comment);
  8545. return true;
  8546. }
  8547. return false;
  8548. }
  8549. // Same as IfStatement but for TryStatement
  8550. function handleTryStatementComments(enclosingNode, followingNode, comment) {
  8551. if (
  8552. !enclosingNode ||
  8553. enclosingNode.type !== "TryStatement" ||
  8554. !followingNode
  8555. ) {
  8556. return false;
  8557. }
  8558. if (followingNode.type === "BlockStatement") {
  8559. addBlockStatementFirstComment(followingNode, comment);
  8560. return true;
  8561. }
  8562. if (followingNode.type === "TryStatement") {
  8563. addBlockOrNotComment(followingNode.finalizer, comment);
  8564. return true;
  8565. }
  8566. if (followingNode.type === "CatchClause") {
  8567. addBlockOrNotComment(followingNode.body, comment);
  8568. return true;
  8569. }
  8570. return false;
  8571. }
  8572. function handleMemberExpressionComments(enclosingNode, followingNode, comment) {
  8573. if (
  8574. enclosingNode &&
  8575. enclosingNode.type === "MemberExpression" &&
  8576. followingNode &&
  8577. followingNode.type === "Identifier"
  8578. ) {
  8579. addLeadingComment$2(enclosingNode, comment);
  8580. return true;
  8581. }
  8582. return false;
  8583. }
  8584. function handleConditionalExpressionComments(
  8585. enclosingNode,
  8586. precedingNode,
  8587. followingNode,
  8588. comment,
  8589. text,
  8590. options
  8591. ) {
  8592. const isSameLineAsPrecedingNode =
  8593. precedingNode &&
  8594. !util$1.hasNewlineInRange(
  8595. text,
  8596. options.locEnd(precedingNode),
  8597. options.locStart(comment)
  8598. );
  8599. if (
  8600. (!precedingNode || !isSameLineAsPrecedingNode) &&
  8601. enclosingNode &&
  8602. enclosingNode.type === "ConditionalExpression" &&
  8603. followingNode
  8604. ) {
  8605. addLeadingComment$2(followingNode, comment);
  8606. return true;
  8607. }
  8608. return false;
  8609. }
  8610. function handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) {
  8611. if (
  8612. enclosingNode &&
  8613. (enclosingNode.type === "ObjectProperty" ||
  8614. enclosingNode.type === "Property") &&
  8615. enclosingNode.shorthand &&
  8616. enclosingNode.key === precedingNode &&
  8617. enclosingNode.value.type === "AssignmentPattern"
  8618. ) {
  8619. addTrailingComment$2(enclosingNode.value.left, comment);
  8620. return true;
  8621. }
  8622. return false;
  8623. }
  8624. function handleClassComments(
  8625. enclosingNode,
  8626. precedingNode,
  8627. followingNode,
  8628. comment
  8629. ) {
  8630. if (
  8631. enclosingNode &&
  8632. (enclosingNode.type === "ClassDeclaration" ||
  8633. enclosingNode.type === "ClassExpression") &&
  8634. (enclosingNode.decorators && enclosingNode.decorators.length > 0) &&
  8635. !(followingNode && followingNode.type === "Decorator")
  8636. ) {
  8637. if (!enclosingNode.decorators || enclosingNode.decorators.length === 0) {
  8638. addLeadingComment$2(enclosingNode, comment);
  8639. } else {
  8640. addTrailingComment$2(
  8641. enclosingNode.decorators[enclosingNode.decorators.length - 1],
  8642. comment
  8643. );
  8644. }
  8645. return true;
  8646. }
  8647. return false;
  8648. }
  8649. function handleMethodNameComments(
  8650. text,
  8651. enclosingNode,
  8652. precedingNode,
  8653. comment,
  8654. options
  8655. ) {
  8656. // This is only needed for estree parsers (flow, typescript) to attach
  8657. // after a method name:
  8658. // obj = { fn /*comment*/() {} };
  8659. if (
  8660. enclosingNode &&
  8661. precedingNode &&
  8662. (enclosingNode.type === "Property" ||
  8663. enclosingNode.type === "MethodDefinition") &&
  8664. precedingNode.type === "Identifier" &&
  8665. enclosingNode.key === precedingNode &&
  8666. // special Property case: { key: /*comment*/(value) };
  8667. // comment should be attached to value instead of key
  8668. util$1.getNextNonSpaceNonCommentCharacter(
  8669. text,
  8670. precedingNode,
  8671. options.locEnd
  8672. ) !== ":"
  8673. ) {
  8674. addTrailingComment$2(precedingNode, comment);
  8675. return true;
  8676. }
  8677. // Print comments between decorators and class methods as a trailing comment
  8678. // on the decorator node instead of the method node
  8679. if (
  8680. precedingNode &&
  8681. enclosingNode &&
  8682. precedingNode.type === "Decorator" &&
  8683. (enclosingNode.type === "ClassMethod" ||
  8684. enclosingNode.type === "ClassProperty" ||
  8685. enclosingNode.type === "TSAbstractClassProperty" ||
  8686. enclosingNode.type === "TSAbstractMethodDefinition" ||
  8687. enclosingNode.type === "MethodDefinition")
  8688. ) {
  8689. addTrailingComment$2(precedingNode, comment);
  8690. return true;
  8691. }
  8692. return false;
  8693. }
  8694. function handleFunctionNameComments(
  8695. text,
  8696. enclosingNode,
  8697. precedingNode,
  8698. comment,
  8699. options
  8700. ) {
  8701. if (
  8702. util$1.getNextNonSpaceNonCommentCharacter(
  8703. text,
  8704. comment,
  8705. options.locEnd
  8706. ) !== "("
  8707. ) {
  8708. return false;
  8709. }
  8710. if (
  8711. precedingNode &&
  8712. enclosingNode &&
  8713. (enclosingNode.type === "FunctionDeclaration" ||
  8714. enclosingNode.type === "FunctionExpression" ||
  8715. enclosingNode.type === "ClassMethod" ||
  8716. enclosingNode.type === "MethodDefinition" ||
  8717. enclosingNode.type === "ObjectMethod")
  8718. ) {
  8719. addTrailingComment$2(precedingNode, comment);
  8720. return true;
  8721. }
  8722. return false;
  8723. }
  8724. function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
  8725. if (!(enclosingNode && enclosingNode.type === "ArrowFunctionExpression")) {
  8726. return false;
  8727. }
  8728. const index = utilShared.getNextNonSpaceNonCommentCharacterIndex(
  8729. text,
  8730. comment,
  8731. options
  8732. );
  8733. if (text.substr(index, 2) === "=>") {
  8734. addDanglingComment$2(enclosingNode, comment);
  8735. return true;
  8736. }
  8737. return false;
  8738. }
  8739. function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
  8740. if (
  8741. util$1.getNextNonSpaceNonCommentCharacter(
  8742. text,
  8743. comment,
  8744. options.locEnd
  8745. ) !== ")"
  8746. ) {
  8747. return false;
  8748. }
  8749. // Only add dangling comments to fix the case when no params are present,
  8750. // i.e. a function without any argument.
  8751. if (
  8752. enclosingNode &&
  8753. (((enclosingNode.type === "FunctionDeclaration" ||
  8754. enclosingNode.type === "FunctionExpression" ||
  8755. (enclosingNode.type === "ArrowFunctionExpression" &&
  8756. (enclosingNode.body.type !== "CallExpression" ||
  8757. enclosingNode.body.arguments.length === 0)) ||
  8758. enclosingNode.type === "ClassMethod" ||
  8759. enclosingNode.type === "ObjectMethod") &&
  8760. enclosingNode.params.length === 0) ||
  8761. (enclosingNode.type === "CallExpression" &&
  8762. enclosingNode.arguments.length === 0))
  8763. ) {
  8764. addDanglingComment$2(enclosingNode, comment);
  8765. return true;
  8766. }
  8767. if (
  8768. enclosingNode &&
  8769. (enclosingNode.type === "MethodDefinition" &&
  8770. enclosingNode.value.params.length === 0)
  8771. ) {
  8772. addDanglingComment$2(enclosingNode.value, comment);
  8773. return true;
  8774. }
  8775. return false;
  8776. }
  8777. function handleLastFunctionArgComments(
  8778. text,
  8779. precedingNode,
  8780. enclosingNode,
  8781. followingNode,
  8782. comment,
  8783. options
  8784. ) {
  8785. // Type definitions functions
  8786. if (
  8787. precedingNode &&
  8788. precedingNode.type === "FunctionTypeParam" &&
  8789. enclosingNode &&
  8790. enclosingNode.type === "FunctionTypeAnnotation" &&
  8791. followingNode &&
  8792. followingNode.type !== "FunctionTypeParam"
  8793. ) {
  8794. addTrailingComment$2(precedingNode, comment);
  8795. return true;
  8796. }
  8797. // Real functions
  8798. if (
  8799. precedingNode &&
  8800. (precedingNode.type === "Identifier" ||
  8801. precedingNode.type === "AssignmentPattern") &&
  8802. enclosingNode &&
  8803. (enclosingNode.type === "ArrowFunctionExpression" ||
  8804. enclosingNode.type === "FunctionExpression" ||
  8805. enclosingNode.type === "FunctionDeclaration" ||
  8806. enclosingNode.type === "ObjectMethod" ||
  8807. enclosingNode.type === "ClassMethod") &&
  8808. util$1.getNextNonSpaceNonCommentCharacter(
  8809. text,
  8810. comment,
  8811. options.locEnd
  8812. ) === ")"
  8813. ) {
  8814. addTrailingComment$2(precedingNode, comment);
  8815. return true;
  8816. }
  8817. return false;
  8818. }
  8819. function handleImportSpecifierComments(enclosingNode, comment) {
  8820. if (enclosingNode && enclosingNode.type === "ImportSpecifier") {
  8821. addLeadingComment$2(enclosingNode, comment);
  8822. return true;
  8823. }
  8824. return false;
  8825. }
  8826. function handleLabeledStatementComments(enclosingNode, comment) {
  8827. if (enclosingNode && enclosingNode.type === "LabeledStatement") {
  8828. addLeadingComment$2(enclosingNode, comment);
  8829. return true;
  8830. }
  8831. return false;
  8832. }
  8833. function handleBreakAndContinueStatementComments(enclosingNode, comment) {
  8834. if (
  8835. enclosingNode &&
  8836. (enclosingNode.type === "ContinueStatement" ||
  8837. enclosingNode.type === "BreakStatement") &&
  8838. !enclosingNode.label
  8839. ) {
  8840. addTrailingComment$2(enclosingNode, comment);
  8841. return true;
  8842. }
  8843. return false;
  8844. }
  8845. function handleCallExpressionComments(precedingNode, enclosingNode, comment) {
  8846. if (
  8847. enclosingNode &&
  8848. enclosingNode.type === "CallExpression" &&
  8849. precedingNode &&
  8850. enclosingNode.callee === precedingNode &&
  8851. enclosingNode.arguments.length > 0
  8852. ) {
  8853. addLeadingComment$2(enclosingNode.arguments[0], comment);
  8854. return true;
  8855. }
  8856. return false;
  8857. }
  8858. function handleUnionTypeComments(
  8859. precedingNode,
  8860. enclosingNode,
  8861. followingNode,
  8862. comment
  8863. ) {
  8864. if (
  8865. enclosingNode &&
  8866. (enclosingNode.type === "UnionTypeAnnotation" ||
  8867. enclosingNode.type === "TSUnionType")
  8868. ) {
  8869. addTrailingComment$2(precedingNode, comment);
  8870. return true;
  8871. }
  8872. return false;
  8873. }
  8874. function handlePropertyComments(enclosingNode, comment) {
  8875. if (
  8876. enclosingNode &&
  8877. (enclosingNode.type === "Property" ||
  8878. enclosingNode.type === "ObjectProperty")
  8879. ) {
  8880. addLeadingComment$2(enclosingNode, comment);
  8881. return true;
  8882. }
  8883. return false;
  8884. }
  8885. function handleOnlyComments(enclosingNode, ast, comment, isLastComment) {
  8886. // With Flow the enclosingNode is undefined so use the AST instead.
  8887. if (ast && ast.body && ast.body.length === 0) {
  8888. if (isLastComment) {
  8889. addDanglingComment$2(ast, comment);
  8890. } else {
  8891. addLeadingComment$2(ast, comment);
  8892. }
  8893. return true;
  8894. } else if (
  8895. enclosingNode &&
  8896. enclosingNode.type === "Program" &&
  8897. enclosingNode.body.length === 0 &&
  8898. enclosingNode.directives &&
  8899. enclosingNode.directives.length === 0
  8900. ) {
  8901. if (isLastComment) {
  8902. addDanglingComment$2(enclosingNode, comment);
  8903. } else {
  8904. addLeadingComment$2(enclosingNode, comment);
  8905. }
  8906. return true;
  8907. }
  8908. return false;
  8909. }
  8910. function handleForComments(enclosingNode, precedingNode, comment) {
  8911. if (
  8912. enclosingNode &&
  8913. (enclosingNode.type === "ForInStatement" ||
  8914. enclosingNode.type === "ForOfStatement")
  8915. ) {
  8916. addLeadingComment$2(enclosingNode, comment);
  8917. return true;
  8918. }
  8919. return false;
  8920. }
  8921. function handleImportDeclarationComments(
  8922. text,
  8923. enclosingNode,
  8924. precedingNode,
  8925. comment,
  8926. options
  8927. ) {
  8928. if (
  8929. precedingNode &&
  8930. enclosingNode &&
  8931. enclosingNode.type === "ImportDeclaration" &&
  8932. util$1.hasNewline(text, options.locEnd(comment))
  8933. ) {
  8934. addTrailingComment$2(precedingNode, comment);
  8935. return true;
  8936. }
  8937. return false;
  8938. }
  8939. function handleAssignmentPatternComments(enclosingNode, comment) {
  8940. if (enclosingNode && enclosingNode.type === "AssignmentPattern") {
  8941. addLeadingComment$2(enclosingNode, comment);
  8942. return true;
  8943. }
  8944. return false;
  8945. }
  8946. function handleTypeAliasComments(enclosingNode, followingNode, comment) {
  8947. if (enclosingNode && enclosingNode.type === "TypeAlias") {
  8948. addLeadingComment$2(enclosingNode, comment);
  8949. return true;
  8950. }
  8951. return false;
  8952. }
  8953. function handleVariableDeclaratorComments(
  8954. enclosingNode,
  8955. followingNode,
  8956. comment
  8957. ) {
  8958. if (
  8959. enclosingNode &&
  8960. enclosingNode.type === "VariableDeclarator" &&
  8961. followingNode &&
  8962. (followingNode.type === "ObjectExpression" ||
  8963. followingNode.type === "ArrayExpression")
  8964. ) {
  8965. addLeadingComment$2(followingNode, comment);
  8966. return true;
  8967. }
  8968. return false;
  8969. }
  8970. var comments$2 = {
  8971. handleOwnLineComment,
  8972. handleEndOfLineComment,
  8973. handleRemainingComment
  8974. };
  8975. function needsParens(path$$1, options) {
  8976. const parent = path$$1.getParentNode();
  8977. if (!parent) {
  8978. return false;
  8979. }
  8980. const name = path$$1.getName();
  8981. const node = path$$1.getNode();
  8982. // If the value of this path is some child of a Node and not a Node
  8983. // itself, then it doesn't need parentheses. Only Node objects (in
  8984. // fact, only Expression nodes) need parentheses.
  8985. if (path$$1.getValue() !== node) {
  8986. return false;
  8987. }
  8988. // Only statements don't need parentheses.
  8989. if (isStatement(node)) {
  8990. return false;
  8991. }
  8992. // Closure compiler requires that type casted expressions to be surrounded by
  8993. // parentheses.
  8994. if (
  8995. util$1.hasClosureCompilerTypeCastComment(
  8996. options.originalText,
  8997. node,
  8998. options.locEnd
  8999. )
  9000. ) {
  9001. return true;
  9002. }
  9003. // Identifiers never need parentheses.
  9004. if (node.type === "Identifier") {
  9005. return false;
  9006. }
  9007. if (parent.type === "ParenthesizedExpression") {
  9008. return false;
  9009. }
  9010. // Add parens around the extends clause of a class. It is needed for almost
  9011. // all expressions.
  9012. if (
  9013. (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") &&
  9014. parent.superClass === node &&
  9015. (node.type === "ArrowFunctionExpression" ||
  9016. node.type === "AssignmentExpression" ||
  9017. node.type === "AwaitExpression" ||
  9018. node.type === "BinaryExpression" ||
  9019. node.type === "ConditionalExpression" ||
  9020. node.type === "LogicalExpression" ||
  9021. node.type === "NewExpression" ||
  9022. node.type === "ObjectExpression" ||
  9023. node.type === "ParenthesizedExpression" ||
  9024. node.type === "SequenceExpression" ||
  9025. node.type === "TaggedTemplateExpression" ||
  9026. node.type === "UnaryExpression" ||
  9027. node.type === "UpdateExpression" ||
  9028. node.type === "YieldExpression")
  9029. ) {
  9030. return true;
  9031. }
  9032. if (
  9033. (parent.type === "ArrowFunctionExpression" &&
  9034. parent.body === node &&
  9035. node.type !== "SequenceExpression" && // these have parens added anyway
  9036. util$1.startsWithNoLookaheadToken(
  9037. node,
  9038. /* forbidFunctionAndClass */ false
  9039. )) ||
  9040. (parent.type === "ExpressionStatement" &&
  9041. util$1.startsWithNoLookaheadToken(node, /* forbidFunctionAndClass */ true))
  9042. ) {
  9043. return true;
  9044. }
  9045. switch (node.type) {
  9046. case "CallExpression": {
  9047. let firstParentNotMemberExpression = parent;
  9048. let i = 0;
  9049. while (
  9050. firstParentNotMemberExpression &&
  9051. firstParentNotMemberExpression.type === "MemberExpression"
  9052. ) {
  9053. firstParentNotMemberExpression = path$$1.getParentNode(++i);
  9054. }
  9055. if (
  9056. firstParentNotMemberExpression.type === "NewExpression" &&
  9057. firstParentNotMemberExpression.callee === path$$1.getParentNode(i - 1)
  9058. ) {
  9059. return true;
  9060. }
  9061. return false;
  9062. }
  9063. case "SpreadElement":
  9064. case "SpreadProperty":
  9065. return (
  9066. parent.type === "MemberExpression" &&
  9067. name === "object" &&
  9068. parent.object === node
  9069. );
  9070. case "UpdateExpression":
  9071. if (parent.type === "UnaryExpression") {
  9072. return (
  9073. node.prefix &&
  9074. ((node.operator === "++" && parent.operator === "+") ||
  9075. (node.operator === "--" && parent.operator === "-"))
  9076. );
  9077. }
  9078. // else fallthrough
  9079. case "UnaryExpression":
  9080. switch (parent.type) {
  9081. case "UnaryExpression":
  9082. return (
  9083. node.operator === parent.operator &&
  9084. (node.operator === "+" || node.operator === "-")
  9085. );
  9086. case "MemberExpression":
  9087. return name === "object" && parent.object === node;
  9088. case "TaggedTemplateExpression":
  9089. return true;
  9090. case "NewExpression":
  9091. case "CallExpression":
  9092. return name === "callee" && parent.callee === node;
  9093. case "BinaryExpression":
  9094. return parent.operator === "**" && name === "left";
  9095. case "TSNonNullExpression":
  9096. return true;
  9097. default:
  9098. return false;
  9099. }
  9100. case "BinaryExpression": {
  9101. if (parent.type === "UpdateExpression") {
  9102. return true;
  9103. }
  9104. const isLeftOfAForStatement = node => {
  9105. let i = 0;
  9106. while (node) {
  9107. const parent = path$$1.getParentNode(i++);
  9108. if (!parent) {
  9109. return false;
  9110. }
  9111. if (parent.type === "ForStatement" && parent.init === node) {
  9112. return true;
  9113. }
  9114. node = parent;
  9115. }
  9116. return false;
  9117. };
  9118. if (node.operator === "in" && isLeftOfAForStatement(node)) {
  9119. return true;
  9120. }
  9121. }
  9122. // fallthrough
  9123. case "TSTypeAssertionExpression":
  9124. case "TSAsExpression":
  9125. case "LogicalExpression":
  9126. switch (parent.type) {
  9127. case "ConditionalExpression":
  9128. return node.type === "TSAsExpression";
  9129. case "CallExpression":
  9130. case "NewExpression":
  9131. return name === "callee" && parent.callee === node;
  9132. case "ClassDeclaration":
  9133. case "TSAbstractClassDeclaration":
  9134. return name === "superClass" && parent.superClass === node;
  9135. case "TSTypeAssertionExpression":
  9136. case "TaggedTemplateExpression":
  9137. case "UnaryExpression":
  9138. case "SpreadElement":
  9139. case "SpreadProperty":
  9140. case "ExperimentalSpreadProperty":
  9141. case "BindExpression":
  9142. case "AwaitExpression":
  9143. case "TSAsExpression":
  9144. case "TSNonNullExpression":
  9145. case "UpdateExpression":
  9146. return true;
  9147. case "MemberExpression":
  9148. return name === "object" && parent.object === node;
  9149. case "AssignmentExpression":
  9150. return (
  9151. parent.left === node &&
  9152. (node.type === "TSTypeAssertionExpression" ||
  9153. node.type === "TSAsExpression")
  9154. );
  9155. case "Decorator":
  9156. return (
  9157. parent.expression === node &&
  9158. (node.type === "TSTypeAssertionExpression" ||
  9159. node.type === "TSAsExpression")
  9160. );
  9161. case "BinaryExpression":
  9162. case "LogicalExpression": {
  9163. if (!node.operator && node.type !== "TSTypeAssertionExpression") {
  9164. return true;
  9165. }
  9166. const po = parent.operator;
  9167. const pp = util$1.getPrecedence(po);
  9168. const no = node.operator;
  9169. const np = util$1.getPrecedence(no);
  9170. if (pp > np) {
  9171. return true;
  9172. }
  9173. if ((po === "||" || po === "??") && no === "&&") {
  9174. return true;
  9175. }
  9176. if (pp === np && name === "right") {
  9177. assert.strictEqual(parent.right, node);
  9178. return true;
  9179. }
  9180. if (pp === np && !util$1.shouldFlatten(po, no)) {
  9181. return true;
  9182. }
  9183. // Add parenthesis when working with binary operators
  9184. // It's not stricly needed but helps with code understanding
  9185. if (util$1.isBitwiseOperator(po)) {
  9186. return true;
  9187. }
  9188. return false;
  9189. }
  9190. default:
  9191. return false;
  9192. }
  9193. case "TSParenthesizedType": {
  9194. const grandParent = path$$1.getParentNode(1);
  9195. if (
  9196. (parent.type === "TSTypeParameter" ||
  9197. parent.type === "TypeParameter" ||
  9198. parent.type === "VariableDeclarator" ||
  9199. parent.type === "TSTypeAnnotation" ||
  9200. parent.type === "GenericTypeAnnotation" ||
  9201. parent.type === "TSTypeReference") &&
  9202. (node.typeAnnotation.type === "TSTypeAnnotation" &&
  9203. node.typeAnnotation.typeAnnotation.type !== "TSFunctionType" &&
  9204. grandParent.type !== "TSTypeOperator")
  9205. ) {
  9206. return false;
  9207. }
  9208. // Delegate to inner TSParenthesizedType
  9209. if (node.typeAnnotation.type === "TSParenthesizedType") {
  9210. return false;
  9211. }
  9212. return true;
  9213. }
  9214. case "SequenceExpression":
  9215. switch (parent.type) {
  9216. case "ReturnStatement":
  9217. return false;
  9218. case "ForStatement":
  9219. // Although parentheses wouldn't hurt around sequence
  9220. // expressions in the head of for loops, traditional style
  9221. // dictates that e.g. i++, j++ should not be wrapped with
  9222. // parentheses.
  9223. return false;
  9224. case "ExpressionStatement":
  9225. return name !== "expression";
  9226. case "ArrowFunctionExpression":
  9227. // We do need parentheses, but SequenceExpressions are handled
  9228. // specially when printing bodies of arrow functions.
  9229. return name !== "body";
  9230. default:
  9231. // Otherwise err on the side of overparenthesization, adding
  9232. // explicit exceptions above if this proves overzealous.
  9233. return true;
  9234. }
  9235. case "YieldExpression":
  9236. if (
  9237. parent.type === "UnaryExpression" ||
  9238. parent.type === "AwaitExpression" ||
  9239. parent.type === "TSAsExpression" ||
  9240. parent.type === "TSNonNullExpression"
  9241. ) {
  9242. return true;
  9243. }
  9244. // else fallthrough
  9245. case "AwaitExpression":
  9246. switch (parent.type) {
  9247. case "TaggedTemplateExpression":
  9248. case "UnaryExpression":
  9249. case "BinaryExpression":
  9250. case "LogicalExpression":
  9251. case "SpreadElement":
  9252. case "SpreadProperty":
  9253. case "ExperimentalSpreadProperty":
  9254. case "TSAsExpression":
  9255. case "TSNonNullExpression":
  9256. return true;
  9257. case "MemberExpression":
  9258. return parent.object === node;
  9259. case "NewExpression":
  9260. case "CallExpression":
  9261. return parent.callee === node;
  9262. case "ConditionalExpression":
  9263. return parent.test === node;
  9264. default:
  9265. return false;
  9266. }
  9267. case "ArrayTypeAnnotation":
  9268. return parent.type === "NullableTypeAnnotation";
  9269. case "IntersectionTypeAnnotation":
  9270. case "UnionTypeAnnotation":
  9271. return (
  9272. parent.type === "ArrayTypeAnnotation" ||
  9273. parent.type === "NullableTypeAnnotation" ||
  9274. parent.type === "IntersectionTypeAnnotation" ||
  9275. parent.type === "UnionTypeAnnotation"
  9276. );
  9277. case "NullableTypeAnnotation":
  9278. return parent.type === "ArrayTypeAnnotation";
  9279. case "FunctionTypeAnnotation":
  9280. return (
  9281. parent.type === "UnionTypeAnnotation" ||
  9282. parent.type === "IntersectionTypeAnnotation" ||
  9283. parent.type === "ArrayTypeAnnotation"
  9284. );
  9285. case "StringLiteral":
  9286. case "NumericLiteral":
  9287. case "Literal":
  9288. if (
  9289. typeof node.value === "string" &&
  9290. parent.type === "ExpressionStatement" &&
  9291. // TypeScript workaround for eslint/typescript-eslint-parser#267
  9292. // See corresponding workaround in printer.js case: "Literal"
  9293. ((options.parser !== "typescript" && !parent.directive) ||
  9294. (options.parser === "typescript" &&
  9295. options.originalText.substr(options.locStart(node) - 1, 1) === "("))
  9296. ) {
  9297. // To avoid becoming a directive
  9298. const grandParent = path$$1.getParentNode(1);
  9299. return (
  9300. grandParent.type === "Program" ||
  9301. grandParent.type === "BlockStatement"
  9302. );
  9303. }
  9304. return (
  9305. parent.type === "MemberExpression" &&
  9306. typeof node.value === "number" &&
  9307. name === "object" &&
  9308. parent.object === node
  9309. );
  9310. case "AssignmentExpression": {
  9311. const grandParent = path$$1.getParentNode(1);
  9312. if (parent.type === "ArrowFunctionExpression" && parent.body === node) {
  9313. return true;
  9314. } else if (
  9315. parent.type === "ClassProperty" &&
  9316. parent.key === node &&
  9317. parent.computed
  9318. ) {
  9319. return false;
  9320. } else if (
  9321. parent.type === "TSPropertySignature" &&
  9322. parent.name === node
  9323. ) {
  9324. return false;
  9325. } else if (
  9326. parent.type === "ForStatement" &&
  9327. (parent.init === node || parent.update === node)
  9328. ) {
  9329. return false;
  9330. } else if (parent.type === "ExpressionStatement") {
  9331. return node.left.type === "ObjectPattern";
  9332. } else if (parent.type === "TSPropertySignature" && parent.key === node) {
  9333. return false;
  9334. } else if (parent.type === "AssignmentExpression") {
  9335. return false;
  9336. } else if (
  9337. parent.type === "SequenceExpression" &&
  9338. grandParent &&
  9339. grandParent.type === "ForStatement" &&
  9340. (grandParent.init === parent || grandParent.update === parent)
  9341. ) {
  9342. return false;
  9343. }
  9344. return true;
  9345. }
  9346. case "ConditionalExpression":
  9347. switch (parent.type) {
  9348. case "TaggedTemplateExpression":
  9349. case "UnaryExpression":
  9350. case "SpreadElement":
  9351. case "SpreadProperty":
  9352. case "ExperimentalSpreadProperty":
  9353. case "BinaryExpression":
  9354. case "LogicalExpression":
  9355. case "ExportDefaultDeclaration":
  9356. case "AwaitExpression":
  9357. case "JSXSpreadAttribute":
  9358. case "TSTypeAssertionExpression":
  9359. case "TypeCastExpression":
  9360. case "TSAsExpression":
  9361. case "TSNonNullExpression":
  9362. return true;
  9363. case "NewExpression":
  9364. case "CallExpression":
  9365. return name === "callee" && parent.callee === node;
  9366. case "ConditionalExpression":
  9367. return name === "test" && parent.test === node;
  9368. case "MemberExpression":
  9369. return name === "object" && parent.object === node;
  9370. default:
  9371. return false;
  9372. }
  9373. case "FunctionExpression":
  9374. switch (parent.type) {
  9375. case "CallExpression":
  9376. return name === "callee"; // Not strictly necessary, but it's clearer to the reader if IIFEs are wrapped in parentheses.
  9377. case "TaggedTemplateExpression":
  9378. return true; // This is basically a kind of IIFE.
  9379. case "ExportDefaultDeclaration":
  9380. return true;
  9381. default:
  9382. return false;
  9383. }
  9384. case "ArrowFunctionExpression":
  9385. switch (parent.type) {
  9386. case "CallExpression":
  9387. return name === "callee";
  9388. case "NewExpression":
  9389. return name === "callee";
  9390. case "MemberExpression":
  9391. return name === "object";
  9392. case "TSAsExpression":
  9393. case "BindExpression":
  9394. case "TaggedTemplateExpression":
  9395. case "UnaryExpression":
  9396. case "LogicalExpression":
  9397. case "BinaryExpression":
  9398. case "AwaitExpression":
  9399. case "TSTypeAssertionExpression":
  9400. return true;
  9401. case "ConditionalExpression":
  9402. return name === "test";
  9403. default:
  9404. return false;
  9405. }
  9406. case "ClassExpression":
  9407. return parent.type === "ExportDefaultDeclaration";
  9408. }
  9409. return false;
  9410. }
  9411. function isStatement(node) {
  9412. return (
  9413. node.type === "BlockStatement" ||
  9414. node.type === "BreakStatement" ||
  9415. node.type === "ClassBody" ||
  9416. node.type === "ClassDeclaration" ||
  9417. node.type === "ClassMethod" ||
  9418. node.type === "ClassProperty" ||
  9419. node.type === "ClassPrivateProperty" ||
  9420. node.type === "ContinueStatement" ||
  9421. node.type === "DebuggerStatement" ||
  9422. node.type === "DeclareClass" ||
  9423. node.type === "DeclareExportAllDeclaration" ||
  9424. node.type === "DeclareExportDeclaration" ||
  9425. node.type === "DeclareFunction" ||
  9426. node.type === "DeclareInterface" ||
  9427. node.type === "DeclareModule" ||
  9428. node.type === "DeclareModuleExports" ||
  9429. node.type === "DeclareVariable" ||
  9430. node.type === "DoWhileStatement" ||
  9431. node.type === "ExportAllDeclaration" ||
  9432. node.type === "ExportDefaultDeclaration" ||
  9433. node.type === "ExportNamedDeclaration" ||
  9434. node.type === "ExpressionStatement" ||
  9435. node.type === "ForAwaitStatement" ||
  9436. node.type === "ForInStatement" ||
  9437. node.type === "ForOfStatement" ||
  9438. node.type === "ForStatement" ||
  9439. node.type === "FunctionDeclaration" ||
  9440. node.type === "IfStatement" ||
  9441. node.type === "ImportDeclaration" ||
  9442. node.type === "InterfaceDeclaration" ||
  9443. node.type === "LabeledStatement" ||
  9444. node.type === "MethodDefinition" ||
  9445. node.type === "ReturnStatement" ||
  9446. node.type === "SwitchStatement" ||
  9447. node.type === "ThrowStatement" ||
  9448. node.type === "TryStatement" ||
  9449. node.type === "TSAbstractClassDeclaration" ||
  9450. node.type === "TSEnumDeclaration" ||
  9451. node.type === "TSImportEqualsDeclaration" ||
  9452. node.type === "TSInterfaceDeclaration" ||
  9453. node.type === "TSModuleDeclaration" ||
  9454. node.type === "TSNamespaceExportDeclaration" ||
  9455. node.type === "TypeAlias" ||
  9456. node.type === "VariableDeclaration" ||
  9457. node.type === "WhileStatement" ||
  9458. node.type === "WithStatement"
  9459. );
  9460. }
  9461. var needsParens_1 = needsParens;
  9462. // TODO(azz): anything that imports from main shouldn't be in a `language-*` dir.
  9463. const isIdentifierName = utils$2.keyword.isIdentifierNameES6;
  9464. const insertPragma = pragma.insertPragma;
  9465. const docBuilders = doc.builders;
  9466. const concat = docBuilders.concat;
  9467. const join = docBuilders.join;
  9468. const line = docBuilders.line;
  9469. const hardline = docBuilders.hardline;
  9470. const softline = docBuilders.softline;
  9471. const literalline = docBuilders.literalline;
  9472. const group = docBuilders.group;
  9473. const indent = docBuilders.indent;
  9474. const align = docBuilders.align;
  9475. const conditionalGroup = docBuilders.conditionalGroup;
  9476. const fill = docBuilders.fill;
  9477. const ifBreak = docBuilders.ifBreak;
  9478. const breakParent = docBuilders.breakParent;
  9479. const lineSuffixBoundary = docBuilders.lineSuffixBoundary;
  9480. const addAlignmentToDoc = docBuilders.addAlignmentToDoc;
  9481. const dedent = docBuilders.dedent;
  9482. const docUtils$3 = doc.utils;
  9483. const willBreak$1 = docUtils$3.willBreak;
  9484. const isLineNext$1 = docUtils$3.isLineNext;
  9485. const isEmpty$1 = docUtils$3.isEmpty;
  9486. function shouldPrintComma(options, level) {
  9487. level = level || "es5";
  9488. switch (options.trailingComma) {
  9489. case "all":
  9490. if (level === "all") {
  9491. return true;
  9492. }
  9493. // fallthrough
  9494. case "es5":
  9495. if (level === "es5") {
  9496. return true;
  9497. }
  9498. // fallthrough
  9499. case "none":
  9500. default:
  9501. return false;
  9502. }
  9503. }
  9504. function genericPrint(path$$1, options, printPath, args) {
  9505. const node = path$$1.getValue();
  9506. let needsParens = false;
  9507. const linesWithoutParens = printPathNoParens(path$$1, options, printPath, args);
  9508. if (!node || isEmpty$1(linesWithoutParens)) {
  9509. return linesWithoutParens;
  9510. }
  9511. const decorators = [];
  9512. if (
  9513. node.decorators &&
  9514. node.decorators.length > 0 &&
  9515. // If the parent node is an export declaration, it will be
  9516. // responsible for printing node.decorators.
  9517. !util$1.getParentExportDeclaration(path$$1)
  9518. ) {
  9519. let separator = hardline;
  9520. path$$1.each(decoratorPath => {
  9521. let prefix = "@";
  9522. let decorator = decoratorPath.getValue();
  9523. if (decorator.expression) {
  9524. decorator = decorator.expression;
  9525. prefix = "";
  9526. }
  9527. if (
  9528. node.decorators.length === 1 &&
  9529. node.type !== "ClassDeclaration" &&
  9530. node.type !== "MethodDefinition" &&
  9531. node.type !== "ClassMethod" &&
  9532. (decorator.type === "Identifier" ||
  9533. decorator.type === "MemberExpression" ||
  9534. (decorator.type === "CallExpression" &&
  9535. (decorator.arguments.length === 0 ||
  9536. (decorator.arguments.length === 1 &&
  9537. (isStringLiteral(decorator.arguments[0]) ||
  9538. decorator.arguments[0].type === "Identifier" ||
  9539. decorator.arguments[0].type === "MemberExpression")))))
  9540. ) {
  9541. separator = line;
  9542. }
  9543. decorators.push(prefix, printPath(decoratorPath), separator);
  9544. }, "decorators");
  9545. } else if (
  9546. util$1.isExportDeclaration(node) &&
  9547. node.declaration &&
  9548. node.declaration.decorators
  9549. ) {
  9550. // Export declarations are responsible for printing any decorators
  9551. // that logically apply to node.declaration.
  9552. path$$1.each(
  9553. decoratorPath => {
  9554. const decorator = decoratorPath.getValue();
  9555. const prefix = decorator.type === "Decorator" ? "" : "@";
  9556. decorators.push(prefix, printPath(decoratorPath), hardline);
  9557. },
  9558. "declaration",
  9559. "decorators"
  9560. );
  9561. } else {
  9562. // Nodes with decorators can't have parentheses, so we can avoid
  9563. // computing pathNeedsParens() except in this case.
  9564. needsParens = needsParens_1(path$$1, options);
  9565. }
  9566. const parts = [];
  9567. if (needsParens) {
  9568. parts.unshift("(");
  9569. }
  9570. parts.push(linesWithoutParens);
  9571. if (needsParens) {
  9572. parts.push(")");
  9573. }
  9574. if (decorators.length > 0) {
  9575. return group(concat(decorators.concat(parts)));
  9576. }
  9577. return concat(parts);
  9578. }
  9579. function hasPrettierIgnore(path$$1) {
  9580. return util$1.hasIgnoreComment(path$$1) || hasJsxIgnoreComment(path$$1);
  9581. }
  9582. function hasJsxIgnoreComment(path$$1) {
  9583. const node = path$$1.getValue();
  9584. const parent = path$$1.getParentNode();
  9585. if (!parent || !node || !isJSXNode(node) || !isJSXNode(parent)) {
  9586. return false;
  9587. }
  9588. // Lookup the previous sibling, ignoring any empty JSXText elements
  9589. const index = parent.children.indexOf(node);
  9590. let prevSibling = null;
  9591. for (let i = index; i > 0; i--) {
  9592. const candidate = parent.children[i - 1];
  9593. if (candidate.type === "JSXText" && !isMeaningfulJSXText(candidate)) {
  9594. continue;
  9595. }
  9596. prevSibling = candidate;
  9597. break;
  9598. }
  9599. return (
  9600. prevSibling &&
  9601. prevSibling.type === "JSXExpressionContainer" &&
  9602. prevSibling.expression.type === "JSXEmptyExpression" &&
  9603. prevSibling.expression.comments &&
  9604. prevSibling.expression.comments.find(
  9605. comment => comment.value.trim() === "prettier-ignore"
  9606. )
  9607. );
  9608. }
  9609. // The following is the shared logic for
  9610. // ternary operators, namely ConditionalExpression
  9611. // and TSConditionalType
  9612. function formatTernaryOperator(path$$1, options, print, operatorOptions) {
  9613. const n = path$$1.getValue();
  9614. const parts = [];
  9615. const operatorOpts = Object.assign(
  9616. {
  9617. beforeParts: () => [""],
  9618. afterParts: () => [""],
  9619. shouldCheckJsx: true,
  9620. operatorName: "ConditionalExpression",
  9621. consequentNode: "consequent",
  9622. alternateNode: "alternate",
  9623. testNode: "test",
  9624. breakNested: true
  9625. },
  9626. operatorOptions || {}
  9627. );
  9628. // We print a ConditionalExpression in either "JSX mode" or "normal mode".
  9629. // See tests/jsx/conditional-expression.js for more info.
  9630. let jsxMode = false;
  9631. const parent = path$$1.getParentNode();
  9632. let forceNoIndent = parent.type === operatorOpts.operatorName;
  9633. // Find the outermost non-ConditionalExpression parent, and the outermost
  9634. // ConditionalExpression parent. We'll use these to determine if we should
  9635. // print in JSX mode.
  9636. let currentParent;
  9637. let previousParent;
  9638. let i = 0;
  9639. do {
  9640. previousParent = currentParent || n;
  9641. currentParent = path$$1.getParentNode(i);
  9642. i++;
  9643. } while (currentParent && currentParent.type === operatorOpts.operatorName);
  9644. const firstNonConditionalParent = currentParent || parent;
  9645. const lastConditionalParent = previousParent;
  9646. if (
  9647. (operatorOpts.shouldCheckJsx && isJSXNode(n[operatorOpts.testNode])) ||
  9648. isJSXNode(n[operatorOpts.consequentNode]) ||
  9649. isJSXNode(n[operatorOpts.alternateNode]) ||
  9650. conditionalExpressionChainContainsJSX(lastConditionalParent)
  9651. ) {
  9652. jsxMode = true;
  9653. forceNoIndent = true;
  9654. // Even though they don't need parens, we wrap (almost) everything in
  9655. // parens when using ?: within JSX, because the parens are analogous to
  9656. // curly braces in an if statement.
  9657. const wrap = doc$$1 =>
  9658. concat([
  9659. ifBreak("(", ""),
  9660. indent(concat([softline, doc$$1])),
  9661. softline,
  9662. ifBreak(")", "")
  9663. ]);
  9664. // The only things we don't wrap are:
  9665. // * Nested conditional expressions in alternates
  9666. // * null
  9667. const isNull = node =>
  9668. node.type === "NullLiteral" ||
  9669. (node.type === "Literal" && node.value === null);
  9670. parts.push(
  9671. " ? ",
  9672. isNull(n[operatorOpts.consequentNode])
  9673. ? path$$1.call(print, operatorOpts.consequentNode)
  9674. : wrap(path$$1.call(print, operatorOpts.consequentNode)),
  9675. " : ",
  9676. n[operatorOpts.alternateNode].type === operatorOpts.operatorName ||
  9677. isNull(n[operatorOpts.alternateNode])
  9678. ? path$$1.call(print, operatorOpts.alternateNode)
  9679. : wrap(path$$1.call(print, operatorOpts.alternateNode))
  9680. );
  9681. } else {
  9682. // normal mode
  9683. const part = concat([
  9684. line,
  9685. "? ",
  9686. n[operatorOpts.consequentNode].type === operatorOpts.operatorName
  9687. ? ifBreak("", "(")
  9688. : "",
  9689. align(2, path$$1.call(print, operatorOpts.consequentNode)),
  9690. n[operatorOpts.consequentNode].type === operatorOpts.operatorName
  9691. ? ifBreak("", ")")
  9692. : "",
  9693. line,
  9694. ": ",
  9695. align(2, path$$1.call(print, operatorOpts.alternateNode))
  9696. ]);
  9697. parts.push(
  9698. parent.type === operatorOpts.operatorName
  9699. ? options.useTabs
  9700. ? dedent(indent(part))
  9701. : align(Math.max(0, options.tabWidth - 2), part)
  9702. : part
  9703. );
  9704. }
  9705. // We want a whole chain of ConditionalExpressions to all
  9706. // break if any of them break. That means we should only group around the
  9707. // outer-most ConditionalExpression.
  9708. const maybeGroup = doc$$1 =>
  9709. operatorOpts.breakNested
  9710. ? parent === firstNonConditionalParent
  9711. ? group(doc$$1)
  9712. : doc$$1
  9713. : group(doc$$1); // Always group in normal mode.
  9714. // Break the closing paren to keep the chain right after it:
  9715. // (a
  9716. // ? b
  9717. // : c
  9718. // ).call()
  9719. const breakClosingParen =
  9720. !jsxMode && parent.type === "MemberExpression" && !parent.computed;
  9721. return maybeGroup(
  9722. concat(
  9723. [].concat(
  9724. operatorOpts.beforeParts(),
  9725. forceNoIndent ? concat(parts) : indent(concat(parts)),
  9726. operatorOpts.afterParts(breakClosingParen)
  9727. )
  9728. )
  9729. );
  9730. }
  9731. function getTypeScriptMappedTypeModifier(tokenNode, keyword) {
  9732. if (tokenNode.type === "TSPlusToken") {
  9733. return "+" + keyword;
  9734. } else if (tokenNode.type === "TSMinusToken") {
  9735. return "-" + keyword;
  9736. }
  9737. return keyword;
  9738. }
  9739. function printPathNoParens(path$$1, options, print, args) {
  9740. const n = path$$1.getValue();
  9741. const semi = options.semi ? ";" : "";
  9742. if (!n) {
  9743. return "";
  9744. }
  9745. if (typeof n === "string") {
  9746. return n;
  9747. }
  9748. let parts = [];
  9749. switch (n.type) {
  9750. case "File":
  9751. return path$$1.call(print, "program");
  9752. case "Program":
  9753. // Babel 6
  9754. if (n.directives) {
  9755. path$$1.each(childPath => {
  9756. parts.push(print(childPath), semi, hardline);
  9757. if (
  9758. utilShared.isNextLineEmpty(
  9759. options.originalText,
  9760. childPath.getValue(),
  9761. options
  9762. )
  9763. ) {
  9764. parts.push(hardline);
  9765. }
  9766. }, "directives");
  9767. }
  9768. parts.push(
  9769. path$$1.call(bodyPath => {
  9770. return printStatementSequence(bodyPath, options, print);
  9771. }, "body")
  9772. );
  9773. parts.push(
  9774. comments.printDanglingComments(path$$1, options, /* sameIndent */ true)
  9775. );
  9776. // Only force a trailing newline if there were any contents.
  9777. if (n.body.length || n.comments) {
  9778. parts.push(hardline);
  9779. }
  9780. return concat(parts);
  9781. // Babel extension.
  9782. case "EmptyStatement":
  9783. return "";
  9784. case "ExpressionStatement":
  9785. // Detect Flow-parsed directives
  9786. if (n.directive) {
  9787. return concat([nodeStr(n.expression, options, true), semi]);
  9788. }
  9789. // Do not append semicolon after the only JSX element in a program
  9790. return concat([
  9791. path$$1.call(print, "expression"),
  9792. isTheOnlyJSXElementInMarkdown(options, path$$1) ? "" : semi
  9793. ]); // Babel extension.
  9794. case "ParenthesizedExpression":
  9795. return concat(["(", path$$1.call(print, "expression"), ")"]);
  9796. case "AssignmentExpression":
  9797. return printAssignment(
  9798. n.left,
  9799. path$$1.call(print, "left"),
  9800. concat([" ", n.operator]),
  9801. n.right,
  9802. path$$1.call(print, "right"),
  9803. options
  9804. );
  9805. case "BinaryExpression":
  9806. case "LogicalExpression": {
  9807. const parent = path$$1.getParentNode();
  9808. const parentParent = path$$1.getParentNode(1);
  9809. const isInsideParenthesis =
  9810. n !== parent.body &&
  9811. (parent.type === "IfStatement" ||
  9812. parent.type === "WhileStatement" ||
  9813. parent.type === "DoWhileStatement");
  9814. const parts = printBinaryishExpressions(
  9815. path$$1,
  9816. print,
  9817. options,
  9818. /* isNested */ false,
  9819. isInsideParenthesis
  9820. );
  9821. // if (
  9822. // this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft
  9823. // ) {
  9824. //
  9825. // looks super weird, we want to break the children if the parent breaks
  9826. //
  9827. // if (
  9828. // this.hasPlugin("dynamicImports") &&
  9829. // this.lookahead().type === tt.parenLeft
  9830. // ) {
  9831. if (isInsideParenthesis) {
  9832. return concat(parts);
  9833. }
  9834. // Break between the parens in unaries or in a member expression, i.e.
  9835. //
  9836. // (
  9837. // a &&
  9838. // b &&
  9839. // c
  9840. // ).call()
  9841. if (
  9842. parent.type === "UnaryExpression" ||
  9843. (parent.type === "MemberExpression" && !parent.computed)
  9844. ) {
  9845. return group(
  9846. concat([indent(concat([softline, concat(parts)])), softline])
  9847. );
  9848. }
  9849. // Avoid indenting sub-expressions in some cases where the first sub-expression is already
  9850. // indented accordingly. We should indent sub-expressions where the first case isn't indented.
  9851. const shouldNotIndent =
  9852. parent.type === "ReturnStatement" ||
  9853. (parent.type === "JSXExpressionContainer" &&
  9854. parentParent.type === "JSXAttribute") ||
  9855. (n === parent.body && parent.type === "ArrowFunctionExpression") ||
  9856. (n !== parent.body && parent.type === "ForStatement") ||
  9857. (parent.type === "ConditionalExpression" &&
  9858. parentParent.type !== "ReturnStatement");
  9859. const shouldIndentIfInlining =
  9860. parent.type === "AssignmentExpression" ||
  9861. parent.type === "VariableDeclarator" ||
  9862. parent.type === "ClassProperty" ||
  9863. parent.type === "TSAbstractClassProperty" ||
  9864. parent.type === "ClassPrivateProperty" ||
  9865. parent.type === "ObjectProperty" ||
  9866. parent.type === "Property";
  9867. const samePrecedenceSubExpression =
  9868. isBinaryish(n.left) &&
  9869. util$1.shouldFlatten(n.operator, n.left.operator);
  9870. if (
  9871. shouldNotIndent ||
  9872. (shouldInlineLogicalExpression(n) && !samePrecedenceSubExpression) ||
  9873. (!shouldInlineLogicalExpression(n) && shouldIndentIfInlining)
  9874. ) {
  9875. return group(concat(parts));
  9876. }
  9877. const rest = concat(parts.slice(1));
  9878. return group(
  9879. concat([
  9880. // Don't include the initial expression in the indentation
  9881. // level. The first item is guaranteed to be the first
  9882. // left-most expression.
  9883. parts.length > 0 ? parts[0] : "",
  9884. indent(rest)
  9885. ])
  9886. );
  9887. }
  9888. case "AssignmentPattern":
  9889. return concat([
  9890. path$$1.call(print, "left"),
  9891. " = ",
  9892. path$$1.call(print, "right")
  9893. ]);
  9894. case "TSTypeAssertionExpression":
  9895. return concat([
  9896. "<",
  9897. path$$1.call(print, "typeAnnotation"),
  9898. ">",
  9899. path$$1.call(print, "expression")
  9900. ]);
  9901. case "MemberExpression": {
  9902. const parent = path$$1.getParentNode();
  9903. let firstNonMemberParent;
  9904. let i = 0;
  9905. do {
  9906. firstNonMemberParent = path$$1.getParentNode(i);
  9907. i++;
  9908. } while (
  9909. firstNonMemberParent &&
  9910. (firstNonMemberParent.type === "MemberExpression" ||
  9911. firstNonMemberParent.type === "TSNonNullExpression")
  9912. );
  9913. const shouldInline =
  9914. (firstNonMemberParent &&
  9915. (firstNonMemberParent.type === "NewExpression" ||
  9916. (firstNonMemberParent.type === "VariableDeclarator" &&
  9917. firstNonMemberParent.id.type !== "Identifier") ||
  9918. (firstNonMemberParent.type === "AssignmentExpression" &&
  9919. firstNonMemberParent.left.type !== "Identifier"))) ||
  9920. n.computed ||
  9921. (n.object.type === "Identifier" &&
  9922. n.property.type === "Identifier" &&
  9923. parent.type !== "MemberExpression");
  9924. return concat([
  9925. path$$1.call(print, "object"),
  9926. shouldInline
  9927. ? printMemberLookup(path$$1, options, print)
  9928. : group(
  9929. indent(
  9930. concat([softline, printMemberLookup(path$$1, options, print)])
  9931. )
  9932. )
  9933. ]);
  9934. }
  9935. case "MetaProperty":
  9936. return concat([
  9937. path$$1.call(print, "meta"),
  9938. ".",
  9939. path$$1.call(print, "property")
  9940. ]);
  9941. case "BindExpression":
  9942. if (n.object) {
  9943. parts.push(path$$1.call(print, "object"));
  9944. }
  9945. parts.push(printBindExpressionCallee(path$$1, options, print));
  9946. return concat(parts);
  9947. case "Identifier": {
  9948. return concat([
  9949. n.name,
  9950. printOptionalToken(path$$1),
  9951. printTypeAnnotation(path$$1, options, print)
  9952. ]);
  9953. }
  9954. case "SpreadElement":
  9955. case "SpreadElementPattern":
  9956. case "RestProperty":
  9957. case "ExperimentalRestProperty":
  9958. case "ExperimentalSpreadProperty":
  9959. case "SpreadProperty":
  9960. case "SpreadPropertyPattern":
  9961. case "RestElement":
  9962. case "ObjectTypeSpreadProperty":
  9963. return concat([
  9964. "...",
  9965. path$$1.call(print, "argument"),
  9966. printTypeAnnotation(path$$1, options, print)
  9967. ]);
  9968. case "FunctionDeclaration":
  9969. case "FunctionExpression":
  9970. if (isNodeStartingWithDeclare(n, options)) {
  9971. parts.push("declare ");
  9972. }
  9973. parts.push(printFunctionDeclaration(path$$1, print, options));
  9974. if (!n.body) {
  9975. parts.push(semi);
  9976. }
  9977. return concat(parts);
  9978. case "ArrowFunctionExpression": {
  9979. if (n.async) {
  9980. parts.push("async ");
  9981. }
  9982. if (shouldPrintParamsWithoutParens(path$$1, options)) {
  9983. parts.push(path$$1.call(print, "params", 0));
  9984. } else {
  9985. parts.push(
  9986. group(
  9987. concat([
  9988. printFunctionParams(
  9989. path$$1,
  9990. print,
  9991. options,
  9992. /* expandLast */ args &&
  9993. (args.expandLastArg || args.expandFirstArg),
  9994. /* printTypeParams */ true
  9995. ),
  9996. printReturnType(path$$1, print, options)
  9997. ])
  9998. )
  9999. );
  10000. }
  10001. const dangling = comments.printDanglingComments(
  10002. path$$1,
  10003. options,
  10004. /* sameIndent */ true,
  10005. comment => {
  10006. const nextCharacter = utilShared.getNextNonSpaceNonCommentCharacterIndex(
  10007. options.originalText,
  10008. comment,
  10009. options
  10010. );
  10011. return options.originalText.substr(nextCharacter, 2) === "=>";
  10012. }
  10013. );
  10014. if (dangling) {
  10015. parts.push(" ", dangling);
  10016. }
  10017. parts.push(" =>");
  10018. const body = path$$1.call(bodyPath => print(bodyPath, args), "body");
  10019. // We want to always keep these types of nodes on the same line
  10020. // as the arrow.
  10021. if (
  10022. !hasLeadingOwnLineComment(options.originalText, n.body, options) &&
  10023. (n.body.type === "ArrayExpression" ||
  10024. n.body.type === "ObjectExpression" ||
  10025. n.body.type === "BlockStatement" ||
  10026. isJSXNode(n.body) ||
  10027. isTemplateOnItsOwnLine(n.body, options.originalText, options) ||
  10028. n.body.type === "ArrowFunctionExpression")
  10029. ) {
  10030. return group(concat([concat(parts), " ", body]));
  10031. }
  10032. // We handle sequence expressions as the body of arrows specially,
  10033. // so that the required parentheses end up on their own lines.
  10034. if (n.body.type === "SequenceExpression") {
  10035. return group(
  10036. concat([
  10037. concat(parts),
  10038. group(
  10039. concat([" (", indent(concat([softline, body])), softline, ")"])
  10040. )
  10041. ])
  10042. );
  10043. }
  10044. // if the arrow function is expanded as last argument, we are adding a
  10045. // level of indentation and need to add a softline to align the closing )
  10046. // with the opening (, or if it's inside a JSXExpression (e.g. an attribute)
  10047. // we should align the expression's closing } with the line with the opening {.
  10048. const shouldAddSoftLine =
  10049. ((args && args.expandLastArg) ||
  10050. path$$1.getParentNode().type === "JSXExpressionContainer") &&
  10051. !(n.comments && n.comments.length);
  10052. const printTrailingComma =
  10053. args && args.expandLastArg && shouldPrintComma(options, "all");
  10054. // In order to avoid confusion between
  10055. // a => a ? a : a
  10056. // a <= a ? a : a
  10057. const shouldAddParens =
  10058. n.body.type === "ConditionalExpression" &&
  10059. !util$1.startsWithNoLookaheadToken(
  10060. n.body,
  10061. /* forbidFunctionAndClass */ false
  10062. );
  10063. return group(
  10064. concat([
  10065. concat(parts),
  10066. group(
  10067. concat([
  10068. indent(
  10069. concat([
  10070. line,
  10071. shouldAddParens ? ifBreak("", "(") : "",
  10072. body,
  10073. shouldAddParens ? ifBreak("", ")") : ""
  10074. ])
  10075. ),
  10076. shouldAddSoftLine
  10077. ? concat([ifBreak(printTrailingComma ? "," : ""), softline])
  10078. : ""
  10079. ])
  10080. )
  10081. ])
  10082. );
  10083. }
  10084. case "MethodDefinition":
  10085. case "TSAbstractMethodDefinition":
  10086. if (n.accessibility) {
  10087. parts.push(n.accessibility + " ");
  10088. }
  10089. if (n.static) {
  10090. parts.push("static ");
  10091. }
  10092. if (n.type === "TSAbstractMethodDefinition") {
  10093. parts.push("abstract ");
  10094. }
  10095. parts.push(printMethod(path$$1, options, print));
  10096. return concat(parts);
  10097. case "YieldExpression":
  10098. parts.push("yield");
  10099. if (n.delegate) {
  10100. parts.push("*");
  10101. }
  10102. if (n.argument) {
  10103. parts.push(" ", path$$1.call(print, "argument"));
  10104. }
  10105. return concat(parts);
  10106. case "AwaitExpression":
  10107. return concat(["await ", path$$1.call(print, "argument")]);
  10108. case "ImportSpecifier":
  10109. if (n.importKind) {
  10110. parts.push(path$$1.call(print, "importKind"), " ");
  10111. }
  10112. parts.push(path$$1.call(print, "imported"));
  10113. if (n.local && n.local.name !== n.imported.name) {
  10114. parts.push(" as ", path$$1.call(print, "local"));
  10115. }
  10116. return concat(parts);
  10117. case "ExportSpecifier":
  10118. parts.push(path$$1.call(print, "local"));
  10119. if (n.exported && n.exported.name !== n.local.name) {
  10120. parts.push(" as ", path$$1.call(print, "exported"));
  10121. }
  10122. return concat(parts);
  10123. case "ImportNamespaceSpecifier":
  10124. parts.push("* as ");
  10125. if (n.local) {
  10126. parts.push(path$$1.call(print, "local"));
  10127. } else if (n.id) {
  10128. parts.push(path$$1.call(print, "id"));
  10129. }
  10130. return concat(parts);
  10131. case "ImportDefaultSpecifier":
  10132. if (n.local) {
  10133. return path$$1.call(print, "local");
  10134. }
  10135. return path$$1.call(print, "id");
  10136. case "TSExportAssignment":
  10137. return concat(["export = ", path$$1.call(print, "expression"), semi]);
  10138. case "ExportDefaultDeclaration":
  10139. case "ExportNamedDeclaration":
  10140. return printExportDeclaration(path$$1, options, print);
  10141. case "ExportAllDeclaration":
  10142. parts.push("export ");
  10143. if (n.exportKind === "type") {
  10144. parts.push("type ");
  10145. }
  10146. parts.push("* from ", path$$1.call(print, "source"), semi);
  10147. return concat(parts);
  10148. case "ExportNamespaceSpecifier":
  10149. case "ExportDefaultSpecifier":
  10150. return path$$1.call(print, "exported");
  10151. case "ImportDeclaration": {
  10152. parts.push("import ");
  10153. if (n.importKind && n.importKind !== "value") {
  10154. parts.push(n.importKind + " ");
  10155. }
  10156. const standalones = [];
  10157. const grouped = [];
  10158. if (n.specifiers && n.specifiers.length > 0) {
  10159. path$$1.each(specifierPath => {
  10160. const value = specifierPath.getValue();
  10161. if (
  10162. value.type === "ImportDefaultSpecifier" ||
  10163. value.type === "ImportNamespaceSpecifier"
  10164. ) {
  10165. standalones.push(print(specifierPath));
  10166. } else {
  10167. grouped.push(print(specifierPath));
  10168. }
  10169. }, "specifiers");
  10170. if (standalones.length > 0) {
  10171. parts.push(join(", ", standalones));
  10172. }
  10173. if (standalones.length > 0 && grouped.length > 0) {
  10174. parts.push(", ");
  10175. }
  10176. if (
  10177. grouped.length === 1 &&
  10178. standalones.length === 0 &&
  10179. n.specifiers &&
  10180. !n.specifiers.some(node => node.comments)
  10181. ) {
  10182. parts.push(
  10183. concat([
  10184. "{",
  10185. options.bracketSpacing ? " " : "",
  10186. concat(grouped),
  10187. options.bracketSpacing ? " " : "",
  10188. "}"
  10189. ])
  10190. );
  10191. } else if (grouped.length >= 1) {
  10192. parts.push(
  10193. group(
  10194. concat([
  10195. "{",
  10196. indent(
  10197. concat([
  10198. options.bracketSpacing ? line : softline,
  10199. join(concat([",", line]), grouped)
  10200. ])
  10201. ),
  10202. ifBreak(shouldPrintComma(options) ? "," : ""),
  10203. options.bracketSpacing ? line : softline,
  10204. "}"
  10205. ])
  10206. )
  10207. );
  10208. }
  10209. parts.push(" from ");
  10210. } else if (
  10211. (n.importKind && n.importKind === "type") ||
  10212. // import {} from 'x'
  10213. /{\s*}/.test(
  10214. options.originalText.slice(
  10215. options.locStart(n),
  10216. options.locStart(n.source)
  10217. )
  10218. )
  10219. ) {
  10220. parts.push("{} from ");
  10221. }
  10222. parts.push(path$$1.call(print, "source"), semi);
  10223. return concat(parts);
  10224. }
  10225. case "Import":
  10226. return "import";
  10227. case "BlockStatement": {
  10228. const naked = path$$1.call(bodyPath => {
  10229. return printStatementSequence(bodyPath, options, print);
  10230. }, "body");
  10231. const hasContent = n.body.find(node => node.type !== "EmptyStatement");
  10232. const hasDirectives = n.directives && n.directives.length > 0;
  10233. const parent = path$$1.getParentNode();
  10234. const parentParent = path$$1.getParentNode(1);
  10235. if (
  10236. !hasContent &&
  10237. !hasDirectives &&
  10238. !hasDanglingComments(n) &&
  10239. (parent.type === "ArrowFunctionExpression" ||
  10240. parent.type === "FunctionExpression" ||
  10241. parent.type === "FunctionDeclaration" ||
  10242. parent.type === "ObjectMethod" ||
  10243. parent.type === "ClassMethod" ||
  10244. parent.type === "ForStatement" ||
  10245. parent.type === "WhileStatement" ||
  10246. parent.type === "DoWhileStatement" ||
  10247. (parent.type === "CatchClause" && !parentParent.finalizer))
  10248. ) {
  10249. return "{}";
  10250. }
  10251. parts.push("{");
  10252. // Babel 6
  10253. if (hasDirectives) {
  10254. path$$1.each(childPath => {
  10255. parts.push(indent(concat([hardline, print(childPath), semi])));
  10256. if (
  10257. utilShared.isNextLineEmpty(
  10258. options.originalText,
  10259. childPath.getValue(),
  10260. options
  10261. )
  10262. ) {
  10263. parts.push(hardline);
  10264. }
  10265. }, "directives");
  10266. }
  10267. if (hasContent) {
  10268. parts.push(indent(concat([hardline, naked])));
  10269. }
  10270. parts.push(comments.printDanglingComments(path$$1, options));
  10271. parts.push(hardline, "}");
  10272. return concat(parts);
  10273. }
  10274. case "ReturnStatement":
  10275. parts.push("return");
  10276. if (n.argument) {
  10277. if (returnArgumentHasLeadingComment(options, n.argument)) {
  10278. parts.push(
  10279. concat([
  10280. " (",
  10281. indent(concat([hardline, path$$1.call(print, "argument")])),
  10282. hardline,
  10283. ")"
  10284. ])
  10285. );
  10286. } else if (
  10287. n.argument.type === "LogicalExpression" ||
  10288. n.argument.type === "BinaryExpression" ||
  10289. n.argument.type === "SequenceExpression"
  10290. ) {
  10291. parts.push(
  10292. group(
  10293. concat([
  10294. ifBreak(" (", " "),
  10295. indent(concat([softline, path$$1.call(print, "argument")])),
  10296. softline,
  10297. ifBreak(")")
  10298. ])
  10299. )
  10300. );
  10301. } else {
  10302. parts.push(" ", path$$1.call(print, "argument"));
  10303. }
  10304. }
  10305. if (hasDanglingComments(n)) {
  10306. parts.push(
  10307. " ",
  10308. comments.printDanglingComments(path$$1, options, /* sameIndent */ true)
  10309. );
  10310. }
  10311. parts.push(semi);
  10312. return concat(parts);
  10313. case "NewExpression":
  10314. case "CallExpression": {
  10315. const isNew = n.type === "NewExpression";
  10316. const optional = printOptionalToken(path$$1);
  10317. if (
  10318. // We want to keep CommonJS- and AMD-style require calls, and AMD-style
  10319. // define calls, as a unit.
  10320. // e.g. `define(["some/lib", (lib) => {`
  10321. (!isNew &&
  10322. n.callee.type === "Identifier" &&
  10323. (n.callee.name === "require" || n.callee.name === "define")) ||
  10324. n.callee.type === "Import" ||
  10325. // Template literals as single arguments
  10326. (n.arguments.length === 1 &&
  10327. isTemplateOnItsOwnLine(
  10328. n.arguments[0],
  10329. options.originalText,
  10330. options
  10331. )) ||
  10332. // Keep test declarations on a single line
  10333. // e.g. `it('long name', () => {`
  10334. (!isNew && isTestCall(n, path$$1.getParentNode()))
  10335. ) {
  10336. return concat([
  10337. isNew ? "new " : "",
  10338. path$$1.call(print, "callee"),
  10339. optional,
  10340. path$$1.call(print, "typeParameters"),
  10341. concat(["(", join(", ", path$$1.map(print, "arguments")), ")"])
  10342. ]);
  10343. }
  10344. // We detect calls on member lookups and possibly print them in a
  10345. // special chain format. See `printMemberChain` for more info.
  10346. if (!isNew && isMemberish(n.callee)) {
  10347. return printMemberChain(path$$1, options, print);
  10348. }
  10349. return concat([
  10350. isNew ? "new " : "",
  10351. path$$1.call(print, "callee"),
  10352. optional,
  10353. printFunctionTypeParameters(path$$1, options, print),
  10354. printArgumentsList(path$$1, options, print)
  10355. ]);
  10356. }
  10357. case "TSInterfaceDeclaration":
  10358. if (isNodeStartingWithDeclare(n, options)) {
  10359. parts.push("declare ");
  10360. }
  10361. parts.push(
  10362. n.abstract ? "abstract " : "",
  10363. printTypeScriptModifiers(path$$1, options, print),
  10364. "interface ",
  10365. path$$1.call(print, "id"),
  10366. n.typeParameters ? path$$1.call(print, "typeParameters") : "",
  10367. " "
  10368. );
  10369. if (n.heritage.length) {
  10370. parts.push(
  10371. group(
  10372. indent(
  10373. concat([
  10374. softline,
  10375. "extends ",
  10376. indent(join(concat([",", line]), path$$1.map(print, "heritage"))),
  10377. " "
  10378. ])
  10379. )
  10380. )
  10381. );
  10382. }
  10383. parts.push(path$$1.call(print, "body"));
  10384. return concat(parts);
  10385. case "ObjectExpression":
  10386. case "ObjectPattern":
  10387. case "ObjectTypeAnnotation":
  10388. case "TSInterfaceBody":
  10389. case "TSTypeLiteral": {
  10390. const isTypeAnnotation = n.type === "ObjectTypeAnnotation";
  10391. const parent = path$$1.getParentNode(0);
  10392. const shouldBreak =
  10393. n.type === "TSInterfaceBody" ||
  10394. (n.type === "ObjectPattern" &&
  10395. parent.type !== "FunctionDeclaration" &&
  10396. parent.type !== "FunctionExpression" &&
  10397. parent.type !== "ArrowFunctionExpression" &&
  10398. parent.type !== "AssignmentPattern" &&
  10399. n.properties.some(
  10400. property =>
  10401. property.value &&
  10402. (property.value.type === "ObjectPattern" ||
  10403. property.value.type === "ArrayPattern")
  10404. )) ||
  10405. (n.type !== "ObjectPattern" &&
  10406. util$1.hasNewlineInRange(
  10407. options.originalText,
  10408. options.locStart(n),
  10409. options.locEnd(n)
  10410. ));
  10411. const isFlowInterfaceLikeBody =
  10412. isTypeAnnotation &&
  10413. parent &&
  10414. (parent.type === "InterfaceDeclaration" ||
  10415. parent.type === "DeclareInterface" ||
  10416. parent.type === "DeclareClass") &&
  10417. path$$1.getName() === "body";
  10418. const separator = isFlowInterfaceLikeBody
  10419. ? ";"
  10420. : n.type === "TSInterfaceBody" || n.type === "TSTypeLiteral"
  10421. ? ifBreak(semi, ";")
  10422. : ",";
  10423. const fields = [];
  10424. const leftBrace = n.exact ? "{|" : "{";
  10425. const rightBrace = n.exact ? "|}" : "}";
  10426. let propertiesField;
  10427. if (n.type === "TSTypeLiteral") {
  10428. propertiesField = "members";
  10429. } else if (n.type === "TSInterfaceBody") {
  10430. propertiesField = "body";
  10431. } else {
  10432. propertiesField = "properties";
  10433. }
  10434. if (isTypeAnnotation) {
  10435. fields.push("indexers", "callProperties");
  10436. }
  10437. fields.push(propertiesField);
  10438. // Unfortunately, things are grouped together in the ast can be
  10439. // interleaved in the source code. So we need to reorder them before
  10440. // printing them.
  10441. const propsAndLoc = [];
  10442. fields.forEach(field => {
  10443. path$$1.each(childPath => {
  10444. const node = childPath.getValue();
  10445. propsAndLoc.push({
  10446. node: node,
  10447. printed: print(childPath),
  10448. loc: options.locStart(node)
  10449. });
  10450. }, field);
  10451. });
  10452. let separatorParts = [];
  10453. const props = propsAndLoc.sort((a, b) => a.loc - b.loc).map(prop => {
  10454. const result = concat(separatorParts.concat(group(prop.printed)));
  10455. separatorParts = [separator, line];
  10456. if (
  10457. prop.node.type === "TSPropertySignature" &&
  10458. util$1.hasNodeIgnoreComment(prop.node)
  10459. ) {
  10460. separatorParts.shift();
  10461. }
  10462. if (
  10463. utilShared.isNextLineEmpty(options.originalText, prop.node, options)
  10464. ) {
  10465. separatorParts.push(hardline);
  10466. }
  10467. return result;
  10468. });
  10469. const lastElem = util$1.getLast(n[propertiesField]);
  10470. const canHaveTrailingSeparator = !(
  10471. lastElem &&
  10472. (lastElem.type === "RestProperty" ||
  10473. lastElem.type === "RestElement" ||
  10474. lastElem.type === "ExperimentalRestProperty" ||
  10475. util$1.hasNodeIgnoreComment(lastElem))
  10476. );
  10477. let content;
  10478. if (props.length === 0 && !n.typeAnnotation) {
  10479. if (!hasDanglingComments(n)) {
  10480. return concat([leftBrace, rightBrace]);
  10481. }
  10482. content = group(
  10483. concat([
  10484. leftBrace,
  10485. comments.printDanglingComments(path$$1, options),
  10486. softline,
  10487. rightBrace,
  10488. printOptionalToken(path$$1)
  10489. ])
  10490. );
  10491. } else {
  10492. content = concat([
  10493. leftBrace,
  10494. indent(
  10495. concat([options.bracketSpacing ? line : softline, concat(props)])
  10496. ),
  10497. ifBreak(
  10498. canHaveTrailingSeparator &&
  10499. (separator !== "," || shouldPrintComma(options))
  10500. ? separator
  10501. : ""
  10502. ),
  10503. concat([options.bracketSpacing ? line : softline, rightBrace]),
  10504. printOptionalToken(path$$1),
  10505. printTypeAnnotation(path$$1, options, print)
  10506. ]);
  10507. }
  10508. // If we inline the object as first argument of the parent, we don't want
  10509. // to create another group so that the object breaks before the return
  10510. // type
  10511. const parentParentParent = path$$1.getParentNode(2);
  10512. if (
  10513. (n.type === "ObjectPattern" &&
  10514. parent &&
  10515. shouldHugArguments(parent) &&
  10516. parent.params[0] === n) ||
  10517. (shouldHugType(n) &&
  10518. parentParentParent &&
  10519. shouldHugArguments(parentParentParent) &&
  10520. parentParentParent.params[0].typeAnnotation &&
  10521. parentParentParent.params[0].typeAnnotation.typeAnnotation === n)
  10522. ) {
  10523. return content;
  10524. }
  10525. return group(content, { shouldBreak });
  10526. }
  10527. // Babel 6
  10528. case "ObjectProperty": // Non-standard AST node type.
  10529. case "Property":
  10530. if (n.method || n.kind === "get" || n.kind === "set") {
  10531. return printMethod(path$$1, options, print);
  10532. }
  10533. if (n.shorthand) {
  10534. parts.push(path$$1.call(print, "value"));
  10535. } else {
  10536. let printedLeft;
  10537. if (n.computed) {
  10538. printedLeft = concat(["[", path$$1.call(print, "key"), "]"]);
  10539. } else {
  10540. printedLeft = printPropertyKey(path$$1, options, print);
  10541. }
  10542. parts.push(
  10543. printAssignment(
  10544. n.key,
  10545. printedLeft,
  10546. ":",
  10547. n.value,
  10548. path$$1.call(print, "value"),
  10549. options
  10550. )
  10551. );
  10552. }
  10553. return concat(parts); // Babel 6
  10554. case "ClassMethod":
  10555. if (n.static) {
  10556. parts.push("static ");
  10557. }
  10558. parts = parts.concat(printObjectMethod(path$$1, options, print));
  10559. return concat(parts); // Babel 6
  10560. case "ObjectMethod":
  10561. return printObjectMethod(path$$1, options, print);
  10562. case "Decorator":
  10563. return concat(["@", path$$1.call(print, "expression")]);
  10564. case "ArrayExpression":
  10565. case "ArrayPattern":
  10566. if (n.elements.length === 0) {
  10567. if (!hasDanglingComments(n)) {
  10568. parts.push("[]");
  10569. } else {
  10570. parts.push(
  10571. group(
  10572. concat([
  10573. "[",
  10574. comments.printDanglingComments(path$$1, options),
  10575. softline,
  10576. "]"
  10577. ])
  10578. )
  10579. );
  10580. }
  10581. } else {
  10582. const lastElem = util$1.getLast(n.elements);
  10583. const canHaveTrailingComma = !(
  10584. lastElem && lastElem.type === "RestElement"
  10585. );
  10586. // JavaScript allows you to have empty elements in an array which
  10587. // changes its length based on the number of commas. The algorithm
  10588. // is that if the last argument is null, we need to force insert
  10589. // a comma to ensure JavaScript recognizes it.
  10590. // [,].length === 1
  10591. // [1,].length === 1
  10592. // [1,,].length === 2
  10593. //
  10594. // Note that privateUtil.getLast returns null if the array is empty, but
  10595. // we already check for an empty array just above so we are safe
  10596. const needsForcedTrailingComma =
  10597. canHaveTrailingComma && lastElem === null;
  10598. parts.push(
  10599. group(
  10600. concat([
  10601. "[",
  10602. indent(
  10603. concat([
  10604. softline,
  10605. printArrayItems(path$$1, options, "elements", print)
  10606. ])
  10607. ),
  10608. needsForcedTrailingComma ? "," : "",
  10609. ifBreak(
  10610. canHaveTrailingComma &&
  10611. !needsForcedTrailingComma &&
  10612. shouldPrintComma(options)
  10613. ? ","
  10614. : ""
  10615. ),
  10616. comments.printDanglingComments(
  10617. path$$1,
  10618. options,
  10619. /* sameIndent */ true
  10620. ),
  10621. softline,
  10622. "]"
  10623. ])
  10624. )
  10625. );
  10626. }
  10627. parts.push(
  10628. printOptionalToken(path$$1),
  10629. printTypeAnnotation(path$$1, options, print)
  10630. );
  10631. return concat(parts);
  10632. case "SequenceExpression": {
  10633. const parent = path$$1.getParentNode(0);
  10634. if (
  10635. parent.type === "ExpressionStatement" ||
  10636. parent.type === "ForStatement"
  10637. ) {
  10638. // For ExpressionStatements and for-loop heads, which are among
  10639. // the few places a SequenceExpression appears unparenthesized, we want
  10640. // to indent expressions after the first.
  10641. const parts = [];
  10642. path$$1.each(p => {
  10643. if (p.getName() === 0) {
  10644. parts.push(print(p));
  10645. } else {
  10646. parts.push(",", indent(concat([line, print(p)])));
  10647. }
  10648. }, "expressions");
  10649. return group(concat(parts));
  10650. }
  10651. return group(
  10652. concat([join(concat([",", line]), path$$1.map(print, "expressions"))])
  10653. );
  10654. }
  10655. case "ThisExpression":
  10656. return "this";
  10657. case "Super":
  10658. return "super";
  10659. case "NullLiteral": // Babel 6 Literal split
  10660. return "null";
  10661. case "RegExpLiteral": // Babel 6 Literal split
  10662. return printRegex(n);
  10663. case "NumericLiteral": // Babel 6 Literal split
  10664. return util$1.printNumber(n.extra.raw);
  10665. case "BooleanLiteral": // Babel 6 Literal split
  10666. case "StringLiteral": // Babel 6 Literal split
  10667. case "Literal": {
  10668. if (n.regex) {
  10669. return printRegex(n.regex);
  10670. }
  10671. if (typeof n.value === "number") {
  10672. return util$1.printNumber(n.raw);
  10673. }
  10674. if (typeof n.value !== "string") {
  10675. return "" + n.value;
  10676. }
  10677. // TypeScript workaround for eslint/typescript-eslint-parser#267
  10678. // See corresponding workaround in needs-parens.js
  10679. const grandParent = path$$1.getParentNode(1);
  10680. const isTypeScriptDirective =
  10681. options.parser === "typescript" &&
  10682. typeof n.value === "string" &&
  10683. grandParent &&
  10684. (grandParent.type === "Program" ||
  10685. grandParent.type === "BlockStatement");
  10686. return nodeStr(n, options, isTypeScriptDirective);
  10687. }
  10688. case "Directive":
  10689. return path$$1.call(print, "value"); // Babel 6
  10690. case "DirectiveLiteral":
  10691. return nodeStr(n, options);
  10692. case "UnaryExpression":
  10693. parts.push(n.operator);
  10694. if (/[a-z]$/.test(n.operator)) {
  10695. parts.push(" ");
  10696. }
  10697. parts.push(path$$1.call(print, "argument"));
  10698. return concat(parts);
  10699. case "UpdateExpression":
  10700. parts.push(path$$1.call(print, "argument"), n.operator);
  10701. if (n.prefix) {
  10702. parts.reverse();
  10703. }
  10704. return concat(parts);
  10705. case "ConditionalExpression":
  10706. return formatTernaryOperator(path$$1, options, print, {
  10707. beforeParts: () => [path$$1.call(print, "test")],
  10708. afterParts: breakClosingParen => [breakClosingParen ? softline : ""]
  10709. });
  10710. case "VariableDeclaration": {
  10711. const printed = path$$1.map(childPath => {
  10712. return print(childPath);
  10713. }, "declarations");
  10714. // We generally want to terminate all variable declarations with a
  10715. // semicolon, except when they in the () part of for loops.
  10716. const parentNode = path$$1.getParentNode();
  10717. const isParentForLoop =
  10718. parentNode.type === "ForStatement" ||
  10719. parentNode.type === "ForInStatement" ||
  10720. parentNode.type === "ForOfStatement" ||
  10721. parentNode.type === "ForAwaitStatement";
  10722. const hasValue = n.declarations.some(decl => decl.init);
  10723. let firstVariable;
  10724. if (printed.length === 1) {
  10725. firstVariable = printed[0];
  10726. } else if (printed.length > 1) {
  10727. // Indent first var to comply with eslint one-var rule
  10728. firstVariable = indent(printed[0]);
  10729. }
  10730. parts = [
  10731. isNodeStartingWithDeclare(n, options) ? "declare " : "",
  10732. n.kind,
  10733. firstVariable ? concat([" ", firstVariable]) : "",
  10734. indent(
  10735. concat(
  10736. printed
  10737. .slice(1)
  10738. .map(p =>
  10739. concat([",", hasValue && !isParentForLoop ? hardline : line, p])
  10740. )
  10741. )
  10742. )
  10743. ];
  10744. if (!(isParentForLoop && parentNode.body !== n)) {
  10745. parts.push(semi);
  10746. }
  10747. return group(concat(parts));
  10748. }
  10749. case "VariableDeclarator":
  10750. return printAssignment(
  10751. n.id,
  10752. concat([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]),
  10753. " =",
  10754. n.init,
  10755. n.init && path$$1.call(print, "init"),
  10756. options
  10757. );
  10758. case "WithStatement":
  10759. return group(
  10760. concat([
  10761. "with (",
  10762. path$$1.call(print, "object"),
  10763. ")",
  10764. adjustClause(n.body, path$$1.call(print, "body"))
  10765. ])
  10766. );
  10767. case "IfStatement": {
  10768. const con = adjustClause(n.consequent, path$$1.call(print, "consequent"));
  10769. const opening = group(
  10770. concat([
  10771. "if (",
  10772. group(
  10773. concat([
  10774. indent(concat([softline, path$$1.call(print, "test")])),
  10775. softline
  10776. ])
  10777. ),
  10778. ")",
  10779. con
  10780. ])
  10781. );
  10782. parts.push(opening);
  10783. if (n.alternate) {
  10784. const commentOnOwnLine =
  10785. (hasTrailingComment(n.consequent) &&
  10786. n.consequent.comments.some(
  10787. comment =>
  10788. comment.trailing && !util$1.isBlockComment(comment)
  10789. )) ||
  10790. needsHardlineAfterDanglingComment(n);
  10791. const elseOnSameLine =
  10792. n.consequent.type === "BlockStatement" && !commentOnOwnLine;
  10793. parts.push(elseOnSameLine ? " " : hardline);
  10794. if (hasDanglingComments(n)) {
  10795. parts.push(
  10796. comments.printDanglingComments(path$$1, options, true),
  10797. commentOnOwnLine ? hardline : " "
  10798. );
  10799. }
  10800. parts.push(
  10801. "else",
  10802. group(
  10803. adjustClause(
  10804. n.alternate,
  10805. path$$1.call(print, "alternate"),
  10806. n.alternate.type === "IfStatement"
  10807. )
  10808. )
  10809. );
  10810. }
  10811. return concat(parts);
  10812. }
  10813. case "ForStatement": {
  10814. const body = adjustClause(n.body, path$$1.call(print, "body"));
  10815. // We want to keep dangling comments above the loop to stay consistent.
  10816. // Any comment positioned between the for statement and the parentheses
  10817. // is going to be printed before the statement.
  10818. const dangling = comments.printDanglingComments(
  10819. path$$1,
  10820. options,
  10821. /* sameLine */ true
  10822. );
  10823. const printedComments = dangling ? concat([dangling, softline]) : "";
  10824. if (!n.init && !n.test && !n.update) {
  10825. return concat([printedComments, group(concat(["for (;;)", body]))]);
  10826. }
  10827. return concat([
  10828. printedComments,
  10829. group(
  10830. concat([
  10831. "for (",
  10832. group(
  10833. concat([
  10834. indent(
  10835. concat([
  10836. softline,
  10837. path$$1.call(print, "init"),
  10838. ";",
  10839. line,
  10840. path$$1.call(print, "test"),
  10841. ";",
  10842. line,
  10843. path$$1.call(print, "update")
  10844. ])
  10845. ),
  10846. softline
  10847. ])
  10848. ),
  10849. ")",
  10850. body
  10851. ])
  10852. )
  10853. ]);
  10854. }
  10855. case "WhileStatement":
  10856. return group(
  10857. concat([
  10858. "while (",
  10859. group(
  10860. concat([
  10861. indent(concat([softline, path$$1.call(print, "test")])),
  10862. softline
  10863. ])
  10864. ),
  10865. ")",
  10866. adjustClause(n.body, path$$1.call(print, "body"))
  10867. ])
  10868. );
  10869. case "ForInStatement":
  10870. // Note: esprima can't actually parse "for each (".
  10871. return group(
  10872. concat([
  10873. n.each ? "for each (" : "for (",
  10874. path$$1.call(print, "left"),
  10875. " in ",
  10876. path$$1.call(print, "right"),
  10877. ")",
  10878. adjustClause(n.body, path$$1.call(print, "body"))
  10879. ])
  10880. );
  10881. case "ForOfStatement":
  10882. case "ForAwaitStatement": {
  10883. // Babylon 7 removed ForAwaitStatement in favor of ForOfStatement
  10884. // with `"await": true`:
  10885. // https://github.com/estree/estree/pull/138
  10886. const isAwait = n.type === "ForAwaitStatement" || n.await;
  10887. return group(
  10888. concat([
  10889. "for",
  10890. isAwait ? " await" : "",
  10891. " (",
  10892. path$$1.call(print, "left"),
  10893. " of ",
  10894. path$$1.call(print, "right"),
  10895. ")",
  10896. adjustClause(n.body, path$$1.call(print, "body"))
  10897. ])
  10898. );
  10899. }
  10900. case "DoWhileStatement": {
  10901. const clause = adjustClause(n.body, path$$1.call(print, "body"));
  10902. const doBody = group(concat(["do", clause]));
  10903. parts = [doBody];
  10904. if (n.body.type === "BlockStatement") {
  10905. parts.push(" ");
  10906. } else {
  10907. parts.push(hardline);
  10908. }
  10909. parts.push("while (");
  10910. parts.push(
  10911. group(
  10912. concat([
  10913. indent(concat([softline, path$$1.call(print, "test")])),
  10914. softline
  10915. ])
  10916. ),
  10917. ")",
  10918. semi
  10919. );
  10920. return concat(parts);
  10921. }
  10922. case "DoExpression":
  10923. return concat(["do ", path$$1.call(print, "body")]);
  10924. case "BreakStatement":
  10925. parts.push("break");
  10926. if (n.label) {
  10927. parts.push(" ", path$$1.call(print, "label"));
  10928. }
  10929. parts.push(semi);
  10930. return concat(parts);
  10931. case "ContinueStatement":
  10932. parts.push("continue");
  10933. if (n.label) {
  10934. parts.push(" ", path$$1.call(print, "label"));
  10935. }
  10936. parts.push(semi);
  10937. return concat(parts);
  10938. case "LabeledStatement":
  10939. if (n.body.type === "EmptyStatement") {
  10940. return concat([path$$1.call(print, "label"), ":;"]);
  10941. }
  10942. return concat([
  10943. path$$1.call(print, "label"),
  10944. ": ",
  10945. path$$1.call(print, "body")
  10946. ]);
  10947. case "TryStatement":
  10948. return concat([
  10949. "try ",
  10950. path$$1.call(print, "block"),
  10951. n.handler ? concat([" ", path$$1.call(print, "handler")]) : "",
  10952. n.finalizer ? concat([" finally ", path$$1.call(print, "finalizer")]) : ""
  10953. ]);
  10954. case "CatchClause":
  10955. return concat([
  10956. "catch ",
  10957. n.param ? concat(["(", path$$1.call(print, "param"), ") "]) : "",
  10958. path$$1.call(print, "body")
  10959. ]);
  10960. case "ThrowStatement":
  10961. return concat(["throw ", path$$1.call(print, "argument"), semi]);
  10962. // Note: ignoring n.lexical because it has no printing consequences.
  10963. case "SwitchStatement":
  10964. return concat([
  10965. group(
  10966. concat([
  10967. "switch (",
  10968. indent(concat([softline, path$$1.call(print, "discriminant")])),
  10969. softline,
  10970. ")"
  10971. ])
  10972. ),
  10973. " {",
  10974. n.cases.length > 0
  10975. ? indent(
  10976. concat([
  10977. hardline,
  10978. join(
  10979. hardline,
  10980. path$$1.map(casePath => {
  10981. const caseNode = casePath.getValue();
  10982. return concat([
  10983. casePath.call(print),
  10984. n.cases.indexOf(caseNode) !== n.cases.length - 1 &&
  10985. utilShared.isNextLineEmpty(
  10986. options.originalText,
  10987. caseNode,
  10988. options
  10989. )
  10990. ? hardline
  10991. : ""
  10992. ]);
  10993. }, "cases")
  10994. )
  10995. ])
  10996. )
  10997. : "",
  10998. hardline,
  10999. "}"
  11000. ]);
  11001. case "SwitchCase": {
  11002. if (n.test) {
  11003. parts.push("case ", path$$1.call(print, "test"), ":");
  11004. } else {
  11005. parts.push("default:");
  11006. }
  11007. const consequent = n.consequent.filter(
  11008. node => node.type !== "EmptyStatement"
  11009. );
  11010. if (consequent.length > 0) {
  11011. const cons = path$$1.call(consequentPath => {
  11012. return printStatementSequence(consequentPath, options, print);
  11013. }, "consequent");
  11014. parts.push(
  11015. consequent.length === 1 && consequent[0].type === "BlockStatement"
  11016. ? concat([" ", cons])
  11017. : indent(concat([hardline, cons]))
  11018. );
  11019. }
  11020. return concat(parts);
  11021. }
  11022. // JSX extensions below.
  11023. case "DebuggerStatement":
  11024. return concat(["debugger", semi]);
  11025. case "JSXAttribute":
  11026. parts.push(path$$1.call(print, "name"));
  11027. if (n.value) {
  11028. let res;
  11029. if (isStringLiteral(n.value)) {
  11030. const value = rawText(n.value);
  11031. res = '"' + value.slice(1, -1).replace(/"/g, "&quot;") + '"';
  11032. } else {
  11033. res = path$$1.call(print, "value");
  11034. }
  11035. parts.push("=", res);
  11036. }
  11037. return concat(parts);
  11038. case "JSXIdentifier":
  11039. // Can be removed when this is fixed:
  11040. // https://github.com/eslint/typescript-eslint-parser/issues/337
  11041. if (!n.name) {
  11042. return "this";
  11043. }
  11044. return "" + n.name;
  11045. case "JSXNamespacedName":
  11046. return join(":", [
  11047. path$$1.call(print, "namespace"),
  11048. path$$1.call(print, "name")
  11049. ]);
  11050. case "JSXMemberExpression":
  11051. return join(".", [
  11052. path$$1.call(print, "object"),
  11053. path$$1.call(print, "property")
  11054. ]);
  11055. case "TSQualifiedName":
  11056. return join(".", [path$$1.call(print, "left"), path$$1.call(print, "right")]);
  11057. case "JSXSpreadAttribute":
  11058. case "JSXSpreadChild": {
  11059. return concat([
  11060. "{",
  11061. path$$1.call(p => {
  11062. const printed = concat(["...", print(p)]);
  11063. const n = p.getValue();
  11064. if (!n.comments || !n.comments.length) {
  11065. return printed;
  11066. }
  11067. return concat([
  11068. indent(
  11069. concat([
  11070. softline,
  11071. comments.printComments(p, () => printed, options)
  11072. ])
  11073. ),
  11074. softline
  11075. ]);
  11076. }, n.type === "JSXSpreadAttribute" ? "argument" : "expression"),
  11077. "}"
  11078. ]);
  11079. }
  11080. case "JSXExpressionContainer": {
  11081. const parent = path$$1.getParentNode(0);
  11082. const preventInline =
  11083. parent.type === "JSXAttribute" &&
  11084. n.expression.comments &&
  11085. n.expression.comments.length > 0;
  11086. const shouldInline =
  11087. !preventInline &&
  11088. (n.expression.type === "ArrayExpression" ||
  11089. n.expression.type === "ObjectExpression" ||
  11090. n.expression.type === "ArrowFunctionExpression" ||
  11091. n.expression.type === "CallExpression" ||
  11092. n.expression.type === "FunctionExpression" ||
  11093. n.expression.type === "JSXEmptyExpression" ||
  11094. n.expression.type === "TemplateLiteral" ||
  11095. n.expression.type === "TaggedTemplateExpression" ||
  11096. n.expression.type === "DoExpression" ||
  11097. (isJSXNode(parent) &&
  11098. (n.expression.type === "ConditionalExpression" ||
  11099. isBinaryish(n.expression))));
  11100. if (shouldInline) {
  11101. return group(
  11102. concat(["{", path$$1.call(print, "expression"), lineSuffixBoundary, "}"])
  11103. );
  11104. }
  11105. return group(
  11106. concat([
  11107. "{",
  11108. indent(concat([softline, path$$1.call(print, "expression")])),
  11109. softline,
  11110. lineSuffixBoundary,
  11111. "}"
  11112. ])
  11113. );
  11114. }
  11115. case "JSXFragment":
  11116. case "TSJsxFragment":
  11117. case "JSXElement": {
  11118. const elem = comments.printComments(
  11119. path$$1,
  11120. () => printJSXElement(path$$1, options, print),
  11121. options
  11122. );
  11123. return maybeWrapJSXElementInParens(path$$1, elem);
  11124. }
  11125. case "JSXOpeningElement": {
  11126. const n = path$$1.getValue();
  11127. const nameHasComments =
  11128. n.name && n.name.comments && n.name.comments.length > 0;
  11129. // Don't break self-closing elements with no attributes and no comments
  11130. if (n.selfClosing && !n.attributes.length && !nameHasComments) {
  11131. return concat(["<", path$$1.call(print, "name"), " />"]);
  11132. }
  11133. // don't break up opening elements with a single long text attribute
  11134. if (
  11135. n.attributes &&
  11136. n.attributes.length === 1 &&
  11137. n.attributes[0].value &&
  11138. isStringLiteral(n.attributes[0].value) &&
  11139. !n.attributes[0].value.value.includes("\n") &&
  11140. // We should break for the following cases:
  11141. // <div
  11142. // // comment
  11143. // attr="value"
  11144. // >
  11145. // <div
  11146. // attr="value"
  11147. // // comment
  11148. // >
  11149. !nameHasComments &&
  11150. (!n.attributes[0].comments || !n.attributes[0].comments.length)
  11151. ) {
  11152. return group(
  11153. concat([
  11154. "<",
  11155. path$$1.call(print, "name"),
  11156. " ",
  11157. concat(path$$1.map(print, "attributes")),
  11158. n.selfClosing ? " />" : ">"
  11159. ])
  11160. );
  11161. }
  11162. const lastAttrHasTrailingComments =
  11163. n.attributes.length &&
  11164. hasTrailingComment(util$1.getLast(n.attributes));
  11165. const bracketSameLine =
  11166. options.jsxBracketSameLine &&
  11167. // We should print the bracket in a new line for the following cases:
  11168. // <div
  11169. // // comment
  11170. // >
  11171. // <div
  11172. // attr // comment
  11173. // >
  11174. (!nameHasComments || n.attributes.length) &&
  11175. !lastAttrHasTrailingComments;
  11176. // We should print the opening element expanded if any prop value is a
  11177. // string literal with newlines
  11178. const shouldBreak =
  11179. n.attributes &&
  11180. n.attributes.some(
  11181. attr =>
  11182. attr.value &&
  11183. isStringLiteral(attr.value) &&
  11184. attr.value.value.includes("\n")
  11185. );
  11186. return group(
  11187. concat([
  11188. "<",
  11189. path$$1.call(print, "name"),
  11190. concat([
  11191. indent(
  11192. concat(
  11193. path$$1.map(attr => concat([line, print(attr)]), "attributes")
  11194. )
  11195. ),
  11196. n.selfClosing ? line : bracketSameLine ? ">" : softline
  11197. ]),
  11198. n.selfClosing ? "/>" : bracketSameLine ? "" : ">"
  11199. ]),
  11200. { shouldBreak }
  11201. );
  11202. }
  11203. case "JSXClosingElement":
  11204. return concat(["</", path$$1.call(print, "name"), ">"]);
  11205. case "JSXOpeningFragment":
  11206. case "JSXClosingFragment":
  11207. case "TSJsxOpeningFragment":
  11208. case "TSJsxClosingFragment": {
  11209. const hasComment = n.comments && n.comments.length;
  11210. const hasOwnLineComment =
  11211. hasComment && !n.comments.every(util$1.isBlockComment);
  11212. const isOpeningFragment =
  11213. n.type === "JSXOpeningFragment" || n.type === "TSJsxOpeningFragment";
  11214. return concat([
  11215. isOpeningFragment ? "<" : "</",
  11216. indent(
  11217. concat([
  11218. hasOwnLineComment
  11219. ? hardline
  11220. : hasComment && !isOpeningFragment
  11221. ? " "
  11222. : "",
  11223. comments.printDanglingComments(path$$1, options, true)
  11224. ])
  11225. ),
  11226. hasOwnLineComment ? hardline : "",
  11227. ">"
  11228. ]);
  11229. }
  11230. case "JSXText":
  11231. /* istanbul ignore next */
  11232. throw new Error("JSXTest should be handled by JSXElement");
  11233. case "JSXEmptyExpression": {
  11234. const requiresHardline =
  11235. n.comments && !n.comments.every(util$1.isBlockComment);
  11236. return concat([
  11237. comments.printDanglingComments(
  11238. path$$1,
  11239. options,
  11240. /* sameIndent */ !requiresHardline
  11241. ),
  11242. requiresHardline ? hardline : ""
  11243. ]);
  11244. }
  11245. case "ClassBody":
  11246. if (!n.comments && n.body.length === 0) {
  11247. return "{}";
  11248. }
  11249. return concat([
  11250. "{",
  11251. n.body.length > 0
  11252. ? indent(
  11253. concat([
  11254. hardline,
  11255. path$$1.call(bodyPath => {
  11256. return printStatementSequence(bodyPath, options, print);
  11257. }, "body")
  11258. ])
  11259. )
  11260. : comments.printDanglingComments(path$$1, options),
  11261. hardline,
  11262. "}"
  11263. ]);
  11264. case "ClassProperty":
  11265. case "TSAbstractClassProperty":
  11266. case "ClassPrivateProperty": {
  11267. if (n.accessibility) {
  11268. parts.push(n.accessibility + " ");
  11269. }
  11270. if (n.static) {
  11271. parts.push("static ");
  11272. }
  11273. if (n.type === "TSAbstractClassProperty") {
  11274. parts.push("abstract ");
  11275. }
  11276. if (n.readonly) {
  11277. parts.push("readonly ");
  11278. }
  11279. const variance = getFlowVariance(n);
  11280. if (variance) {
  11281. parts.push(variance);
  11282. }
  11283. if (n.computed) {
  11284. parts.push("[", path$$1.call(print, "key"), "]");
  11285. } else {
  11286. parts.push(printPropertyKey(path$$1, options, print));
  11287. }
  11288. parts.push(printTypeAnnotation(path$$1, options, print));
  11289. if (n.value) {
  11290. parts.push(
  11291. " =",
  11292. printAssignmentRight(
  11293. n.value,
  11294. path$$1.call(print, "value"),
  11295. false, // canBreak
  11296. options
  11297. )
  11298. );
  11299. }
  11300. parts.push(semi);
  11301. return concat(parts);
  11302. }
  11303. case "ClassDeclaration":
  11304. case "ClassExpression":
  11305. case "TSAbstractClassDeclaration":
  11306. if (isNodeStartingWithDeclare(n, options)) {
  11307. parts.push("declare ");
  11308. }
  11309. parts.push(concat(printClass(path$$1, options, print)));
  11310. return concat(parts);
  11311. case "TSInterfaceHeritage":
  11312. parts.push(path$$1.call(print, "id"));
  11313. if (n.typeParameters) {
  11314. parts.push(path$$1.call(print, "typeParameters"));
  11315. }
  11316. return concat(parts);
  11317. case "TemplateElement":
  11318. return join(literalline, n.value.raw.split(/\r?\n/g));
  11319. case "TemplateLiteral": {
  11320. const expressions = path$$1.map(print, "expressions");
  11321. parts.push("`");
  11322. path$$1.each(childPath => {
  11323. const i = childPath.getName();
  11324. parts.push(print(childPath));
  11325. if (i < expressions.length) {
  11326. // For a template literal of the following form:
  11327. // `someQuery {
  11328. // ${call({
  11329. // a,
  11330. // b,
  11331. // })}
  11332. // }`
  11333. // the expression is on its own line (there is a \n in the previous
  11334. // quasi literal), therefore we want to indent the JavaScript
  11335. // expression inside at the beginning of ${ instead of the beginning
  11336. // of the `.
  11337. const tabWidth = options.tabWidth;
  11338. const indentSize = util$1.getIndentSize(
  11339. childPath.getValue().value.raw,
  11340. tabWidth
  11341. );
  11342. let printed = expressions[i];
  11343. if (
  11344. (n.expressions[i].comments && n.expressions[i].comments.length) ||
  11345. n.expressions[i].type === "MemberExpression" ||
  11346. n.expressions[i].type === "ConditionalExpression"
  11347. ) {
  11348. printed = concat([indent(concat([softline, printed])), softline]);
  11349. }
  11350. const aligned = addAlignmentToDoc(printed, indentSize, tabWidth);
  11351. parts.push(group(concat(["${", aligned, lineSuffixBoundary, "}"])));
  11352. }
  11353. }, "quasis");
  11354. parts.push("`");
  11355. return concat(parts);
  11356. }
  11357. // These types are unprintable because they serve as abstract
  11358. // supertypes for other (printable) types.
  11359. case "TaggedTemplateExpression":
  11360. return concat([path$$1.call(print, "tag"), path$$1.call(print, "quasi")]);
  11361. case "Node":
  11362. case "Printable":
  11363. case "SourceLocation":
  11364. case "Position":
  11365. case "Statement":
  11366. case "Function":
  11367. case "Pattern":
  11368. case "Expression":
  11369. case "Declaration":
  11370. case "Specifier":
  11371. case "NamedSpecifier":
  11372. case "Comment":
  11373. case "MemberTypeAnnotation": // Flow
  11374. case "Type":
  11375. /* istanbul ignore next */
  11376. throw new Error("unprintable type: " + JSON.stringify(n.type));
  11377. // Type Annotations for Facebook Flow, typically stripped out or
  11378. // transformed away before printing.
  11379. case "TypeAnnotation":
  11380. case "TSTypeAnnotation":
  11381. if (n.typeAnnotation) {
  11382. return path$$1.call(print, "typeAnnotation");
  11383. }
  11384. /* istanbul ignore next */
  11385. return "";
  11386. case "TSTupleType":
  11387. case "TupleTypeAnnotation": {
  11388. const typesField = n.type === "TSTupleType" ? "elementTypes" : "types";
  11389. return group(
  11390. concat([
  11391. "[",
  11392. indent(
  11393. concat([
  11394. softline,
  11395. printArrayItems(path$$1, options, typesField, print)
  11396. ])
  11397. ),
  11398. // TypeScript doesn't support trailing commas in tuple types
  11399. n.type === "TSTupleType"
  11400. ? ""
  11401. : ifBreak(shouldPrintComma(options) ? "," : ""),
  11402. comments.printDanglingComments(path$$1, options, /* sameIndent */ true),
  11403. softline,
  11404. "]"
  11405. ])
  11406. );
  11407. }
  11408. case "ExistsTypeAnnotation":
  11409. return "*";
  11410. case "EmptyTypeAnnotation":
  11411. return "empty";
  11412. case "AnyTypeAnnotation":
  11413. return "any";
  11414. case "MixedTypeAnnotation":
  11415. return "mixed";
  11416. case "ArrayTypeAnnotation":
  11417. return concat([path$$1.call(print, "elementType"), "[]"]);
  11418. case "BooleanTypeAnnotation":
  11419. return "boolean";
  11420. case "BooleanLiteralTypeAnnotation":
  11421. return "" + n.value;
  11422. case "DeclareClass":
  11423. return printFlowDeclaration(path$$1, printClass(path$$1, options, print));
  11424. case "DeclareFunction":
  11425. // For TypeScript the DeclareFunction node shares the AST
  11426. // structure with FunctionDeclaration
  11427. if (n.params) {
  11428. return concat([
  11429. "declare ",
  11430. printFunctionDeclaration(path$$1, print, options),
  11431. semi
  11432. ]);
  11433. }
  11434. return printFlowDeclaration(path$$1, [
  11435. "function ",
  11436. path$$1.call(print, "id"),
  11437. n.predicate ? " " : "",
  11438. path$$1.call(print, "predicate"),
  11439. semi
  11440. ]);
  11441. case "DeclareModule":
  11442. return printFlowDeclaration(path$$1, [
  11443. "module ",
  11444. path$$1.call(print, "id"),
  11445. " ",
  11446. path$$1.call(print, "body")
  11447. ]);
  11448. case "DeclareModuleExports":
  11449. return printFlowDeclaration(path$$1, [
  11450. "module.exports",
  11451. ": ",
  11452. path$$1.call(print, "typeAnnotation"),
  11453. semi
  11454. ]);
  11455. case "DeclareVariable":
  11456. return printFlowDeclaration(path$$1, ["var ", path$$1.call(print, "id"), semi]);
  11457. case "DeclareExportAllDeclaration":
  11458. return concat(["declare export * from ", path$$1.call(print, "source")]);
  11459. case "DeclareExportDeclaration":
  11460. return concat(["declare ", printExportDeclaration(path$$1, options, print)]);
  11461. case "DeclareOpaqueType":
  11462. case "OpaqueType": {
  11463. parts.push(
  11464. "opaque type ",
  11465. path$$1.call(print, "id"),
  11466. path$$1.call(print, "typeParameters")
  11467. );
  11468. if (n.supertype) {
  11469. parts.push(": ", path$$1.call(print, "supertype"));
  11470. }
  11471. if (n.impltype) {
  11472. parts.push(" = ", path$$1.call(print, "impltype"));
  11473. }
  11474. parts.push(semi);
  11475. if (n.type === "DeclareOpaqueType") {
  11476. return printFlowDeclaration(path$$1, parts);
  11477. }
  11478. return concat(parts);
  11479. }
  11480. case "FunctionTypeAnnotation":
  11481. case "TSFunctionType": {
  11482. // FunctionTypeAnnotation is ambiguous:
  11483. // declare function foo(a: B): void; OR
  11484. // var A: (a: B) => void;
  11485. const parent = path$$1.getParentNode(0);
  11486. const parentParent = path$$1.getParentNode(1);
  11487. const parentParentParent = path$$1.getParentNode(2);
  11488. let isArrowFunctionTypeAnnotation =
  11489. n.type === "TSFunctionType" ||
  11490. !(
  11491. (parent.type === "ObjectTypeProperty" &&
  11492. !getFlowVariance(parent) &&
  11493. !parent.optional &&
  11494. options.locStart(parent) === options.locStart(n)) ||
  11495. parent.type === "ObjectTypeCallProperty" ||
  11496. (parentParentParent && parentParentParent.type === "DeclareFunction")
  11497. );
  11498. let needsColon =
  11499. isArrowFunctionTypeAnnotation &&
  11500. (parent.type === "TypeAnnotation" ||
  11501. parent.type === "TSTypeAnnotation");
  11502. // Sadly we can't put it inside of FastPath::needsColon because we are
  11503. // printing ":" as part of the expression and it would put parenthesis
  11504. // around :(
  11505. const needsParens =
  11506. needsColon &&
  11507. isArrowFunctionTypeAnnotation &&
  11508. (parent.type === "TypeAnnotation" ||
  11509. parent.type === "TSTypeAnnotation") &&
  11510. parentParent.type === "ArrowFunctionExpression";
  11511. if (isObjectTypePropertyAFunction(parent, options)) {
  11512. isArrowFunctionTypeAnnotation = true;
  11513. needsColon = true;
  11514. }
  11515. if (needsParens) {
  11516. parts.push("(");
  11517. }
  11518. parts.push(
  11519. printFunctionParams(
  11520. path$$1,
  11521. print,
  11522. options,
  11523. /* expandArg */ false,
  11524. /* printTypeParams */ true
  11525. )
  11526. );
  11527. // The returnType is not wrapped in a TypeAnnotation, so the colon
  11528. // needs to be added separately.
  11529. if (n.returnType || n.predicate || n.typeAnnotation) {
  11530. parts.push(
  11531. isArrowFunctionTypeAnnotation ? " => " : ": ",
  11532. path$$1.call(print, "returnType"),
  11533. path$$1.call(print, "predicate"),
  11534. path$$1.call(print, "typeAnnotation")
  11535. );
  11536. }
  11537. if (needsParens) {
  11538. parts.push(")");
  11539. }
  11540. return group(concat(parts));
  11541. }
  11542. case "FunctionTypeParam":
  11543. return concat([
  11544. path$$1.call(print, "name"),
  11545. printOptionalToken(path$$1),
  11546. n.name ? ": " : "",
  11547. path$$1.call(print, "typeAnnotation")
  11548. ]);
  11549. case "GenericTypeAnnotation":
  11550. return concat([
  11551. path$$1.call(print, "id"),
  11552. path$$1.call(print, "typeParameters")
  11553. ]);
  11554. case "DeclareInterface":
  11555. case "InterfaceDeclaration": {
  11556. if (
  11557. n.type === "DeclareInterface" ||
  11558. isNodeStartingWithDeclare(n, options)
  11559. ) {
  11560. parts.push("declare ");
  11561. }
  11562. parts.push(
  11563. "interface ",
  11564. path$$1.call(print, "id"),
  11565. path$$1.call(print, "typeParameters")
  11566. );
  11567. if (n["extends"].length > 0) {
  11568. parts.push(
  11569. group(
  11570. indent(
  11571. concat([line, "extends ", join(", ", path$$1.map(print, "extends"))])
  11572. )
  11573. )
  11574. );
  11575. }
  11576. parts.push(" ");
  11577. parts.push(path$$1.call(print, "body"));
  11578. return group(concat(parts));
  11579. }
  11580. case "ClassImplements":
  11581. case "InterfaceExtends":
  11582. return concat([
  11583. path$$1.call(print, "id"),
  11584. path$$1.call(print, "typeParameters")
  11585. ]);
  11586. case "TSIntersectionType":
  11587. case "IntersectionTypeAnnotation": {
  11588. const types = path$$1.map(print, "types");
  11589. const result = [];
  11590. let wasIndented = false;
  11591. for (let i = 0; i < types.length; ++i) {
  11592. if (i === 0) {
  11593. result.push(types[i]);
  11594. } else if (isObjectType(n.types[i - 1]) && isObjectType(n.types[i])) {
  11595. // If both are objects, don't indent
  11596. result.push(
  11597. concat([" & ", wasIndented ? indent(types[i]) : types[i]])
  11598. );
  11599. } else if (!isObjectType(n.types[i - 1]) && !isObjectType(n.types[i])) {
  11600. // If no object is involved, go to the next line if it breaks
  11601. result.push(indent(concat([" &", line, types[i]])));
  11602. } else {
  11603. // If you go from object to non-object or vis-versa, then inline it
  11604. if (i > 1) {
  11605. wasIndented = true;
  11606. }
  11607. result.push(" & ", i > 1 ? indent(types[i]) : types[i]);
  11608. }
  11609. }
  11610. return group(concat(result));
  11611. }
  11612. case "TSUnionType":
  11613. case "UnionTypeAnnotation": {
  11614. // single-line variation
  11615. // A | B | C
  11616. // multi-line variation
  11617. // | A
  11618. // | B
  11619. // | C
  11620. const parent = path$$1.getParentNode();
  11621. // If there's a leading comment, the parent is doing the indentation
  11622. const shouldIndent =
  11623. parent.type !== "TypeParameterInstantiation" &&
  11624. parent.type !== "TSTypeParameterInstantiation" &&
  11625. parent.type !== "GenericTypeAnnotation" &&
  11626. parent.type !== "TSTypeReference" &&
  11627. !(parent.type === "FunctionTypeParam" && !parent.name) &&
  11628. !(
  11629. (parent.type === "TypeAlias" ||
  11630. parent.type === "VariableDeclarator") &&
  11631. hasLeadingOwnLineComment(options.originalText, n, options)
  11632. );
  11633. // {
  11634. // a: string
  11635. // } | null | void
  11636. // should be inlined and not be printed in the multi-line variant
  11637. const shouldHug = shouldHugType(n);
  11638. // We want to align the children but without its comment, so it looks like
  11639. // | child1
  11640. // // comment
  11641. // | child2
  11642. const printed = path$$1.map(typePath => {
  11643. let printedType = typePath.call(print);
  11644. if (!shouldHug) {
  11645. printedType = align(2, printedType);
  11646. }
  11647. return comments.printComments(typePath, () => printedType, options);
  11648. }, "types");
  11649. if (shouldHug) {
  11650. return join(" | ", printed);
  11651. }
  11652. const code = concat([
  11653. ifBreak(concat([shouldIndent ? line : "", "| "])),
  11654. join(concat([line, "| "]), printed)
  11655. ]);
  11656. let hasParens;
  11657. if (n.type === "TSUnionType") {
  11658. const greatGrandParent = path$$1.getParentNode(2);
  11659. const greatGreatGrandParent = path$$1.getParentNode(3);
  11660. hasParens =
  11661. greatGrandParent &&
  11662. greatGrandParent.type === "TSParenthesizedType" &&
  11663. greatGreatGrandParent &&
  11664. (greatGreatGrandParent.type === "TSUnionType" ||
  11665. greatGreatGrandParent.type === "TSIntersectionType");
  11666. } else {
  11667. hasParens = needsParens_1(path$$1, options);
  11668. }
  11669. if (hasParens) {
  11670. return group(concat([indent(code), softline]));
  11671. }
  11672. return group(shouldIndent ? indent(code) : code);
  11673. }
  11674. case "NullableTypeAnnotation":
  11675. return concat(["?", path$$1.call(print, "typeAnnotation")]);
  11676. case "TSNullKeyword":
  11677. case "NullLiteralTypeAnnotation":
  11678. return "null";
  11679. case "ThisTypeAnnotation":
  11680. return "this";
  11681. case "NumberTypeAnnotation":
  11682. return "number";
  11683. case "ObjectTypeCallProperty":
  11684. if (n.static) {
  11685. parts.push("static ");
  11686. }
  11687. parts.push(path$$1.call(print, "value"));
  11688. return concat(parts);
  11689. case "ObjectTypeIndexer": {
  11690. const variance = getFlowVariance(n);
  11691. return concat([
  11692. variance || "",
  11693. "[",
  11694. path$$1.call(print, "id"),
  11695. n.id ? ": " : "",
  11696. path$$1.call(print, "key"),
  11697. "]: ",
  11698. path$$1.call(print, "value")
  11699. ]);
  11700. }
  11701. case "ObjectTypeProperty": {
  11702. const variance = getFlowVariance(n);
  11703. return concat([
  11704. n.static ? "static " : "",
  11705. isGetterOrSetter(n) ? n.kind + " " : "",
  11706. variance || "",
  11707. printPropertyKey(path$$1, options, print),
  11708. printOptionalToken(path$$1),
  11709. isFunctionNotation(n, options) ? "" : ": ",
  11710. path$$1.call(print, "value")
  11711. ]);
  11712. }
  11713. case "QualifiedTypeIdentifier":
  11714. return concat([
  11715. path$$1.call(print, "qualification"),
  11716. ".",
  11717. path$$1.call(print, "id")
  11718. ]);
  11719. case "StringLiteralTypeAnnotation":
  11720. return nodeStr(n, options);
  11721. case "NumberLiteralTypeAnnotation":
  11722. assert.strictEqual(typeof n.value, "number");
  11723. if (n.extra != null) {
  11724. return util$1.printNumber(n.extra.raw);
  11725. }
  11726. return util$1.printNumber(n.raw);
  11727. case "StringTypeAnnotation":
  11728. return "string";
  11729. case "DeclareTypeAlias":
  11730. case "TypeAlias": {
  11731. if (
  11732. n.type === "DeclareTypeAlias" ||
  11733. isNodeStartingWithDeclare(n, options)
  11734. ) {
  11735. parts.push("declare ");
  11736. }
  11737. const canBreak = n.right.type === "StringLiteralTypeAnnotation";
  11738. const printed = printAssignmentRight(
  11739. n.right,
  11740. path$$1.call(print, "right"),
  11741. canBreak,
  11742. options
  11743. );
  11744. parts.push(
  11745. "type ",
  11746. path$$1.call(print, "id"),
  11747. path$$1.call(print, "typeParameters"),
  11748. " =",
  11749. printed,
  11750. semi
  11751. );
  11752. return group(concat(parts));
  11753. }
  11754. case "TypeCastExpression":
  11755. return concat([
  11756. "(",
  11757. path$$1.call(print, "expression"),
  11758. ": ",
  11759. path$$1.call(print, "typeAnnotation"),
  11760. ")"
  11761. ]);
  11762. case "TypeParameterDeclaration":
  11763. case "TypeParameterInstantiation":
  11764. case "TSTypeParameterDeclaration":
  11765. case "TSTypeParameterInstantiation":
  11766. return printTypeParameters(path$$1, options, print, "params");
  11767. case "TSTypeParameter":
  11768. case "TypeParameter": {
  11769. const parent = path$$1.getParentNode();
  11770. if (parent.type === "TSMappedType") {
  11771. parts.push(path$$1.call(print, "name"));
  11772. if (n.constraint) {
  11773. parts.push(" in ", path$$1.call(print, "constraint"));
  11774. }
  11775. return concat(parts);
  11776. }
  11777. const variance = getFlowVariance(n);
  11778. if (variance) {
  11779. parts.push(variance);
  11780. }
  11781. parts.push(path$$1.call(print, "name"));
  11782. if (n.bound) {
  11783. parts.push(": ");
  11784. parts.push(path$$1.call(print, "bound"));
  11785. }
  11786. if (n.constraint) {
  11787. parts.push(" extends ", path$$1.call(print, "constraint"));
  11788. }
  11789. if (n["default"]) {
  11790. parts.push(" = ", path$$1.call(print, "default"));
  11791. }
  11792. return concat(parts);
  11793. }
  11794. case "TypeofTypeAnnotation":
  11795. return concat(["typeof ", path$$1.call(print, "argument")]);
  11796. case "VoidTypeAnnotation":
  11797. return "void";
  11798. case "InferredPredicate":
  11799. return "%checks";
  11800. // Unhandled types below. If encountered, nodes of these types should
  11801. // be either left alone or desugared into AST types that are fully
  11802. // supported by the pretty-printer.
  11803. case "DeclaredPredicate":
  11804. return concat(["%checks(", path$$1.call(print, "value"), ")"]);
  11805. case "TSAbstractKeyword":
  11806. return "abstract";
  11807. case "TSAnyKeyword":
  11808. return "any";
  11809. case "TSAsyncKeyword":
  11810. return "async";
  11811. case "TSBooleanKeyword":
  11812. return "boolean";
  11813. case "TSConstKeyword":
  11814. return "const";
  11815. case "TSDeclareKeyword":
  11816. return "declare";
  11817. case "TSExportKeyword":
  11818. return "export";
  11819. case "TSNeverKeyword":
  11820. return "never";
  11821. case "TSNumberKeyword":
  11822. return "number";
  11823. case "TSObjectKeyword":
  11824. return "object";
  11825. case "TSProtectedKeyword":
  11826. return "protected";
  11827. case "TSPrivateKeyword":
  11828. return "private";
  11829. case "TSPublicKeyword":
  11830. return "public";
  11831. case "TSReadonlyKeyword":
  11832. return "readonly";
  11833. case "TSSymbolKeyword":
  11834. return "symbol";
  11835. case "TSStaticKeyword":
  11836. return "static";
  11837. case "TSStringKeyword":
  11838. return "string";
  11839. case "TSUndefinedKeyword":
  11840. return "undefined";
  11841. case "TSVoidKeyword":
  11842. return "void";
  11843. case "TSAsExpression":
  11844. return concat([
  11845. path$$1.call(print, "expression"),
  11846. " as ",
  11847. path$$1.call(print, "typeAnnotation")
  11848. ]);
  11849. case "TSArrayType":
  11850. return concat([path$$1.call(print, "elementType"), "[]"]);
  11851. case "TSPropertySignature": {
  11852. if (n.export) {
  11853. parts.push("export ");
  11854. }
  11855. if (n.accessibility) {
  11856. parts.push(n.accessibility + " ");
  11857. }
  11858. if (n.static) {
  11859. parts.push("static ");
  11860. }
  11861. if (n.readonly) {
  11862. parts.push("readonly ");
  11863. }
  11864. if (n.computed) {
  11865. parts.push("[");
  11866. }
  11867. parts.push(printPropertyKey(path$$1, options, print));
  11868. if (n.computed) {
  11869. parts.push("]");
  11870. }
  11871. parts.push(printOptionalToken(path$$1));
  11872. if (n.typeAnnotation) {
  11873. parts.push(": ");
  11874. parts.push(path$$1.call(print, "typeAnnotation"));
  11875. }
  11876. // This isn't valid semantically, but it's in the AST so we can print it.
  11877. if (n.initializer) {
  11878. parts.push(" = ", path$$1.call(print, "initializer"));
  11879. }
  11880. return concat(parts);
  11881. }
  11882. case "TSParameterProperty":
  11883. if (n.accessibility) {
  11884. parts.push(n.accessibility + " ");
  11885. }
  11886. if (n.export) {
  11887. parts.push("export ");
  11888. }
  11889. if (n.static) {
  11890. parts.push("static ");
  11891. }
  11892. if (n.readonly) {
  11893. parts.push("readonly ");
  11894. }
  11895. parts.push(path$$1.call(print, "parameter"));
  11896. return concat(parts);
  11897. case "TSTypeReference":
  11898. return concat([
  11899. path$$1.call(print, "typeName"),
  11900. printTypeParameters(path$$1, options, print, "typeParameters")
  11901. ]);
  11902. case "TSTypeQuery":
  11903. return concat(["typeof ", path$$1.call(print, "exprName")]);
  11904. case "TSParenthesizedType": {
  11905. return path$$1.call(print, "typeAnnotation");
  11906. }
  11907. case "TSIndexSignature": {
  11908. const parent = path$$1.getParentNode();
  11909. return concat([
  11910. n.export ? "export " : "",
  11911. n.accessibility ? concat([n.accessibility, " "]) : "",
  11912. n.static ? "static " : "",
  11913. n.readonly ? "readonly " : "",
  11914. "[",
  11915. path$$1.call(print, "index"),
  11916. "]: ",
  11917. path$$1.call(print, "typeAnnotation"),
  11918. parent.type === "ClassBody" ? semi : ""
  11919. ]);
  11920. }
  11921. case "TSTypePredicate":
  11922. return concat([
  11923. path$$1.call(print, "parameterName"),
  11924. " is ",
  11925. path$$1.call(print, "typeAnnotation")
  11926. ]);
  11927. case "TSNonNullExpression":
  11928. return concat([path$$1.call(print, "expression"), "!"]);
  11929. case "TSThisType":
  11930. return "this";
  11931. case "TSLastTypeNode":
  11932. return path$$1.call(print, "literal");
  11933. case "TSIndexedAccessType":
  11934. return concat([
  11935. path$$1.call(print, "objectType"),
  11936. "[",
  11937. path$$1.call(print, "indexType"),
  11938. "]"
  11939. ]);
  11940. case "TSConstructSignature":
  11941. case "TSConstructorType":
  11942. case "TSCallSignature": {
  11943. if (n.type !== "TSCallSignature") {
  11944. parts.push("new ");
  11945. }
  11946. parts.push(
  11947. group(
  11948. printFunctionParams(
  11949. path$$1,
  11950. print,
  11951. options,
  11952. /* expandArg */ false,
  11953. /* printTypeParams */ true
  11954. )
  11955. )
  11956. );
  11957. if (n.typeAnnotation) {
  11958. const isType = n.type === "TSConstructorType";
  11959. parts.push(isType ? " => " : ": ", path$$1.call(print, "typeAnnotation"));
  11960. }
  11961. return concat(parts);
  11962. }
  11963. case "TSTypeOperator":
  11964. return concat([n.operator, " ", path$$1.call(print, "typeAnnotation")]);
  11965. case "TSMappedType":
  11966. return group(
  11967. concat([
  11968. "{",
  11969. indent(
  11970. concat([
  11971. options.bracketSpacing ? line : softline,
  11972. n.readonlyToken
  11973. ? concat([
  11974. getTypeScriptMappedTypeModifier(
  11975. n.readonlyToken,
  11976. "readonly"
  11977. ),
  11978. " "
  11979. ])
  11980. : "",
  11981. printTypeScriptModifiers(path$$1, options, print),
  11982. "[",
  11983. path$$1.call(print, "typeParameter"),
  11984. "]",
  11985. n.questionToken
  11986. ? getTypeScriptMappedTypeModifier(n.questionToken, "?")
  11987. : "",
  11988. ": ",
  11989. path$$1.call(print, "typeAnnotation")
  11990. ])
  11991. ),
  11992. comments.printDanglingComments(path$$1, options, /* sameIndent */ true),
  11993. options.bracketSpacing ? line : softline,
  11994. "}"
  11995. ])
  11996. );
  11997. case "TSMethodSignature":
  11998. parts.push(
  11999. n.accessibility ? concat([n.accessibility, " "]) : "",
  12000. n.export ? "export " : "",
  12001. n.static ? "static " : "",
  12002. n.readonly ? "readonly " : "",
  12003. n.computed ? "[" : "",
  12004. path$$1.call(print, "key"),
  12005. n.computed ? "]" : "",
  12006. printOptionalToken(path$$1),
  12007. printFunctionParams(
  12008. path$$1,
  12009. print,
  12010. options,
  12011. /* expandArg */ false,
  12012. /* printTypeParams */ true
  12013. )
  12014. );
  12015. if (n.typeAnnotation) {
  12016. parts.push(": ", path$$1.call(print, "typeAnnotation"));
  12017. }
  12018. return group(concat(parts));
  12019. case "TSNamespaceExportDeclaration":
  12020. parts.push("export as namespace ", path$$1.call(print, "name"));
  12021. if (options.semi) {
  12022. parts.push(";");
  12023. }
  12024. return group(concat(parts));
  12025. case "TSEnumDeclaration":
  12026. if (isNodeStartingWithDeclare(n, options)) {
  12027. parts.push("declare ");
  12028. }
  12029. if (n.modifiers) {
  12030. parts.push(printTypeScriptModifiers(path$$1, options, print));
  12031. }
  12032. if (n.const) {
  12033. parts.push("const ");
  12034. }
  12035. parts.push("enum ", path$$1.call(print, "id"), " ");
  12036. if (n.members.length === 0) {
  12037. parts.push(
  12038. group(
  12039. concat([
  12040. "{",
  12041. comments.printDanglingComments(path$$1, options),
  12042. softline,
  12043. "}"
  12044. ])
  12045. )
  12046. );
  12047. } else {
  12048. parts.push(
  12049. group(
  12050. concat([
  12051. "{",
  12052. indent(
  12053. concat([
  12054. hardline,
  12055. printArrayItems(path$$1, options, "members", print),
  12056. shouldPrintComma(options, "es5") ? "," : ""
  12057. ])
  12058. ),
  12059. comments.printDanglingComments(
  12060. path$$1,
  12061. options,
  12062. /* sameIndent */ true
  12063. ),
  12064. hardline,
  12065. "}"
  12066. ])
  12067. )
  12068. );
  12069. }
  12070. return concat(parts);
  12071. case "TSEnumMember":
  12072. parts.push(path$$1.call(print, "id"));
  12073. if (n.initializer) {
  12074. parts.push(" = ", path$$1.call(print, "initializer"));
  12075. }
  12076. return concat(parts);
  12077. case "TSImportEqualsDeclaration":
  12078. parts.push(
  12079. printTypeScriptModifiers(path$$1, options, print),
  12080. "import ",
  12081. path$$1.call(print, "name"),
  12082. " = ",
  12083. path$$1.call(print, "moduleReference")
  12084. );
  12085. if (options.semi) {
  12086. parts.push(";");
  12087. }
  12088. return group(concat(parts));
  12089. case "TSExternalModuleReference":
  12090. return concat(["require(", path$$1.call(print, "expression"), ")"]);
  12091. case "TSModuleDeclaration": {
  12092. const parent = path$$1.getParentNode();
  12093. const isExternalModule = isLiteral(n.id);
  12094. const parentIsDeclaration = parent.type === "TSModuleDeclaration";
  12095. const bodyIsDeclaration = n.body && n.body.type === "TSModuleDeclaration";
  12096. if (parentIsDeclaration) {
  12097. parts.push(".");
  12098. } else {
  12099. if (n.declare === true) {
  12100. parts.push("declare ");
  12101. }
  12102. parts.push(printTypeScriptModifiers(path$$1, options, print));
  12103. // Global declaration looks like this:
  12104. // (declare)? global { ... }
  12105. const isGlobalDeclaration =
  12106. n.id.type === "Identifier" &&
  12107. n.id.name === "global" &&
  12108. !/namespace|module/.test(
  12109. options.originalText.slice(
  12110. options.locStart(n),
  12111. options.locStart(n.id)
  12112. )
  12113. );
  12114. if (!isGlobalDeclaration) {
  12115. parts.push(isExternalModule ? "module " : "namespace ");
  12116. }
  12117. }
  12118. parts.push(path$$1.call(print, "id"));
  12119. if (bodyIsDeclaration) {
  12120. parts.push(path$$1.call(print, "body"));
  12121. } else if (n.body) {
  12122. parts.push(
  12123. " {",
  12124. indent(
  12125. concat([
  12126. line,
  12127. path$$1.call(
  12128. bodyPath =>
  12129. comments.printDanglingComments(bodyPath, options, true),
  12130. "body"
  12131. ),
  12132. group(path$$1.call(print, "body"))
  12133. ])
  12134. ),
  12135. line,
  12136. "}"
  12137. );
  12138. } else {
  12139. parts.push(semi);
  12140. }
  12141. return concat(parts);
  12142. }
  12143. case "TSModuleBlock":
  12144. return path$$1.call(bodyPath => {
  12145. return printStatementSequence(bodyPath, options, print);
  12146. }, "body");
  12147. case "PrivateName":
  12148. return concat(["#", path$$1.call(print, "id")]);
  12149. case "TSConditionalType":
  12150. return formatTernaryOperator(path$$1, options, print, {
  12151. beforeParts: () => [
  12152. path$$1.call(print, "checkType"),
  12153. " ",
  12154. "extends",
  12155. " ",
  12156. path$$1.call(print, "extendsType")
  12157. ],
  12158. shouldCheckJsx: false,
  12159. operatorName: "TSConditionalType",
  12160. consequentNode: "trueType",
  12161. alternateNode: "falseType",
  12162. testNode: "checkType",
  12163. breakNested: false
  12164. });
  12165. case "TSInferType":
  12166. return concat(["infer", " ", path$$1.call(print, "typeParameter")]);
  12167. default:
  12168. /* istanbul ignore next */
  12169. throw new Error("unknown type: " + JSON.stringify(n.type));
  12170. }
  12171. }
  12172. function printStatementSequence(path$$1, options, print) {
  12173. const printed = [];
  12174. const bodyNode = path$$1.getNode();
  12175. const isClass = bodyNode.type === "ClassBody";
  12176. path$$1.map((stmtPath, i) => {
  12177. const stmt = stmtPath.getValue();
  12178. // Just in case the AST has been modified to contain falsy
  12179. // "statements," it's safer simply to skip them.
  12180. /* istanbul ignore if */
  12181. if (!stmt) {
  12182. return;
  12183. }
  12184. // Skip printing EmptyStatement nodes to avoid leaving stray
  12185. // semicolons lying around.
  12186. if (stmt.type === "EmptyStatement") {
  12187. return;
  12188. }
  12189. const stmtPrinted = print(stmtPath);
  12190. const text = options.originalText;
  12191. const parts = [];
  12192. // in no-semi mode, prepend statement with semicolon if it might break ASI
  12193. // don't prepend the only JSX element in a program with semicolon
  12194. if (
  12195. !options.semi &&
  12196. !isClass &&
  12197. !isTheOnlyJSXElementInMarkdown(options, stmtPath) &&
  12198. stmtNeedsASIProtection(stmtPath, options)
  12199. ) {
  12200. if (stmt.comments && stmt.comments.some(comment => comment.leading)) {
  12201. parts.push(print(stmtPath, { needsSemi: true }));
  12202. } else {
  12203. parts.push(";", stmtPrinted);
  12204. }
  12205. } else {
  12206. parts.push(stmtPrinted);
  12207. }
  12208. if (!options.semi && isClass) {
  12209. if (classPropMayCauseASIProblems(stmtPath)) {
  12210. parts.push(";");
  12211. } else if (stmt.type === "ClassProperty") {
  12212. const nextChild = bodyNode.body[i + 1];
  12213. if (classChildNeedsASIProtection(nextChild)) {
  12214. parts.push(";");
  12215. }
  12216. }
  12217. }
  12218. if (
  12219. utilShared.isNextLineEmpty(text, stmt, options) &&
  12220. !isLastStatement(stmtPath)
  12221. ) {
  12222. parts.push(hardline);
  12223. }
  12224. printed.push(concat(parts));
  12225. });
  12226. return join(hardline, printed);
  12227. }
  12228. function printPropertyKey(path$$1, options, print) {
  12229. const node = path$$1.getNode();
  12230. const key = node.key;
  12231. if (
  12232. isStringLiteral(key) &&
  12233. isIdentifierName(key.value) &&
  12234. !node.computed &&
  12235. options.parser !== "json"
  12236. ) {
  12237. // 'a' -> a
  12238. return path$$1.call(
  12239. keyPath => comments.printComments(keyPath, () => key.value, options),
  12240. "key"
  12241. );
  12242. }
  12243. return path$$1.call(print, "key");
  12244. }
  12245. function printMethod(path$$1, options, print) {
  12246. const node = path$$1.getNode();
  12247. const semi = options.semi ? ";" : "";
  12248. const kind = node.kind;
  12249. const parts = [];
  12250. if (node.type === "ObjectMethod" || node.type === "ClassMethod") {
  12251. node.value = node;
  12252. }
  12253. if (node.value.async) {
  12254. parts.push("async ");
  12255. }
  12256. if (!kind || kind === "init" || kind === "method" || kind === "constructor") {
  12257. if (node.value.generator) {
  12258. parts.push("*");
  12259. }
  12260. } else {
  12261. assert.ok(kind === "get" || kind === "set");
  12262. parts.push(kind, " ");
  12263. }
  12264. let key = printPropertyKey(path$$1, options, print);
  12265. if (node.computed) {
  12266. key = concat(["[", key, "]"]);
  12267. }
  12268. parts.push(
  12269. key,
  12270. concat(
  12271. path$$1.call(
  12272. valuePath => [
  12273. printFunctionTypeParameters(valuePath, options, print),
  12274. group(
  12275. concat([
  12276. printFunctionParams(valuePath, print, options),
  12277. printReturnType(valuePath, print, options)
  12278. ])
  12279. )
  12280. ],
  12281. "value"
  12282. )
  12283. )
  12284. );
  12285. if (!node.value.body || node.value.body.length === 0) {
  12286. parts.push(semi);
  12287. } else {
  12288. parts.push(" ", path$$1.call(print, "value", "body"));
  12289. }
  12290. return concat(parts);
  12291. }
  12292. function couldGroupArg(arg) {
  12293. return (
  12294. (arg.type === "ObjectExpression" &&
  12295. (arg.properties.length > 0 || arg.comments)) ||
  12296. (arg.type === "ArrayExpression" &&
  12297. (arg.elements.length > 0 || arg.comments)) ||
  12298. arg.type === "TSTypeAssertionExpression" ||
  12299. arg.type === "TSAsExpression" ||
  12300. arg.type === "FunctionExpression" ||
  12301. (arg.type === "ArrowFunctionExpression" &&
  12302. (arg.body.type === "BlockStatement" ||
  12303. arg.body.type === "ArrowFunctionExpression" ||
  12304. arg.body.type === "ObjectExpression" ||
  12305. arg.body.type === "ArrayExpression" ||
  12306. arg.body.type === "CallExpression" ||
  12307. isJSXNode(arg.body)))
  12308. );
  12309. }
  12310. function shouldGroupLastArg(args) {
  12311. const lastArg = util$1.getLast(args);
  12312. const penultimateArg = util$1.getPenultimate(args);
  12313. return (
  12314. !hasLeadingComment(lastArg) &&
  12315. !hasTrailingComment(lastArg) &&
  12316. couldGroupArg(lastArg) &&
  12317. // If the last two arguments are of the same type,
  12318. // disable last element expansion.
  12319. (!penultimateArg || penultimateArg.type !== lastArg.type)
  12320. );
  12321. }
  12322. function shouldGroupFirstArg(args) {
  12323. if (args.length !== 2) {
  12324. return false;
  12325. }
  12326. const firstArg = args[0];
  12327. const secondArg = args[1];
  12328. return (
  12329. (!firstArg.comments || !firstArg.comments.length) &&
  12330. (firstArg.type === "FunctionExpression" ||
  12331. (firstArg.type === "ArrowFunctionExpression" &&
  12332. firstArg.body.type === "BlockStatement")) &&
  12333. !couldGroupArg(secondArg)
  12334. );
  12335. }
  12336. function printArgumentsList(path$$1, options, print) {
  12337. const args = path$$1.getValue().arguments;
  12338. if (args.length === 0) {
  12339. return concat([
  12340. "(",
  12341. comments.printDanglingComments(path$$1, options, /* sameIndent */ true),
  12342. ")"
  12343. ]);
  12344. }
  12345. let anyArgEmptyLine = false;
  12346. let hasEmptyLineFollowingFirstArg = false;
  12347. const lastArgIndex = args.length - 1;
  12348. const printedArguments = path$$1.map((argPath, index) => {
  12349. const arg = argPath.getNode();
  12350. const parts = [print(argPath)];
  12351. if (index === lastArgIndex) {
  12352. // do nothing
  12353. } else if (utilShared.isNextLineEmpty(options.originalText, arg, options)) {
  12354. if (index === 0) {
  12355. hasEmptyLineFollowingFirstArg = true;
  12356. }
  12357. anyArgEmptyLine = true;
  12358. parts.push(",", hardline, hardline);
  12359. } else {
  12360. parts.push(",", line);
  12361. }
  12362. return concat(parts);
  12363. }, "arguments");
  12364. const shouldGroupFirst = shouldGroupFirstArg(args);
  12365. const shouldGroupLast = shouldGroupLastArg(args);
  12366. if (shouldGroupFirst || shouldGroupLast) {
  12367. const shouldBreak =
  12368. (shouldGroupFirst
  12369. ? printedArguments.slice(1).some(willBreak$1)
  12370. : printedArguments.slice(0, -1).some(willBreak$1)) || anyArgEmptyLine;
  12371. // We want to print the last argument with a special flag
  12372. let printedExpanded;
  12373. let i = 0;
  12374. path$$1.each(argPath => {
  12375. if (shouldGroupFirst && i === 0) {
  12376. printedExpanded = [
  12377. concat([
  12378. argPath.call(p => print(p, { expandFirstArg: true })),
  12379. printedArguments.length > 1 ? "," : "",
  12380. hasEmptyLineFollowingFirstArg ? hardline : line,
  12381. hasEmptyLineFollowingFirstArg ? hardline : ""
  12382. ])
  12383. ].concat(printedArguments.slice(1));
  12384. }
  12385. if (shouldGroupLast && i === args.length - 1) {
  12386. printedExpanded = printedArguments
  12387. .slice(0, -1)
  12388. .concat(argPath.call(p => print(p, { expandLastArg: true })));
  12389. }
  12390. i++;
  12391. }, "arguments");
  12392. const somePrintedArgumentsWillBreak = printedArguments.some(willBreak$1);
  12393. const maybeTrailingComma = shouldPrintComma(options, "all") ? "," : "";
  12394. return concat([
  12395. somePrintedArgumentsWillBreak ? breakParent : "",
  12396. conditionalGroup(
  12397. [
  12398. concat([
  12399. ifBreak(
  12400. indent(concat(["(", softline, concat(printedExpanded)])),
  12401. concat(["(", concat(printedExpanded)])
  12402. ),
  12403. somePrintedArgumentsWillBreak
  12404. ? concat([ifBreak(maybeTrailingComma), softline])
  12405. : "",
  12406. ")"
  12407. ]),
  12408. shouldGroupFirst
  12409. ? concat([
  12410. "(",
  12411. group(printedExpanded[0], { shouldBreak: true }),
  12412. concat(printedExpanded.slice(1)),
  12413. ")"
  12414. ])
  12415. : concat([
  12416. "(",
  12417. concat(printedArguments.slice(0, -1)),
  12418. group(util$1.getLast(printedExpanded), {
  12419. shouldBreak: true
  12420. }),
  12421. ")"
  12422. ]),
  12423. group(
  12424. concat([
  12425. "(",
  12426. indent(concat([line, concat(printedArguments)])),
  12427. maybeTrailingComma,
  12428. line,
  12429. ")"
  12430. ]),
  12431. { shouldBreak: true }
  12432. )
  12433. ],
  12434. { shouldBreak }
  12435. )
  12436. ]);
  12437. }
  12438. return group(
  12439. concat([
  12440. "(",
  12441. indent(concat([softline, concat(printedArguments)])),
  12442. ifBreak(shouldPrintComma(options, "all") ? "," : ""),
  12443. softline,
  12444. ")"
  12445. ]),
  12446. { shouldBreak: printedArguments.some(willBreak$1) || anyArgEmptyLine }
  12447. );
  12448. }
  12449. function printTypeAnnotation(path$$1, options, print) {
  12450. const node = path$$1.getValue();
  12451. if (!node.typeAnnotation) {
  12452. return "";
  12453. }
  12454. const parentNode = path$$1.getParentNode();
  12455. const isDefinite =
  12456. node.definite ||
  12457. (parentNode &&
  12458. parentNode.type === "VariableDeclarator" &&
  12459. parentNode.definite);
  12460. const isFunctionDeclarationIdentifier =
  12461. parentNode.type === "DeclareFunction" && parentNode.id === node;
  12462. if (
  12463. isFlowAnnotationComment(options.originalText, node.typeAnnotation, options)
  12464. ) {
  12465. return concat([" /*: ", path$$1.call(print, "typeAnnotation"), " */"]);
  12466. }
  12467. return concat([
  12468. isFunctionDeclarationIdentifier ? "" : isDefinite ? "!: " : ": ",
  12469. path$$1.call(print, "typeAnnotation")
  12470. ]);
  12471. }
  12472. function printFunctionTypeParameters(path$$1, options, print) {
  12473. const fun = path$$1.getValue();
  12474. if (fun.typeParameters) {
  12475. return path$$1.call(print, "typeParameters");
  12476. }
  12477. return "";
  12478. }
  12479. function printFunctionParams(path$$1, print, options, expandArg, printTypeParams) {
  12480. const fun = path$$1.getValue();
  12481. const paramsField = fun.parameters ? "parameters" : "params";
  12482. const typeParams = printTypeParams
  12483. ? printFunctionTypeParameters(path$$1, options, print)
  12484. : "";
  12485. let printed = [];
  12486. if (fun[paramsField]) {
  12487. printed = path$$1.map(print, paramsField);
  12488. }
  12489. if (fun.rest) {
  12490. printed.push(concat(["...", path$$1.call(print, "rest")]));
  12491. }
  12492. if (printed.length === 0) {
  12493. return concat([
  12494. typeParams,
  12495. "(",
  12496. comments.printDanglingComments(
  12497. path$$1,
  12498. options,
  12499. /* sameIndent */ true,
  12500. comment =>
  12501. util$1.getNextNonSpaceNonCommentCharacter(
  12502. options.originalText,
  12503. comment,
  12504. options.locEnd
  12505. ) === ")"
  12506. ),
  12507. ")"
  12508. ]);
  12509. }
  12510. const lastParam = util$1.getLast(fun[paramsField]);
  12511. // If the parent is a call with the first/last argument expansion and this is the
  12512. // params of the first/last argument, we dont want the arguments to break and instead
  12513. // want the whole expression to be on a new line.
  12514. //
  12515. // Good: Bad:
  12516. // verylongcall( verylongcall((
  12517. // (a, b) => { a,
  12518. // } b,
  12519. // }) ) => {
  12520. // })
  12521. if (
  12522. expandArg &&
  12523. !(fun[paramsField] && fun[paramsField].some(n => n.comments))
  12524. ) {
  12525. return group(
  12526. concat([
  12527. docUtils$3.removeLines(typeParams),
  12528. "(",
  12529. join(", ", printed.map(docUtils$3.removeLines)),
  12530. ")"
  12531. ])
  12532. );
  12533. }
  12534. // Single object destructuring should hug
  12535. //
  12536. // function({
  12537. // a,
  12538. // b,
  12539. // c
  12540. // }) {}
  12541. if (shouldHugArguments(fun)) {
  12542. return concat([typeParams, "(", join(", ", printed), ")"]);
  12543. }
  12544. const parent = path$$1.getParentNode();
  12545. // don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})`
  12546. if (parent.type === "CallExpression" && isTestCall(parent)) {
  12547. return concat([typeParams, "(", join(", ", printed), ")"]);
  12548. }
  12549. const flowTypeAnnotations = [
  12550. "AnyTypeAnnotation",
  12551. "NullLiteralTypeAnnotation",
  12552. "GenericTypeAnnotation",
  12553. "ThisTypeAnnotation",
  12554. "NumberTypeAnnotation",
  12555. "VoidTypeAnnotation",
  12556. "EmptyTypeAnnotation",
  12557. "MixedTypeAnnotation",
  12558. "BooleanTypeAnnotation",
  12559. "BooleanLiteralTypeAnnotation",
  12560. "StringTypeAnnotation"
  12561. ];
  12562. const isFlowShorthandWithOneArg =
  12563. (isObjectTypePropertyAFunction(parent, options) ||
  12564. isTypeAnnotationAFunction(parent, options) ||
  12565. parent.type === "TypeAlias" ||
  12566. parent.type === "UnionTypeAnnotation" ||
  12567. parent.type === "TSUnionType" ||
  12568. parent.type === "IntersectionTypeAnnotation" ||
  12569. (parent.type === "FunctionTypeAnnotation" &&
  12570. parent.returnType === fun)) &&
  12571. fun[paramsField].length === 1 &&
  12572. fun[paramsField][0].name === null &&
  12573. fun[paramsField][0].typeAnnotation &&
  12574. fun.typeParameters === null &&
  12575. flowTypeAnnotations.indexOf(fun[paramsField][0].typeAnnotation.type) !==
  12576. -1 &&
  12577. !(
  12578. fun[paramsField][0].typeAnnotation.type === "GenericTypeAnnotation" &&
  12579. fun[paramsField][0].typeAnnotation.typeParameters
  12580. ) &&
  12581. !fun.rest;
  12582. if (isFlowShorthandWithOneArg) {
  12583. if (options.arrowParens === "always") {
  12584. return concat(["(", concat(printed), ")"]);
  12585. }
  12586. return concat(printed);
  12587. }
  12588. const canHaveTrailingComma =
  12589. !(lastParam && lastParam.type === "RestElement") && !fun.rest;
  12590. return concat([
  12591. typeParams,
  12592. "(",
  12593. indent(concat([softline, join(concat([",", line]), printed)])),
  12594. ifBreak(
  12595. canHaveTrailingComma && shouldPrintComma(options, "all") ? "," : ""
  12596. ),
  12597. softline,
  12598. ")"
  12599. ]);
  12600. }
  12601. function shouldPrintParamsWithoutParens(path$$1, options) {
  12602. if (options.arrowParens === "always") {
  12603. return false;
  12604. }
  12605. if (options.arrowParens === "avoid") {
  12606. const node = path$$1.getValue();
  12607. return canPrintParamsWithoutParens(node);
  12608. }
  12609. // Fallback default; should be unreachable
  12610. return false;
  12611. }
  12612. function canPrintParamsWithoutParens(node) {
  12613. return (
  12614. node.params.length === 1 &&
  12615. !node.rest &&
  12616. !node.typeParameters &&
  12617. !hasDanglingComments(node) &&
  12618. node.params[0].type === "Identifier" &&
  12619. !node.params[0].typeAnnotation &&
  12620. !node.params[0].comments &&
  12621. !node.params[0].optional &&
  12622. !node.predicate &&
  12623. !node.returnType
  12624. );
  12625. }
  12626. function printFunctionDeclaration(path$$1, print, options) {
  12627. const n = path$$1.getValue();
  12628. const parts = [];
  12629. if (n.async) {
  12630. parts.push("async ");
  12631. }
  12632. parts.push("function");
  12633. if (n.generator) {
  12634. parts.push("*");
  12635. }
  12636. if (n.id) {
  12637. parts.push(" ", path$$1.call(print, "id"));
  12638. }
  12639. parts.push(
  12640. printFunctionTypeParameters(path$$1, options, print),
  12641. group(
  12642. concat([
  12643. printFunctionParams(path$$1, print, options),
  12644. printReturnType(path$$1, print, options)
  12645. ])
  12646. ),
  12647. n.body ? " " : "",
  12648. path$$1.call(print, "body")
  12649. );
  12650. return concat(parts);
  12651. }
  12652. function printObjectMethod(path$$1, options, print) {
  12653. const objMethod = path$$1.getValue();
  12654. const parts = [];
  12655. if (objMethod.async) {
  12656. parts.push("async ");
  12657. }
  12658. if (objMethod.generator) {
  12659. parts.push("*");
  12660. }
  12661. if (
  12662. objMethod.method ||
  12663. objMethod.kind === "get" ||
  12664. objMethod.kind === "set"
  12665. ) {
  12666. return printMethod(path$$1, options, print);
  12667. }
  12668. const key = printPropertyKey(path$$1, options, print);
  12669. if (objMethod.computed) {
  12670. parts.push("[", key, "]");
  12671. } else {
  12672. parts.push(key);
  12673. }
  12674. parts.push(
  12675. printFunctionTypeParameters(path$$1, options, print),
  12676. group(
  12677. concat([
  12678. printFunctionParams(path$$1, print, options),
  12679. printReturnType(path$$1, print, options)
  12680. ])
  12681. ),
  12682. " ",
  12683. path$$1.call(print, "body")
  12684. );
  12685. return concat(parts);
  12686. }
  12687. function printReturnType(path$$1, print, options) {
  12688. const n = path$$1.getValue();
  12689. const returnType = path$$1.call(print, "returnType");
  12690. if (
  12691. n.returnType &&
  12692. isFlowAnnotationComment(options.originalText, n.returnType, options)
  12693. ) {
  12694. return concat([" /*: ", returnType, " */"]);
  12695. }
  12696. const parts = [returnType];
  12697. // prepend colon to TypeScript type annotation
  12698. if (n.returnType && n.returnType.typeAnnotation) {
  12699. parts.unshift(": ");
  12700. }
  12701. if (n.predicate) {
  12702. // The return type will already add the colon, but otherwise we
  12703. // need to do it ourselves
  12704. parts.push(n.returnType ? " " : ": ", path$$1.call(print, "predicate"));
  12705. }
  12706. return concat(parts);
  12707. }
  12708. function printExportDeclaration(path$$1, options, print) {
  12709. const decl = path$$1.getValue();
  12710. const semi = options.semi ? ";" : "";
  12711. const parts = ["export "];
  12712. const isDefault = decl["default"] || decl.type === "ExportDefaultDeclaration";
  12713. if (isDefault) {
  12714. parts.push("default ");
  12715. }
  12716. parts.push(
  12717. comments.printDanglingComments(path$$1, options, /* sameIndent */ true)
  12718. );
  12719. if (needsHardlineAfterDanglingComment(decl)) {
  12720. parts.push(hardline);
  12721. }
  12722. if (decl.declaration) {
  12723. parts.push(path$$1.call(print, "declaration"));
  12724. if (
  12725. isDefault &&
  12726. (decl.declaration.type !== "ClassDeclaration" &&
  12727. decl.declaration.type !== "FunctionDeclaration" &&
  12728. decl.declaration.type !== "TSAbstractClassDeclaration" &&
  12729. decl.declaration.type !== "TSInterfaceDeclaration" &&
  12730. decl.declaration.type !== "DeclareClass" &&
  12731. decl.declaration.type !== "DeclareFunction")
  12732. ) {
  12733. parts.push(semi);
  12734. }
  12735. } else {
  12736. if (decl.specifiers && decl.specifiers.length > 0) {
  12737. const specifiers = [];
  12738. const defaultSpecifiers = [];
  12739. const namespaceSpecifiers = [];
  12740. path$$1.each(specifierPath => {
  12741. const specifierType = path$$1.getValue().type;
  12742. if (specifierType === "ExportSpecifier") {
  12743. specifiers.push(print(specifierPath));
  12744. } else if (specifierType === "ExportDefaultSpecifier") {
  12745. defaultSpecifiers.push(print(specifierPath));
  12746. } else if (specifierType === "ExportNamespaceSpecifier") {
  12747. namespaceSpecifiers.push(concat(["* as ", print(specifierPath)]));
  12748. }
  12749. }, "specifiers");
  12750. const isNamespaceFollowed =
  12751. namespaceSpecifiers.length !== 0 && specifiers.length !== 0;
  12752. const isDefaultFollowed =
  12753. defaultSpecifiers.length !== 0 &&
  12754. (namespaceSpecifiers.length !== 0 || specifiers.length !== 0);
  12755. parts.push(
  12756. decl.exportKind === "type" ? "type " : "",
  12757. concat(defaultSpecifiers),
  12758. concat([isDefaultFollowed ? ", " : ""]),
  12759. concat(namespaceSpecifiers),
  12760. concat([isNamespaceFollowed ? ", " : ""]),
  12761. specifiers.length !== 0
  12762. ? group(
  12763. concat([
  12764. "{",
  12765. indent(
  12766. concat([
  12767. options.bracketSpacing ? line : softline,
  12768. join(concat([",", line]), specifiers)
  12769. ])
  12770. ),
  12771. ifBreak(shouldPrintComma(options) ? "," : ""),
  12772. options.bracketSpacing ? line : softline,
  12773. "}"
  12774. ])
  12775. )
  12776. : ""
  12777. );
  12778. } else {
  12779. parts.push("{}");
  12780. }
  12781. if (decl.source) {
  12782. parts.push(" from ", path$$1.call(print, "source"));
  12783. }
  12784. parts.push(semi);
  12785. }
  12786. return concat(parts);
  12787. }
  12788. function printFlowDeclaration(path$$1, parts) {
  12789. const parentExportDecl = util$1.getParentExportDeclaration(path$$1);
  12790. if (parentExportDecl) {
  12791. assert.strictEqual(parentExportDecl.type, "DeclareExportDeclaration");
  12792. } else {
  12793. // If the parent node has type DeclareExportDeclaration, then it
  12794. // will be responsible for printing the "declare" token. Otherwise
  12795. // it needs to be printed with this non-exported declaration node.
  12796. parts.unshift("declare ");
  12797. }
  12798. return concat(parts);
  12799. }
  12800. function getFlowVariance(path$$1) {
  12801. if (!path$$1.variance) {
  12802. return null;
  12803. }
  12804. // Babylon 7.0 currently uses variance node type, and flow should
  12805. // follow suit soon:
  12806. // https://github.com/babel/babel/issues/4722
  12807. const variance = path$$1.variance.kind || path$$1.variance;
  12808. switch (variance) {
  12809. case "plus":
  12810. return "+";
  12811. case "minus":
  12812. return "-";
  12813. default:
  12814. /* istanbul ignore next */
  12815. return variance;
  12816. }
  12817. }
  12818. function printTypeScriptModifiers(path$$1, options, print) {
  12819. const n = path$$1.getValue();
  12820. if (!n.modifiers || !n.modifiers.length) {
  12821. return "";
  12822. }
  12823. return concat([join(" ", path$$1.map(print, "modifiers")), " "]);
  12824. }
  12825. function printTypeParameters(path$$1, options, print, paramsKey) {
  12826. const n = path$$1.getValue();
  12827. if (!n[paramsKey]) {
  12828. return "";
  12829. }
  12830. // for TypeParameterDeclaration typeParameters is a single node
  12831. if (!Array.isArray(n[paramsKey])) {
  12832. return path$$1.call(print, paramsKey);
  12833. }
  12834. const grandparent = path$$1.getNode(2);
  12835. const isParameterInTestCall =
  12836. grandparent != null &&
  12837. grandparent.type === "CallExpression" &&
  12838. isTestCall(grandparent);
  12839. const shouldInline =
  12840. isParameterInTestCall ||
  12841. n[paramsKey].length === 0 ||
  12842. (n[paramsKey].length === 1 &&
  12843. (shouldHugType(n[paramsKey][0]) ||
  12844. (n[paramsKey][0].type === "GenericTypeAnnotation" &&
  12845. shouldHugType(n[paramsKey][0].id)) ||
  12846. (n[paramsKey][0].type === "TSTypeReference" &&
  12847. shouldHugType(n[paramsKey][0].typeName)) ||
  12848. n[paramsKey][0].type === "NullableTypeAnnotation"));
  12849. if (shouldInline) {
  12850. return concat(["<", join(", ", path$$1.map(print, paramsKey)), ">"]);
  12851. }
  12852. return group(
  12853. concat([
  12854. "<",
  12855. indent(
  12856. concat([
  12857. softline,
  12858. join(concat([",", line]), path$$1.map(print, paramsKey))
  12859. ])
  12860. ),
  12861. ifBreak(
  12862. options.parser !== "typescript" && shouldPrintComma(options, "all")
  12863. ? ","
  12864. : ""
  12865. ),
  12866. softline,
  12867. ">"
  12868. ])
  12869. );
  12870. }
  12871. function printClass(path$$1, options, print) {
  12872. const n = path$$1.getValue();
  12873. const parts = [];
  12874. if (n.type === "TSAbstractClassDeclaration") {
  12875. parts.push("abstract ");
  12876. }
  12877. parts.push("class");
  12878. if (n.id) {
  12879. parts.push(" ", path$$1.call(print, "id"));
  12880. }
  12881. parts.push(path$$1.call(print, "typeParameters"));
  12882. const partsGroup = [];
  12883. if (n.superClass) {
  12884. const printed = concat([
  12885. "extends ",
  12886. path$$1.call(print, "superClass"),
  12887. path$$1.call(print, "superTypeParameters")
  12888. ]);
  12889. // Keep old behaviour of extends in same line
  12890. // If there is only on extends and there are not comments
  12891. if (
  12892. (!n.implements || n.implements.length === 0) &&
  12893. (!n.superClass.comments || n.superClass.comments.length === 0)
  12894. ) {
  12895. parts.push(
  12896. concat([
  12897. " ",
  12898. path$$1.call(
  12899. superClass =>
  12900. comments.printComments(superClass, () => printed, options),
  12901. "superClass"
  12902. )
  12903. ])
  12904. );
  12905. } else {
  12906. partsGroup.push(
  12907. group(
  12908. concat([
  12909. line,
  12910. path$$1.call(
  12911. superClass =>
  12912. comments.printComments(superClass, () => printed, options),
  12913. "superClass"
  12914. )
  12915. ])
  12916. )
  12917. );
  12918. }
  12919. } else if (n.extends && n.extends.length > 0) {
  12920. parts.push(" extends ", join(", ", path$$1.map(print, "extends")));
  12921. }
  12922. if (n["implements"] && n["implements"].length > 0) {
  12923. partsGroup.push(
  12924. line,
  12925. "implements",
  12926. group(
  12927. indent(
  12928. concat([
  12929. line,
  12930. join(concat([",", line]), path$$1.map(print, "implements"))
  12931. ])
  12932. )
  12933. )
  12934. );
  12935. }
  12936. if (n["mixins"] && n["mixins"].length > 0) {
  12937. partsGroup.push(
  12938. line,
  12939. "mixins ",
  12940. group(indent(join(concat([",", line]), path$$1.map(print, "mixins"))))
  12941. );
  12942. }
  12943. if (partsGroup.length > 0) {
  12944. parts.push(group(indent(concat(partsGroup))));
  12945. }
  12946. if (
  12947. n.body &&
  12948. n.body.comments &&
  12949. hasLeadingOwnLineComment(options.originalText, n.body, options)
  12950. ) {
  12951. parts.push(hardline);
  12952. } else {
  12953. parts.push(" ");
  12954. }
  12955. parts.push(path$$1.call(print, "body"));
  12956. return parts;
  12957. }
  12958. function printOptionalToken(path$$1) {
  12959. const node = path$$1.getValue();
  12960. if (!node.optional) {
  12961. return "";
  12962. }
  12963. if (
  12964. node.type === "CallExpression" ||
  12965. (node.type === "MemberExpression" && node.computed)
  12966. ) {
  12967. return "?.";
  12968. }
  12969. return "?";
  12970. }
  12971. function printMemberLookup(path$$1, options, print) {
  12972. const property = path$$1.call(print, "property");
  12973. const n = path$$1.getValue();
  12974. const optional = printOptionalToken(path$$1);
  12975. if (!n.computed) {
  12976. return concat([optional, ".", property]);
  12977. }
  12978. if (!n.property || isNumericLiteral(n.property)) {
  12979. return concat([optional, "[", property, "]"]);
  12980. }
  12981. return group(
  12982. concat([optional, "[", indent(concat([softline, property])), softline, "]"])
  12983. );
  12984. }
  12985. function printBindExpressionCallee(path$$1, options, print) {
  12986. return concat(["::", path$$1.call(print, "callee")]);
  12987. }
  12988. // We detect calls on member expressions specially to format a
  12989. // common pattern better. The pattern we are looking for is this:
  12990. //
  12991. // arr
  12992. // .map(x => x + 1)
  12993. // .filter(x => x > 10)
  12994. // .some(x => x % 2)
  12995. //
  12996. // The way it is structured in the AST is via a nested sequence of
  12997. // MemberExpression and CallExpression. We need to traverse the AST
  12998. // and make groups out of it to print it in the desired way.
  12999. function printMemberChain(path$$1, options, print) {
  13000. // The first phase is to linearize the AST by traversing it down.
  13001. //
  13002. // a().b()
  13003. // has the following AST structure:
  13004. // CallExpression(MemberExpression(CallExpression(Identifier)))
  13005. // and we transform it into
  13006. // [Identifier, CallExpression, MemberExpression, CallExpression]
  13007. const printedNodes = [];
  13008. // Here we try to retain one typed empty line after each call expression or
  13009. // the first group whether it is in parentheses or not
  13010. function shouldInsertEmptyLineAfter(node) {
  13011. const originalText = options.originalText;
  13012. const nextCharIndex = utilShared.getNextNonSpaceNonCommentCharacterIndex(
  13013. originalText,
  13014. node,
  13015. options
  13016. );
  13017. const nextChar = originalText.charAt(nextCharIndex);
  13018. // if it is cut off by a parenthesis, we only account for one typed empty
  13019. // line after that parenthesis
  13020. if (nextChar == ")") {
  13021. return utilShared.isNextLineEmptyAfterIndex(
  13022. originalText,
  13023. nextCharIndex + 1,
  13024. options
  13025. );
  13026. }
  13027. return utilShared.isNextLineEmpty(originalText, node, options);
  13028. }
  13029. function rec(path$$1) {
  13030. const node = path$$1.getValue();
  13031. if (
  13032. node.type === "CallExpression" &&
  13033. (isMemberish(node.callee) || node.callee.type === "CallExpression")
  13034. ) {
  13035. printedNodes.unshift({
  13036. node: node,
  13037. printed: concat([
  13038. comments.printComments(
  13039. path$$1,
  13040. () =>
  13041. concat([
  13042. printOptionalToken(path$$1),
  13043. printFunctionTypeParameters(path$$1, options, print),
  13044. printArgumentsList(path$$1, options, print)
  13045. ]),
  13046. options
  13047. ),
  13048. shouldInsertEmptyLineAfter(node) ? hardline : ""
  13049. ])
  13050. });
  13051. path$$1.call(callee => rec(callee), "callee");
  13052. } else if (isMemberish(node)) {
  13053. printedNodes.unshift({
  13054. node: node,
  13055. printed: comments.printComments(
  13056. path$$1,
  13057. () =>
  13058. node.type === "MemberExpression"
  13059. ? printMemberLookup(path$$1, options, print)
  13060. : printBindExpressionCallee(path$$1, options, print),
  13061. options
  13062. )
  13063. });
  13064. path$$1.call(object => rec(object), "object");
  13065. } else if (node.type === "TSNonNullExpression") {
  13066. printedNodes.unshift({
  13067. node: node,
  13068. printed: comments.printComments(path$$1, () => "!", options)
  13069. });
  13070. path$$1.call(expression => rec(expression), "expression");
  13071. } else {
  13072. printedNodes.unshift({
  13073. node: node,
  13074. printed: path$$1.call(print)
  13075. });
  13076. }
  13077. }
  13078. // Note: the comments of the root node have already been printed, so we
  13079. // need to extract this first call without printing them as they would
  13080. // if handled inside of the recursive call.
  13081. const node = path$$1.getValue();
  13082. printedNodes.unshift({
  13083. node,
  13084. printed: concat([
  13085. printOptionalToken(path$$1),
  13086. printFunctionTypeParameters(path$$1, options, print),
  13087. printArgumentsList(path$$1, options, print)
  13088. ])
  13089. });
  13090. path$$1.call(callee => rec(callee), "callee");
  13091. // Once we have a linear list of printed nodes, we want to create groups out
  13092. // of it.
  13093. //
  13094. // a().b.c().d().e
  13095. // will be grouped as
  13096. // [
  13097. // [Identifier, CallExpression],
  13098. // [MemberExpression, MemberExpression, CallExpression],
  13099. // [MemberExpression, CallExpression],
  13100. // [MemberExpression],
  13101. // ]
  13102. // so that we can print it as
  13103. // a()
  13104. // .b.c()
  13105. // .d()
  13106. // .e
  13107. // The first group is the first node followed by
  13108. // - as many CallExpression as possible
  13109. // < fn()()() >.something()
  13110. // - as many array acessors as possible
  13111. // < fn()[0][1][2] >.something()
  13112. // - then, as many MemberExpression as possible but the last one
  13113. // < this.items >.something()
  13114. const groups = [];
  13115. let currentGroup = [printedNodes[0]];
  13116. let i = 1;
  13117. for (; i < printedNodes.length; ++i) {
  13118. if (
  13119. printedNodes[i].node.type === "TSNonNullExpression" ||
  13120. printedNodes[i].node.type === "CallExpression" ||
  13121. (printedNodes[i].node.type === "MemberExpression" &&
  13122. printedNodes[i].node.computed &&
  13123. isNumericLiteral(printedNodes[i].node.property))
  13124. ) {
  13125. currentGroup.push(printedNodes[i]);
  13126. } else {
  13127. break;
  13128. }
  13129. }
  13130. if (printedNodes[0].node.type !== "CallExpression") {
  13131. for (; i + 1 < printedNodes.length; ++i) {
  13132. if (
  13133. isMemberish(printedNodes[i].node) &&
  13134. isMemberish(printedNodes[i + 1].node)
  13135. ) {
  13136. currentGroup.push(printedNodes[i]);
  13137. } else {
  13138. break;
  13139. }
  13140. }
  13141. }
  13142. groups.push(currentGroup);
  13143. currentGroup = [];
  13144. // Then, each following group is a sequence of MemberExpression followed by
  13145. // a sequence of CallExpression. To compute it, we keep adding things to the
  13146. // group until we has seen a CallExpression in the past and reach a
  13147. // MemberExpression
  13148. let hasSeenCallExpression = false;
  13149. for (; i < printedNodes.length; ++i) {
  13150. if (hasSeenCallExpression && isMemberish(printedNodes[i].node)) {
  13151. // [0] should be appended at the end of the group instead of the
  13152. // beginning of the next one
  13153. if (
  13154. printedNodes[i].node.computed &&
  13155. isNumericLiteral(printedNodes[i].node.property)
  13156. ) {
  13157. currentGroup.push(printedNodes[i]);
  13158. continue;
  13159. }
  13160. groups.push(currentGroup);
  13161. currentGroup = [];
  13162. hasSeenCallExpression = false;
  13163. }
  13164. if (printedNodes[i].node.type === "CallExpression") {
  13165. hasSeenCallExpression = true;
  13166. }
  13167. currentGroup.push(printedNodes[i]);
  13168. if (
  13169. printedNodes[i].node.comments &&
  13170. printedNodes[i].node.comments.some(comment => comment.trailing)
  13171. ) {
  13172. groups.push(currentGroup);
  13173. currentGroup = [];
  13174. hasSeenCallExpression = false;
  13175. }
  13176. }
  13177. if (currentGroup.length > 0) {
  13178. groups.push(currentGroup);
  13179. }
  13180. // There are cases like Object.keys(), Observable.of(), _.values() where
  13181. // they are the subject of all the chained calls and therefore should
  13182. // be kept on the same line:
  13183. //
  13184. // Object.keys(items)
  13185. // .filter(x => x)
  13186. // .map(x => x)
  13187. //
  13188. // In order to detect those cases, we use an heuristic: if the first
  13189. // node is just an identifier with the name starting with a capital
  13190. // letter, just a sequence of _$ or this. The rationale is that they are
  13191. // likely to be factories.
  13192. function isFactory(name) {
  13193. return name.match(/(^[A-Z])|^[_$]+$/);
  13194. }
  13195. const shouldMerge =
  13196. groups.length >= 2 &&
  13197. !groups[1][0].node.comments &&
  13198. ((groups[0].length === 1 &&
  13199. (groups[0][0].node.type === "ThisExpression" ||
  13200. (groups[0][0].node.type === "Identifier" &&
  13201. (isFactory(groups[0][0].node.name) ||
  13202. (groups[1].length && groups[1][0].node.computed))))) ||
  13203. (groups[0].length > 1 &&
  13204. groups[0][groups[0].length - 1].node.type === "MemberExpression" &&
  13205. groups[0][groups[0].length - 1].node.property.type === "Identifier" &&
  13206. (isFactory(groups[0][groups[0].length - 1].node.property.name) ||
  13207. (groups[1].length && groups[1][0].node.computed))));
  13208. function printGroup(printedGroup) {
  13209. return concat(printedGroup.map(tuple => tuple.printed));
  13210. }
  13211. function printIndentedGroup(groups) {
  13212. if (groups.length === 0) {
  13213. return "";
  13214. }
  13215. return indent(
  13216. group(concat([hardline, join(hardline, groups.map(printGroup))]))
  13217. );
  13218. }
  13219. const printedGroups = groups.map(printGroup);
  13220. const oneLine = concat(printedGroups);
  13221. const cutoff = shouldMerge ? 3 : 2;
  13222. const flatGroups = groups
  13223. .slice(0, cutoff)
  13224. .reduce((res, group) => res.concat(group), []);
  13225. const hasComment =
  13226. flatGroups.slice(1, -1).some(node => hasLeadingComment(node.node)) ||
  13227. flatGroups.slice(0, -1).some(node => hasTrailingComment(node.node)) ||
  13228. (groups[cutoff] && hasLeadingComment(groups[cutoff][0].node));
  13229. // If we only have a single `.`, we shouldn't do anything fancy and just
  13230. // render everything concatenated together.
  13231. if (groups.length <= cutoff && !hasComment) {
  13232. return group(oneLine);
  13233. }
  13234. // Find out the last node in the first group and check if it has an
  13235. // empty line after
  13236. const lastNodeBeforeIndent = util$1.getLast(
  13237. shouldMerge ? groups.slice(1, 2)[0] : groups[0]
  13238. ).node;
  13239. const shouldHaveEmptyLineBeforeIndent =
  13240. lastNodeBeforeIndent.type !== "CallExpression" &&
  13241. shouldInsertEmptyLineAfter(lastNodeBeforeIndent);
  13242. const expanded = concat([
  13243. printGroup(groups[0]),
  13244. shouldMerge ? concat(groups.slice(1, 2).map(printGroup)) : "",
  13245. shouldHaveEmptyLineBeforeIndent ? hardline : "",
  13246. printIndentedGroup(groups.slice(shouldMerge ? 2 : 1))
  13247. ]);
  13248. const callExpressionCount = printedNodes.filter(
  13249. tuple => tuple.node.type === "CallExpression"
  13250. ).length;
  13251. // We don't want to print in one line if there's:
  13252. // * A comment.
  13253. // * 3 or more chained calls.
  13254. // * Any group but the last one has a hard line.
  13255. // If the last group is a function it's okay to inline if it fits.
  13256. if (
  13257. hasComment ||
  13258. callExpressionCount >= 3 ||
  13259. printedGroups.slice(0, -1).some(willBreak$1)
  13260. ) {
  13261. return group(expanded);
  13262. }
  13263. return concat([
  13264. // We only need to check `oneLine` because if `expanded` is chosen
  13265. // that means that the parent group has already been broken
  13266. // naturally
  13267. willBreak$1(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent : "",
  13268. conditionalGroup([oneLine, expanded])
  13269. ]);
  13270. }
  13271. function isJSXNode(node) {
  13272. return (
  13273. node.type === "JSXElement" ||
  13274. node.type === "JSXFragment" ||
  13275. node.type === "TSJsxFragment"
  13276. );
  13277. }
  13278. function isEmptyJSXElement(node) {
  13279. if (node.children.length === 0) {
  13280. return true;
  13281. }
  13282. if (node.children.length > 1) {
  13283. return false;
  13284. }
  13285. // if there is one text child and does not contain any meaningful text
  13286. // we can treat the element as empty.
  13287. const child = node.children[0];
  13288. return isLiteral(child) && !isMeaningfulJSXText(child);
  13289. }
  13290. // Only space, newline, carriage return, and tab are treated as whitespace
  13291. // inside JSX.
  13292. const jsxWhitespaceChars = " \n\r\t";
  13293. const containsNonJsxWhitespaceRegex = new RegExp(
  13294. "[^" + jsxWhitespaceChars + "]"
  13295. );
  13296. const matchJsxWhitespaceRegex = new RegExp("([" + jsxWhitespaceChars + "]+)");
  13297. // Meaningful if it contains non-whitespace characters,
  13298. // or it contains whitespace without a new line.
  13299. function isMeaningfulJSXText(node) {
  13300. return (
  13301. isLiteral(node) &&
  13302. (containsNonJsxWhitespaceRegex.test(rawText(node)) ||
  13303. !/\n/.test(rawText(node)))
  13304. );
  13305. }
  13306. function conditionalExpressionChainContainsJSX(node) {
  13307. return Boolean(getConditionalChainContents(node).find(isJSXNode));
  13308. }
  13309. // If we have nested conditional expressions, we want to print them in JSX mode
  13310. // if there's at least one JSXElement somewhere in the tree.
  13311. //
  13312. // A conditional expression chain like this should be printed in normal mode,
  13313. // because there aren't JSXElements anywhere in it:
  13314. //
  13315. // isA ? "A" : isB ? "B" : isC ? "C" : "Unknown";
  13316. //
  13317. // But a conditional expression chain like this should be printed in JSX mode,
  13318. // because there is a JSXElement in the last ConditionalExpression:
  13319. //
  13320. // isA ? "A" : isB ? "B" : isC ? "C" : <span className="warning">Unknown</span>;
  13321. //
  13322. // This type of ConditionalExpression chain is structured like this in the AST:
  13323. //
  13324. // ConditionalExpression {
  13325. // test: ...,
  13326. // consequent: ...,
  13327. // alternate: ConditionalExpression {
  13328. // test: ...,
  13329. // consequent: ...,
  13330. // alternate: ConditionalExpression {
  13331. // test: ...,
  13332. // consequent: ...,
  13333. // alternate: ...,
  13334. // }
  13335. // }
  13336. // }
  13337. //
  13338. // We want to traverse over that shape and convert it into a flat structure so
  13339. // that we can find if there's a JSXElement somewhere inside.
  13340. function getConditionalChainContents(node) {
  13341. // Given this code:
  13342. //
  13343. // // Using a ConditionalExpression as the consequent is uncommon, but should
  13344. // // be handled.
  13345. // A ? B : C ? D : E ? F ? G : H : I
  13346. //
  13347. // which has this AST:
  13348. //
  13349. // ConditionalExpression {
  13350. // test: Identifier(A),
  13351. // consequent: Identifier(B),
  13352. // alternate: ConditionalExpression {
  13353. // test: Identifier(C),
  13354. // consequent: Identifier(D),
  13355. // alternate: ConditionalExpression {
  13356. // test: Identifier(E),
  13357. // consequent: ConditionalExpression {
  13358. // test: Identifier(F),
  13359. // consequent: Identifier(G),
  13360. // alternate: Identifier(H),
  13361. // },
  13362. // alternate: Identifier(I),
  13363. // }
  13364. // }
  13365. // }
  13366. //
  13367. // we should return this Array:
  13368. //
  13369. // [
  13370. // Identifier(A),
  13371. // Identifier(B),
  13372. // Identifier(C),
  13373. // Identifier(D),
  13374. // Identifier(E),
  13375. // Identifier(F),
  13376. // Identifier(G),
  13377. // Identifier(H),
  13378. // Identifier(I)
  13379. // ];
  13380. //
  13381. // This loses the information about whether each node was the test,
  13382. // consequent, or alternate, but we don't care about that here- we are only
  13383. // flattening this structure to find if there's any JSXElements inside.
  13384. const nonConditionalExpressions = [];
  13385. function recurse(node) {
  13386. if (node.type === "ConditionalExpression") {
  13387. recurse(node.test);
  13388. recurse(node.consequent);
  13389. recurse(node.alternate);
  13390. } else {
  13391. nonConditionalExpressions.push(node);
  13392. }
  13393. }
  13394. recurse(node);
  13395. return nonConditionalExpressions;
  13396. }
  13397. // Detect an expression node representing `{" "}`
  13398. function isJSXWhitespaceExpression(node) {
  13399. return (
  13400. node.type === "JSXExpressionContainer" &&
  13401. isLiteral(node.expression) &&
  13402. node.expression.value === " " &&
  13403. !node.expression.comments
  13404. );
  13405. }
  13406. // JSX Children are strange, mostly for two reasons:
  13407. // 1. JSX reads newlines into string values, instead of skipping them like JS
  13408. // 2. up to one whitespace between elements within a line is significant,
  13409. // but not between lines.
  13410. //
  13411. // Leading, trailing, and lone whitespace all need to
  13412. // turn themselves into the rather ugly `{' '}` when breaking.
  13413. //
  13414. // We print JSX using the `fill` doc primitive.
  13415. // This requires that we give it an array of alternating
  13416. // content and whitespace elements.
  13417. // To ensure this we add dummy `""` content elements as needed.
  13418. function printJSXChildren(path$$1, options, print, jsxWhitespace) {
  13419. const n = path$$1.getValue();
  13420. const children = [];
  13421. // using `map` instead of `each` because it provides `i`
  13422. path$$1.map((childPath, i) => {
  13423. const child = childPath.getValue();
  13424. if (isLiteral(child)) {
  13425. const text = rawText(child);
  13426. // Contains a non-whitespace character
  13427. if (isMeaningfulJSXText(child)) {
  13428. const words = text.split(matchJsxWhitespaceRegex);
  13429. // Starts with whitespace
  13430. if (words[0] === "") {
  13431. children.push("");
  13432. words.shift();
  13433. if (/\n/.test(words[0])) {
  13434. children.push(hardline);
  13435. } else {
  13436. children.push(jsxWhitespace);
  13437. }
  13438. words.shift();
  13439. }
  13440. let endWhitespace;
  13441. // Ends with whitespace
  13442. if (util$1.getLast(words) === "") {
  13443. words.pop();
  13444. endWhitespace = words.pop();
  13445. }
  13446. // This was whitespace only without a new line.
  13447. if (words.length === 0) {
  13448. return;
  13449. }
  13450. words.forEach((word, i) => {
  13451. if (i % 2 === 1) {
  13452. children.push(line);
  13453. } else {
  13454. children.push(word);
  13455. }
  13456. });
  13457. if (endWhitespace !== undefined) {
  13458. if (/\n/.test(endWhitespace)) {
  13459. children.push(hardline);
  13460. } else {
  13461. children.push(jsxWhitespace);
  13462. }
  13463. } else {
  13464. // Ideally this would be a `hardline` to allow a break between
  13465. // tags and text.
  13466. // Unfortunately Facebook have a custom translation pipeline
  13467. // (https://github.com/prettier/prettier/issues/1581#issuecomment-300975032)
  13468. // that uses the JSX syntax, but does not follow the React whitespace
  13469. // rules.
  13470. // Ensuring that we never have a break between tags and text in JSX
  13471. // will allow Facebook to adopt Prettier without too much of an
  13472. // adverse effect on formatting algorithm.
  13473. children.push("");
  13474. }
  13475. } else if (/\n/.test(text)) {
  13476. // Keep (up to one) blank line between tags/expressions/text.
  13477. // Note: We don't keep blank lines between text elements.
  13478. if (text.match(/\n/g).length > 1) {
  13479. children.push("");
  13480. children.push(hardline);
  13481. }
  13482. } else {
  13483. children.push("");
  13484. children.push(jsxWhitespace);
  13485. }
  13486. } else {
  13487. const printedChild = print(childPath);
  13488. children.push(printedChild);
  13489. const next = n.children[i + 1];
  13490. const directlyFollowedByMeaningfulText =
  13491. next && isMeaningfulJSXText(next) && !/^[ \n\r\t]/.test(rawText(next));
  13492. if (directlyFollowedByMeaningfulText) {
  13493. // Potentially this could be a hardline as well.
  13494. // See the comment above about the Facebook translation pipeline as
  13495. // to why this is an empty string.
  13496. children.push("");
  13497. } else {
  13498. children.push(hardline);
  13499. }
  13500. }
  13501. }, "children");
  13502. return children;
  13503. }
  13504. // JSX expands children from the inside-out, instead of the outside-in.
  13505. // This is both to break children before attributes,
  13506. // and to ensure that when children break, their parents do as well.
  13507. //
  13508. // Any element that is written without any newlines and fits on a single line
  13509. // is left that way.
  13510. // Not only that, any user-written-line containing multiple JSX siblings
  13511. // should also be kept on one line if possible,
  13512. // so each user-written-line is wrapped in its own group.
  13513. //
  13514. // Elements that contain newlines or don't fit on a single line (recursively)
  13515. // are fully-split, using hardline and shouldBreak: true.
  13516. //
  13517. // To support that case properly, all leading and trailing spaces
  13518. // are stripped from the list of children, and replaced with a single hardline.
  13519. function printJSXElement(path$$1, options, print) {
  13520. const n = path$$1.getValue();
  13521. // Turn <div></div> into <div />
  13522. if (n.type === "JSXElement" && isEmptyJSXElement(n)) {
  13523. n.openingElement.selfClosing = true;
  13524. return path$$1.call(print, "openingElement");
  13525. }
  13526. const openingLines =
  13527. n.type === "JSXElement"
  13528. ? path$$1.call(print, "openingElement")
  13529. : path$$1.call(print, "openingFragment");
  13530. const closingLines =
  13531. n.type === "JSXElement"
  13532. ? path$$1.call(print, "closingElement")
  13533. : path$$1.call(print, "closingFragment");
  13534. if (
  13535. n.children.length === 1 &&
  13536. n.children[0].type === "JSXExpressionContainer" &&
  13537. (n.children[0].expression.type === "TemplateLiteral" ||
  13538. n.children[0].expression.type === "TaggedTemplateExpression")
  13539. ) {
  13540. return concat([
  13541. openingLines,
  13542. concat(path$$1.map(print, "children")),
  13543. closingLines
  13544. ]);
  13545. }
  13546. // Convert `{" "}` to text nodes containing a space.
  13547. // This makes it easy to turn them into `jsxWhitespace` which
  13548. // can then print as either a space or `{" "}` when breaking.
  13549. n.children = n.children.map(child => {
  13550. if (isJSXWhitespaceExpression(child)) {
  13551. return {
  13552. type: "JSXText",
  13553. value: " ",
  13554. raw: " "
  13555. };
  13556. }
  13557. return child;
  13558. });
  13559. const containsTag = n.children.filter(isJSXNode).length > 0;
  13560. const containsMultipleExpressions =
  13561. n.children.filter(child => child.type === "JSXExpressionContainer").length >
  13562. 1;
  13563. const containsMultipleAttributes =
  13564. n.type === "JSXElement" && n.openingElement.attributes.length > 1;
  13565. // Record any breaks. Should never go from true to false, only false to true.
  13566. let forcedBreak =
  13567. willBreak$1(openingLines) ||
  13568. containsTag ||
  13569. containsMultipleAttributes ||
  13570. containsMultipleExpressions;
  13571. const rawJsxWhitespace = options.singleQuote ? "{' '}" : '{" "}';
  13572. const jsxWhitespace = ifBreak(concat([rawJsxWhitespace, softline]), " ");
  13573. const children = printJSXChildren(path$$1, options, print, jsxWhitespace);
  13574. const containsText =
  13575. n.children.filter(child => isMeaningfulJSXText(child)).length > 0;
  13576. // We can end up we multiple whitespace elements with empty string
  13577. // content between them.
  13578. // We need to remove empty whitespace and softlines before JSX whitespace
  13579. // to get the correct output.
  13580. for (let i = children.length - 2; i >= 0; i--) {
  13581. const isPairOfEmptyStrings = children[i] === "" && children[i + 1] === "";
  13582. const isPairOfHardlines =
  13583. children[i] === hardline &&
  13584. children[i + 1] === "" &&
  13585. children[i + 2] === hardline;
  13586. const isLineFollowedByJSXWhitespace =
  13587. (children[i] === softline || children[i] === hardline) &&
  13588. children[i + 1] === "" &&
  13589. children[i + 2] === jsxWhitespace;
  13590. const isJSXWhitespaceFollowedByLine =
  13591. children[i] === jsxWhitespace &&
  13592. children[i + 1] === "" &&
  13593. (children[i + 2] === softline || children[i + 2] === hardline);
  13594. const isDoubleJSXWhitespace =
  13595. children[i] === jsxWhitespace &&
  13596. children[i + 1] === "" &&
  13597. children[i + 2] === jsxWhitespace;
  13598. if (
  13599. (isPairOfHardlines && containsText) ||
  13600. isPairOfEmptyStrings ||
  13601. isLineFollowedByJSXWhitespace ||
  13602. isDoubleJSXWhitespace
  13603. ) {
  13604. children.splice(i, 2);
  13605. } else if (isJSXWhitespaceFollowedByLine) {
  13606. children.splice(i + 1, 2);
  13607. }
  13608. }
  13609. // Trim trailing lines (or empty strings)
  13610. while (
  13611. children.length &&
  13612. (isLineNext$1(util$1.getLast(children)) ||
  13613. isEmpty$1(util$1.getLast(children)))
  13614. ) {
  13615. children.pop();
  13616. }
  13617. // Trim leading lines (or empty strings)
  13618. while (
  13619. children.length &&
  13620. (isLineNext$1(children[0]) || isEmpty$1(children[0])) &&
  13621. (isLineNext$1(children[1]) || isEmpty$1(children[1]))
  13622. ) {
  13623. children.shift();
  13624. children.shift();
  13625. }
  13626. // Tweak how we format children if outputting this element over multiple lines.
  13627. // Also detect whether we will force this element to output over multiple lines.
  13628. const multilineChildren = [];
  13629. children.forEach((child, i) => {
  13630. // There are a number of situations where we need to ensure we display
  13631. // whitespace as `{" "}` when outputting this element over multiple lines.
  13632. if (child === jsxWhitespace) {
  13633. if (i === 1 && children[i - 1] === "") {
  13634. if (children.length === 2) {
  13635. // Solitary whitespace
  13636. multilineChildren.push(rawJsxWhitespace);
  13637. return;
  13638. }
  13639. // Leading whitespace
  13640. multilineChildren.push(concat([rawJsxWhitespace, hardline]));
  13641. return;
  13642. } else if (i === children.length - 1) {
  13643. // Trailing whitespace
  13644. multilineChildren.push(rawJsxWhitespace);
  13645. return;
  13646. } else if (children[i - 1] === "" && children[i - 2] === hardline) {
  13647. // Whitespace after line break
  13648. multilineChildren.push(rawJsxWhitespace);
  13649. return;
  13650. }
  13651. }
  13652. multilineChildren.push(child);
  13653. if (willBreak$1(child)) {
  13654. forcedBreak = true;
  13655. }
  13656. });
  13657. // If there is text we use `fill` to fit as much onto each line as possible.
  13658. // When there is no text (just tags and expressions) we use `group`
  13659. // to output each on a separate line.
  13660. const content = containsText
  13661. ? fill(multilineChildren)
  13662. : group(concat(multilineChildren), { shouldBreak: true });
  13663. const multiLineElem = group(
  13664. concat([
  13665. openingLines,
  13666. indent(concat([hardline, content])),
  13667. hardline,
  13668. closingLines
  13669. ])
  13670. );
  13671. if (forcedBreak) {
  13672. return multiLineElem;
  13673. }
  13674. return conditionalGroup([
  13675. group(concat([openingLines, concat(children), closingLines])),
  13676. multiLineElem
  13677. ]);
  13678. }
  13679. function maybeWrapJSXElementInParens(path$$1, elem) {
  13680. const parent = path$$1.getParentNode();
  13681. if (!parent) {
  13682. return elem;
  13683. }
  13684. const NO_WRAP_PARENTS = {
  13685. ArrayExpression: true,
  13686. JSXAttribute: true,
  13687. JSXElement: true,
  13688. JSXExpressionContainer: true,
  13689. JSXFragment: true,
  13690. TSJsxFragment: true,
  13691. ExpressionStatement: true,
  13692. CallExpression: true,
  13693. ConditionalExpression: true
  13694. };
  13695. if (NO_WRAP_PARENTS[parent.type]) {
  13696. return elem;
  13697. }
  13698. return group(
  13699. concat([
  13700. ifBreak("("),
  13701. indent(concat([softline, elem])),
  13702. softline,
  13703. ifBreak(")")
  13704. ])
  13705. );
  13706. }
  13707. function isBinaryish(node) {
  13708. return node.type === "BinaryExpression" || node.type === "LogicalExpression";
  13709. }
  13710. function isMemberish(node) {
  13711. return (
  13712. node.type === "MemberExpression" ||
  13713. (node.type === "BindExpression" && node.object)
  13714. );
  13715. }
  13716. function shouldInlineLogicalExpression(node) {
  13717. if (node.type !== "LogicalExpression") {
  13718. return false;
  13719. }
  13720. if (
  13721. node.right.type === "ObjectExpression" &&
  13722. node.right.properties.length !== 0
  13723. ) {
  13724. return true;
  13725. }
  13726. if (
  13727. node.right.type === "ArrayExpression" &&
  13728. node.right.elements.length !== 0
  13729. ) {
  13730. return true;
  13731. }
  13732. if (isJSXNode(node.right)) {
  13733. return true;
  13734. }
  13735. return false;
  13736. }
  13737. // For binary expressions to be consistent, we need to group
  13738. // subsequent operators with the same precedence level under a single
  13739. // group. Otherwise they will be nested such that some of them break
  13740. // onto new lines but not all. Operators with the same precedence
  13741. // level should either all break or not. Because we group them by
  13742. // precedence level and the AST is structured based on precedence
  13743. // level, things are naturally broken up correctly, i.e. `&&` is
  13744. // broken before `+`.
  13745. function printBinaryishExpressions(
  13746. path$$1,
  13747. print,
  13748. options,
  13749. isNested,
  13750. isInsideParenthesis
  13751. ) {
  13752. let parts = [];
  13753. const node = path$$1.getValue();
  13754. // We treat BinaryExpression and LogicalExpression nodes the same.
  13755. if (isBinaryish(node)) {
  13756. // Put all operators with the same precedence level in the same
  13757. // group. The reason we only need to do this with the `left`
  13758. // expression is because given an expression like `1 + 2 - 3`, it
  13759. // is always parsed like `((1 + 2) - 3)`, meaning the `left` side
  13760. // is where the rest of the expression will exist. Binary
  13761. // expressions on the right side mean they have a difference
  13762. // precedence level and should be treated as a separate group, so
  13763. // print them normally. (This doesn't hold for the `**` operator,
  13764. // which is unique in that it is right-associative.)
  13765. if (util$1.shouldFlatten(node.operator, node.left.operator)) {
  13766. // Flatten them out by recursively calling this function.
  13767. parts = parts.concat(
  13768. path$$1.call(
  13769. left =>
  13770. printBinaryishExpressions(
  13771. left,
  13772. print,
  13773. options,
  13774. /* isNested */ true,
  13775. isInsideParenthesis
  13776. ),
  13777. "left"
  13778. )
  13779. );
  13780. } else {
  13781. parts.push(path$$1.call(print, "left"));
  13782. }
  13783. const shouldInline = shouldInlineLogicalExpression(node);
  13784. const lineBeforeOperator = node.operator === "|>";
  13785. const right = shouldInline
  13786. ? concat([node.operator, " ", path$$1.call(print, "right")])
  13787. : concat([
  13788. lineBeforeOperator ? softline : "",
  13789. node.operator,
  13790. lineBeforeOperator ? " " : line,
  13791. path$$1.call(print, "right")
  13792. ]);
  13793. // If there's only a single binary expression, we want to create a group
  13794. // in order to avoid having a small right part like -1 be on its own line.
  13795. const parent = path$$1.getParentNode();
  13796. const shouldGroup =
  13797. !(isInsideParenthesis && node.type === "LogicalExpression") &&
  13798. parent.type !== node.type &&
  13799. node.left.type !== node.type &&
  13800. node.right.type !== node.type;
  13801. parts.push(" ", shouldGroup ? group(right) : right);
  13802. // The root comments are already printed, but we need to manually print
  13803. // the other ones since we don't call the normal print on BinaryExpression,
  13804. // only for the left and right parts
  13805. if (isNested && node.comments) {
  13806. parts = comments.printComments(path$$1, () => concat(parts), options);
  13807. }
  13808. } else {
  13809. // Our stopping case. Simply print the node normally.
  13810. parts.push(path$$1.call(print));
  13811. }
  13812. return parts;
  13813. }
  13814. function printAssignmentRight(rightNode, printedRight, canBreak, options) {
  13815. if (hasLeadingOwnLineComment(options.originalText, rightNode, options)) {
  13816. return indent(concat([hardline, printedRight]));
  13817. }
  13818. if (canBreak) {
  13819. return indent(concat([line, printedRight]));
  13820. }
  13821. return concat([" ", printedRight]);
  13822. }
  13823. function printAssignment(
  13824. leftNode,
  13825. printedLeft,
  13826. operator,
  13827. rightNode,
  13828. printedRight,
  13829. options
  13830. ) {
  13831. if (!rightNode) {
  13832. return printedLeft;
  13833. }
  13834. const canBreak =
  13835. (isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode)) ||
  13836. (rightNode.type === "ConditionalExpression" &&
  13837. isBinaryish(rightNode.test) &&
  13838. !shouldInlineLogicalExpression(rightNode.test)) ||
  13839. ((leftNode.type === "Identifier" ||
  13840. isStringLiteral(leftNode) ||
  13841. leftNode.type === "MemberExpression") &&
  13842. (isStringLiteral(rightNode) || isMemberExpressionChain(rightNode)));
  13843. const printed = printAssignmentRight(
  13844. rightNode,
  13845. printedRight,
  13846. canBreak,
  13847. options
  13848. );
  13849. return group(concat([printedLeft, operator, printed]));
  13850. }
  13851. function adjustClause(node, clause, forceSpace) {
  13852. if (node.type === "EmptyStatement") {
  13853. return ";";
  13854. }
  13855. if (node.type === "BlockStatement" || forceSpace) {
  13856. return concat([" ", clause]);
  13857. }
  13858. return indent(concat([line, clause]));
  13859. }
  13860. function nodeStr(node, options, isFlowOrTypeScriptDirectiveLiteral) {
  13861. const raw = rawText(node);
  13862. const isDirectiveLiteral =
  13863. isFlowOrTypeScriptDirectiveLiteral || node.type === "DirectiveLiteral";
  13864. return util$1.printString(raw, options, isDirectiveLiteral);
  13865. }
  13866. function printRegex(node) {
  13867. const flags = node.flags
  13868. .split("")
  13869. .sort()
  13870. .join("");
  13871. return `/${node.pattern}/${flags}`;
  13872. }
  13873. function isLastStatement(path$$1) {
  13874. const parent = path$$1.getParentNode();
  13875. if (!parent) {
  13876. return true;
  13877. }
  13878. const node = path$$1.getValue();
  13879. const body = (parent.body || parent.consequent).filter(
  13880. stmt => stmt.type !== "EmptyStatement"
  13881. );
  13882. return body && body[body.length - 1] === node;
  13883. }
  13884. function hasLeadingComment(node) {
  13885. return node.comments && node.comments.some(comment => comment.leading);
  13886. }
  13887. function hasTrailingComment(node) {
  13888. return node.comments && node.comments.some(comment => comment.trailing);
  13889. }
  13890. function hasLeadingOwnLineComment(text, node, options) {
  13891. if (isJSXNode(node)) {
  13892. return util$1.hasNodeIgnoreComment(node);
  13893. }
  13894. const res =
  13895. node.comments &&
  13896. node.comments.some(
  13897. comment =>
  13898. comment.leading && util$1.hasNewline(text, options.locEnd(comment))
  13899. );
  13900. return res;
  13901. }
  13902. function hasNakedLeftSide(node) {
  13903. return (
  13904. node.type === "AssignmentExpression" ||
  13905. node.type === "BinaryExpression" ||
  13906. node.type === "LogicalExpression" ||
  13907. node.type === "ConditionalExpression" ||
  13908. node.type === "CallExpression" ||
  13909. node.type === "MemberExpression" ||
  13910. node.type === "SequenceExpression" ||
  13911. node.type === "TaggedTemplateExpression" ||
  13912. (node.type === "BindExpression" && !node.object) ||
  13913. (node.type === "UpdateExpression" && !node.prefix)
  13914. );
  13915. }
  13916. function isFlowAnnotationComment(text, typeAnnotation, options) {
  13917. const start = options.locStart(typeAnnotation);
  13918. const end = util$1.skipWhitespace(text, options.locEnd(typeAnnotation));
  13919. return text.substr(start, 2) === "/*" && text.substr(end, 2) === "*/";
  13920. }
  13921. function getLeftSide(node) {
  13922. if (node.expressions) {
  13923. return node.expressions[0];
  13924. }
  13925. return (
  13926. node.left ||
  13927. node.test ||
  13928. node.callee ||
  13929. node.object ||
  13930. node.tag ||
  13931. node.argument ||
  13932. node.expression
  13933. );
  13934. }
  13935. function getLeftSidePathName(path$$1, node) {
  13936. if (node.expressions) {
  13937. return ["expressions", 0];
  13938. }
  13939. if (node.left) {
  13940. return ["left"];
  13941. }
  13942. if (node.test) {
  13943. return ["test"];
  13944. }
  13945. if (node.callee) {
  13946. return ["callee"];
  13947. }
  13948. if (node.object) {
  13949. return ["object"];
  13950. }
  13951. if (node.tag) {
  13952. return ["tag"];
  13953. }
  13954. if (node.argument) {
  13955. return ["argument"];
  13956. }
  13957. if (node.expression) {
  13958. return ["expression"];
  13959. }
  13960. throw new Error("Unexpected node has no left side", node);
  13961. }
  13962. function exprNeedsASIProtection(path$$1, options) {
  13963. const node = path$$1.getValue();
  13964. const maybeASIProblem =
  13965. needsParens_1(path$$1, options) ||
  13966. node.type === "ParenthesizedExpression" ||
  13967. node.type === "TypeCastExpression" ||
  13968. (node.type === "ArrowFunctionExpression" &&
  13969. !shouldPrintParamsWithoutParens(path$$1, options)) ||
  13970. node.type === "ArrayExpression" ||
  13971. node.type === "ArrayPattern" ||
  13972. (node.type === "UnaryExpression" &&
  13973. node.prefix &&
  13974. (node.operator === "+" || node.operator === "-")) ||
  13975. node.type === "TemplateLiteral" ||
  13976. node.type === "TemplateElement" ||
  13977. isJSXNode(node) ||
  13978. node.type === "BindExpression" ||
  13979. node.type === "RegExpLiteral" ||
  13980. (node.type === "Literal" && node.pattern) ||
  13981. (node.type === "Literal" && node.regex);
  13982. if (maybeASIProblem) {
  13983. return true;
  13984. }
  13985. if (!hasNakedLeftSide(node)) {
  13986. return false;
  13987. }
  13988. return path$$1.call.apply(
  13989. path$$1,
  13990. [childPath => exprNeedsASIProtection(childPath, options)].concat(
  13991. getLeftSidePathName(path$$1, node)
  13992. )
  13993. );
  13994. }
  13995. function stmtNeedsASIProtection(path$$1, options) {
  13996. const node = path$$1.getNode();
  13997. if (node.type !== "ExpressionStatement") {
  13998. return false;
  13999. }
  14000. return path$$1.call(
  14001. childPath => exprNeedsASIProtection(childPath, options),
  14002. "expression"
  14003. );
  14004. }
  14005. function classPropMayCauseASIProblems(path$$1) {
  14006. const node = path$$1.getNode();
  14007. if (node.type !== "ClassProperty") {
  14008. return false;
  14009. }
  14010. const name = node.key && node.key.name;
  14011. // this isn't actually possible yet with most parsers available today
  14012. // so isn't properly tested yet.
  14013. if (
  14014. (name === "static" || name === "get" || name === "set") &&
  14015. !node.value &&
  14016. !node.typeAnnotation
  14017. ) {
  14018. return true;
  14019. }
  14020. }
  14021. function classChildNeedsASIProtection(node) {
  14022. if (!node) {
  14023. return;
  14024. }
  14025. if (!node.computed) {
  14026. const name = node.key && node.key.name;
  14027. if (name === "in" || name === "instanceof") {
  14028. return true;
  14029. }
  14030. }
  14031. switch (node.type) {
  14032. case "ClassProperty":
  14033. case "TSAbstractClassProperty":
  14034. return node.computed;
  14035. case "MethodDefinition": // Flow
  14036. case "TSAbstractMethodDefinition": // TypeScript
  14037. case "ClassMethod": {
  14038. // Babylon
  14039. const isAsync = node.value ? node.value.async : node.async;
  14040. const isGenerator = node.value ? node.value.generator : node.generator;
  14041. if (
  14042. isAsync ||
  14043. node.static ||
  14044. node.kind === "get" ||
  14045. node.kind === "set"
  14046. ) {
  14047. return false;
  14048. }
  14049. if (node.computed || isGenerator) {
  14050. return true;
  14051. }
  14052. return false;
  14053. }
  14054. default:
  14055. /* istanbul ignore next */
  14056. return false;
  14057. }
  14058. }
  14059. // This recurses the return argument, looking for the first token
  14060. // (the leftmost leaf node) and, if it (or its parents) has any
  14061. // leadingComments, returns true (so it can be wrapped in parens).
  14062. function returnArgumentHasLeadingComment(options, argument) {
  14063. if (hasLeadingOwnLineComment(options.originalText, argument, options)) {
  14064. return true;
  14065. }
  14066. if (hasNakedLeftSide(argument)) {
  14067. let leftMost = argument;
  14068. let newLeftMost;
  14069. while ((newLeftMost = getLeftSide(leftMost))) {
  14070. leftMost = newLeftMost;
  14071. if (hasLeadingOwnLineComment(options.originalText, leftMost, options)) {
  14072. return true;
  14073. }
  14074. }
  14075. }
  14076. return false;
  14077. }
  14078. function isMemberExpressionChain(node) {
  14079. if (node.type !== "MemberExpression") {
  14080. return false;
  14081. }
  14082. if (node.object.type === "Identifier") {
  14083. return true;
  14084. }
  14085. return isMemberExpressionChain(node.object);
  14086. }
  14087. // Hack to differentiate between the following two which have the same ast
  14088. // type T = { method: () => void };
  14089. // type T = { method(): void };
  14090. function isObjectTypePropertyAFunction(node, options) {
  14091. return (
  14092. node.type === "ObjectTypeProperty" &&
  14093. node.value.type === "FunctionTypeAnnotation" &&
  14094. !node.static &&
  14095. !isFunctionNotation(node, options)
  14096. );
  14097. }
  14098. // TODO: This is a bad hack and we need a better way to distinguish between
  14099. // arrow functions and otherwise
  14100. function isFunctionNotation(node, options) {
  14101. return isGetterOrSetter(node) || sameLocStart(node, node.value, options);
  14102. }
  14103. function isGetterOrSetter(node) {
  14104. return node.kind === "get" || node.kind === "set";
  14105. }
  14106. function sameLocStart(nodeA, nodeB, options) {
  14107. return options.locStart(nodeA) === options.locStart(nodeB);
  14108. }
  14109. // Hack to differentiate between the following two which have the same ast
  14110. // declare function f(a): void;
  14111. // var f: (a) => void;
  14112. function isTypeAnnotationAFunction(node, options) {
  14113. return (
  14114. (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") &&
  14115. node.typeAnnotation.type === "FunctionTypeAnnotation" &&
  14116. !node.static &&
  14117. !sameLocStart(node, node.typeAnnotation, options)
  14118. );
  14119. }
  14120. function isNodeStartingWithDeclare(node, options) {
  14121. if (!(options.parser === "flow" || options.parser === "typescript")) {
  14122. return false;
  14123. }
  14124. return (
  14125. options.originalText
  14126. .slice(0, options.locStart(node))
  14127. .match(/declare[ \t]*$/) ||
  14128. options.originalText
  14129. .slice(node.range[0], node.range[1])
  14130. .startsWith("declare ")
  14131. );
  14132. }
  14133. function shouldHugType(node) {
  14134. if (isObjectType(node)) {
  14135. return true;
  14136. }
  14137. if (node.type === "UnionTypeAnnotation" || node.type === "TSUnionType") {
  14138. const voidCount = node.types.filter(
  14139. n =>
  14140. n.type === "VoidTypeAnnotation" ||
  14141. n.type === "TSVoidKeyword" ||
  14142. n.type === "NullLiteralTypeAnnotation" ||
  14143. n.type === "TSNullKeyword"
  14144. ).length;
  14145. const objectCount = node.types.filter(
  14146. n =>
  14147. n.type === "ObjectTypeAnnotation" ||
  14148. n.type === "TSTypeLiteral" ||
  14149. // This is a bit aggressive but captures Array<{x}>
  14150. n.type === "GenericTypeAnnotation" ||
  14151. n.type === "TSTypeReference"
  14152. ).length;
  14153. if (node.types.length - 1 === voidCount && objectCount > 0) {
  14154. return true;
  14155. }
  14156. }
  14157. return false;
  14158. }
  14159. function shouldHugArguments(fun) {
  14160. return (
  14161. fun &&
  14162. fun.params &&
  14163. fun.params.length === 1 &&
  14164. !fun.params[0].comments &&
  14165. (fun.params[0].type === "ObjectPattern" ||
  14166. fun.params[0].type === "ArrayPattern" ||
  14167. (fun.params[0].type === "Identifier" &&
  14168. fun.params[0].typeAnnotation &&
  14169. (fun.params[0].typeAnnotation.type === "TypeAnnotation" ||
  14170. fun.params[0].typeAnnotation.type === "TSTypeAnnotation") &&
  14171. isObjectType(fun.params[0].typeAnnotation.typeAnnotation)) ||
  14172. (fun.params[0].type === "FunctionTypeParam" &&
  14173. isObjectType(fun.params[0].typeAnnotation)) ||
  14174. (fun.params[0].type === "AssignmentPattern" &&
  14175. (fun.params[0].left.type === "ObjectPattern" ||
  14176. fun.params[0].left.type === "ArrayPattern") &&
  14177. (fun.params[0].right.type === "Identifier" ||
  14178. (fun.params[0].right.type === "ObjectExpression" &&
  14179. fun.params[0].right.properties.length === 0) ||
  14180. (fun.params[0].right.type === "ArrayExpression" &&
  14181. fun.params[0].right.elements.length === 0)))) &&
  14182. !fun.rest
  14183. );
  14184. }
  14185. function templateLiteralHasNewLines(template) {
  14186. return template.quasis.some(quasi => quasi.value.raw.includes("\n"));
  14187. }
  14188. function isTemplateOnItsOwnLine(n, text, options) {
  14189. return (
  14190. ((n.type === "TemplateLiteral" && templateLiteralHasNewLines(n)) ||
  14191. (n.type === "TaggedTemplateExpression" &&
  14192. templateLiteralHasNewLines(n.quasi))) &&
  14193. !util$1.hasNewline(text, options.locStart(n), { backwards: true })
  14194. );
  14195. }
  14196. function printArrayItems(path$$1, options, printPath, print) {
  14197. const printedElements = [];
  14198. let separatorParts = [];
  14199. path$$1.each(childPath => {
  14200. printedElements.push(concat(separatorParts));
  14201. printedElements.push(group(print(childPath)));
  14202. separatorParts = [",", line];
  14203. if (
  14204. childPath.getValue() &&
  14205. utilShared.isNextLineEmpty(
  14206. options.originalText,
  14207. childPath.getValue(),
  14208. options
  14209. )
  14210. ) {
  14211. separatorParts.push(softline);
  14212. }
  14213. }, printPath);
  14214. return concat(printedElements);
  14215. }
  14216. function hasDanglingComments(node) {
  14217. return (
  14218. node.comments &&
  14219. node.comments.some(comment => !comment.leading && !comment.trailing)
  14220. );
  14221. }
  14222. function needsHardlineAfterDanglingComment(node) {
  14223. if (!node.comments) {
  14224. return false;
  14225. }
  14226. const lastDanglingComment = util$1.getLast(
  14227. node.comments.filter(comment => !comment.leading && !comment.trailing)
  14228. );
  14229. return (
  14230. lastDanglingComment && !util$1.isBlockComment(lastDanglingComment)
  14231. );
  14232. }
  14233. function isLiteral(node) {
  14234. return (
  14235. node.type === "BooleanLiteral" ||
  14236. node.type === "DirectiveLiteral" ||
  14237. node.type === "Literal" ||
  14238. node.type === "NullLiteral" ||
  14239. node.type === "NumericLiteral" ||
  14240. node.type === "RegExpLiteral" ||
  14241. node.type === "StringLiteral" ||
  14242. node.type === "TemplateLiteral" ||
  14243. node.type === "TSTypeLiteral" ||
  14244. node.type === "JSXText"
  14245. );
  14246. }
  14247. function isNumericLiteral(node) {
  14248. return (
  14249. node.type === "NumericLiteral" ||
  14250. (node.type === "Literal" && typeof node.value === "number")
  14251. );
  14252. }
  14253. function isStringLiteral(node) {
  14254. return (
  14255. node.type === "StringLiteral" ||
  14256. (node.type === "Literal" && typeof node.value === "string")
  14257. );
  14258. }
  14259. function isObjectType(n) {
  14260. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral";
  14261. }
  14262. // eg; `describe("some string", (done) => {})`
  14263. function isTestCall(n, parent) {
  14264. const unitTestRe = /^(skip|(f|x)?(it|describe|test))$/;
  14265. if (n.arguments.length === 1) {
  14266. if (
  14267. n.callee.type === "Identifier" &&
  14268. n.callee.name === "async" &&
  14269. parent &&
  14270. parent.type === "CallExpression" &&
  14271. isTestCall(parent)
  14272. ) {
  14273. return isFunctionOrArrowExpression(n.arguments[0].type);
  14274. }
  14275. if (isUnitTestSetUp(n)) {
  14276. return (
  14277. isFunctionOrArrowExpression(n.arguments[0].type) ||
  14278. isIdentiferAsync(n.arguments[0])
  14279. );
  14280. }
  14281. } else if (n.arguments.length === 2) {
  14282. if (
  14283. ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name)) ||
  14284. isSkipOrOnlyBlock(n)) &&
  14285. (isTemplateLiteral(n.arguments[0]) || isStringLiteral(n.arguments[0]))
  14286. ) {
  14287. return (
  14288. (isFunctionOrArrowExpression(n.arguments[1].type) &&
  14289. n.arguments[1].params.length <= 1) ||
  14290. isIdentiferAsync(n.arguments[1])
  14291. );
  14292. }
  14293. }
  14294. return false;
  14295. }
  14296. function isSkipOrOnlyBlock(node) {
  14297. const unitTestRe = /^(skip|(f|x)?(it|describe|test))$/;
  14298. return (
  14299. node.callee.type === "MemberExpression" &&
  14300. node.callee.object.type === "Identifier" &&
  14301. node.callee.property.type === "Identifier" &&
  14302. unitTestRe.test(node.callee.object.name) &&
  14303. (node.callee.property.name === "only" ||
  14304. node.callee.property.name === "skip")
  14305. );
  14306. }
  14307. function isTemplateLiteral(node) {
  14308. return node.type === "TemplateLiteral";
  14309. }
  14310. function isIdentiferAsync(node) {
  14311. return (
  14312. node.type === "CallExpression" &&
  14313. node.callee.type === "Identifier" &&
  14314. node.callee.name === "async"
  14315. );
  14316. }
  14317. function isFunctionOrArrowExpression(type) {
  14318. return type === "FunctionExpression" || type === "ArrowFunctionExpression";
  14319. }
  14320. function isUnitTestSetUp(n) {
  14321. const unitTestSetUpRe = /^(before|after)(Each|All)$/;
  14322. return (
  14323. n.callee.type === "Identifier" &&
  14324. unitTestSetUpRe.test(n.callee.name) &&
  14325. n.arguments.length === 1
  14326. );
  14327. }
  14328. function isTheOnlyJSXElementInMarkdown(options, path$$1) {
  14329. if (options.parentParser !== "markdown") {
  14330. return false;
  14331. }
  14332. const node = path$$1.getNode();
  14333. if (!node.expression || !isJSXNode(node.expression)) {
  14334. return false;
  14335. }
  14336. const parent = path$$1.getParentNode();
  14337. return parent.type === "Program" && parent.body.length == 1;
  14338. }
  14339. function willPrintOwnComments(path$$1) {
  14340. const node = path$$1.getValue();
  14341. const parent = path$$1.getParentNode();
  14342. return (
  14343. ((node && isJSXNode(node)) ||
  14344. (parent &&
  14345. (parent.type === "JSXSpreadAttribute" ||
  14346. parent.type === "JSXSpreadChild" ||
  14347. parent.type === "UnionTypeAnnotation" ||
  14348. parent.type === "TSUnionType" ||
  14349. ((parent.type === "ClassDeclaration" ||
  14350. parent.type === "ClassExpression") &&
  14351. parent.superClass === node)))) &&
  14352. !util$1.hasIgnoreComment(path$$1)
  14353. );
  14354. }
  14355. function canAttachComment(node) {
  14356. return (
  14357. node.type &&
  14358. node.type !== "CommentBlock" &&
  14359. node.type !== "CommentLine" &&
  14360. node.type !== "Line" &&
  14361. node.type !== "Block" &&
  14362. node.type !== "EmptyStatement" &&
  14363. node.type !== "TemplateElement" &&
  14364. node.type !== "Import" &&
  14365. !(node.callee && node.callee.type === "Import")
  14366. );
  14367. }
  14368. function printComment(commentPath, options) {
  14369. const comment = commentPath.getValue();
  14370. switch (comment.type) {
  14371. case "CommentBlock":
  14372. case "Block": {
  14373. if (isJsDocComment(comment)) {
  14374. return printJsDocComment(comment);
  14375. }
  14376. const isInsideFlowComment =
  14377. options.originalText.substr(options.locEnd(comment) - 3, 3) === "*-/";
  14378. return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
  14379. }
  14380. case "CommentLine":
  14381. case "Line":
  14382. // Print shebangs with the proper comment characters
  14383. if (
  14384. options.originalText.slice(options.locStart(comment)).startsWith("#!")
  14385. ) {
  14386. return "#!" + comment.value.trimRight();
  14387. }
  14388. return "//" + comment.value.trimRight();
  14389. default:
  14390. throw new Error("Not a comment: " + JSON.stringify(comment));
  14391. }
  14392. }
  14393. function isJsDocComment(comment) {
  14394. const lines = comment.value.split("\n");
  14395. return (
  14396. lines.length > 1 &&
  14397. lines.slice(0, lines.length - 1).every(line => line.trim()[0] === "*")
  14398. );
  14399. }
  14400. function printJsDocComment(comment) {
  14401. const lines = comment.value.split("\n");
  14402. return concat([
  14403. "/*",
  14404. join(
  14405. hardline,
  14406. lines.map(
  14407. (line, index) =>
  14408. (index > 0 ? " " : "") +
  14409. (index < lines.length - 1 ? line.trim() : line.trimLeft())
  14410. )
  14411. ),
  14412. "*/"
  14413. ]);
  14414. }
  14415. function rawText(node) {
  14416. return node.extra ? node.extra.raw : node.raw;
  14417. }
  14418. var printerEstree = {
  14419. print: genericPrint,
  14420. embed: embed_1,
  14421. insertPragma,
  14422. massageAstNode: clean_1,
  14423. hasPrettierIgnore,
  14424. willPrintOwnComments,
  14425. canAttachComment,
  14426. printComment,
  14427. handleComments: {
  14428. ownLine: comments$2.handleOwnLineComment,
  14429. endOfLine: comments$2.handleEndOfLineComment,
  14430. remaining: comments$2.handleRemainingComment
  14431. }
  14432. };
  14433. const CATEGORY_JAVASCRIPT = "JavaScript";
  14434. // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js
  14435. var options = {
  14436. arrowParens: {
  14437. since: "1.9.0",
  14438. category: CATEGORY_JAVASCRIPT,
  14439. type: "choice",
  14440. default: "avoid",
  14441. description: "Include parentheses around a sole arrow function parameter.",
  14442. choices: [
  14443. {
  14444. value: "avoid",
  14445. description: "Omit parens when possible. Example: `x => x`"
  14446. },
  14447. {
  14448. value: "always",
  14449. description: "Always include parens. Example: `(x) => x`"
  14450. }
  14451. ]
  14452. },
  14453. bracketSpacing: {
  14454. since: "0.0.0",
  14455. category: CATEGORY_JAVASCRIPT,
  14456. type: "boolean",
  14457. default: true,
  14458. description: "Print spaces between brackets.",
  14459. oppositeDescription: "Do not print spaces between brackets."
  14460. },
  14461. jsxBracketSameLine: {
  14462. since: "0.17.0",
  14463. category: CATEGORY_JAVASCRIPT,
  14464. type: "boolean",
  14465. default: false,
  14466. description: "Put > on the last line instead of at a new line."
  14467. },
  14468. semi: {
  14469. since: "1.0.0",
  14470. category: CATEGORY_JAVASCRIPT,
  14471. type: "boolean",
  14472. default: true,
  14473. description: "Print semicolons.",
  14474. oppositeDescription:
  14475. "Do not print semicolons, except at the beginning of lines which may need them."
  14476. },
  14477. singleQuote: {
  14478. since: "0.0.0",
  14479. category: CATEGORY_JAVASCRIPT,
  14480. type: "boolean",
  14481. default: false,
  14482. description: "Use single quotes instead of double quotes."
  14483. },
  14484. trailingComma: {
  14485. since: "0.0.0",
  14486. category: CATEGORY_JAVASCRIPT,
  14487. type: "choice",
  14488. default: [
  14489. { since: "0.0.0", value: false },
  14490. { since: "0.19.0", value: "none" }
  14491. ],
  14492. description: "Print trailing commas wherever possible when multi-line.",
  14493. choices: [
  14494. { value: "none", description: "No trailing commas." },
  14495. {
  14496. value: "es5",
  14497. description:
  14498. "Trailing commas where valid in ES5 (objects, arrays, etc.)"
  14499. },
  14500. {
  14501. value: "all",
  14502. description:
  14503. "Trailing commas wherever possible (including function arguments)."
  14504. },
  14505. { value: true, deprecated: "0.19.0", redirect: "es5" },
  14506. { value: false, deprecated: "0.19.0", redirect: "none" }
  14507. ]
  14508. }
  14509. };
  14510. const hasPragma = pragma.hasPragma;
  14511. // Based on:
  14512. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  14513. const locStart = function(node) {
  14514. // Handle nodes with decorators. They should start at the first decorator
  14515. if (
  14516. node.declaration &&
  14517. node.declaration.decorators &&
  14518. node.declaration.decorators.length > 0
  14519. ) {
  14520. return locStart(node.declaration.decorators[0]);
  14521. }
  14522. if (node.decorators && node.decorators.length > 0) {
  14523. return locStart(node.decorators[0]);
  14524. }
  14525. if (node.__location) {
  14526. return node.__location.startOffset;
  14527. }
  14528. if (node.range) {
  14529. return node.range[0];
  14530. }
  14531. if (typeof node.start === "number") {
  14532. return node.start;
  14533. }
  14534. if (node.loc) {
  14535. return node.loc.start;
  14536. }
  14537. return null;
  14538. };
  14539. const locEnd = function(node) {
  14540. const endNode = node.nodes && util$1.getLast(node.nodes);
  14541. if (endNode && node.source && !node.source.end) {
  14542. node = endNode;
  14543. }
  14544. let loc;
  14545. if (node.range) {
  14546. loc = node.range[1];
  14547. } else if (typeof node.end === "number") {
  14548. loc = node.end;
  14549. }
  14550. if (node.__location) {
  14551. return node.__location.endOffset;
  14552. }
  14553. if (node.typeAnnotation) {
  14554. return Math.max(loc, locEnd(node.typeAnnotation));
  14555. }
  14556. if (node.loc && !loc) {
  14557. return node.loc.end;
  14558. }
  14559. return loc;
  14560. };
  14561. const languages = [
  14562. {
  14563. name: "JavaScript",
  14564. since: "0.0.0",
  14565. parsers: ["babylon", "flow"],
  14566. group: "JavaScript",
  14567. tmScope: "source.js",
  14568. aceMode: "javascript",
  14569. codemirrorMode: "javascript",
  14570. codemirrorMimeType: "text/javascript",
  14571. aliases: ["js", "node"],
  14572. extensions: [
  14573. ".js",
  14574. "._js",
  14575. ".bones",
  14576. ".es",
  14577. ".es6",
  14578. ".frag",
  14579. ".gs",
  14580. ".jake",
  14581. ".jsb",
  14582. ".jscad",
  14583. ".jsfl",
  14584. ".jsm",
  14585. ".jss",
  14586. ".mjs",
  14587. ".njs",
  14588. ".pac",
  14589. ".sjs",
  14590. ".ssjs",
  14591. ".xsjs",
  14592. ".xsjslib"
  14593. ],
  14594. filenames: ["Jakefile"],
  14595. linguistLanguageId: 183,
  14596. vscodeLanguageIds: ["javascript"]
  14597. },
  14598. {
  14599. name: "JSX",
  14600. since: "0.0.0",
  14601. parsers: ["babylon", "flow"],
  14602. group: "JavaScript",
  14603. extensions: [".jsx"],
  14604. tmScope: "source.js.jsx",
  14605. aceMode: "javascript",
  14606. codemirrorMode: "jsx",
  14607. codemirrorMimeType: "text/jsx",
  14608. liguistLanguageId: 178,
  14609. vscodeLanguageIds: ["javascriptreact"]
  14610. },
  14611. {
  14612. name: "TypeScript",
  14613. since: "1.4.0",
  14614. parsers: ["typescript-eslint"],
  14615. group: "JavaScript",
  14616. aliases: ["ts"],
  14617. extensions: [".ts", ".tsx"],
  14618. tmScope: "source.ts",
  14619. aceMode: "typescript",
  14620. codemirrorMode: "javascript",
  14621. codemirrorMimeType: "application/typescript",
  14622. liguistLanguageId: 378,
  14623. vscodeLanguageIds: ["typescript", "typescriptreact"]
  14624. },
  14625. {
  14626. name: "JSON",
  14627. since: "1.5.0",
  14628. parsers: ["json"],
  14629. group: "JavaScript",
  14630. tmScope: "source.json",
  14631. aceMode: "json",
  14632. codemirrorMode: "javascript",
  14633. codemirrorMimeType: "application/json",
  14634. extensions: [
  14635. ".json",
  14636. ".json5",
  14637. ".geojson",
  14638. ".JSON-tmLanguage",
  14639. ".topojson"
  14640. ],
  14641. filenames: [
  14642. ".arcconfig",
  14643. ".jshintrc",
  14644. ".babelrc",
  14645. ".eslintrc",
  14646. ".prettierrc",
  14647. "composer.lock",
  14648. "mcmod.info"
  14649. ],
  14650. linguistLanguageId: 174,
  14651. vscodeLanguageIds: ["json", "jsonc"]
  14652. }
  14653. ];
  14654. const typescript = {
  14655. get parse() {
  14656. return require("./parser-typescript");
  14657. },
  14658. astFormat: "estree",
  14659. hasPragma,
  14660. locStart,
  14661. locEnd
  14662. };
  14663. const babylon = {
  14664. get parse() {
  14665. return require("./parser-babylon");
  14666. },
  14667. astFormat: "estree",
  14668. hasPragma,
  14669. locStart,
  14670. locEnd
  14671. };
  14672. const parsers = {
  14673. babylon,
  14674. json: Object.assign({}, babylon, {
  14675. hasPragma() {
  14676. return false;
  14677. }
  14678. }),
  14679. flow: {
  14680. get parse() {
  14681. return require("./parser-flow");
  14682. },
  14683. astFormat: "estree",
  14684. hasPragma,
  14685. locStart,
  14686. locEnd
  14687. },
  14688. "typescript-eslint": typescript,
  14689. // TODO: Delete this in 2.0
  14690. typescript
  14691. };
  14692. const printers = {
  14693. estree: printerEstree
  14694. };
  14695. var languageJs = {
  14696. languages,
  14697. options,
  14698. parsers,
  14699. printers,
  14700. locStart,
  14701. locEnd
  14702. };
  14703. var index$1 = [
  14704. "a",
  14705. "abbr",
  14706. "acronym",
  14707. "address",
  14708. "applet",
  14709. "area",
  14710. "article",
  14711. "aside",
  14712. "audio",
  14713. "b",
  14714. "base",
  14715. "basefont",
  14716. "bdi",
  14717. "bdo",
  14718. "bgsound",
  14719. "big",
  14720. "blink",
  14721. "blockquote",
  14722. "body",
  14723. "br",
  14724. "button",
  14725. "canvas",
  14726. "caption",
  14727. "center",
  14728. "cite",
  14729. "code",
  14730. "col",
  14731. "colgroup",
  14732. "command",
  14733. "content",
  14734. "data",
  14735. "datalist",
  14736. "dd",
  14737. "del",
  14738. "details",
  14739. "dfn",
  14740. "dialog",
  14741. "dir",
  14742. "div",
  14743. "dl",
  14744. "dt",
  14745. "element",
  14746. "em",
  14747. "embed",
  14748. "fieldset",
  14749. "figcaption",
  14750. "figure",
  14751. "font",
  14752. "footer",
  14753. "form",
  14754. "frame",
  14755. "frameset",
  14756. "h1",
  14757. "h2",
  14758. "h3",
  14759. "h4",
  14760. "h5",
  14761. "h6",
  14762. "head",
  14763. "header",
  14764. "hgroup",
  14765. "hr",
  14766. "html",
  14767. "i",
  14768. "iframe",
  14769. "image",
  14770. "img",
  14771. "input",
  14772. "ins",
  14773. "isindex",
  14774. "kbd",
  14775. "keygen",
  14776. "label",
  14777. "legend",
  14778. "li",
  14779. "link",
  14780. "listing",
  14781. "main",
  14782. "map",
  14783. "mark",
  14784. "marquee",
  14785. "math",
  14786. "menu",
  14787. "menuitem",
  14788. "meta",
  14789. "meter",
  14790. "multicol",
  14791. "nav",
  14792. "nextid",
  14793. "nobr",
  14794. "noembed",
  14795. "noframes",
  14796. "noscript",
  14797. "object",
  14798. "ol",
  14799. "optgroup",
  14800. "option",
  14801. "output",
  14802. "p",
  14803. "param",
  14804. "picture",
  14805. "plaintext",
  14806. "pre",
  14807. "progress",
  14808. "q",
  14809. "rb",
  14810. "rbc",
  14811. "rp",
  14812. "rt",
  14813. "rtc",
  14814. "ruby",
  14815. "s",
  14816. "samp",
  14817. "script",
  14818. "section",
  14819. "select",
  14820. "shadow",
  14821. "slot",
  14822. "small",
  14823. "source",
  14824. "spacer",
  14825. "span",
  14826. "strike",
  14827. "strong",
  14828. "style",
  14829. "sub",
  14830. "summary",
  14831. "sup",
  14832. "svg",
  14833. "table",
  14834. "tbody",
  14835. "td",
  14836. "template",
  14837. "textarea",
  14838. "tfoot",
  14839. "th",
  14840. "thead",
  14841. "time",
  14842. "title",
  14843. "tr",
  14844. "track",
  14845. "tt",
  14846. "u",
  14847. "ul",
  14848. "var",
  14849. "video",
  14850. "wbr",
  14851. "xmp"
  14852. ]
  14853. ;
  14854. var htmlTagNames = Object.freeze({
  14855. default: index$1
  14856. });
  14857. var htmlTagNames$1 = ( htmlTagNames && index$1 ) || htmlTagNames;
  14858. function clean$2(ast, newObj) {
  14859. if (
  14860. ast.type === "media-query" ||
  14861. ast.type === "media-query-list" ||
  14862. ast.type === "media-feature-expression"
  14863. ) {
  14864. delete newObj.value;
  14865. }
  14866. if (ast.type === "css-rule") {
  14867. delete newObj.params;
  14868. }
  14869. if (ast.type === "selector-combinator") {
  14870. newObj.value = newObj.value.replace(/\s+/g, " ");
  14871. }
  14872. if (ast.type === "media-feature") {
  14873. newObj.value = newObj.value.replace(/ /g, "");
  14874. }
  14875. if (
  14876. (ast.type === "value-word" &&
  14877. ((ast.isColor && ast.isHex) ||
  14878. ["initial", "inherit", "unset", "revert"].indexOf(
  14879. newObj.value.replace().toLowerCase()
  14880. ) !== -1)) ||
  14881. ast.type === "media-feature" ||
  14882. ast.type === "selector-root-invalid" ||
  14883. ast.type === "selector-pseudo"
  14884. ) {
  14885. newObj.value = newObj.value.toLowerCase();
  14886. }
  14887. if (ast.type === "css-decl") {
  14888. newObj.prop = newObj.prop.toLowerCase();
  14889. }
  14890. if (ast.type === "css-atrule" || ast.type === "css-import") {
  14891. newObj.name = newObj.name.toLowerCase();
  14892. }
  14893. if (ast.type === "value-number") {
  14894. newObj.unit = newObj.unit.toLowerCase();
  14895. }
  14896. if (
  14897. (ast.type === "media-feature" ||
  14898. ast.type === "media-keyword" ||
  14899. ast.type === "media-type" ||
  14900. ast.type === "media-unknown" ||
  14901. ast.type === "media-url" ||
  14902. ast.type === "media-value" ||
  14903. ast.type === "selector-root-invalid" ||
  14904. ast.type === "selector-attribute" ||
  14905. ast.type === "selector-string" ||
  14906. ast.type === "selector-class" ||
  14907. ast.type === "selector-combinator" ||
  14908. ast.type === "value-string") &&
  14909. newObj.value
  14910. ) {
  14911. newObj.value = cleanCSSStrings(newObj.value);
  14912. }
  14913. if (ast.type === "css-import" && newObj.importPath) {
  14914. newObj.importPath = cleanCSSStrings(newObj.importPath);
  14915. }
  14916. if (ast.type === "selector-attribute") {
  14917. newObj.attribute = newObj.attribute.trim();
  14918. if (newObj.namespace) {
  14919. if (typeof newObj.namespace === "string") {
  14920. newObj.namespace = newObj.namespace.trim();
  14921. if (newObj.namespace.length === 0) {
  14922. newObj.namespace = true;
  14923. }
  14924. }
  14925. }
  14926. if (newObj.value) {
  14927. newObj.value = newObj.value.trim().replace(/^['"]|['"]$/g, "");
  14928. delete newObj.quoted;
  14929. }
  14930. }
  14931. if (
  14932. (ast.type === "media-value" ||
  14933. ast.type === "media-type" ||
  14934. ast.type === "value-number" ||
  14935. ast.type === "selector-root-invalid" ||
  14936. ast.type === "selector-class" ||
  14937. ast.type === "selector-combinator" ||
  14938. ast.type === "selector-tag") &&
  14939. newObj.value
  14940. ) {
  14941. newObj.value = newObj.value.replace(
  14942. /([\d.eE+-]+)([a-zA-Z]*)/g,
  14943. (match, numStr, unit) => {
  14944. const num = Number(numStr);
  14945. return isNaN(num) ? match : num + unit.toLowerCase();
  14946. }
  14947. );
  14948. }
  14949. if (ast.type === "media-url") {
  14950. newObj.value = newObj.value
  14951. .replace(/^url\(\s+/gi, "url(")
  14952. .replace(/\s+\)$/gi, ")");
  14953. }
  14954. if (ast.type === "selector-tag") {
  14955. const lowercasedValue = ast.value.toLowerCase();
  14956. if (htmlTagNames$1.indexOf(lowercasedValue) !== -1) {
  14957. newObj.value = lowercasedValue;
  14958. }
  14959. if (["from", "to"].indexOf(lowercasedValue) !== -1) {
  14960. newObj.value = lowercasedValue;
  14961. }
  14962. }
  14963. }
  14964. function cleanCSSStrings(value) {
  14965. return value.replace(/'/g, '"').replace(/\\([^a-fA-F\d])/g, "$1");
  14966. }
  14967. var clean_1$2 = clean$2;
  14968. const docBuilders$6 = doc.builders;
  14969. const concat$5 = docBuilders$6.concat;
  14970. const join$4 = docBuilders$6.join;
  14971. const line$2 = docBuilders$6.line;
  14972. const hardline$4 = docBuilders$6.hardline;
  14973. const softline$3 = docBuilders$6.softline;
  14974. const group$2 = docBuilders$6.group;
  14975. const fill$3 = docBuilders$6.fill;
  14976. const indent$4 = docBuilders$6.indent;
  14977. const removeLines$1 = doc.utils.removeLines;
  14978. function genericPrint$1(path$$1, options, print) {
  14979. const node = path$$1.getValue();
  14980. /* istanbul ignore if */
  14981. if (!node) {
  14982. return "";
  14983. }
  14984. if (typeof node === "string") {
  14985. return node;
  14986. }
  14987. switch (node.type) {
  14988. case "css-comment-yaml":
  14989. return node.value;
  14990. case "css-root": {
  14991. const nodes = printNodeSequence(path$$1, options, print);
  14992. if (nodes.parts.length) {
  14993. return concat$5([nodes, hardline$4]);
  14994. }
  14995. return nodes;
  14996. }
  14997. case "css-comment": {
  14998. if (node.raws.content) {
  14999. return node.raws.content;
  15000. }
  15001. const text = options.originalText.slice(
  15002. options.locStart(node),
  15003. options.locEnd(node)
  15004. );
  15005. const rawText = node.raws.text || node.text;
  15006. // Workaround a bug where the location is off.
  15007. // https://github.com/postcss/postcss-scss/issues/63
  15008. if (text.indexOf(rawText) === -1) {
  15009. if (node.raws.inline) {
  15010. return concat$5(["// ", rawText]);
  15011. }
  15012. return concat$5(["/* ", rawText, " */"]);
  15013. }
  15014. return text;
  15015. }
  15016. case "css-rule": {
  15017. return concat$5([
  15018. path$$1.call(print, "selector"),
  15019. node.important ? " !important" : "",
  15020. node.nodes
  15021. ? concat$5([
  15022. " {",
  15023. node.nodes.length > 0
  15024. ? indent$4(
  15025. concat$5([hardline$4, printNodeSequence(path$$1, options, print)])
  15026. )
  15027. : "",
  15028. hardline$4,
  15029. "}",
  15030. isDetachedRulesetDeclaration(node) ? ";" : ""
  15031. ])
  15032. : ";"
  15033. ]);
  15034. }
  15035. case "css-decl": {
  15036. // When the following less construct &:extend(.foo); is parsed with scss,
  15037. // it will put a space after `:` and break it. Ideally we should parse
  15038. // less files with less, but we can hardcode this to work with scss as
  15039. // well.
  15040. const isValueExtend =
  15041. node.value.type === "value-root" &&
  15042. node.value.group.type === "value-value" &&
  15043. node.value.group.group.type === "value-func" &&
  15044. node.value.group.group.value === "extend";
  15045. const isComposed =
  15046. node.value.type === "value-root" &&
  15047. node.value.group.type === "value-value" &&
  15048. node.prop === "composes";
  15049. const ruleAncestorNode = getAncestorNode(path$$1, "css-rule");
  15050. const isiCSS =
  15051. ruleAncestorNode &&
  15052. ruleAncestorNode.raws.selector &&
  15053. (ruleAncestorNode.raws.selector.startsWith(":import") ||
  15054. ruleAncestorNode.raws.selector.startsWith(":export"));
  15055. return concat$5([
  15056. node.raws.before.replace(/[\s;]/g, ""),
  15057. isiCSS ? node.prop : maybeToLowerCase(node.prop),
  15058. node.raws.between.trim() === ":" ? ":" : node.raws.between.trim(),
  15059. isValueExtend ? "" : " ",
  15060. isComposed
  15061. ? removeLines$1(path$$1.call(print, "value"))
  15062. : path$$1.call(print, "value"),
  15063. node.raws.important
  15064. ? node.raws.important.replace(/\s*!\s*important/i, " !important")
  15065. : node.important
  15066. ? " !important"
  15067. : "",
  15068. node.raws.scssDefault
  15069. ? node.raws.scssDefault.replace(/\s*!default/i, " !default")
  15070. : node.scssDefault
  15071. ? " !default"
  15072. : "",
  15073. node.raws.scssGlobal
  15074. ? node.raws.scssGlobal.replace(/\s*!global/i, " !global")
  15075. : node.scssGlobal
  15076. ? " !global"
  15077. : "",
  15078. node.nodes
  15079. ? concat$5([
  15080. " {",
  15081. indent$4(
  15082. concat$5([softline$3, printNodeSequence(path$$1, options, print)])
  15083. ),
  15084. softline$3,
  15085. "}"
  15086. ])
  15087. : ";"
  15088. ]);
  15089. }
  15090. case "css-atrule": {
  15091. const hasParams =
  15092. node.params &&
  15093. !(node.params.type === "media-query-list" && node.params.value === "");
  15094. const isDetachedRulesetCall = hasParams && /^\(\s*\)$/.test(node.params);
  15095. const hasParensAround =
  15096. node.value &&
  15097. node.value.group.group.type === "value-paren_group" &&
  15098. node.value.group.group.open !== null &&
  15099. node.value.group.group.close !== null;
  15100. return concat$5([
  15101. "@",
  15102. // If a Less file ends up being parsed with the SCSS parser, Less
  15103. // variable declarations will be parsed as atrules with names ending
  15104. // with a colon, so keep the original case then.
  15105. isDetachedRulesetCall || node.name.endsWith(":")
  15106. ? node.name
  15107. : maybeToLowerCase(node.name),
  15108. hasParams
  15109. ? concat$5([
  15110. isDetachedRulesetCall ? "" : " ",
  15111. path$$1.call(print, "params")
  15112. ])
  15113. : "",
  15114. node.selector
  15115. ? indent$4(concat$5([" ", path$$1.call(print, "selector")]))
  15116. : "",
  15117. node.value
  15118. ? group$2(
  15119. concat$5([
  15120. " ",
  15121. path$$1.call(print, "value"),
  15122. isControlDirectiveNode(node)
  15123. ? hasParensAround
  15124. ? " "
  15125. : line$2
  15126. : ""
  15127. ])
  15128. )
  15129. : node.name === "else"
  15130. ? " "
  15131. : "",
  15132. node.nodes
  15133. ? concat$5([
  15134. isControlDirectiveNode(node) ? "" : " ",
  15135. "{",
  15136. indent$4(
  15137. concat$5([
  15138. node.nodes.length > 0 ? softline$3 : "",
  15139. printNodeSequence(path$$1, options, print)
  15140. ])
  15141. ),
  15142. softline$3,
  15143. "}"
  15144. ])
  15145. : ";"
  15146. ]);
  15147. }
  15148. case "css-import": {
  15149. return concat$5([
  15150. "@",
  15151. maybeToLowerCase(node.name),
  15152. " ",
  15153. node.directives ? concat$5([node.directives, " "]) : "",
  15154. adjustStrings(node.importPath, options),
  15155. node.nodes.length > 0
  15156. ? concat$5([
  15157. " {",
  15158. indent$4(
  15159. concat$5([softline$3, printNodeSequence(path$$1, options, print)])
  15160. ),
  15161. softline$3,
  15162. "}"
  15163. ])
  15164. : ";"
  15165. ]);
  15166. }
  15167. // postcss-media-query-parser
  15168. case "media-query-list": {
  15169. const parts = [];
  15170. path$$1.each(childPath => {
  15171. const node = childPath.getValue();
  15172. if (node.type === "media-query" && node.value === "") {
  15173. return;
  15174. }
  15175. parts.push(childPath.call(print));
  15176. }, "nodes");
  15177. return group$2(indent$4(join$4(line$2, parts)));
  15178. }
  15179. case "media-query": {
  15180. return concat$5([
  15181. join$4(" ", path$$1.map(print, "nodes")),
  15182. isLastNode(path$$1, node) ? "" : ","
  15183. ]);
  15184. }
  15185. case "media-type": {
  15186. const atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
  15187. if (
  15188. atRuleAncestorNode &&
  15189. atRuleAncestorNode.name.toLowerCase() === "charset"
  15190. ) {
  15191. return node.value;
  15192. }
  15193. return adjustNumbers(adjustStrings(node.value, options));
  15194. }
  15195. case "media-feature-expression": {
  15196. if (!node.nodes) {
  15197. return node.value;
  15198. }
  15199. return concat$5(["(", concat$5(path$$1.map(print, "nodes")), ")"]);
  15200. }
  15201. case "media-feature": {
  15202. return maybeToLowerCase(
  15203. adjustStrings(node.value.replace(/ +/g, " "), options)
  15204. );
  15205. }
  15206. case "media-colon": {
  15207. return concat$5([node.value, " "]);
  15208. }
  15209. case "media-value": {
  15210. return adjustNumbers(adjustStrings(node.value, options));
  15211. }
  15212. case "media-keyword": {
  15213. return adjustStrings(node.value, options);
  15214. }
  15215. case "media-url": {
  15216. return adjustStrings(
  15217. node.value.replace(/^url\(\s+/gi, "url(").replace(/\s+\)$/gi, ")"),
  15218. options
  15219. );
  15220. }
  15221. case "media-unknown": {
  15222. return adjustStrings(node.value, options);
  15223. }
  15224. // postcss-selector-parser
  15225. case "selector-root-invalid": {
  15226. // This is likely a SCSS nested property: `background: { color: red; }`.
  15227. return adjustNumbers(
  15228. adjustStrings(maybeToLowerCase(node.value), options)
  15229. );
  15230. }
  15231. case "selector-root": {
  15232. const atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
  15233. const insideAtRuleNode =
  15234. atRuleAncestorNode &&
  15235. ["extend", "custom-selector", "nest"].indexOf(
  15236. atRuleAncestorNode.name
  15237. ) !== -1;
  15238. return group$2(
  15239. concat$5([
  15240. atRuleAncestorNode && atRuleAncestorNode.name === "custom-selector"
  15241. ? concat$5([atRuleAncestorNode.customSelector, line$2])
  15242. : "",
  15243. join$4(
  15244. concat$5([",", insideAtRuleNode ? line$2 : hardline$4]),
  15245. path$$1.map(print, "nodes")
  15246. )
  15247. ])
  15248. );
  15249. }
  15250. case "selector-comment": {
  15251. return node.value;
  15252. }
  15253. case "selector-string": {
  15254. return adjustStrings(node.value, options);
  15255. }
  15256. case "selector-tag": {
  15257. const parentNode = path$$1.getParentNode();
  15258. const index = parentNode && parentNode.nodes.indexOf(node);
  15259. const prevNode = index && parentNode.nodes[index - 1];
  15260. return concat$5([
  15261. node.namespace
  15262. ? concat$5([node.namespace === true ? "" : node.namespace.trim(), "|"])
  15263. : "",
  15264. prevNode.type === "selector-nesting"
  15265. ? node.value
  15266. : adjustNumbers(
  15267. isHTMLTag(node.value) ||
  15268. isKeyframeAtRuleKeywords(path$$1, node.value)
  15269. ? node.value.toLowerCase()
  15270. : node.value
  15271. )
  15272. ]);
  15273. }
  15274. case "selector-id": {
  15275. return concat$5(["#", node.value]);
  15276. }
  15277. case "selector-class": {
  15278. return concat$5([".", adjustNumbers(adjustStrings(node.value, options))]);
  15279. }
  15280. case "selector-attribute": {
  15281. return concat$5([
  15282. "[",
  15283. node.namespace
  15284. ? concat$5([node.namespace === true ? "" : node.namespace.trim(), "|"])
  15285. : "",
  15286. node.attribute.trim(),
  15287. node.operator ? node.operator : "",
  15288. node.value
  15289. ? quoteAttributeValue(
  15290. adjustStrings(node.value.trim(), options),
  15291. options
  15292. )
  15293. : "",
  15294. node.insensitive ? " i" : "",
  15295. "]"
  15296. ]);
  15297. }
  15298. case "selector-combinator": {
  15299. if (
  15300. node.value === "+" ||
  15301. node.value === ">" ||
  15302. node.value === "~" ||
  15303. node.value === ">>>"
  15304. ) {
  15305. const parentNode = path$$1.getParentNode();
  15306. const leading =
  15307. parentNode.type === "selector-selector" &&
  15308. parentNode.nodes[0] === node
  15309. ? ""
  15310. : line$2;
  15311. return concat$5([leading, node.value, isLastNode(path$$1, node) ? "" : " "]);
  15312. }
  15313. const leading = node.value.trim().startsWith("(") ? line$2 : "";
  15314. const value =
  15315. adjustNumbers(adjustStrings(node.value.trim(), options)) || line$2;
  15316. return concat$5([leading, value]);
  15317. }
  15318. case "selector-universal": {
  15319. return concat$5([
  15320. node.namespace
  15321. ? concat$5([node.namespace === true ? "" : node.namespace.trim(), "|"])
  15322. : "",
  15323. adjustNumbers(node.value)
  15324. ]);
  15325. }
  15326. case "selector-selector": {
  15327. return group$2(indent$4(concat$5(path$$1.map(print, "nodes"))));
  15328. }
  15329. case "selector-pseudo": {
  15330. return concat$5([
  15331. maybeToLowerCase(node.value),
  15332. node.nodes && node.nodes.length > 0
  15333. ? concat$5(["(", join$4(", ", path$$1.map(print, "nodes")), ")"])
  15334. : ""
  15335. ]);
  15336. }
  15337. case "selector-nesting": {
  15338. return node.value;
  15339. }
  15340. // postcss-values-parser
  15341. case "value-root": {
  15342. return path$$1.call(print, "group");
  15343. }
  15344. case "value-comment": {
  15345. return concat$5([
  15346. node.inline ? "//" : "/*",
  15347. node.value,
  15348. node.inline ? "" : "*/"
  15349. ]);
  15350. }
  15351. case "value-comma_group": {
  15352. const parentNode = path$$1.getParentNode();
  15353. const declAncestorNode = getAncestorNode(path$$1, "css-decl");
  15354. const declAncestorProp =
  15355. declAncestorNode &&
  15356. declAncestorNode.prop &&
  15357. declAncestorNode.prop.toLowerCase();
  15358. const isGridValue =
  15359. declAncestorProp &&
  15360. parentNode.type === "value-value" &&
  15361. (declAncestorProp === "grid" ||
  15362. declAncestorProp.startsWith("grid-template"));
  15363. const atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
  15364. const isControlDirective =
  15365. atRuleAncestorNode && isControlDirectiveNode(atRuleAncestorNode);
  15366. const printed = path$$1.map(print, "groups");
  15367. const parts = [];
  15368. const functionAncestorNode = getAncestorNode(path$$1, "value-func");
  15369. const insideInFunction =
  15370. functionAncestorNode && functionAncestorNode.value;
  15371. const insideURLFunction =
  15372. insideInFunction && functionAncestorNode.value.toLowerCase() === "url";
  15373. let didBreak = false;
  15374. for (let i = 0; i < node.groups.length; ++i) {
  15375. parts.push(printed[i]);
  15376. // Ignore value inside `url()`
  15377. if (insideURLFunction) {
  15378. continue;
  15379. }
  15380. const iPrevNode = node.groups[i - 1];
  15381. const iNode = node.groups[i];
  15382. const iNextNode = node.groups[i + 1];
  15383. const iNextNextNode = node.groups[i + 2];
  15384. // Ignore after latest node (i.e. before semicolon)
  15385. if (!iNextNode) {
  15386. continue;
  15387. }
  15388. // Ignore colon
  15389. if (iNode.value === ":") {
  15390. continue;
  15391. }
  15392. // Ignore `@` in Less (i.e. `@@var;`)
  15393. if (iNode.type === "value-atword" && iNode.value === "") {
  15394. continue;
  15395. }
  15396. // Ignore `~` in Less (i.e. `content: ~"^//* some horrible but needed css hack";`)
  15397. if (iNode.value === "~") {
  15398. continue;
  15399. }
  15400. if (
  15401. (iPrevNode &&
  15402. iPrevNode.type === "value-comment" &&
  15403. iPrevNode.inline) ||
  15404. (iNextNode.type === "value-comment" && iNextNode.inline)
  15405. ) {
  15406. continue;
  15407. }
  15408. const isHash = iNode.type === "value-word" && iNode.value === "#";
  15409. const isLeftCurlyBrace =
  15410. iNode.type === "value-word" && iNode.value === "{";
  15411. const isNextLeftCurlyBrace =
  15412. iNextNode.type === "value-word" && iNextNode.value === "{";
  15413. const isRightCurlyBrace =
  15414. iNode.type === "value-word" && iNode.value === "}";
  15415. const isNextRightCurlyBrace =
  15416. iNextNode.type === "value-word" && iNextNode.value === "}";
  15417. // Ignore interpolation in SCSS (i.e. ``#{variable}``)
  15418. if (
  15419. isHash ||
  15420. isLeftCurlyBrace ||
  15421. isNextRightCurlyBrace ||
  15422. (isNextLeftCurlyBrace &&
  15423. iNextNode.raws &&
  15424. iNextNode.raws.before === "") ||
  15425. (isRightCurlyBrace && iNextNode.raws && iNextNode.raws.before === "")
  15426. ) {
  15427. continue;
  15428. }
  15429. const isNextHash =
  15430. iNextNode.type === "value-word" && iNextNode.value === "#";
  15431. const isMathOperator = isMathOperatorNode(iNode);
  15432. const isNextMathOperator = isMathOperatorNode(iNextNode);
  15433. const isMultiplication =
  15434. !isNextHash && isMathOperator && iNode.value === "*";
  15435. const isNextMultiplication =
  15436. !isRightCurlyBrace && isNextMathOperator && iNextNode.value === "*";
  15437. const isDivision = !isNextHash && isMathOperator && iNode.value === "/";
  15438. const isNextDivision =
  15439. !isRightCurlyBrace && isNextMathOperator && iNextNode.value === "/";
  15440. const isAddition = !isNextHash && isMathOperator && iNode.value === "+";
  15441. const isNextAddition =
  15442. !isRightCurlyBrace && isNextMathOperator && iNextNode.value === "+";
  15443. const isPrevFunction = iPrevNode && iPrevNode.type === "value-func";
  15444. const isFunction = iNode.type === "value-func";
  15445. const isNextFunction = iNextNode.type === "value-func";
  15446. const isNextNextFunction =
  15447. iNextNextNode && iNextNextNode.type === "value-func";
  15448. const isPrevWord =
  15449. iPrevNode &&
  15450. ["value-word", "value-atword"].indexOf(iPrevNode.type) !== -1;
  15451. const isWord =
  15452. ["value-word", "value-atword"].indexOf(iNode.type) !== -1;
  15453. const isNextWord =
  15454. ["value-word", "value-atword"].indexOf(iNextNode.type) !== -1;
  15455. const isNextNextWord =
  15456. iNextNextNode &&
  15457. ["value-word", "value-atword"].indexOf(iNextNextNode.type) !== -1;
  15458. // Math operators
  15459. const insideCalcFunction =
  15460. insideInFunction &&
  15461. functionAncestorNode.value.toLowerCase() === "calc";
  15462. const hasSpaceBeforeOperator =
  15463. isNextNextFunction || isNextNextWord || isFunction || isWord;
  15464. const hasSpaceAfterOperator =
  15465. isNextFunction || isNextWord || isPrevFunction || isPrevWord;
  15466. if (
  15467. (isMathOperator || isNextMathOperator) &&
  15468. // Multiplication
  15469. !isMultiplication &&
  15470. !isNextMultiplication &&
  15471. // Division
  15472. !(isNextDivision && (hasSpaceBeforeOperator || insideCalcFunction)) &&
  15473. !(isDivision && (hasSpaceAfterOperator || insideCalcFunction)) &&
  15474. // Addition
  15475. !(isNextAddition && hasSpaceBeforeOperator) &&
  15476. !(isAddition && hasSpaceAfterOperator)
  15477. ) {
  15478. const isNextParenGroup = isParenGroupNode(iNextNode);
  15479. const isNextValueNumber = iNextNode.type === "value-number";
  15480. if (
  15481. (iNextNode.raws && iNextNode.raws.before === "") ||
  15482. (isMathOperator &&
  15483. (isNextParenGroup ||
  15484. isNextWord ||
  15485. isNextValueNumber ||
  15486. isMathOperatorNode(iNextNode)) &&
  15487. (!iPrevNode || (iPrevNode && isMathOperatorNode(iPrevNode))))
  15488. ) {
  15489. continue;
  15490. }
  15491. }
  15492. const isEqualityOperator =
  15493. isControlDirective && isEqualityOperatorNode(iNode);
  15494. const isRelationalOperator =
  15495. isControlDirective && isRelationalOperatorNode(iNode);
  15496. const isNextEqualityOperator =
  15497. isControlDirective && isEqualityOperatorNode(iNextNode);
  15498. const isNextRelationalOperator =
  15499. isControlDirective && isRelationalOperatorNode(iNextNode);
  15500. const isNextIfElseKeyword =
  15501. isControlDirective && isIfElseKeywordNode(iNextNode);
  15502. const isEachKeyword = isControlDirective && isEachKeywordNode(iNode);
  15503. const isNextEachKeyword =
  15504. isControlDirective && isEachKeywordNode(iNextNode);
  15505. const isForKeyword =
  15506. atRuleAncestorNode &&
  15507. atRuleAncestorNode.name === "for" &&
  15508. isForKeywordNode(iNode);
  15509. const isNextForKeyword =
  15510. isControlDirective && isForKeywordNode(iNextNode);
  15511. const IsNextColon = iNextNode.value === ":";
  15512. if (isGridValue) {
  15513. if (iNode.source.start.line !== iNextNode.source.start.line) {
  15514. parts.push(hardline$4);
  15515. didBreak = true;
  15516. } else {
  15517. parts.push(" ");
  15518. }
  15519. } else if (iNode.type === "value-comment" && iNode.inline) {
  15520. parts.push(hardline$4);
  15521. } else if (
  15522. isNextMathOperator ||
  15523. isNextEqualityOperator ||
  15524. isNextRelationalOperator ||
  15525. isNextIfElseKeyword ||
  15526. isForKeyword ||
  15527. isEachKeyword
  15528. ) {
  15529. parts.push(" ");
  15530. } else if (
  15531. !IsNextColon ||
  15532. isEqualityOperator ||
  15533. isRelationalOperator ||
  15534. isNextForKeyword ||
  15535. isNextEachKeyword
  15536. ) {
  15537. parts.push(line$2);
  15538. }
  15539. }
  15540. if (didBreak) {
  15541. parts.unshift(hardline$4);
  15542. }
  15543. if (isControlDirective) {
  15544. return group$2(indent$4(concat$5(parts)));
  15545. }
  15546. return group$2(indent$4(fill$3(parts)));
  15547. }
  15548. case "value-paren_group": {
  15549. const parentNode = path$$1.getParentNode();
  15550. const isURLCall =
  15551. parentNode &&
  15552. parentNode.type === "value-func" &&
  15553. parentNode.value === "url";
  15554. if (
  15555. isURLCall &&
  15556. (node.groups.length === 1 ||
  15557. (node.groups.length > 0 &&
  15558. node.groups[0].type === "value-comma_group" &&
  15559. node.groups[0].groups.length > 0 &&
  15560. node.groups[0].groups[0].type === "value-word" &&
  15561. node.groups[0].groups[0].value.startsWith("data:")))
  15562. ) {
  15563. return concat$5([
  15564. node.open ? path$$1.call(print, "open") : "",
  15565. join$4(",", path$$1.map(print, "groups")),
  15566. node.close ? path$$1.call(print, "close") : ""
  15567. ]);
  15568. }
  15569. if (!node.open) {
  15570. const printed = path$$1.map(print, "groups");
  15571. const res = [];
  15572. for (let i = 0; i < printed.length; i++) {
  15573. if (i !== 0) {
  15574. res.push(concat$5([",", line$2]));
  15575. }
  15576. res.push(printed[i]);
  15577. }
  15578. return group$2(indent$4(fill$3(res)));
  15579. }
  15580. const declNode = path$$1.getParentNode(2);
  15581. const isMap =
  15582. declNode &&
  15583. declNode.type === "css-decl" &&
  15584. declNode.prop.startsWith("$");
  15585. return group$2(
  15586. concat$5([
  15587. node.open ? path$$1.call(print, "open") : "",
  15588. indent$4(
  15589. concat$5([
  15590. softline$3,
  15591. join$4(
  15592. concat$5([",", isMap ? hardline$4 : line$2]),
  15593. path$$1.map(print, "groups")
  15594. )
  15595. ])
  15596. ),
  15597. softline$3,
  15598. node.close ? path$$1.call(print, "close") : ""
  15599. ])
  15600. );
  15601. }
  15602. case "value-value": {
  15603. return path$$1.call(print, "group");
  15604. }
  15605. case "value-func": {
  15606. return concat$5([node.value, path$$1.call(print, "group")]);
  15607. }
  15608. case "value-paren": {
  15609. return node.value;
  15610. }
  15611. case "value-number": {
  15612. return concat$5([printNumber$1(node.value), maybeToLowerCase(node.unit)]);
  15613. }
  15614. case "value-operator": {
  15615. return node.value;
  15616. }
  15617. case "value-word": {
  15618. if ((node.isColor && node.isHex) || isWideKeywords(node.value)) {
  15619. return node.value.toLowerCase();
  15620. }
  15621. return node.value;
  15622. }
  15623. case "value-colon": {
  15624. return concat$5([node.value, insideURLFunctionNode(path$$1) ? "" : line$2]);
  15625. }
  15626. case "value-comma": {
  15627. return concat$5([node.value, " "]);
  15628. }
  15629. case "value-string": {
  15630. return util$1.printString(
  15631. node.raws.quote + node.value + node.raws.quote,
  15632. options
  15633. );
  15634. }
  15635. case "value-atword": {
  15636. return concat$5(["@", node.value]);
  15637. }
  15638. case "value-unicode-range": {
  15639. return node.value;
  15640. }
  15641. default:
  15642. /* istanbul ignore next */
  15643. throw new Error(`Unknown postcss type ${JSON.stringify(node.type)}`);
  15644. }
  15645. }
  15646. function isLastNode(path$$1, node) {
  15647. const parentNode = path$$1.getParentNode();
  15648. if (!parentNode) {
  15649. return false;
  15650. }
  15651. const nodes = parentNode.nodes;
  15652. return nodes && nodes.indexOf(node) === nodes.length - 1;
  15653. }
  15654. function isDetachedRulesetDeclaration(node) {
  15655. // If a Less file ends up being parsed with the SCSS parser, Less
  15656. // variable declarations will be parsed as atrules with names ending
  15657. // with a colon, so keep the original case then.
  15658. return (
  15659. node.selector &&
  15660. node.selector.type !== "selector-root-invalid" &&
  15661. ((typeof node.selector === "string" && /^@.+:.*$/.test(node.selector)) ||
  15662. (node.selector.value && /^@.+:.*$/.test(node.selector.value)))
  15663. );
  15664. }
  15665. function isKeyframeAtRuleKeywords(path$$1, value) {
  15666. const atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
  15667. return (
  15668. atRuleAncestorNode &&
  15669. atRuleAncestorNode.name &&
  15670. atRuleAncestorNode.name.toLowerCase().endsWith("keyframes") &&
  15671. ["from", "to"].indexOf(value.toLowerCase()) !== -1
  15672. );
  15673. }
  15674. function isHTMLTag(value) {
  15675. return htmlTagNames$1.indexOf(value.toLowerCase()) !== -1;
  15676. }
  15677. function insideURLFunctionNode(path$$1) {
  15678. const funcAncestorNode = getAncestorNode(path$$1, "value-func");
  15679. return (
  15680. funcAncestorNode &&
  15681. funcAncestorNode.value &&
  15682. funcAncestorNode.value === "url"
  15683. );
  15684. }
  15685. function isParenGroupNode(node) {
  15686. return node.type && node.type === "value-paren_group";
  15687. }
  15688. function isForKeywordNode(node) {
  15689. return (
  15690. node.type &&
  15691. node.type === "value-word" &&
  15692. node.value &&
  15693. ["from", "through", "end"].indexOf(node.value) !== -1
  15694. );
  15695. }
  15696. function isIfElseKeywordNode(node) {
  15697. return (
  15698. node.type &&
  15699. node.type === "value-word" &&
  15700. node.value &&
  15701. ["and", "or", "not"].indexOf(node.value) !== -1
  15702. );
  15703. }
  15704. function isEachKeywordNode(node) {
  15705. return (
  15706. node.type &&
  15707. node.type === "value-word" &&
  15708. node.value &&
  15709. ["in"].indexOf(node.value) !== -1
  15710. );
  15711. }
  15712. function isMathOperatorNode(node) {
  15713. return (
  15714. node.type &&
  15715. node.type === "value-operator" &&
  15716. node.value &&
  15717. ["+", "-", "/", "*", "%"].indexOf(node.value) !== -1
  15718. );
  15719. }
  15720. function isEqualityOperatorNode(node) {
  15721. return (
  15722. node.type &&
  15723. node.type === "value-word" &&
  15724. node.value &&
  15725. ["==", "!="].indexOf(node.value) !== -1
  15726. );
  15727. }
  15728. function isRelationalOperatorNode(node) {
  15729. return (
  15730. node.type &&
  15731. node.type === "value-word" &&
  15732. node.value &&
  15733. ["<", ">", "<=", ">="].indexOf(node.value) !== -1
  15734. );
  15735. }
  15736. function isControlDirectiveNode(node) {
  15737. return (
  15738. node.type &&
  15739. node.type === "css-atrule" &&
  15740. node.name &&
  15741. (node.name === "if" ||
  15742. node.name === "else" ||
  15743. node.name === "for" ||
  15744. node.name === "each" ||
  15745. node.name === "while")
  15746. );
  15747. }
  15748. function getAncestorCounter(path$$1, typeOrTypes) {
  15749. const types = [].concat(typeOrTypes);
  15750. let counter = -1;
  15751. let ancestorNode;
  15752. while ((ancestorNode = path$$1.getParentNode(++counter))) {
  15753. if (types.indexOf(ancestorNode.type) !== -1) {
  15754. return counter;
  15755. }
  15756. }
  15757. return -1;
  15758. }
  15759. function getAncestorNode(path$$1, typeOrTypes) {
  15760. const counter = getAncestorCounter(path$$1, typeOrTypes);
  15761. return counter === -1 ? null : path$$1.getParentNode(counter);
  15762. }
  15763. function printNodeSequence(path$$1, options, print) {
  15764. const node = path$$1.getValue();
  15765. const parts = [];
  15766. let i = 0;
  15767. path$$1.map(pathChild => {
  15768. const prevNode = node.nodes[i - 1];
  15769. if (
  15770. prevNode &&
  15771. prevNode.type === "css-comment" &&
  15772. prevNode.text.trim() === "prettier-ignore"
  15773. ) {
  15774. const childNode = pathChild.getValue();
  15775. parts.push(
  15776. options.originalText.slice(
  15777. options.locStart(childNode),
  15778. options.locEnd(childNode)
  15779. )
  15780. );
  15781. } else {
  15782. parts.push(pathChild.call(print));
  15783. }
  15784. if (i !== node.nodes.length - 1) {
  15785. if (
  15786. (node.nodes[i + 1].type === "css-comment" &&
  15787. !util$1.hasNewline(
  15788. options.originalText,
  15789. options.locStart(node.nodes[i + 1]),
  15790. { backwards: true }
  15791. )) ||
  15792. (node.nodes[i + 1].type === "css-atrule" &&
  15793. node.nodes[i + 1].name === "else" &&
  15794. node.nodes[i].type !== "css-comment")
  15795. ) {
  15796. parts.push(" ");
  15797. } else {
  15798. parts.push(hardline$4);
  15799. if (
  15800. utilShared.isNextLineEmpty(
  15801. options.originalText,
  15802. pathChild.getValue(),
  15803. options
  15804. )
  15805. ) {
  15806. parts.push(hardline$4);
  15807. }
  15808. }
  15809. }
  15810. i++;
  15811. }, "nodes");
  15812. return concat$5(parts);
  15813. }
  15814. const STRING_REGEX = /(['"])(?:(?!\1)[^\\]|\\[\s\S])*\1/g;
  15815. const NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g;
  15816. const STANDARD_UNIT_REGEX = /[a-zA-Z]+/g;
  15817. const WORD_PART_REGEX = /[$@]?[a-zA-Z_\u0080-\uFFFF][\w\-\u0080-\uFFFF]*/g;
  15818. const ADJUST_NUMBERS_REGEX = RegExp(
  15819. STRING_REGEX.source +
  15820. `|` +
  15821. `(${WORD_PART_REGEX.source})?` +
  15822. `(${NUMBER_REGEX.source})` +
  15823. `(${STANDARD_UNIT_REGEX.source})?`,
  15824. "g"
  15825. );
  15826. function adjustStrings(value, options) {
  15827. return value.replace(STRING_REGEX, match =>
  15828. util$1.printString(match, options)
  15829. );
  15830. }
  15831. function quoteAttributeValue(value, options) {
  15832. const quote = options.singleQuote ? "'" : '"';
  15833. return value.includes('"') || value.includes("'")
  15834. ? value
  15835. : quote + value + quote;
  15836. }
  15837. function adjustNumbers(value) {
  15838. return value.replace(
  15839. ADJUST_NUMBERS_REGEX,
  15840. (match, quote, wordPart, number, unit) =>
  15841. !wordPart && number
  15842. ? (wordPart || "") + printNumber$1(number) + maybeToLowerCase(unit || "")
  15843. : match
  15844. );
  15845. }
  15846. function printNumber$1(rawNumber) {
  15847. return (
  15848. util$1
  15849. .printNumber(rawNumber)
  15850. // Remove trailing `.0`.
  15851. .replace(/\.0(?=$|e)/, "")
  15852. );
  15853. }
  15854. function maybeToLowerCase(value) {
  15855. return value.includes("$") ||
  15856. value.includes("@") ||
  15857. value.includes("#") ||
  15858. value.startsWith("%") ||
  15859. value.startsWith("--") ||
  15860. value.startsWith(":--") ||
  15861. (value.includes("(") && value.includes(")"))
  15862. ? value
  15863. : value.toLowerCase();
  15864. }
  15865. function isWideKeywords(value) {
  15866. return (
  15867. ["initial", "inherit", "unset", "revert"].indexOf(
  15868. value.replace().toLowerCase()
  15869. ) !== -1
  15870. );
  15871. }
  15872. var printerPostcss = {
  15873. print: genericPrint$1,
  15874. hasPrettierIgnore: util$1.hasIgnoreComment,
  15875. massageAstNode: clean_1$2
  15876. };
  15877. // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js
  15878. var options$2 = {
  15879. singleQuote: options.singleQuote
  15880. };
  15881. const lineColumnToIndex$1 = util$1.lineColumnToIndex;
  15882. const getLast$1 = util$1.getLast;
  15883. // Based on:
  15884. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  15885. const languages$1 = [
  15886. {
  15887. name: "CSS",
  15888. since: "1.4.0",
  15889. parsers: ["css"],
  15890. group: "CSS",
  15891. tmScope: "source.css",
  15892. aceMode: "css",
  15893. codemirrorMode: "css",
  15894. codemirrorMimeType: "text/css",
  15895. extensions: [".css", ".pcss", ".postcss"],
  15896. liguistLanguageId: 50,
  15897. vscodeLanguageIds: ["css", "postcss"]
  15898. },
  15899. {
  15900. name: "Less",
  15901. since: "1.4.0",
  15902. parsers: ["less"],
  15903. group: "CSS",
  15904. extensions: [".less"],
  15905. tmScope: "source.css.less",
  15906. aceMode: "less",
  15907. codemirrorMode: "css",
  15908. codemirrorMimeType: "text/css",
  15909. liguistLanguageId: 198,
  15910. vscodeLanguageIds: ["less"]
  15911. },
  15912. {
  15913. name: "SCSS",
  15914. since: "1.4.0",
  15915. parsers: ["scss"],
  15916. group: "CSS",
  15917. tmScope: "source.scss",
  15918. aceMode: "scss",
  15919. codemirrorMode: "css",
  15920. codemirrorMimeType: "text/x-scss",
  15921. extensions: [".scss"],
  15922. liguistLanguageId: 329,
  15923. vscodeLanguageIds: ["scss"]
  15924. }
  15925. ];
  15926. const postcss = {
  15927. get parse() {
  15928. return require("./parser-postcss");
  15929. },
  15930. astFormat: "postcss",
  15931. locEnd: function(node) {
  15932. const endNode = node.nodes && getLast$1(node.nodes);
  15933. if (endNode && node.source && !node.source.end) {
  15934. node = endNode;
  15935. }
  15936. if (node.source) {
  15937. return lineColumnToIndex$1(node.source.end, node.source.input.css);
  15938. }
  15939. return null;
  15940. },
  15941. locStart: function(node) {
  15942. if (node.source) {
  15943. return lineColumnToIndex$1(node.source.start, node.source.input.css) - 1;
  15944. }
  15945. return null;
  15946. }
  15947. };
  15948. // TODO: switch these to just `postcss` and use `language` instead.
  15949. const parsers$1 = {
  15950. css: postcss,
  15951. less: postcss,
  15952. scss: postcss
  15953. };
  15954. const printers$1 = {
  15955. postcss: printerPostcss
  15956. };
  15957. var languageCss = {
  15958. languages: languages$1,
  15959. options: options$2,
  15960. parsers: parsers$1,
  15961. printers: printers$1
  15962. };
  15963. const concat$6 = docBuilders$2.concat;
  15964. const join$5 = docBuilders$2.join;
  15965. const softline$4 = docBuilders$2.softline;
  15966. const hardline$5 = docBuilders$2.hardline;
  15967. const line$3 = docBuilders$2.line;
  15968. const group$3 = docBuilders$2.group;
  15969. const indent$5 = docBuilders$2.indent;
  15970. const ifBreak$2 = docBuilders$2.ifBreak;
  15971. // http://w3c.github.io/html/single-page.html#void-elements
  15972. const voidTags = [
  15973. "area",
  15974. "base",
  15975. "br",
  15976. "col",
  15977. "embed",
  15978. "hr",
  15979. "img",
  15980. "input",
  15981. "link",
  15982. "meta",
  15983. "param",
  15984. "source",
  15985. "track",
  15986. "wbr"
  15987. ];
  15988. // Formatter based on @glimmerjs/syntax's built-in test formatter:
  15989. // https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts
  15990. function print(path$$1, options, print) {
  15991. const n = path$$1.getValue();
  15992. /* istanbul ignore if*/
  15993. if (!n) {
  15994. return "";
  15995. }
  15996. switch (n.type) {
  15997. case "Program": {
  15998. return group$3(
  15999. join$5(softline$4, path$$1.map(print, "body").filter(text => text !== ""))
  16000. );
  16001. }
  16002. case "ElementNode": {
  16003. const isVoid = voidTags.indexOf(n.tag) !== -1;
  16004. const closeTag = isVoid ? concat$6([" />", softline$4]) : ">";
  16005. const hasChildren = n.children.length > 0;
  16006. const getParams = (path$$1, print) =>
  16007. indent$5(
  16008. concat$6([
  16009. n.attributes.length ? line$3 : "",
  16010. join$5(line$3, path$$1.map(print, "attributes")),
  16011. n.modifiers.length ? line$3 : "",
  16012. join$5(line$3, path$$1.map(print, "modifiers")),
  16013. n.comments.length ? line$3 : "",
  16014. join$5(line$3, path$$1.map(print, "comments"))
  16015. ])
  16016. );
  16017. // The problem here is that I want to not break at all if the children
  16018. // would not break but I need to force an indent, so I use a hardline.
  16019. /**
  16020. * What happens now:
  16021. * <div>
  16022. * Hello
  16023. * </div>
  16024. * ==>
  16025. * <div>Hello</div>
  16026. * This is due to me using hasChildren to decide to put the hardline in.
  16027. * I would rather use a {DOES THE WHOLE THING NEED TO BREAK}
  16028. */
  16029. return concat$6([
  16030. group$3(
  16031. concat$6([
  16032. "<",
  16033. n.tag,
  16034. getParams(path$$1, print),
  16035. ifBreak$2(softline$4, ""),
  16036. closeTag
  16037. ])
  16038. ),
  16039. group$3(
  16040. concat$6([
  16041. indent$5(join$5(softline$4, [""].concat(path$$1.map(print, "children")))),
  16042. ifBreak$2(hasChildren ? hardline$5 : "", ""),
  16043. !isVoid ? concat$6(["</", n.tag, ">"]) : ""
  16044. ])
  16045. )
  16046. ]);
  16047. }
  16048. case "BlockStatement": {
  16049. const pp = path$$1.getParentNode(1);
  16050. const isElseIf =
  16051. pp &&
  16052. pp.inverse &&
  16053. pp.inverse.body[0] === n &&
  16054. pp.inverse.body[0].path.parts[0] === "if";
  16055. const hasElseIf =
  16056. n.inverse &&
  16057. n.inverse.body[0] &&
  16058. n.inverse.body[0].type === "BlockStatement" &&
  16059. n.inverse.body[0].path.parts[0] === "if";
  16060. const indentElse = hasElseIf ? a => a : indent$5;
  16061. if (n.inverse) {
  16062. return concat$6([
  16063. isElseIf
  16064. ? concat$6(["{{else ", printPathParams(path$$1, print), "}}"])
  16065. : printOpenBlock(path$$1, print),
  16066. indent$5(concat$6([hardline$5, path$$1.call(print, "program")])),
  16067. n.inverse && !hasElseIf ? concat$6([hardline$5, "{{else}}"]) : "",
  16068. n.inverse
  16069. ? indentElse(concat$6([hardline$5, path$$1.call(print, "inverse")]))
  16070. : "",
  16071. isElseIf ? "" : concat$6([hardline$5, printCloseBlock(path$$1, print)])
  16072. ]);
  16073. } else if (isElseIf) {
  16074. return concat$6([
  16075. concat$6(["{{else ", printPathParams(path$$1, print), "}}"]),
  16076. indent$5(concat$6([hardline$5, path$$1.call(print, "program")]))
  16077. ]);
  16078. }
  16079. /**
  16080. * I want this boolean to be: if params are going to cause a break,
  16081. * not that it has params.
  16082. */
  16083. const hasParams = n.params.length > 0 || n.hash.pairs.length > 0;
  16084. const hasChildren = n.program.body.length > 0;
  16085. return concat$6([
  16086. printOpenBlock(path$$1, print),
  16087. group$3(
  16088. concat$6([
  16089. indent$5(concat$6([softline$4, path$$1.call(print, "program")])),
  16090. hasParams && hasChildren ? hardline$5 : "",
  16091. printCloseBlock(path$$1, print)
  16092. ])
  16093. )
  16094. ]);
  16095. }
  16096. case "ElementModifierStatement":
  16097. case "MustacheStatement": {
  16098. const pp = path$$1.getParentNode(1);
  16099. const isConcat = pp && pp.type === "ConcatStatement";
  16100. return group$3(
  16101. concat$6([
  16102. /*n.escaped ? "{{{" : */ "{{",
  16103. printPathParams(path$$1, print),
  16104. isConcat ? "" : softline$4,
  16105. /*.escaped ? "}}}" :*/ "}}"
  16106. ])
  16107. );
  16108. }
  16109. case "SubExpression": {
  16110. return group$3(
  16111. concat$6([
  16112. "(",
  16113. printPath(path$$1, print),
  16114. indent$5(concat$6([line$3, group$3(join$5(line$3, getParams(path$$1, print)))])),
  16115. softline$4,
  16116. ")"
  16117. ])
  16118. );
  16119. }
  16120. case "AttrNode": {
  16121. const quote = n.value.type === "TextNode" ? '"' : "";
  16122. return concat$6([n.name, "=", quote, path$$1.call(print, "value"), quote]);
  16123. }
  16124. case "ConcatStatement": {
  16125. return concat$6([
  16126. '"',
  16127. group$3(
  16128. indent$5(
  16129. join$5(
  16130. softline$4,
  16131. path$$1
  16132. .map(partPath => print(partPath), "parts")
  16133. .filter(a => a !== "")
  16134. )
  16135. )
  16136. ),
  16137. '"'
  16138. ]);
  16139. }
  16140. case "Hash": {
  16141. return concat$6([join$5(line$3, path$$1.map(print, "pairs"))]);
  16142. }
  16143. case "HashPair": {
  16144. return concat$6([n.key, "=", path$$1.call(print, "value")]);
  16145. }
  16146. case "TextNode": {
  16147. return n.chars.replace(/^\s+/, "").replace(/\s+$/, "");
  16148. }
  16149. case "MustacheCommentStatement": {
  16150. const dashes = n.value.indexOf("}}") > -1 ? "--" : "";
  16151. return concat$6(["{{!", dashes, n.value, dashes, "}}"]);
  16152. }
  16153. case "PathExpression": {
  16154. return n.original;
  16155. }
  16156. case "BooleanLiteral": {
  16157. return String(n.value);
  16158. }
  16159. case "CommentStatement": {
  16160. return concat$6(["<!--", n.value, "-->"]);
  16161. }
  16162. case "StringLiteral": {
  16163. return `"${n.value}"`;
  16164. }
  16165. case "NumberLiteral": {
  16166. return String(n.value);
  16167. }
  16168. case "UndefinedLiteral": {
  16169. return "undefined";
  16170. }
  16171. case "NullLiteral": {
  16172. return "null";
  16173. }
  16174. /* istanbul ignore next */
  16175. default:
  16176. throw new Error("unknown glimmer type: " + JSON.stringify(n.type));
  16177. }
  16178. }
  16179. function printPath(path$$1, print) {
  16180. return path$$1.call(print, "path");
  16181. }
  16182. function getParams(path$$1, print) {
  16183. const node = path$$1.getValue();
  16184. let parts = [];
  16185. if (node.params.length > 0) {
  16186. parts = parts.concat(path$$1.map(print, "params"));
  16187. }
  16188. if (node.hash && node.hash.pairs.length > 0) {
  16189. parts.push(path$$1.call(print, "hash"));
  16190. }
  16191. return parts;
  16192. }
  16193. function printPathParams(path$$1, print) {
  16194. let parts = [];
  16195. parts.push(printPath(path$$1, print));
  16196. parts = parts.concat(getParams(path$$1, print));
  16197. return indent$5(group$3(join$5(line$3, parts)));
  16198. }
  16199. function printBlockParams(path$$1) {
  16200. const block = path$$1.getValue();
  16201. if (!block.program || !block.program.blockParams.length) {
  16202. return "";
  16203. }
  16204. return concat$6([" as |", block.program.blockParams.join(" "), "|"]);
  16205. }
  16206. function printOpenBlock(path$$1, print) {
  16207. return group$3(
  16208. concat$6([
  16209. "{{#",
  16210. printPathParams(path$$1, print),
  16211. printBlockParams(path$$1, print),
  16212. softline$4,
  16213. "}}"
  16214. ])
  16215. );
  16216. }
  16217. function printCloseBlock(path$$1, print) {
  16218. return concat$6(["{{/", path$$1.call(print, "path"), "}}"]);
  16219. }
  16220. function clean$4(ast, newObj) {
  16221. // (Glimmer/HTML) ignore TextNode whitespace
  16222. if (ast.type === "TextNode") {
  16223. if (ast.chars.replace(/\s+/, "") === "") {
  16224. return null;
  16225. }
  16226. newObj.chars = ast.chars.replace(/^\s+/, "").replace(/\s+$/, "");
  16227. }
  16228. }
  16229. var printerGlimmer = {
  16230. print,
  16231. massageAstNode: clean$4
  16232. };
  16233. // Based on:
  16234. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  16235. const languages$2 = [
  16236. {
  16237. type: "markup",
  16238. group: "HTML",
  16239. aliases: ["hbs", "htmlbars"],
  16240. extensions: [".handlebars", ".hbs"],
  16241. tm_scope: "text.html.handlebars",
  16242. ace_mode: "handlebars",
  16243. language_id: 155,
  16244. since: null // unreleased
  16245. }
  16246. ];
  16247. const parsers$2 = {
  16248. glimmer: {
  16249. get parse() {
  16250. return require("./parser-glimmer");
  16251. },
  16252. astFormat: "glimmer",
  16253. locEnd: function(node) {
  16254. return node.loc && node.loc.end;
  16255. },
  16256. locStart: function(node) {
  16257. return node.loc && node.loc.start;
  16258. }
  16259. }
  16260. };
  16261. const printers$2 = {
  16262. glimmer: printerGlimmer
  16263. };
  16264. var languageHandlebars = {
  16265. languages: languages$2,
  16266. parsers: parsers$2,
  16267. printers: printers$2
  16268. };
  16269. const docBuilders$7 = doc.builders;
  16270. const concat$7 = docBuilders$7.concat;
  16271. const join$6 = docBuilders$7.join;
  16272. const hardline$6 = docBuilders$7.hardline;
  16273. const line$4 = docBuilders$7.line;
  16274. const softline$5 = docBuilders$7.softline;
  16275. const group$4 = docBuilders$7.group;
  16276. const indent$6 = docBuilders$7.indent;
  16277. const ifBreak$3 = docBuilders$7.ifBreak;
  16278. function genericPrint$2(path$$1, options, print) {
  16279. const n = path$$1.getValue();
  16280. if (!n) {
  16281. return "";
  16282. }
  16283. if (typeof n === "string") {
  16284. return n;
  16285. }
  16286. switch (n.kind) {
  16287. case "Document": {
  16288. return concat$7([
  16289. join$6(concat$7([hardline$6, hardline$6]), path$$1.map(print, "definitions")),
  16290. hardline$6
  16291. ]);
  16292. }
  16293. case "OperationDefinition": {
  16294. const hasOperation = options.originalText[options.locStart(n)] !== "{";
  16295. const hasName = !!n.name;
  16296. return concat$7([
  16297. hasOperation ? n.operation : "",
  16298. hasOperation && hasName ? concat$7([" ", path$$1.call(print, "name")]) : "",
  16299. n.variableDefinitions && n.variableDefinitions.length
  16300. ? group$4(
  16301. concat$7([
  16302. "(",
  16303. indent$6(
  16304. concat$7([
  16305. softline$5,
  16306. join$6(
  16307. concat$7([ifBreak$3("", ", "), softline$5]),
  16308. path$$1.map(print, "variableDefinitions")
  16309. )
  16310. ])
  16311. ),
  16312. softline$5,
  16313. ")"
  16314. ])
  16315. )
  16316. : "",
  16317. printDirectives(path$$1, print, n),
  16318. n.selectionSet ? (!hasOperation && !hasName ? "" : " ") : "",
  16319. path$$1.call(print, "selectionSet")
  16320. ]);
  16321. }
  16322. case "FragmentDefinition": {
  16323. return concat$7([
  16324. "fragment ",
  16325. path$$1.call(print, "name"),
  16326. " on ",
  16327. path$$1.call(print, "typeCondition"),
  16328. printDirectives(path$$1, print, n),
  16329. " ",
  16330. path$$1.call(print, "selectionSet")
  16331. ]);
  16332. }
  16333. case "SelectionSet": {
  16334. return concat$7([
  16335. "{",
  16336. indent$6(
  16337. concat$7([
  16338. hardline$6,
  16339. join$6(
  16340. hardline$6,
  16341. path$$1.call(
  16342. selectionsPath => printSequence(selectionsPath, options, print),
  16343. "selections"
  16344. )
  16345. )
  16346. ])
  16347. ),
  16348. hardline$6,
  16349. "}"
  16350. ]);
  16351. }
  16352. case "Field": {
  16353. return group$4(
  16354. concat$7([
  16355. n.alias ? concat$7([path$$1.call(print, "alias"), ": "]) : "",
  16356. path$$1.call(print, "name"),
  16357. n.arguments.length > 0
  16358. ? group$4(
  16359. concat$7([
  16360. "(",
  16361. indent$6(
  16362. concat$7([
  16363. softline$5,
  16364. join$6(
  16365. concat$7([ifBreak$3("", ", "), softline$5]),
  16366. path$$1.call(
  16367. argsPath => printSequence(argsPath, options, print),
  16368. "arguments"
  16369. )
  16370. )
  16371. ])
  16372. ),
  16373. softline$5,
  16374. ")"
  16375. ])
  16376. )
  16377. : "",
  16378. printDirectives(path$$1, print, n),
  16379. n.selectionSet ? " " : "",
  16380. path$$1.call(print, "selectionSet")
  16381. ])
  16382. );
  16383. }
  16384. case "Name": {
  16385. return n.value;
  16386. }
  16387. case "StringValue": {
  16388. if (n.block) {
  16389. return concat$7([
  16390. '"""',
  16391. hardline$6,
  16392. join$6(hardline$6, n.value.replace(/"""/g, "\\$&").split("\n")),
  16393. hardline$6,
  16394. '"""'
  16395. ]);
  16396. }
  16397. return concat$7(['"', n.value.replace(/["\\]/g, "\\$&"), '"']);
  16398. }
  16399. case "IntValue":
  16400. case "FloatValue":
  16401. case "EnumValue": {
  16402. return n.value;
  16403. }
  16404. case "BooleanValue": {
  16405. return n.value ? "true" : "false";
  16406. }
  16407. case "NullValue": {
  16408. return "null";
  16409. }
  16410. case "Variable": {
  16411. return concat$7(["$", path$$1.call(print, "name")]);
  16412. }
  16413. case "ListValue": {
  16414. return group$4(
  16415. concat$7([
  16416. "[",
  16417. indent$6(
  16418. concat$7([
  16419. softline$5,
  16420. join$6(
  16421. concat$7([ifBreak$3("", ", "), softline$5]),
  16422. path$$1.map(print, "values")
  16423. )
  16424. ])
  16425. ),
  16426. softline$5,
  16427. "]"
  16428. ])
  16429. );
  16430. }
  16431. case "ObjectValue": {
  16432. return group$4(
  16433. concat$7([
  16434. "{",
  16435. options.bracketSpacing && n.fields.length > 0 ? " " : "",
  16436. indent$6(
  16437. concat$7([
  16438. softline$5,
  16439. join$6(
  16440. concat$7([ifBreak$3("", ", "), softline$5]),
  16441. path$$1.map(print, "fields")
  16442. )
  16443. ])
  16444. ),
  16445. softline$5,
  16446. ifBreak$3("", options.bracketSpacing && n.fields.length > 0 ? " " : ""),
  16447. "}"
  16448. ])
  16449. );
  16450. }
  16451. case "ObjectField":
  16452. case "Argument": {
  16453. return concat$7([
  16454. path$$1.call(print, "name"),
  16455. ": ",
  16456. path$$1.call(print, "value")
  16457. ]);
  16458. }
  16459. case "Directive": {
  16460. return concat$7([
  16461. "@",
  16462. path$$1.call(print, "name"),
  16463. n.arguments.length > 0
  16464. ? group$4(
  16465. concat$7([
  16466. "(",
  16467. indent$6(
  16468. concat$7([
  16469. softline$5,
  16470. join$6(
  16471. concat$7([ifBreak$3("", ", "), softline$5]),
  16472. path$$1.call(
  16473. argsPath => printSequence(argsPath, options, print),
  16474. "arguments"
  16475. )
  16476. )
  16477. ])
  16478. ),
  16479. softline$5,
  16480. ")"
  16481. ])
  16482. )
  16483. : ""
  16484. ]);
  16485. }
  16486. case "NamedType": {
  16487. return path$$1.call(print, "name");
  16488. }
  16489. case "VariableDefinition": {
  16490. return concat$7([
  16491. path$$1.call(print, "variable"),
  16492. ": ",
  16493. path$$1.call(print, "type"),
  16494. n.defaultValue ? concat$7([" = ", path$$1.call(print, "defaultValue")]) : ""
  16495. ]);
  16496. }
  16497. case "TypeExtensionDefinition": {
  16498. return concat$7(["extend ", path$$1.call(print, "definition")]);
  16499. }
  16500. case "ObjectTypeExtension":
  16501. case "ObjectTypeDefinition": {
  16502. return concat$7([
  16503. path$$1.call(print, "description"),
  16504. n.description ? hardline$6 : "",
  16505. n.kind === "ObjectTypeExtension" ? "extend " : "",
  16506. "type ",
  16507. path$$1.call(print, "name"),
  16508. n.interfaces.length > 0
  16509. ? concat$7([
  16510. " implements ",
  16511. join$6(
  16512. determineInterfaceSeparator(
  16513. options.originalText.substr(
  16514. options.locStart(n),
  16515. options.locEnd(n)
  16516. )
  16517. ),
  16518. path$$1.map(print, "interfaces")
  16519. )
  16520. ])
  16521. : "",
  16522. printDirectives(path$$1, print, n),
  16523. n.fields.length > 0
  16524. ? concat$7([
  16525. " {",
  16526. indent$6(
  16527. concat$7([
  16528. hardline$6,
  16529. join$6(
  16530. hardline$6,
  16531. path$$1.call(
  16532. fieldsPath => printSequence(fieldsPath, options, print),
  16533. "fields"
  16534. )
  16535. )
  16536. ])
  16537. ),
  16538. hardline$6,
  16539. "}"
  16540. ])
  16541. : ""
  16542. ]);
  16543. }
  16544. case "FieldDefinition": {
  16545. return concat$7([
  16546. path$$1.call(print, "description"),
  16547. n.description ? hardline$6 : "",
  16548. path$$1.call(print, "name"),
  16549. n.arguments.length > 0
  16550. ? group$4(
  16551. concat$7([
  16552. "(",
  16553. indent$6(
  16554. concat$7([
  16555. softline$5,
  16556. join$6(
  16557. concat$7([ifBreak$3("", ", "), softline$5]),
  16558. path$$1.call(
  16559. argsPath => printSequence(argsPath, options, print),
  16560. "arguments"
  16561. )
  16562. )
  16563. ])
  16564. ),
  16565. softline$5,
  16566. ")"
  16567. ])
  16568. )
  16569. : "",
  16570. ": ",
  16571. path$$1.call(print, "type"),
  16572. printDirectives(path$$1, print, n)
  16573. ]);
  16574. }
  16575. case "DirectiveDefinition": {
  16576. return concat$7([
  16577. path$$1.call(print, "description"),
  16578. n.description ? hardline$6 : "",
  16579. "directive ",
  16580. "@",
  16581. path$$1.call(print, "name"),
  16582. n.arguments.length > 0
  16583. ? group$4(
  16584. concat$7([
  16585. "(",
  16586. indent$6(
  16587. concat$7([
  16588. softline$5,
  16589. join$6(
  16590. concat$7([ifBreak$3("", ", "), softline$5]),
  16591. path$$1.call(
  16592. argsPath => printSequence(argsPath, options, print),
  16593. "arguments"
  16594. )
  16595. )
  16596. ])
  16597. ),
  16598. softline$5,
  16599. ")"
  16600. ])
  16601. )
  16602. : "",
  16603. concat$7([" on ", join$6(" | ", path$$1.map(print, "locations"))])
  16604. ]);
  16605. }
  16606. case "EnumTypeExtension":
  16607. case "EnumTypeDefinition": {
  16608. return concat$7([
  16609. path$$1.call(print, "description"),
  16610. n.description ? hardline$6 : "",
  16611. n.kind === "EnumTypeExtension" ? "extend " : "",
  16612. "enum ",
  16613. path$$1.call(print, "name"),
  16614. printDirectives(path$$1, print, n),
  16615. n.values.length > 0
  16616. ? concat$7([
  16617. " {",
  16618. indent$6(
  16619. concat$7([
  16620. hardline$6,
  16621. join$6(
  16622. hardline$6,
  16623. path$$1.call(
  16624. valuesPath => printSequence(valuesPath, options, print),
  16625. "values"
  16626. )
  16627. )
  16628. ])
  16629. ),
  16630. hardline$6,
  16631. "}"
  16632. ])
  16633. : ""
  16634. ]);
  16635. }
  16636. case "EnumValueDefinition": {
  16637. return concat$7([
  16638. path$$1.call(print, "description"),
  16639. n.description ? hardline$6 : "",
  16640. path$$1.call(print, "name"),
  16641. printDirectives(path$$1, print, n)
  16642. ]);
  16643. }
  16644. case "InputValueDefinition": {
  16645. return concat$7([
  16646. path$$1.call(print, "description"),
  16647. n.description ? (n.description.block ? hardline$6 : line$4) : "",
  16648. path$$1.call(print, "name"),
  16649. ": ",
  16650. path$$1.call(print, "type"),
  16651. n.defaultValue ? concat$7([" = ", path$$1.call(print, "defaultValue")]) : "",
  16652. printDirectives(path$$1, print, n)
  16653. ]);
  16654. }
  16655. case "InputObjectTypeExtension":
  16656. case "InputObjectTypeDefinition": {
  16657. return concat$7([
  16658. path$$1.call(print, "description"),
  16659. n.description ? hardline$6 : "",
  16660. n.kind === "InputObjectTypeExtension" ? "extend " : "",
  16661. "input ",
  16662. path$$1.call(print, "name"),
  16663. printDirectives(path$$1, print, n),
  16664. n.fields.length > 0
  16665. ? concat$7([
  16666. " {",
  16667. indent$6(
  16668. concat$7([
  16669. hardline$6,
  16670. join$6(
  16671. hardline$6,
  16672. path$$1.call(
  16673. fieldsPath => printSequence(fieldsPath, options, print),
  16674. "fields"
  16675. )
  16676. )
  16677. ])
  16678. ),
  16679. hardline$6,
  16680. "}"
  16681. ])
  16682. : ""
  16683. ]);
  16684. }
  16685. case "SchemaDefinition": {
  16686. return concat$7([
  16687. "schema",
  16688. printDirectives(path$$1, print, n),
  16689. " {",
  16690. n.operationTypes.length > 0
  16691. ? indent$6(
  16692. concat$7([
  16693. hardline$6,
  16694. join$6(
  16695. hardline$6,
  16696. path$$1.call(
  16697. opsPath => printSequence(opsPath, options, print),
  16698. "operationTypes"
  16699. )
  16700. )
  16701. ])
  16702. )
  16703. : "",
  16704. hardline$6,
  16705. "}"
  16706. ]);
  16707. }
  16708. case "OperationTypeDefinition": {
  16709. return concat$7([
  16710. path$$1.call(print, "operation"),
  16711. ": ",
  16712. path$$1.call(print, "type")
  16713. ]);
  16714. }
  16715. case "InterfaceTypeExtension":
  16716. case "InterfaceTypeDefinition": {
  16717. return concat$7([
  16718. path$$1.call(print, "description"),
  16719. n.description ? hardline$6 : "",
  16720. n.kind === "InterfaceTypeExtension" ? "extend " : "",
  16721. "interface ",
  16722. path$$1.call(print, "name"),
  16723. printDirectives(path$$1, print, n),
  16724. n.fields.length > 0
  16725. ? concat$7([
  16726. " {",
  16727. indent$6(
  16728. concat$7([
  16729. hardline$6,
  16730. join$6(
  16731. hardline$6,
  16732. path$$1.call(
  16733. fieldsPath => printSequence(fieldsPath, options, print),
  16734. "fields"
  16735. )
  16736. )
  16737. ])
  16738. ),
  16739. hardline$6,
  16740. "}"
  16741. ])
  16742. : ""
  16743. ]);
  16744. }
  16745. case "FragmentSpread": {
  16746. return concat$7([
  16747. "...",
  16748. path$$1.call(print, "name"),
  16749. printDirectives(path$$1, print, n)
  16750. ]);
  16751. }
  16752. case "InlineFragment": {
  16753. return concat$7([
  16754. "...",
  16755. n.typeCondition
  16756. ? concat$7([" on ", path$$1.call(print, "typeCondition")])
  16757. : "",
  16758. printDirectives(path$$1, print, n),
  16759. " ",
  16760. path$$1.call(print, "selectionSet")
  16761. ]);
  16762. }
  16763. case "UnionTypeExtension":
  16764. case "UnionTypeDefinition": {
  16765. return group$4(
  16766. concat$7([
  16767. path$$1.call(print, "description"),
  16768. n.description ? hardline$6 : "",
  16769. group$4(
  16770. concat$7([
  16771. n.kind === "UnionTypeExtension" ? "extend " : "",
  16772. "union ",
  16773. path$$1.call(print, "name"),
  16774. printDirectives(path$$1, print, n),
  16775. n.types.length > 0
  16776. ? concat$7([
  16777. " =",
  16778. ifBreak$3("", " "),
  16779. indent$6(
  16780. concat$7([
  16781. ifBreak$3(concat$7([line$4, " "])),
  16782. join$6(concat$7([line$4, "| "]), path$$1.map(print, "types"))
  16783. ])
  16784. )
  16785. ])
  16786. : ""
  16787. ])
  16788. )
  16789. ])
  16790. );
  16791. }
  16792. case "ScalarTypeExtension":
  16793. case "ScalarTypeDefinition": {
  16794. return concat$7([
  16795. path$$1.call(print, "description"),
  16796. n.description ? hardline$6 : "",
  16797. n.kind === "ScalarTypeExtension" ? "extend " : "",
  16798. "scalar ",
  16799. path$$1.call(print, "name"),
  16800. printDirectives(path$$1, print, n)
  16801. ]);
  16802. }
  16803. case "NonNullType": {
  16804. return concat$7([path$$1.call(print, "type"), "!"]);
  16805. }
  16806. case "ListType": {
  16807. return concat$7(["[", path$$1.call(print, "type"), "]"]);
  16808. }
  16809. default:
  16810. /* istanbul ignore next */
  16811. throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
  16812. }
  16813. }
  16814. function printDirectives(path$$1, print, n) {
  16815. if (n.directives.length === 0) {
  16816. return "";
  16817. }
  16818. return concat$7([
  16819. " ",
  16820. group$4(
  16821. indent$6(
  16822. concat$7([
  16823. softline$5,
  16824. join$6(
  16825. concat$7([ifBreak$3("", " "), softline$5]),
  16826. path$$1.map(print, "directives")
  16827. )
  16828. ])
  16829. )
  16830. )
  16831. ]);
  16832. }
  16833. function printSequence(sequencePath, options, print) {
  16834. const count = sequencePath.getValue().length;
  16835. return sequencePath.map((path$$1, i) => {
  16836. const printed = print(path$$1);
  16837. if (
  16838. utilShared.isNextLineEmpty(
  16839. options.originalText,
  16840. path$$1.getValue(),
  16841. options
  16842. ) &&
  16843. i < count - 1
  16844. ) {
  16845. return concat$7([printed, hardline$6]);
  16846. }
  16847. return printed;
  16848. });
  16849. }
  16850. function canAttachComment$1(node) {
  16851. return node.kind && node.kind !== "Comment";
  16852. }
  16853. function printComment$2(commentPath) {
  16854. const comment = commentPath.getValue();
  16855. switch (comment.kind) {
  16856. case "Comment":
  16857. return "#" + comment.value.trimRight();
  16858. default:
  16859. throw new Error("Not a comment: " + JSON.stringify(comment));
  16860. }
  16861. }
  16862. function determineInterfaceSeparator(originalSource) {
  16863. const start = originalSource.indexOf("implements");
  16864. if (start === -1) {
  16865. throw new Error("Must implement interfaces: " + originalSource);
  16866. }
  16867. let end = originalSource.indexOf("{");
  16868. if (end === -1) {
  16869. end = originalSource.length;
  16870. }
  16871. return originalSource.substr(start, end).includes("&") ? " & " : ", ";
  16872. }
  16873. var printerGraphql = {
  16874. print: genericPrint$2,
  16875. hasPrettierIgnore: util$1.hasIgnoreComment,
  16876. printComment: printComment$2,
  16877. canAttachComment: canAttachComment$1
  16878. };
  16879. // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js
  16880. var options$5 = {
  16881. bracketSpacing: options.bracketSpacing
  16882. };
  16883. // Based on:
  16884. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  16885. const languages$3 = [
  16886. {
  16887. name: "GraphQL",
  16888. since: "1.5.0",
  16889. parsers: ["graphql"],
  16890. extensions: [".graphql", ".gql"],
  16891. tmScope: "source.graphql",
  16892. aceMode: "text",
  16893. liguistLanguageId: 139,
  16894. vscodeLanguageIds: ["graphql"]
  16895. }
  16896. ];
  16897. const parsers$3 = {
  16898. graphql: {
  16899. get parse() {
  16900. return require("./parser-graphql");
  16901. },
  16902. astFormat: "graphql",
  16903. locStart: function(node) {
  16904. if (typeof node.start === "number") {
  16905. return node.start;
  16906. }
  16907. return node.loc && node.loc.start;
  16908. },
  16909. locEnd: function(node) {
  16910. if (typeof node.end === "number") {
  16911. return node.end;
  16912. }
  16913. return node.loc && node.loc.end;
  16914. }
  16915. }
  16916. };
  16917. const printers$3 = {
  16918. graphql: printerGraphql
  16919. };
  16920. var languageGraphql = {
  16921. languages: languages$3,
  16922. options: options$5,
  16923. parsers: parsers$3,
  16924. printers: printers$3
  16925. };
  16926. const docBuilders$9 = doc.builders;
  16927. const hardline$8 = docBuilders$9.hardline;
  16928. const literalline$3 = docBuilders$9.literalline;
  16929. const concat$9 = docBuilders$9.concat;
  16930. const markAsRoot$1 = docBuilders$9.markAsRoot;
  16931. function embed$2(path$$1, print, textToDoc, options) {
  16932. const node = path$$1.getValue();
  16933. if (node.type === "code" && node.lang !== null) {
  16934. // only look for the first string so as to support [markdown-preview-enhanced](https://shd101wyy.github.io/markdown-preview-enhanced/#/code-chunk)
  16935. const lang = node.lang.split(/\s/, 1)[0];
  16936. const parser = getParserName(lang);
  16937. if (parser) {
  16938. const styleUnit = options.__inJsTemplate ? "~" : "`";
  16939. const style = styleUnit.repeat(
  16940. Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1)
  16941. );
  16942. const doc$$2 = textToDoc(node.value, { parser });
  16943. return markAsRoot$1(
  16944. concat$9([
  16945. style,
  16946. node.lang,
  16947. hardline$8,
  16948. replaceNewlinesWithLiterallines(doc$$2),
  16949. style
  16950. ])
  16951. );
  16952. }
  16953. }
  16954. return null;
  16955. function getParserName(lang) {
  16956. const supportInfo = support.getSupportInfo(null, {
  16957. plugins: options.plugins,
  16958. pluginsLoaded: true
  16959. });
  16960. const language = supportInfo.languages.find(
  16961. language =>
  16962. language.name.toLowerCase() === lang ||
  16963. (language.extensions &&
  16964. language.extensions.find(ext => ext.substring(1) === lang))
  16965. );
  16966. if (language) {
  16967. return language.parsers[0];
  16968. }
  16969. return null;
  16970. }
  16971. function replaceNewlinesWithLiterallines(doc$$2) {
  16972. return docUtils.mapDoc(
  16973. doc$$2,
  16974. currentDoc =>
  16975. typeof currentDoc === "string" && currentDoc.includes("\n")
  16976. ? concat$9(
  16977. currentDoc
  16978. .split(/(\n)/g)
  16979. .map((v, i) => (i % 2 === 0 ? v : literalline$3))
  16980. )
  16981. : currentDoc
  16982. );
  16983. }
  16984. }
  16985. var embed_1$2 = embed$2;
  16986. var pragma$2 = createCommonjsModule(function (module) {
  16987. "use strict";
  16988. const pragmas = ["format", "prettier"];
  16989. function startWithPragma(text) {
  16990. const pragma = `@(${pragmas.join("|")})`;
  16991. const regex = new RegExp(
  16992. [
  16993. `<!--\\s*${pragma}\\s*-->`,
  16994. `<!--.*\n[\\s\\S]*(^|\n)[^\\S\n]*${pragma}[^\\S\n]*($|\n)[\\s\\S]*\n.*-->`
  16995. ].join("|"),
  16996. "m"
  16997. );
  16998. const matched = text.match(regex);
  16999. return matched && matched.index === 0;
  17000. }
  17001. function extract(text) {
  17002. // yaml (---) and toml (+++)
  17003. const matched = text.match(
  17004. /^((---|\+\+\+)(?:\n[\s\S]*?\n|\n)\2(?:\n|$))?([\s\S]*)/
  17005. );
  17006. const frontMatter = matched[1];
  17007. const mainContent = matched[3];
  17008. return { frontMatter, mainContent };
  17009. }
  17010. module.exports = {
  17011. startWithPragma,
  17012. hasPragma: text => startWithPragma(extract(text).mainContent.trimLeft()),
  17013. insertPragma: text => {
  17014. const extracted = extract(text);
  17015. const pragma = `<!-- @${pragmas[0]} -->`;
  17016. return extracted.frontMatter
  17017. ? `${extracted.frontMatter}\n\n${pragma}\n\n${extracted.mainContent}`
  17018. : `${pragma}\n\n${extracted.mainContent}`;
  17019. }
  17020. };
  17021. });
  17022. const docBuilders$8 = doc.builders;
  17023. const concat$8 = docBuilders$8.concat;
  17024. const join$7 = docBuilders$8.join;
  17025. const line$5 = docBuilders$8.line;
  17026. const hardline$7 = docBuilders$8.hardline;
  17027. const softline$6 = docBuilders$8.softline;
  17028. const fill$4 = docBuilders$8.fill;
  17029. const align$2 = docBuilders$8.align;
  17030. const group$5 = docBuilders$8.group;
  17031. const printDocToString$2 = doc.printer.printDocToString;
  17032. const SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link"];
  17033. const SIBLING_NODE_TYPES = ["listItem", "definition", "footnoteDefinition"];
  17034. const INLINE_NODE_TYPES = [
  17035. "inlineCode",
  17036. "emphasis",
  17037. "strong",
  17038. "delete",
  17039. "link",
  17040. "linkReference",
  17041. "image",
  17042. "imageReference",
  17043. "footnote",
  17044. "footnoteReference",
  17045. "sentence",
  17046. "whitespace",
  17047. "word",
  17048. "break"
  17049. ];
  17050. const INLINE_NODE_WRAPPER_TYPES = INLINE_NODE_TYPES.concat([
  17051. "tableCell",
  17052. "paragraph",
  17053. "heading"
  17054. ]);
  17055. function genericPrint$3(path$$1, options, print) {
  17056. const node = path$$1.getValue();
  17057. if (shouldRemainTheSameContent(path$$1)) {
  17058. return concat$8(
  17059. util$1
  17060. .splitText(
  17061. options.originalText.slice(
  17062. node.position.start.offset,
  17063. node.position.end.offset
  17064. )
  17065. )
  17066. .map(
  17067. node =>
  17068. node.type === "word"
  17069. ? node.value
  17070. : node.value === ""
  17071. ? ""
  17072. : printLine(path$$1, node.value, options)
  17073. )
  17074. );
  17075. }
  17076. switch (node.type) {
  17077. case "root":
  17078. return concat$8([normalizeDoc(printRoot(path$$1, options, print)), hardline$7]);
  17079. case "paragraph":
  17080. return printChildren(path$$1, options, print, {
  17081. postprocessor: fill$4
  17082. });
  17083. case "sentence":
  17084. return printChildren(path$$1, options, print);
  17085. case "word":
  17086. return node.value
  17087. .replace(/[*]/g, "\\*") // escape all `*`
  17088. .replace(
  17089. new RegExp(
  17090. [
  17091. `(^|[${util$1.punctuationCharRange}])(_+)`,
  17092. `(_+)([${util$1.punctuationCharRange}]|$)`
  17093. ].join("|"),
  17094. "g"
  17095. ),
  17096. (_, text1, underscore1, underscore2, text2) =>
  17097. (underscore1
  17098. ? `${text1}${underscore1}`
  17099. : `${underscore2}${text2}`
  17100. ).replace(/_/g, "\\_")
  17101. ); // escape all `_` except concating with non-punctuation, e.g. `1_2_3` is not considered emphasis
  17102. case "whitespace": {
  17103. const parentNode = path$$1.getParentNode();
  17104. const index = parentNode.children.indexOf(node);
  17105. const nextNode = parentNode.children[index + 1];
  17106. const proseWrap =
  17107. // leading char that may cause different syntax
  17108. nextNode && /^>|^([-+*]|#{1,6}|[0-9]+[.)])$/.test(nextNode.value)
  17109. ? "never"
  17110. : options.proseWrap;
  17111. return printLine(path$$1, node.value, { proseWrap });
  17112. }
  17113. case "emphasis": {
  17114. const parentNode = path$$1.getParentNode();
  17115. const index = parentNode.children.indexOf(node);
  17116. const prevNode = parentNode.children[index - 1];
  17117. const nextNode = parentNode.children[index + 1];
  17118. const hasPrevOrNextWord = // `1*2*3` is considered emphais but `1_2_3` is not
  17119. (prevNode &&
  17120. prevNode.type === "sentence" &&
  17121. prevNode.children.length > 0 &&
  17122. util$1.getLast(prevNode.children).type === "word" &&
  17123. !util$1.getLast(prevNode.children).hasTrailingPunctuation) ||
  17124. (nextNode &&
  17125. nextNode.type === "sentence" &&
  17126. nextNode.children.length > 0 &&
  17127. nextNode.children[0].type === "word" &&
  17128. !nextNode.children[0].hasLeadingPunctuation);
  17129. const style =
  17130. hasPrevOrNextWord || getAncestorNode$1(path$$1, "emphasis") ? "*" : "_";
  17131. return concat$8([style, printChildren(path$$1, options, print), style]);
  17132. }
  17133. case "strong":
  17134. return concat$8(["**", printChildren(path$$1, options, print), "**"]);
  17135. case "delete":
  17136. return concat$8(["~~", printChildren(path$$1, options, print), "~~"]);
  17137. case "inlineCode": {
  17138. const backtickCount = util$1.getMaxContinuousCount(node.value, "`");
  17139. const style = backtickCount === 1 ? "``" : "`";
  17140. const gap = backtickCount ? " " : "";
  17141. return concat$8([style, gap, node.value, gap, style]);
  17142. }
  17143. case "link":
  17144. switch (options.originalText[node.position.start.offset]) {
  17145. case "<":
  17146. return concat$8(["<", node.url, ">"]);
  17147. case "[":
  17148. return concat$8([
  17149. "[",
  17150. printChildren(path$$1, options, print),
  17151. "](",
  17152. printUrl(node.url, ")"),
  17153. printTitle(node.title, options),
  17154. ")"
  17155. ]);
  17156. default:
  17157. return options.originalText.slice(
  17158. node.position.start.offset,
  17159. node.position.end.offset
  17160. );
  17161. }
  17162. case "image":
  17163. return concat$8([
  17164. "![",
  17165. node.alt || "",
  17166. "](",
  17167. printUrl(node.url, ")"),
  17168. printTitle(node.title, options),
  17169. ")"
  17170. ]);
  17171. case "blockquote":
  17172. return concat$8(["> ", align$2("> ", printChildren(path$$1, options, print))]);
  17173. case "heading":
  17174. return concat$8([
  17175. "#".repeat(node.depth) + " ",
  17176. printChildren(path$$1, options, print)
  17177. ]);
  17178. case "code": {
  17179. if (
  17180. // the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it
  17181. /^\n?( {4,}|\t)/.test(
  17182. options.originalText.slice(
  17183. node.position.start.offset,
  17184. node.position.end.offset
  17185. )
  17186. )
  17187. ) {
  17188. // indented code block
  17189. const alignment = " ".repeat(4);
  17190. return align$2(
  17191. alignment,
  17192. concat$8([alignment, join$7(hardline$7, node.value.split("\n"))])
  17193. );
  17194. }
  17195. // fenced code block
  17196. const styleUnit = options.__inJsTemplate ? "~" : "`";
  17197. const style = styleUnit.repeat(
  17198. Math.max(
  17199. 3,
  17200. util$1.getMaxContinuousCount(node.value, styleUnit) + 1
  17201. )
  17202. );
  17203. return concat$8([
  17204. style,
  17205. node.lang || "",
  17206. hardline$7,
  17207. join$7(hardline$7, node.value.split("\n")),
  17208. hardline$7,
  17209. style
  17210. ]);
  17211. }
  17212. case "yaml":
  17213. case "toml": {
  17214. const style = node.type === "yaml" ? "---" : "+++";
  17215. return node.value
  17216. ? concat$8([style, hardline$7, node.value, hardline$7, style])
  17217. : concat$8([style, hardline$7, style]);
  17218. }
  17219. case "html": {
  17220. const parentNode = path$$1.getParentNode();
  17221. return replaceNewlinesWithHardlines(
  17222. parentNode.type === "root" &&
  17223. util$1.getLast(parentNode.children) === node
  17224. ? node.value.trimRight()
  17225. : node.value
  17226. );
  17227. }
  17228. case "list": {
  17229. const nthSiblingIndex = getNthListSiblingIndex(
  17230. node,
  17231. path$$1.getParentNode()
  17232. );
  17233. const isGitDiffFriendlyOrderedList =
  17234. node.ordered &&
  17235. node.children.length > 1 &&
  17236. /^\s*1(\.|\))/.test(
  17237. options.originalText.slice(
  17238. node.children[1].position.start.offset,
  17239. node.children[1].position.end.offset
  17240. )
  17241. );
  17242. return printChildren(path$$1, options, print, {
  17243. processor: (childPath, index) => {
  17244. const prefix = getPrefix();
  17245. return concat$8([
  17246. prefix,
  17247. align$2(
  17248. " ".repeat(prefix.length),
  17249. printListItem(childPath, options, print, prefix)
  17250. )
  17251. ]);
  17252. function getPrefix() {
  17253. const rawPrefix = node.ordered
  17254. ? (index === 0
  17255. ? node.start
  17256. : isGitDiffFriendlyOrderedList
  17257. ? 1
  17258. : node.start + index) +
  17259. (nthSiblingIndex % 2 === 0 ? ". " : ") ")
  17260. : nthSiblingIndex % 2 === 0
  17261. ? "* "
  17262. : "- ";
  17263. // do not print trailing spaces for empty list item since it might be treated as `break` node
  17264. // by [doc-printer](https://github.com/prettier/prettier/blob/1.10.2/src/doc/doc-printer.js#L395-L405),
  17265. // we don't want to preserve unnecessary trailing spaces.
  17266. const listItem = childPath.getValue();
  17267. return listItem.children.length
  17268. ? alignListPrefix(rawPrefix, options)
  17269. : rawPrefix;
  17270. }
  17271. }
  17272. });
  17273. }
  17274. case "thematicBreak": {
  17275. const counter = getAncestorCounter$1(path$$1, "list");
  17276. if (counter === -1) {
  17277. return "---";
  17278. }
  17279. const nthSiblingIndex = getNthListSiblingIndex(
  17280. path$$1.getParentNode(counter),
  17281. path$$1.getParentNode(counter + 1)
  17282. );
  17283. return nthSiblingIndex % 2 === 0 ? "---" : "***";
  17284. }
  17285. case "linkReference":
  17286. return concat$8([
  17287. "[",
  17288. printChildren(path$$1, options, print),
  17289. "]",
  17290. node.referenceType === "full"
  17291. ? concat$8(["[", node.identifier, "]"])
  17292. : node.referenceType === "collapsed"
  17293. ? "[]"
  17294. : ""
  17295. ]);
  17296. case "imageReference":
  17297. switch (node.referenceType) {
  17298. case "full":
  17299. return concat$8(["![", node.alt || "", "][", node.identifier, "]"]);
  17300. default:
  17301. return concat$8([
  17302. "![",
  17303. node.alt,
  17304. "]",
  17305. node.referenceType === "collapsed" ? "[]" : ""
  17306. ]);
  17307. }
  17308. case "definition":
  17309. return concat$8([
  17310. "[",
  17311. node.identifier,
  17312. "]: ",
  17313. printUrl(node.url),
  17314. printTitle(node.title, options)
  17315. ]);
  17316. case "footnote":
  17317. return concat$8(["[^", printChildren(path$$1, options, print), "]"]);
  17318. case "footnoteReference":
  17319. return concat$8(["[^", node.identifier, "]"]);
  17320. case "footnoteDefinition": {
  17321. const nextNode = path$$1.getParentNode().children[path$$1.getName() + 1];
  17322. return concat$8([
  17323. "[^",
  17324. node.identifier,
  17325. "]: ",
  17326. group$5(
  17327. concat$8([
  17328. align$2(
  17329. " ".repeat(options.tabWidth),
  17330. printChildren(path$$1, options, print, {
  17331. processor: (childPath, index) =>
  17332. index === 0
  17333. ? group$5(concat$8([softline$6, softline$6, childPath.call(print)]))
  17334. : childPath.call(print)
  17335. })
  17336. ),
  17337. nextNode && nextNode.type === "footnoteDefinition" ? softline$6 : ""
  17338. ])
  17339. )
  17340. ]);
  17341. }
  17342. case "table":
  17343. return printTable(path$$1, options, print);
  17344. case "tableCell":
  17345. return printChildren(path$$1, options, print);
  17346. case "break":
  17347. return concat$8([
  17348. /\s/.test(options.originalText[node.position.start.offset])
  17349. ? " "
  17350. : "\\",
  17351. hardline$7
  17352. ]);
  17353. case "tableRow": // handled in "table"
  17354. case "listItem": // handled in "list"
  17355. default:
  17356. throw new Error(`Unknown markdown type ${JSON.stringify(node.type)}`);
  17357. }
  17358. }
  17359. function printListItem(path$$1, options, print, listPrefix) {
  17360. const node = path$$1.getValue();
  17361. const prefix = node.checked === null ? "" : node.checked ? "[x] " : "[ ] ";
  17362. return concat$8([
  17363. prefix,
  17364. printChildren(path$$1, options, print, {
  17365. processor: (childPath, index) => {
  17366. if (index === 0 && childPath.getValue().type !== "list") {
  17367. return align$2(" ".repeat(prefix.length), childPath.call(print));
  17368. }
  17369. const alignment = " ".repeat(
  17370. clamp(options.tabWidth - listPrefix.length, 0, 3) // 4+ will cause indented code block
  17371. );
  17372. return concat$8([alignment, align$2(alignment, childPath.call(print))]);
  17373. }
  17374. })
  17375. ]);
  17376. }
  17377. function alignListPrefix(prefix, options) {
  17378. const additionalSpaces = getAdditionalSpaces();
  17379. return (
  17380. prefix +
  17381. " ".repeat(
  17382. additionalSpaces >= 4 ? 0 : additionalSpaces // 4+ will cause indented code block
  17383. )
  17384. );
  17385. function getAdditionalSpaces() {
  17386. const restSpaces = prefix.length % options.tabWidth;
  17387. return restSpaces === 0 ? 0 : options.tabWidth - restSpaces;
  17388. }
  17389. }
  17390. function getNthListSiblingIndex(node, parentNode) {
  17391. return getNthSiblingIndex(
  17392. node,
  17393. parentNode,
  17394. siblingNode => siblingNode.ordered === node.ordered
  17395. );
  17396. }
  17397. function replaceNewlinesWithHardlines(str) {
  17398. return join$7(hardline$7, str.split("\n"));
  17399. }
  17400. function getNthSiblingIndex(node, parentNode, condition) {
  17401. condition = condition || (() => true);
  17402. let index = -1;
  17403. for (const childNode of parentNode.children) {
  17404. if (childNode.type === node.type && condition(childNode)) {
  17405. index++;
  17406. } else {
  17407. index = -1;
  17408. }
  17409. if (childNode === node) {
  17410. return index;
  17411. }
  17412. }
  17413. }
  17414. function getAncestorCounter$1(path$$1, typeOrTypes) {
  17415. const types = [].concat(typeOrTypes);
  17416. let counter = -1;
  17417. let ancestorNode;
  17418. while ((ancestorNode = path$$1.getParentNode(++counter))) {
  17419. if (types.indexOf(ancestorNode.type) !== -1) {
  17420. return counter;
  17421. }
  17422. }
  17423. return -1;
  17424. }
  17425. function getAncestorNode$1(path$$1, typeOrTypes) {
  17426. const counter = getAncestorCounter$1(path$$1, typeOrTypes);
  17427. return counter === -1 ? null : path$$1.getParentNode(counter);
  17428. }
  17429. function printLine(path$$1, value, options) {
  17430. if (options.proseWrap === "preserve" && value === "\n") {
  17431. return hardline$7;
  17432. }
  17433. const isBreakable =
  17434. options.proseWrap === "always" &&
  17435. !getAncestorNode$1(path$$1, SINGLE_LINE_NODE_TYPES);
  17436. return value !== ""
  17437. ? isBreakable
  17438. ? line$5
  17439. : " "
  17440. : isBreakable
  17441. ? softline$6
  17442. : "";
  17443. }
  17444. function printTable(path$$1, options, print) {
  17445. const node = path$$1.getValue();
  17446. const contents = []; // { [rowIndex: number]: { [columnIndex: number]: string } }
  17447. path$$1.map(rowPath => {
  17448. const rowContents = [];
  17449. rowPath.map(cellPath => {
  17450. rowContents.push(
  17451. printDocToString$2(cellPath.call(print), options).formatted
  17452. );
  17453. }, "children");
  17454. contents.push(rowContents);
  17455. }, "children");
  17456. const columnMaxWidths = contents.reduce(
  17457. (currentWidths, rowContents) =>
  17458. currentWidths.map((width, columnIndex) =>
  17459. Math.max(width, util$1.getStringWidth(rowContents[columnIndex]))
  17460. ),
  17461. contents[0].map(() => 3) // minimum width = 3 (---, :--, :-:, --:)
  17462. );
  17463. return join$7(hardline$7, [
  17464. printRow(contents[0]),
  17465. printSeparator(),
  17466. join$7(hardline$7, contents.slice(1).map(printRow))
  17467. ]);
  17468. function printSeparator() {
  17469. return concat$8([
  17470. "| ",
  17471. join$7(
  17472. " | ",
  17473. columnMaxWidths.map((width, index) => {
  17474. switch (node.align[index]) {
  17475. case "left":
  17476. return ":" + "-".repeat(width - 1);
  17477. case "right":
  17478. return "-".repeat(width - 1) + ":";
  17479. case "center":
  17480. return ":" + "-".repeat(width - 2) + ":";
  17481. default:
  17482. return "-".repeat(width);
  17483. }
  17484. })
  17485. ),
  17486. " |"
  17487. ]);
  17488. }
  17489. function printRow(rowContents) {
  17490. return concat$8([
  17491. "| ",
  17492. join$7(
  17493. " | ",
  17494. rowContents.map((rowContent, columnIndex) => {
  17495. switch (node.align[columnIndex]) {
  17496. case "right":
  17497. return alignRight(rowContent, columnMaxWidths[columnIndex]);
  17498. case "center":
  17499. return alignCenter(rowContent, columnMaxWidths[columnIndex]);
  17500. default:
  17501. return alignLeft(rowContent, columnMaxWidths[columnIndex]);
  17502. }
  17503. })
  17504. ),
  17505. " |"
  17506. ]);
  17507. }
  17508. function alignLeft(text, width) {
  17509. return concat$8([text, " ".repeat(width - util$1.getStringWidth(text))]);
  17510. }
  17511. function alignRight(text, width) {
  17512. return concat$8([" ".repeat(width - util$1.getStringWidth(text)), text]);
  17513. }
  17514. function alignCenter(text, width) {
  17515. const spaces = width - util$1.getStringWidth(text);
  17516. const left = Math.floor(spaces / 2);
  17517. const right = spaces - left;
  17518. return concat$8([" ".repeat(left), text, " ".repeat(right)]);
  17519. }
  17520. }
  17521. function printRoot(path$$1, options, print) {
  17522. /** @typedef {{ index: number, offset: number }} IgnorePosition */
  17523. /** @type {Array<{start: IgnorePosition, end: IgnorePosition}>} */
  17524. const ignoreRanges = [];
  17525. /** @type {IgnorePosition | null} */
  17526. let ignoreStart = null;
  17527. const children = path$$1.getValue().children;
  17528. children.forEach((childNode, index) => {
  17529. switch (isPrettierIgnore(childNode)) {
  17530. case "start":
  17531. if (ignoreStart === null) {
  17532. ignoreStart = { index, offset: childNode.position.end.offset };
  17533. }
  17534. break;
  17535. case "end":
  17536. if (ignoreStart !== null) {
  17537. ignoreRanges.push({
  17538. start: ignoreStart,
  17539. end: { index, offset: childNode.position.start.offset }
  17540. });
  17541. ignoreStart = null;
  17542. }
  17543. break;
  17544. default:
  17545. // do nothing
  17546. break;
  17547. }
  17548. });
  17549. return printChildren(path$$1, options, print, {
  17550. processor: (childPath, index) => {
  17551. if (ignoreRanges.length !== 0) {
  17552. const ignoreRange = ignoreRanges[0];
  17553. if (index === ignoreRange.start.index) {
  17554. return concat$8([
  17555. children[ignoreRange.start.index].value,
  17556. options.originalText.slice(
  17557. ignoreRange.start.offset,
  17558. ignoreRange.end.offset
  17559. ),
  17560. children[ignoreRange.end.index].value
  17561. ]);
  17562. }
  17563. if (ignoreRange.start.index < index && index < ignoreRange.end.index) {
  17564. return false;
  17565. }
  17566. if (index === ignoreRange.end.index) {
  17567. ignoreRanges.shift();
  17568. return false;
  17569. }
  17570. }
  17571. return childPath.call(print);
  17572. }
  17573. });
  17574. }
  17575. function printChildren(path$$1, options, print, events) {
  17576. events = events || {};
  17577. const postprocessor = events.postprocessor || concat$8;
  17578. const processor = events.processor || (childPath => childPath.call(print));
  17579. const node = path$$1.getValue();
  17580. const parts = [];
  17581. let lastChildNode;
  17582. path$$1.map((childPath, index) => {
  17583. const childNode = childPath.getValue();
  17584. const result = processor(childPath, index);
  17585. if (result !== false) {
  17586. const data = {
  17587. parts,
  17588. prevNode: lastChildNode,
  17589. parentNode: node,
  17590. options
  17591. };
  17592. if (!shouldNotPrePrintHardline(childNode, data)) {
  17593. parts.push(hardline$7);
  17594. if (
  17595. shouldPrePrintDoubleHardline(childNode, data) ||
  17596. shouldPrePrintTripleHardline(childNode, data)
  17597. ) {
  17598. parts.push(hardline$7);
  17599. }
  17600. if (shouldPrePrintTripleHardline(childNode, data)) {
  17601. parts.push(hardline$7);
  17602. }
  17603. }
  17604. parts.push(result);
  17605. lastChildNode = childNode;
  17606. }
  17607. }, "children");
  17608. return postprocessor(parts);
  17609. }
  17610. /** @return {false | 'next' | 'start' | 'end'} */
  17611. function isPrettierIgnore(node) {
  17612. if (node.type !== "html") {
  17613. return false;
  17614. }
  17615. const match = node.value.match(
  17616. /^<!--\s*prettier-ignore(?:-(start|end))?\s*-->$/
  17617. );
  17618. return match === null ? false : match[1] ? match[1] : "next";
  17619. }
  17620. function shouldNotPrePrintHardline(node, data) {
  17621. const isFirstNode = data.parts.length === 0;
  17622. const isInlineNode = INLINE_NODE_TYPES.indexOf(node.type) !== -1;
  17623. const isInlineHTML =
  17624. node.type === "html" &&
  17625. INLINE_NODE_WRAPPER_TYPES.indexOf(data.parentNode.type) !== -1;
  17626. return isFirstNode || isInlineNode || isInlineHTML;
  17627. }
  17628. function shouldPrePrintDoubleHardline(node, data) {
  17629. const isSequence = (data.prevNode && data.prevNode.type) === node.type;
  17630. const isSiblingNode =
  17631. isSequence && SIBLING_NODE_TYPES.indexOf(node.type) !== -1;
  17632. const isInTightListItem =
  17633. data.parentNode.type === "listItem" && !data.parentNode.loose;
  17634. const isPrevNodeLooseListItem =
  17635. data.prevNode && data.prevNode.type === "listItem" && data.prevNode.loose;
  17636. const isPrevNodePrettierIgnore = isPrettierIgnore(data.prevNode) === "next";
  17637. return (
  17638. isPrevNodeLooseListItem ||
  17639. !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore)
  17640. );
  17641. }
  17642. function shouldPrePrintTripleHardline(node, data) {
  17643. const isPrevNodeList = data.prevNode && data.prevNode.type === "list";
  17644. const isIndentedCode =
  17645. node.type === "code" &&
  17646. /\s/.test(data.options.originalText[node.position.start.offset]);
  17647. return isPrevNodeList && isIndentedCode;
  17648. }
  17649. function shouldRemainTheSameContent(path$$1) {
  17650. const ancestorNode = getAncestorNode$1(path$$1, [
  17651. "linkReference",
  17652. "imageReference"
  17653. ]);
  17654. return (
  17655. ancestorNode &&
  17656. (ancestorNode.type !== "linkReference" ||
  17657. ancestorNode.referenceType !== "full")
  17658. );
  17659. }
  17660. function normalizeDoc(doc$$2) {
  17661. return docUtils.mapDoc(doc$$2, currentDoc => {
  17662. if (!currentDoc.parts) {
  17663. return currentDoc;
  17664. }
  17665. if (currentDoc.type === "concat" && currentDoc.parts.length === 1) {
  17666. return currentDoc.parts[0];
  17667. }
  17668. const parts = [];
  17669. currentDoc.parts.forEach(part => {
  17670. if (part.type === "concat") {
  17671. parts.push.apply(parts, part.parts);
  17672. } else if (part !== "") {
  17673. parts.push(part);
  17674. }
  17675. });
  17676. return Object.assign({}, currentDoc, {
  17677. parts: normalizeParts(parts)
  17678. });
  17679. });
  17680. }
  17681. function printUrl(url$$1, dangerousCharOrChars) {
  17682. const dangerousChars = [" "].concat(dangerousCharOrChars || []);
  17683. return new RegExp(dangerousChars.map(x => `\\${x}`).join("|")).test(url$$1)
  17684. ? `<${url$$1}>`
  17685. : url$$1;
  17686. }
  17687. function printTitle(title, options) {
  17688. if (!title) {
  17689. return "";
  17690. }
  17691. if (title.includes('"') && title.includes("'") && !title.includes(")")) {
  17692. return ` (${title})`; // avoid escaped quotes
  17693. }
  17694. // faster than using RegExps: https://jsperf.com/performance-of-match-vs-split
  17695. const singleCount = title.split("'").length - 1;
  17696. const doubleCount = title.split('"').length - 1;
  17697. const quote =
  17698. singleCount > doubleCount
  17699. ? '"'
  17700. : doubleCount > singleCount
  17701. ? "'"
  17702. : options.singleQuote
  17703. ? "'"
  17704. : '"';
  17705. title = title.replace(new RegExp(`(${quote})`, "g"), "\\$1");
  17706. return ` ${quote}${title}${quote}`;
  17707. }
  17708. function normalizeParts(parts) {
  17709. return parts.reduce((current, part) => {
  17710. const lastPart = util$1.getLast(current);
  17711. if (typeof lastPart === "string" && typeof part === "string") {
  17712. current.splice(-1, 1, lastPart + part);
  17713. } else {
  17714. current.push(part);
  17715. }
  17716. return current;
  17717. }, []);
  17718. }
  17719. function clamp(value, min, max) {
  17720. return value < min ? min : value > max ? max : value;
  17721. }
  17722. function clean$5(ast, newObj, parent) {
  17723. // for codeblock
  17724. if (ast.type === "code") {
  17725. delete newObj.value;
  17726. }
  17727. // for whitespace: "\n" and " " are considered the same
  17728. if (ast.type === "whitespace" && ast.value === "\n") {
  17729. newObj.value = " ";
  17730. }
  17731. // for insert pragma
  17732. if (
  17733. parent &&
  17734. parent.type === "root" &&
  17735. (parent.children[0] === ast ||
  17736. ((parent.children[0].type === "yaml" ||
  17737. parent.children[0].type === "toml") &&
  17738. parent.children[1] === ast)) &&
  17739. ast.type === "html" &&
  17740. pragma$2.startWithPragma(ast.value)
  17741. ) {
  17742. return null;
  17743. }
  17744. }
  17745. function hasPrettierIgnore$1(path$$1) {
  17746. const index = +path$$1.getName();
  17747. if (index === 0) {
  17748. return false;
  17749. }
  17750. const prevNode = path$$1.getParentNode().children[index - 1];
  17751. return isPrettierIgnore(prevNode) === "next";
  17752. }
  17753. var printerMarkdown = {
  17754. print: genericPrint$3,
  17755. embed: embed_1$2,
  17756. massageAstNode: clean$5,
  17757. hasPrettierIgnore: hasPrettierIgnore$1,
  17758. insertPragma: pragma$2.insertPragma
  17759. };
  17760. const CATEGORY_MARKDOWN = "Markdown";
  17761. // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js
  17762. var options$8 = {
  17763. proseWrap: {
  17764. since: "1.8.2",
  17765. category: CATEGORY_MARKDOWN,
  17766. type: "choice",
  17767. default: [
  17768. { since: "1.8.2", value: true },
  17769. { since: "1.9.0", value: "preserve" }
  17770. ],
  17771. description: "How to wrap prose. (markdown)",
  17772. choices: [
  17773. {
  17774. since: "1.9.0",
  17775. value: "always",
  17776. description: "Wrap prose if it exceeds the print width."
  17777. },
  17778. {
  17779. since: "1.9.0",
  17780. value: "never",
  17781. description: "Do not wrap prose."
  17782. },
  17783. {
  17784. since: "1.9.0",
  17785. value: "preserve",
  17786. description: "Wrap prose as-is."
  17787. },
  17788. { value: false, deprecated: "1.9.0", redirect: "never" },
  17789. { value: true, deprecated: "1.9.0", redirect: "always" }
  17790. ]
  17791. },
  17792. singleQuote: options.singleQuote
  17793. };
  17794. // Based on:
  17795. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  17796. const languages$4 = [
  17797. {
  17798. name: "Markdown",
  17799. since: "1.8.0",
  17800. parsers: ["remark"],
  17801. aliases: ["pandoc"],
  17802. aceMode: "markdown",
  17803. codemirrorMode: "gfm",
  17804. codemirrorMimeType: "text/x-gfm",
  17805. wrap: true,
  17806. extensions: [
  17807. ".md",
  17808. ".markdown",
  17809. ".mdown",
  17810. ".mdwn",
  17811. ".mkd",
  17812. ".mkdn",
  17813. ".mkdown",
  17814. ".ron",
  17815. ".workbook"
  17816. ],
  17817. filenames: ["README"],
  17818. tmScope: "source.gfm",
  17819. linguistLanguageId: 222,
  17820. vscodeLanguageIds: ["markdown"]
  17821. }
  17822. ];
  17823. const remark = {
  17824. get parse() {
  17825. return require("./parser-markdown");
  17826. },
  17827. astFormat: "mdast",
  17828. hasPragma: pragma$2.hasPragma,
  17829. locStart: node => node.position.start.offset,
  17830. locEnd: node => node.position.end.offset
  17831. };
  17832. const parsers$4 = {
  17833. remark,
  17834. // TODO: Delete this in 2.0
  17835. markdown: remark
  17836. };
  17837. const printers$4 = {
  17838. mdast: printerMarkdown
  17839. };
  17840. var languageMarkdown = {
  17841. languages: languages$4,
  17842. options: options$8,
  17843. parsers: parsers$4,
  17844. printers: printers$4
  17845. };
  17846. const docUtils$5 = doc.utils;
  17847. const docBuilders$11 = doc.builders;
  17848. const hardline$10 = docBuilders$11.hardline;
  17849. const concat$11 = docBuilders$11.concat;
  17850. function embed$4(path$$1, print, textToDoc, options) {
  17851. const node = path$$1.getValue();
  17852. switch (node.type) {
  17853. case "text": {
  17854. const parent = path$$1.getParentNode();
  17855. // Inline JavaScript
  17856. if (
  17857. parent.type === "script" &&
  17858. ((!parent.attribs.lang && !parent.attribs.lang) ||
  17859. parent.attribs.type === "text/javascript" ||
  17860. parent.attribs.type === "application/javascript")
  17861. ) {
  17862. const parser = options.parser === "flow" ? "flow" : "babylon";
  17863. const doc$$2 = textToDoc(getText(options, node), { parser });
  17864. return concat$11([hardline$10, doc$$2]);
  17865. }
  17866. // Inline TypeScript
  17867. if (
  17868. parent.type === "script" &&
  17869. (parent.attribs.type === "application/x-typescript" ||
  17870. parent.attribs.lang === "ts")
  17871. ) {
  17872. const doc$$2 = textToDoc(
  17873. getText(options, node),
  17874. { parser: "typescript" },
  17875. options
  17876. );
  17877. return concat$11([hardline$10, doc$$2]);
  17878. }
  17879. // Inline Styles
  17880. if (parent.type === "style") {
  17881. const doc$$2 = textToDoc(getText(options, node), { parser: "css" });
  17882. return concat$11([hardline$10, docUtils$5.stripTrailingHardline(doc$$2)]);
  17883. }
  17884. break;
  17885. }
  17886. case "attribute": {
  17887. /*
  17888. * Vue binding sytax: JS expressions
  17889. * :class="{ 'some-key': value }"
  17890. * v-bind:id="'list-' + id"
  17891. * v-if="foo && !bar"
  17892. * @click="someFunction()"
  17893. */
  17894. if (/(^@)|(^v-)|:/.test(node.key) && !/^\w+$/.test(node.value)) {
  17895. const doc$$2 = textToDoc(node.value, {
  17896. parser: parseJavaScriptExpression,
  17897. // Use singleQuote since HTML attributes use double-quotes.
  17898. // TODO(azz): We still need to do an entity escape on the attribute.
  17899. singleQuote: true
  17900. });
  17901. return concat$11([
  17902. node.key,
  17903. '="',
  17904. util$1.hasNewlineInRange(node.value, 0, node.value.length)
  17905. ? doc$$2
  17906. : docUtils$5.removeLines(doc$$2),
  17907. '"'
  17908. ]);
  17909. }
  17910. }
  17911. }
  17912. }
  17913. function parseJavaScriptExpression(text, parsers) {
  17914. // Force parsing as an expression
  17915. const ast = parsers.babylon(`(${text})`);
  17916. // Extract expression from the declaration
  17917. return {
  17918. type: "File",
  17919. program: ast.program.body[0].expression
  17920. };
  17921. }
  17922. function getText(options, node) {
  17923. return options.originalText.slice(
  17924. options.locStart(node),
  17925. options.locEnd(node)
  17926. );
  17927. }
  17928. var embed_1$4 = embed$4;
  17929. const docBuilders$10 = doc.builders;
  17930. const concat$10 = docBuilders$10.concat;
  17931. const join$8 = docBuilders$10.join;
  17932. const hardline$9 = docBuilders$10.hardline;
  17933. const line$6 = docBuilders$10.line;
  17934. const softline$7 = docBuilders$10.softline;
  17935. const group$6 = docBuilders$10.group;
  17936. const indent$7 = docBuilders$10.indent;
  17937. // http://w3c.github.io/html/single-page.html#void-elements
  17938. const voidTags$1 = {
  17939. area: true,
  17940. base: true,
  17941. br: true,
  17942. col: true,
  17943. embed: true,
  17944. hr: true,
  17945. img: true,
  17946. input: true,
  17947. link: true,
  17948. meta: true,
  17949. param: true,
  17950. source: true,
  17951. track: true,
  17952. wbr: true
  17953. };
  17954. function genericPrint$4(path$$1, options, print) {
  17955. const n = path$$1.getValue();
  17956. if (!n) {
  17957. return "";
  17958. }
  17959. if (typeof n === "string") {
  17960. return n;
  17961. }
  17962. switch (n.type) {
  17963. case "root": {
  17964. return printChildren$1(path$$1, print);
  17965. }
  17966. case "directive": {
  17967. return concat$10(["<", n.data, ">", hardline$9]);
  17968. }
  17969. case "text": {
  17970. return n.data.replace(/\s+/g, " ").trim();
  17971. }
  17972. case "script":
  17973. case "style":
  17974. case "tag": {
  17975. const selfClose = voidTags$1[n.name] ? ">" : " />";
  17976. const children = printChildren$1(path$$1, print);
  17977. const hasNewline = util$1.hasNewlineInRange(
  17978. options.originalText,
  17979. options.locStart(n),
  17980. options.locEnd(n)
  17981. );
  17982. return group$6(
  17983. concat$10([
  17984. hasNewline ? hardline$9 : "",
  17985. "<",
  17986. n.name,
  17987. printAttributes(path$$1, print),
  17988. n.children.length ? ">" : selfClose,
  17989. n.name.toLowerCase() === "html"
  17990. ? concat$10([hardline$9, children])
  17991. : indent$7(children),
  17992. n.children.length ? concat$10([softline$7, "</", n.name, ">"]) : hardline$9
  17993. ])
  17994. );
  17995. }
  17996. case "comment": {
  17997. return concat$10(["<!-- ", n.data.trim(), " -->"]);
  17998. }
  17999. case "attribute": {
  18000. if (!n.value) {
  18001. return n.key;
  18002. }
  18003. return concat$10([n.key, '="', n.value, '"']);
  18004. }
  18005. default:
  18006. /* istanbul ignore next */
  18007. throw new Error("unknown htmlparser2 type: " + n.type);
  18008. }
  18009. }
  18010. function printAttributes(path$$1, print) {
  18011. const node = path$$1.getValue();
  18012. return concat$10([
  18013. node.attributes.length ? " " : "",
  18014. indent$7(join$8(line$6, path$$1.map(print, "attributes")))
  18015. ]);
  18016. }
  18017. function printChildren$1(path$$1, print) {
  18018. const children = [];
  18019. path$$1.each(childPath => {
  18020. const child = childPath.getValue();
  18021. if (child.type !== "text") {
  18022. children.push(hardline$9);
  18023. }
  18024. children.push(childPath.call(print));
  18025. }, "children");
  18026. return concat$10(children);
  18027. }
  18028. var printerHtmlparser2 = {
  18029. print: genericPrint$4,
  18030. embed: embed_1$4,
  18031. hasPrettierIgnore: util$1.hasIgnoreComment
  18032. };
  18033. // Based on:
  18034. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  18035. const languages$5 = [
  18036. {
  18037. name: "HTML",
  18038. since: null, // unreleased
  18039. parsers: ["parse5"],
  18040. group: "HTML",
  18041. tmScope: "text.html.basic",
  18042. aceMode: "html",
  18043. codemirrorMode: "htmlmixed",
  18044. codemirrorMimeType: "text/html",
  18045. aliases: ["xhtml"],
  18046. extensions: [".html", ".htm", ".html.hl", ".inc", ".st", ".xht", ".xhtml"],
  18047. linguistLanguageId: 146,
  18048. vscodeLanguageIds: ["html"]
  18049. }
  18050. ];
  18051. const parsers$5 = {
  18052. parse5: {
  18053. get parse() {
  18054. return require("./parser-parse5");
  18055. },
  18056. astFormat: "htmlparser2",
  18057. locEnd: function(node) {
  18058. return node.__location && node.__location.endOffset;
  18059. },
  18060. locStart: function(node) {
  18061. return node.__location && node.__location.startOffset;
  18062. }
  18063. }
  18064. };
  18065. const printers$5 = {
  18066. htmlparser2: printerHtmlparser2
  18067. };
  18068. var languageHtml = {
  18069. languages: languages$5,
  18070. parsers: parsers$5,
  18071. printers: printers$5
  18072. };
  18073. const docBuilders$13 = doc.builders;
  18074. const concat$13 = docBuilders$13.concat;
  18075. const hardline$12 = docBuilders$13.hardline;
  18076. function embed$6(path$$1, print, textToDoc, options) {
  18077. const node = path$$1.getValue();
  18078. const parent = path$$1.getParentNode();
  18079. if (!parent || parent.tag !== "root" || node.unary) {
  18080. return null;
  18081. }
  18082. let parser;
  18083. if (node.tag === "style") {
  18084. const langAttr = node.attrs.find(attr => attr.name === "lang");
  18085. if (!langAttr || langAttr.value === "postcss") {
  18086. parser = "css";
  18087. } else if (langAttr.value === "scss") {
  18088. parser = "scss";
  18089. } else if (langAttr.value === "less") {
  18090. parser = "less";
  18091. }
  18092. }
  18093. if (node.tag === "script") {
  18094. const langAttr = node.attrs.find(attr => attr.name === "lang");
  18095. if (!langAttr) {
  18096. parser = "babylon";
  18097. } else if (langAttr.value === "ts" || langAttr.value === "tsx") {
  18098. parser = "typescript";
  18099. }
  18100. }
  18101. if (!parser) {
  18102. return null;
  18103. }
  18104. return concat$13([
  18105. options.originalText.slice(node.start, node.contentStart),
  18106. hardline$12,
  18107. textToDoc(options.originalText.slice(node.contentStart, node.contentEnd), {
  18108. parser
  18109. }),
  18110. options.originalText.slice(node.contentEnd, node.end)
  18111. ]);
  18112. }
  18113. var embed_1$6 = embed$6;
  18114. const docBuilders$12 = doc.builders;
  18115. const concat$12 = docBuilders$12.concat;
  18116. const hardline$11 = docBuilders$12.hardline;
  18117. function genericPrint$5(path$$1, options, print) {
  18118. const n = path$$1.getValue();
  18119. const res = [];
  18120. let index = n.start;
  18121. path$$1.each(childPath => {
  18122. const child = childPath.getValue();
  18123. res.push(options.originalText.slice(index, child.start));
  18124. res.push(childPath.call(print));
  18125. index = child.end;
  18126. }, "children");
  18127. // If there are no children, we just print the node from start to end.
  18128. // Otherwise, index should point to the end of the last child, and we
  18129. // need to print the closing tag.
  18130. res.push(options.originalText.slice(index, n.end));
  18131. // Only force a trailing newline if there were any contents.
  18132. if (n.tag === "root" && n.children.length) {
  18133. res.push(hardline$11);
  18134. }
  18135. return concat$12(res);
  18136. }
  18137. const clean$6 = (ast, newObj) => {
  18138. delete newObj.contentStart;
  18139. delete newObj.contentEnd;
  18140. };
  18141. var printerVue = {
  18142. print: genericPrint$5,
  18143. embed: embed_1$6,
  18144. massageAstNode: clean$6
  18145. };
  18146. // Based on:
  18147. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  18148. const languages$6 = [
  18149. {
  18150. name: "Vue",
  18151. since: "1.10.0",
  18152. parsers: ["vue"],
  18153. group: "HTML",
  18154. tmScope: "text.html.vue",
  18155. aceMode: "html",
  18156. codemirrorMode: "htmlmixed",
  18157. codemirrorMimeType: "text/html",
  18158. extensions: [".vue"],
  18159. linguistLanguageId: 146,
  18160. vscodeLanguageIds: ["vue"]
  18161. }
  18162. ];
  18163. const parsers$6 = {
  18164. vue: {
  18165. get parse() {
  18166. return require("./parser-vue");
  18167. },
  18168. astFormat: "vue"
  18169. }
  18170. };
  18171. const printers$6 = {
  18172. vue: printerVue
  18173. };
  18174. var languageVue = {
  18175. languages: languages$6,
  18176. parsers: parsers$6,
  18177. printers: printers$6
  18178. };
  18179. function loadPlugins(plugins) {
  18180. plugins = plugins || [];
  18181. const internalPlugins = [
  18182. languageJs,
  18183. languageCss,
  18184. languageHandlebars,
  18185. languageGraphql,
  18186. languageMarkdown,
  18187. languageHtml,
  18188. languageVue
  18189. ];
  18190. const externalPlugins = plugins
  18191. .concat(
  18192. getPluginsFromPackage(
  18193. readPkgUp.sync({
  18194. normalize: false
  18195. }).pkg
  18196. )
  18197. )
  18198. .map(plugin => {
  18199. if (typeof plugin !== "string") {
  18200. return plugin;
  18201. }
  18202. const pluginPath = resolve.sync(plugin, { basedir: process.cwd() });
  18203. return Object.assign({ name: plugin }, require(pluginPath));
  18204. });
  18205. return deduplicate(internalPlugins.concat(externalPlugins));
  18206. }
  18207. function getPluginsFromPackage(pkg) {
  18208. if (!pkg) {
  18209. return [];
  18210. }
  18211. const deps = Object.assign({}, pkg.dependencies, pkg.devDependencies);
  18212. return Object.keys(deps).filter(
  18213. dep =>
  18214. dep.startsWith("prettier-plugin-") || dep.startsWith("@prettier/plugin-")
  18215. );
  18216. }
  18217. function deduplicate(items) {
  18218. const uniqItems = [];
  18219. for (const item of items) {
  18220. if (uniqItems.indexOf(item) < 0) {
  18221. uniqItems.push(item);
  18222. }
  18223. }
  18224. return uniqItems;
  18225. }
  18226. var loadPlugins_1 = loadPlugins;
  18227. const CATEGORY_CONFIG = "Config";
  18228. const CATEGORY_EDITOR = "Editor";
  18229. const CATEGORY_FORMAT = "Format";
  18230. const CATEGORY_OTHER = "Other";
  18231. const CATEGORY_OUTPUT = "Output";
  18232. const categoryOrder = [
  18233. CATEGORY_OUTPUT,
  18234. CATEGORY_FORMAT,
  18235. CATEGORY_CONFIG,
  18236. CATEGORY_EDITOR,
  18237. CATEGORY_OTHER
  18238. ];
  18239. /**
  18240. * {
  18241. * [optionName]: {
  18242. * // The type of the option. For 'choice', see also `choices` below.
  18243. * // When passing a type other than the ones listed below, the option is
  18244. * // treated as taking any string as argument, and `--option <${type}>` will
  18245. * // be displayed in --help.
  18246. * type: "boolean" | "choice" | "int" | string;
  18247. *
  18248. * // Default value to be passed to the minimist option `default`.
  18249. * default?: any;
  18250. *
  18251. * // Alias name to be passed to the minimist option `alias`.
  18252. * alias?: string;
  18253. *
  18254. * // For grouping options by category in --help.
  18255. * category?: string;
  18256. *
  18257. * // Description to be displayed in --help. If omitted, the option won't be
  18258. * // shown at all in --help (but see also `oppositeDescription` below).
  18259. * description?: string;
  18260. *
  18261. * // Description for `--no-${name}` to be displayed in --help. If omitted,
  18262. * // `--no-${name}` won't be shown.
  18263. * oppositeDescription?: string;
  18264. *
  18265. * // Indicate if this option is simply passed to the API.
  18266. * // true: use camelified name as the API option name.
  18267. * // string: use this value as the API option name.
  18268. * forwardToApi?: boolean | string;
  18269. *
  18270. * // Indicate that a CLI flag should be an array when forwarded to the API.
  18271. * array?: boolean;
  18272. *
  18273. * // Specify available choices for validation. They will also be displayed
  18274. * // in --help as <a|b|c>.
  18275. * // Use an object instead of a string if a choice is deprecated and should
  18276. * // be treated as `redirect` instead, or if you'd like to add description for
  18277. * // the choice.
  18278. * choices?: Array<
  18279. * | string
  18280. * | { value: string, description?: string, deprecated?: boolean, redirect?: string }
  18281. * >;
  18282. *
  18283. * // If the option has a value that is an exception to the regular value
  18284. * // constraints, indicate that value here (or use a function for more
  18285. * // flexibility).
  18286. * exception?: ((value: any) => boolean);
  18287. *
  18288. * // Indicate that the option is deprecated. Use a string to add an extra
  18289. * // message to --help for the option, for example to suggest a replacement
  18290. * // option.
  18291. * deprecated?: true | string;
  18292. * }
  18293. * }
  18294. *
  18295. * Note: The options below are sorted alphabetically.
  18296. */
  18297. const options$11 = {
  18298. color: {
  18299. // The supports-color package (a sub sub dependency) looks directly at
  18300. // `process.argv` for `--no-color` and such-like options. The reason it is
  18301. // listed here is to avoid "Ignored unknown option: --no-color" warnings.
  18302. // See https://github.com/chalk/supports-color/#info for more information.
  18303. type: "boolean",
  18304. default: true,
  18305. description: "Colorize error messages.",
  18306. oppositeDescription: "Do not colorize error messages."
  18307. },
  18308. config: {
  18309. type: "path",
  18310. category: CATEGORY_CONFIG,
  18311. description:
  18312. "Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js).",
  18313. oppositeDescription: "Do not look for a configuration file."
  18314. },
  18315. "config-precedence": {
  18316. type: "choice",
  18317. category: CATEGORY_CONFIG,
  18318. default: "cli-override",
  18319. choices: [
  18320. {
  18321. value: "cli-override",
  18322. description: "CLI options take precedence over config file"
  18323. },
  18324. {
  18325. value: "file-override",
  18326. description: "Config file take precedence over CLI options"
  18327. },
  18328. {
  18329. value: "prefer-file",
  18330. description: dedent_1`
  18331. If a config file is found will evaluate it and ignore other CLI options.
  18332. If no config file is found CLI options will evaluate as normal.
  18333. `
  18334. }
  18335. ],
  18336. description:
  18337. "Define in which order config files and CLI options should be evaluated."
  18338. },
  18339. "debug-check": {
  18340. type: "boolean"
  18341. },
  18342. "debug-print-doc": {
  18343. type: "boolean"
  18344. },
  18345. editorconfig: {
  18346. type: "boolean",
  18347. category: CATEGORY_CONFIG,
  18348. description: "Take .editorconfig into account when parsing configuration.",
  18349. oppositeDescription:
  18350. "Don't take .editorconfig into account when parsing configuration.",
  18351. default: true
  18352. },
  18353. "find-config-path": {
  18354. type: "path",
  18355. category: CATEGORY_CONFIG,
  18356. description:
  18357. "Find and print the path to a configuration file for the given input file."
  18358. },
  18359. help: {
  18360. type: "flag",
  18361. alias: "h",
  18362. description: dedent_1`
  18363. Show CLI usage, or details about the given flag.
  18364. Example: --help write
  18365. `
  18366. },
  18367. "ignore-path": {
  18368. type: "path",
  18369. category: CATEGORY_CONFIG,
  18370. default: ".prettierignore",
  18371. description: "Path to a file with patterns describing files to ignore."
  18372. },
  18373. "list-different": {
  18374. type: "boolean",
  18375. category: CATEGORY_OUTPUT,
  18376. alias: "l",
  18377. description:
  18378. "Print the names of files that are different from Prettier's formatting."
  18379. },
  18380. loglevel: {
  18381. type: "choice",
  18382. description: "What level of logs to report.",
  18383. default: "log",
  18384. choices: ["silent", "error", "warn", "log", "debug"]
  18385. },
  18386. stdin: {
  18387. type: "boolean",
  18388. description: "Force reading input from stdin."
  18389. },
  18390. "support-info": {
  18391. type: "boolean",
  18392. description: "Print support information as JSON."
  18393. },
  18394. version: {
  18395. type: "boolean",
  18396. alias: "v",
  18397. description: "Print Prettier version."
  18398. },
  18399. "with-node-modules": {
  18400. type: "boolean",
  18401. category: CATEGORY_CONFIG,
  18402. description: "Process files inside 'node_modules' directory."
  18403. },
  18404. write: {
  18405. type: "boolean",
  18406. category: CATEGORY_OUTPUT,
  18407. description: "Edit files in-place. (Beware!)"
  18408. }
  18409. };
  18410. const usageSummary = dedent_1`
  18411. Usage: prettier [options] [file/glob ...]
  18412. By default, output is written to stdout.
  18413. Stdin is read if it is piped to Prettier and no files are given.
  18414. `;
  18415. var constant = {
  18416. CATEGORY_CONFIG,
  18417. CATEGORY_EDITOR,
  18418. CATEGORY_FORMAT,
  18419. CATEGORY_OTHER,
  18420. CATEGORY_OUTPUT,
  18421. categoryOrder,
  18422. options: options$11,
  18423. usageSummary
  18424. };
  18425. var require$$0$11 = ( _package$1 && _package ) || _package$1;
  18426. const currentVersion = require$$0$11.version;
  18427. const CATEGORY_GLOBAL = "Global";
  18428. const CATEGORY_SPECIAL = "Special";
  18429. /**
  18430. * @typedef {Object} OptionInfo
  18431. * @property {string} since - available since version
  18432. * @property {string} category
  18433. * @property {'int' | 'boolean' | 'choice' | 'path'} type
  18434. * @property {boolean} array - indicate it's an array of the specified type
  18435. * @property {boolean?} deprecated - deprecated since version
  18436. * @property {OptionRedirectInfo?} redirect - redirect deprecated option
  18437. * @property {string} description
  18438. * @property {string?} oppositeDescription - for `false` option
  18439. * @property {OptionValueInfo} default
  18440. * @property {OptionRangeInfo?} range - for type int
  18441. * @property {OptionChoiceInfo?} choices - for type choice
  18442. * @property {(value: any) => boolean} exception
  18443. *
  18444. * @typedef {number | boolean | string} OptionValue
  18445. * @typedef {OptionValue | [{ value: OptionValue[] }] | Array<{ since: string, value: OptionValue}>} OptionValueInfo
  18446. *
  18447. * @typedef {Object} OptionRedirectInfo
  18448. * @property {string} option
  18449. * @property {OptionValue} value
  18450. *
  18451. * @typedef {Object} OptionRangeInfo
  18452. * @property {number} start - recommended range start
  18453. * @property {number} end - recommended range end
  18454. * @property {number} step - recommended range step
  18455. *
  18456. * @typedef {Object} OptionChoiceInfo
  18457. * @property {boolean | string} value - boolean for the option that is originally boolean type
  18458. * @property {string?} description - undefined if redirect
  18459. * @property {string?} since - undefined if available since the first version of the option
  18460. * @property {string?} deprecated - deprecated since version
  18461. * @property {OptionValueInfo?} redirect - redirect deprecated value
  18462. *
  18463. * @property {string?} cliName
  18464. * @property {string?} cliCategory
  18465. * @property {string?} cliDescription
  18466. */
  18467. /** @type {{ [name: string]: OptionInfo } */
  18468. const supportOptions = {
  18469. cursorOffset: {
  18470. since: "1.4.0",
  18471. category: CATEGORY_SPECIAL,
  18472. type: "int",
  18473. default: -1,
  18474. range: { start: -1, end: Infinity, step: 1 },
  18475. description: dedent_1`
  18476. Print (to stderr) where a cursor at the given position would move to after formatting.
  18477. This option cannot be used with --range-start and --range-end.
  18478. `,
  18479. cliCategory: constant.CATEGORY_EDITOR
  18480. },
  18481. filepath: {
  18482. since: "1.4.0",
  18483. category: CATEGORY_SPECIAL,
  18484. type: "path",
  18485. default: undefined,
  18486. description:
  18487. "Specify the input filepath. This will be used to do parser inference.",
  18488. cliName: "stdin-filepath",
  18489. cliCategory: constant.CATEGORY_OTHER,
  18490. cliDescription: "Path to the file to pretend that stdin comes from."
  18491. },
  18492. insertPragma: {
  18493. since: "1.8.0",
  18494. category: CATEGORY_SPECIAL,
  18495. type: "boolean",
  18496. default: false,
  18497. description: "Insert @format pragma into file's first docblock comment.",
  18498. cliCategory: constant.CATEGORY_OTHER
  18499. },
  18500. parser: {
  18501. since: "0.0.10",
  18502. category: CATEGORY_GLOBAL,
  18503. type: "choice",
  18504. default: "babylon",
  18505. description: "Which parser to use.",
  18506. exception: value =>
  18507. typeof value === "string" || typeof value === "function",
  18508. choices: [
  18509. { value: "flow", description: "Flow" },
  18510. { value: "babylon", description: "JavaScript" },
  18511. { value: "typescript", since: "1.4.0", description: "TypeScript" },
  18512. { value: "css", since: "1.7.1", description: "CSS" },
  18513. {
  18514. value: "postcss",
  18515. since: "1.4.0",
  18516. description: "CSS/Less/SCSS",
  18517. deprecated: "1.7.1",
  18518. redirect: "css"
  18519. },
  18520. { value: "less", since: "1.7.1", description: "Less" },
  18521. { value: "scss", since: "1.7.1", description: "SCSS" },
  18522. { value: "json", since: "1.5.0", description: "JSON" },
  18523. { value: "graphql", since: "1.5.0", description: "GraphQL" },
  18524. { value: "markdown", since: "1.8.0", description: "Markdown" },
  18525. { value: "vue", since: "1.10.0", description: "Vue" }
  18526. ]
  18527. },
  18528. plugins: {
  18529. since: "1.10.0",
  18530. type: "path",
  18531. array: true,
  18532. default: [{ value: [] }],
  18533. category: CATEGORY_GLOBAL,
  18534. description:
  18535. "Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
  18536. exception: value => typeof value === "string" || typeof value === "object",
  18537. cliName: "plugin",
  18538. cliCategory: constant.CATEGORY_CONFIG
  18539. },
  18540. printWidth: {
  18541. since: "0.0.0",
  18542. category: CATEGORY_GLOBAL,
  18543. type: "int",
  18544. default: 80,
  18545. description: "The line length where Prettier will try wrap.",
  18546. range: { start: 0, end: Infinity, step: 1 }
  18547. },
  18548. rangeEnd: {
  18549. since: "1.4.0",
  18550. category: CATEGORY_SPECIAL,
  18551. type: "int",
  18552. default: Infinity,
  18553. range: { start: 0, end: Infinity, step: 1 },
  18554. description: dedent_1`
  18555. Format code ending at a given character offset (exclusive).
  18556. The range will extend forwards to the end of the selected statement.
  18557. This option cannot be used with --cursor-offset.
  18558. `,
  18559. cliCategory: constant.CATEGORY_EDITOR
  18560. },
  18561. rangeStart: {
  18562. since: "1.4.0",
  18563. category: CATEGORY_SPECIAL,
  18564. type: "int",
  18565. default: 0,
  18566. range: { start: 0, end: Infinity, step: 1 },
  18567. description: dedent_1`
  18568. Format code starting at a given character offset.
  18569. The range will extend backwards to the start of the first line containing the selected statement.
  18570. This option cannot be used with --cursor-offset.
  18571. `,
  18572. cliCategory: constant.CATEGORY_EDITOR
  18573. },
  18574. requirePragma: {
  18575. since: "1.7.0",
  18576. category: CATEGORY_SPECIAL,
  18577. type: "boolean",
  18578. default: false,
  18579. description: dedent_1`
  18580. Require either '@prettier' or '@format' to be present in the file's first docblock comment
  18581. in order for it to be formatted.
  18582. `,
  18583. cliCategory: constant.CATEGORY_OTHER
  18584. },
  18585. tabWidth: {
  18586. type: "int",
  18587. category: CATEGORY_GLOBAL,
  18588. default: 2,
  18589. description: "Number of spaces per indentation level.",
  18590. range: { start: 0, end: Infinity, step: 1 }
  18591. },
  18592. useFlowParser: {
  18593. since: "0.0.0",
  18594. category: CATEGORY_GLOBAL,
  18595. type: "boolean",
  18596. default: false,
  18597. deprecated: "0.0.10",
  18598. description: "Use flow parser.",
  18599. redirect: { option: "parser", value: "flow" },
  18600. cliName: "flow-parser"
  18601. },
  18602. useTabs: {
  18603. since: "1.0.0",
  18604. category: CATEGORY_GLOBAL,
  18605. type: "boolean",
  18606. default: false,
  18607. description: "Indent with tabs instead of spaces."
  18608. }
  18609. };
  18610. function getSupportInfo$1(version, opts) {
  18611. opts = Object.assign(
  18612. {
  18613. plugins: [],
  18614. pluginsLoaded: false,
  18615. showUnreleased: false,
  18616. showDeprecated: false,
  18617. showInternal: false
  18618. },
  18619. opts
  18620. );
  18621. if (!version) {
  18622. version = currentVersion;
  18623. }
  18624. const plugins = opts.pluginsLoaded ? opts.plugins : loadPlugins_1(opts.plugins);
  18625. const options = util$1
  18626. .arrayify(
  18627. Object.assign(
  18628. plugins.reduce(
  18629. (currentOptions, plugin) =>
  18630. Object.assign(currentOptions, plugin.options),
  18631. {}
  18632. ),
  18633. supportOptions
  18634. ),
  18635. "name"
  18636. )
  18637. .sort((a, b) => (a.name === b.name ? 0 : a.name < b.name ? -1 : 1))
  18638. .filter(filterSince)
  18639. .filter(filterDeprecated)
  18640. .map(mapDeprecated)
  18641. .map(mapInternal)
  18642. .map(option => {
  18643. const newOption = Object.assign({}, option);
  18644. if (Array.isArray(newOption.default)) {
  18645. newOption.default =
  18646. newOption.default.length === 1
  18647. ? newOption.default[0].value
  18648. : newOption.default
  18649. .filter(filterSince)
  18650. .sort((info1, info2) =>
  18651. semver.compare(info2.since, info1.since)
  18652. )[0].value;
  18653. }
  18654. if (Array.isArray(newOption.choices)) {
  18655. newOption.choices = newOption.choices
  18656. .filter(filterSince)
  18657. .filter(filterDeprecated)
  18658. .map(mapDeprecated);
  18659. }
  18660. return newOption;
  18661. })
  18662. .map(option => {
  18663. const filteredPlugins = plugins.filter(
  18664. plugin => plugin.defaultOptions && plugin.defaultOptions[option.name]
  18665. );
  18666. const pluginDefaults = filteredPlugins.reduce((reduced, plugin) => {
  18667. reduced[plugin.name] = plugin.defaultOptions[option.name];
  18668. return reduced;
  18669. }, {});
  18670. return Object.assign(option, { pluginDefaults });
  18671. });
  18672. const usePostCssParser = semver.lt(version, "1.7.1");
  18673. const languages = plugins
  18674. .reduce((all, plugin) => all.concat(plugin.languages), [])
  18675. .filter(
  18676. language =>
  18677. language.since
  18678. ? semver.gte(version, language.since)
  18679. : language.since !== null
  18680. )
  18681. .map(language => {
  18682. // Prevent breaking changes
  18683. if (language.name === "Markdown") {
  18684. return Object.assign({}, language, {
  18685. parsers: ["markdown"]
  18686. });
  18687. }
  18688. if (language.name === "TypeScript") {
  18689. return Object.assign({}, language, {
  18690. parsers: ["typescript"]
  18691. });
  18692. }
  18693. if (usePostCssParser && language.group === "CSS") {
  18694. return Object.assign({}, language, {
  18695. parsers: ["postcss"]
  18696. });
  18697. }
  18698. return language;
  18699. });
  18700. return { languages, options };
  18701. function filterSince(object) {
  18702. return (
  18703. opts.showUnreleased ||
  18704. !("since" in object) ||
  18705. (object.since && semver.gte(version, object.since))
  18706. );
  18707. }
  18708. function filterDeprecated(object) {
  18709. return (
  18710. opts.showDeprecated ||
  18711. !("deprecated" in object) ||
  18712. (object.deprecated && semver.lt(version, object.deprecated))
  18713. );
  18714. }
  18715. function mapDeprecated(object) {
  18716. if (!object.deprecated || opts.showDeprecated) {
  18717. return object;
  18718. }
  18719. const newObject = Object.assign({}, object);
  18720. delete newObject.deprecated;
  18721. delete newObject.redirect;
  18722. return newObject;
  18723. }
  18724. function mapInternal(object) {
  18725. if (opts.showInternal) {
  18726. return object;
  18727. }
  18728. const newObject = Object.assign({}, object);
  18729. delete newObject.cliName;
  18730. delete newObject.cliCategory;
  18731. delete newObject.cliDescription;
  18732. return newObject;
  18733. }
  18734. }
  18735. var support = {
  18736. getSupportInfo: getSupportInfo$1
  18737. };
  18738. function FastPath(value) {
  18739. assert.ok(this instanceof FastPath);
  18740. this.stack = [value];
  18741. }
  18742. // The name of the current property is always the penultimate element of
  18743. // this.stack, and always a String.
  18744. FastPath.prototype.getName = function getName() {
  18745. const s = this.stack;
  18746. const len = s.length;
  18747. if (len > 1) {
  18748. return s[len - 2];
  18749. }
  18750. // Since the name is always a string, null is a safe sentinel value to
  18751. // return if we do not know the name of the (root) value.
  18752. /* istanbul ignore next */
  18753. return null;
  18754. };
  18755. // The value of the current property is always the final element of
  18756. // this.stack.
  18757. FastPath.prototype.getValue = function getValue() {
  18758. const s = this.stack;
  18759. return s[s.length - 1];
  18760. };
  18761. function getNodeHelper(path$$1, count) {
  18762. const s = path$$1.stack;
  18763. for (let i = s.length - 1; i >= 0; i -= 2) {
  18764. const value = s[i];
  18765. if (value && !Array.isArray(value) && --count < 0) {
  18766. return value;
  18767. }
  18768. }
  18769. return null;
  18770. }
  18771. FastPath.prototype.getNode = function getNode(count) {
  18772. return getNodeHelper(this, ~~count);
  18773. };
  18774. FastPath.prototype.getParentNode = function getParentNode(count) {
  18775. return getNodeHelper(this, ~~count + 1);
  18776. };
  18777. // Temporarily push properties named by string arguments given after the
  18778. // callback function onto this.stack, then call the callback with a
  18779. // reference to this (modified) FastPath object. Note that the stack will
  18780. // be restored to its original state after the callback is finished, so it
  18781. // is probably a mistake to retain a reference to the path.
  18782. FastPath.prototype.call = function call(callback /*, name1, name2, ... */) {
  18783. const s = this.stack;
  18784. const origLen = s.length;
  18785. let value = s[origLen - 1];
  18786. const argc = arguments.length;
  18787. for (let i = 1; i < argc; ++i) {
  18788. const name = arguments[i];
  18789. value = value[name];
  18790. s.push(name, value);
  18791. }
  18792. const result = callback(this);
  18793. s.length = origLen;
  18794. return result;
  18795. };
  18796. // Similar to FastPath.prototype.call, except that the value obtained by
  18797. // accessing this.getValue()[name1][name2]... should be array-like. The
  18798. // callback will be called with a reference to this path object for each
  18799. // element of the array.
  18800. FastPath.prototype.each = function each(callback /*, name1, name2, ... */) {
  18801. const s = this.stack;
  18802. const origLen = s.length;
  18803. let value = s[origLen - 1];
  18804. const argc = arguments.length;
  18805. for (let i = 1; i < argc; ++i) {
  18806. const name = arguments[i];
  18807. value = value[name];
  18808. s.push(name, value);
  18809. }
  18810. for (let i = 0; i < value.length; ++i) {
  18811. if (i in value) {
  18812. s.push(i, value[i]);
  18813. // If the callback needs to know the value of i, call
  18814. // path.getName(), assuming path is the parameter name.
  18815. callback(this);
  18816. s.length -= 2;
  18817. }
  18818. }
  18819. s.length = origLen;
  18820. };
  18821. // Similar to FastPath.prototype.each, except that the results of the
  18822. // callback function invocations are stored in an array and returned at
  18823. // the end of the iteration.
  18824. FastPath.prototype.map = function map(callback /*, name1, name2, ... */) {
  18825. const s = this.stack;
  18826. const origLen = s.length;
  18827. let value = s[origLen - 1];
  18828. const argc = arguments.length;
  18829. for (let i = 1; i < argc; ++i) {
  18830. const name = arguments[i];
  18831. value = value[name];
  18832. s.push(name, value);
  18833. }
  18834. const result = new Array(value.length);
  18835. for (let i = 0; i < value.length; ++i) {
  18836. if (i in value) {
  18837. s.push(i, value[i]);
  18838. result[i] = callback(this, i);
  18839. s.length -= 2;
  18840. }
  18841. }
  18842. s.length = origLen;
  18843. return result;
  18844. };
  18845. var fastPath = FastPath;
  18846. /* eslint-disable no-nested-ternary */
  18847. var arr = [];
  18848. var charCodeCache = [];
  18849. var leven = function (a, b) {
  18850. if (a === b) {
  18851. return 0;
  18852. }
  18853. var swap = a;
  18854. // Swapping the strings if `a` is longer than `b` so we know which one is the
  18855. // shortest & which one is the longest
  18856. if (a.length > b.length) {
  18857. a = b;
  18858. b = swap;
  18859. }
  18860. var aLen = a.length;
  18861. var bLen = b.length;
  18862. if (aLen === 0) {
  18863. return bLen;
  18864. }
  18865. if (bLen === 0) {
  18866. return aLen;
  18867. }
  18868. // Performing suffix trimming:
  18869. // We can linearly drop suffix common to both strings since they
  18870. // don't increase distance at all
  18871. // Note: `~-` is the bitwise way to perform a `- 1` operation
  18872. while (aLen > 0 && (a.charCodeAt(~-aLen) === b.charCodeAt(~-bLen))) {
  18873. aLen--;
  18874. bLen--;
  18875. }
  18876. if (aLen === 0) {
  18877. return bLen;
  18878. }
  18879. // Performing prefix trimming
  18880. // We can linearly drop prefix common to both strings since they
  18881. // don't increase distance at all
  18882. var start = 0;
  18883. while (start < aLen && (a.charCodeAt(start) === b.charCodeAt(start))) {
  18884. start++;
  18885. }
  18886. aLen -= start;
  18887. bLen -= start;
  18888. if (aLen === 0) {
  18889. return bLen;
  18890. }
  18891. var bCharCode;
  18892. var ret;
  18893. var tmp;
  18894. var tmp2;
  18895. var i = 0;
  18896. var j = 0;
  18897. while (i < aLen) {
  18898. charCodeCache[start + i] = a.charCodeAt(start + i);
  18899. arr[i] = ++i;
  18900. }
  18901. while (j < bLen) {
  18902. bCharCode = b.charCodeAt(start + j);
  18903. tmp = j++;
  18904. ret = j;
  18905. for (i = 0; i < aLen; i++) {
  18906. tmp2 = bCharCode === charCodeCache[start + i] ? tmp : tmp + 1;
  18907. tmp = arr[i];
  18908. ret = arr[i] = tmp > ret ? tmp2 > ret ? ret + 1 : tmp2 : tmp2 > tmp ? tmp + 1 : tmp2;
  18909. }
  18910. }
  18911. return ret;
  18912. };
  18913. function apiDescriptor(name, value) {
  18914. return arguments.length === 1
  18915. ? JSON.stringify(name)
  18916. : `\`{ ${apiDescriptor(name)}: ${JSON.stringify(value)} }\``;
  18917. }
  18918. function cliDescriptor(name, value) {
  18919. return value === false
  18920. ? `\`--no-${name}\``
  18921. : value === true || arguments.length === 1
  18922. ? `\`--${name}\``
  18923. : value === ""
  18924. ? `\`--${name}\` without an argument`
  18925. : `\`--${name}=${value}\``;
  18926. }
  18927. var optionsDescriptor = {
  18928. apiDescriptor,
  18929. cliDescriptor
  18930. };
  18931. function validateOption(value, optionInfo, opts) {
  18932. opts = opts || {};
  18933. const descriptor = opts.descriptor || optionsDescriptor.apiDescriptor;
  18934. if (
  18935. typeof optionInfo.exception === "function" &&
  18936. optionInfo.exception(value)
  18937. ) {
  18938. return;
  18939. }
  18940. try {
  18941. validateOptionType(value, optionInfo);
  18942. } catch (error) {
  18943. throw new Error(
  18944. `Invalid \`${descriptor(optionInfo.name)}\` value. ${
  18945. error.message
  18946. }, but received \`${JSON.stringify(value)}\`.`
  18947. );
  18948. }
  18949. }
  18950. function validateOptionType(value, optionInfo) {
  18951. if (optionInfo.array) {
  18952. if (!Array.isArray(value)) {
  18953. throw new Error(`Expected an array`);
  18954. }
  18955. value.forEach(v =>
  18956. validateOptionType(v, Object.assign({}, optionInfo, { array: false }))
  18957. );
  18958. } else {
  18959. switch (optionInfo.type) {
  18960. case "int":
  18961. validateIntOption(value);
  18962. break;
  18963. case "boolean":
  18964. validateBooleanOption(value);
  18965. break;
  18966. case "choice":
  18967. validateChoiceOption(value, optionInfo.choices);
  18968. break;
  18969. }
  18970. }
  18971. }
  18972. function validateBooleanOption(value) {
  18973. if (typeof value !== "boolean") {
  18974. throw new Error(`Expected a boolean`);
  18975. }
  18976. }
  18977. function validateIntOption(value) {
  18978. if (
  18979. !(
  18980. typeof value === "number" &&
  18981. Math.floor(value) === value &&
  18982. value >= 0 &&
  18983. value !== Infinity
  18984. )
  18985. ) {
  18986. throw new Error(`Expected an integer`);
  18987. }
  18988. }
  18989. function validateChoiceOption(value, choiceInfos) {
  18990. if (!choiceInfos.some(choiceInfo => choiceInfo.value === value)) {
  18991. const choices = choiceInfos
  18992. .filter(choiceInfo => !choiceInfo.deprecated)
  18993. .map(choiceInfo => JSON.stringify(choiceInfo.value))
  18994. .sort();
  18995. const head = choices.slice(0, -2);
  18996. const tail = choices.slice(-2);
  18997. throw new Error(`Expected ${head.concat(tail.join(" or ")).join(", ")}`);
  18998. }
  18999. }
  19000. var optionsValidator = { validateOption };
  19001. function normalizeOptions$1(options, optionInfos, opts) {
  19002. opts = opts || {};
  19003. const logger =
  19004. opts.logger === false
  19005. ? { warn() {} }
  19006. : opts.logger !== undefined
  19007. ? opts.logger
  19008. : console;
  19009. const descriptor = opts.descriptor || optionsDescriptor.apiDescriptor;
  19010. const passThrough = opts.passThrough || [];
  19011. const optionInfoMap = optionInfos.reduce(
  19012. (reduced, optionInfo) =>
  19013. Object.assign(reduced, { [optionInfo.name]: optionInfo }),
  19014. {}
  19015. );
  19016. const normalizedOptions = Object.keys(options).reduce((newOptions, key) => {
  19017. const optionInfo = optionInfoMap[key];
  19018. let optionName = key;
  19019. let optionValue = options[key];
  19020. if (!optionInfo) {
  19021. if (passThrough === true || passThrough.indexOf(optionName) !== -1) {
  19022. newOptions[optionName] = optionValue;
  19023. } else {
  19024. logger.warn(
  19025. createUnknownOptionMessage(
  19026. optionName,
  19027. optionValue,
  19028. optionInfos,
  19029. descriptor
  19030. )
  19031. );
  19032. }
  19033. return newOptions;
  19034. }
  19035. if (!optionInfo.deprecated) {
  19036. optionValue = normalizeOption(optionValue, optionInfo);
  19037. } else if (typeof optionInfo.redirect === "string") {
  19038. logger.warn(createRedirectOptionMessage(optionInfo, descriptor));
  19039. optionName = optionInfo.redirect;
  19040. } else if (optionValue) {
  19041. logger.warn(createRedirectOptionMessage(optionInfo, descriptor));
  19042. optionValue = optionInfo.redirect.value;
  19043. optionName = optionInfo.redirect.option;
  19044. }
  19045. if (optionInfo.choices) {
  19046. const choiceInfo = optionInfo.choices.find(
  19047. choice => choice.value === optionValue
  19048. );
  19049. if (choiceInfo && choiceInfo.deprecated) {
  19050. logger.warn(
  19051. createRedirectChoiceMessage(optionInfo, choiceInfo, descriptor)
  19052. );
  19053. optionValue = choiceInfo.redirect;
  19054. }
  19055. }
  19056. if (optionInfo.array && !Array.isArray(optionValue)) {
  19057. optionValue = [optionValue];
  19058. }
  19059. if (optionValue !== optionInfo.default) {
  19060. optionsValidator.validateOption(optionValue, optionInfoMap[optionName], {
  19061. descriptor
  19062. });
  19063. }
  19064. newOptions[optionName] = optionValue;
  19065. return newOptions;
  19066. }, {});
  19067. return normalizedOptions;
  19068. }
  19069. function normalizeOption(option, optionInfo) {
  19070. return optionInfo.type === "int" ? Number(option) : option;
  19071. }
  19072. function createUnknownOptionMessage(key, value, optionInfos, descriptor) {
  19073. const messages = [`Ignored unknown option ${descriptor(key, value)}.`];
  19074. const suggestedOptionInfo = optionInfos.find(
  19075. optionInfo => leven(optionInfo.name, key) < 3
  19076. );
  19077. if (suggestedOptionInfo) {
  19078. messages.push(`Did you mean ${JSON.stringify(suggestedOptionInfo.name)}?`);
  19079. }
  19080. return messages.join(" ");
  19081. }
  19082. function createRedirectOptionMessage(optionInfo, descriptor) {
  19083. return `${descriptor(
  19084. optionInfo.name
  19085. )} is deprecated. Prettier now treats it as ${
  19086. typeof optionInfo.redirect === "string"
  19087. ? descriptor(optionInfo.redirect)
  19088. : descriptor(optionInfo.redirect.option, optionInfo.redirect.value)
  19089. }.`;
  19090. }
  19091. function createRedirectChoiceMessage(optionInfo, choiceInfo, descriptor) {
  19092. return `${descriptor(
  19093. optionInfo.name,
  19094. choiceInfo.value
  19095. )} is deprecated. Prettier now treats it as ${descriptor(
  19096. optionInfo.name,
  19097. choiceInfo.redirect
  19098. )}.`;
  19099. }
  19100. function normalizeApiOptions(options, optionInfos, opts) {
  19101. return normalizeOptions$1(
  19102. options,
  19103. optionInfos,
  19104. Object.assign({ descriptor: optionsDescriptor.apiDescriptor }, opts)
  19105. );
  19106. }
  19107. function normalizeCliOptions(options, optionInfos, opts) {
  19108. const args = options["_"] || [];
  19109. const newOptions = normalizeOptions$1(
  19110. Object.keys(options).reduce(
  19111. (reduced, key) =>
  19112. Object.assign(
  19113. reduced,
  19114. key.length === 1 // omit alias
  19115. ? null
  19116. : { [key]: options[key] }
  19117. ),
  19118. {}
  19119. ),
  19120. optionInfos,
  19121. Object.assign({ descriptor: optionsDescriptor.cliDescriptor }, opts)
  19122. );
  19123. newOptions["_"] = args;
  19124. return newOptions;
  19125. }
  19126. var optionsNormalizer = {
  19127. normalizeApiOptions,
  19128. normalizeCliOptions
  19129. };
  19130. class ConfigError$1 extends Error {}
  19131. class DebugError extends Error {}
  19132. var errors = {
  19133. ConfigError: ConfigError$1,
  19134. DebugError
  19135. };
  19136. var jsTokens = createCommonjsModule(function (module, exports) {
  19137. // Copyright 2014, 2015, 2016, 2017 Simon Lydell
  19138. // License: MIT. (See LICENSE.)
  19139. Object.defineProperty(exports, "__esModule", {
  19140. value: true
  19141. });
  19142. // This regex comes from regex.coffee, and is inserted here by generate-index.js
  19143. // (run `npm run build`).
  19144. 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;
  19145. exports.matchToToken = function(match) {
  19146. var token = {type: "invalid", value: match[0]};
  19147. if (match[ 1]) token.type = "string" , token.closed = !!(match[3] || match[4]);
  19148. else if (match[ 5]) token.type = "comment";
  19149. else if (match[ 6]) token.type = "comment", token.closed = !!match[7];
  19150. else if (match[ 8]) token.type = "regex";
  19151. else if (match[ 9]) token.type = "number";
  19152. else if (match[10]) token.type = "name";
  19153. else if (match[11]) token.type = "punctuator";
  19154. else if (match[12]) token.type = "whitespace";
  19155. return token
  19156. };
  19157. });
  19158. unwrapExports(jsTokens);
  19159. var colorName = {
  19160. "aliceblue": [240, 248, 255],
  19161. "antiquewhite": [250, 235, 215],
  19162. "aqua": [0, 255, 255],
  19163. "aquamarine": [127, 255, 212],
  19164. "azure": [240, 255, 255],
  19165. "beige": [245, 245, 220],
  19166. "bisque": [255, 228, 196],
  19167. "black": [0, 0, 0],
  19168. "blanchedalmond": [255, 235, 205],
  19169. "blue": [0, 0, 255],
  19170. "blueviolet": [138, 43, 226],
  19171. "brown": [165, 42, 42],
  19172. "burlywood": [222, 184, 135],
  19173. "cadetblue": [95, 158, 160],
  19174. "chartreuse": [127, 255, 0],
  19175. "chocolate": [210, 105, 30],
  19176. "coral": [255, 127, 80],
  19177. "cornflowerblue": [100, 149, 237],
  19178. "cornsilk": [255, 248, 220],
  19179. "crimson": [220, 20, 60],
  19180. "cyan": [0, 255, 255],
  19181. "darkblue": [0, 0, 139],
  19182. "darkcyan": [0, 139, 139],
  19183. "darkgoldenrod": [184, 134, 11],
  19184. "darkgray": [169, 169, 169],
  19185. "darkgreen": [0, 100, 0],
  19186. "darkgrey": [169, 169, 169],
  19187. "darkkhaki": [189, 183, 107],
  19188. "darkmagenta": [139, 0, 139],
  19189. "darkolivegreen": [85, 107, 47],
  19190. "darkorange": [255, 140, 0],
  19191. "darkorchid": [153, 50, 204],
  19192. "darkred": [139, 0, 0],
  19193. "darksalmon": [233, 150, 122],
  19194. "darkseagreen": [143, 188, 143],
  19195. "darkslateblue": [72, 61, 139],
  19196. "darkslategray": [47, 79, 79],
  19197. "darkslategrey": [47, 79, 79],
  19198. "darkturquoise": [0, 206, 209],
  19199. "darkviolet": [148, 0, 211],
  19200. "deeppink": [255, 20, 147],
  19201. "deepskyblue": [0, 191, 255],
  19202. "dimgray": [105, 105, 105],
  19203. "dimgrey": [105, 105, 105],
  19204. "dodgerblue": [30, 144, 255],
  19205. "firebrick": [178, 34, 34],
  19206. "floralwhite": [255, 250, 240],
  19207. "forestgreen": [34, 139, 34],
  19208. "fuchsia": [255, 0, 255],
  19209. "gainsboro": [220, 220, 220],
  19210. "ghostwhite": [248, 248, 255],
  19211. "gold": [255, 215, 0],
  19212. "goldenrod": [218, 165, 32],
  19213. "gray": [128, 128, 128],
  19214. "green": [0, 128, 0],
  19215. "greenyellow": [173, 255, 47],
  19216. "grey": [128, 128, 128],
  19217. "honeydew": [240, 255, 240],
  19218. "hotpink": [255, 105, 180],
  19219. "indianred": [205, 92, 92],
  19220. "indigo": [75, 0, 130],
  19221. "ivory": [255, 255, 240],
  19222. "khaki": [240, 230, 140],
  19223. "lavender": [230, 230, 250],
  19224. "lavenderblush": [255, 240, 245],
  19225. "lawngreen": [124, 252, 0],
  19226. "lemonchiffon": [255, 250, 205],
  19227. "lightblue": [173, 216, 230],
  19228. "lightcoral": [240, 128, 128],
  19229. "lightcyan": [224, 255, 255],
  19230. "lightgoldenrodyellow": [250, 250, 210],
  19231. "lightgray": [211, 211, 211],
  19232. "lightgreen": [144, 238, 144],
  19233. "lightgrey": [211, 211, 211],
  19234. "lightpink": [255, 182, 193],
  19235. "lightsalmon": [255, 160, 122],
  19236. "lightseagreen": [32, 178, 170],
  19237. "lightskyblue": [135, 206, 250],
  19238. "lightslategray": [119, 136, 153],
  19239. "lightslategrey": [119, 136, 153],
  19240. "lightsteelblue": [176, 196, 222],
  19241. "lightyellow": [255, 255, 224],
  19242. "lime": [0, 255, 0],
  19243. "limegreen": [50, 205, 50],
  19244. "linen": [250, 240, 230],
  19245. "magenta": [255, 0, 255],
  19246. "maroon": [128, 0, 0],
  19247. "mediumaquamarine": [102, 205, 170],
  19248. "mediumblue": [0, 0, 205],
  19249. "mediumorchid": [186, 85, 211],
  19250. "mediumpurple": [147, 112, 219],
  19251. "mediumseagreen": [60, 179, 113],
  19252. "mediumslateblue": [123, 104, 238],
  19253. "mediumspringgreen": [0, 250, 154],
  19254. "mediumturquoise": [72, 209, 204],
  19255. "mediumvioletred": [199, 21, 133],
  19256. "midnightblue": [25, 25, 112],
  19257. "mintcream": [245, 255, 250],
  19258. "mistyrose": [255, 228, 225],
  19259. "moccasin": [255, 228, 181],
  19260. "navajowhite": [255, 222, 173],
  19261. "navy": [0, 0, 128],
  19262. "oldlace": [253, 245, 230],
  19263. "olive": [128, 128, 0],
  19264. "olivedrab": [107, 142, 35],
  19265. "orange": [255, 165, 0],
  19266. "orangered": [255, 69, 0],
  19267. "orchid": [218, 112, 214],
  19268. "palegoldenrod": [238, 232, 170],
  19269. "palegreen": [152, 251, 152],
  19270. "paleturquoise": [175, 238, 238],
  19271. "palevioletred": [219, 112, 147],
  19272. "papayawhip": [255, 239, 213],
  19273. "peachpuff": [255, 218, 185],
  19274. "peru": [205, 133, 63],
  19275. "pink": [255, 192, 203],
  19276. "plum": [221, 160, 221],
  19277. "powderblue": [176, 224, 230],
  19278. "purple": [128, 0, 128],
  19279. "rebeccapurple": [102, 51, 153],
  19280. "red": [255, 0, 0],
  19281. "rosybrown": [188, 143, 143],
  19282. "royalblue": [65, 105, 225],
  19283. "saddlebrown": [139, 69, 19],
  19284. "salmon": [250, 128, 114],
  19285. "sandybrown": [244, 164, 96],
  19286. "seagreen": [46, 139, 87],
  19287. "seashell": [255, 245, 238],
  19288. "sienna": [160, 82, 45],
  19289. "silver": [192, 192, 192],
  19290. "skyblue": [135, 206, 235],
  19291. "slateblue": [106, 90, 205],
  19292. "slategray": [112, 128, 144],
  19293. "slategrey": [112, 128, 144],
  19294. "snow": [255, 250, 250],
  19295. "springgreen": [0, 255, 127],
  19296. "steelblue": [70, 130, 180],
  19297. "tan": [210, 180, 140],
  19298. "teal": [0, 128, 128],
  19299. "thistle": [216, 191, 216],
  19300. "tomato": [255, 99, 71],
  19301. "turquoise": [64, 224, 208],
  19302. "violet": [238, 130, 238],
  19303. "wheat": [245, 222, 179],
  19304. "white": [255, 255, 255],
  19305. "whitesmoke": [245, 245, 245],
  19306. "yellow": [255, 255, 0],
  19307. "yellowgreen": [154, 205, 50]
  19308. };
  19309. var conversions = createCommonjsModule(function (module) {
  19310. /* MIT license */
  19311. // NOTE: conversions should only return primitive values (i.e. arrays, or
  19312. // values that give correct `typeof` results).
  19313. // do not use box values types (i.e. Number(), String(), etc.)
  19314. var reverseKeywords = {};
  19315. for (var key in colorName) {
  19316. if (colorName.hasOwnProperty(key)) {
  19317. reverseKeywords[colorName[key]] = key;
  19318. }
  19319. }
  19320. var convert = module.exports = {
  19321. rgb: {channels: 3, labels: 'rgb'},
  19322. hsl: {channels: 3, labels: 'hsl'},
  19323. hsv: {channels: 3, labels: 'hsv'},
  19324. hwb: {channels: 3, labels: 'hwb'},
  19325. cmyk: {channels: 4, labels: 'cmyk'},
  19326. xyz: {channels: 3, labels: 'xyz'},
  19327. lab: {channels: 3, labels: 'lab'},
  19328. lch: {channels: 3, labels: 'lch'},
  19329. hex: {channels: 1, labels: ['hex']},
  19330. keyword: {channels: 1, labels: ['keyword']},
  19331. ansi16: {channels: 1, labels: ['ansi16']},
  19332. ansi256: {channels: 1, labels: ['ansi256']},
  19333. hcg: {channels: 3, labels: ['h', 'c', 'g']},
  19334. apple: {channels: 3, labels: ['r16', 'g16', 'b16']},
  19335. gray: {channels: 1, labels: ['gray']}
  19336. };
  19337. // hide .channels and .labels properties
  19338. for (var model in convert) {
  19339. if (convert.hasOwnProperty(model)) {
  19340. if (!('channels' in convert[model])) {
  19341. throw new Error('missing channels property: ' + model);
  19342. }
  19343. if (!('labels' in convert[model])) {
  19344. throw new Error('missing channel labels property: ' + model);
  19345. }
  19346. if (convert[model].labels.length !== convert[model].channels) {
  19347. throw new Error('channel and label counts mismatch: ' + model);
  19348. }
  19349. var channels = convert[model].channels;
  19350. var labels = convert[model].labels;
  19351. delete convert[model].channels;
  19352. delete convert[model].labels;
  19353. Object.defineProperty(convert[model], 'channels', {value: channels});
  19354. Object.defineProperty(convert[model], 'labels', {value: labels});
  19355. }
  19356. }
  19357. convert.rgb.hsl = function (rgb) {
  19358. var r = rgb[0] / 255;
  19359. var g = rgb[1] / 255;
  19360. var b = rgb[2] / 255;
  19361. var min = Math.min(r, g, b);
  19362. var max = Math.max(r, g, b);
  19363. var delta = max - min;
  19364. var h;
  19365. var s;
  19366. var l;
  19367. if (max === min) {
  19368. h = 0;
  19369. } else if (r === max) {
  19370. h = (g - b) / delta;
  19371. } else if (g === max) {
  19372. h = 2 + (b - r) / delta;
  19373. } else if (b === max) {
  19374. h = 4 + (r - g) / delta;
  19375. }
  19376. h = Math.min(h * 60, 360);
  19377. if (h < 0) {
  19378. h += 360;
  19379. }
  19380. l = (min + max) / 2;
  19381. if (max === min) {
  19382. s = 0;
  19383. } else if (l <= 0.5) {
  19384. s = delta / (max + min);
  19385. } else {
  19386. s = delta / (2 - max - min);
  19387. }
  19388. return [h, s * 100, l * 100];
  19389. };
  19390. convert.rgb.hsv = function (rgb) {
  19391. var r = rgb[0];
  19392. var g = rgb[1];
  19393. var b = rgb[2];
  19394. var min = Math.min(r, g, b);
  19395. var max = Math.max(r, g, b);
  19396. var delta = max - min;
  19397. var h;
  19398. var s;
  19399. var v;
  19400. if (max === 0) {
  19401. s = 0;
  19402. } else {
  19403. s = (delta / max * 1000) / 10;
  19404. }
  19405. if (max === min) {
  19406. h = 0;
  19407. } else if (r === max) {
  19408. h = (g - b) / delta;
  19409. } else if (g === max) {
  19410. h = 2 + (b - r) / delta;
  19411. } else if (b === max) {
  19412. h = 4 + (r - g) / delta;
  19413. }
  19414. h = Math.min(h * 60, 360);
  19415. if (h < 0) {
  19416. h += 360;
  19417. }
  19418. v = ((max / 255) * 1000) / 10;
  19419. return [h, s, v];
  19420. };
  19421. convert.rgb.hwb = function (rgb) {
  19422. var r = rgb[0];
  19423. var g = rgb[1];
  19424. var b = rgb[2];
  19425. var h = convert.rgb.hsl(rgb)[0];
  19426. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  19427. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  19428. return [h, w * 100, b * 100];
  19429. };
  19430. convert.rgb.cmyk = function (rgb) {
  19431. var r = rgb[0] / 255;
  19432. var g = rgb[1] / 255;
  19433. var b = rgb[2] / 255;
  19434. var c;
  19435. var m;
  19436. var y;
  19437. var k;
  19438. k = Math.min(1 - r, 1 - g, 1 - b);
  19439. c = (1 - r - k) / (1 - k) || 0;
  19440. m = (1 - g - k) / (1 - k) || 0;
  19441. y = (1 - b - k) / (1 - k) || 0;
  19442. return [c * 100, m * 100, y * 100, k * 100];
  19443. };
  19444. /**
  19445. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  19446. * */
  19447. function comparativeDistance(x, y) {
  19448. return (
  19449. Math.pow(x[0] - y[0], 2) +
  19450. Math.pow(x[1] - y[1], 2) +
  19451. Math.pow(x[2] - y[2], 2)
  19452. );
  19453. }
  19454. convert.rgb.keyword = function (rgb) {
  19455. var reversed = reverseKeywords[rgb];
  19456. if (reversed) {
  19457. return reversed;
  19458. }
  19459. var currentClosestDistance = Infinity;
  19460. var currentClosestKeyword;
  19461. for (var keyword in colorName) {
  19462. if (colorName.hasOwnProperty(keyword)) {
  19463. var value = colorName[keyword];
  19464. // Compute comparative distance
  19465. var distance = comparativeDistance(rgb, value);
  19466. // Check if its less, if so set as closest
  19467. if (distance < currentClosestDistance) {
  19468. currentClosestDistance = distance;
  19469. currentClosestKeyword = keyword;
  19470. }
  19471. }
  19472. }
  19473. return currentClosestKeyword;
  19474. };
  19475. convert.keyword.rgb = function (keyword) {
  19476. return colorName[keyword];
  19477. };
  19478. convert.rgb.xyz = function (rgb) {
  19479. var r = rgb[0] / 255;
  19480. var g = rgb[1] / 255;
  19481. var b = rgb[2] / 255;
  19482. // assume sRGB
  19483. r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
  19484. g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
  19485. b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
  19486. var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
  19487. var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
  19488. var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
  19489. return [x * 100, y * 100, z * 100];
  19490. };
  19491. convert.rgb.lab = function (rgb) {
  19492. var xyz = convert.rgb.xyz(rgb);
  19493. var x = xyz[0];
  19494. var y = xyz[1];
  19495. var z = xyz[2];
  19496. var l;
  19497. var a;
  19498. var b;
  19499. x /= 95.047;
  19500. y /= 100;
  19501. z /= 108.883;
  19502. x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116);
  19503. y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116);
  19504. z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116);
  19505. l = (116 * y) - 16;
  19506. a = 500 * (x - y);
  19507. b = 200 * (y - z);
  19508. return [l, a, b];
  19509. };
  19510. convert.hsl.rgb = function (hsl) {
  19511. var h = hsl[0] / 360;
  19512. var s = hsl[1] / 100;
  19513. var l = hsl[2] / 100;
  19514. var t1;
  19515. var t2;
  19516. var t3;
  19517. var rgb;
  19518. var val;
  19519. if (s === 0) {
  19520. val = l * 255;
  19521. return [val, val, val];
  19522. }
  19523. if (l < 0.5) {
  19524. t2 = l * (1 + s);
  19525. } else {
  19526. t2 = l + s - l * s;
  19527. }
  19528. t1 = 2 * l - t2;
  19529. rgb = [0, 0, 0];
  19530. for (var i = 0; i < 3; i++) {
  19531. t3 = h + 1 / 3 * -(i - 1);
  19532. if (t3 < 0) {
  19533. t3++;
  19534. }
  19535. if (t3 > 1) {
  19536. t3--;
  19537. }
  19538. if (6 * t3 < 1) {
  19539. val = t1 + (t2 - t1) * 6 * t3;
  19540. } else if (2 * t3 < 1) {
  19541. val = t2;
  19542. } else if (3 * t3 < 2) {
  19543. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  19544. } else {
  19545. val = t1;
  19546. }
  19547. rgb[i] = val * 255;
  19548. }
  19549. return rgb;
  19550. };
  19551. convert.hsl.hsv = function (hsl) {
  19552. var h = hsl[0];
  19553. var s = hsl[1] / 100;
  19554. var l = hsl[2] / 100;
  19555. var smin = s;
  19556. var lmin = Math.max(l, 0.01);
  19557. var sv;
  19558. var v;
  19559. l *= 2;
  19560. s *= (l <= 1) ? l : 2 - l;
  19561. smin *= lmin <= 1 ? lmin : 2 - lmin;
  19562. v = (l + s) / 2;
  19563. sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s);
  19564. return [h, sv * 100, v * 100];
  19565. };
  19566. convert.hsv.rgb = function (hsv) {
  19567. var h = hsv[0] / 60;
  19568. var s = hsv[1] / 100;
  19569. var v = hsv[2] / 100;
  19570. var hi = Math.floor(h) % 6;
  19571. var f = h - Math.floor(h);
  19572. var p = 255 * v * (1 - s);
  19573. var q = 255 * v * (1 - (s * f));
  19574. var t = 255 * v * (1 - (s * (1 - f)));
  19575. v *= 255;
  19576. switch (hi) {
  19577. case 0:
  19578. return [v, t, p];
  19579. case 1:
  19580. return [q, v, p];
  19581. case 2:
  19582. return [p, v, t];
  19583. case 3:
  19584. return [p, q, v];
  19585. case 4:
  19586. return [t, p, v];
  19587. case 5:
  19588. return [v, p, q];
  19589. }
  19590. };
  19591. convert.hsv.hsl = function (hsv) {
  19592. var h = hsv[0];
  19593. var s = hsv[1] / 100;
  19594. var v = hsv[2] / 100;
  19595. var vmin = Math.max(v, 0.01);
  19596. var lmin;
  19597. var sl;
  19598. var l;
  19599. l = (2 - s) * v;
  19600. lmin = (2 - s) * vmin;
  19601. sl = s * vmin;
  19602. sl /= (lmin <= 1) ? lmin : 2 - lmin;
  19603. sl = sl || 0;
  19604. l /= 2;
  19605. return [h, sl * 100, l * 100];
  19606. };
  19607. // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  19608. convert.hwb.rgb = function (hwb) {
  19609. var h = hwb[0] / 360;
  19610. var wh = hwb[1] / 100;
  19611. var bl = hwb[2] / 100;
  19612. var ratio = wh + bl;
  19613. var i;
  19614. var v;
  19615. var f;
  19616. var n;
  19617. // wh + bl cant be > 1
  19618. if (ratio > 1) {
  19619. wh /= ratio;
  19620. bl /= ratio;
  19621. }
  19622. i = Math.floor(6 * h);
  19623. v = 1 - bl;
  19624. f = 6 * h - i;
  19625. if ((i & 0x01) !== 0) {
  19626. f = 1 - f;
  19627. }
  19628. n = wh + f * (v - wh); // linear interpolation
  19629. var r;
  19630. var g;
  19631. var b;
  19632. switch (i) {
  19633. default:
  19634. case 6:
  19635. case 0: r = v; g = n; b = wh; break;
  19636. case 1: r = n; g = v; b = wh; break;
  19637. case 2: r = wh; g = v; b = n; break;
  19638. case 3: r = wh; g = n; b = v; break;
  19639. case 4: r = n; g = wh; b = v; break;
  19640. case 5: r = v; g = wh; b = n; break;
  19641. }
  19642. return [r * 255, g * 255, b * 255];
  19643. };
  19644. convert.cmyk.rgb = function (cmyk) {
  19645. var c = cmyk[0] / 100;
  19646. var m = cmyk[1] / 100;
  19647. var y = cmyk[2] / 100;
  19648. var k = cmyk[3] / 100;
  19649. var r;
  19650. var g;
  19651. var b;
  19652. r = 1 - Math.min(1, c * (1 - k) + k);
  19653. g = 1 - Math.min(1, m * (1 - k) + k);
  19654. b = 1 - Math.min(1, y * (1 - k) + k);
  19655. return [r * 255, g * 255, b * 255];
  19656. };
  19657. convert.xyz.rgb = function (xyz) {
  19658. var x = xyz[0] / 100;
  19659. var y = xyz[1] / 100;
  19660. var z = xyz[2] / 100;
  19661. var r;
  19662. var g;
  19663. var b;
  19664. r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
  19665. g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
  19666. b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
  19667. // assume sRGB
  19668. r = r > 0.0031308
  19669. ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
  19670. : r * 12.92;
  19671. g = g > 0.0031308
  19672. ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
  19673. : g * 12.92;
  19674. b = b > 0.0031308
  19675. ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
  19676. : b * 12.92;
  19677. r = Math.min(Math.max(0, r), 1);
  19678. g = Math.min(Math.max(0, g), 1);
  19679. b = Math.min(Math.max(0, b), 1);
  19680. return [r * 255, g * 255, b * 255];
  19681. };
  19682. convert.xyz.lab = function (xyz) {
  19683. var x = xyz[0];
  19684. var y = xyz[1];
  19685. var z = xyz[2];
  19686. var l;
  19687. var a;
  19688. var b;
  19689. x /= 95.047;
  19690. y /= 100;
  19691. z /= 108.883;
  19692. x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116);
  19693. y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116);
  19694. z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116);
  19695. l = (116 * y) - 16;
  19696. a = 500 * (x - y);
  19697. b = 200 * (y - z);
  19698. return [l, a, b];
  19699. };
  19700. convert.lab.xyz = function (lab) {
  19701. var l = lab[0];
  19702. var a = lab[1];
  19703. var b = lab[2];
  19704. var x;
  19705. var y;
  19706. var z;
  19707. y = (l + 16) / 116;
  19708. x = a / 500 + y;
  19709. z = y - b / 200;
  19710. var y2 = Math.pow(y, 3);
  19711. var x2 = Math.pow(x, 3);
  19712. var z2 = Math.pow(z, 3);
  19713. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  19714. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  19715. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  19716. x *= 95.047;
  19717. y *= 100;
  19718. z *= 108.883;
  19719. return [x, y, z];
  19720. };
  19721. convert.lab.lch = function (lab) {
  19722. var l = lab[0];
  19723. var a = lab[1];
  19724. var b = lab[2];
  19725. var hr;
  19726. var h;
  19727. var c;
  19728. hr = Math.atan2(b, a);
  19729. h = hr * 360 / 2 / Math.PI;
  19730. if (h < 0) {
  19731. h += 360;
  19732. }
  19733. c = Math.sqrt(a * a + b * b);
  19734. return [l, c, h];
  19735. };
  19736. convert.lch.lab = function (lch) {
  19737. var l = lch[0];
  19738. var c = lch[1];
  19739. var h = lch[2];
  19740. var a;
  19741. var b;
  19742. var hr;
  19743. hr = h / 360 * 2 * Math.PI;
  19744. a = c * Math.cos(hr);
  19745. b = c * Math.sin(hr);
  19746. return [l, a, b];
  19747. };
  19748. convert.rgb.ansi16 = function (args) {
  19749. var r = args[0];
  19750. var g = args[1];
  19751. var b = args[2];
  19752. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  19753. value = Math.round(value / 50);
  19754. if (value === 0) {
  19755. return 30;
  19756. }
  19757. var ansi = 30
  19758. + ((Math.round(b / 255) << 2)
  19759. | (Math.round(g / 255) << 1)
  19760. | Math.round(r / 255));
  19761. if (value === 2) {
  19762. ansi += 60;
  19763. }
  19764. return ansi;
  19765. };
  19766. convert.hsv.ansi16 = function (args) {
  19767. // optimization here; we already know the value and don't need to get
  19768. // it converted for us.
  19769. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  19770. };
  19771. convert.rgb.ansi256 = function (args) {
  19772. var r = args[0];
  19773. var g = args[1];
  19774. var b = args[2];
  19775. // we use the extended greyscale palette here, with the exception of
  19776. // black and white. normal palette only has 4 greyscale shades.
  19777. if (r === g && g === b) {
  19778. if (r < 8) {
  19779. return 16;
  19780. }
  19781. if (r > 248) {
  19782. return 231;
  19783. }
  19784. return Math.round(((r - 8) / 247) * 24) + 232;
  19785. }
  19786. var ansi = 16
  19787. + (36 * Math.round(r / 255 * 5))
  19788. + (6 * Math.round(g / 255 * 5))
  19789. + Math.round(b / 255 * 5);
  19790. return ansi;
  19791. };
  19792. convert.ansi16.rgb = function (args) {
  19793. var color = args % 10;
  19794. // handle greyscale
  19795. if (color === 0 || color === 7) {
  19796. if (args > 50) {
  19797. color += 3.5;
  19798. }
  19799. color = color / 10.5 * 255;
  19800. return [color, color, color];
  19801. }
  19802. var mult = (~~(args > 50) + 1) * 0.5;
  19803. var r = ((color & 1) * mult) * 255;
  19804. var g = (((color >> 1) & 1) * mult) * 255;
  19805. var b = (((color >> 2) & 1) * mult) * 255;
  19806. return [r, g, b];
  19807. };
  19808. convert.ansi256.rgb = function (args) {
  19809. // handle greyscale
  19810. if (args >= 232) {
  19811. var c = (args - 232) * 10 + 8;
  19812. return [c, c, c];
  19813. }
  19814. args -= 16;
  19815. var rem;
  19816. var r = Math.floor(args / 36) / 5 * 255;
  19817. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  19818. var b = (rem % 6) / 5 * 255;
  19819. return [r, g, b];
  19820. };
  19821. convert.rgb.hex = function (args) {
  19822. var integer = ((Math.round(args[0]) & 0xFF) << 16)
  19823. + ((Math.round(args[1]) & 0xFF) << 8)
  19824. + (Math.round(args[2]) & 0xFF);
  19825. var string = integer.toString(16).toUpperCase();
  19826. return '000000'.substring(string.length) + string;
  19827. };
  19828. convert.hex.rgb = function (args) {
  19829. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  19830. if (!match) {
  19831. return [0, 0, 0];
  19832. }
  19833. var colorString = match[0];
  19834. if (match[0].length === 3) {
  19835. colorString = colorString.split('').map(function (char) {
  19836. return char + char;
  19837. }).join('');
  19838. }
  19839. var integer = parseInt(colorString, 16);
  19840. var r = (integer >> 16) & 0xFF;
  19841. var g = (integer >> 8) & 0xFF;
  19842. var b = integer & 0xFF;
  19843. return [r, g, b];
  19844. };
  19845. convert.rgb.hcg = function (rgb) {
  19846. var r = rgb[0] / 255;
  19847. var g = rgb[1] / 255;
  19848. var b = rgb[2] / 255;
  19849. var max = Math.max(Math.max(r, g), b);
  19850. var min = Math.min(Math.min(r, g), b);
  19851. var chroma = (max - min);
  19852. var grayscale;
  19853. var hue;
  19854. if (chroma < 1) {
  19855. grayscale = min / (1 - chroma);
  19856. } else {
  19857. grayscale = 0;
  19858. }
  19859. if (chroma <= 0) {
  19860. hue = 0;
  19861. } else
  19862. if (max === r) {
  19863. hue = ((g - b) / chroma) % 6;
  19864. } else
  19865. if (max === g) {
  19866. hue = 2 + (b - r) / chroma;
  19867. } else {
  19868. hue = 4 + (r - g) / chroma + 4;
  19869. }
  19870. hue /= 6;
  19871. hue %= 1;
  19872. return [hue * 360, chroma * 100, grayscale * 100];
  19873. };
  19874. convert.hsl.hcg = function (hsl) {
  19875. var s = hsl[1] / 100;
  19876. var l = hsl[2] / 100;
  19877. var c = 1;
  19878. var f = 0;
  19879. if (l < 0.5) {
  19880. c = 2.0 * s * l;
  19881. } else {
  19882. c = 2.0 * s * (1.0 - l);
  19883. }
  19884. if (c < 1.0) {
  19885. f = (l - 0.5 * c) / (1.0 - c);
  19886. }
  19887. return [hsl[0], c * 100, f * 100];
  19888. };
  19889. convert.hsv.hcg = function (hsv) {
  19890. var s = hsv[1] / 100;
  19891. var v = hsv[2] / 100;
  19892. var c = s * v;
  19893. var f = 0;
  19894. if (c < 1.0) {
  19895. f = (v - c) / (1 - c);
  19896. }
  19897. return [hsv[0], c * 100, f * 100];
  19898. };
  19899. convert.hcg.rgb = function (hcg) {
  19900. var h = hcg[0] / 360;
  19901. var c = hcg[1] / 100;
  19902. var g = hcg[2] / 100;
  19903. if (c === 0.0) {
  19904. return [g * 255, g * 255, g * 255];
  19905. }
  19906. var pure = [0, 0, 0];
  19907. var hi = (h % 1) * 6;
  19908. var v = hi % 1;
  19909. var w = 1 - v;
  19910. var mg = 0;
  19911. switch (Math.floor(hi)) {
  19912. case 0:
  19913. pure[0] = 1; pure[1] = v; pure[2] = 0; break;
  19914. case 1:
  19915. pure[0] = w; pure[1] = 1; pure[2] = 0; break;
  19916. case 2:
  19917. pure[0] = 0; pure[1] = 1; pure[2] = v; break;
  19918. case 3:
  19919. pure[0] = 0; pure[1] = w; pure[2] = 1; break;
  19920. case 4:
  19921. pure[0] = v; pure[1] = 0; pure[2] = 1; break;
  19922. default:
  19923. pure[0] = 1; pure[1] = 0; pure[2] = w;
  19924. }
  19925. mg = (1.0 - c) * g;
  19926. return [
  19927. (c * pure[0] + mg) * 255,
  19928. (c * pure[1] + mg) * 255,
  19929. (c * pure[2] + mg) * 255
  19930. ];
  19931. };
  19932. convert.hcg.hsv = function (hcg) {
  19933. var c = hcg[1] / 100;
  19934. var g = hcg[2] / 100;
  19935. var v = c + g * (1.0 - c);
  19936. var f = 0;
  19937. if (v > 0.0) {
  19938. f = c / v;
  19939. }
  19940. return [hcg[0], f * 100, v * 100];
  19941. };
  19942. convert.hcg.hsl = function (hcg) {
  19943. var c = hcg[1] / 100;
  19944. var g = hcg[2] / 100;
  19945. var l = g * (1.0 - c) + 0.5 * c;
  19946. var s = 0;
  19947. if (l > 0.0 && l < 0.5) {
  19948. s = c / (2 * l);
  19949. } else
  19950. if (l >= 0.5 && l < 1.0) {
  19951. s = c / (2 * (1 - l));
  19952. }
  19953. return [hcg[0], s * 100, l * 100];
  19954. };
  19955. convert.hcg.hwb = function (hcg) {
  19956. var c = hcg[1] / 100;
  19957. var g = hcg[2] / 100;
  19958. var v = c + g * (1.0 - c);
  19959. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  19960. };
  19961. convert.hwb.hcg = function (hwb) {
  19962. var w = hwb[1] / 100;
  19963. var b = hwb[2] / 100;
  19964. var v = 1 - b;
  19965. var c = v - w;
  19966. var g = 0;
  19967. if (c < 1) {
  19968. g = (v - c) / (1 - c);
  19969. }
  19970. return [hwb[0], c * 100, g * 100];
  19971. };
  19972. convert.apple.rgb = function (apple) {
  19973. return [(apple[0] / 65535) * 255, (apple[1] / 65535) * 255, (apple[2] / 65535) * 255];
  19974. };
  19975. convert.rgb.apple = function (rgb) {
  19976. return [(rgb[0] / 255) * 65535, (rgb[1] / 255) * 65535, (rgb[2] / 255) * 65535];
  19977. };
  19978. convert.gray.rgb = function (args) {
  19979. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  19980. };
  19981. convert.gray.hsl = convert.gray.hsv = function (args) {
  19982. return [0, 0, args[0]];
  19983. };
  19984. convert.gray.hwb = function (gray) {
  19985. return [0, 100, gray[0]];
  19986. };
  19987. convert.gray.cmyk = function (gray) {
  19988. return [0, 0, 0, gray[0]];
  19989. };
  19990. convert.gray.lab = function (gray) {
  19991. return [gray[0], 0, 0];
  19992. };
  19993. convert.gray.hex = function (gray) {
  19994. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  19995. var integer = (val << 16) + (val << 8) + val;
  19996. var string = integer.toString(16).toUpperCase();
  19997. return '000000'.substring(string.length) + string;
  19998. };
  19999. convert.rgb.gray = function (rgb) {
  20000. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  20001. return [val / 255 * 100];
  20002. };
  20003. });
  20004. /*
  20005. this function routes a model to all other models.
  20006. all functions that are routed have a property `.conversion` attached
  20007. to the returned synthetic function. This property is an array
  20008. of strings, each with the steps in between the 'from' and 'to'
  20009. color models (inclusive).
  20010. conversions that are not possible simply are not included.
  20011. */
  20012. // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  20013. var models$1 = Object.keys(conversions);
  20014. function buildGraph() {
  20015. var graph = {};
  20016. for (var len = models$1.length, i = 0; i < len; i++) {
  20017. graph[models$1[i]] = {
  20018. // http://jsperf.com/1-vs-infinity
  20019. // micro-opt, but this is simple.
  20020. distance: -1,
  20021. parent: null
  20022. };
  20023. }
  20024. return graph;
  20025. }
  20026. // https://en.wikipedia.org/wiki/Breadth-first_search
  20027. function deriveBFS(fromModel) {
  20028. var graph = buildGraph();
  20029. var queue = [fromModel]; // unshift -> queue -> pop
  20030. graph[fromModel].distance = 0;
  20031. while (queue.length) {
  20032. var current = queue.pop();
  20033. var adjacents = Object.keys(conversions[current]);
  20034. for (var len = adjacents.length, i = 0; i < len; i++) {
  20035. var adjacent = adjacents[i];
  20036. var node = graph[adjacent];
  20037. if (node.distance === -1) {
  20038. node.distance = graph[current].distance + 1;
  20039. node.parent = current;
  20040. queue.unshift(adjacent);
  20041. }
  20042. }
  20043. }
  20044. return graph;
  20045. }
  20046. function link(from, to) {
  20047. return function (args) {
  20048. return to(from(args));
  20049. };
  20050. }
  20051. function wrapConversion(toModel, graph) {
  20052. var path$$1 = [graph[toModel].parent, toModel];
  20053. var fn = conversions[graph[toModel].parent][toModel];
  20054. var cur = graph[toModel].parent;
  20055. while (graph[cur].parent) {
  20056. path$$1.unshift(graph[cur].parent);
  20057. fn = link(conversions[graph[cur].parent][cur], fn);
  20058. cur = graph[cur].parent;
  20059. }
  20060. fn.conversion = path$$1;
  20061. return fn;
  20062. }
  20063. var route = function (fromModel) {
  20064. var graph = deriveBFS(fromModel);
  20065. var conversion = {};
  20066. var models = Object.keys(graph);
  20067. for (var len = models.length, i = 0; i < len; i++) {
  20068. var toModel = models[i];
  20069. var node = graph[toModel];
  20070. if (node.parent === null) {
  20071. // no possible conversion, or this node is the source model.
  20072. continue;
  20073. }
  20074. conversion[toModel] = wrapConversion(toModel, graph);
  20075. }
  20076. return conversion;
  20077. };
  20078. var convert = {};
  20079. var models = Object.keys(conversions);
  20080. function wrapRaw(fn) {
  20081. var wrappedFn = function (args) {
  20082. if (args === undefined || args === null) {
  20083. return args;
  20084. }
  20085. if (arguments.length > 1) {
  20086. args = Array.prototype.slice.call(arguments);
  20087. }
  20088. return fn(args);
  20089. };
  20090. // preserve .conversion property if there is one
  20091. if ('conversion' in fn) {
  20092. wrappedFn.conversion = fn.conversion;
  20093. }
  20094. return wrappedFn;
  20095. }
  20096. function wrapRounded(fn) {
  20097. var wrappedFn = function (args) {
  20098. if (args === undefined || args === null) {
  20099. return args;
  20100. }
  20101. if (arguments.length > 1) {
  20102. args = Array.prototype.slice.call(arguments);
  20103. }
  20104. var result = fn(args);
  20105. // we're assuming the result is an array here.
  20106. // see notice in conversions.js; don't use box types
  20107. // in conversion functions.
  20108. if (typeof result === 'object') {
  20109. for (var len = result.length, i = 0; i < len; i++) {
  20110. result[i] = Math.round(result[i]);
  20111. }
  20112. }
  20113. return result;
  20114. };
  20115. // preserve .conversion property if there is one
  20116. if ('conversion' in fn) {
  20117. wrappedFn.conversion = fn.conversion;
  20118. }
  20119. return wrappedFn;
  20120. }
  20121. models.forEach(function (fromModel) {
  20122. convert[fromModel] = {};
  20123. Object.defineProperty(convert[fromModel], 'channels', {value: conversions[fromModel].channels});
  20124. Object.defineProperty(convert[fromModel], 'labels', {value: conversions[fromModel].labels});
  20125. var routes = route(fromModel);
  20126. var routeModels = Object.keys(routes);
  20127. routeModels.forEach(function (toModel) {
  20128. var fn = routes[toModel];
  20129. convert[fromModel][toModel] = wrapRounded(fn);
  20130. convert[fromModel][toModel].raw = wrapRaw(fn);
  20131. });
  20132. });
  20133. var colorConvert = convert;
  20134. var ansiStyles = createCommonjsModule(function (module) {
  20135. 'use strict';
  20136. const wrapAnsi16 = (fn, offset) => function () {
  20137. const code = fn.apply(colorConvert, arguments);
  20138. return `\u001B[${code + offset}m`;
  20139. };
  20140. const wrapAnsi256 = (fn, offset) => function () {
  20141. const code = fn.apply(colorConvert, arguments);
  20142. return `\u001B[${38 + offset};5;${code}m`;
  20143. };
  20144. const wrapAnsi16m = (fn, offset) => function () {
  20145. const rgb = fn.apply(colorConvert, arguments);
  20146. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  20147. };
  20148. function assembleStyles() {
  20149. const styles = {
  20150. modifier: {
  20151. reset: [0, 0],
  20152. // 21 isn't widely supported and 22 does the same thing
  20153. bold: [1, 22],
  20154. dim: [2, 22],
  20155. italic: [3, 23],
  20156. underline: [4, 24],
  20157. inverse: [7, 27],
  20158. hidden: [8, 28],
  20159. strikethrough: [9, 29]
  20160. },
  20161. color: {
  20162. black: [30, 39],
  20163. red: [31, 39],
  20164. green: [32, 39],
  20165. yellow: [33, 39],
  20166. blue: [34, 39],
  20167. magenta: [35, 39],
  20168. cyan: [36, 39],
  20169. white: [37, 39],
  20170. gray: [90, 39],
  20171. // Bright color
  20172. redBright: [91, 39],
  20173. greenBright: [92, 39],
  20174. yellowBright: [93, 39],
  20175. blueBright: [94, 39],
  20176. magentaBright: [95, 39],
  20177. cyanBright: [96, 39],
  20178. whiteBright: [97, 39]
  20179. },
  20180. bgColor: {
  20181. bgBlack: [40, 49],
  20182. bgRed: [41, 49],
  20183. bgGreen: [42, 49],
  20184. bgYellow: [43, 49],
  20185. bgBlue: [44, 49],
  20186. bgMagenta: [45, 49],
  20187. bgCyan: [46, 49],
  20188. bgWhite: [47, 49],
  20189. // Bright color
  20190. bgBlackBright: [100, 49],
  20191. bgRedBright: [101, 49],
  20192. bgGreenBright: [102, 49],
  20193. bgYellowBright: [103, 49],
  20194. bgBlueBright: [104, 49],
  20195. bgMagentaBright: [105, 49],
  20196. bgCyanBright: [106, 49],
  20197. bgWhiteBright: [107, 49]
  20198. }
  20199. };
  20200. // Fix humans
  20201. styles.color.grey = styles.color.gray;
  20202. Object.keys(styles).forEach(groupName => {
  20203. const group = styles[groupName];
  20204. Object.keys(group).forEach(styleName => {
  20205. const style = group[styleName];
  20206. styles[styleName] = {
  20207. open: `\u001B[${style[0]}m`,
  20208. close: `\u001B[${style[1]}m`
  20209. };
  20210. group[styleName] = styles[styleName];
  20211. });
  20212. Object.defineProperty(styles, groupName, {
  20213. value: group,
  20214. enumerable: false
  20215. });
  20216. });
  20217. const rgb2rgb = (r, g, b) => [r, g, b];
  20218. styles.color.close = '\u001B[39m';
  20219. styles.bgColor.close = '\u001B[49m';
  20220. styles.color.ansi = {};
  20221. styles.color.ansi256 = {};
  20222. styles.color.ansi16m = {
  20223. rgb: wrapAnsi16m(rgb2rgb, 0)
  20224. };
  20225. styles.bgColor.ansi = {};
  20226. styles.bgColor.ansi256 = {};
  20227. styles.bgColor.ansi16m = {
  20228. rgb: wrapAnsi16m(rgb2rgb, 10)
  20229. };
  20230. for (const key of Object.keys(colorConvert)) {
  20231. if (typeof colorConvert[key] !== 'object') {
  20232. continue;
  20233. }
  20234. const suite = colorConvert[key];
  20235. if ('ansi16' in suite) {
  20236. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  20237. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  20238. }
  20239. if ('ansi256' in suite) {
  20240. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  20241. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  20242. }
  20243. if ('rgb' in suite) {
  20244. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  20245. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  20246. }
  20247. }
  20248. return styles;
  20249. }
  20250. Object.defineProperty(module, 'exports', {
  20251. enumerable: true,
  20252. get: assembleStyles
  20253. });
  20254. });
  20255. var hasFlag = function (flag, argv) {
  20256. argv = argv || process.argv;
  20257. var terminatorPos = argv.indexOf('--');
  20258. var prefix = /^-{1,2}/.test(flag) ? '' : '--';
  20259. var pos = argv.indexOf(prefix + flag);
  20260. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  20261. };
  20262. var supportsColor = createCommonjsModule(function (module) {
  20263. 'use strict';
  20264. const env = process.env;
  20265. const support = level => {
  20266. if (level === 0) {
  20267. return false;
  20268. }
  20269. return {
  20270. level,
  20271. hasBasic: true,
  20272. has256: level >= 2,
  20273. has16m: level >= 3
  20274. };
  20275. };
  20276. let supportLevel = (() => {
  20277. if (hasFlag('no-color') ||
  20278. hasFlag('no-colors') ||
  20279. hasFlag('color=false')) {
  20280. return 0;
  20281. }
  20282. if (hasFlag('color=16m') ||
  20283. hasFlag('color=full') ||
  20284. hasFlag('color=truecolor')) {
  20285. return 3;
  20286. }
  20287. if (hasFlag('color=256')) {
  20288. return 2;
  20289. }
  20290. if (hasFlag('color') ||
  20291. hasFlag('colors') ||
  20292. hasFlag('color=true') ||
  20293. hasFlag('color=always')) {
  20294. return 1;
  20295. }
  20296. if (process.stdout && !process.stdout.isTTY) {
  20297. return 0;
  20298. }
  20299. if (process.platform === 'win32') {
  20300. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  20301. // libuv that enables 256 color output on Windows. Anything earlier and it
  20302. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  20303. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  20304. // release that supports 256 colors.
  20305. const osRelease = os.release().split('.');
  20306. if (
  20307. Number(process.version.split('.')[0]) >= 8 &&
  20308. Number(osRelease[0]) >= 10 &&
  20309. Number(osRelease[2]) >= 10586
  20310. ) {
  20311. return 2;
  20312. }
  20313. return 1;
  20314. }
  20315. if ('CI' in env) {
  20316. if ('TRAVIS' in env || env.CI === 'Travis' || 'CIRCLECI' in env) {
  20317. return 1;
  20318. }
  20319. return 0;
  20320. }
  20321. if ('TEAMCITY_VERSION' in env) {
  20322. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  20323. }
  20324. if ('TERM_PROGRAM' in env) {
  20325. const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  20326. switch (env.TERM_PROGRAM) {
  20327. case 'iTerm.app':
  20328. return version >= 3 ? 3 : 2;
  20329. case 'Hyper':
  20330. return 3;
  20331. case 'Apple_Terminal':
  20332. return 2;
  20333. // No default
  20334. }
  20335. }
  20336. if (/^(screen|xterm)-256(?:color)?/.test(env.TERM)) {
  20337. return 2;
  20338. }
  20339. if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) {
  20340. return 1;
  20341. }
  20342. if ('COLORTERM' in env) {
  20343. return 1;
  20344. }
  20345. if (env.TERM === 'dumb') {
  20346. return 0;
  20347. }
  20348. return 0;
  20349. })();
  20350. if ('FORCE_COLOR' in env) {
  20351. supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : (supportLevel || 1);
  20352. }
  20353. module.exports = process && support(supportLevel);
  20354. });
  20355. var templates = createCommonjsModule(function (module) {
  20356. 'use strict';
  20357. const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  20358. const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  20359. const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  20360. const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  20361. const ESCAPES = new Map([
  20362. ['n', '\n'],
  20363. ['r', '\r'],
  20364. ['t', '\t'],
  20365. ['b', '\b'],
  20366. ['f', '\f'],
  20367. ['v', '\v'],
  20368. ['0', '\0'],
  20369. ['\\', '\\'],
  20370. ['e', '\u001B'],
  20371. ['a', '\u0007']
  20372. ]);
  20373. function unescape(c) {
  20374. if ((c[0] === 'u' && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
  20375. return String.fromCharCode(parseInt(c.slice(1), 16));
  20376. }
  20377. return ESCAPES.get(c) || c;
  20378. }
  20379. function parseArguments(name, args) {
  20380. const results = [];
  20381. const chunks = args.trim().split(/\s*,\s*/g);
  20382. let matches;
  20383. for (const chunk of chunks) {
  20384. if (!isNaN(chunk)) {
  20385. results.push(Number(chunk));
  20386. } else if ((matches = chunk.match(STRING_REGEX))) {
  20387. results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr));
  20388. } else {
  20389. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  20390. }
  20391. }
  20392. return results;
  20393. }
  20394. function parseStyle(style) {
  20395. STYLE_REGEX.lastIndex = 0;
  20396. const results = [];
  20397. let matches;
  20398. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  20399. const name = matches[1];
  20400. if (matches[2]) {
  20401. const args = parseArguments(name, matches[2]);
  20402. results.push([name].concat(args));
  20403. } else {
  20404. results.push([name]);
  20405. }
  20406. }
  20407. return results;
  20408. }
  20409. function buildStyle(chalk, styles) {
  20410. const enabled = {};
  20411. for (const layer of styles) {
  20412. for (const style of layer.styles) {
  20413. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  20414. }
  20415. }
  20416. let current = chalk;
  20417. for (const styleName of Object.keys(enabled)) {
  20418. if (Array.isArray(enabled[styleName])) {
  20419. if (!(styleName in current)) {
  20420. throw new Error(`Unknown Chalk style: ${styleName}`);
  20421. }
  20422. if (enabled[styleName].length > 0) {
  20423. current = current[styleName].apply(current, enabled[styleName]);
  20424. } else {
  20425. current = current[styleName];
  20426. }
  20427. }
  20428. }
  20429. return current;
  20430. }
  20431. module.exports = (chalk, tmp) => {
  20432. const styles = [];
  20433. const chunks = [];
  20434. let chunk = [];
  20435. // eslint-disable-next-line max-params
  20436. tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => {
  20437. if (escapeChar) {
  20438. chunk.push(unescape(escapeChar));
  20439. } else if (style) {
  20440. const str = chunk.join('');
  20441. chunk = [];
  20442. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  20443. styles.push({inverse, styles: parseStyle(style)});
  20444. } else if (close) {
  20445. if (styles.length === 0) {
  20446. throw new Error('Found extraneous } in Chalk template literal');
  20447. }
  20448. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  20449. chunk = [];
  20450. styles.pop();
  20451. } else {
  20452. chunk.push(chr);
  20453. }
  20454. });
  20455. chunks.push(chunk.join(''));
  20456. if (styles.length > 0) {
  20457. const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  20458. throw new Error(errMsg);
  20459. }
  20460. return chunks.join('');
  20461. };
  20462. });
  20463. var chalk = createCommonjsModule(function (module) {
  20464. 'use strict';
  20465. const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
  20466. // `supportsColor.level` → `ansiStyles.color[name]` mapping
  20467. const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
  20468. // `color-convert` models to exclude from the Chalk API due to conflicts and such
  20469. const skipModels = new Set(['gray']);
  20470. const styles = Object.create(null);
  20471. function applyOptions(obj, options) {
  20472. options = options || {};
  20473. // Detect level if not set manually
  20474. const scLevel = supportsColor ? supportsColor.level : 0;
  20475. obj.level = options.level === undefined ? scLevel : options.level;
  20476. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  20477. }
  20478. function Chalk(options) {
  20479. // We check for this.template here since calling `chalk.constructor()`
  20480. // by itself will have a `this` of a previously constructed chalk object
  20481. if (!this || !(this instanceof Chalk) || this.template) {
  20482. const chalk = {};
  20483. applyOptions(chalk, options);
  20484. chalk.template = function () {
  20485. const args = [].slice.call(arguments);
  20486. return chalkTag.apply(null, [chalk.template].concat(args));
  20487. };
  20488. Object.setPrototypeOf(chalk, Chalk.prototype);
  20489. Object.setPrototypeOf(chalk.template, chalk);
  20490. chalk.template.constructor = Chalk;
  20491. return chalk.template;
  20492. }
  20493. applyOptions(this, options);
  20494. }
  20495. // Use bright blue on Windows as the normal blue color is illegible
  20496. if (isSimpleWindowsTerm) {
  20497. ansiStyles.blue.open = '\u001B[94m';
  20498. }
  20499. for (const key of Object.keys(ansiStyles)) {
  20500. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  20501. styles[key] = {
  20502. get() {
  20503. const codes = ansiStyles[key];
  20504. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  20505. }
  20506. };
  20507. }
  20508. styles.visible = {
  20509. get() {
  20510. return build.call(this, this._styles || [], true, 'visible');
  20511. }
  20512. };
  20513. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  20514. for (const model of Object.keys(ansiStyles.color.ansi)) {
  20515. if (skipModels.has(model)) {
  20516. continue;
  20517. }
  20518. styles[model] = {
  20519. get() {
  20520. const level = this.level;
  20521. return function () {
  20522. const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  20523. const codes = {
  20524. open,
  20525. close: ansiStyles.color.close,
  20526. closeRe: ansiStyles.color.closeRe
  20527. };
  20528. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  20529. };
  20530. }
  20531. };
  20532. }
  20533. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  20534. for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
  20535. if (skipModels.has(model)) {
  20536. continue;
  20537. }
  20538. const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  20539. styles[bgModel] = {
  20540. get() {
  20541. const level = this.level;
  20542. return function () {
  20543. const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  20544. const codes = {
  20545. open,
  20546. close: ansiStyles.bgColor.close,
  20547. closeRe: ansiStyles.bgColor.closeRe
  20548. };
  20549. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  20550. };
  20551. }
  20552. };
  20553. }
  20554. const proto = Object.defineProperties(() => {}, styles);
  20555. function build(_styles, _empty, key) {
  20556. const builder = function () {
  20557. return applyStyle.apply(builder, arguments);
  20558. };
  20559. builder._styles = _styles;
  20560. builder._empty = _empty;
  20561. const self = this;
  20562. Object.defineProperty(builder, 'level', {
  20563. enumerable: true,
  20564. get() {
  20565. return self.level;
  20566. },
  20567. set(level) {
  20568. self.level = level;
  20569. }
  20570. });
  20571. Object.defineProperty(builder, 'enabled', {
  20572. enumerable: true,
  20573. get() {
  20574. return self.enabled;
  20575. },
  20576. set(enabled) {
  20577. self.enabled = enabled;
  20578. }
  20579. });
  20580. // See below for fix regarding invisible grey/dim combination on Windows
  20581. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey';
  20582. // `__proto__` is used because we must return a function, but there is
  20583. // no way to create a function with a different prototype
  20584. builder.__proto__ = proto; // eslint-disable-line no-proto
  20585. return builder;
  20586. }
  20587. function applyStyle() {
  20588. // Support varags, but simply cast to string in case there's only one arg
  20589. const args = arguments;
  20590. const argsLen = args.length;
  20591. let str = String(arguments[0]);
  20592. if (argsLen === 0) {
  20593. return '';
  20594. }
  20595. if (argsLen > 1) {
  20596. // Don't slice `arguments`, it prevents V8 optimizations
  20597. for (let a = 1; a < argsLen; a++) {
  20598. str += ' ' + args[a];
  20599. }
  20600. }
  20601. if (!this.enabled || this.level <= 0 || !str) {
  20602. return this._empty ? '' : str;
  20603. }
  20604. // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  20605. // see https://github.com/chalk/chalk/issues/58
  20606. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  20607. const originalDim = ansiStyles.dim.open;
  20608. if (isSimpleWindowsTerm && this.hasGrey) {
  20609. ansiStyles.dim.open = '';
  20610. }
  20611. for (const code of this._styles.slice().reverse()) {
  20612. // Replace any instances already present with a re-opening code
  20613. // otherwise only the part of the string until said closing code
  20614. // will be colored, and the rest will simply be 'plain'.
  20615. str = code.open + str.replace(code.closeRe, code.open) + code.close;
  20616. // Close the styling before a linebreak and reopen
  20617. // after next line to fix a bleed issue on macOS
  20618. // https://github.com/chalk/chalk/pull/92
  20619. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  20620. }
  20621. // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  20622. ansiStyles.dim.open = originalDim;
  20623. return str;
  20624. }
  20625. function chalkTag(chalk, strings) {
  20626. if (!Array.isArray(strings)) {
  20627. // If chalk() was called by itself or with a string,
  20628. // return the string itself as a string.
  20629. return [].slice.call(arguments, 1).join(' ');
  20630. }
  20631. const args = [].slice.call(arguments, 2);
  20632. const parts = [strings.raw[0]];
  20633. for (let i = 1; i < strings.length; i++) {
  20634. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  20635. parts.push(String(strings.raw[i]));
  20636. }
  20637. return templates(chalk, parts.join(''));
  20638. }
  20639. Object.defineProperties(Chalk.prototype, styles);
  20640. module.exports = Chalk(); // eslint-disable-line new-cap
  20641. module.exports.supportsColor = supportsColor;
  20642. module.exports.default = module.exports; // For TypeScript
  20643. });
  20644. var lib$5 = createCommonjsModule(function (module, exports) {
  20645. "use strict";
  20646. exports.__esModule = true;
  20647. exports.shouldHighlight = shouldHighlight;
  20648. exports.getChalk = getChalk;
  20649. exports.default = highlight;
  20650. var _jsTokens = _interopRequireWildcard(jsTokens);
  20651. var _esutils = _interopRequireDefault(utils$2);
  20652. var _chalk = _interopRequireDefault(chalk);
  20653. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  20654. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  20655. function getDefs(chalk$$1) {
  20656. return {
  20657. keyword: chalk$$1.cyan,
  20658. capitalized: chalk$$1.yellow,
  20659. jsx_tag: chalk$$1.yellow,
  20660. punctuator: chalk$$1.yellow,
  20661. number: chalk$$1.magenta,
  20662. string: chalk$$1.green,
  20663. regex: chalk$$1.magenta,
  20664. comment: chalk$$1.grey,
  20665. invalid: chalk$$1.white.bgRed.bold
  20666. };
  20667. }
  20668. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  20669. var JSX_TAG = /^[a-z][\w-]*$/i;
  20670. var BRACKET = /^[()[\]{}]$/;
  20671. function getTokenType(match) {
  20672. var _match$slice = match.slice(-2),
  20673. offset = _match$slice[0],
  20674. text = _match$slice[1];
  20675. var token = (0, _jsTokens.matchToToken)(match);
  20676. if (token.type === "name") {
  20677. if (_esutils.default.keyword.isReservedWordES6(token.value)) {
  20678. return "keyword";
  20679. }
  20680. if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
  20681. return "jsx_tag";
  20682. }
  20683. if (token.value[0] !== token.value[0].toLowerCase()) {
  20684. return "capitalized";
  20685. }
  20686. }
  20687. if (token.type === "punctuator" && BRACKET.test(token.value)) {
  20688. return "bracket";
  20689. }
  20690. if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
  20691. return "punctuator";
  20692. }
  20693. return token.type;
  20694. }
  20695. function highlightTokens(defs, text) {
  20696. return text.replace(_jsTokens.default, function () {
  20697. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  20698. args[_key] = arguments[_key];
  20699. }
  20700. var type = getTokenType(args);
  20701. var colorize = defs[type];
  20702. if (colorize) {
  20703. return args[0].split(NEWLINE).map(function (str) {
  20704. return colorize(str);
  20705. }).join("\n");
  20706. } else {
  20707. return args[0];
  20708. }
  20709. });
  20710. }
  20711. function shouldHighlight(options) {
  20712. return _chalk.default.supportsColor || options.forceColor;
  20713. }
  20714. function getChalk(options) {
  20715. var chalk$$1 = _chalk.default;
  20716. if (options.forceColor) {
  20717. chalk$$1 = new _chalk.default.constructor({
  20718. enabled: true,
  20719. level: 1
  20720. });
  20721. }
  20722. return chalk$$1;
  20723. }
  20724. function highlight(code, options) {
  20725. if (options === void 0) {
  20726. options = {};
  20727. }
  20728. if (shouldHighlight(options)) {
  20729. var chalk$$1 = getChalk(options);
  20730. var defs = getDefs(chalk$$1);
  20731. return highlightTokens(defs, code);
  20732. } else {
  20733. return code;
  20734. }
  20735. }
  20736. });
  20737. unwrapExports(lib$5);
  20738. var lib$4 = createCommonjsModule(function (module, exports) {
  20739. "use strict";
  20740. exports.__esModule = true;
  20741. exports.codeFrameColumns = codeFrameColumns;
  20742. exports.default = _default;
  20743. var _highlight = _interopRequireWildcard(lib$5);
  20744. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  20745. var deprecationWarningShown = false;
  20746. function getDefs(chalk) {
  20747. return {
  20748. gutter: chalk.grey,
  20749. marker: chalk.red.bold,
  20750. message: chalk.red.bold
  20751. };
  20752. }
  20753. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  20754. function getMarkerLines(loc, source, opts) {
  20755. var startLoc = Object.assign({}, {
  20756. column: 0,
  20757. line: -1
  20758. }, loc.start);
  20759. var endLoc = Object.assign({}, startLoc, loc.end);
  20760. var _ref = opts || {},
  20761. _ref$linesAbove = _ref.linesAbove,
  20762. linesAbove = _ref$linesAbove === void 0 ? 2 : _ref$linesAbove,
  20763. _ref$linesBelow = _ref.linesBelow,
  20764. linesBelow = _ref$linesBelow === void 0 ? 3 : _ref$linesBelow;
  20765. var startLine = startLoc.line;
  20766. var startColumn = startLoc.column;
  20767. var endLine = endLoc.line;
  20768. var endColumn = endLoc.column;
  20769. var start = Math.max(startLine - (linesAbove + 1), 0);
  20770. var end = Math.min(source.length, endLine + linesBelow);
  20771. if (startLine === -1) {
  20772. start = 0;
  20773. }
  20774. if (endLine === -1) {
  20775. end = source.length;
  20776. }
  20777. var lineDiff = endLine - startLine;
  20778. var markerLines = {};
  20779. if (lineDiff) {
  20780. for (var i = 0; i <= lineDiff; i++) {
  20781. var lineNumber = i + startLine;
  20782. if (!startColumn) {
  20783. markerLines[lineNumber] = true;
  20784. } else if (i === 0) {
  20785. var sourceLength = source[lineNumber - 1].length;
  20786. markerLines[lineNumber] = [startColumn, sourceLength - startColumn];
  20787. } else if (i === lineDiff) {
  20788. markerLines[lineNumber] = [0, endColumn];
  20789. } else {
  20790. var _sourceLength = source[lineNumber - i].length;
  20791. markerLines[lineNumber] = [0, _sourceLength];
  20792. }
  20793. }
  20794. } else {
  20795. if (startColumn === endColumn) {
  20796. if (startColumn) {
  20797. markerLines[startLine] = [startColumn, 0];
  20798. } else {
  20799. markerLines[startLine] = true;
  20800. }
  20801. } else {
  20802. markerLines[startLine] = [startColumn, endColumn - startColumn];
  20803. }
  20804. }
  20805. return {
  20806. start: start,
  20807. end: end,
  20808. markerLines: markerLines
  20809. };
  20810. }
  20811. function codeFrameColumns(rawLines, loc, opts) {
  20812. if (opts === void 0) {
  20813. opts = {};
  20814. }
  20815. var highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight.shouldHighlight)(opts);
  20816. var chalk = (0, _highlight.getChalk)(opts);
  20817. var defs = getDefs(chalk);
  20818. var maybeHighlight = function maybeHighlight(chalkFn, string) {
  20819. return highlighted ? chalkFn(string) : string;
  20820. };
  20821. if (highlighted) rawLines = (0, _highlight.default)(rawLines, opts);
  20822. var lines = rawLines.split(NEWLINE);
  20823. var _getMarkerLines = getMarkerLines(loc, lines, opts),
  20824. start = _getMarkerLines.start,
  20825. end = _getMarkerLines.end,
  20826. markerLines = _getMarkerLines.markerLines;
  20827. var hasColumns = loc.start && typeof loc.start.column === "number";
  20828. var numberMaxWidth = String(end).length;
  20829. var frame = lines.slice(start, end).map(function (line, index) {
  20830. var number = start + 1 + index;
  20831. var paddedNumber = (" " + number).slice(-numberMaxWidth);
  20832. var gutter = " " + paddedNumber + " | ";
  20833. var hasMarker = markerLines[number];
  20834. var lastMarkerLine = !markerLines[number + 1];
  20835. if (hasMarker) {
  20836. var markerLine = "";
  20837. if (Array.isArray(hasMarker)) {
  20838. var markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  20839. var numberOfMarkers = hasMarker[1] || 1;
  20840. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  20841. if (lastMarkerLine && opts.message) {
  20842. markerLine += " " + maybeHighlight(defs.message, opts.message);
  20843. }
  20844. }
  20845. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
  20846. } else {
  20847. return " " + maybeHighlight(defs.gutter, gutter) + line;
  20848. }
  20849. }).join("\n");
  20850. if (opts.message && !hasColumns) {
  20851. frame = "" + " ".repeat(numberMaxWidth + 1) + opts.message + "\n" + frame;
  20852. }
  20853. if (highlighted) {
  20854. return chalk.reset(frame);
  20855. } else {
  20856. return frame;
  20857. }
  20858. }
  20859. function _default(rawLines, lineNumber, colNumber, opts) {
  20860. if (opts === void 0) {
  20861. opts = {};
  20862. }
  20863. if (!deprecationWarningShown) {
  20864. deprecationWarningShown = true;
  20865. var deprecationError = new Error("Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.");
  20866. deprecationError.name = "DeprecationWarning";
  20867. if (process.emitWarning) {
  20868. process.emitWarning(deprecationError);
  20869. } else {
  20870. console.warn(deprecationError);
  20871. }
  20872. }
  20873. colNumber = Math.max(colNumber, 0);
  20874. var location = {
  20875. start: {
  20876. column: colNumber,
  20877. line: lineNumber
  20878. }
  20879. };
  20880. return codeFrameColumns(rawLines, location, opts);
  20881. }
  20882. });
  20883. unwrapExports(lib$4);
  20884. const ConfigError = errors.ConfigError;
  20885. const locStart$1 = languageJs.locStart;
  20886. const locEnd$1 = languageJs.locEnd;
  20887. function getParsers(options) {
  20888. return options.plugins.reduce(
  20889. (parsers, plugin) => Object.assign({}, parsers, plugin.parsers),
  20890. {}
  20891. );
  20892. }
  20893. function resolveParser$1(opts, parsers) {
  20894. parsers = parsers || getParsers(opts);
  20895. if (typeof opts.parser === "function") {
  20896. // Custom parser API always works with JavaScript.
  20897. return {
  20898. parse: opts.parser,
  20899. astFormat: "estree",
  20900. locStart: locStart$1,
  20901. locEnd: locEnd$1
  20902. };
  20903. }
  20904. if (typeof opts.parser === "string") {
  20905. if (parsers.hasOwnProperty(opts.parser)) {
  20906. return parsers[opts.parser];
  20907. }
  20908. try {
  20909. return {
  20910. parse: require(path.resolve(process.cwd(), opts.parser)),
  20911. astFormat: "estree",
  20912. locStart: locStart$1,
  20913. locEnd: locEnd$1
  20914. };
  20915. } catch (err) {
  20916. /* istanbul ignore next */
  20917. throw new ConfigError(`Couldn't resolve parser "${opts.parser}"`);
  20918. }
  20919. }
  20920. /* istanbul ignore next */
  20921. return parsers.babylon;
  20922. }
  20923. function parse$3(text, opts) {
  20924. const parsers = getParsers(opts);
  20925. // Copy the "parse" function from parser to a new object whose values are
  20926. // functions. Use defineProperty()/getOwnPropertyDescriptor() such that we
  20927. // don't invoke the parser.parse getters.
  20928. const parsersForCustomParserApi = Object.keys(parsers).reduce(
  20929. (object, parserName) =>
  20930. Object.defineProperty(
  20931. object,
  20932. parserName,
  20933. Object.getOwnPropertyDescriptor(parsers[parserName], "parse")
  20934. ),
  20935. {}
  20936. );
  20937. const parser = resolveParser$1(opts, parsers);
  20938. try {
  20939. if (parser.preprocess) {
  20940. text = parser.preprocess(text, opts);
  20941. }
  20942. return {
  20943. text,
  20944. ast: parser.parse(text, parsersForCustomParserApi, opts)
  20945. };
  20946. } catch (error) {
  20947. const loc = error.loc;
  20948. if (loc) {
  20949. const codeFrame = lib$4;
  20950. error.codeFrame = codeFrame.codeFrameColumns(text, loc, {
  20951. highlightCode: true
  20952. });
  20953. error.message += "\n" + error.codeFrame;
  20954. throw error;
  20955. }
  20956. /* istanbul ignore next */
  20957. throw error.stack;
  20958. }
  20959. }
  20960. var parser$3 = { parse: parse$3, resolveParser: resolveParser$1 };
  20961. function getPlugin(options) {
  20962. const astFormat = options.astFormat;
  20963. if (!astFormat) {
  20964. throw new Error("getPlugin() requires astFormat to be set");
  20965. }
  20966. const printerPlugin = options.plugins.find(
  20967. plugin => plugin.printers[astFormat]
  20968. );
  20969. if (!printerPlugin) {
  20970. throw new Error(`Couldn't find plugin for AST format "${astFormat}"`);
  20971. }
  20972. return printerPlugin;
  20973. }
  20974. var getPlugin_1 = getPlugin;
  20975. const getSupportInfo$2 = support.getSupportInfo;
  20976. const resolveParser = parser$3.resolveParser;
  20977. const hiddenDefaults = {
  20978. astFormat: "estree",
  20979. printer: {},
  20980. locStart: null,
  20981. locEnd: null
  20982. };
  20983. // Copy options and fill in default values.
  20984. function normalize$2(options, opts) {
  20985. opts = opts || {};
  20986. const rawOptions = Object.assign({}, options);
  20987. const plugins = loadPlugins_1(rawOptions.plugins);
  20988. rawOptions.plugins = plugins;
  20989. const supportOptions = getSupportInfo$2(null, {
  20990. plugins,
  20991. pluginsLoaded: true,
  20992. showUnreleased: true,
  20993. showDeprecated: true
  20994. }).options;
  20995. const defaults = supportOptions.reduce(
  20996. (reduced, optionInfo) =>
  20997. Object.assign(reduced, { [optionInfo.name]: optionInfo.default }),
  20998. Object.assign({}, hiddenDefaults)
  20999. );
  21000. if (opts.inferParser !== false) {
  21001. if (
  21002. rawOptions.filepath &&
  21003. (!rawOptions.parser || rawOptions.parser === defaults.parser)
  21004. ) {
  21005. const inferredParser = inferParser(
  21006. rawOptions.filepath,
  21007. rawOptions.plugins
  21008. );
  21009. if (inferredParser) {
  21010. rawOptions.parser = inferredParser;
  21011. }
  21012. }
  21013. }
  21014. const parser = resolveParser(
  21015. !rawOptions.parser
  21016. ? rawOptions
  21017. : // handle deprecated parsers
  21018. optionsNormalizer.normalizeApiOptions(
  21019. rawOptions,
  21020. [supportOptions.find(x => x.name === "parser")],
  21021. { passThrough: true, logger: false }
  21022. )
  21023. );
  21024. rawOptions.astFormat = parser.astFormat;
  21025. rawOptions.locEnd = parser.locEnd;
  21026. rawOptions.locStart = parser.locStart;
  21027. const plugin = getPlugin_1(rawOptions);
  21028. rawOptions.printer = plugin.printers[rawOptions.astFormat];
  21029. const pluginDefaults = supportOptions
  21030. .filter(
  21031. optionInfo =>
  21032. optionInfo.pluginDefaults && optionInfo.pluginDefaults[plugin.name]
  21033. )
  21034. .reduce(
  21035. (reduced, optionInfo) =>
  21036. Object.assign(reduced, {
  21037. [optionInfo.name]: optionInfo.pluginDefaults[plugin.name]
  21038. }),
  21039. {}
  21040. );
  21041. const mixedDefaults = Object.assign({}, defaults, pluginDefaults);
  21042. Object.keys(mixedDefaults).forEach(k => {
  21043. if (rawOptions[k] == null) {
  21044. rawOptions[k] = mixedDefaults[k];
  21045. }
  21046. });
  21047. if (rawOptions.parser === "json") {
  21048. rawOptions.trailingComma = "none";
  21049. }
  21050. return optionsNormalizer.normalizeApiOptions(
  21051. rawOptions,
  21052. supportOptions,
  21053. Object.assign({ passThrough: Object.keys(hiddenDefaults) }, opts)
  21054. );
  21055. }
  21056. function inferParser(filepath, plugins) {
  21057. const extension = path.extname(filepath);
  21058. const filename = path.basename(filepath).toLowerCase();
  21059. const language = getSupportInfo$2(null, {
  21060. plugins,
  21061. pluginsLoaded: true
  21062. }).languages.find(
  21063. language =>
  21064. language.since !== null &&
  21065. (language.extensions.indexOf(extension) > -1 ||
  21066. (language.filenames &&
  21067. language.filenames.find(name => name.toLowerCase() === filename)))
  21068. );
  21069. return language && language.parsers[0];
  21070. }
  21071. var options$12 = { normalize: normalize$2, hiddenDefaults };
  21072. const normalize$1 = options$12.normalize;
  21073. function printSubtree(path$$1, print, options) {
  21074. if (options.printer.embed) {
  21075. return options.printer.embed(
  21076. path$$1,
  21077. print,
  21078. (text, partialNextOptions) =>
  21079. textToDoc(text, partialNextOptions, options),
  21080. options
  21081. );
  21082. }
  21083. }
  21084. function textToDoc(text, partialNextOptions, parentOptions) {
  21085. const nextOptions = normalize$1(
  21086. Object.assign({}, parentOptions, partialNextOptions, {
  21087. parentParser: parentOptions.parser,
  21088. originalText: text
  21089. }),
  21090. { passThrough: true, inferParser: false }
  21091. );
  21092. const result = parser$3.parse(text, nextOptions);
  21093. const ast = result.ast;
  21094. text = result.text;
  21095. const astComments = ast.comments;
  21096. delete ast.comments;
  21097. comments.attach(astComments, ast, text, nextOptions);
  21098. return astToDoc(ast, nextOptions);
  21099. }
  21100. var multiparser = {
  21101. printSubtree
  21102. };
  21103. const doc$3 = doc;
  21104. const docBuilders$14 = doc$3.builders;
  21105. const concat$14 = docBuilders$14.concat;
  21106. const hardline$13 = docBuilders$14.hardline;
  21107. const addAlignmentToDoc$2 = docBuilders$14.addAlignmentToDoc;
  21108. const docUtils$6 = doc$3.utils;
  21109. function printAstToDoc(ast, options, addAlignmentSize) {
  21110. addAlignmentSize = addAlignmentSize || 0;
  21111. const printer = options.printer;
  21112. const cache = new Map();
  21113. function printGenerically(path$$1, args) {
  21114. const node = path$$1.getValue();
  21115. const shouldCache = node && typeof node === "object" && args === undefined;
  21116. if (shouldCache && cache.has(node)) {
  21117. return cache.get(node);
  21118. }
  21119. // We let JSXElement print its comments itself because it adds () around
  21120. // UnionTypeAnnotation has to align the child without the comments
  21121. let res;
  21122. if (printer.willPrintOwnComments && printer.willPrintOwnComments(path$$1)) {
  21123. res = genericPrint$6(path$$1, options, printGenerically, args);
  21124. } else {
  21125. res = comments.printComments(
  21126. path$$1,
  21127. p => genericPrint$6(p, options, printGenerically, args),
  21128. options,
  21129. args && args.needsSemi
  21130. );
  21131. }
  21132. if (shouldCache) {
  21133. cache.set(node, res);
  21134. }
  21135. return res;
  21136. }
  21137. let doc$$2 = printGenerically(new fastPath(ast));
  21138. if (addAlignmentSize > 0) {
  21139. // Add a hardline to make the indents take effect
  21140. // It should be removed in index.js format()
  21141. doc$$2 = addAlignmentToDoc$2(
  21142. docUtils$6.removeLines(concat$14([hardline$13, doc$$2])),
  21143. addAlignmentSize,
  21144. options.tabWidth
  21145. );
  21146. }
  21147. docUtils$6.propagateBreaks(doc$$2);
  21148. if (options.parser === "json") {
  21149. doc$$2 = concat$14([doc$$2, hardline$13]);
  21150. }
  21151. return doc$$2;
  21152. }
  21153. function genericPrint$6(path$$1, options, printPath, args) {
  21154. assert.ok(path$$1 instanceof fastPath);
  21155. const node = path$$1.getValue();
  21156. const printer = options.printer;
  21157. // Escape hatch
  21158. if (printer.hasPrettierIgnore && printer.hasPrettierIgnore(path$$1)) {
  21159. return options.originalText.slice(
  21160. options.locStart(node),
  21161. options.locEnd(node)
  21162. );
  21163. }
  21164. if (node) {
  21165. try {
  21166. // Potentially switch to a different parser
  21167. const sub = multiparser.printSubtree(path$$1, printPath, options);
  21168. if (sub) {
  21169. return sub;
  21170. }
  21171. } catch (error) {
  21172. /* istanbul ignore if */
  21173. if (process.env.PRETTIER_DEBUG) {
  21174. throw error;
  21175. }
  21176. // Continue with current parser
  21177. }
  21178. }
  21179. return printer.print(path$$1, options, printPath, args);
  21180. }
  21181. var astToDoc = printAstToDoc;
  21182. var concatMap = function (xs, fn) {
  21183. var res = [];
  21184. for (var i = 0; i < xs.length; i++) {
  21185. var x = fn(xs[i], i);
  21186. if (isArray(x)) res.push.apply(res, x);
  21187. else res.push(x);
  21188. }
  21189. return res;
  21190. };
  21191. var isArray = Array.isArray || function (xs) {
  21192. return Object.prototype.toString.call(xs) === '[object Array]';
  21193. };
  21194. var balancedMatch = balanced;
  21195. function balanced(a, b, str) {
  21196. if (a instanceof RegExp) a = maybeMatch(a, str);
  21197. if (b instanceof RegExp) b = maybeMatch(b, str);
  21198. var r = range(a, b, str);
  21199. return r && {
  21200. start: r[0],
  21201. end: r[1],
  21202. pre: str.slice(0, r[0]),
  21203. body: str.slice(r[0] + a.length, r[1]),
  21204. post: str.slice(r[1] + b.length)
  21205. };
  21206. }
  21207. function maybeMatch(reg, str) {
  21208. var m = str.match(reg);
  21209. return m ? m[0] : null;
  21210. }
  21211. balanced.range = range;
  21212. function range(a, b, str) {
  21213. var begs, beg, left, right, result;
  21214. var ai = str.indexOf(a);
  21215. var bi = str.indexOf(b, ai + 1);
  21216. var i = ai;
  21217. if (ai >= 0 && bi > 0) {
  21218. begs = [];
  21219. left = str.length;
  21220. while (i >= 0 && !result) {
  21221. if (i == ai) {
  21222. begs.push(i);
  21223. ai = str.indexOf(a, i + 1);
  21224. } else if (begs.length == 1) {
  21225. result = [ begs.pop(), bi ];
  21226. } else {
  21227. beg = begs.pop();
  21228. if (beg < left) {
  21229. left = beg;
  21230. right = bi;
  21231. }
  21232. bi = str.indexOf(b, i + 1);
  21233. }
  21234. i = ai < bi && ai >= 0 ? ai : bi;
  21235. }
  21236. if (begs.length) {
  21237. result = [ left, right ];
  21238. }
  21239. }
  21240. return result;
  21241. }
  21242. var braceExpansion = expandTop;
  21243. var escSlash = '\0SLASH'+Math.random()+'\0';
  21244. var escOpen = '\0OPEN'+Math.random()+'\0';
  21245. var escClose = '\0CLOSE'+Math.random()+'\0';
  21246. var escComma = '\0COMMA'+Math.random()+'\0';
  21247. var escPeriod = '\0PERIOD'+Math.random()+'\0';
  21248. function numeric(str) {
  21249. return parseInt(str, 10) == str
  21250. ? parseInt(str, 10)
  21251. : str.charCodeAt(0);
  21252. }
  21253. function escapeBraces(str) {
  21254. return str.split('\\\\').join(escSlash)
  21255. .split('\\{').join(escOpen)
  21256. .split('\\}').join(escClose)
  21257. .split('\\,').join(escComma)
  21258. .split('\\.').join(escPeriod);
  21259. }
  21260. function unescapeBraces(str) {
  21261. return str.split(escSlash).join('\\')
  21262. .split(escOpen).join('{')
  21263. .split(escClose).join('}')
  21264. .split(escComma).join(',')
  21265. .split(escPeriod).join('.');
  21266. }
  21267. // Basically just str.split(","), but handling cases
  21268. // where we have nested braced sections, which should be
  21269. // treated as individual members, like {a,{b,c},d}
  21270. function parseCommaParts(str) {
  21271. if (!str)
  21272. return [''];
  21273. var parts = [];
  21274. var m = balancedMatch('{', '}', str);
  21275. if (!m)
  21276. return str.split(',');
  21277. var pre = m.pre;
  21278. var body = m.body;
  21279. var post = m.post;
  21280. var p = pre.split(',');
  21281. p[p.length-1] += '{' + body + '}';
  21282. var postParts = parseCommaParts(post);
  21283. if (post.length) {
  21284. p[p.length-1] += postParts.shift();
  21285. p.push.apply(p, postParts);
  21286. }
  21287. parts.push.apply(parts, p);
  21288. return parts;
  21289. }
  21290. function expandTop(str) {
  21291. if (!str)
  21292. return [];
  21293. // I don't know why Bash 4.3 does this, but it does.
  21294. // Anything starting with {} will have the first two bytes preserved
  21295. // but *only* at the top level, so {},a}b will not expand to anything,
  21296. // but a{},b}c will be expanded to [a}c,abc].
  21297. // One could argue that this is a bug in Bash, but since the goal of
  21298. // this module is to match Bash's rules, we escape a leading {}
  21299. if (str.substr(0, 2) === '{}') {
  21300. str = '\\{\\}' + str.substr(2);
  21301. }
  21302. return expand(escapeBraces(str), true).map(unescapeBraces);
  21303. }
  21304. function embrace(str) {
  21305. return '{' + str + '}';
  21306. }
  21307. function isPadded(el) {
  21308. return /^-?0\d/.test(el);
  21309. }
  21310. function lte(i, y) {
  21311. return i <= y;
  21312. }
  21313. function gte(i, y) {
  21314. return i >= y;
  21315. }
  21316. function expand(str, isTop) {
  21317. var expansions = [];
  21318. var m = balancedMatch('{', '}', str);
  21319. if (!m || /\$$/.test(m.pre)) return [str];
  21320. var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
  21321. var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
  21322. var isSequence = isNumericSequence || isAlphaSequence;
  21323. var isOptions = m.body.indexOf(',') >= 0;
  21324. if (!isSequence && !isOptions) {
  21325. // {a},b}
  21326. if (m.post.match(/,.*\}/)) {
  21327. str = m.pre + '{' + m.body + escClose + m.post;
  21328. return expand(str);
  21329. }
  21330. return [str];
  21331. }
  21332. var n;
  21333. if (isSequence) {
  21334. n = m.body.split(/\.\./);
  21335. } else {
  21336. n = parseCommaParts(m.body);
  21337. if (n.length === 1) {
  21338. // x{{a,b}}y ==> x{a}y x{b}y
  21339. n = expand(n[0], false).map(embrace);
  21340. if (n.length === 1) {
  21341. var post = m.post.length
  21342. ? expand(m.post, false)
  21343. : [''];
  21344. return post.map(function(p) {
  21345. return m.pre + n[0] + p;
  21346. });
  21347. }
  21348. }
  21349. }
  21350. // at this point, n is the parts, and we know it's not a comma set
  21351. // with a single entry.
  21352. // no need to expand pre, since it is guaranteed to be free of brace-sets
  21353. var pre = m.pre;
  21354. var post = m.post.length
  21355. ? expand(m.post, false)
  21356. : [''];
  21357. var N;
  21358. if (isSequence) {
  21359. var x = numeric(n[0]);
  21360. var y = numeric(n[1]);
  21361. var width = Math.max(n[0].length, n[1].length);
  21362. var incr = n.length == 3
  21363. ? Math.abs(numeric(n[2]))
  21364. : 1;
  21365. var test = lte;
  21366. var reverse = y < x;
  21367. if (reverse) {
  21368. incr *= -1;
  21369. test = gte;
  21370. }
  21371. var pad = n.some(isPadded);
  21372. N = [];
  21373. for (var i = x; test(i, y); i += incr) {
  21374. var c;
  21375. if (isAlphaSequence) {
  21376. c = String.fromCharCode(i);
  21377. if (c === '\\')
  21378. c = '';
  21379. } else {
  21380. c = String(i);
  21381. if (pad) {
  21382. var need = width - c.length;
  21383. if (need > 0) {
  21384. var z = new Array(need + 1).join('0');
  21385. if (i < 0)
  21386. c = '-' + z + c.slice(1);
  21387. else
  21388. c = z + c;
  21389. }
  21390. }
  21391. }
  21392. N.push(c);
  21393. }
  21394. } else {
  21395. N = concatMap(n, function(el) { return expand(el, false) });
  21396. }
  21397. for (var j = 0; j < N.length; j++) {
  21398. for (var k = 0; k < post.length; k++) {
  21399. var expansion = pre + N[j] + post[k];
  21400. if (!isTop || isSequence || expansion)
  21401. expansions.push(expansion);
  21402. }
  21403. }
  21404. return expansions;
  21405. }
  21406. var minimatch_1 = minimatch;
  21407. minimatch.Minimatch = Minimatch;
  21408. var path$3 = { sep: '/' };
  21409. try {
  21410. path$3 = path;
  21411. } catch (er) {}
  21412. var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
  21413. var plTypes = {
  21414. '!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
  21415. '?': { open: '(?:', close: ')?' },
  21416. '+': { open: '(?:', close: ')+' },
  21417. '*': { open: '(?:', close: ')*' },
  21418. '@': { open: '(?:', close: ')' }
  21419. };
  21420. // any single thing other than /
  21421. // don't need to escape / when using new RegExp()
  21422. var qmark = '[^/]';
  21423. // * => any number of characters
  21424. var star = qmark + '*?';
  21425. // ** when dots are allowed. Anything goes, except .. and .
  21426. // not (^ or / followed by one or two dots followed by $ or /),
  21427. // followed by anything, any number of times.
  21428. var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?';
  21429. // not a ^ or / followed by a dot,
  21430. // followed by anything, any number of times.
  21431. var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?';
  21432. // characters that need to be escaped in RegExp.
  21433. var reSpecials = charSet('().*{}+?[]^$\\!');
  21434. // "abc" -> { a:true, b:true, c:true }
  21435. function charSet (s) {
  21436. return s.split('').reduce(function (set, c) {
  21437. set[c] = true;
  21438. return set
  21439. }, {})
  21440. }
  21441. // normalizes slashes.
  21442. var slashSplit = /\/+/;
  21443. minimatch.filter = filter;
  21444. function filter (pattern, options) {
  21445. options = options || {};
  21446. return function (p, i, list) {
  21447. return minimatch(p, pattern, options)
  21448. }
  21449. }
  21450. function ext (a, b) {
  21451. a = a || {};
  21452. b = b || {};
  21453. var t = {};
  21454. Object.keys(b).forEach(function (k) {
  21455. t[k] = b[k];
  21456. });
  21457. Object.keys(a).forEach(function (k) {
  21458. t[k] = a[k];
  21459. });
  21460. return t
  21461. }
  21462. minimatch.defaults = function (def) {
  21463. if (!def || !Object.keys(def).length) return minimatch
  21464. var orig = minimatch;
  21465. var m = function minimatch (p, pattern, options) {
  21466. return orig.minimatch(p, pattern, ext(def, options))
  21467. };
  21468. m.Minimatch = function Minimatch (pattern, options) {
  21469. return new orig.Minimatch(pattern, ext(def, options))
  21470. };
  21471. return m
  21472. };
  21473. Minimatch.defaults = function (def) {
  21474. if (!def || !Object.keys(def).length) return Minimatch
  21475. return minimatch.defaults(def).Minimatch
  21476. };
  21477. function minimatch (p, pattern, options) {
  21478. if (typeof pattern !== 'string') {
  21479. throw new TypeError('glob pattern string required')
  21480. }
  21481. if (!options) options = {};
  21482. // shortcut: comments match nothing.
  21483. if (!options.nocomment && pattern.charAt(0) === '#') {
  21484. return false
  21485. }
  21486. // "" only matches ""
  21487. if (pattern.trim() === '') return p === ''
  21488. return new Minimatch(pattern, options).match(p)
  21489. }
  21490. function Minimatch (pattern, options) {
  21491. if (!(this instanceof Minimatch)) {
  21492. return new Minimatch(pattern, options)
  21493. }
  21494. if (typeof pattern !== 'string') {
  21495. throw new TypeError('glob pattern string required')
  21496. }
  21497. if (!options) options = {};
  21498. pattern = pattern.trim();
  21499. // windows support: need to use /, not \
  21500. if (path$3.sep !== '/') {
  21501. pattern = pattern.split(path$3.sep).join('/');
  21502. }
  21503. this.options = options;
  21504. this.set = [];
  21505. this.pattern = pattern;
  21506. this.regexp = null;
  21507. this.negate = false;
  21508. this.comment = false;
  21509. this.empty = false;
  21510. // make the set of regexps etc.
  21511. this.make();
  21512. }
  21513. Minimatch.prototype.debug = function () {};
  21514. Minimatch.prototype.make = make;
  21515. function make () {
  21516. // don't do it more than once.
  21517. if (this._made) return
  21518. var pattern = this.pattern;
  21519. var options = this.options;
  21520. // empty patterns and comments match nothing.
  21521. if (!options.nocomment && pattern.charAt(0) === '#') {
  21522. this.comment = true;
  21523. return
  21524. }
  21525. if (!pattern) {
  21526. this.empty = true;
  21527. return
  21528. }
  21529. // step 1: figure out negation, etc.
  21530. this.parseNegate();
  21531. // step 2: expand braces
  21532. var set = this.globSet = this.braceExpand();
  21533. if (options.debug) this.debug = console.error;
  21534. this.debug(this.pattern, set);
  21535. // step 3: now we have a set, so turn each one into a series of path-portion
  21536. // matching patterns.
  21537. // These will be regexps, except in the case of "**", which is
  21538. // set to the GLOBSTAR object for globstar behavior,
  21539. // and will not contain any / characters
  21540. set = this.globParts = set.map(function (s) {
  21541. return s.split(slashSplit)
  21542. });
  21543. this.debug(this.pattern, set);
  21544. // glob --> regexps
  21545. set = set.map(function (s, si, set) {
  21546. return s.map(this.parse, this)
  21547. }, this);
  21548. this.debug(this.pattern, set);
  21549. // filter out everything that didn't compile properly.
  21550. set = set.filter(function (s) {
  21551. return s.indexOf(false) === -1
  21552. });
  21553. this.debug(this.pattern, set);
  21554. this.set = set;
  21555. }
  21556. Minimatch.prototype.parseNegate = parseNegate;
  21557. function parseNegate () {
  21558. var pattern = this.pattern;
  21559. var negate = false;
  21560. var options = this.options;
  21561. var negateOffset = 0;
  21562. if (options.nonegate) return
  21563. for (var i = 0, l = pattern.length
  21564. ; i < l && pattern.charAt(i) === '!'
  21565. ; i++) {
  21566. negate = !negate;
  21567. negateOffset++;
  21568. }
  21569. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  21570. this.negate = negate;
  21571. }
  21572. // Brace expansion:
  21573. // a{b,c}d -> abd acd
  21574. // a{b,}c -> abc ac
  21575. // a{0..3}d -> a0d a1d a2d a3d
  21576. // a{b,c{d,e}f}g -> abg acdfg acefg
  21577. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  21578. //
  21579. // Invalid sets are not expanded.
  21580. // a{2..}b -> a{2..}b
  21581. // a{b}c -> a{b}c
  21582. minimatch.braceExpand = function (pattern, options) {
  21583. return braceExpand(pattern, options)
  21584. };
  21585. Minimatch.prototype.braceExpand = braceExpand;
  21586. function braceExpand (pattern, options) {
  21587. if (!options) {
  21588. if (this instanceof Minimatch) {
  21589. options = this.options;
  21590. } else {
  21591. options = {};
  21592. }
  21593. }
  21594. pattern = typeof pattern === 'undefined'
  21595. ? this.pattern : pattern;
  21596. if (typeof pattern === 'undefined') {
  21597. throw new TypeError('undefined pattern')
  21598. }
  21599. if (options.nobrace ||
  21600. !pattern.match(/\{.*\}/)) {
  21601. // shortcut. no need to expand.
  21602. return [pattern]
  21603. }
  21604. return braceExpansion(pattern)
  21605. }
  21606. // parse a component of the expanded set.
  21607. // At this point, no pattern may contain "/" in it
  21608. // so we're going to return a 2d array, where each entry is the full
  21609. // pattern, split on '/', and then turned into a regular expression.
  21610. // A regexp is made at the end which joins each array with an
  21611. // escaped /, and another full one which joins each regexp with |.
  21612. //
  21613. // Following the lead of Bash 4.1, note that "**" only has special meaning
  21614. // when it is the *only* thing in a path portion. Otherwise, any series
  21615. // of * is equivalent to a single *. Globstar behavior is enabled by
  21616. // default, and can be disabled by setting options.noglobstar.
  21617. Minimatch.prototype.parse = parse$4;
  21618. var SUBPARSE = {};
  21619. function parse$4 (pattern, isSub) {
  21620. if (pattern.length > 1024 * 64) {
  21621. throw new TypeError('pattern is too long')
  21622. }
  21623. var options = this.options;
  21624. // shortcuts
  21625. if (!options.noglobstar && pattern === '**') return GLOBSTAR
  21626. if (pattern === '') return ''
  21627. var re = '';
  21628. var hasMagic = !!options.nocase;
  21629. var escaping = false;
  21630. // ? => one single character
  21631. var patternListStack = [];
  21632. var negativeLists = [];
  21633. var stateChar;
  21634. var inClass = false;
  21635. var reClassStart = -1;
  21636. var classStart = -1;
  21637. // . and .. never match anything that doesn't start with .,
  21638. // even when options.dot is set.
  21639. var patternStart = pattern.charAt(0) === '.' ? '' // anything
  21640. // not (start or / followed by . or .. followed by / or end)
  21641. : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
  21642. : '(?!\\.)';
  21643. var self = this;
  21644. function clearStateChar () {
  21645. if (stateChar) {
  21646. // we had some state-tracking character
  21647. // that wasn't consumed by this pass.
  21648. switch (stateChar) {
  21649. case '*':
  21650. re += star;
  21651. hasMagic = true;
  21652. break
  21653. case '?':
  21654. re += qmark;
  21655. hasMagic = true;
  21656. break
  21657. default:
  21658. re += '\\' + stateChar;
  21659. break
  21660. }
  21661. self.debug('clearStateChar %j %j', stateChar, re);
  21662. stateChar = false;
  21663. }
  21664. }
  21665. for (var i = 0, len = pattern.length, c
  21666. ; (i < len) && (c = pattern.charAt(i))
  21667. ; i++) {
  21668. this.debug('%s\t%s %s %j', pattern, i, re, c);
  21669. // skip over any that are escaped.
  21670. if (escaping && reSpecials[c]) {
  21671. re += '\\' + c;
  21672. escaping = false;
  21673. continue
  21674. }
  21675. switch (c) {
  21676. case '/':
  21677. // completely not allowed, even escaped.
  21678. // Should already be path-split by now.
  21679. return false
  21680. case '\\':
  21681. clearStateChar();
  21682. escaping = true;
  21683. continue
  21684. // the various stateChar values
  21685. // for the "extglob" stuff.
  21686. case '?':
  21687. case '*':
  21688. case '+':
  21689. case '@':
  21690. case '!':
  21691. this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c);
  21692. // all of those are literals inside a class, except that
  21693. // the glob [!a] means [^a] in regexp
  21694. if (inClass) {
  21695. this.debug(' in class');
  21696. if (c === '!' && i === classStart + 1) c = '^';
  21697. re += c;
  21698. continue
  21699. }
  21700. // if we already have a stateChar, then it means
  21701. // that there was something like ** or +? in there.
  21702. // Handle the stateChar, then proceed with this one.
  21703. self.debug('call clearStateChar %j', stateChar);
  21704. clearStateChar();
  21705. stateChar = c;
  21706. // if extglob is disabled, then +(asdf|foo) isn't a thing.
  21707. // just clear the statechar *now*, rather than even diving into
  21708. // the patternList stuff.
  21709. if (options.noext) clearStateChar();
  21710. continue
  21711. case '(':
  21712. if (inClass) {
  21713. re += '(';
  21714. continue
  21715. }
  21716. if (!stateChar) {
  21717. re += '\\(';
  21718. continue
  21719. }
  21720. patternListStack.push({
  21721. type: stateChar,
  21722. start: i - 1,
  21723. reStart: re.length,
  21724. open: plTypes[stateChar].open,
  21725. close: plTypes[stateChar].close
  21726. });
  21727. // negation is (?:(?!js)[^/]*)
  21728. re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
  21729. this.debug('plType %j %j', stateChar, re);
  21730. stateChar = false;
  21731. continue
  21732. case ')':
  21733. if (inClass || !patternListStack.length) {
  21734. re += '\\)';
  21735. continue
  21736. }
  21737. clearStateChar();
  21738. hasMagic = true;
  21739. var pl = patternListStack.pop();
  21740. // negation is (?:(?!js)[^/]*)
  21741. // The others are (?:<pattern>)<type>
  21742. re += pl.close;
  21743. if (pl.type === '!') {
  21744. negativeLists.push(pl);
  21745. }
  21746. pl.reEnd = re.length;
  21747. continue
  21748. case '|':
  21749. if (inClass || !patternListStack.length || escaping) {
  21750. re += '\\|';
  21751. escaping = false;
  21752. continue
  21753. }
  21754. clearStateChar();
  21755. re += '|';
  21756. continue
  21757. // these are mostly the same in regexp and glob
  21758. case '[':
  21759. // swallow any state-tracking char before the [
  21760. clearStateChar();
  21761. if (inClass) {
  21762. re += '\\' + c;
  21763. continue
  21764. }
  21765. inClass = true;
  21766. classStart = i;
  21767. reClassStart = re.length;
  21768. re += c;
  21769. continue
  21770. case ']':
  21771. // a right bracket shall lose its special
  21772. // meaning and represent itself in
  21773. // a bracket expression if it occurs
  21774. // first in the list. -- POSIX.2 2.8.3.2
  21775. if (i === classStart + 1 || !inClass) {
  21776. re += '\\' + c;
  21777. escaping = false;
  21778. continue
  21779. }
  21780. // handle the case where we left a class open.
  21781. // "[z-a]" is valid, equivalent to "\[z-a\]"
  21782. if (inClass) {
  21783. // split where the last [ was, make sure we don't have
  21784. // an invalid re. if so, re-walk the contents of the
  21785. // would-be class to re-translate any characters that
  21786. // were passed through as-is
  21787. // TODO: It would probably be faster to determine this
  21788. // without a try/catch and a new RegExp, but it's tricky
  21789. // to do safely. For now, this is safe and works.
  21790. var cs = pattern.substring(classStart + 1, i);
  21791. try {
  21792. RegExp('[' + cs + ']');
  21793. } catch (er) {
  21794. // not a valid class!
  21795. var sp = this.parse(cs, SUBPARSE);
  21796. re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
  21797. hasMagic = hasMagic || sp[1];
  21798. inClass = false;
  21799. continue
  21800. }
  21801. }
  21802. // finish up the class.
  21803. hasMagic = true;
  21804. inClass = false;
  21805. re += c;
  21806. continue
  21807. default:
  21808. // swallow any state char that wasn't consumed
  21809. clearStateChar();
  21810. if (escaping) {
  21811. // no need
  21812. escaping = false;
  21813. } else if (reSpecials[c]
  21814. && !(c === '^' && inClass)) {
  21815. re += '\\';
  21816. }
  21817. re += c;
  21818. } // switch
  21819. } // for
  21820. // handle the case where we left a class open.
  21821. // "[abc" is valid, equivalent to "\[abc"
  21822. if (inClass) {
  21823. // split where the last [ was, and escape it
  21824. // this is a huge pita. We now have to re-walk
  21825. // the contents of the would-be class to re-translate
  21826. // any characters that were passed through as-is
  21827. cs = pattern.substr(classStart + 1);
  21828. sp = this.parse(cs, SUBPARSE);
  21829. re = re.substr(0, reClassStart) + '\\[' + sp[0];
  21830. hasMagic = hasMagic || sp[1];
  21831. }
  21832. // handle the case where we had a +( thing at the *end*
  21833. // of the pattern.
  21834. // each pattern list stack adds 3 chars, and we need to go through
  21835. // and escape any | chars that were passed through as-is for the regexp.
  21836. // Go through and escape them, taking care not to double-escape any
  21837. // | chars that were already escaped.
  21838. for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
  21839. var tail = re.slice(pl.reStart + pl.open.length);
  21840. this.debug('setting tail', re, pl);
  21841. // maybe some even number of \, then maybe 1 \, followed by a |
  21842. tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
  21843. if (!$2) {
  21844. // the | isn't already escaped, so escape it.
  21845. $2 = '\\';
  21846. }
  21847. // need to escape all those slashes *again*, without escaping the
  21848. // one that we need for escaping the | character. As it works out,
  21849. // escaping an even number of slashes can be done by simply repeating
  21850. // it exactly after itself. That's why this trick works.
  21851. //
  21852. // I am sorry that you have to see this.
  21853. return $1 + $1 + $2 + '|'
  21854. });
  21855. this.debug('tail=%j\n %s', tail, tail, pl, re);
  21856. var t = pl.type === '*' ? star
  21857. : pl.type === '?' ? qmark
  21858. : '\\' + pl.type;
  21859. hasMagic = true;
  21860. re = re.slice(0, pl.reStart) + t + '\\(' + tail;
  21861. }
  21862. // handle trailing things that only matter at the very end.
  21863. clearStateChar();
  21864. if (escaping) {
  21865. // trailing \\
  21866. re += '\\\\';
  21867. }
  21868. // only need to apply the nodot start if the re starts with
  21869. // something that could conceivably capture a dot
  21870. var addPatternStart = false;
  21871. switch (re.charAt(0)) {
  21872. case '.':
  21873. case '[':
  21874. case '(': addPatternStart = true;
  21875. }
  21876. // Hack to work around lack of negative lookbehind in JS
  21877. // A pattern like: *.!(x).!(y|z) needs to ensure that a name
  21878. // like 'a.xyz.yz' doesn't match. So, the first negative
  21879. // lookahead, has to look ALL the way ahead, to the end of
  21880. // the pattern.
  21881. for (var n = negativeLists.length - 1; n > -1; n--) {
  21882. var nl = negativeLists[n];
  21883. var nlBefore = re.slice(0, nl.reStart);
  21884. var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
  21885. var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
  21886. var nlAfter = re.slice(nl.reEnd);
  21887. nlLast += nlAfter;
  21888. // Handle nested stuff like *(*.js|!(*.json)), where open parens
  21889. // mean that we should *not* include the ) in the bit that is considered
  21890. // "after" the negated section.
  21891. var openParensBefore = nlBefore.split('(').length - 1;
  21892. var cleanAfter = nlAfter;
  21893. for (i = 0; i < openParensBefore; i++) {
  21894. cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
  21895. }
  21896. nlAfter = cleanAfter;
  21897. var dollar = '';
  21898. if (nlAfter === '' && isSub !== SUBPARSE) {
  21899. dollar = '$';
  21900. }
  21901. var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
  21902. re = newRe;
  21903. }
  21904. // if the re is not "" at this point, then we need to make sure
  21905. // it doesn't match against an empty path part.
  21906. // Otherwise a/* will match a/, which it should not.
  21907. if (re !== '' && hasMagic) {
  21908. re = '(?=.)' + re;
  21909. }
  21910. if (addPatternStart) {
  21911. re = patternStart + re;
  21912. }
  21913. // parsing just a piece of a larger pattern.
  21914. if (isSub === SUBPARSE) {
  21915. return [re, hasMagic]
  21916. }
  21917. // skip the regexp for non-magical patterns
  21918. // unescape anything in it, though, so that it'll be
  21919. // an exact match against a file etc.
  21920. if (!hasMagic) {
  21921. return globUnescape(pattern)
  21922. }
  21923. var flags = options.nocase ? 'i' : '';
  21924. try {
  21925. var regExp = new RegExp('^' + re + '$', flags);
  21926. } catch (er) {
  21927. // If it was an invalid regular expression, then it can't match
  21928. // anything. This trick looks for a character after the end of
  21929. // the string, which is of course impossible, except in multi-line
  21930. // mode, but it's not a /m regex.
  21931. return new RegExp('$.')
  21932. }
  21933. regExp._glob = pattern;
  21934. regExp._src = re;
  21935. return regExp
  21936. }
  21937. minimatch.makeRe = function (pattern, options) {
  21938. return new Minimatch(pattern, options || {}).makeRe()
  21939. };
  21940. Minimatch.prototype.makeRe = makeRe;
  21941. function makeRe () {
  21942. if (this.regexp || this.regexp === false) return this.regexp
  21943. // at this point, this.set is a 2d array of partial
  21944. // pattern strings, or "**".
  21945. //
  21946. // It's better to use .match(). This function shouldn't
  21947. // be used, really, but it's pretty convenient sometimes,
  21948. // when you just want to work with a regex.
  21949. var set = this.set;
  21950. if (!set.length) {
  21951. this.regexp = false;
  21952. return this.regexp
  21953. }
  21954. var options = this.options;
  21955. var twoStar = options.noglobstar ? star
  21956. : options.dot ? twoStarDot
  21957. : twoStarNoDot;
  21958. var flags = options.nocase ? 'i' : '';
  21959. var re = set.map(function (pattern) {
  21960. return pattern.map(function (p) {
  21961. return (p === GLOBSTAR) ? twoStar
  21962. : (typeof p === 'string') ? regExpEscape(p)
  21963. : p._src
  21964. }).join('\\\/')
  21965. }).join('|');
  21966. // must match entire pattern
  21967. // ending in a * or ** will make it less strict.
  21968. re = '^(?:' + re + ')$';
  21969. // can match anything, as long as it's not this.
  21970. if (this.negate) re = '^(?!' + re + ').*$';
  21971. try {
  21972. this.regexp = new RegExp(re, flags);
  21973. } catch (ex) {
  21974. this.regexp = false;
  21975. }
  21976. return this.regexp
  21977. }
  21978. minimatch.match = function (list, pattern, options) {
  21979. options = options || {};
  21980. var mm = new Minimatch(pattern, options);
  21981. list = list.filter(function (f) {
  21982. return mm.match(f)
  21983. });
  21984. if (mm.options.nonull && !list.length) {
  21985. list.push(pattern);
  21986. }
  21987. return list
  21988. };
  21989. Minimatch.prototype.match = match;
  21990. function match (f, partial) {
  21991. this.debug('match', f, this.pattern);
  21992. // short-circuit in the case of busted things.
  21993. // comments, etc.
  21994. if (this.comment) return false
  21995. if (this.empty) return f === ''
  21996. if (f === '/' && partial) return true
  21997. var options = this.options;
  21998. // windows: need to use /, not \
  21999. if (path$3.sep !== '/') {
  22000. f = f.split(path$3.sep).join('/');
  22001. }
  22002. // treat the test path as a set of pathparts.
  22003. f = f.split(slashSplit);
  22004. this.debug(this.pattern, 'split', f);
  22005. // just ONE of the pattern sets in this.set needs to match
  22006. // in order for it to be valid. If negating, then just one
  22007. // match means that we have failed.
  22008. // Either way, return on the first hit.
  22009. var set = this.set;
  22010. this.debug(this.pattern, 'set', set);
  22011. // Find the basename of the path by looking for the last non-empty segment
  22012. var filename;
  22013. var i;
  22014. for (i = f.length - 1; i >= 0; i--) {
  22015. filename = f[i];
  22016. if (filename) break
  22017. }
  22018. for (i = 0; i < set.length; i++) {
  22019. var pattern = set[i];
  22020. var file = f;
  22021. if (options.matchBase && pattern.length === 1) {
  22022. file = [filename];
  22023. }
  22024. var hit = this.matchOne(file, pattern, partial);
  22025. if (hit) {
  22026. if (options.flipNegate) return true
  22027. return !this.negate
  22028. }
  22029. }
  22030. // didn't get any hits. this is success if it's a negative
  22031. // pattern, failure otherwise.
  22032. if (options.flipNegate) return false
  22033. return this.negate
  22034. }
  22035. // set partial to true to test if, for example,
  22036. // "/a/b" matches the start of "/*/b/*/d"
  22037. // Partial means, if you run out of file before you run
  22038. // out of pattern, then that's fine, as long as all
  22039. // the parts match.
  22040. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  22041. var options = this.options;
  22042. this.debug('matchOne',
  22043. { 'this': this, file: file, pattern: pattern });
  22044. this.debug('matchOne', file.length, pattern.length);
  22045. for (var fi = 0,
  22046. pi = 0,
  22047. fl = file.length,
  22048. pl = pattern.length
  22049. ; (fi < fl) && (pi < pl)
  22050. ; fi++, pi++) {
  22051. this.debug('matchOne loop');
  22052. var p = pattern[pi];
  22053. var f = file[fi];
  22054. this.debug(pattern, p, f);
  22055. // should be impossible.
  22056. // some invalid regexp stuff in the set.
  22057. if (p === false) return false
  22058. if (p === GLOBSTAR) {
  22059. this.debug('GLOBSTAR', [pattern, p, f]);
  22060. // "**"
  22061. // a/**/b/**/c would match the following:
  22062. // a/b/x/y/z/c
  22063. // a/x/y/z/b/c
  22064. // a/b/x/b/x/c
  22065. // a/b/c
  22066. // To do this, take the rest of the pattern after
  22067. // the **, and see if it would match the file remainder.
  22068. // If so, return success.
  22069. // If not, the ** "swallows" a segment, and try again.
  22070. // This is recursively awful.
  22071. //
  22072. // a/**/b/**/c matching a/b/x/y/z/c
  22073. // - a matches a
  22074. // - doublestar
  22075. // - matchOne(b/x/y/z/c, b/**/c)
  22076. // - b matches b
  22077. // - doublestar
  22078. // - matchOne(x/y/z/c, c) -> no
  22079. // - matchOne(y/z/c, c) -> no
  22080. // - matchOne(z/c, c) -> no
  22081. // - matchOne(c, c) yes, hit
  22082. var fr = fi;
  22083. var pr = pi + 1;
  22084. if (pr === pl) {
  22085. this.debug('** at the end');
  22086. // a ** at the end will just swallow the rest.
  22087. // We have found a match.
  22088. // however, it will not swallow /.x, unless
  22089. // options.dot is set.
  22090. // . and .. are *never* matched by **, for explosively
  22091. // exponential reasons.
  22092. for (; fi < fl; fi++) {
  22093. if (file[fi] === '.' || file[fi] === '..' ||
  22094. (!options.dot && file[fi].charAt(0) === '.')) return false
  22095. }
  22096. return true
  22097. }
  22098. // ok, let's see if we can swallow whatever we can.
  22099. while (fr < fl) {
  22100. var swallowee = file[fr];
  22101. this.debug('\nglobstar while', file, fr, pattern, pr, swallowee);
  22102. // XXX remove this slice. Just pass the start index.
  22103. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  22104. this.debug('globstar found match!', fr, fl, swallowee);
  22105. // found a match.
  22106. return true
  22107. } else {
  22108. // can't swallow "." or ".." ever.
  22109. // can only swallow ".foo" when explicitly asked.
  22110. if (swallowee === '.' || swallowee === '..' ||
  22111. (!options.dot && swallowee.charAt(0) === '.')) {
  22112. this.debug('dot detected!', file, fr, pattern, pr);
  22113. break
  22114. }
  22115. // ** swallows a segment, and continue.
  22116. this.debug('globstar swallow a segment, and continue');
  22117. fr++;
  22118. }
  22119. }
  22120. // no match was found.
  22121. // However, in partial mode, we can't say this is necessarily over.
  22122. // If there's more *pattern* left, then
  22123. if (partial) {
  22124. // ran out of file
  22125. this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
  22126. if (fr === fl) return true
  22127. }
  22128. return false
  22129. }
  22130. // something other than **
  22131. // non-magic patterns just have to match exactly
  22132. // patterns with magic have been turned into regexps.
  22133. var hit;
  22134. if (typeof p === 'string') {
  22135. if (options.nocase) {
  22136. hit = f.toLowerCase() === p.toLowerCase();
  22137. } else {
  22138. hit = f === p;
  22139. }
  22140. this.debug('string match', p, f, hit);
  22141. } else {
  22142. hit = f.match(p);
  22143. this.debug('pattern match', p, f, hit);
  22144. }
  22145. if (!hit) return false
  22146. }
  22147. // Note: ending in / means that we'll get a final ""
  22148. // at the end of the pattern. This can only match a
  22149. // corresponding "" at the end of the file.
  22150. // If the file ends in /, then it can only match a
  22151. // a pattern that ends in /, unless the pattern just
  22152. // doesn't have any more for it. But, a/b/ should *not*
  22153. // match "a/b/*", even though "" matches against the
  22154. // [^/]*? pattern, except in partial mode, where it might
  22155. // simply not be reached yet.
  22156. // However, a/b/ should still satisfy a/*
  22157. // now either we fell off the end of the pattern, or we're done.
  22158. if (fi === fl && pi === pl) {
  22159. // ran out of pattern and filename at the same time.
  22160. // an exact hit!
  22161. return true
  22162. } else if (fi === fl) {
  22163. // ran out of file, but still had pattern left.
  22164. // this is ok if we're doing the match as part of
  22165. // a glob fs traversal.
  22166. return partial
  22167. } else if (pi === pl) {
  22168. // ran out of pattern, still have file left.
  22169. // this is only acceptable if we're on the very last
  22170. // empty segment of a file with a trailing slash.
  22171. // a/* should match a/b/
  22172. var emptyFileEnd = (fi === fl - 1) && (file[fi] === '');
  22173. return emptyFileEnd
  22174. }
  22175. // should be unreachable.
  22176. throw new Error('wtf?')
  22177. };
  22178. // replace stuff like \* with *
  22179. function globUnescape (s) {
  22180. return s.replace(/\\(.)/g, '$1')
  22181. }
  22182. function regExpEscape (s) {
  22183. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
  22184. }
  22185. var mimicFn = (to, from) => {
  22186. // TODO: use `Reflect.ownKeys()` when targeting Node.js 6
  22187. for (const prop of Object.getOwnPropertyNames(from).concat(Object.getOwnPropertySymbols(from))) {
  22188. Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
  22189. }
  22190. };
  22191. var mem = createCommonjsModule(function (module) {
  22192. 'use strict';
  22193. const cacheStore = new WeakMap();
  22194. const defaultCacheKey = function (x) {
  22195. if (arguments.length === 1 && (x === null || x === undefined || (typeof x !== 'function' && typeof x !== 'object'))) {
  22196. return x;
  22197. }
  22198. return JSON.stringify(arguments);
  22199. };
  22200. module.exports = (fn, opts) => {
  22201. opts = Object.assign({
  22202. cacheKey: defaultCacheKey,
  22203. cache: new Map()
  22204. }, opts);
  22205. const memoized = function () {
  22206. const cache = cacheStore.get(memoized);
  22207. const key = opts.cacheKey.apply(null, arguments);
  22208. if (cache.has(key)) {
  22209. const c = cache.get(key);
  22210. if (typeof opts.maxAge !== 'number' || Date.now() < c.maxAge) {
  22211. return c.data;
  22212. }
  22213. }
  22214. const ret = fn.apply(null, arguments);
  22215. cache.set(key, {
  22216. data: ret,
  22217. maxAge: Date.now() + (opts.maxAge || 0)
  22218. });
  22219. return ret;
  22220. };
  22221. mimicFn(memoized, fn);
  22222. cacheStore.set(memoized, opts.cache);
  22223. return memoized;
  22224. };
  22225. module.exports.clear = fn => {
  22226. const cache = cacheStore.get(fn);
  22227. if (cache && typeof cache.clear === 'function') {
  22228. cache.clear();
  22229. }
  22230. };
  22231. });
  22232. var semver$3 = createCommonjsModule(function (module, exports) {
  22233. exports = module.exports = SemVer;
  22234. // The debug function is excluded entirely from the minified version.
  22235. /* nomin */ var debug;
  22236. /* nomin */ if (typeof process === 'object' &&
  22237. /* nomin */ process.env &&
  22238. /* nomin */ process.env.NODE_DEBUG &&
  22239. /* nomin */ /\bsemver\b/i.test(process.env.NODE_DEBUG))
  22240. /* nomin */ debug = function() {
  22241. /* nomin */ var args = Array.prototype.slice.call(arguments, 0);
  22242. /* nomin */ args.unshift('SEMVER');
  22243. /* nomin */ console.log.apply(console, args);
  22244. /* nomin */ };
  22245. /* nomin */ else
  22246. /* nomin */ debug = function() {};
  22247. // Note: this is the semver.org version of the spec that it implements
  22248. // Not necessarily the package version of this code.
  22249. exports.SEMVER_SPEC_VERSION = '2.0.0';
  22250. var MAX_LENGTH = 256;
  22251. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
  22252. // Max safe segment length for coercion.
  22253. var MAX_SAFE_COMPONENT_LENGTH = 16;
  22254. // The actual regexps go on exports.re
  22255. var re = exports.re = [];
  22256. var src = exports.src = [];
  22257. var R = 0;
  22258. // The following Regular Expressions can be used for tokenizing,
  22259. // validating, and parsing SemVer version strings.
  22260. // ## Numeric Identifier
  22261. // A single `0`, or a non-zero digit followed by zero or more digits.
  22262. var NUMERICIDENTIFIER = R++;
  22263. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  22264. var NUMERICIDENTIFIERLOOSE = R++;
  22265. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+';
  22266. // ## Non-numeric Identifier
  22267. // Zero or more digits, followed by a letter or hyphen, and then zero or
  22268. // more letters, digits, or hyphens.
  22269. var NONNUMERICIDENTIFIER = R++;
  22270. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*';
  22271. // ## Main Version
  22272. // Three dot-separated numeric identifiers.
  22273. var MAINVERSION = R++;
  22274. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' +
  22275. '(' + src[NUMERICIDENTIFIER] + ')\\.' +
  22276. '(' + src[NUMERICIDENTIFIER] + ')';
  22277. var MAINVERSIONLOOSE = R++;
  22278. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
  22279. '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
  22280. '(' + src[NUMERICIDENTIFIERLOOSE] + ')';
  22281. // ## Pre-release Version Identifier
  22282. // A numeric identifier, or a non-numeric identifier.
  22283. var PRERELEASEIDENTIFIER = R++;
  22284. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] +
  22285. '|' + src[NONNUMERICIDENTIFIER] + ')';
  22286. var PRERELEASEIDENTIFIERLOOSE = R++;
  22287. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] +
  22288. '|' + src[NONNUMERICIDENTIFIER] + ')';
  22289. // ## Pre-release Version
  22290. // Hyphen, followed by one or more dot-separated pre-release version
  22291. // identifiers.
  22292. var PRERELEASE = R++;
  22293. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] +
  22294. '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  22295. var PRERELEASELOOSE = R++;
  22296. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] +
  22297. '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))';
  22298. // ## Build Metadata Identifier
  22299. // Any combination of digits, letters, or hyphens.
  22300. var BUILDIDENTIFIER = R++;
  22301. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+';
  22302. // ## Build Metadata
  22303. // Plus sign, followed by one or more period-separated build metadata
  22304. // identifiers.
  22305. var BUILD = R++;
  22306. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] +
  22307. '(?:\\.' + src[BUILDIDENTIFIER] + ')*))';
  22308. // ## Full Version String
  22309. // A main version, followed optionally by a pre-release version and
  22310. // build metadata.
  22311. // Note that the only major, minor, patch, and pre-release sections of
  22312. // the version string are capturing groups. The build metadata is not a
  22313. // capturing group, because it should not ever be used in version
  22314. // comparison.
  22315. var FULL = R++;
  22316. var FULLPLAIN = 'v?' + src[MAINVERSION] +
  22317. src[PRERELEASE] + '?' +
  22318. src[BUILD] + '?';
  22319. src[FULL] = '^' + FULLPLAIN + '$';
  22320. // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  22321. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  22322. // common in the npm registry.
  22323. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] +
  22324. src[PRERELEASELOOSE] + '?' +
  22325. src[BUILD] + '?';
  22326. var LOOSE = R++;
  22327. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  22328. var GTLT = R++;
  22329. src[GTLT] = '((?:<|>)?=?)';
  22330. // Something like "2.*" or "1.2.x".
  22331. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  22332. // Only the first item is strictly required.
  22333. var XRANGEIDENTIFIERLOOSE = R++;
  22334. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  22335. var XRANGEIDENTIFIER = R++;
  22336. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  22337. var XRANGEPLAIN = R++;
  22338. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' +
  22339. '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
  22340. '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
  22341. '(?:' + src[PRERELEASE] + ')?' +
  22342. src[BUILD] + '?' +
  22343. ')?)?';
  22344. var XRANGEPLAINLOOSE = R++;
  22345. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
  22346. '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
  22347. '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
  22348. '(?:' + src[PRERELEASELOOSE] + ')?' +
  22349. src[BUILD] + '?' +
  22350. ')?)?';
  22351. var XRANGE = R++;
  22352. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  22353. var XRANGELOOSE = R++;
  22354. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$';
  22355. // Coercion.
  22356. // Extract anything that could conceivably be a part of a valid semver
  22357. var COERCE = R++;
  22358. src[COERCE] = '(?:^|[^\\d])' +
  22359. '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' +
  22360. '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
  22361. '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
  22362. '(?:$|[^\\d])';
  22363. // Tilde ranges.
  22364. // Meaning is "reasonably at or greater than"
  22365. var LONETILDE = R++;
  22366. src[LONETILDE] = '(?:~>?)';
  22367. var TILDETRIM = R++;
  22368. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  22369. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  22370. var tildeTrimReplace = '$1~';
  22371. var TILDE = R++;
  22372. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  22373. var TILDELOOSE = R++;
  22374. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$';
  22375. // Caret ranges.
  22376. // Meaning is "at least and backwards compatible with"
  22377. var LONECARET = R++;
  22378. src[LONECARET] = '(?:\\^)';
  22379. var CARETTRIM = R++;
  22380. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  22381. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  22382. var caretTrimReplace = '$1^';
  22383. var CARET = R++;
  22384. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  22385. var CARETLOOSE = R++;
  22386. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$';
  22387. // A simple gt/lt/eq thing, or just "" to indicate "any version"
  22388. var COMPARATORLOOSE = R++;
  22389. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  22390. var COMPARATOR = R++;
  22391. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$';
  22392. // An expression to strip any whitespace between the gtlt and the thing
  22393. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  22394. var COMPARATORTRIM = R++;
  22395. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] +
  22396. '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')';
  22397. // this one has to use the /g flag
  22398. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  22399. var comparatorTrimReplace = '$1$2$3';
  22400. // Something like `1.2.3 - 1.2.4`
  22401. // Note that these all use the loose form, because they'll be
  22402. // checked against either the strict or loose comparator form
  22403. // later.
  22404. var HYPHENRANGE = R++;
  22405. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' +
  22406. '\\s+-\\s+' +
  22407. '(' + src[XRANGEPLAIN] + ')' +
  22408. '\\s*$';
  22409. var HYPHENRANGELOOSE = R++;
  22410. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' +
  22411. '\\s+-\\s+' +
  22412. '(' + src[XRANGEPLAINLOOSE] + ')' +
  22413. '\\s*$';
  22414. // Star ranges basically just allow anything at all.
  22415. var STAR = R++;
  22416. src[STAR] = '(<|>)?=?\\s*\\*';
  22417. // Compile to actual regexp objects.
  22418. // All are flag-free, unless they were created above with a flag.
  22419. for (var i = 0; i < R; i++) {
  22420. debug(i, src[i]);
  22421. if (!re[i])
  22422. re[i] = new RegExp(src[i]);
  22423. }
  22424. exports.parse = parse;
  22425. function parse(version, loose) {
  22426. if (version instanceof SemVer)
  22427. return version;
  22428. if (typeof version !== 'string')
  22429. return null;
  22430. if (version.length > MAX_LENGTH)
  22431. return null;
  22432. var r = loose ? re[LOOSE] : re[FULL];
  22433. if (!r.test(version))
  22434. return null;
  22435. try {
  22436. return new SemVer(version, loose);
  22437. } catch (er) {
  22438. return null;
  22439. }
  22440. }
  22441. exports.valid = valid;
  22442. function valid(version, loose) {
  22443. var v = parse(version, loose);
  22444. return v ? v.version : null;
  22445. }
  22446. exports.clean = clean;
  22447. function clean(version, loose) {
  22448. var s = parse(version.trim().replace(/^[=v]+/, ''), loose);
  22449. return s ? s.version : null;
  22450. }
  22451. exports.SemVer = SemVer;
  22452. function SemVer(version, loose) {
  22453. if (version instanceof SemVer) {
  22454. if (version.loose === loose)
  22455. return version;
  22456. else
  22457. version = version.version;
  22458. } else if (typeof version !== 'string') {
  22459. throw new TypeError('Invalid Version: ' + version);
  22460. }
  22461. if (version.length > MAX_LENGTH)
  22462. throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters')
  22463. if (!(this instanceof SemVer))
  22464. return new SemVer(version, loose);
  22465. debug('SemVer', version, loose);
  22466. this.loose = loose;
  22467. var m = version.trim().match(loose ? re[LOOSE] : re[FULL]);
  22468. if (!m)
  22469. throw new TypeError('Invalid Version: ' + version);
  22470. this.raw = version;
  22471. // these are actually numbers
  22472. this.major = +m[1];
  22473. this.minor = +m[2];
  22474. this.patch = +m[3];
  22475. if (this.major > MAX_SAFE_INTEGER || this.major < 0)
  22476. throw new TypeError('Invalid major version')
  22477. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0)
  22478. throw new TypeError('Invalid minor version')
  22479. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0)
  22480. throw new TypeError('Invalid patch version')
  22481. // numberify any prerelease numeric ids
  22482. if (!m[4])
  22483. this.prerelease = [];
  22484. else
  22485. this.prerelease = m[4].split('.').map(function(id) {
  22486. if (/^[0-9]+$/.test(id)) {
  22487. var num = +id;
  22488. if (num >= 0 && num < MAX_SAFE_INTEGER)
  22489. return num;
  22490. }
  22491. return id;
  22492. });
  22493. this.build = m[5] ? m[5].split('.') : [];
  22494. this.format();
  22495. }
  22496. SemVer.prototype.format = function() {
  22497. this.version = this.major + '.' + this.minor + '.' + this.patch;
  22498. if (this.prerelease.length)
  22499. this.version += '-' + this.prerelease.join('.');
  22500. return this.version;
  22501. };
  22502. SemVer.prototype.toString = function() {
  22503. return this.version;
  22504. };
  22505. SemVer.prototype.compare = function(other) {
  22506. debug('SemVer.compare', this.version, this.loose, other);
  22507. if (!(other instanceof SemVer))
  22508. other = new SemVer(other, this.loose);
  22509. return this.compareMain(other) || this.comparePre(other);
  22510. };
  22511. SemVer.prototype.compareMain = function(other) {
  22512. if (!(other instanceof SemVer))
  22513. other = new SemVer(other, this.loose);
  22514. return compareIdentifiers(this.major, other.major) ||
  22515. compareIdentifiers(this.minor, other.minor) ||
  22516. compareIdentifiers(this.patch, other.patch);
  22517. };
  22518. SemVer.prototype.comparePre = function(other) {
  22519. if (!(other instanceof SemVer))
  22520. other = new SemVer(other, this.loose);
  22521. // NOT having a prerelease is > having one
  22522. if (this.prerelease.length && !other.prerelease.length)
  22523. return -1;
  22524. else if (!this.prerelease.length && other.prerelease.length)
  22525. return 1;
  22526. else if (!this.prerelease.length && !other.prerelease.length)
  22527. return 0;
  22528. var i = 0;
  22529. do {
  22530. var a = this.prerelease[i];
  22531. var b = other.prerelease[i];
  22532. debug('prerelease compare', i, a, b);
  22533. if (a === undefined && b === undefined)
  22534. return 0;
  22535. else if (b === undefined)
  22536. return 1;
  22537. else if (a === undefined)
  22538. return -1;
  22539. else if (a === b)
  22540. continue;
  22541. else
  22542. return compareIdentifiers(a, b);
  22543. } while (++i);
  22544. };
  22545. // preminor will bump the version up to the next minor release, and immediately
  22546. // down to pre-release. premajor and prepatch work the same way.
  22547. SemVer.prototype.inc = function(release, identifier) {
  22548. switch (release) {
  22549. case 'premajor':
  22550. this.prerelease.length = 0;
  22551. this.patch = 0;
  22552. this.minor = 0;
  22553. this.major++;
  22554. this.inc('pre', identifier);
  22555. break;
  22556. case 'preminor':
  22557. this.prerelease.length = 0;
  22558. this.patch = 0;
  22559. this.minor++;
  22560. this.inc('pre', identifier);
  22561. break;
  22562. case 'prepatch':
  22563. // If this is already a prerelease, it will bump to the next version
  22564. // drop any prereleases that might already exist, since they are not
  22565. // relevant at this point.
  22566. this.prerelease.length = 0;
  22567. this.inc('patch', identifier);
  22568. this.inc('pre', identifier);
  22569. break;
  22570. // If the input is a non-prerelease version, this acts the same as
  22571. // prepatch.
  22572. case 'prerelease':
  22573. if (this.prerelease.length === 0)
  22574. this.inc('patch', identifier);
  22575. this.inc('pre', identifier);
  22576. break;
  22577. case 'major':
  22578. // If this is a pre-major version, bump up to the same major version.
  22579. // Otherwise increment major.
  22580. // 1.0.0-5 bumps to 1.0.0
  22581. // 1.1.0 bumps to 2.0.0
  22582. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0)
  22583. this.major++;
  22584. this.minor = 0;
  22585. this.patch = 0;
  22586. this.prerelease = [];
  22587. break;
  22588. case 'minor':
  22589. // If this is a pre-minor version, bump up to the same minor version.
  22590. // Otherwise increment minor.
  22591. // 1.2.0-5 bumps to 1.2.0
  22592. // 1.2.1 bumps to 1.3.0
  22593. if (this.patch !== 0 || this.prerelease.length === 0)
  22594. this.minor++;
  22595. this.patch = 0;
  22596. this.prerelease = [];
  22597. break;
  22598. case 'patch':
  22599. // If this is not a pre-release version, it will increment the patch.
  22600. // If it is a pre-release it will bump up to the same patch version.
  22601. // 1.2.0-5 patches to 1.2.0
  22602. // 1.2.0 patches to 1.2.1
  22603. if (this.prerelease.length === 0)
  22604. this.patch++;
  22605. this.prerelease = [];
  22606. break;
  22607. // This probably shouldn't be used publicly.
  22608. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  22609. case 'pre':
  22610. if (this.prerelease.length === 0)
  22611. this.prerelease = [0];
  22612. else {
  22613. var i = this.prerelease.length;
  22614. while (--i >= 0) {
  22615. if (typeof this.prerelease[i] === 'number') {
  22616. this.prerelease[i]++;
  22617. i = -2;
  22618. }
  22619. }
  22620. if (i === -1) // didn't increment anything
  22621. this.prerelease.push(0);
  22622. }
  22623. if (identifier) {
  22624. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  22625. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  22626. if (this.prerelease[0] === identifier) {
  22627. if (isNaN(this.prerelease[1]))
  22628. this.prerelease = [identifier, 0];
  22629. } else
  22630. this.prerelease = [identifier, 0];
  22631. }
  22632. break;
  22633. default:
  22634. throw new Error('invalid increment argument: ' + release);
  22635. }
  22636. this.format();
  22637. this.raw = this.version;
  22638. return this;
  22639. };
  22640. exports.inc = inc;
  22641. function inc(version, release, loose, identifier) {
  22642. if (typeof(loose) === 'string') {
  22643. identifier = loose;
  22644. loose = undefined;
  22645. }
  22646. try {
  22647. return new SemVer(version, loose).inc(release, identifier).version;
  22648. } catch (er) {
  22649. return null;
  22650. }
  22651. }
  22652. exports.diff = diff;
  22653. function diff(version1, version2) {
  22654. if (eq(version1, version2)) {
  22655. return null;
  22656. } else {
  22657. var v1 = parse(version1);
  22658. var v2 = parse(version2);
  22659. if (v1.prerelease.length || v2.prerelease.length) {
  22660. for (var key in v1) {
  22661. if (key === 'major' || key === 'minor' || key === 'patch') {
  22662. if (v1[key] !== v2[key]) {
  22663. return 'pre'+key;
  22664. }
  22665. }
  22666. }
  22667. return 'prerelease';
  22668. }
  22669. for (var key in v1) {
  22670. if (key === 'major' || key === 'minor' || key === 'patch') {
  22671. if (v1[key] !== v2[key]) {
  22672. return key;
  22673. }
  22674. }
  22675. }
  22676. }
  22677. }
  22678. exports.compareIdentifiers = compareIdentifiers;
  22679. var numeric = /^[0-9]+$/;
  22680. function compareIdentifiers(a, b) {
  22681. var anum = numeric.test(a);
  22682. var bnum = numeric.test(b);
  22683. if (anum && bnum) {
  22684. a = +a;
  22685. b = +b;
  22686. }
  22687. return (anum && !bnum) ? -1 :
  22688. (bnum && !anum) ? 1 :
  22689. a < b ? -1 :
  22690. a > b ? 1 :
  22691. 0;
  22692. }
  22693. exports.rcompareIdentifiers = rcompareIdentifiers;
  22694. function rcompareIdentifiers(a, b) {
  22695. return compareIdentifiers(b, a);
  22696. }
  22697. exports.major = major;
  22698. function major(a, loose) {
  22699. return new SemVer(a, loose).major;
  22700. }
  22701. exports.minor = minor;
  22702. function minor(a, loose) {
  22703. return new SemVer(a, loose).minor;
  22704. }
  22705. exports.patch = patch;
  22706. function patch(a, loose) {
  22707. return new SemVer(a, loose).patch;
  22708. }
  22709. exports.compare = compare;
  22710. function compare(a, b, loose) {
  22711. return new SemVer(a, loose).compare(new SemVer(b, loose));
  22712. }
  22713. exports.compareLoose = compareLoose;
  22714. function compareLoose(a, b) {
  22715. return compare(a, b, true);
  22716. }
  22717. exports.rcompare = rcompare;
  22718. function rcompare(a, b, loose) {
  22719. return compare(b, a, loose);
  22720. }
  22721. exports.sort = sort;
  22722. function sort(list, loose) {
  22723. return list.sort(function(a, b) {
  22724. return exports.compare(a, b, loose);
  22725. });
  22726. }
  22727. exports.rsort = rsort;
  22728. function rsort(list, loose) {
  22729. return list.sort(function(a, b) {
  22730. return exports.rcompare(a, b, loose);
  22731. });
  22732. }
  22733. exports.gt = gt;
  22734. function gt(a, b, loose) {
  22735. return compare(a, b, loose) > 0;
  22736. }
  22737. exports.lt = lt;
  22738. function lt(a, b, loose) {
  22739. return compare(a, b, loose) < 0;
  22740. }
  22741. exports.eq = eq;
  22742. function eq(a, b, loose) {
  22743. return compare(a, b, loose) === 0;
  22744. }
  22745. exports.neq = neq;
  22746. function neq(a, b, loose) {
  22747. return compare(a, b, loose) !== 0;
  22748. }
  22749. exports.gte = gte;
  22750. function gte(a, b, loose) {
  22751. return compare(a, b, loose) >= 0;
  22752. }
  22753. exports.lte = lte;
  22754. function lte(a, b, loose) {
  22755. return compare(a, b, loose) <= 0;
  22756. }
  22757. exports.cmp = cmp;
  22758. function cmp(a, op, b, loose) {
  22759. var ret;
  22760. switch (op) {
  22761. case '===':
  22762. if (typeof a === 'object') a = a.version;
  22763. if (typeof b === 'object') b = b.version;
  22764. ret = a === b;
  22765. break;
  22766. case '!==':
  22767. if (typeof a === 'object') a = a.version;
  22768. if (typeof b === 'object') b = b.version;
  22769. ret = a !== b;
  22770. break;
  22771. case '': case '=': case '==': ret = eq(a, b, loose); break;
  22772. case '!=': ret = neq(a, b, loose); break;
  22773. case '>': ret = gt(a, b, loose); break;
  22774. case '>=': ret = gte(a, b, loose); break;
  22775. case '<': ret = lt(a, b, loose); break;
  22776. case '<=': ret = lte(a, b, loose); break;
  22777. default: throw new TypeError('Invalid operator: ' + op);
  22778. }
  22779. return ret;
  22780. }
  22781. exports.Comparator = Comparator;
  22782. function Comparator(comp, loose) {
  22783. if (comp instanceof Comparator) {
  22784. if (comp.loose === loose)
  22785. return comp;
  22786. else
  22787. comp = comp.value;
  22788. }
  22789. if (!(this instanceof Comparator))
  22790. return new Comparator(comp, loose);
  22791. debug('comparator', comp, loose);
  22792. this.loose = loose;
  22793. this.parse(comp);
  22794. if (this.semver === ANY)
  22795. this.value = '';
  22796. else
  22797. this.value = this.operator + this.semver.version;
  22798. debug('comp', this);
  22799. }
  22800. var ANY = {};
  22801. Comparator.prototype.parse = function(comp) {
  22802. var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  22803. var m = comp.match(r);
  22804. if (!m)
  22805. throw new TypeError('Invalid comparator: ' + comp);
  22806. this.operator = m[1];
  22807. if (this.operator === '=')
  22808. this.operator = '';
  22809. // if it literally is just '>' or '' then allow anything.
  22810. if (!m[2])
  22811. this.semver = ANY;
  22812. else
  22813. this.semver = new SemVer(m[2], this.loose);
  22814. };
  22815. Comparator.prototype.toString = function() {
  22816. return this.value;
  22817. };
  22818. Comparator.prototype.test = function(version) {
  22819. debug('Comparator.test', version, this.loose);
  22820. if (this.semver === ANY)
  22821. return true;
  22822. if (typeof version === 'string')
  22823. version = new SemVer(version, this.loose);
  22824. return cmp(version, this.operator, this.semver, this.loose);
  22825. };
  22826. Comparator.prototype.intersects = function(comp, loose) {
  22827. if (!(comp instanceof Comparator)) {
  22828. throw new TypeError('a Comparator is required');
  22829. }
  22830. var rangeTmp;
  22831. if (this.operator === '') {
  22832. rangeTmp = new Range(comp.value, loose);
  22833. return satisfies(this.value, rangeTmp, loose);
  22834. } else if (comp.operator === '') {
  22835. rangeTmp = new Range(this.value, loose);
  22836. return satisfies(comp.semver, rangeTmp, loose);
  22837. }
  22838. var sameDirectionIncreasing =
  22839. (this.operator === '>=' || this.operator === '>') &&
  22840. (comp.operator === '>=' || comp.operator === '>');
  22841. var sameDirectionDecreasing =
  22842. (this.operator === '<=' || this.operator === '<') &&
  22843. (comp.operator === '<=' || comp.operator === '<');
  22844. var sameSemVer = this.semver.version === comp.semver.version;
  22845. var differentDirectionsInclusive =
  22846. (this.operator === '>=' || this.operator === '<=') &&
  22847. (comp.operator === '>=' || comp.operator === '<=');
  22848. var oppositeDirectionsLessThan =
  22849. cmp(this.semver, '<', comp.semver, loose) &&
  22850. ((this.operator === '>=' || this.operator === '>') &&
  22851. (comp.operator === '<=' || comp.operator === '<'));
  22852. var oppositeDirectionsGreaterThan =
  22853. cmp(this.semver, '>', comp.semver, loose) &&
  22854. ((this.operator === '<=' || this.operator === '<') &&
  22855. (comp.operator === '>=' || comp.operator === '>'));
  22856. return sameDirectionIncreasing || sameDirectionDecreasing ||
  22857. (sameSemVer && differentDirectionsInclusive) ||
  22858. oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  22859. };
  22860. exports.Range = Range;
  22861. function Range(range, loose) {
  22862. if (range instanceof Range) {
  22863. if (range.loose === loose) {
  22864. return range;
  22865. } else {
  22866. return new Range(range.raw, loose);
  22867. }
  22868. }
  22869. if (range instanceof Comparator) {
  22870. return new Range(range.value, loose);
  22871. }
  22872. if (!(this instanceof Range))
  22873. return new Range(range, loose);
  22874. this.loose = loose;
  22875. // First, split based on boolean or ||
  22876. this.raw = range;
  22877. this.set = range.split(/\s*\|\|\s*/).map(function(range) {
  22878. return this.parseRange(range.trim());
  22879. }, this).filter(function(c) {
  22880. // throw out any that are not relevant for whatever reason
  22881. return c.length;
  22882. });
  22883. if (!this.set.length) {
  22884. throw new TypeError('Invalid SemVer Range: ' + range);
  22885. }
  22886. this.format();
  22887. }
  22888. Range.prototype.format = function() {
  22889. this.range = this.set.map(function(comps) {
  22890. return comps.join(' ').trim();
  22891. }).join('||').trim();
  22892. return this.range;
  22893. };
  22894. Range.prototype.toString = function() {
  22895. return this.range;
  22896. };
  22897. Range.prototype.parseRange = function(range) {
  22898. var loose = this.loose;
  22899. range = range.trim();
  22900. debug('range', range, loose);
  22901. // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  22902. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  22903. range = range.replace(hr, hyphenReplace);
  22904. debug('hyphen replace', range);
  22905. // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  22906. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  22907. debug('comparator trim', range, re[COMPARATORTRIM]);
  22908. // `~ 1.2.3` => `~1.2.3`
  22909. range = range.replace(re[TILDETRIM], tildeTrimReplace);
  22910. // `^ 1.2.3` => `^1.2.3`
  22911. range = range.replace(re[CARETTRIM], caretTrimReplace);
  22912. // normalize spaces
  22913. range = range.split(/\s+/).join(' ');
  22914. // At this point, the range is completely trimmed and
  22915. // ready to be split into comparators.
  22916. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  22917. var set = range.split(' ').map(function(comp) {
  22918. return parseComparator(comp, loose);
  22919. }).join(' ').split(/\s+/);
  22920. if (this.loose) {
  22921. // in loose mode, throw out any that are not valid comparators
  22922. set = set.filter(function(comp) {
  22923. return !!comp.match(compRe);
  22924. });
  22925. }
  22926. set = set.map(function(comp) {
  22927. return new Comparator(comp, loose);
  22928. });
  22929. return set;
  22930. };
  22931. Range.prototype.intersects = function(range, loose) {
  22932. if (!(range instanceof Range)) {
  22933. throw new TypeError('a Range is required');
  22934. }
  22935. return this.set.some(function(thisComparators) {
  22936. return thisComparators.every(function(thisComparator) {
  22937. return range.set.some(function(rangeComparators) {
  22938. return rangeComparators.every(function(rangeComparator) {
  22939. return thisComparator.intersects(rangeComparator, loose);
  22940. });
  22941. });
  22942. });
  22943. });
  22944. };
  22945. // Mostly just for testing and legacy API reasons
  22946. exports.toComparators = toComparators;
  22947. function toComparators(range, loose) {
  22948. return new Range(range, loose).set.map(function(comp) {
  22949. return comp.map(function(c) {
  22950. return c.value;
  22951. }).join(' ').trim().split(' ');
  22952. });
  22953. }
  22954. // comprised of xranges, tildes, stars, and gtlt's at this point.
  22955. // already replaced the hyphen ranges
  22956. // turn into a set of JUST comparators.
  22957. function parseComparator(comp, loose) {
  22958. debug('comp', comp);
  22959. comp = replaceCarets(comp, loose);
  22960. debug('caret', comp);
  22961. comp = replaceTildes(comp, loose);
  22962. debug('tildes', comp);
  22963. comp = replaceXRanges(comp, loose);
  22964. debug('xrange', comp);
  22965. comp = replaceStars(comp, loose);
  22966. debug('stars', comp);
  22967. return comp;
  22968. }
  22969. function isX(id) {
  22970. return !id || id.toLowerCase() === 'x' || id === '*';
  22971. }
  22972. // ~, ~> --> * (any, kinda silly)
  22973. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  22974. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  22975. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  22976. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  22977. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  22978. function replaceTildes(comp, loose) {
  22979. return comp.trim().split(/\s+/).map(function(comp) {
  22980. return replaceTilde(comp, loose);
  22981. }).join(' ');
  22982. }
  22983. function replaceTilde(comp, loose) {
  22984. var r = loose ? re[TILDELOOSE] : re[TILDE];
  22985. return comp.replace(r, function(_, M, m, p, pr) {
  22986. debug('tilde', comp, _, M, m, p, pr);
  22987. var ret;
  22988. if (isX(M))
  22989. ret = '';
  22990. else if (isX(m))
  22991. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  22992. else if (isX(p))
  22993. // ~1.2 == >=1.2.0 <1.3.0
  22994. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  22995. else if (pr) {
  22996. debug('replaceTilde pr', pr);
  22997. if (pr.charAt(0) !== '-')
  22998. pr = '-' + pr;
  22999. ret = '>=' + M + '.' + m + '.' + p + pr +
  23000. ' <' + M + '.' + (+m + 1) + '.0';
  23001. } else
  23002. // ~1.2.3 == >=1.2.3 <1.3.0
  23003. ret = '>=' + M + '.' + m + '.' + p +
  23004. ' <' + M + '.' + (+m + 1) + '.0';
  23005. debug('tilde return', ret);
  23006. return ret;
  23007. });
  23008. }
  23009. // ^ --> * (any, kinda silly)
  23010. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  23011. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  23012. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  23013. // ^1.2.3 --> >=1.2.3 <2.0.0
  23014. // ^1.2.0 --> >=1.2.0 <2.0.0
  23015. function replaceCarets(comp, loose) {
  23016. return comp.trim().split(/\s+/).map(function(comp) {
  23017. return replaceCaret(comp, loose);
  23018. }).join(' ');
  23019. }
  23020. function replaceCaret(comp, loose) {
  23021. debug('caret', comp, loose);
  23022. var r = loose ? re[CARETLOOSE] : re[CARET];
  23023. return comp.replace(r, function(_, M, m, p, pr) {
  23024. debug('caret', comp, _, M, m, p, pr);
  23025. var ret;
  23026. if (isX(M))
  23027. ret = '';
  23028. else if (isX(m))
  23029. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  23030. else if (isX(p)) {
  23031. if (M === '0')
  23032. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  23033. else
  23034. ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  23035. } else if (pr) {
  23036. debug('replaceCaret pr', pr);
  23037. if (pr.charAt(0) !== '-')
  23038. pr = '-' + pr;
  23039. if (M === '0') {
  23040. if (m === '0')
  23041. ret = '>=' + M + '.' + m + '.' + p + pr +
  23042. ' <' + M + '.' + m + '.' + (+p + 1);
  23043. else
  23044. ret = '>=' + M + '.' + m + '.' + p + pr +
  23045. ' <' + M + '.' + (+m + 1) + '.0';
  23046. } else
  23047. ret = '>=' + M + '.' + m + '.' + p + pr +
  23048. ' <' + (+M + 1) + '.0.0';
  23049. } else {
  23050. debug('no pr');
  23051. if (M === '0') {
  23052. if (m === '0')
  23053. ret = '>=' + M + '.' + m + '.' + p +
  23054. ' <' + M + '.' + m + '.' + (+p + 1);
  23055. else
  23056. ret = '>=' + M + '.' + m + '.' + p +
  23057. ' <' + M + '.' + (+m + 1) + '.0';
  23058. } else
  23059. ret = '>=' + M + '.' + m + '.' + p +
  23060. ' <' + (+M + 1) + '.0.0';
  23061. }
  23062. debug('caret return', ret);
  23063. return ret;
  23064. });
  23065. }
  23066. function replaceXRanges(comp, loose) {
  23067. debug('replaceXRanges', comp, loose);
  23068. return comp.split(/\s+/).map(function(comp) {
  23069. return replaceXRange(comp, loose);
  23070. }).join(' ');
  23071. }
  23072. function replaceXRange(comp, loose) {
  23073. comp = comp.trim();
  23074. var r = loose ? re[XRANGELOOSE] : re[XRANGE];
  23075. return comp.replace(r, function(ret, gtlt, M, m, p, pr) {
  23076. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  23077. var xM = isX(M);
  23078. var xm = xM || isX(m);
  23079. var xp = xm || isX(p);
  23080. var anyX = xp;
  23081. if (gtlt === '=' && anyX)
  23082. gtlt = '';
  23083. if (xM) {
  23084. if (gtlt === '>' || gtlt === '<') {
  23085. // nothing is allowed
  23086. ret = '<0.0.0';
  23087. } else {
  23088. // nothing is forbidden
  23089. ret = '*';
  23090. }
  23091. } else if (gtlt && anyX) {
  23092. // replace X with 0
  23093. if (xm)
  23094. m = 0;
  23095. if (xp)
  23096. p = 0;
  23097. if (gtlt === '>') {
  23098. // >1 => >=2.0.0
  23099. // >1.2 => >=1.3.0
  23100. // >1.2.3 => >= 1.2.4
  23101. gtlt = '>=';
  23102. if (xm) {
  23103. M = +M + 1;
  23104. m = 0;
  23105. p = 0;
  23106. } else if (xp) {
  23107. m = +m + 1;
  23108. p = 0;
  23109. }
  23110. } else if (gtlt === '<=') {
  23111. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  23112. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  23113. gtlt = '<';
  23114. if (xm)
  23115. M = +M + 1;
  23116. else
  23117. m = +m + 1;
  23118. }
  23119. ret = gtlt + M + '.' + m + '.' + p;
  23120. } else if (xm) {
  23121. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  23122. } else if (xp) {
  23123. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  23124. }
  23125. debug('xRange return', ret);
  23126. return ret;
  23127. });
  23128. }
  23129. // Because * is AND-ed with everything else in the comparator,
  23130. // and '' means "any version", just remove the *s entirely.
  23131. function replaceStars(comp, loose) {
  23132. debug('replaceStars', comp, loose);
  23133. // Looseness is ignored here. star is always as loose as it gets!
  23134. return comp.trim().replace(re[STAR], '');
  23135. }
  23136. // This function is passed to string.replace(re[HYPHENRANGE])
  23137. // M, m, patch, prerelease, build
  23138. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  23139. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  23140. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  23141. function hyphenReplace($0,
  23142. from, fM, fm, fp, fpr, fb,
  23143. to, tM, tm, tp, tpr, tb) {
  23144. if (isX(fM))
  23145. from = '';
  23146. else if (isX(fm))
  23147. from = '>=' + fM + '.0.0';
  23148. else if (isX(fp))
  23149. from = '>=' + fM + '.' + fm + '.0';
  23150. else
  23151. from = '>=' + from;
  23152. if (isX(tM))
  23153. to = '';
  23154. else if (isX(tm))
  23155. to = '<' + (+tM + 1) + '.0.0';
  23156. else if (isX(tp))
  23157. to = '<' + tM + '.' + (+tm + 1) + '.0';
  23158. else if (tpr)
  23159. to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
  23160. else
  23161. to = '<=' + to;
  23162. return (from + ' ' + to).trim();
  23163. }
  23164. // if ANY of the sets match ALL of its comparators, then pass
  23165. Range.prototype.test = function(version) {
  23166. if (!version)
  23167. return false;
  23168. if (typeof version === 'string')
  23169. version = new SemVer(version, this.loose);
  23170. for (var i = 0; i < this.set.length; i++) {
  23171. if (testSet(this.set[i], version))
  23172. return true;
  23173. }
  23174. return false;
  23175. };
  23176. function testSet(set, version) {
  23177. for (var i = 0; i < set.length; i++) {
  23178. if (!set[i].test(version))
  23179. return false;
  23180. }
  23181. if (version.prerelease.length) {
  23182. // Find the set of versions that are allowed to have prereleases
  23183. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  23184. // That should allow `1.2.3-pr.2` to pass.
  23185. // However, `1.2.4-alpha.notready` should NOT be allowed,
  23186. // even though it's within the range set by the comparators.
  23187. for (var i = 0; i < set.length; i++) {
  23188. debug(set[i].semver);
  23189. if (set[i].semver === ANY)
  23190. continue;
  23191. if (set[i].semver.prerelease.length > 0) {
  23192. var allowed = set[i].semver;
  23193. if (allowed.major === version.major &&
  23194. allowed.minor === version.minor &&
  23195. allowed.patch === version.patch)
  23196. return true;
  23197. }
  23198. }
  23199. // Version has a -pre, but it's not one of the ones we like.
  23200. return false;
  23201. }
  23202. return true;
  23203. }
  23204. exports.satisfies = satisfies;
  23205. function satisfies(version, range, loose) {
  23206. try {
  23207. range = new Range(range, loose);
  23208. } catch (er) {
  23209. return false;
  23210. }
  23211. return range.test(version);
  23212. }
  23213. exports.maxSatisfying = maxSatisfying;
  23214. function maxSatisfying(versions, range, loose) {
  23215. var max = null;
  23216. var maxSV = null;
  23217. try {
  23218. var rangeObj = new Range(range, loose);
  23219. } catch (er) {
  23220. return null;
  23221. }
  23222. versions.forEach(function (v) {
  23223. if (rangeObj.test(v)) { // satisfies(v, range, loose)
  23224. if (!max || maxSV.compare(v) === -1) { // compare(max, v, true)
  23225. max = v;
  23226. maxSV = new SemVer(max, loose);
  23227. }
  23228. }
  23229. });
  23230. return max;
  23231. }
  23232. exports.minSatisfying = minSatisfying;
  23233. function minSatisfying(versions, range, loose) {
  23234. var min = null;
  23235. var minSV = null;
  23236. try {
  23237. var rangeObj = new Range(range, loose);
  23238. } catch (er) {
  23239. return null;
  23240. }
  23241. versions.forEach(function (v) {
  23242. if (rangeObj.test(v)) { // satisfies(v, range, loose)
  23243. if (!min || minSV.compare(v) === 1) { // compare(min, v, true)
  23244. min = v;
  23245. minSV = new SemVer(min, loose);
  23246. }
  23247. }
  23248. });
  23249. return min;
  23250. }
  23251. exports.validRange = validRange;
  23252. function validRange(range, loose) {
  23253. try {
  23254. // Return '*' instead of '' so that truthiness works.
  23255. // This will throw if it's invalid anyway
  23256. return new Range(range, loose).range || '*';
  23257. } catch (er) {
  23258. return null;
  23259. }
  23260. }
  23261. // Determine if version is less than all the versions possible in the range
  23262. exports.ltr = ltr;
  23263. function ltr(version, range, loose) {
  23264. return outside(version, range, '<', loose);
  23265. }
  23266. // Determine if version is greater than all the versions possible in the range.
  23267. exports.gtr = gtr;
  23268. function gtr(version, range, loose) {
  23269. return outside(version, range, '>', loose);
  23270. }
  23271. exports.outside = outside;
  23272. function outside(version, range, hilo, loose) {
  23273. version = new SemVer(version, loose);
  23274. range = new Range(range, loose);
  23275. var gtfn, ltefn, ltfn, comp, ecomp;
  23276. switch (hilo) {
  23277. case '>':
  23278. gtfn = gt;
  23279. ltefn = lte;
  23280. ltfn = lt;
  23281. comp = '>';
  23282. ecomp = '>=';
  23283. break;
  23284. case '<':
  23285. gtfn = lt;
  23286. ltefn = gte;
  23287. ltfn = gt;
  23288. comp = '<';
  23289. ecomp = '<=';
  23290. break;
  23291. default:
  23292. throw new TypeError('Must provide a hilo val of "<" or ">"');
  23293. }
  23294. // If it satisifes the range it is not outside
  23295. if (satisfies(version, range, loose)) {
  23296. return false;
  23297. }
  23298. // From now on, variable terms are as if we're in "gtr" mode.
  23299. // but note that everything is flipped for the "ltr" function.
  23300. for (var i = 0; i < range.set.length; ++i) {
  23301. var comparators = range.set[i];
  23302. var high = null;
  23303. var low = null;
  23304. comparators.forEach(function(comparator) {
  23305. if (comparator.semver === ANY) {
  23306. comparator = new Comparator('>=0.0.0');
  23307. }
  23308. high = high || comparator;
  23309. low = low || comparator;
  23310. if (gtfn(comparator.semver, high.semver, loose)) {
  23311. high = comparator;
  23312. } else if (ltfn(comparator.semver, low.semver, loose)) {
  23313. low = comparator;
  23314. }
  23315. });
  23316. // If the edge version comparator has a operator then our version
  23317. // isn't outside it
  23318. if (high.operator === comp || high.operator === ecomp) {
  23319. return false;
  23320. }
  23321. // If the lowest version comparator has an operator and our version
  23322. // is less than it then it isn't higher than the range
  23323. if ((!low.operator || low.operator === comp) &&
  23324. ltefn(version, low.semver)) {
  23325. return false;
  23326. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  23327. return false;
  23328. }
  23329. }
  23330. return true;
  23331. }
  23332. exports.prerelease = prerelease;
  23333. function prerelease(version, loose) {
  23334. var parsed = parse(version, loose);
  23335. return (parsed && parsed.prerelease.length) ? parsed.prerelease : null;
  23336. }
  23337. exports.intersects = intersects;
  23338. function intersects(r1, r2, loose) {
  23339. r1 = new Range(r1, loose);
  23340. r2 = new Range(r2, loose);
  23341. return r1.intersects(r2)
  23342. }
  23343. exports.coerce = coerce;
  23344. function coerce(version) {
  23345. if (version instanceof SemVer)
  23346. return version;
  23347. if (typeof version !== 'string')
  23348. return null;
  23349. var match = version.match(re[COERCE]);
  23350. if (match == null)
  23351. return null;
  23352. return parse((match[1] || '0') + '.' + (match[2] || '0') + '.' + (match[3] || '0'));
  23353. }
  23354. });
  23355. var hasOwnProperty = Object.prototype.hasOwnProperty;
  23356. var pseudomap = PseudoMap;
  23357. function PseudoMap (set) {
  23358. if (!(this instanceof PseudoMap)) // whyyyyyyy
  23359. throw new TypeError("Constructor PseudoMap requires 'new'")
  23360. this.clear();
  23361. if (set) {
  23362. if ((set instanceof PseudoMap) ||
  23363. (typeof Map === 'function' && set instanceof Map))
  23364. set.forEach(function (value, key) {
  23365. this.set(key, value);
  23366. }, this);
  23367. else if (Array.isArray(set))
  23368. set.forEach(function (kv) {
  23369. this.set(kv[0], kv[1]);
  23370. }, this);
  23371. else
  23372. throw new TypeError('invalid argument')
  23373. }
  23374. }
  23375. PseudoMap.prototype.forEach = function (fn, thisp) {
  23376. thisp = thisp || this;
  23377. Object.keys(this._data).forEach(function (k) {
  23378. if (k !== 'size')
  23379. fn.call(thisp, this._data[k].value, this._data[k].key);
  23380. }, this);
  23381. };
  23382. PseudoMap.prototype.has = function (k) {
  23383. return !!find(this._data, k)
  23384. };
  23385. PseudoMap.prototype.get = function (k) {
  23386. var res = find(this._data, k);
  23387. return res && res.value
  23388. };
  23389. PseudoMap.prototype.set = function (k, v) {
  23390. set(this._data, k, v);
  23391. };
  23392. PseudoMap.prototype.delete = function (k) {
  23393. var res = find(this._data, k);
  23394. if (res) {
  23395. delete this._data[res._index];
  23396. this._data.size--;
  23397. }
  23398. };
  23399. PseudoMap.prototype.clear = function () {
  23400. var data = Object.create(null);
  23401. data.size = 0;
  23402. Object.defineProperty(this, '_data', {
  23403. value: data,
  23404. enumerable: false,
  23405. configurable: true,
  23406. writable: false
  23407. });
  23408. };
  23409. Object.defineProperty(PseudoMap.prototype, 'size', {
  23410. get: function () {
  23411. return this._data.size
  23412. },
  23413. set: function (n) {},
  23414. enumerable: true,
  23415. configurable: true
  23416. });
  23417. PseudoMap.prototype.values =
  23418. PseudoMap.prototype.keys =
  23419. PseudoMap.prototype.entries = function () {
  23420. throw new Error('iterators are not implemented in this version')
  23421. };
  23422. // Either identical, or both NaN
  23423. function same (a, b) {
  23424. return a === b || a !== a && b !== b
  23425. }
  23426. function Entry$1 (k, v, i) {
  23427. this.key = k;
  23428. this.value = v;
  23429. this._index = i;
  23430. }
  23431. function find (data, k) {
  23432. for (var i = 0, s = '_' + k, key = s;
  23433. hasOwnProperty.call(data, key);
  23434. key = s + i++) {
  23435. if (same(data[key].key, k))
  23436. return data[key]
  23437. }
  23438. }
  23439. function set (data, k, v) {
  23440. for (var i = 0, s = '_' + k, key = s;
  23441. hasOwnProperty.call(data, key);
  23442. key = s + i++) {
  23443. if (same(data[key].key, k)) {
  23444. data[key].value = v;
  23445. return
  23446. }
  23447. }
  23448. data.size++;
  23449. data[key] = new Entry$1(k, v, key);
  23450. }
  23451. var map = createCommonjsModule(function (module) {
  23452. if (process.env.npm_package_name === 'pseudomap' &&
  23453. process.env.npm_lifecycle_script === 'test')
  23454. process.env.TEST_PSEUDOMAP = 'true';
  23455. if (typeof Map === 'function' && !process.env.TEST_PSEUDOMAP) {
  23456. module.exports = Map;
  23457. } else {
  23458. module.exports = pseudomap;
  23459. }
  23460. });
  23461. var yallist = Yallist;
  23462. Yallist.Node = Node;
  23463. Yallist.create = Yallist;
  23464. function Yallist (list) {
  23465. var self = this;
  23466. if (!(self instanceof Yallist)) {
  23467. self = new Yallist();
  23468. }
  23469. self.tail = null;
  23470. self.head = null;
  23471. self.length = 0;
  23472. if (list && typeof list.forEach === 'function') {
  23473. list.forEach(function (item) {
  23474. self.push(item);
  23475. });
  23476. } else if (arguments.length > 0) {
  23477. for (var i = 0, l = arguments.length; i < l; i++) {
  23478. self.push(arguments[i]);
  23479. }
  23480. }
  23481. return self
  23482. }
  23483. Yallist.prototype.removeNode = function (node) {
  23484. if (node.list !== this) {
  23485. throw new Error('removing node which does not belong to this list')
  23486. }
  23487. var next = node.next;
  23488. var prev = node.prev;
  23489. if (next) {
  23490. next.prev = prev;
  23491. }
  23492. if (prev) {
  23493. prev.next = next;
  23494. }
  23495. if (node === this.head) {
  23496. this.head = next;
  23497. }
  23498. if (node === this.tail) {
  23499. this.tail = prev;
  23500. }
  23501. node.list.length--;
  23502. node.next = null;
  23503. node.prev = null;
  23504. node.list = null;
  23505. };
  23506. Yallist.prototype.unshiftNode = function (node) {
  23507. if (node === this.head) {
  23508. return
  23509. }
  23510. if (node.list) {
  23511. node.list.removeNode(node);
  23512. }
  23513. var head = this.head;
  23514. node.list = this;
  23515. node.next = head;
  23516. if (head) {
  23517. head.prev = node;
  23518. }
  23519. this.head = node;
  23520. if (!this.tail) {
  23521. this.tail = node;
  23522. }
  23523. this.length++;
  23524. };
  23525. Yallist.prototype.pushNode = function (node) {
  23526. if (node === this.tail) {
  23527. return
  23528. }
  23529. if (node.list) {
  23530. node.list.removeNode(node);
  23531. }
  23532. var tail = this.tail;
  23533. node.list = this;
  23534. node.prev = tail;
  23535. if (tail) {
  23536. tail.next = node;
  23537. }
  23538. this.tail = node;
  23539. if (!this.head) {
  23540. this.head = node;
  23541. }
  23542. this.length++;
  23543. };
  23544. Yallist.prototype.push = function () {
  23545. for (var i = 0, l = arguments.length; i < l; i++) {
  23546. push(this, arguments[i]);
  23547. }
  23548. return this.length
  23549. };
  23550. Yallist.prototype.unshift = function () {
  23551. for (var i = 0, l = arguments.length; i < l; i++) {
  23552. unshift(this, arguments[i]);
  23553. }
  23554. return this.length
  23555. };
  23556. Yallist.prototype.pop = function () {
  23557. if (!this.tail) {
  23558. return undefined
  23559. }
  23560. var res = this.tail.value;
  23561. this.tail = this.tail.prev;
  23562. if (this.tail) {
  23563. this.tail.next = null;
  23564. } else {
  23565. this.head = null;
  23566. }
  23567. this.length--;
  23568. return res
  23569. };
  23570. Yallist.prototype.shift = function () {
  23571. if (!this.head) {
  23572. return undefined
  23573. }
  23574. var res = this.head.value;
  23575. this.head = this.head.next;
  23576. if (this.head) {
  23577. this.head.prev = null;
  23578. } else {
  23579. this.tail = null;
  23580. }
  23581. this.length--;
  23582. return res
  23583. };
  23584. Yallist.prototype.forEach = function (fn, thisp) {
  23585. thisp = thisp || this;
  23586. for (var walker = this.head, i = 0; walker !== null; i++) {
  23587. fn.call(thisp, walker.value, i, this);
  23588. walker = walker.next;
  23589. }
  23590. };
  23591. Yallist.prototype.forEachReverse = function (fn, thisp) {
  23592. thisp = thisp || this;
  23593. for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
  23594. fn.call(thisp, walker.value, i, this);
  23595. walker = walker.prev;
  23596. }
  23597. };
  23598. Yallist.prototype.get = function (n) {
  23599. for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
  23600. // abort out of the list early if we hit a cycle
  23601. walker = walker.next;
  23602. }
  23603. if (i === n && walker !== null) {
  23604. return walker.value
  23605. }
  23606. };
  23607. Yallist.prototype.getReverse = function (n) {
  23608. for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
  23609. // abort out of the list early if we hit a cycle
  23610. walker = walker.prev;
  23611. }
  23612. if (i === n && walker !== null) {
  23613. return walker.value
  23614. }
  23615. };
  23616. Yallist.prototype.map = function (fn, thisp) {
  23617. thisp = thisp || this;
  23618. var res = new Yallist();
  23619. for (var walker = this.head; walker !== null;) {
  23620. res.push(fn.call(thisp, walker.value, this));
  23621. walker = walker.next;
  23622. }
  23623. return res
  23624. };
  23625. Yallist.prototype.mapReverse = function (fn, thisp) {
  23626. thisp = thisp || this;
  23627. var res = new Yallist();
  23628. for (var walker = this.tail; walker !== null;) {
  23629. res.push(fn.call(thisp, walker.value, this));
  23630. walker = walker.prev;
  23631. }
  23632. return res
  23633. };
  23634. Yallist.prototype.reduce = function (fn, initial) {
  23635. var acc;
  23636. var walker = this.head;
  23637. if (arguments.length > 1) {
  23638. acc = initial;
  23639. } else if (this.head) {
  23640. walker = this.head.next;
  23641. acc = this.head.value;
  23642. } else {
  23643. throw new TypeError('Reduce of empty list with no initial value')
  23644. }
  23645. for (var i = 0; walker !== null; i++) {
  23646. acc = fn(acc, walker.value, i);
  23647. walker = walker.next;
  23648. }
  23649. return acc
  23650. };
  23651. Yallist.prototype.reduceReverse = function (fn, initial) {
  23652. var acc;
  23653. var walker = this.tail;
  23654. if (arguments.length > 1) {
  23655. acc = initial;
  23656. } else if (this.tail) {
  23657. walker = this.tail.prev;
  23658. acc = this.tail.value;
  23659. } else {
  23660. throw new TypeError('Reduce of empty list with no initial value')
  23661. }
  23662. for (var i = this.length - 1; walker !== null; i--) {
  23663. acc = fn(acc, walker.value, i);
  23664. walker = walker.prev;
  23665. }
  23666. return acc
  23667. };
  23668. Yallist.prototype.toArray = function () {
  23669. var arr = new Array(this.length);
  23670. for (var i = 0, walker = this.head; walker !== null; i++) {
  23671. arr[i] = walker.value;
  23672. walker = walker.next;
  23673. }
  23674. return arr
  23675. };
  23676. Yallist.prototype.toArrayReverse = function () {
  23677. var arr = new Array(this.length);
  23678. for (var i = 0, walker = this.tail; walker !== null; i++) {
  23679. arr[i] = walker.value;
  23680. walker = walker.prev;
  23681. }
  23682. return arr
  23683. };
  23684. Yallist.prototype.slice = function (from, to) {
  23685. to = to || this.length;
  23686. if (to < 0) {
  23687. to += this.length;
  23688. }
  23689. from = from || 0;
  23690. if (from < 0) {
  23691. from += this.length;
  23692. }
  23693. var ret = new Yallist();
  23694. if (to < from || to < 0) {
  23695. return ret
  23696. }
  23697. if (from < 0) {
  23698. from = 0;
  23699. }
  23700. if (to > this.length) {
  23701. to = this.length;
  23702. }
  23703. for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
  23704. walker = walker.next;
  23705. }
  23706. for (; walker !== null && i < to; i++, walker = walker.next) {
  23707. ret.push(walker.value);
  23708. }
  23709. return ret
  23710. };
  23711. Yallist.prototype.sliceReverse = function (from, to) {
  23712. to = to || this.length;
  23713. if (to < 0) {
  23714. to += this.length;
  23715. }
  23716. from = from || 0;
  23717. if (from < 0) {
  23718. from += this.length;
  23719. }
  23720. var ret = new Yallist();
  23721. if (to < from || to < 0) {
  23722. return ret
  23723. }
  23724. if (from < 0) {
  23725. from = 0;
  23726. }
  23727. if (to > this.length) {
  23728. to = this.length;
  23729. }
  23730. for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
  23731. walker = walker.prev;
  23732. }
  23733. for (; walker !== null && i > from; i--, walker = walker.prev) {
  23734. ret.push(walker.value);
  23735. }
  23736. return ret
  23737. };
  23738. Yallist.prototype.reverse = function () {
  23739. var head = this.head;
  23740. var tail = this.tail;
  23741. for (var walker = head; walker !== null; walker = walker.prev) {
  23742. var p = walker.prev;
  23743. walker.prev = walker.next;
  23744. walker.next = p;
  23745. }
  23746. this.head = tail;
  23747. this.tail = head;
  23748. return this
  23749. };
  23750. function push (self, item) {
  23751. self.tail = new Node(item, self.tail, null, self);
  23752. if (!self.head) {
  23753. self.head = self.tail;
  23754. }
  23755. self.length++;
  23756. }
  23757. function unshift (self, item) {
  23758. self.head = new Node(item, null, self.head, self);
  23759. if (!self.tail) {
  23760. self.tail = self.head;
  23761. }
  23762. self.length++;
  23763. }
  23764. function Node (value, prev, next, list) {
  23765. if (!(this instanceof Node)) {
  23766. return new Node(value, prev, next, list)
  23767. }
  23768. this.list = list;
  23769. this.value = value;
  23770. if (prev) {
  23771. prev.next = this;
  23772. this.prev = prev;
  23773. } else {
  23774. this.prev = null;
  23775. }
  23776. if (next) {
  23777. next.prev = this;
  23778. this.next = next;
  23779. } else {
  23780. this.next = null;
  23781. }
  23782. }
  23783. var lruCache = LRUCache;
  23784. // This will be a proper iterable 'Map' in engines that support it,
  23785. // or a fakey-fake PseudoMap in older versions.
  23786. // A linked list to keep track of recently-used-ness
  23787. // use symbols if possible, otherwise just _props
  23788. var hasSymbol = typeof Symbol === 'function';
  23789. var makeSymbol;
  23790. if (hasSymbol) {
  23791. makeSymbol = function (key) {
  23792. return Symbol.for(key)
  23793. };
  23794. } else {
  23795. makeSymbol = function (key) {
  23796. return '_' + key
  23797. };
  23798. }
  23799. var MAX = makeSymbol('max');
  23800. var LENGTH = makeSymbol('length');
  23801. var LENGTH_CALCULATOR = makeSymbol('lengthCalculator');
  23802. var ALLOW_STALE = makeSymbol('allowStale');
  23803. var MAX_AGE = makeSymbol('maxAge');
  23804. var DISPOSE = makeSymbol('dispose');
  23805. var NO_DISPOSE_ON_SET = makeSymbol('noDisposeOnSet');
  23806. var LRU_LIST = makeSymbol('lruList');
  23807. var CACHE = makeSymbol('cache');
  23808. function naiveLength () { return 1 }
  23809. // lruList is a yallist where the head is the youngest
  23810. // item, and the tail is the oldest. the list contains the Hit
  23811. // objects as the entries.
  23812. // Each Hit object has a reference to its Yallist.Node. This
  23813. // never changes.
  23814. //
  23815. // cache is a Map (or PseudoMap) that matches the keys to
  23816. // the Yallist.Node object.
  23817. function LRUCache (options) {
  23818. if (!(this instanceof LRUCache)) {
  23819. return new LRUCache(options)
  23820. }
  23821. if (typeof options === 'number') {
  23822. options = { max: options };
  23823. }
  23824. if (!options) {
  23825. options = {};
  23826. }
  23827. var max = this[MAX] = options.max;
  23828. // Kind of weird to have a default max of Infinity, but oh well.
  23829. if (!max ||
  23830. !(typeof max === 'number') ||
  23831. max <= 0) {
  23832. this[MAX] = Infinity;
  23833. }
  23834. var lc = options.length || naiveLength;
  23835. if (typeof lc !== 'function') {
  23836. lc = naiveLength;
  23837. }
  23838. this[LENGTH_CALCULATOR] = lc;
  23839. this[ALLOW_STALE] = options.stale || false;
  23840. this[MAX_AGE] = options.maxAge || 0;
  23841. this[DISPOSE] = options.dispose;
  23842. this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
  23843. this.reset();
  23844. }
  23845. // resize the cache when the max changes.
  23846. Object.defineProperty(LRUCache.prototype, 'max', {
  23847. set: function (mL) {
  23848. if (!mL || !(typeof mL === 'number') || mL <= 0) {
  23849. mL = Infinity;
  23850. }
  23851. this[MAX] = mL;
  23852. trim(this);
  23853. },
  23854. get: function () {
  23855. return this[MAX]
  23856. },
  23857. enumerable: true
  23858. });
  23859. Object.defineProperty(LRUCache.prototype, 'allowStale', {
  23860. set: function (allowStale) {
  23861. this[ALLOW_STALE] = !!allowStale;
  23862. },
  23863. get: function () {
  23864. return this[ALLOW_STALE]
  23865. },
  23866. enumerable: true
  23867. });
  23868. Object.defineProperty(LRUCache.prototype, 'maxAge', {
  23869. set: function (mA) {
  23870. if (!mA || !(typeof mA === 'number') || mA < 0) {
  23871. mA = 0;
  23872. }
  23873. this[MAX_AGE] = mA;
  23874. trim(this);
  23875. },
  23876. get: function () {
  23877. return this[MAX_AGE]
  23878. },
  23879. enumerable: true
  23880. });
  23881. // resize the cache when the lengthCalculator changes.
  23882. Object.defineProperty(LRUCache.prototype, 'lengthCalculator', {
  23883. set: function (lC) {
  23884. if (typeof lC !== 'function') {
  23885. lC = naiveLength;
  23886. }
  23887. if (lC !== this[LENGTH_CALCULATOR]) {
  23888. this[LENGTH_CALCULATOR] = lC;
  23889. this[LENGTH] = 0;
  23890. this[LRU_LIST].forEach(function (hit) {
  23891. hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
  23892. this[LENGTH] += hit.length;
  23893. }, this);
  23894. }
  23895. trim(this);
  23896. },
  23897. get: function () { return this[LENGTH_CALCULATOR] },
  23898. enumerable: true
  23899. });
  23900. Object.defineProperty(LRUCache.prototype, 'length', {
  23901. get: function () { return this[LENGTH] },
  23902. enumerable: true
  23903. });
  23904. Object.defineProperty(LRUCache.prototype, 'itemCount', {
  23905. get: function () { return this[LRU_LIST].length },
  23906. enumerable: true
  23907. });
  23908. LRUCache.prototype.rforEach = function (fn, thisp) {
  23909. thisp = thisp || this;
  23910. for (var walker = this[LRU_LIST].tail; walker !== null;) {
  23911. var prev = walker.prev;
  23912. forEachStep(this, fn, walker, thisp);
  23913. walker = prev;
  23914. }
  23915. };
  23916. function forEachStep (self, fn, node, thisp) {
  23917. var hit = node.value;
  23918. if (isStale(self, hit)) {
  23919. del(self, node);
  23920. if (!self[ALLOW_STALE]) {
  23921. hit = undefined;
  23922. }
  23923. }
  23924. if (hit) {
  23925. fn.call(thisp, hit.value, hit.key, self);
  23926. }
  23927. }
  23928. LRUCache.prototype.forEach = function (fn, thisp) {
  23929. thisp = thisp || this;
  23930. for (var walker = this[LRU_LIST].head; walker !== null;) {
  23931. var next = walker.next;
  23932. forEachStep(this, fn, walker, thisp);
  23933. walker = next;
  23934. }
  23935. };
  23936. LRUCache.prototype.keys = function () {
  23937. return this[LRU_LIST].toArray().map(function (k) {
  23938. return k.key
  23939. }, this)
  23940. };
  23941. LRUCache.prototype.values = function () {
  23942. return this[LRU_LIST].toArray().map(function (k) {
  23943. return k.value
  23944. }, this)
  23945. };
  23946. LRUCache.prototype.reset = function () {
  23947. if (this[DISPOSE] &&
  23948. this[LRU_LIST] &&
  23949. this[LRU_LIST].length) {
  23950. this[LRU_LIST].forEach(function (hit) {
  23951. this[DISPOSE](hit.key, hit.value);
  23952. }, this);
  23953. }
  23954. this[CACHE] = new map(); // hash of items by key
  23955. this[LRU_LIST] = new yallist(); // list of items in order of use recency
  23956. this[LENGTH] = 0; // length of items in the list
  23957. };
  23958. LRUCache.prototype.dump = function () {
  23959. return this[LRU_LIST].map(function (hit) {
  23960. if (!isStale(this, hit)) {
  23961. return {
  23962. k: hit.key,
  23963. v: hit.value,
  23964. e: hit.now + (hit.maxAge || 0)
  23965. }
  23966. }
  23967. }, this).toArray().filter(function (h) {
  23968. return h
  23969. })
  23970. };
  23971. LRUCache.prototype.dumpLru = function () {
  23972. return this[LRU_LIST]
  23973. };
  23974. LRUCache.prototype.inspect = function (n, opts) {
  23975. var str = 'LRUCache {';
  23976. var extras = false;
  23977. var as = this[ALLOW_STALE];
  23978. if (as) {
  23979. str += '\n allowStale: true';
  23980. extras = true;
  23981. }
  23982. var max = this[MAX];
  23983. if (max && max !== Infinity) {
  23984. if (extras) {
  23985. str += ',';
  23986. }
  23987. str += '\n max: ' + util.inspect(max, opts);
  23988. extras = true;
  23989. }
  23990. var maxAge = this[MAX_AGE];
  23991. if (maxAge) {
  23992. if (extras) {
  23993. str += ',';
  23994. }
  23995. str += '\n maxAge: ' + util.inspect(maxAge, opts);
  23996. extras = true;
  23997. }
  23998. var lc = this[LENGTH_CALCULATOR];
  23999. if (lc && lc !== naiveLength) {
  24000. if (extras) {
  24001. str += ',';
  24002. }
  24003. str += '\n length: ' + util.inspect(this[LENGTH], opts);
  24004. extras = true;
  24005. }
  24006. var didFirst = false;
  24007. this[LRU_LIST].forEach(function (item) {
  24008. if (didFirst) {
  24009. str += ',\n ';
  24010. } else {
  24011. if (extras) {
  24012. str += ',\n';
  24013. }
  24014. didFirst = true;
  24015. str += '\n ';
  24016. }
  24017. var key = util.inspect(item.key).split('\n').join('\n ');
  24018. var val = { value: item.value };
  24019. if (item.maxAge !== maxAge) {
  24020. val.maxAge = item.maxAge;
  24021. }
  24022. if (lc !== naiveLength) {
  24023. val.length = item.length;
  24024. }
  24025. if (isStale(this, item)) {
  24026. val.stale = true;
  24027. }
  24028. val = util.inspect(val, opts).split('\n').join('\n ');
  24029. str += key + ' => ' + val;
  24030. });
  24031. if (didFirst || extras) {
  24032. str += '\n';
  24033. }
  24034. str += '}';
  24035. return str
  24036. };
  24037. LRUCache.prototype.set = function (key, value, maxAge) {
  24038. maxAge = maxAge || this[MAX_AGE];
  24039. var now = maxAge ? Date.now() : 0;
  24040. var len = this[LENGTH_CALCULATOR](value, key);
  24041. if (this[CACHE].has(key)) {
  24042. if (len > this[MAX]) {
  24043. del(this, this[CACHE].get(key));
  24044. return false
  24045. }
  24046. var node = this[CACHE].get(key);
  24047. var item = node.value;
  24048. // dispose of the old one before overwriting
  24049. // split out into 2 ifs for better coverage tracking
  24050. if (this[DISPOSE]) {
  24051. if (!this[NO_DISPOSE_ON_SET]) {
  24052. this[DISPOSE](key, item.value);
  24053. }
  24054. }
  24055. item.now = now;
  24056. item.maxAge = maxAge;
  24057. item.value = value;
  24058. this[LENGTH] += len - item.length;
  24059. item.length = len;
  24060. this.get(key);
  24061. trim(this);
  24062. return true
  24063. }
  24064. var hit = new Entry(key, value, len, now, maxAge);
  24065. // oversized objects fall out of cache automatically.
  24066. if (hit.length > this[MAX]) {
  24067. if (this[DISPOSE]) {
  24068. this[DISPOSE](key, value);
  24069. }
  24070. return false
  24071. }
  24072. this[LENGTH] += hit.length;
  24073. this[LRU_LIST].unshift(hit);
  24074. this[CACHE].set(key, this[LRU_LIST].head);
  24075. trim(this);
  24076. return true
  24077. };
  24078. LRUCache.prototype.has = function (key) {
  24079. if (!this[CACHE].has(key)) return false
  24080. var hit = this[CACHE].get(key).value;
  24081. if (isStale(this, hit)) {
  24082. return false
  24083. }
  24084. return true
  24085. };
  24086. LRUCache.prototype.get = function (key) {
  24087. return get(this, key, true)
  24088. };
  24089. LRUCache.prototype.peek = function (key) {
  24090. return get(this, key, false)
  24091. };
  24092. LRUCache.prototype.pop = function () {
  24093. var node = this[LRU_LIST].tail;
  24094. if (!node) return null
  24095. del(this, node);
  24096. return node.value
  24097. };
  24098. LRUCache.prototype.del = function (key) {
  24099. del(this, this[CACHE].get(key));
  24100. };
  24101. LRUCache.prototype.load = function (arr) {
  24102. // reset the cache
  24103. this.reset();
  24104. var now = Date.now();
  24105. // A previous serialized cache has the most recent items first
  24106. for (var l = arr.length - 1; l >= 0; l--) {
  24107. var hit = arr[l];
  24108. var expiresAt = hit.e || 0;
  24109. if (expiresAt === 0) {
  24110. // the item was created without expiration in a non aged cache
  24111. this.set(hit.k, hit.v);
  24112. } else {
  24113. var maxAge = expiresAt - now;
  24114. // dont add already expired items
  24115. if (maxAge > 0) {
  24116. this.set(hit.k, hit.v, maxAge);
  24117. }
  24118. }
  24119. }
  24120. };
  24121. LRUCache.prototype.prune = function () {
  24122. var self = this;
  24123. this[CACHE].forEach(function (value, key) {
  24124. get(self, key, false);
  24125. });
  24126. };
  24127. function get (self, key, doUse) {
  24128. var node = self[CACHE].get(key);
  24129. if (node) {
  24130. var hit = node.value;
  24131. if (isStale(self, hit)) {
  24132. del(self, node);
  24133. if (!self[ALLOW_STALE]) hit = undefined;
  24134. } else {
  24135. if (doUse) {
  24136. self[LRU_LIST].unshiftNode(node);
  24137. }
  24138. }
  24139. if (hit) hit = hit.value;
  24140. }
  24141. return hit
  24142. }
  24143. function isStale (self, hit) {
  24144. if (!hit || (!hit.maxAge && !self[MAX_AGE])) {
  24145. return false
  24146. }
  24147. var stale = false;
  24148. var diff = Date.now() - hit.now;
  24149. if (hit.maxAge) {
  24150. stale = diff > hit.maxAge;
  24151. } else {
  24152. stale = self[MAX_AGE] && (diff > self[MAX_AGE]);
  24153. }
  24154. return stale
  24155. }
  24156. function trim (self) {
  24157. if (self[LENGTH] > self[MAX]) {
  24158. for (var walker = self[LRU_LIST].tail;
  24159. self[LENGTH] > self[MAX] && walker !== null;) {
  24160. // We know that we're about to delete this one, and also
  24161. // what the next least recently used key will be, so just
  24162. // go ahead and set it now.
  24163. var prev = walker.prev;
  24164. del(self, walker);
  24165. walker = prev;
  24166. }
  24167. }
  24168. }
  24169. function del (self, node) {
  24170. if (node) {
  24171. var hit = node.value;
  24172. if (self[DISPOSE]) {
  24173. self[DISPOSE](hit.key, hit.value);
  24174. }
  24175. self[LENGTH] -= hit.length;
  24176. self[CACHE].delete(hit.key);
  24177. self[LRU_LIST].removeNode(node);
  24178. }
  24179. }
  24180. // classy, since V8 prefers predictable objects.
  24181. function Entry (key, value, length, now, maxAge) {
  24182. this.key = key;
  24183. this.value = value;
  24184. this.length = length;
  24185. this.now = now;
  24186. this.maxAge = maxAge || 0;
  24187. }
  24188. var sigmund_1 = sigmund;
  24189. function sigmund (subject, maxSessions) {
  24190. maxSessions = maxSessions || 10;
  24191. var notes = [];
  24192. var analysis = '';
  24193. var RE = RegExp;
  24194. function psychoAnalyze (subject, session) {
  24195. if (session > maxSessions) return;
  24196. if (typeof subject === 'function' ||
  24197. typeof subject === 'undefined') {
  24198. return;
  24199. }
  24200. if (typeof subject !== 'object' || !subject ||
  24201. (subject instanceof RE)) {
  24202. analysis += subject;
  24203. return;
  24204. }
  24205. if (notes.indexOf(subject) !== -1 || session === maxSessions) return;
  24206. notes.push(subject);
  24207. analysis += '{';
  24208. Object.keys(subject).forEach(function (issue, _, __) {
  24209. // pseudo-private values. skip those.
  24210. if (issue.charAt(0) === '_') return;
  24211. var to = typeof subject[issue];
  24212. if (to === 'function' || to === 'undefined') return;
  24213. analysis += issue;
  24214. psychoAnalyze(subject[issue], session + 1);
  24215. });
  24216. }
  24217. psychoAnalyze(subject, 0);
  24218. return analysis;
  24219. }
  24220. // vim: set softtabstop=4 shiftwidth=4:
  24221. var fnmatch = createCommonjsModule(function (module, exports) {
  24222. // Based on minimatch.js by isaacs <https://npmjs.org/package/minimatch>
  24223. var platform = typeof process === "object" ? process.platform : "win32";
  24224. if (module) module.exports = minimatch;
  24225. else exports.minimatch = minimatch;
  24226. minimatch.Minimatch = Minimatch;
  24227. var cache = minimatch.cache = new lruCache({max: 100})
  24228. , GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
  24229. var qmark = "[^/]"
  24230. // * => any number of characters
  24231. , star = qmark + "*?"
  24232. // ** when dots are allowed. Anything goes, except .. and .
  24233. // not (^ or / followed by one or two dots followed by $ or /),
  24234. // followed by anything, any number of times.
  24235. , twoStarDot = "(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?"
  24236. // not a ^ or / followed by a dot,
  24237. // followed by anything, any number of times.
  24238. , twoStarNoDot = "(?:(?!(?:\\\/|^)\\.).)*?"
  24239. // characters that need to be escaped in RegExp.
  24240. , reSpecials = charSet("().*{}+?[]^$\\!");
  24241. // "abc" -> { a:true, b:true, c:true }
  24242. function charSet (s) {
  24243. return s.split("").reduce(function (set, c) {
  24244. set[c] = true;
  24245. return set
  24246. }, {})
  24247. }
  24248. // normalizes slashes.
  24249. var slashSplit = /\/+/;
  24250. minimatch.monkeyPatch = monkeyPatch;
  24251. function monkeyPatch () {
  24252. var desc = Object.getOwnPropertyDescriptor(String.prototype, "match");
  24253. var orig = desc.value;
  24254. desc.value = function (p) {
  24255. if (p instanceof Minimatch) return p.match(this)
  24256. return orig.call(this, p)
  24257. };
  24258. Object.defineProperty(String.prototype, desc);
  24259. }
  24260. minimatch.filter = filter;
  24261. function filter (pattern, options) {
  24262. options = options || {};
  24263. return function (p, i, list) {
  24264. return minimatch(p, pattern, options)
  24265. }
  24266. }
  24267. function ext (a, b) {
  24268. a = a || {};
  24269. b = b || {};
  24270. var t = {};
  24271. Object.keys(b).forEach(function (k) {
  24272. t[k] = b[k];
  24273. });
  24274. Object.keys(a).forEach(function (k) {
  24275. t[k] = a[k];
  24276. });
  24277. return t
  24278. }
  24279. minimatch.defaults = function (def) {
  24280. if (!def || !Object.keys(def).length) return minimatch
  24281. var orig = minimatch;
  24282. var m = function minimatch (p, pattern, options) {
  24283. return orig.minimatch(p, pattern, ext(def, options))
  24284. };
  24285. m.Minimatch = function Minimatch (pattern, options) {
  24286. return new orig.Minimatch(pattern, ext(def, options))
  24287. };
  24288. return m
  24289. };
  24290. Minimatch.defaults = function (def) {
  24291. if (!def || !Object.keys(def).length) return Minimatch
  24292. return minimatch.defaults(def).Minimatch
  24293. };
  24294. function minimatch (p, pattern, options) {
  24295. if (typeof pattern !== "string") {
  24296. throw new TypeError("glob pattern string required")
  24297. }
  24298. if (!options) options = {};
  24299. // shortcut: comments match nothing.
  24300. if (!options.nocomment && pattern.charAt(0) === "#") {
  24301. return false
  24302. }
  24303. // "" only matches ""
  24304. if (pattern.trim() === "") return p === ""
  24305. return new Minimatch(pattern, options).match(p)
  24306. }
  24307. function Minimatch (pattern, options) {
  24308. if (!(this instanceof Minimatch)) {
  24309. return new Minimatch(pattern, options, cache)
  24310. }
  24311. if (typeof pattern !== "string") {
  24312. throw new TypeError("glob pattern string required")
  24313. }
  24314. if (!options) options = {};
  24315. // windows: need to use /, not \
  24316. // On other platforms, \ is a valid (albeit bad) filename char.
  24317. if (platform === "win32") {
  24318. pattern = pattern.split("\\").join("/");
  24319. }
  24320. // lru storage.
  24321. // these things aren't particularly big, but walking down the string
  24322. // and turning it into a regexp can get pretty costly.
  24323. var cacheKey = pattern + "\n" + sigmund_1(options);
  24324. var cached = minimatch.cache.get(cacheKey);
  24325. if (cached) return cached
  24326. minimatch.cache.set(cacheKey, this);
  24327. this.options = options;
  24328. this.set = [];
  24329. this.pattern = pattern;
  24330. this.regexp = null;
  24331. this.negate = false;
  24332. this.comment = false;
  24333. this.empty = false;
  24334. // make the set of regexps etc.
  24335. this.make();
  24336. }
  24337. Minimatch.prototype.make = make;
  24338. function make () {
  24339. // don't do it more than once.
  24340. if (this._made) return
  24341. var pattern = this.pattern;
  24342. var options = this.options;
  24343. // empty patterns and comments match nothing.
  24344. if (!options.nocomment && pattern.charAt(0) === "#") {
  24345. this.comment = true;
  24346. return
  24347. }
  24348. if (!pattern) {
  24349. this.empty = true;
  24350. return
  24351. }
  24352. // step 1: figure out negation, etc.
  24353. this.parseNegate();
  24354. // step 2: expand braces
  24355. var set = this.globSet = this.braceExpand();
  24356. if (options.debug) console.error(this.pattern, set);
  24357. // step 3: now we have a set, so turn each one into a series of path-portion
  24358. // matching patterns.
  24359. // These will be regexps, except in the case of "**", which is
  24360. // set to the GLOBSTAR object for globstar behavior,
  24361. // and will not contain any / characters
  24362. set = this.globParts = set.map(function (s) {
  24363. return s.split(slashSplit)
  24364. });
  24365. if (options.debug) console.error(this.pattern, set);
  24366. // glob --> regexps
  24367. set = set.map(function (s, si, set) {
  24368. return s.map(this.parse, this)
  24369. }, this);
  24370. if (options.debug) console.error(this.pattern, set);
  24371. // filter out everything that didn't compile properly.
  24372. set = set.filter(function (s) {
  24373. return -1 === s.indexOf(false)
  24374. });
  24375. if (options.debug) console.error(this.pattern, set);
  24376. this.set = set;
  24377. }
  24378. Minimatch.prototype.parseNegate = parseNegate;
  24379. function parseNegate () {
  24380. var pattern = this.pattern
  24381. , negate = false
  24382. , options = this.options
  24383. , negateOffset = 0;
  24384. if (options.nonegate) return
  24385. for ( var i = 0, l = pattern.length
  24386. ; i < l && pattern.charAt(i) === "!"
  24387. ; i ++) {
  24388. negate = !negate;
  24389. negateOffset ++;
  24390. }
  24391. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  24392. this.negate = negate;
  24393. }
  24394. // Brace expansion:
  24395. // a{b,c}d -> abd acd
  24396. // a{b,}c -> abc ac
  24397. // a{0..3}d -> a0d a1d a2d a3d
  24398. // a{b,c{d,e}f}g -> abg acdfg acefg
  24399. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  24400. //
  24401. // Invalid sets are not expanded.
  24402. // a{2..}b -> a{2..}b
  24403. // a{b}c -> a{b}c
  24404. minimatch.braceExpand = function (pattern, options) {
  24405. return new Minimatch(pattern, options).braceExpand()
  24406. };
  24407. Minimatch.prototype.braceExpand = braceExpand;
  24408. function braceExpand (pattern, options) {
  24409. options = options || this.options;
  24410. pattern = typeof pattern === "undefined"
  24411. ? this.pattern : pattern;
  24412. if (typeof pattern === "undefined") {
  24413. throw new Error("undefined pattern")
  24414. }
  24415. if (options.nobrace ||
  24416. !pattern.match(/\{.*\}/)) {
  24417. // shortcut. no need to expand.
  24418. return [pattern]
  24419. }
  24420. var escaping = false;
  24421. // examples and comments refer to this crazy pattern:
  24422. // a{b,c{d,e},{f,g}h}x{y,z}
  24423. // expected:
  24424. // abxy
  24425. // abxz
  24426. // acdxy
  24427. // acdxz
  24428. // acexy
  24429. // acexz
  24430. // afhxy
  24431. // afhxz
  24432. // aghxy
  24433. // aghxz
  24434. // everything before the first \{ is just a prefix.
  24435. // So, we pluck that off, and work with the rest,
  24436. // and then prepend it to everything we find.
  24437. if (pattern.charAt(0) !== "{") {
  24438. // console.error(pattern)
  24439. var prefix = null;
  24440. for (var i = 0, l = pattern.length; i < l; i ++) {
  24441. var c = pattern.charAt(i);
  24442. // console.error(i, c)
  24443. if (c === "\\") {
  24444. escaping = !escaping;
  24445. } else if (c === "{" && !escaping) {
  24446. prefix = pattern.substr(0, i);
  24447. break
  24448. }
  24449. }
  24450. // actually no sets, all { were escaped.
  24451. if (prefix === null) {
  24452. // console.error("no sets")
  24453. return [pattern]
  24454. }
  24455. var tail = braceExpand(pattern.substr(i), options);
  24456. return tail.map(function (t) {
  24457. return prefix + t
  24458. })
  24459. }
  24460. // now we have something like:
  24461. // {b,c{d,e},{f,g}h}x{y,z}
  24462. // walk through the set, expanding each part, until
  24463. // the set ends. then, we'll expand the suffix.
  24464. // If the set only has a single member, then'll put the {} back
  24465. // first, handle numeric sets, since they're easier
  24466. var numset = pattern.match(/^\{(-?[0-9]+)\.\.(-?[0-9]+)\}/);
  24467. if (numset) {
  24468. // console.error("numset", numset[1], numset[2])
  24469. var suf = braceExpand(pattern.substr(numset[0].length), options)
  24470. , start = +numset[1]
  24471. , end = +numset[2]
  24472. , inc = start > end ? -1 : 1
  24473. , set = [];
  24474. for (var i = start; i != (end + inc); i += inc) {
  24475. // append all the suffixes
  24476. for (var ii = 0, ll = suf.length; ii < ll; ii ++) {
  24477. set.push(i + suf[ii]);
  24478. }
  24479. }
  24480. return set
  24481. }
  24482. // ok, walk through the set
  24483. // We hope, somewhat optimistically, that there
  24484. // will be a } at the end.
  24485. // If the closing brace isn't found, then the pattern is
  24486. // interpreted as braceExpand("\\" + pattern) so that
  24487. // the leading \{ will be interpreted literally.
  24488. var i = 1 // skip the \{
  24489. , depth = 1
  24490. , set = []
  24491. , member = ""
  24492. , sawEnd = false
  24493. , escaping = false;
  24494. function addMember () {
  24495. set.push(member);
  24496. member = "";
  24497. }
  24498. // console.error("Entering for")
  24499. FOR: for (i = 1, l = pattern.length; i < l; i ++) {
  24500. var c = pattern.charAt(i);
  24501. // console.error("", i, c)
  24502. if (escaping) {
  24503. escaping = false;
  24504. member += "\\" + c;
  24505. } else {
  24506. switch (c) {
  24507. case "\\":
  24508. escaping = true;
  24509. continue
  24510. case "{":
  24511. depth ++;
  24512. member += "{";
  24513. continue
  24514. case "}":
  24515. depth --;
  24516. // if this closes the actual set, then we're done
  24517. if (depth === 0) {
  24518. addMember();
  24519. // pluck off the close-brace
  24520. i ++;
  24521. break FOR
  24522. } else {
  24523. member += c;
  24524. continue
  24525. }
  24526. case ",":
  24527. if (depth === 1) {
  24528. addMember();
  24529. } else {
  24530. member += c;
  24531. }
  24532. continue
  24533. default:
  24534. member += c;
  24535. continue
  24536. } // switch
  24537. } // else
  24538. } // for
  24539. // now we've either finished the set, and the suffix is
  24540. // pattern.substr(i), or we have *not* closed the set,
  24541. // and need to escape the leading brace
  24542. if (depth !== 0) {
  24543. // console.error("didn't close", pattern)
  24544. return braceExpand("\\" + pattern, options)
  24545. }
  24546. // x{y,z} -> ["xy", "xz"]
  24547. // console.error("set", set)
  24548. // console.error("suffix", pattern.substr(i))
  24549. var suf = braceExpand(pattern.substr(i), options);
  24550. // ["b", "c{d,e}","{f,g}h"] ->
  24551. // [["b"], ["cd", "ce"], ["fh", "gh"]]
  24552. var addBraces = set.length === 1;
  24553. // console.error("set pre-expanded", set)
  24554. set = set.map(function (p) {
  24555. return braceExpand(p, options)
  24556. });
  24557. // console.error("set expanded", set)
  24558. // [["b"], ["cd", "ce"], ["fh", "gh"]] ->
  24559. // ["b", "cd", "ce", "fh", "gh"]
  24560. set = set.reduce(function (l, r) {
  24561. return l.concat(r)
  24562. });
  24563. if (addBraces) {
  24564. set = set.map(function (s) {
  24565. return "{" + s + "}"
  24566. });
  24567. }
  24568. // now attach the suffixes.
  24569. var ret = [];
  24570. for (var i = 0, l = set.length; i < l; i ++) {
  24571. for (var ii = 0, ll = suf.length; ii < ll; ii ++) {
  24572. ret.push(set[i] + suf[ii]);
  24573. }
  24574. }
  24575. return ret
  24576. }
  24577. // parse a component of the expanded set.
  24578. // At this point, no pattern may contain "/" in it
  24579. // so we're going to return a 2d array, where each entry is the full
  24580. // pattern, split on '/', and then turned into a regular expression.
  24581. // A regexp is made at the end which joins each array with an
  24582. // escaped /, and another full one which joins each regexp with |.
  24583. //
  24584. // Following the lead of Bash 4.1, note that "**" only has special meaning
  24585. // when it is the *only* thing in a path portion. Otherwise, any series
  24586. // of * is equivalent to a single *. Globstar behavior is enabled by
  24587. // default, and can be disabled by setting options.noglobstar.
  24588. Minimatch.prototype.parse = parse;
  24589. var SUBPARSE = {};
  24590. function parse (pattern, isSub) {
  24591. var options = this.options;
  24592. // shortcuts
  24593. if (!options.noglobstar && pattern === "**") return GLOBSTAR
  24594. if (pattern === "") return ""
  24595. var re = ""
  24596. , hasMagic = !!options.nocase
  24597. , escaping = false
  24598. // ? => one single character
  24599. , patternListStack = []
  24600. , plType
  24601. , stateChar
  24602. , inClass = false
  24603. , reClassStart = -1
  24604. , classStart = -1
  24605. // . and .. never match anything that doesn't start with .,
  24606. // even when options.dot is set.
  24607. , patternStart = pattern.charAt(0) === "." ? "" // anything
  24608. // not (start or / followed by . or .. followed by / or end)
  24609. : options.dot ? "(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))"
  24610. : "(?!\\.)";
  24611. function clearStateChar () {
  24612. if (stateChar) {
  24613. // we had some state-tracking character
  24614. // that wasn't consumed by this pass.
  24615. switch (stateChar) {
  24616. case "*":
  24617. re += star;
  24618. hasMagic = true;
  24619. break
  24620. case "?":
  24621. re += qmark;
  24622. hasMagic = true;
  24623. break
  24624. default:
  24625. re += "\\"+stateChar;
  24626. break
  24627. }
  24628. stateChar = false;
  24629. }
  24630. }
  24631. for ( var i = 0, len = pattern.length, c
  24632. ; (i < len) && (c = pattern.charAt(i))
  24633. ; i ++ ) {
  24634. if (options.debug) {
  24635. console.error("%s\t%s %s %j", pattern, i, re, c);
  24636. }
  24637. // skip over any that are escaped.
  24638. if (escaping && reSpecials[c]) {
  24639. re += "\\" + c;
  24640. escaping = false;
  24641. continue
  24642. }
  24643. SWITCH: switch (c) {
  24644. case "/":
  24645. // completely not allowed, even escaped.
  24646. // Should already be path-split by now.
  24647. return false
  24648. case "\\":
  24649. clearStateChar();
  24650. escaping = true;
  24651. continue
  24652. // the various stateChar values
  24653. // for the "extglob" stuff.
  24654. case "?":
  24655. case "*":
  24656. case "+":
  24657. case "@":
  24658. case "!":
  24659. if (options.debug) {
  24660. console.error("%s\t%s %s %j <-- stateChar", pattern, i, re, c);
  24661. }
  24662. // all of those are literals inside a class, except that
  24663. // the glob [!a] means [^a] in regexp
  24664. if (inClass) {
  24665. if (c === "!" && i === classStart + 1) c = "^";
  24666. re += c;
  24667. continue
  24668. }
  24669. // if we already have a stateChar, then it means
  24670. // that there was something like ** or +? in there.
  24671. // Handle the stateChar, then proceed with this one.
  24672. clearStateChar();
  24673. stateChar = c;
  24674. // if extglob is disabled, then +(asdf|foo) isn't a thing.
  24675. // just clear the statechar *now*, rather than even diving into
  24676. // the patternList stuff.
  24677. if (options.noext) clearStateChar();
  24678. continue
  24679. case "(":
  24680. if (inClass) {
  24681. re += "(";
  24682. continue
  24683. }
  24684. if (!stateChar) {
  24685. re += "\\(";
  24686. continue
  24687. }
  24688. plType = stateChar;
  24689. patternListStack.push({ type: plType
  24690. , start: i - 1
  24691. , reStart: re.length });
  24692. // negation is (?:(?!js)[^/]*)
  24693. re += stateChar === "!" ? "(?:(?!" : "(?:";
  24694. stateChar = false;
  24695. continue
  24696. case ")":
  24697. if (inClass || !patternListStack.length) {
  24698. re += "\\)";
  24699. continue
  24700. }
  24701. hasMagic = true;
  24702. re += ")";
  24703. plType = patternListStack.pop().type;
  24704. // negation is (?:(?!js)[^/]*)
  24705. // The others are (?:<pattern>)<type>
  24706. switch (plType) {
  24707. case "!":
  24708. re += "[^/]*?)";
  24709. break
  24710. case "?":
  24711. case "+":
  24712. case "*": re += plType;
  24713. case "@": break // the default anyway
  24714. }
  24715. continue
  24716. case "|":
  24717. if (inClass || !patternListStack.length || escaping) {
  24718. re += "\\|";
  24719. escaping = false;
  24720. continue
  24721. }
  24722. re += "|";
  24723. continue
  24724. // these are mostly the same in regexp and glob
  24725. case "[":
  24726. // swallow any state-tracking char before the [
  24727. clearStateChar();
  24728. if (inClass) {
  24729. re += "\\" + c;
  24730. continue
  24731. }
  24732. inClass = true;
  24733. classStart = i;
  24734. reClassStart = re.length;
  24735. re += c;
  24736. continue
  24737. case "]":
  24738. // a right bracket shall lose its special
  24739. // meaning and represent itself in
  24740. // a bracket expression if it occurs
  24741. // first in the list. -- POSIX.2 2.8.3.2
  24742. if (i === classStart + 1 || !inClass) {
  24743. re += "\\" + c;
  24744. escaping = false;
  24745. continue
  24746. }
  24747. // finish up the class.
  24748. hasMagic = true;
  24749. inClass = false;
  24750. re += c;
  24751. continue
  24752. default:
  24753. // swallow any state char that wasn't consumed
  24754. clearStateChar();
  24755. if (escaping) {
  24756. // no need
  24757. escaping = false;
  24758. } else if (reSpecials[c]
  24759. && !(c === "^" && inClass)) {
  24760. re += "\\";
  24761. }
  24762. re += c;
  24763. } // switch
  24764. } // for
  24765. // handle the case where we left a class open.
  24766. // "[abc" is valid, equivalent to "\[abc"
  24767. if (inClass) {
  24768. // split where the last [ was, and escape it
  24769. // this is a huge pita. We now have to re-walk
  24770. // the contents of the would-be class to re-translate
  24771. // any characters that were passed through as-is
  24772. var cs = pattern.substr(classStart + 1)
  24773. , sp = this.parse(cs, SUBPARSE);
  24774. re = re.substr(0, reClassStart) + "\\[" + sp[0];
  24775. hasMagic = hasMagic || sp[1];
  24776. }
  24777. // handle the case where we had a +( thing at the *end*
  24778. // of the pattern.
  24779. // each pattern list stack adds 3 chars, and we need to go through
  24780. // and escape any | chars that were passed through as-is for the regexp.
  24781. // Go through and escape them, taking care not to double-escape any
  24782. // | chars that were already escaped.
  24783. var pl;
  24784. while (pl = patternListStack.pop()) {
  24785. var tail = re.slice(pl.reStart + 3);
  24786. // maybe some even number of \, then maybe 1 \, followed by a |
  24787. tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
  24788. if (!$2) {
  24789. // the | isn't already escaped, so escape it.
  24790. $2 = "\\";
  24791. }
  24792. // need to escape all those slashes *again*, without escaping the
  24793. // one that we need for escaping the | character. As it works out,
  24794. // escaping an even number of slashes can be done by simply repeating
  24795. // it exactly after itself. That's why this trick works.
  24796. //
  24797. // I am sorry that you have to see this.
  24798. return $1 + $1 + $2 + "|"
  24799. });
  24800. // console.error("tail=%j\n %s", tail, tail)
  24801. var t = pl.type === "*" ? star
  24802. : pl.type === "?" ? qmark
  24803. : "\\" + pl.type;
  24804. hasMagic = true;
  24805. re = re.slice(0, pl.reStart)
  24806. + t + "\\("
  24807. + tail;
  24808. }
  24809. // handle trailing things that only matter at the very end.
  24810. clearStateChar();
  24811. if (escaping) {
  24812. // trailing \\
  24813. re += "\\\\";
  24814. }
  24815. // only need to apply the nodot start if the re starts with
  24816. // something that could conceivably capture a dot
  24817. var addPatternStart = false;
  24818. switch (re.charAt(0)) {
  24819. case ".":
  24820. case "[":
  24821. case "(": addPatternStart = true;
  24822. }
  24823. // if the re is not "" at this point, then we need to make sure
  24824. // it doesn't match against an empty path part.
  24825. // Otherwise a/* will match a/, which it should not.
  24826. if (re !== "" && hasMagic) re = "(?=.)" + re;
  24827. if (addPatternStart) re = patternStart + re;
  24828. // parsing just a piece of a larger pattern.
  24829. if (isSub === SUBPARSE) {
  24830. return [ re, hasMagic ]
  24831. }
  24832. // skip the regexp for non-magical patterns
  24833. // unescape anything in it, though, so that it'll be
  24834. // an exact match against a file etc.
  24835. if (!hasMagic) {
  24836. return globUnescape(pattern)
  24837. }
  24838. var flags = options.nocase ? "i" : ""
  24839. , regExp = new RegExp("^" + re + "$", flags);
  24840. regExp._glob = pattern;
  24841. regExp._src = re;
  24842. return regExp
  24843. }
  24844. minimatch.makeRe = function (pattern, options) {
  24845. return new Minimatch(pattern, options || {}).makeRe()
  24846. };
  24847. Minimatch.prototype.makeRe = makeRe;
  24848. function makeRe () {
  24849. if (this.regexp || this.regexp === false) return this.regexp
  24850. // at this point, this.set is a 2d array of partial
  24851. // pattern strings, or "**".
  24852. //
  24853. // It's better to use .match(). This function shouldn't
  24854. // be used, really, but it's pretty convenient sometimes,
  24855. // when you just want to work with a regex.
  24856. var set = this.set;
  24857. if (!set.length) return this.regexp = false
  24858. var options = this.options;
  24859. var twoStar = options.noglobstar ? star
  24860. : options.dot ? twoStarDot
  24861. : twoStarNoDot
  24862. , flags = options.nocase ? "i" : "";
  24863. var re = set.map(function (pattern) {
  24864. return pattern.map(function (p) {
  24865. return (p === GLOBSTAR) ? twoStar
  24866. : (typeof p === "string") ? regExpEscape(p)
  24867. : p._src
  24868. }).join("\\\/")
  24869. }).join("|");
  24870. // must match entire pattern
  24871. // ending in a * or ** will make it less strict.
  24872. re = "^(?:" + re + ")$";
  24873. // can match anything, as long as it's not this.
  24874. if (this.negate) re = "^(?!" + re + ").*$";
  24875. try {
  24876. return this.regexp = new RegExp(re, flags)
  24877. } catch (ex) {
  24878. return this.regexp = false
  24879. }
  24880. }
  24881. minimatch.match = function (list, pattern, options) {
  24882. var mm = new Minimatch(pattern, options);
  24883. list = list.filter(function (f) {
  24884. return mm.match(f)
  24885. });
  24886. if (options.nonull && !list.length) {
  24887. list.push(pattern);
  24888. }
  24889. return list
  24890. };
  24891. Minimatch.prototype.match = match;
  24892. function match (f, partial) {
  24893. // console.error("match", f, this.pattern)
  24894. // short-circuit in the case of busted things.
  24895. // comments, etc.
  24896. if (this.comment) return false
  24897. if (this.empty) return f === ""
  24898. if (f === "/" && partial) return true
  24899. var options = this.options;
  24900. // windows: need to use /, not \
  24901. // On other platforms, \ is a valid (albeit bad) filename char.
  24902. if (platform === "win32") {
  24903. f = f.split("\\").join("/");
  24904. }
  24905. // treat the test path as a set of pathparts.
  24906. f = f.split(slashSplit);
  24907. if (options.debug) {
  24908. console.error(this.pattern, "split", f);
  24909. }
  24910. // just ONE of the pattern sets in this.set needs to match
  24911. // in order for it to be valid. If negating, then just one
  24912. // match means that we have failed.
  24913. // Either way, return on the first hit.
  24914. var set = this.set;
  24915. // console.error(this.pattern, "set", set)
  24916. for (var i = 0, l = set.length; i < l; i ++) {
  24917. var pattern = set[i];
  24918. var hit = this.matchOne(f, pattern, partial);
  24919. if (hit) {
  24920. if (options.flipNegate) return true
  24921. return !this.negate
  24922. }
  24923. }
  24924. // didn't get any hits. this is success if it's a negative
  24925. // pattern, failure otherwise.
  24926. if (options.flipNegate) return false
  24927. return this.negate
  24928. }
  24929. // set partial to true to test if, for example,
  24930. // "/a/b" matches the start of "/*/b/*/d"
  24931. // Partial means, if you run out of file before you run
  24932. // out of pattern, then that's fine, as long as all
  24933. // the parts match.
  24934. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  24935. var options = this.options;
  24936. if (options.debug) {
  24937. console.error("matchOne",
  24938. { "this": this
  24939. , file: file
  24940. , pattern: pattern });
  24941. }
  24942. if (options.matchBase && pattern.length === 1) {
  24943. file = path.basename(file.join("/")).split("/");
  24944. }
  24945. if (options.debug) {
  24946. console.error("matchOne", file.length, pattern.length);
  24947. }
  24948. for ( var fi = 0
  24949. , pi = 0
  24950. , fl = file.length
  24951. , pl = pattern.length
  24952. ; (fi < fl) && (pi < pl)
  24953. ; fi ++, pi ++ ) {
  24954. if (options.debug) {
  24955. console.error("matchOne loop");
  24956. }
  24957. var p = pattern[pi]
  24958. , f = file[fi];
  24959. if (options.debug) {
  24960. console.error(pattern, p, f);
  24961. }
  24962. // should be impossible.
  24963. // some invalid regexp stuff in the set.
  24964. if (p === false) return false
  24965. if (p === GLOBSTAR) {
  24966. if (options.debug)
  24967. console.error('GLOBSTAR', [pattern, p, f]);
  24968. // "**"
  24969. // a/**/b/**/c would match the following:
  24970. // a/b/x/y/z/c
  24971. // a/x/y/z/b/c
  24972. // a/b/x/b/x/c
  24973. // a/b/c
  24974. // To do this, take the rest of the pattern after
  24975. // the **, and see if it would match the file remainder.
  24976. // If so, return success.
  24977. // If not, the ** "swallows" a segment, and try again.
  24978. // This is recursively awful.
  24979. //
  24980. // a/**/b/**/c matching a/b/x/y/z/c
  24981. // - a matches a
  24982. // - doublestar
  24983. // - matchOne(b/x/y/z/c, b/**/c)
  24984. // - b matches b
  24985. // - doublestar
  24986. // - matchOne(x/y/z/c, c) -> no
  24987. // - matchOne(y/z/c, c) -> no
  24988. // - matchOne(z/c, c) -> no
  24989. // - matchOne(c, c) yes, hit
  24990. var fr = fi
  24991. , pr = pi + 1;
  24992. if (pr === pl) {
  24993. if (options.debug)
  24994. console.error('** at the end');
  24995. // a ** at the end will just swallow the rest.
  24996. // We have found a match.
  24997. // however, it will not swallow /.x, unless
  24998. // options.dot is set.
  24999. // . and .. are *never* matched by **, for explosively
  25000. // exponential reasons.
  25001. for ( ; fi < fl; fi ++) {
  25002. if (file[fi] === "." || file[fi] === ".." ||
  25003. (!options.dot && file[fi].charAt(0) === ".")) return false
  25004. }
  25005. return true
  25006. }
  25007. // ok, let's see if we can swallow whatever we can.
  25008. WHILE: while (fr < fl) {
  25009. var swallowee = file[fr];
  25010. if (options.debug) {
  25011. console.error('\nglobstar while',
  25012. file, fr, pattern, pr, swallowee);
  25013. }
  25014. // XXX remove this slice. Just pass the start index.
  25015. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  25016. if (options.debug)
  25017. console.error('globstar found match!', fr, fl, swallowee);
  25018. // found a match.
  25019. return true
  25020. } else {
  25021. // can't swallow "." or ".." ever.
  25022. // can only swallow ".foo" when explicitly asked.
  25023. if (swallowee === "." || swallowee === ".." ||
  25024. (!options.dot && swallowee.charAt(0) === ".")) {
  25025. if (options.debug)
  25026. console.error("dot detected!", file, fr, pattern, pr);
  25027. break WHILE
  25028. }
  25029. // ** swallows a segment, and continue.
  25030. if (options.debug)
  25031. console.error('globstar swallow a segment, and continue');
  25032. fr ++;
  25033. }
  25034. }
  25035. // no match was found.
  25036. // However, in partial mode, we can't say this is necessarily over.
  25037. // If there's more *pattern* left, then
  25038. if (partial) {
  25039. // ran out of file
  25040. // console.error("\n>>> no match, partial?", file, fr, pattern, pr)
  25041. if (fr === fl) return true
  25042. }
  25043. return false
  25044. }
  25045. // something other than **
  25046. // non-magic patterns just have to match exactly
  25047. // patterns with magic have been turned into regexps.
  25048. var hit;
  25049. if (typeof p === "string") {
  25050. if (options.nocase) {
  25051. hit = f.toLowerCase() === p.toLowerCase();
  25052. } else {
  25053. hit = f === p;
  25054. }
  25055. if (options.debug) {
  25056. console.error("string match", p, f, hit);
  25057. }
  25058. } else {
  25059. hit = f.match(p);
  25060. if (options.debug) {
  25061. console.error("pattern match", p, f, hit);
  25062. }
  25063. }
  25064. if (!hit) return false
  25065. }
  25066. // Note: ending in / means that we'll get a final ""
  25067. // at the end of the pattern. This can only match a
  25068. // corresponding "" at the end of the file.
  25069. // If the file ends in /, then it can only match a
  25070. // a pattern that ends in /, unless the pattern just
  25071. // doesn't have any more for it. But, a/b/ should *not*
  25072. // match "a/b/*", even though "" matches against the
  25073. // [^/]*? pattern, except in partial mode, where it might
  25074. // simply not be reached yet.
  25075. // However, a/b/ should still satisfy a/*
  25076. // now either we fell off the end of the pattern, or we're done.
  25077. if (fi === fl && pi === pl) {
  25078. // ran out of pattern and filename at the same time.
  25079. // an exact hit!
  25080. return true
  25081. } else if (fi === fl) {
  25082. // ran out of file, but still had pattern left.
  25083. // this is ok if we're doing the match as part of
  25084. // a glob fs traversal.
  25085. return partial
  25086. } else if (pi === pl) {
  25087. // ran out of pattern, still have file left.
  25088. // this is only acceptable if we're on the very last
  25089. // empty segment of a file with a trailing slash.
  25090. // a/* should match a/b/
  25091. var emptyFileEnd = (fi === fl - 1) && (file[fi] === "");
  25092. return emptyFileEnd
  25093. }
  25094. // should be unreachable.
  25095. throw new Error("wtf?")
  25096. };
  25097. // replace stuff like \* with *
  25098. function globUnescape (s) {
  25099. return s.replace(/\\(.)/g, "$1")
  25100. }
  25101. function regExpEscape (s) {
  25102. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
  25103. }
  25104. });
  25105. var ini = createCommonjsModule(function (module, exports) {
  25106. "use strict";
  25107. // Based on iniparser by shockie <https://npmjs.org/package/iniparser>
  25108. var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
  25109. return new (P || (P = Promise))(function (resolve, reject) {
  25110. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  25111. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  25112. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  25113. step((generator = generator.apply(thisArg, _arguments || [])).next());
  25114. });
  25115. };
  25116. var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
  25117. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  25118. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  25119. function verb(n) { return function (v) { return step([n, v]); }; }
  25120. function step(op) {
  25121. if (f) throw new TypeError("Generator is already executing.");
  25122. while (_) try {
  25123. if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
  25124. if (y = 0, t) op = [0, t.value];
  25125. switch (op[0]) {
  25126. case 0: case 1: t = op; break;
  25127. case 4: _.label++; return { value: op[1], done: false };
  25128. case 5: _.label++; y = op[1]; op = [0]; continue;
  25129. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  25130. default:
  25131. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  25132. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  25133. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  25134. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  25135. if (t[2]) _.ops.pop();
  25136. _.trys.pop(); continue;
  25137. }
  25138. op = body.call(thisArg, _);
  25139. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  25140. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  25141. }
  25142. };
  25143. Object.defineProperty(exports, "__esModule", { value: true });
  25144. /**
  25145. * define the possible values:
  25146. * section: [section]
  25147. * param: key=value
  25148. * comment: ;this is a comment
  25149. */
  25150. var regex = {
  25151. section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
  25152. param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
  25153. comment: /^\s*[#;].*$/,
  25154. };
  25155. /**
  25156. * Parses an .ini file
  25157. * @param file The location of the .ini file
  25158. */
  25159. function parse(file) {
  25160. return __awaiter(this, void 0, void 0, function () {
  25161. return __generator(this, function (_a) {
  25162. return [2 /*return*/, new Promise(function (resolve, reject) {
  25163. fs.readFile(file, 'utf8', function (err, data) {
  25164. if (err) {
  25165. reject(err);
  25166. return;
  25167. }
  25168. resolve(parseString(data));
  25169. });
  25170. })];
  25171. });
  25172. });
  25173. }
  25174. exports.parse = parse;
  25175. function parseSync(file) {
  25176. return parseString(fs.readFileSync(file, 'utf8'));
  25177. }
  25178. exports.parseSync = parseSync;
  25179. function parseString(data) {
  25180. var sectionBody = {};
  25181. var sectionName = null;
  25182. var value = [[sectionName, sectionBody]];
  25183. var lines = data.split(/\r\n|\r|\n/);
  25184. lines.forEach(function (line) {
  25185. var match;
  25186. if (regex.comment.test(line)) {
  25187. return;
  25188. }
  25189. if (regex.param.test(line)) {
  25190. match = line.match(regex.param);
  25191. sectionBody[match[1]] =
  25192. match[2];
  25193. }
  25194. else if (regex.section.test(line)) {
  25195. match = line.match(regex.section);
  25196. sectionName = match[1];
  25197. sectionBody = {};
  25198. value.push([sectionName, sectionBody]);
  25199. }
  25200. });
  25201. return value;
  25202. }
  25203. exports.parseString = parseString;
  25204. });
  25205. unwrapExports(ini);
  25206. var name$1 = "editorconfig";
  25207. var version$2 = "0.15.0";
  25208. var description$1 = "EditorConfig File Locator and Interpreter for Node.js";
  25209. var keywords = ["editorconfig","core"];
  25210. var main$1 = "index.js";
  25211. var bin$1 = {"editorconfig":"bin/editorconfig"};
  25212. var contributors = ["Hong Xu (topbug.net)","Jed Mao (https://github.com/jedmao/)","Trey Hunner (http://treyhunner.com)"];
  25213. var directories = {"bin":"./bin","lib":"./lib"};
  25214. var scripts$1 = {"clean":"rimraf dist","prebuild":"npm run clean","build":"tsc","pretest":"npm run lint && npm run build && npm run copy && cmake .","test":"ctest .","pretest:ci":"npm run pretest","test:ci":"ctest -VV --output-on-failure .","lint":"npm run eclint && npm run tslint","eclint":"eclint check --indent_size ignore \"src/**\"","tslint":"tslint --project tslint.json","copy":"cpy package.json .npmignore LICENSE README.md CHANGELOG.md dist && cpy src/bin/* dist/bin && cpy src/lib/fnmatch*.* dist/lib","prepub":"npm run lint && npm run build && npm run copy","pub":"npm publish ./dist"};
  25215. var repository$1 = {"type":"git","url":"git://github.com/editorconfig/editorconfig-core-js.git"};
  25216. var bugs$1 = "https://github.com/editorconfig/editorconfig-core-js/issues";
  25217. var author$1 = "EditorConfig Team";
  25218. var license$1 = "MIT";
  25219. var dependencies$1 = {"@types/commander":"^2.11.0","@types/semver":"^5.4.0","commander":"^2.11.0","lru-cache":"^4.1.1","semver":"^5.4.1","sigmund":"^1.0.1"};
  25220. var devDependencies$1 = {"@types/mocha":"^2.2.43","cpy-cli":"^1.0.1","eclint":"^2.4.3","mocha":"^4.0.1","rimraf":"^2.6.2","should":"^13.1.2","tslint":"^5.7.0","typescript":"^2.5.3"};
  25221. var _package$2 = {
  25222. name: name$1,
  25223. version: version$2,
  25224. description: description$1,
  25225. keywords: keywords,
  25226. main: main$1,
  25227. bin: bin$1,
  25228. contributors: contributors,
  25229. directories: directories,
  25230. scripts: scripts$1,
  25231. repository: repository$1,
  25232. bugs: bugs$1,
  25233. author: author$1,
  25234. license: license$1,
  25235. dependencies: dependencies$1,
  25236. devDependencies: devDependencies$1
  25237. };
  25238. var _package$3 = Object.freeze({
  25239. name: name$1,
  25240. version: version$2,
  25241. description: description$1,
  25242. keywords: keywords,
  25243. main: main$1,
  25244. bin: bin$1,
  25245. contributors: contributors,
  25246. directories: directories,
  25247. scripts: scripts$1,
  25248. repository: repository$1,
  25249. bugs: bugs$1,
  25250. author: author$1,
  25251. license: license$1,
  25252. dependencies: dependencies$1,
  25253. devDependencies: devDependencies$1,
  25254. default: _package$2
  25255. });
  25256. var pkg = ( _package$3 && _package$2 ) || _package$3;
  25257. var editorconfig = createCommonjsModule(function (module, exports) {
  25258. "use strict";
  25259. var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
  25260. return new (P || (P = Promise))(function (resolve, reject) {
  25261. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  25262. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  25263. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  25264. step((generator = generator.apply(thisArg, _arguments || [])).next());
  25265. });
  25266. };
  25267. var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
  25268. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  25269. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  25270. function verb(n) { return function (v) { return step([n, v]); }; }
  25271. function step(op) {
  25272. if (f) throw new TypeError("Generator is already executing.");
  25273. while (_) try {
  25274. if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
  25275. if (y = 0, t) op = [0, t.value];
  25276. switch (op[0]) {
  25277. case 0: case 1: t = op; break;
  25278. case 4: _.label++; return { value: op[1], done: false };
  25279. case 5: _.label++; y = op[1]; op = [0]; continue;
  25280. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  25281. default:
  25282. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  25283. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  25284. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  25285. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  25286. if (t[2]) _.ops.pop();
  25287. _.trys.pop(); continue;
  25288. }
  25289. op = body.call(thisArg, _);
  25290. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  25291. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  25292. }
  25293. };
  25294. Object.defineProperty(exports, "__esModule", { value: true });
  25295. exports.parseString = ini.parseString;
  25296. // tslint:disable-next-line:no-var-requires
  25297. var knownProps = {
  25298. end_of_line: true,
  25299. indent_style: true,
  25300. indent_size: true,
  25301. insert_final_newline: true,
  25302. trim_trailing_whitespace: true,
  25303. charset: true,
  25304. };
  25305. function fnmatch$$1(filepath, glob) {
  25306. var matchOptions = { matchBase: true, dot: true, noext: true };
  25307. glob = glob.replace(/\*\*/g, '{*,**/**/**}');
  25308. return fnmatch(filepath, glob, matchOptions);
  25309. }
  25310. function getConfigFileNames(filepath, options) {
  25311. var paths = [];
  25312. do {
  25313. filepath = path.dirname(filepath);
  25314. paths.push(path.join(filepath, options.config));
  25315. } while (filepath !== options.root);
  25316. return paths;
  25317. }
  25318. function processMatches(matches, version) {
  25319. // Set indent_size to 'tab' if indent_size is unspecified and
  25320. // indent_style is set to 'tab'.
  25321. if ('indent_style' in matches
  25322. && matches.indent_style === 'tab'
  25323. && !('indent_size' in matches)
  25324. && semver$3.gte(version, '0.10.0')) {
  25325. matches.indent_size = 'tab';
  25326. }
  25327. // Set tab_width to indent_size if indent_size is specified and
  25328. // tab_width is unspecified
  25329. if ('indent_size' in matches
  25330. && !('tab_width' in matches)
  25331. && matches.indent_size !== 'tab') {
  25332. matches.tab_width = matches.indent_size;
  25333. }
  25334. // Set indent_size to tab_width if indent_size is 'tab'
  25335. if ('indent_size' in matches
  25336. && 'tab_width' in matches
  25337. && matches.indent_size === 'tab') {
  25338. matches.indent_size = matches.tab_width;
  25339. }
  25340. return matches;
  25341. }
  25342. function processOptions(options, filepath) {
  25343. if (options === void 0) { options = {}; }
  25344. return {
  25345. config: options.config || '.editorconfig',
  25346. version: options.version || pkg.version,
  25347. root: path.resolve(options.root || path.parse(filepath).root),
  25348. };
  25349. }
  25350. function buildFullGlob(pathPrefix, glob) {
  25351. switch (glob.indexOf('/')) {
  25352. case -1:
  25353. glob = '**/' + glob;
  25354. break;
  25355. case 0:
  25356. glob = glob.substring(1);
  25357. break;
  25358. default:
  25359. break;
  25360. }
  25361. return path.join(pathPrefix, glob);
  25362. }
  25363. function extendProps(props, options) {
  25364. if (props === void 0) { props = {}; }
  25365. if (options === void 0) { options = {}; }
  25366. for (var key in options) {
  25367. if (options.hasOwnProperty(key)) {
  25368. var value = options[key];
  25369. var key2 = key.toLowerCase();
  25370. var value2 = value;
  25371. if (knownProps[key2]) {
  25372. value2 = value.toLowerCase();
  25373. }
  25374. try {
  25375. value2 = JSON.parse(value);
  25376. }
  25377. catch (e) { }
  25378. if (typeof value === 'undefined' || value === null) {
  25379. // null and undefined are values specific to JSON (no special meaning
  25380. // in editorconfig) & should just be returned as regular strings.
  25381. value2 = String(value);
  25382. }
  25383. props[key2] = value2;
  25384. }
  25385. }
  25386. return props;
  25387. }
  25388. function parseFromConfigs(configs, filepath, options) {
  25389. return processMatches(configs
  25390. .reverse()
  25391. .reduce(function (matches, file) {
  25392. var pathPrefix = path.dirname(file.name);
  25393. file.contents.forEach(function (section) {
  25394. var glob = section[0];
  25395. var options2 = section[1];
  25396. if (!glob) {
  25397. return;
  25398. }
  25399. var fullGlob = buildFullGlob(pathPrefix, glob);
  25400. if (!fnmatch$$1(filepath, fullGlob)) {
  25401. return;
  25402. }
  25403. matches = extendProps(matches, options2);
  25404. });
  25405. return matches;
  25406. }, {}), options.version);
  25407. }
  25408. function getConfigsForFiles(files) {
  25409. var configs = [];
  25410. for (var i in files) {
  25411. if (files.hasOwnProperty(i)) {
  25412. var file = files[i];
  25413. var contents = ini.parseString(file.contents);
  25414. configs.push({
  25415. name: file.name,
  25416. contents: contents,
  25417. });
  25418. if ((contents[0][1].root || '').toLowerCase() === 'true') {
  25419. break;
  25420. }
  25421. }
  25422. }
  25423. return configs;
  25424. }
  25425. function readConfigFiles(filepaths) {
  25426. return __awaiter(this, void 0, void 0, function () {
  25427. return __generator(this, function (_a) {
  25428. return [2 /*return*/, Promise.all(filepaths.map(function (name) { return new Promise(function (resolve) {
  25429. fs.readFile(name, 'utf8', function (err, data) {
  25430. resolve({
  25431. name: name,
  25432. contents: err ? '' : data,
  25433. });
  25434. });
  25435. }); }))];
  25436. });
  25437. });
  25438. }
  25439. function readConfigFilesSync(filepaths) {
  25440. var files = [];
  25441. var file;
  25442. filepaths.forEach(function (filepath) {
  25443. try {
  25444. file = fs.readFileSync(filepath, 'utf8');
  25445. }
  25446. catch (e) {
  25447. file = '';
  25448. }
  25449. files.push({
  25450. name: filepath,
  25451. contents: file,
  25452. });
  25453. });
  25454. return files;
  25455. }
  25456. function opts(filepath, options) {
  25457. if (options === void 0) { options = {}; }
  25458. var resolvedFilePath = path.resolve(filepath);
  25459. return [
  25460. resolvedFilePath,
  25461. processOptions(options, resolvedFilePath),
  25462. ];
  25463. }
  25464. function parseFromFiles(filepath, files, options) {
  25465. if (options === void 0) { options = {}; }
  25466. return __awaiter(this, void 0, void 0, function () {
  25467. var _a, resolvedFilePath, processedOptions;
  25468. return __generator(this, function (_b) {
  25469. _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
  25470. return [2 /*return*/, files.then(getConfigsForFiles)
  25471. .then(function (configs) { return parseFromConfigs(configs, resolvedFilePath, processedOptions); })];
  25472. });
  25473. });
  25474. }
  25475. exports.parseFromFiles = parseFromFiles;
  25476. function parseFromFilesSync(filepath, files, options) {
  25477. if (options === void 0) { options = {}; }
  25478. var _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
  25479. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  25480. }
  25481. exports.parseFromFilesSync = parseFromFilesSync;
  25482. function parse(_filepath, _options) {
  25483. if (_options === void 0) { _options = {}; }
  25484. return __awaiter(this, void 0, void 0, function () {
  25485. var _a, resolvedFilePath, processedOptions, filepaths;
  25486. return __generator(this, function (_b) {
  25487. _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
  25488. filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  25489. return [2 /*return*/, readConfigFiles(filepaths)
  25490. .then(getConfigsForFiles)
  25491. .then(function (configs) { return parseFromConfigs(configs, resolvedFilePath, processedOptions); })];
  25492. });
  25493. });
  25494. }
  25495. exports.parse = parse;
  25496. function parseSync(_filepath, _options) {
  25497. if (_options === void 0) { _options = {}; }
  25498. var _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
  25499. var filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  25500. var files = readConfigFilesSync(filepaths);
  25501. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  25502. }
  25503. exports.parseSync = parseSync;
  25504. });
  25505. unwrapExports(editorconfig);
  25506. var editorconfigToPrettier = editorConfigToPrettier;
  25507. function editorConfigToPrettier(editorConfig) {
  25508. if (!editorConfig || Object.keys(editorConfig).length === 0) {
  25509. return null;
  25510. }
  25511. const result = {};
  25512. if (editorConfig.indent_style) {
  25513. result.useTabs = editorConfig.indent_style === "tab";
  25514. }
  25515. if (editorConfig.indent_size === "tab") {
  25516. result.useTabs = true;
  25517. }
  25518. if (result.useTabs && editorConfig.tab_width) {
  25519. result.tabWidth = editorConfig.tab_width;
  25520. } else if (
  25521. editorConfig.indent_style === "space" &&
  25522. editorConfig.indent_size &&
  25523. editorConfig.indent_size !== "tab"
  25524. ) {
  25525. result.tabWidth = editorConfig.indent_size;
  25526. } else if (editorConfig.tab_width !== undefined) {
  25527. result.tabWidth = editorConfig.tab_width;
  25528. }
  25529. if (editorConfig.max_line_length && editorConfig.max_line_length !== "off") {
  25530. result.printWidth = editorConfig.max_line_length;
  25531. }
  25532. if (editorConfig.quote_type === "single") {
  25533. result.singleQuote = true;
  25534. } else if (editorConfig.quote_type === "double") {
  25535. result.singleQuote = false;
  25536. }
  25537. return result;
  25538. }
  25539. function markerExists (files, markers) {
  25540. return markers.some(function(marker) {
  25541. return files.some(function(file) {
  25542. return file === marker;
  25543. });
  25544. });
  25545. }
  25546. function traverseFolder (directory, levels, markers) {
  25547. var files = fs.readdirSync(directory);
  25548. if (levels === 0) {
  25549. return null;
  25550. } else if (markerExists(files, markers)) {
  25551. return directory;
  25552. } else {
  25553. return traverseFolder(path.resolve(directory, '..'), levels - 1, markers);
  25554. }
  25555. }
  25556. var findProjectRoot = function findRoot(dir, opts) {
  25557. if (!dir) throw new Error("Directory not defined");
  25558. opts = opts || {};
  25559. var levels = opts.maxDepth || findRoot.MAX_DEPTH;
  25560. var markers = opts.markers || findRoot.MARKERS;
  25561. return traverseFolder(dir, levels, markers);
  25562. };
  25563. var MAX_DEPTH = 9;
  25564. var MARKERS = [ '.git', '.hg' ];
  25565. findProjectRoot.MAX_DEPTH = MAX_DEPTH;
  25566. findProjectRoot.MARKERS = MARKERS;
  25567. var resolveConfigEditorconfig = createCommonjsModule(function (module) {
  25568. "use strict";
  25569. const maybeParse = (filePath, config, parse) => {
  25570. const root = findProjectRoot(path.dirname(path.resolve(filePath)));
  25571. return filePath && parse(filePath, { root });
  25572. };
  25573. const editorconfigAsyncNoCache = (filePath, config) => {
  25574. return Promise.resolve(maybeParse(filePath, config, editorconfig.parse)).then(
  25575. editorconfigToPrettier
  25576. );
  25577. };
  25578. const editorconfigAsyncWithCache = mem(editorconfigAsyncNoCache);
  25579. const editorconfigSyncNoCache = (filePath, config) => {
  25580. return editorconfigToPrettier(
  25581. maybeParse(filePath, config, editorconfig.parseSync)
  25582. );
  25583. };
  25584. const editorconfigSyncWithCache = mem(editorconfigSyncNoCache);
  25585. function getLoadFunction(opts) {
  25586. if (!opts.editorconfig) {
  25587. return () => null;
  25588. }
  25589. if (opts.sync) {
  25590. return opts.cache ? editorconfigSyncWithCache : editorconfigSyncNoCache;
  25591. }
  25592. return opts.cache ? editorconfigAsyncWithCache : editorconfigAsyncNoCache;
  25593. }
  25594. function clearCache() {
  25595. mem.clear(editorconfigSyncWithCache);
  25596. mem.clear(editorconfigAsyncWithCache);
  25597. }
  25598. module.exports = {
  25599. getLoadFunction,
  25600. clearCache
  25601. };
  25602. });
  25603. var thirdParty$1 = ( thirdParty && thirdParty__default ) || thirdParty;
  25604. var resolveConfig_1 = createCommonjsModule(function (module) {
  25605. "use strict";
  25606. const getExplorerMemoized = mem(opts =>
  25607. thirdParty$1.cosmiconfig("prettier", {
  25608. sync: opts.sync,
  25609. cache: opts.cache,
  25610. rcExtensions: true,
  25611. transform: result => {
  25612. if (result && result.config) {
  25613. delete result.config.$schema;
  25614. }
  25615. return result;
  25616. }
  25617. })
  25618. );
  25619. /** @param {{ cache: boolean, sync: boolean }} opts */
  25620. function getLoadFunction(opts) {
  25621. // Normalize opts before passing to a memoized function
  25622. opts = Object.assign({ sync: false, cache: false }, opts);
  25623. return getExplorerMemoized(opts).load;
  25624. }
  25625. function _resolveConfig(filePath, opts, sync) {
  25626. opts = Object.assign({ useCache: true }, opts);
  25627. const loadOpts = {
  25628. cache: !!opts.useCache,
  25629. sync: !!sync,
  25630. editorconfig: !!opts.editorconfig
  25631. };
  25632. const load = getLoadFunction(loadOpts);
  25633. const loadEditorConfig = resolveConfigEditorconfig.getLoadFunction(loadOpts);
  25634. const arr = [load, loadEditorConfig].map(l => l(filePath, opts.config));
  25635. const unwrapAndMerge = arr => {
  25636. const result = arr[0];
  25637. const editorConfigured = arr[1];
  25638. const merged = Object.assign(
  25639. {},
  25640. editorConfigured,
  25641. mergeOverrides(Object.assign({}, result), filePath)
  25642. );
  25643. if (!result && !editorConfigured) {
  25644. return null;
  25645. }
  25646. return merged;
  25647. };
  25648. if (loadOpts.sync) {
  25649. return unwrapAndMerge(arr);
  25650. }
  25651. return Promise.all(arr).then(unwrapAndMerge);
  25652. }
  25653. const resolveConfig = (filePath, opts) => _resolveConfig(filePath, opts, false);
  25654. resolveConfig.sync = (filePath, opts) => _resolveConfig(filePath, opts, true);
  25655. function clearCache() {
  25656. mem.clear(getExplorerMemoized);
  25657. resolveConfigEditorconfig.clearCache();
  25658. }
  25659. function resolveConfigFile(filePath) {
  25660. const load = getLoadFunction({ sync: false });
  25661. return load(filePath).then(result => {
  25662. return result ? result.filepath : null;
  25663. });
  25664. }
  25665. resolveConfigFile.sync = filePath => {
  25666. const load = getLoadFunction({ sync: true });
  25667. const result = load(filePath);
  25668. return result ? result.filepath : null;
  25669. };
  25670. function mergeOverrides(configResult, filePath) {
  25671. const options = Object.assign({}, configResult.config);
  25672. if (filePath && options.overrides) {
  25673. const relativeFilePath = path.relative(
  25674. path.dirname(configResult.filepath),
  25675. filePath
  25676. );
  25677. for (const override of options.overrides) {
  25678. if (
  25679. pathMatchesGlobs(
  25680. relativeFilePath,
  25681. override.files,
  25682. override.excludeFiles
  25683. )
  25684. ) {
  25685. Object.assign(options, override.options);
  25686. }
  25687. }
  25688. }
  25689. delete options.overrides;
  25690. return options;
  25691. }
  25692. // Based on eslint: https://github.com/eslint/eslint/blob/master/lib/config/config-ops.js
  25693. function pathMatchesGlobs(filePath, patterns, excludedPatterns) {
  25694. const patternList = [].concat(patterns);
  25695. const excludedPatternList = [].concat(excludedPatterns || []);
  25696. const opts = { matchBase: true };
  25697. return (
  25698. patternList.some(pattern => minimatch_1(filePath, pattern, opts)) &&
  25699. !excludedPatternList.some(excludedPattern =>
  25700. minimatch_1(filePath, excludedPattern, opts)
  25701. )
  25702. );
  25703. }
  25704. module.exports = {
  25705. resolveConfig,
  25706. resolveConfigFile,
  25707. clearCache
  25708. };
  25709. });
  25710. const version = require$$0$11.version;
  25711. const getSupportInfo = support.getSupportInfo;
  25712. const normalizeOptions = options$12.normalize;
  25713. const printDocToString = doc.printer.printDocToString;
  25714. const printDocToDebug = doc.debug.printDocToDebug;
  25715. function guessLineEnding(text) {
  25716. const index = text.indexOf("\n");
  25717. if (index >= 0 && text.charAt(index - 1) === "\r") {
  25718. return "\r\n";
  25719. }
  25720. return "\n";
  25721. }
  25722. function attachComments(text, ast, opts) {
  25723. const astComments = ast.comments;
  25724. if (astComments) {
  25725. delete ast.comments;
  25726. comments.attach(astComments, ast, text, opts);
  25727. }
  25728. ast.tokens = [];
  25729. opts.originalText = text.trimRight();
  25730. return astComments;
  25731. }
  25732. function ensureAllCommentsPrinted(astComments) {
  25733. if (!astComments) {
  25734. return;
  25735. }
  25736. for (let i = 0; i < astComments.length; ++i) {
  25737. if (astComments[i].value.trim() === "prettier-ignore") {
  25738. // If there's a prettier-ignore, we're not printing that sub-tree so we
  25739. // don't know if the comments was printed or not.
  25740. return;
  25741. }
  25742. }
  25743. astComments.forEach(comment => {
  25744. if (!comment.printed) {
  25745. throw new Error(
  25746. 'Comment "' +
  25747. comment.value.trim() +
  25748. '" was not printed. Please report this error!'
  25749. );
  25750. }
  25751. delete comment.printed;
  25752. });
  25753. }
  25754. function formatWithCursor(text, opts, addAlignmentSize) {
  25755. const selectedParser = parser$3.resolveParser(opts);
  25756. const hasPragma = !selectedParser.hasPragma || selectedParser.hasPragma(text);
  25757. if (opts.requirePragma && !hasPragma) {
  25758. return { formatted: text };
  25759. }
  25760. const UTF8BOM = 0xfeff;
  25761. const hasUnicodeBOM = text.charCodeAt(0) === UTF8BOM;
  25762. if (hasUnicodeBOM) {
  25763. text = text.substring(1);
  25764. }
  25765. if (
  25766. opts.insertPragma &&
  25767. opts.printer.insertPragma &&
  25768. !hasPragma &&
  25769. opts.rangeStart === 0 &&
  25770. opts.rangeEnd === Infinity
  25771. ) {
  25772. text = opts.printer.insertPragma(text);
  25773. }
  25774. addAlignmentSize = addAlignmentSize || 0;
  25775. const result = parser$3.parse(text, opts);
  25776. const ast = result.ast;
  25777. text = result.text;
  25778. const formattedRangeOnly = formatRange(text, opts, ast);
  25779. if (formattedRangeOnly) {
  25780. return { formatted: formattedRangeOnly };
  25781. }
  25782. let cursorOffset;
  25783. if (opts.cursorOffset >= 0) {
  25784. const cursorNodeAndParents = findNodeAtOffset(ast, opts.cursorOffset, opts);
  25785. const cursorNode = cursorNodeAndParents.node;
  25786. if (cursorNode) {
  25787. cursorOffset = opts.cursorOffset - opts.locStart(cursorNode);
  25788. opts.cursorNode = cursorNode;
  25789. }
  25790. }
  25791. const astComments = attachComments(text, ast, opts);
  25792. const doc$$1 = astToDoc(ast, opts, addAlignmentSize);
  25793. opts.newLine = guessLineEnding(text);
  25794. const toStringResult = printDocToString(doc$$1, opts);
  25795. let str = toStringResult.formatted;
  25796. if (hasUnicodeBOM) {
  25797. str = String.fromCharCode(UTF8BOM) + str;
  25798. }
  25799. const cursorOffsetResult = toStringResult.cursor;
  25800. ensureAllCommentsPrinted(astComments);
  25801. // Remove extra leading indentation as well as the added indentation after last newline
  25802. if (addAlignmentSize > 0) {
  25803. return { formatted: str.trim() + opts.newLine };
  25804. }
  25805. if (cursorOffset !== undefined) {
  25806. return {
  25807. formatted: str,
  25808. cursorOffset: cursorOffsetResult + cursorOffset
  25809. };
  25810. }
  25811. return { formatted: str };
  25812. }
  25813. function format(text, opts, addAlignmentSize) {
  25814. return formatWithCursor(text, opts, addAlignmentSize).formatted;
  25815. }
  25816. function findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts) {
  25817. let resultStartNode = startNodeAndParents.node;
  25818. let resultEndNode = endNodeAndParents.node;
  25819. if (resultStartNode === resultEndNode) {
  25820. return {
  25821. startNode: resultStartNode,
  25822. endNode: resultEndNode
  25823. };
  25824. }
  25825. for (const endParent of endNodeAndParents.parentNodes) {
  25826. if (
  25827. endParent.type !== "Program" &&
  25828. endParent.type !== "File" &&
  25829. opts.locStart(endParent) >= opts.locStart(startNodeAndParents.node)
  25830. ) {
  25831. resultEndNode = endParent;
  25832. } else {
  25833. break;
  25834. }
  25835. }
  25836. for (const startParent of startNodeAndParents.parentNodes) {
  25837. if (
  25838. startParent.type !== "Program" &&
  25839. startParent.type !== "File" &&
  25840. opts.locEnd(startParent) <= opts.locEnd(endNodeAndParents.node)
  25841. ) {
  25842. resultStartNode = startParent;
  25843. } else {
  25844. break;
  25845. }
  25846. }
  25847. return {
  25848. startNode: resultStartNode,
  25849. endNode: resultEndNode
  25850. };
  25851. }
  25852. function findNodeAtOffset(node, offset, options, predicate, parentNodes) {
  25853. predicate = predicate || (() => true);
  25854. parentNodes = parentNodes || [];
  25855. const start = options.locStart(node, options.locStart);
  25856. const end = options.locEnd(node, options.locEnd);
  25857. if (start <= offset && offset <= end) {
  25858. for (const childNode of comments.getSortedChildNodes(
  25859. node,
  25860. undefined /* text */,
  25861. options
  25862. )) {
  25863. const childResult = findNodeAtOffset(
  25864. childNode,
  25865. offset,
  25866. options,
  25867. predicate,
  25868. [node].concat(parentNodes)
  25869. );
  25870. if (childResult) {
  25871. return childResult;
  25872. }
  25873. }
  25874. if (predicate(node)) {
  25875. return {
  25876. node: node,
  25877. parentNodes: parentNodes
  25878. };
  25879. }
  25880. }
  25881. }
  25882. // See https://www.ecma-international.org/ecma-262/5.1/#sec-A.5
  25883. function isSourceElement(opts, node) {
  25884. if (node == null) {
  25885. return false;
  25886. }
  25887. // JS and JS like to avoid repetitions
  25888. const jsSourceElements = [
  25889. "FunctionDeclaration",
  25890. "BlockStatement",
  25891. "BreakStatement",
  25892. "ContinueStatement",
  25893. "DebuggerStatement",
  25894. "DoWhileStatement",
  25895. "EmptyStatement",
  25896. "ExpressionStatement",
  25897. "ForInStatement",
  25898. "ForStatement",
  25899. "IfStatement",
  25900. "LabeledStatement",
  25901. "ReturnStatement",
  25902. "SwitchStatement",
  25903. "ThrowStatement",
  25904. "TryStatement",
  25905. "VariableDeclaration",
  25906. "WhileStatement",
  25907. "WithStatement",
  25908. "ClassDeclaration", // ES 2015
  25909. "ImportDeclaration", // Module
  25910. "ExportDefaultDeclaration", // Module
  25911. "ExportNamedDeclaration", // Module
  25912. "ExportAllDeclaration", // Module
  25913. "TypeAlias", // Flow
  25914. "InterfaceDeclaration", // Flow, TypeScript
  25915. "TypeAliasDeclaration", // TypeScript
  25916. "ExportAssignment", // TypeScript
  25917. "ExportDeclaration" // TypeScript
  25918. ];
  25919. const jsonSourceElements = [
  25920. "ObjectExpression",
  25921. "ArrayExpression",
  25922. "StringLiteral",
  25923. "NumericLiteral",
  25924. "BooleanLiteral",
  25925. "NullLiteral"
  25926. ];
  25927. const graphqlSourceElements = [
  25928. "OperationDefinition",
  25929. "FragmentDefinition",
  25930. "VariableDefinition",
  25931. "TypeExtensionDefinition",
  25932. "ObjectTypeDefinition",
  25933. "FieldDefinition",
  25934. "DirectiveDefinition",
  25935. "EnumTypeDefinition",
  25936. "EnumValueDefinition",
  25937. "InputValueDefinition",
  25938. "InputObjectTypeDefinition",
  25939. "SchemaDefinition",
  25940. "OperationTypeDefinition",
  25941. "InterfaceTypeDefinition",
  25942. "UnionTypeDefinition",
  25943. "ScalarTypeDefinition"
  25944. ];
  25945. switch (opts.parser) {
  25946. case "flow":
  25947. case "babylon":
  25948. case "typescript":
  25949. return jsSourceElements.indexOf(node.type) > -1;
  25950. case "json":
  25951. return jsonSourceElements.indexOf(node.type) > -1;
  25952. case "graphql":
  25953. return graphqlSourceElements.indexOf(node.kind) > -1;
  25954. }
  25955. return false;
  25956. }
  25957. function calculateRange(text, opts, ast) {
  25958. // Contract the range so that it has non-whitespace characters at its endpoints.
  25959. // This ensures we can format a range that doesn't end on a node.
  25960. const rangeStringOrig = text.slice(opts.rangeStart, opts.rangeEnd);
  25961. const startNonWhitespace = Math.max(
  25962. opts.rangeStart + rangeStringOrig.search(/\S/),
  25963. opts.rangeStart
  25964. );
  25965. let endNonWhitespace;
  25966. for (
  25967. endNonWhitespace = opts.rangeEnd;
  25968. endNonWhitespace > opts.rangeStart;
  25969. --endNonWhitespace
  25970. ) {
  25971. if (text[endNonWhitespace - 1].match(/\S/)) {
  25972. break;
  25973. }
  25974. }
  25975. const startNodeAndParents = findNodeAtOffset(
  25976. ast,
  25977. startNonWhitespace,
  25978. opts,
  25979. node => isSourceElement(opts, node)
  25980. );
  25981. const endNodeAndParents = findNodeAtOffset(
  25982. ast,
  25983. endNonWhitespace,
  25984. opts,
  25985. node => isSourceElement(opts, node)
  25986. );
  25987. if (!startNodeAndParents || !endNodeAndParents) {
  25988. return {
  25989. rangeStart: 0,
  25990. rangeEnd: 0
  25991. };
  25992. }
  25993. const siblingAncestors = findSiblingAncestors(
  25994. startNodeAndParents,
  25995. endNodeAndParents,
  25996. opts
  25997. );
  25998. const startNode = siblingAncestors.startNode;
  25999. const endNode = siblingAncestors.endNode;
  26000. const rangeStart = Math.min(
  26001. opts.locStart(startNode, opts.locStart),
  26002. opts.locStart(endNode, opts.locStart)
  26003. );
  26004. const rangeEnd = Math.max(
  26005. opts.locEnd(startNode, opts.locEnd),
  26006. opts.locEnd(endNode, opts.locEnd)
  26007. );
  26008. return {
  26009. rangeStart: rangeStart,
  26010. rangeEnd: rangeEnd
  26011. };
  26012. }
  26013. function formatRange(text, opts, ast) {
  26014. if (opts.rangeStart <= 0 && text.length <= opts.rangeEnd) {
  26015. return;
  26016. }
  26017. const range = calculateRange(text, opts, ast);
  26018. const rangeStart = range.rangeStart;
  26019. const rangeEnd = range.rangeEnd;
  26020. const rangeString = text.slice(rangeStart, rangeEnd);
  26021. // Try to extend the range backwards to the beginning of the line.
  26022. // This is so we can detect indentation correctly and restore it.
  26023. // Use `Math.min` since `lastIndexOf` returns 0 when `rangeStart` is 0
  26024. const rangeStart2 = Math.min(
  26025. rangeStart,
  26026. text.lastIndexOf("\n", rangeStart) + 1
  26027. );
  26028. const indentString = text.slice(rangeStart2, rangeStart);
  26029. const alignmentSize = util$1.getAlignmentSize(
  26030. indentString,
  26031. opts.tabWidth
  26032. );
  26033. const rangeFormatted = format(
  26034. rangeString,
  26035. Object.assign({}, opts, {
  26036. rangeStart: 0,
  26037. rangeEnd: Infinity,
  26038. printWidth: opts.printWidth - alignmentSize
  26039. }),
  26040. alignmentSize
  26041. );
  26042. // Since the range contracts to avoid trailing whitespace,
  26043. // we need to remove the newline that was inserted by the `format` call.
  26044. const rangeTrimmed = rangeFormatted.trimRight();
  26045. return text.slice(0, rangeStart) + rangeTrimmed + text.slice(rangeEnd);
  26046. }
  26047. var prettier = {
  26048. formatWithCursor: function(text, opts) {
  26049. return formatWithCursor(text, normalizeOptions(opts));
  26050. },
  26051. format: function(text, opts) {
  26052. return format(text, normalizeOptions(opts));
  26053. },
  26054. check: function(text, opts) {
  26055. try {
  26056. const formatted = format(text, normalizeOptions(opts));
  26057. return formatted === text;
  26058. } catch (e) {
  26059. return false;
  26060. }
  26061. },
  26062. doc,
  26063. resolveConfig: resolveConfig_1.resolveConfig,
  26064. clearConfigCache: resolveConfig_1.clearCache,
  26065. getSupportInfo,
  26066. version,
  26067. util: utilShared,
  26068. /* istanbul ignore next */
  26069. __debug: {
  26070. parse: function(text, opts) {
  26071. opts = normalizeOptions(opts);
  26072. return parser$3.parse(text, opts);
  26073. },
  26074. formatAST: function(ast, opts) {
  26075. opts = normalizeOptions(opts);
  26076. const doc$$1 = astToDoc(ast, opts);
  26077. const str = printDocToString(doc$$1, opts);
  26078. return str;
  26079. },
  26080. // Doesn't handle shebang for now
  26081. formatDoc: function(doc$$1, opts) {
  26082. opts = normalizeOptions(opts);
  26083. const debug = printDocToDebug(doc$$1);
  26084. const str = format(debug, opts);
  26085. return str;
  26086. },
  26087. printToDoc: function(text, opts) {
  26088. opts = normalizeOptions(opts);
  26089. const result = parser$3.parse(text, opts);
  26090. const ast = result.ast;
  26091. text = result.text;
  26092. attachComments(text, ast, opts);
  26093. const doc$$1 = astToDoc(ast, opts);
  26094. return doc$$1;
  26095. },
  26096. printDocToString: function(doc$$1, opts) {
  26097. opts = normalizeOptions(opts);
  26098. const str = printDocToString(doc$$1, opts);
  26099. return str;
  26100. }
  26101. }
  26102. };
  26103. module.exports = prettier;