bin-prettier.js 1.0 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684
  1. #!/usr/bin/env node
  2. 'use strict';
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var fs = _interopDefault(require('fs'));
  5. var path = _interopDefault(require('path'));
  6. var util = _interopDefault(require('util'));
  7. var url = _interopDefault(require('url'));
  8. var assert = _interopDefault(require('assert'));
  9. var os = _interopDefault(require('os'));
  10. var thirdParty = require('./third-party');
  11. var thirdParty__default = thirdParty['default'];
  12. var events = _interopDefault(require('events'));
  13. var readline = _interopDefault(require('readline'));
  14. var name = "prettier";
  15. var version$1 = "1.12.1";
  16. var description = "Prettier is an opinionated code formatter";
  17. var bin = {"prettier":"./bin/prettier.js"};
  18. var repository = "prettier/prettier";
  19. var homepage = "https://prettier.io";
  20. var author = "James Long";
  21. var license = "MIT";
  22. var main = "./index.js";
  23. var engines = {"node":">=4"};
  24. 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"};
  25. 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"};
  26. 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"};
  27. var _package = {
  28. name: name,
  29. version: version$1,
  30. description: description,
  31. bin: bin,
  32. repository: repository,
  33. homepage: homepage,
  34. author: author,
  35. license: license,
  36. main: main,
  37. engines: engines,
  38. dependencies: dependencies,
  39. devDependencies: devDependencies,
  40. scripts: scripts
  41. };
  42. var _package$1 = Object.freeze({
  43. name: name,
  44. version: version$1,
  45. description: description,
  46. bin: bin,
  47. repository: repository,
  48. homepage: homepage,
  49. author: author,
  50. license: license,
  51. main: main,
  52. engines: engines,
  53. dependencies: dependencies,
  54. devDependencies: devDependencies,
  55. scripts: scripts,
  56. default: _package
  57. });
  58. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  59. function commonjsRequire () {
  60. throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
  61. }
  62. function unwrapExports (x) {
  63. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  64. }
  65. function createCommonjsModule(fn, module) {
  66. return module = { exports: {} }, fn(module, module.exports), module.exports;
  67. }
  68. var ansiRegex = createCommonjsModule(function (module) {
  69. 'use strict';
  70. module.exports = () => {
  71. const pattern = [
  72. '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)',
  73. '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))'
  74. ].join('|');
  75. return new RegExp(pattern, 'g');
  76. };
  77. });
  78. var stripAnsi = input => typeof input === 'string' ? input.replace(ansiRegex(), '') : input;
  79. var isFullwidthCodePoint = createCommonjsModule(function (module) {
  80. 'use strict';
  81. /* eslint-disable yoda */
  82. module.exports = x => {
  83. if (Number.isNaN(x)) {
  84. return false;
  85. }
  86. // code points are derived from:
  87. // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
  88. if (
  89. x >= 0x1100 && (
  90. x <= 0x115f || // Hangul Jamo
  91. x === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  92. x === 0x232a || // RIGHT-POINTING ANGLE BRACKET
  93. // CJK Radicals Supplement .. Enclosed CJK Letters and Months
  94. (0x2e80 <= x && x <= 0x3247 && x !== 0x303f) ||
  95. // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
  96. (0x3250 <= x && x <= 0x4dbf) ||
  97. // CJK Unified Ideographs .. Yi Radicals
  98. (0x4e00 <= x && x <= 0xa4c6) ||
  99. // Hangul Jamo Extended-A
  100. (0xa960 <= x && x <= 0xa97c) ||
  101. // Hangul Syllables
  102. (0xac00 <= x && x <= 0xd7a3) ||
  103. // CJK Compatibility Ideographs
  104. (0xf900 <= x && x <= 0xfaff) ||
  105. // Vertical Forms
  106. (0xfe10 <= x && x <= 0xfe19) ||
  107. // CJK Compatibility Forms .. Small Form Variants
  108. (0xfe30 <= x && x <= 0xfe6b) ||
  109. // Halfwidth and Fullwidth Forms
  110. (0xff01 <= x && x <= 0xff60) ||
  111. (0xffe0 <= x && x <= 0xffe6) ||
  112. // Kana Supplement
  113. (0x1b000 <= x && x <= 0x1b001) ||
  114. // Enclosed Ideographic Supplement
  115. (0x1f200 <= x && x <= 0x1f251) ||
  116. // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
  117. (0x20000 <= x && x <= 0x3fffd)
  118. )
  119. ) {
  120. return true;
  121. }
  122. return false;
  123. };
  124. });
  125. var stringWidth = createCommonjsModule(function (module) {
  126. 'use strict';
  127. module.exports = str => {
  128. if (typeof str !== 'string' || str.length === 0) {
  129. return 0;
  130. }
  131. str = stripAnsi(str);
  132. let width = 0;
  133. for (let i = 0; i < str.length; i++) {
  134. const code = str.codePointAt(i);
  135. // Ignore control characters
  136. if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
  137. continue;
  138. }
  139. // Ignore combining characters
  140. if (code >= 0x300 && code <= 0x36F) {
  141. continue;
  142. }
  143. // Surrogates
  144. if (code > 0xFFFF) {
  145. i++;
  146. }
  147. width += isFullwidthCodePoint(code) ? 2 : 1;
  148. }
  149. return width;
  150. };
  151. });
  152. var emojiRegex$1 = function () {
  153. // https://mathiasbynens.be/notes/es-unicode-property-escapes#emoji
  154. 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
  155. );
  156. };
  157. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  158. var escapeStringRegexp = function (str) {
  159. if (typeof str !== 'string') {
  160. throw new TypeError('Expected a string');
  161. }
  162. return str.replace(matchOperatorsRe, '\\$&');
  163. };
  164. var punctuation_ranges = [
  165. // http://www.unicode.org/charts/PDF/U3000.pdf CJK Symbols and Punctuation
  166. [0x3000, 0x303f],
  167. // http://www.unicode.org/charts/PDF/UAC00.pdf Hangul Syllables
  168. [0xac00, 0xd7af],
  169. // http://www.unicode.org/charts/PDF/UFE10.pdf Vertical Forms
  170. [0xfe10, 0xfe1f],
  171. // http://www.unicode.org/charts/PDF/UFE30.pdf CJK Compatibility Forms
  172. // http://www.unicode.org/charts/PDF/UFE50.pdf Small Form Variants
  173. [0xfe30, 0xfe6f],
  174. // http://www.unicode.org/charts/PDF/UFF00.pdf Halfwidth and Fullwidth Forms
  175. [0xff00, 0xff60],
  176. [0xffe0, 0xffef],
  177. ];
  178. var character_ranges = [
  179. // http://www.unicode.org/charts/PDF/U1100.pdf Hangul Jamo
  180. [0x1100, 0x11ff],
  181. // http://www.unicode.org/charts/PDF/U2E80.pdf CJK Radicals Supplement
  182. // http://www.unicode.org/charts/PDF/U2F00.pdf Kangxi Radicals
  183. [0x2e80, 0x2fdf],
  184. // http://www.unicode.org/charts/PDF/U3040.pdf Hiragana
  185. // http://www.unicode.org/charts/PDF/U30A0.pdf Katakana
  186. // http://www.unicode.org/charts/PDF/U3100.pdf Bopomofo
  187. // http://www.unicode.org/charts/PDF/U3130.pdf Hangul Compatibility Jamo
  188. [0x3040, 0x318f],
  189. // http://www.unicode.org/charts/PDF/U3200.pdf Enclosed CJK Letters and Months
  190. // http://www.unicode.org/charts/PDF/U3300.pdf CJK Compatibility
  191. // http://www.unicode.org/charts/PDF/U3400.pdf CJK Unified Ideographs Extension A
  192. [0x3200, 0x4dbf],
  193. // http://www.unicode.org/charts/PDF/U4E00.pdf CJK Unified Ideographs (Han)
  194. [0x4e00, 0x9fff],
  195. // http://www.unicode.org/charts/PDF/UA960.pdf Hangul Jamo Extended-A
  196. [0xa960, 0xa97f],
  197. // http://www.unicode.org/charts/PDF/UF900.pdf CJK Compatibility Ideographs
  198. [0xf900, 0xfaff],
  199. ];
  200. function get_regex() {
  201. return create_regex(character_ranges.concat(punctuation_ranges));
  202. }
  203. // istanbul ignore next
  204. // tslint:disable-next-line:no-namespace
  205. (function (get_regex) {
  206. function punctuations() {
  207. return create_regex(punctuation_ranges);
  208. }
  209. get_regex.punctuations = punctuations;
  210. function characters() {
  211. return create_regex(character_ranges);
  212. }
  213. get_regex.characters = characters;
  214. })(get_regex || (get_regex = {}));
  215. function create_regex(ranges) {
  216. return new RegExp("[" + ranges.map(get_bracket_content).reduce(function (a, b) { return a + b; }) + "]", 'g');
  217. }
  218. function get_bracket_content(range) {
  219. return get_escaped_unicode(range[0]) + "-" + get_escaped_unicode(range[1]);
  220. }
  221. function get_escaped_unicode(num) {
  222. return "\\u" + num.toString(16);
  223. }
  224. var lib = get_regex;
  225. var data_generated = createCommonjsModule(function (module, exports) {
  226. "use strict";
  227. exports.__esModule = true;
  228. 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]] }); };
  229. });
  230. unwrapExports(data_generated);
  231. var utils = createCommonjsModule(function (module, exports) {
  232. "use strict";
  233. exports.__esModule = true;
  234. function normalize_ranges(ranges) {
  235. return ranges
  236. .sort(function (_a, _b) {
  237. var start1 = _a[0];
  238. var start2 = _b[0];
  239. return start1 - start2;
  240. })
  241. .reduce(function (current, tuple, index) {
  242. if (index === 0) {
  243. return [tuple];
  244. }
  245. var _a = current[current.length - 1], last_start = _a[0], last_end = _a[1];
  246. var start = tuple[0], end = tuple[1];
  247. return last_end + 1 === start
  248. ? current.slice(0, -1).concat([[last_start, end]]) : current.concat([tuple]);
  249. }, []);
  250. }
  251. exports.normalize_ranges = normalize_ranges;
  252. function build_regex(ranges, flag) {
  253. var pattern = ranges
  254. .map(function (_a) {
  255. var start = _a[0], end = _a[1];
  256. return start === end
  257. ? "\\u" + get_hex(start)
  258. : "\\u" + get_hex(start) + "-\\u" + get_hex(end);
  259. })
  260. .join('');
  261. return new RegExp("[" + pattern + "]", flag);
  262. }
  263. exports.build_regex = build_regex;
  264. function get_hex(char_code) {
  265. var hex = char_code.toString(16);
  266. while (hex.length < 4) {
  267. hex = "0" + hex;
  268. }
  269. return hex;
  270. }
  271. });
  272. unwrapExports(utils);
  273. var lib$2 = function (categories, flag) {
  274. var data = data_generated.get_data();
  275. var ranges = categories.reduce(function (current, category) { return current.concat(data[category]); }, []);
  276. return utils.build_regex(utils.normalize_ranges(ranges), flag);
  277. };
  278. const emojiRegex = emojiRegex$1();
  279. const cjkPattern = lib().source;
  280. // http://spec.commonmark.org/0.25/#ascii-punctuation-character
  281. const asciiPunctuationCharRange = escapeStringRegexp(
  282. "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
  283. );
  284. // http://spec.commonmark.org/0.25/#punctuation-character
  285. const punctuationCharRange = `${asciiPunctuationCharRange}${lib$2([
  286. "Pc",
  287. "Pd",
  288. "Pe",
  289. "Pf",
  290. "Pi",
  291. "Po",
  292. "Ps"
  293. ]).source.slice(1, -1)}`; // remove bracket expression `[` and `]`
  294. const punctuationRegex = new RegExp(`[${punctuationCharRange}]`);
  295. function isExportDeclaration(node) {
  296. if (node) {
  297. switch (node.type) {
  298. case "ExportDefaultDeclaration":
  299. case "ExportDefaultSpecifier":
  300. case "DeclareExportDeclaration":
  301. case "ExportNamedDeclaration":
  302. case "ExportAllDeclaration":
  303. return true;
  304. }
  305. }
  306. return false;
  307. }
  308. function getParentExportDeclaration(path$$1) {
  309. const parentNode = path$$1.getParentNode();
  310. if (path$$1.getName() === "declaration" && isExportDeclaration(parentNode)) {
  311. return parentNode;
  312. }
  313. return null;
  314. }
  315. function getPenultimate(arr) {
  316. if (arr.length > 1) {
  317. return arr[arr.length - 2];
  318. }
  319. return null;
  320. }
  321. function getLast(arr) {
  322. if (arr.length > 0) {
  323. return arr[arr.length - 1];
  324. }
  325. return null;
  326. }
  327. function skip(chars) {
  328. return (text, index, opts) => {
  329. const backwards = opts && opts.backwards;
  330. // Allow `skip` functions to be threaded together without having
  331. // to check for failures (did someone say monads?).
  332. if (index === false) {
  333. return false;
  334. }
  335. const length = text.length;
  336. let cursor = index;
  337. while (cursor >= 0 && cursor < length) {
  338. const c = text.charAt(cursor);
  339. if (chars instanceof RegExp) {
  340. if (!chars.test(c)) {
  341. return cursor;
  342. }
  343. } else if (chars.indexOf(c) === -1) {
  344. return cursor;
  345. }
  346. backwards ? cursor-- : cursor++;
  347. }
  348. if (cursor === -1 || cursor === length) {
  349. // If we reached the beginning or end of the file, return the
  350. // out-of-bounds cursor. It's up to the caller to handle this
  351. // correctly. We don't want to indicate `false` though if it
  352. // actually skipped valid characters.
  353. return cursor;
  354. }
  355. return false;
  356. };
  357. }
  358. const skipWhitespace = skip(/\s/);
  359. const skipSpaces = skip(" \t");
  360. const skipToLineEnd = skip(",; \t");
  361. const skipEverythingButNewLine = skip(/[^\r\n]/);
  362. function skipInlineComment(text, index) {
  363. if (index === false) {
  364. return false;
  365. }
  366. if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
  367. for (let i = index + 2; i < text.length; ++i) {
  368. if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
  369. return i + 2;
  370. }
  371. }
  372. }
  373. return index;
  374. }
  375. function skipTrailingComment(text, index) {
  376. if (index === false) {
  377. return false;
  378. }
  379. if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
  380. return skipEverythingButNewLine(text, index);
  381. }
  382. return index;
  383. }
  384. // This one doesn't use the above helper function because it wants to
  385. // test \r\n in order and `skip` doesn't support ordering and we only
  386. // want to skip one newline. It's simple to implement.
  387. function skipNewline(text, index, opts) {
  388. const backwards = opts && opts.backwards;
  389. if (index === false) {
  390. return false;
  391. }
  392. const atIndex = text.charAt(index);
  393. if (backwards) {
  394. if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
  395. return index - 2;
  396. }
  397. if (
  398. atIndex === "\n" ||
  399. atIndex === "\r" ||
  400. atIndex === "\u2028" ||
  401. atIndex === "\u2029"
  402. ) {
  403. return index - 1;
  404. }
  405. } else {
  406. if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
  407. return index + 2;
  408. }
  409. if (
  410. atIndex === "\n" ||
  411. atIndex === "\r" ||
  412. atIndex === "\u2028" ||
  413. atIndex === "\u2029"
  414. ) {
  415. return index + 1;
  416. }
  417. }
  418. return index;
  419. }
  420. function hasNewline(text, index, opts) {
  421. opts = opts || {};
  422. const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  423. const idx2 = skipNewline(text, idx, opts);
  424. return idx !== idx2;
  425. }
  426. function hasNewlineInRange(text, start, end) {
  427. for (let i = start; i < end; ++i) {
  428. if (text.charAt(i) === "\n") {
  429. return true;
  430. }
  431. }
  432. return false;
  433. }
  434. // Note: this function doesn't ignore leading comments unlike isNextLineEmpty
  435. function isPreviousLineEmpty(text, node, locStart) {
  436. let idx = locStart(node) - 1;
  437. idx = skipSpaces(text, idx, { backwards: true });
  438. idx = skipNewline(text, idx, { backwards: true });
  439. idx = skipSpaces(text, idx, { backwards: true });
  440. const idx2 = skipNewline(text, idx, { backwards: true });
  441. return idx !== idx2;
  442. }
  443. function isNextLineEmptyAfterIndex(text, index) {
  444. let oldIdx = null;
  445. let idx = index;
  446. while (idx !== oldIdx) {
  447. // We need to skip all the potential trailing inline comments
  448. oldIdx = idx;
  449. idx = skipToLineEnd(text, idx);
  450. idx = skipInlineComment(text, idx);
  451. idx = skipSpaces(text, idx);
  452. }
  453. idx = skipTrailingComment(text, idx);
  454. idx = skipNewline(text, idx);
  455. return hasNewline(text, idx);
  456. }
  457. function isNextLineEmpty(text, node, locEnd) {
  458. return isNextLineEmptyAfterIndex(text, locEnd(node));
  459. }
  460. function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
  461. let oldIdx = null;
  462. let idx = locEnd(node);
  463. while (idx !== oldIdx) {
  464. oldIdx = idx;
  465. idx = skipSpaces(text, idx);
  466. idx = skipInlineComment(text, idx);
  467. idx = skipTrailingComment(text, idx);
  468. idx = skipNewline(text, idx);
  469. }
  470. return idx;
  471. }
  472. function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
  473. return text.charAt(
  474. getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
  475. );
  476. }
  477. function hasSpaces(text, index, opts) {
  478. opts = opts || {};
  479. const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  480. return idx !== index;
  481. }
  482. // Super inefficient, needs to be cached.
  483. function lineColumnToIndex(lineColumn, text) {
  484. let index = 0;
  485. for (let i = 0; i < lineColumn.line - 1; ++i) {
  486. index = text.indexOf("\n", index) + 1;
  487. if (index === -1) {
  488. return -1;
  489. }
  490. }
  491. return index + lineColumn.column;
  492. }
  493. function setLocStart(node, index) {
  494. if (node.range) {
  495. node.range[0] = index;
  496. } else {
  497. node.start = index;
  498. }
  499. }
  500. function setLocEnd(node, index) {
  501. if (node.range) {
  502. node.range[1] = index;
  503. } else {
  504. node.end = index;
  505. }
  506. }
  507. const PRECEDENCE = {};
  508. [
  509. ["|>"],
  510. ["||", "??"],
  511. ["&&"],
  512. ["|"],
  513. ["^"],
  514. ["&"],
  515. ["==", "===", "!=", "!=="],
  516. ["<", ">", "<=", ">=", "in", "instanceof"],
  517. [">>", "<<", ">>>"],
  518. ["+", "-"],
  519. ["*", "/", "%"],
  520. ["**"]
  521. ].forEach((tier, i) => {
  522. tier.forEach(op => {
  523. PRECEDENCE[op] = i;
  524. });
  525. });
  526. function getPrecedence(op) {
  527. return PRECEDENCE[op];
  528. }
  529. const equalityOperators = {
  530. "==": true,
  531. "!=": true,
  532. "===": true,
  533. "!==": true
  534. };
  535. const multiplicativeOperators = {
  536. "*": true,
  537. "/": true,
  538. "%": true
  539. };
  540. const bitshiftOperators = {
  541. ">>": true,
  542. ">>>": true,
  543. "<<": true
  544. };
  545. function shouldFlatten(parentOp, nodeOp) {
  546. if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) {
  547. return false;
  548. }
  549. // ** is right-associative
  550. // x ** y ** z --> x ** (y ** z)
  551. if (parentOp === "**") {
  552. return false;
  553. }
  554. // x == y == z --> (x == y) == z
  555. if (equalityOperators[parentOp] && equalityOperators[nodeOp]) {
  556. return false;
  557. }
  558. // x * y % z --> (x * y) % z
  559. if (
  560. (nodeOp === "%" && multiplicativeOperators[parentOp]) ||
  561. (parentOp === "%" && multiplicativeOperators[nodeOp])
  562. ) {
  563. return false;
  564. }
  565. // x << y << z --> (x << y) << z
  566. if (bitshiftOperators[parentOp] && bitshiftOperators[nodeOp]) {
  567. return false;
  568. }
  569. return true;
  570. }
  571. function isBitwiseOperator(operator) {
  572. return (
  573. !!bitshiftOperators[operator] ||
  574. operator === "|" ||
  575. operator === "^" ||
  576. operator === "&"
  577. );
  578. }
  579. // Tests if an expression starts with `{`, or (if forbidFunctionAndClass holds) `function` or `class`.
  580. // Will be overzealous if there's already necessary grouping parentheses.
  581. function startsWithNoLookaheadToken(node, forbidFunctionAndClass) {
  582. node = getLeftMost(node);
  583. switch (node.type) {
  584. // Hack. Remove after https://github.com/eslint/typescript-eslint-parser/issues/331
  585. case "ObjectPattern":
  586. return !forbidFunctionAndClass;
  587. case "FunctionExpression":
  588. case "ClassExpression":
  589. return forbidFunctionAndClass;
  590. case "ObjectExpression":
  591. return true;
  592. case "MemberExpression":
  593. return startsWithNoLookaheadToken(node.object, forbidFunctionAndClass);
  594. case "TaggedTemplateExpression":
  595. if (node.tag.type === "FunctionExpression") {
  596. // IIFEs are always already parenthesized
  597. return false;
  598. }
  599. return startsWithNoLookaheadToken(node.tag, forbidFunctionAndClass);
  600. case "CallExpression":
  601. if (node.callee.type === "FunctionExpression") {
  602. // IIFEs are always already parenthesized
  603. return false;
  604. }
  605. return startsWithNoLookaheadToken(node.callee, forbidFunctionAndClass);
  606. case "ConditionalExpression":
  607. return startsWithNoLookaheadToken(node.test, forbidFunctionAndClass);
  608. case "UpdateExpression":
  609. return (
  610. !node.prefix &&
  611. startsWithNoLookaheadToken(node.argument, forbidFunctionAndClass)
  612. );
  613. case "BindExpression":
  614. return (
  615. node.object &&
  616. startsWithNoLookaheadToken(node.object, forbidFunctionAndClass)
  617. );
  618. case "SequenceExpression":
  619. return startsWithNoLookaheadToken(
  620. node.expressions[0],
  621. forbidFunctionAndClass
  622. );
  623. case "TSAsExpression":
  624. return startsWithNoLookaheadToken(
  625. node.expression,
  626. forbidFunctionAndClass
  627. );
  628. default:
  629. return false;
  630. }
  631. }
  632. function getLeftMost(node) {
  633. if (node.left) {
  634. return getLeftMost(node.left);
  635. }
  636. return node;
  637. }
  638. function hasBlockComments(node) {
  639. return node.comments && node.comments.some(isBlockComment);
  640. }
  641. function isBlockComment(comment) {
  642. return comment.type === "Block" || comment.type === "CommentBlock";
  643. }
  644. function hasClosureCompilerTypeCastComment(text, node, locEnd) {
  645. // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
  646. // Syntax example: var x = /** @type {string} */ (fruit);
  647. return (
  648. node.comments &&
  649. node.comments.some(
  650. comment =>
  651. comment.leading &&
  652. isBlockComment(comment) &&
  653. comment.value.match(/^\*\s*@type\s*{[^}]+}\s*$/) &&
  654. getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "("
  655. )
  656. );
  657. }
  658. function getAlignmentSize(value, tabWidth, startIndex) {
  659. startIndex = startIndex || 0;
  660. let size = 0;
  661. for (let i = startIndex; i < value.length; ++i) {
  662. if (value[i] === "\t") {
  663. // Tabs behave in a way that they are aligned to the nearest
  664. // multiple of tabWidth:
  665. // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
  666. // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
  667. size = size + tabWidth - size % tabWidth;
  668. } else {
  669. size++;
  670. }
  671. }
  672. return size;
  673. }
  674. function getIndentSize(value, tabWidth) {
  675. const lastNewlineIndex = value.lastIndexOf("\n");
  676. if (lastNewlineIndex === -1) {
  677. return 0;
  678. }
  679. return getAlignmentSize(
  680. // All the leading whitespaces
  681. value.slice(lastNewlineIndex + 1).match(/^[ \t]*/)[0],
  682. tabWidth
  683. );
  684. }
  685. function printString(raw, options, isDirectiveLiteral) {
  686. // `rawContent` is the string exactly like it appeared in the input source
  687. // code, without its enclosing quotes.
  688. const rawContent = raw.slice(1, -1);
  689. const double = { quote: '"', regex: /"/g };
  690. const single = { quote: "'", regex: /'/g };
  691. const preferred = options.singleQuote ? single : double;
  692. const alternate = preferred === single ? double : single;
  693. let shouldUseAlternateQuote = false;
  694. let canChangeDirectiveQuotes = false;
  695. // If `rawContent` contains at least one of the quote preferred for enclosing
  696. // the string, we might want to enclose with the alternate quote instead, to
  697. // minimize the number of escaped quotes.
  698. // Also check for the alternate quote, to determine if we're allowed to swap
  699. // the quotes on a DirectiveLiteral.
  700. if (
  701. rawContent.includes(preferred.quote) ||
  702. rawContent.includes(alternate.quote)
  703. ) {
  704. const numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
  705. const numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
  706. shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes;
  707. } else {
  708. canChangeDirectiveQuotes = true;
  709. }
  710. const enclosingQuote =
  711. options.parser === "json"
  712. ? double.quote
  713. : shouldUseAlternateQuote
  714. ? alternate.quote
  715. : preferred.quote;
  716. // Directives are exact code unit sequences, which means that you can't
  717. // change the escape sequences they use.
  718. // See https://github.com/prettier/prettier/issues/1555
  719. // and https://tc39.github.io/ecma262/#directive-prologue
  720. if (isDirectiveLiteral) {
  721. if (canChangeDirectiveQuotes) {
  722. return enclosingQuote + rawContent + enclosingQuote;
  723. }
  724. return raw;
  725. }
  726. // It might sound unnecessary to use `makeString` even if the string already
  727. // is enclosed with `enclosingQuote`, but it isn't. The string could contain
  728. // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
  729. // sure that we consistently output the minimum amount of escaped quotes.
  730. return makeString(
  731. rawContent,
  732. enclosingQuote,
  733. !(
  734. options.parser === "css" ||
  735. options.parser === "less" ||
  736. options.parser === "scss"
  737. )
  738. );
  739. }
  740. function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
  741. const otherQuote = enclosingQuote === '"' ? "'" : '"';
  742. // Matches _any_ escape and unescaped quotes (both single and double).
  743. const regex = /\\([\s\S])|(['"])/g;
  744. // Escape and unescape single and double quotes as needed to be able to
  745. // enclose `rawContent` with `enclosingQuote`.
  746. const newContent = rawContent.replace(regex, (match, escaped, quote) => {
  747. // If we matched an escape, and the escaped character is a quote of the
  748. // other type than we intend to enclose the string with, there's no need for
  749. // it to be escaped, so return it _without_ the backslash.
  750. if (escaped === otherQuote) {
  751. return escaped;
  752. }
  753. // If we matched an unescaped quote and it is of the _same_ type as we
  754. // intend to enclose the string with, it must be escaped, so return it with
  755. // a backslash.
  756. if (quote === enclosingQuote) {
  757. return "\\" + quote;
  758. }
  759. if (quote) {
  760. return quote;
  761. }
  762. // Unescape any unnecessarily escaped character.
  763. // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
  764. return unescapeUnnecessaryEscapes &&
  765. /^[^\\nrvtbfux\r\n\u2028\u2029"'0-7]$/.test(escaped)
  766. ? escaped
  767. : "\\" + escaped;
  768. });
  769. return enclosingQuote + newContent + enclosingQuote;
  770. }
  771. function printNumber(rawNumber) {
  772. return (
  773. rawNumber
  774. .toLowerCase()
  775. // Remove unnecessary plus and zeroes from scientific notation.
  776. .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3")
  777. // Remove unnecessary scientific notation (1e0).
  778. .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1")
  779. // Make sure numbers always start with a digit.
  780. .replace(/^([+-])?\./, "$10.")
  781. // Remove extraneous trailing decimal zeroes.
  782. .replace(/(\.\d+?)0+(?=e|$)/, "$1")
  783. // Remove trailing dot.
  784. .replace(/\.(?=e|$)/, "")
  785. );
  786. }
  787. function getMaxContinuousCount(str, target) {
  788. const results = str.match(
  789. new RegExp(`(${escapeStringRegexp(target)})+`, "g")
  790. );
  791. if (results === null) {
  792. return 0;
  793. }
  794. return results.reduce(
  795. (maxCount, result) => Math.max(maxCount, result.length / target.length),
  796. 0
  797. );
  798. }
  799. /**
  800. * split text into whitespaces and words
  801. * @param {string} text
  802. * @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
  803. */
  804. function splitText(text) {
  805. const KIND_NON_CJK = "non-cjk";
  806. const KIND_CJK_CHARACTER = "cjk-character";
  807. const KIND_CJK_PUNCTUATION = "cjk-punctuation";
  808. const nodes = [];
  809. text
  810. .replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")
  811. .split(/([ \t\n]+)/)
  812. .forEach((token, index, tokens) => {
  813. // whitespace
  814. if (index % 2 === 1) {
  815. nodes.push({
  816. type: "whitespace",
  817. value: /\n/.test(token) ? "\n" : " "
  818. });
  819. return;
  820. }
  821. // word separated by whitespace
  822. if ((index === 0 || index === tokens.length - 1) && token === "") {
  823. return;
  824. }
  825. token
  826. .split(new RegExp(`(${cjkPattern})`))
  827. .forEach((innerToken, innerIndex, innerTokens) => {
  828. if (
  829. (innerIndex === 0 || innerIndex === innerTokens.length - 1) &&
  830. innerToken === ""
  831. ) {
  832. return;
  833. }
  834. // non-CJK word
  835. if (innerIndex % 2 === 0) {
  836. if (innerToken !== "") {
  837. appendNode({
  838. type: "word",
  839. value: innerToken,
  840. kind: KIND_NON_CJK,
  841. hasLeadingPunctuation: punctuationRegex.test(innerToken[0]),
  842. hasTrailingPunctuation: punctuationRegex.test(
  843. getLast(innerToken)
  844. )
  845. });
  846. }
  847. return;
  848. }
  849. // CJK character
  850. appendNode(
  851. punctuationRegex.test(innerToken)
  852. ? {
  853. type: "word",
  854. value: innerToken,
  855. kind: KIND_CJK_PUNCTUATION,
  856. hasLeadingPunctuation: true,
  857. hasTrailingPunctuation: true
  858. }
  859. : {
  860. type: "word",
  861. value: innerToken,
  862. kind: KIND_CJK_CHARACTER,
  863. hasLeadingPunctuation: false,
  864. hasTrailingPunctuation: false
  865. }
  866. );
  867. });
  868. });
  869. return nodes;
  870. function appendNode(node) {
  871. const lastNode = getLast(nodes);
  872. if (lastNode && lastNode.type === "word") {
  873. if (
  874. (lastNode.kind === KIND_NON_CJK &&
  875. node.kind === KIND_CJK_CHARACTER &&
  876. !lastNode.hasTrailingPunctuation) ||
  877. (lastNode.kind === KIND_CJK_CHARACTER &&
  878. node.kind === KIND_NON_CJK &&
  879. !node.hasLeadingPunctuation)
  880. ) {
  881. nodes.push({ type: "whitespace", value: " " });
  882. } else if (
  883. !isBetween(KIND_NON_CJK, KIND_CJK_PUNCTUATION) &&
  884. // disallow leading/trailing full-width whitespace
  885. ![lastNode.value, node.value].some(value => /\u3000/.test(value))
  886. ) {
  887. nodes.push({ type: "whitespace", value: "" });
  888. }
  889. }
  890. nodes.push(node);
  891. function isBetween(kind1, kind2) {
  892. return (
  893. (lastNode.kind === kind1 && node.kind === kind2) ||
  894. (lastNode.kind === kind2 && node.kind === kind1)
  895. );
  896. }
  897. }
  898. }
  899. function getStringWidth(text) {
  900. if (!text) {
  901. return 0;
  902. }
  903. // emojis are considered 2-char width for consistency
  904. // see https://github.com/sindresorhus/string-width/issues/11
  905. // for the reason why not implemented in `string-width`
  906. return stringWidth(text.replace(emojiRegex, " "));
  907. }
  908. function hasIgnoreComment(path$$1) {
  909. const node = path$$1.getValue();
  910. return hasNodeIgnoreComment(node);
  911. }
  912. function hasNodeIgnoreComment(node) {
  913. return (
  914. node &&
  915. node.comments &&
  916. node.comments.length > 0 &&
  917. node.comments.some(comment => comment.value.trim() === "prettier-ignore")
  918. );
  919. }
  920. function arrayify(object, keyName) {
  921. return Object.keys(object).reduce(
  922. (array, key) =>
  923. array.concat(Object.assign({ [keyName]: key }, object[key])),
  924. []
  925. );
  926. }
  927. function addCommentHelper(node, comment) {
  928. const comments = node.comments || (node.comments = []);
  929. comments.push(comment);
  930. comment.printed = false;
  931. // For some reason, TypeScript parses `// x` inside of JSXText as a comment
  932. // We already "print" it via the raw text, we don't need to re-print it as a
  933. // comment
  934. if (node.type === "JSXText") {
  935. comment.printed = true;
  936. }
  937. }
  938. function addLeadingComment(node, comment) {
  939. comment.leading = true;
  940. comment.trailing = false;
  941. addCommentHelper(node, comment);
  942. }
  943. function addDanglingComment(node, comment) {
  944. comment.leading = false;
  945. comment.trailing = false;
  946. addCommentHelper(node, comment);
  947. }
  948. function addTrailingComment(node, comment) {
  949. comment.leading = false;
  950. comment.trailing = true;
  951. addCommentHelper(node, comment);
  952. }
  953. var util$1 = {
  954. arrayify,
  955. punctuationRegex,
  956. punctuationCharRange,
  957. getStringWidth,
  958. splitText,
  959. getMaxContinuousCount,
  960. getPrecedence,
  961. shouldFlatten,
  962. isBitwiseOperator,
  963. isExportDeclaration,
  964. getParentExportDeclaration,
  965. getPenultimate,
  966. getLast,
  967. getNextNonSpaceNonCommentCharacterIndex,
  968. getNextNonSpaceNonCommentCharacter,
  969. skipWhitespace,
  970. skipSpaces,
  971. skipNewline,
  972. isNextLineEmptyAfterIndex,
  973. isNextLineEmpty,
  974. isPreviousLineEmpty,
  975. hasNewline,
  976. hasNewlineInRange,
  977. hasSpaces,
  978. setLocStart,
  979. setLocEnd,
  980. startsWithNoLookaheadToken,
  981. hasBlockComments,
  982. isBlockComment,
  983. hasClosureCompilerTypeCastComment,
  984. getAlignmentSize,
  985. getIndentSize,
  986. printString,
  987. printNumber,
  988. hasIgnoreComment,
  989. hasNodeIgnoreComment,
  990. lineColumnToIndex,
  991. makeString,
  992. addLeadingComment,
  993. addDanglingComment,
  994. addTrailingComment
  995. };
  996. function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
  997. function traverseDocRec(doc) {
  998. let shouldRecurse = true;
  999. if (onEnter) {
  1000. if (onEnter(doc) === false) {
  1001. shouldRecurse = false;
  1002. }
  1003. }
  1004. if (shouldRecurse) {
  1005. if (doc.type === "concat" || doc.type === "fill") {
  1006. for (let i = 0; i < doc.parts.length; i++) {
  1007. traverseDocRec(doc.parts[i]);
  1008. }
  1009. } else if (doc.type === "if-break") {
  1010. if (doc.breakContents) {
  1011. traverseDocRec(doc.breakContents);
  1012. }
  1013. if (doc.flatContents) {
  1014. traverseDocRec(doc.flatContents);
  1015. }
  1016. } else if (doc.type === "group" && doc.expandedStates) {
  1017. if (shouldTraverseConditionalGroups) {
  1018. doc.expandedStates.forEach(traverseDocRec);
  1019. } else {
  1020. traverseDocRec(doc.contents);
  1021. }
  1022. } else if (doc.contents) {
  1023. traverseDocRec(doc.contents);
  1024. }
  1025. }
  1026. if (onExit) {
  1027. onExit(doc);
  1028. }
  1029. }
  1030. traverseDocRec(doc);
  1031. }
  1032. function mapDoc(doc, cb) {
  1033. if (doc.type === "concat" || doc.type === "fill") {
  1034. const parts = doc.parts.map(part => mapDoc(part, cb));
  1035. return cb(Object.assign({}, doc, { parts }));
  1036. } else if (doc.type === "if-break") {
  1037. const breakContents = doc.breakContents && mapDoc(doc.breakContents, cb);
  1038. const flatContents = doc.flatContents && mapDoc(doc.flatContents, cb);
  1039. return cb(Object.assign({}, doc, { breakContents, flatContents }));
  1040. } else if (doc.contents) {
  1041. const contents = mapDoc(doc.contents, cb);
  1042. return cb(Object.assign({}, doc, { contents }));
  1043. }
  1044. return cb(doc);
  1045. }
  1046. function findInDoc(doc, fn, defaultValue) {
  1047. let result = defaultValue;
  1048. let hasStopped = false;
  1049. traverseDoc(doc, doc => {
  1050. const maybeResult = fn(doc);
  1051. if (maybeResult !== undefined) {
  1052. hasStopped = true;
  1053. result = maybeResult;
  1054. }
  1055. if (hasStopped) {
  1056. return false;
  1057. }
  1058. });
  1059. return result;
  1060. }
  1061. function isEmpty(n) {
  1062. return typeof n === "string" && n.length === 0;
  1063. }
  1064. function isLineNext(doc) {
  1065. return findInDoc(
  1066. doc,
  1067. doc => {
  1068. if (typeof doc === "string") {
  1069. return false;
  1070. }
  1071. if (doc.type === "line") {
  1072. return true;
  1073. }
  1074. },
  1075. false
  1076. );
  1077. }
  1078. function willBreak(doc) {
  1079. return findInDoc(
  1080. doc,
  1081. doc => {
  1082. if (doc.type === "group" && doc.break) {
  1083. return true;
  1084. }
  1085. if (doc.type === "line" && doc.hard) {
  1086. return true;
  1087. }
  1088. if (doc.type === "break-parent") {
  1089. return true;
  1090. }
  1091. },
  1092. false
  1093. );
  1094. }
  1095. function breakParentGroup(groupStack) {
  1096. if (groupStack.length > 0) {
  1097. const parentGroup = groupStack[groupStack.length - 1];
  1098. // Breaks are not propagated through conditional groups because
  1099. // the user is expected to manually handle what breaks.
  1100. if (!parentGroup.expandedStates) {
  1101. parentGroup.break = true;
  1102. }
  1103. }
  1104. return null;
  1105. }
  1106. function propagateBreaks(doc) {
  1107. const alreadyVisited = new Map();
  1108. const groupStack = [];
  1109. traverseDoc(
  1110. doc,
  1111. doc => {
  1112. if (doc.type === "break-parent") {
  1113. breakParentGroup(groupStack);
  1114. }
  1115. if (doc.type === "group") {
  1116. groupStack.push(doc);
  1117. if (alreadyVisited.has(doc)) {
  1118. return false;
  1119. }
  1120. alreadyVisited.set(doc, true);
  1121. }
  1122. },
  1123. doc => {
  1124. if (doc.type === "group") {
  1125. const group = groupStack.pop();
  1126. if (group.break) {
  1127. breakParentGroup(groupStack);
  1128. }
  1129. }
  1130. },
  1131. /* shouldTraverseConditionalGroups */ true
  1132. );
  1133. }
  1134. function removeLines(doc) {
  1135. // Force this doc into flat mode by statically converting all
  1136. // lines into spaces (or soft lines into nothing). Hard lines
  1137. // should still output because there's too great of a chance
  1138. // of breaking existing assumptions otherwise.
  1139. return mapDoc(doc, d => {
  1140. if (d.type === "line" && !d.hard) {
  1141. return d.soft ? "" : " ";
  1142. } else if (d.type === "if-break") {
  1143. return d.flatContents || "";
  1144. }
  1145. return d;
  1146. });
  1147. }
  1148. function stripTrailingHardline(doc) {
  1149. // HACK remove ending hardline, original PR: #1984
  1150. if (
  1151. doc.type === "concat" &&
  1152. doc.parts.length === 2 &&
  1153. doc.parts[1].type === "concat" &&
  1154. doc.parts[1].parts.length === 2 &&
  1155. doc.parts[1].parts[0].hard &&
  1156. doc.parts[1].parts[1].type === "break-parent"
  1157. ) {
  1158. return doc.parts[0];
  1159. }
  1160. return doc;
  1161. }
  1162. var docUtils = {
  1163. isEmpty,
  1164. willBreak,
  1165. isLineNext,
  1166. traverseDoc,
  1167. mapDoc,
  1168. propagateBreaks,
  1169. removeLines,
  1170. stripTrailingHardline
  1171. };
  1172. function isNextLineEmpty$1(text, node, options) {
  1173. return util$1.isNextLineEmpty(text, node, options.locEnd);
  1174. }
  1175. function getNextNonSpaceNonCommentCharacterIndex$1(text, node, options) {
  1176. return util$1.getNextNonSpaceNonCommentCharacterIndex(
  1177. text,
  1178. node,
  1179. options.locEnd
  1180. );
  1181. }
  1182. var utilShared = {
  1183. isNextLineEmpty: isNextLineEmpty$1,
  1184. isNextLineEmptyAfterIndex: util$1.isNextLineEmptyAfterIndex,
  1185. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$1,
  1186. mapDoc: docUtils.mapDoc, // TODO: remove in 2.0, we already exposed it in docUtils
  1187. makeString: util$1.makeString,
  1188. addLeadingComment: util$1.addLeadingComment,
  1189. addDanglingComment: util$1.addDanglingComment,
  1190. addTrailingComment: util$1.addTrailingComment
  1191. };
  1192. var dedent_1 = createCommonjsModule(function (module) {
  1193. "use strict";
  1194. function dedent(strings) {
  1195. var raw = void 0;
  1196. if (typeof strings === "string") {
  1197. // dedent can be used as a plain function
  1198. raw = [strings];
  1199. } else {
  1200. raw = strings.raw;
  1201. }
  1202. // first, perform interpolation
  1203. var result = "";
  1204. for (var i = 0; i < raw.length; i++) {
  1205. result += raw[i].
  1206. // join lines when there is a suppressed newline
  1207. replace(/\\\n[ \t]*/g, "").
  1208. // handle escaped backticks
  1209. replace(/\\`/g, "`");
  1210. if (i < (arguments.length <= 1 ? 0 : arguments.length - 1)) {
  1211. result += arguments.length <= i + 1 ? undefined : arguments[i + 1];
  1212. }
  1213. }
  1214. // now strip indentation
  1215. var lines = result.split("\n");
  1216. var mindent = null;
  1217. lines.forEach(function (l) {
  1218. var m = l.match(/^(\s+)\S+/);
  1219. if (m) {
  1220. var indent = m[1].length;
  1221. if (!mindent) {
  1222. // this is the first indented line
  1223. mindent = indent;
  1224. } else {
  1225. mindent = Math.min(mindent, indent);
  1226. }
  1227. }
  1228. });
  1229. if (mindent !== null) {
  1230. result = lines.map(function (l) {
  1231. return l[0] === " " ? l.slice(mindent) : l;
  1232. }).join("\n");
  1233. }
  1234. // dedent eats leading and trailing whitespace too
  1235. result = result.trim();
  1236. // handle escaped newlines at the end to ensure they don't get stripped too
  1237. return result.replace(/\\n/g, "\n");
  1238. }
  1239. {
  1240. module.exports = dedent;
  1241. }
  1242. });
  1243. var semver = createCommonjsModule(function (module, exports) {
  1244. exports = module.exports = SemVer;
  1245. // The debug function is excluded entirely from the minified version.
  1246. /* nomin */ var debug;
  1247. /* nomin */ if (typeof process === 'object' &&
  1248. /* nomin */ process.env &&
  1249. /* nomin */ process.env.NODE_DEBUG &&
  1250. /* nomin */ /\bsemver\b/i.test(process.env.NODE_DEBUG))
  1251. /* nomin */ debug = function() {
  1252. /* nomin */ var args = Array.prototype.slice.call(arguments, 0);
  1253. /* nomin */ args.unshift('SEMVER');
  1254. /* nomin */ console.log.apply(console, args);
  1255. /* nomin */ };
  1256. /* nomin */ else
  1257. /* nomin */ debug = function() {};
  1258. // Note: this is the semver.org version of the spec that it implements
  1259. // Not necessarily the package version of this code.
  1260. exports.SEMVER_SPEC_VERSION = '2.0.0';
  1261. var MAX_LENGTH = 256;
  1262. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
  1263. // The actual regexps go on exports.re
  1264. var re = exports.re = [];
  1265. var src = exports.src = [];
  1266. var R = 0;
  1267. // The following Regular Expressions can be used for tokenizing,
  1268. // validating, and parsing SemVer version strings.
  1269. // ## Numeric Identifier
  1270. // A single `0`, or a non-zero digit followed by zero or more digits.
  1271. var NUMERICIDENTIFIER = R++;
  1272. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  1273. var NUMERICIDENTIFIERLOOSE = R++;
  1274. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+';
  1275. // ## Non-numeric Identifier
  1276. // Zero or more digits, followed by a letter or hyphen, and then zero or
  1277. // more letters, digits, or hyphens.
  1278. var NONNUMERICIDENTIFIER = R++;
  1279. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*';
  1280. // ## Main Version
  1281. // Three dot-separated numeric identifiers.
  1282. var MAINVERSION = R++;
  1283. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' +
  1284. '(' + src[NUMERICIDENTIFIER] + ')\\.' +
  1285. '(' + src[NUMERICIDENTIFIER] + ')';
  1286. var MAINVERSIONLOOSE = R++;
  1287. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
  1288. '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
  1289. '(' + src[NUMERICIDENTIFIERLOOSE] + ')';
  1290. // ## Pre-release Version Identifier
  1291. // A numeric identifier, or a non-numeric identifier.
  1292. var PRERELEASEIDENTIFIER = R++;
  1293. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] +
  1294. '|' + src[NONNUMERICIDENTIFIER] + ')';
  1295. var PRERELEASEIDENTIFIERLOOSE = R++;
  1296. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] +
  1297. '|' + src[NONNUMERICIDENTIFIER] + ')';
  1298. // ## Pre-release Version
  1299. // Hyphen, followed by one or more dot-separated pre-release version
  1300. // identifiers.
  1301. var PRERELEASE = R++;
  1302. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] +
  1303. '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  1304. var PRERELEASELOOSE = R++;
  1305. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] +
  1306. '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))';
  1307. // ## Build Metadata Identifier
  1308. // Any combination of digits, letters, or hyphens.
  1309. var BUILDIDENTIFIER = R++;
  1310. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+';
  1311. // ## Build Metadata
  1312. // Plus sign, followed by one or more period-separated build metadata
  1313. // identifiers.
  1314. var BUILD = R++;
  1315. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] +
  1316. '(?:\\.' + src[BUILDIDENTIFIER] + ')*))';
  1317. // ## Full Version String
  1318. // A main version, followed optionally by a pre-release version and
  1319. // build metadata.
  1320. // Note that the only major, minor, patch, and pre-release sections of
  1321. // the version string are capturing groups. The build metadata is not a
  1322. // capturing group, because it should not ever be used in version
  1323. // comparison.
  1324. var FULL = R++;
  1325. var FULLPLAIN = 'v?' + src[MAINVERSION] +
  1326. src[PRERELEASE] + '?' +
  1327. src[BUILD] + '?';
  1328. src[FULL] = '^' + FULLPLAIN + '$';
  1329. // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  1330. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  1331. // common in the npm registry.
  1332. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] +
  1333. src[PRERELEASELOOSE] + '?' +
  1334. src[BUILD] + '?';
  1335. var LOOSE = R++;
  1336. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  1337. var GTLT = R++;
  1338. src[GTLT] = '((?:<|>)?=?)';
  1339. // Something like "2.*" or "1.2.x".
  1340. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  1341. // Only the first item is strictly required.
  1342. var XRANGEIDENTIFIERLOOSE = R++;
  1343. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  1344. var XRANGEIDENTIFIER = R++;
  1345. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  1346. var XRANGEPLAIN = R++;
  1347. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' +
  1348. '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
  1349. '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
  1350. '(?:' + src[PRERELEASE] + ')?' +
  1351. src[BUILD] + '?' +
  1352. ')?)?';
  1353. var XRANGEPLAINLOOSE = R++;
  1354. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
  1355. '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
  1356. '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
  1357. '(?:' + src[PRERELEASELOOSE] + ')?' +
  1358. src[BUILD] + '?' +
  1359. ')?)?';
  1360. var XRANGE = R++;
  1361. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  1362. var XRANGELOOSE = R++;
  1363. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$';
  1364. // Tilde ranges.
  1365. // Meaning is "reasonably at or greater than"
  1366. var LONETILDE = R++;
  1367. src[LONETILDE] = '(?:~>?)';
  1368. var TILDETRIM = R++;
  1369. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  1370. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  1371. var tildeTrimReplace = '$1~';
  1372. var TILDE = R++;
  1373. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  1374. var TILDELOOSE = R++;
  1375. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$';
  1376. // Caret ranges.
  1377. // Meaning is "at least and backwards compatible with"
  1378. var LONECARET = R++;
  1379. src[LONECARET] = '(?:\\^)';
  1380. var CARETTRIM = R++;
  1381. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  1382. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  1383. var caretTrimReplace = '$1^';
  1384. var CARET = R++;
  1385. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  1386. var CARETLOOSE = R++;
  1387. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$';
  1388. // A simple gt/lt/eq thing, or just "" to indicate "any version"
  1389. var COMPARATORLOOSE = R++;
  1390. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  1391. var COMPARATOR = R++;
  1392. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$';
  1393. // An expression to strip any whitespace between the gtlt and the thing
  1394. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  1395. var COMPARATORTRIM = R++;
  1396. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] +
  1397. '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')';
  1398. // this one has to use the /g flag
  1399. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  1400. var comparatorTrimReplace = '$1$2$3';
  1401. // Something like `1.2.3 - 1.2.4`
  1402. // Note that these all use the loose form, because they'll be
  1403. // checked against either the strict or loose comparator form
  1404. // later.
  1405. var HYPHENRANGE = R++;
  1406. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' +
  1407. '\\s+-\\s+' +
  1408. '(' + src[XRANGEPLAIN] + ')' +
  1409. '\\s*$';
  1410. var HYPHENRANGELOOSE = R++;
  1411. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' +
  1412. '\\s+-\\s+' +
  1413. '(' + src[XRANGEPLAINLOOSE] + ')' +
  1414. '\\s*$';
  1415. // Star ranges basically just allow anything at all.
  1416. var STAR = R++;
  1417. src[STAR] = '(<|>)?=?\\s*\\*';
  1418. // Compile to actual regexp objects.
  1419. // All are flag-free, unless they were created above with a flag.
  1420. for (var i = 0; i < R; i++) {
  1421. debug(i, src[i]);
  1422. if (!re[i])
  1423. re[i] = new RegExp(src[i]);
  1424. }
  1425. exports.parse = parse;
  1426. function parse(version, loose) {
  1427. if (version instanceof SemVer)
  1428. return version;
  1429. if (typeof version !== 'string')
  1430. return null;
  1431. if (version.length > MAX_LENGTH)
  1432. return null;
  1433. var r = loose ? re[LOOSE] : re[FULL];
  1434. if (!r.test(version))
  1435. return null;
  1436. try {
  1437. return new SemVer(version, loose);
  1438. } catch (er) {
  1439. return null;
  1440. }
  1441. }
  1442. exports.valid = valid;
  1443. function valid(version, loose) {
  1444. var v = parse(version, loose);
  1445. return v ? v.version : null;
  1446. }
  1447. exports.clean = clean;
  1448. function clean(version, loose) {
  1449. var s = parse(version.trim().replace(/^[=v]+/, ''), loose);
  1450. return s ? s.version : null;
  1451. }
  1452. exports.SemVer = SemVer;
  1453. function SemVer(version, loose) {
  1454. if (version instanceof SemVer) {
  1455. if (version.loose === loose)
  1456. return version;
  1457. else
  1458. version = version.version;
  1459. } else if (typeof version !== 'string') {
  1460. throw new TypeError('Invalid Version: ' + version);
  1461. }
  1462. if (version.length > MAX_LENGTH)
  1463. throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters')
  1464. if (!(this instanceof SemVer))
  1465. return new SemVer(version, loose);
  1466. debug('SemVer', version, loose);
  1467. this.loose = loose;
  1468. var m = version.trim().match(loose ? re[LOOSE] : re[FULL]);
  1469. if (!m)
  1470. throw new TypeError('Invalid Version: ' + version);
  1471. this.raw = version;
  1472. // these are actually numbers
  1473. this.major = +m[1];
  1474. this.minor = +m[2];
  1475. this.patch = +m[3];
  1476. if (this.major > MAX_SAFE_INTEGER || this.major < 0)
  1477. throw new TypeError('Invalid major version')
  1478. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0)
  1479. throw new TypeError('Invalid minor version')
  1480. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0)
  1481. throw new TypeError('Invalid patch version')
  1482. // numberify any prerelease numeric ids
  1483. if (!m[4])
  1484. this.prerelease = [];
  1485. else
  1486. this.prerelease = m[4].split('.').map(function(id) {
  1487. if (/^[0-9]+$/.test(id)) {
  1488. var num = +id;
  1489. if (num >= 0 && num < MAX_SAFE_INTEGER)
  1490. return num;
  1491. }
  1492. return id;
  1493. });
  1494. this.build = m[5] ? m[5].split('.') : [];
  1495. this.format();
  1496. }
  1497. SemVer.prototype.format = function() {
  1498. this.version = this.major + '.' + this.minor + '.' + this.patch;
  1499. if (this.prerelease.length)
  1500. this.version += '-' + this.prerelease.join('.');
  1501. return this.version;
  1502. };
  1503. SemVer.prototype.toString = function() {
  1504. return this.version;
  1505. };
  1506. SemVer.prototype.compare = function(other) {
  1507. debug('SemVer.compare', this.version, this.loose, other);
  1508. if (!(other instanceof SemVer))
  1509. other = new SemVer(other, this.loose);
  1510. return this.compareMain(other) || this.comparePre(other);
  1511. };
  1512. SemVer.prototype.compareMain = function(other) {
  1513. if (!(other instanceof SemVer))
  1514. other = new SemVer(other, this.loose);
  1515. return compareIdentifiers(this.major, other.major) ||
  1516. compareIdentifiers(this.minor, other.minor) ||
  1517. compareIdentifiers(this.patch, other.patch);
  1518. };
  1519. SemVer.prototype.comparePre = function(other) {
  1520. if (!(other instanceof SemVer))
  1521. other = new SemVer(other, this.loose);
  1522. // NOT having a prerelease is > having one
  1523. if (this.prerelease.length && !other.prerelease.length)
  1524. return -1;
  1525. else if (!this.prerelease.length && other.prerelease.length)
  1526. return 1;
  1527. else if (!this.prerelease.length && !other.prerelease.length)
  1528. return 0;
  1529. var i = 0;
  1530. do {
  1531. var a = this.prerelease[i];
  1532. var b = other.prerelease[i];
  1533. debug('prerelease compare', i, a, b);
  1534. if (a === undefined && b === undefined)
  1535. return 0;
  1536. else if (b === undefined)
  1537. return 1;
  1538. else if (a === undefined)
  1539. return -1;
  1540. else if (a === b)
  1541. continue;
  1542. else
  1543. return compareIdentifiers(a, b);
  1544. } while (++i);
  1545. };
  1546. // preminor will bump the version up to the next minor release, and immediately
  1547. // down to pre-release. premajor and prepatch work the same way.
  1548. SemVer.prototype.inc = function(release, identifier) {
  1549. switch (release) {
  1550. case 'premajor':
  1551. this.prerelease.length = 0;
  1552. this.patch = 0;
  1553. this.minor = 0;
  1554. this.major++;
  1555. this.inc('pre', identifier);
  1556. break;
  1557. case 'preminor':
  1558. this.prerelease.length = 0;
  1559. this.patch = 0;
  1560. this.minor++;
  1561. this.inc('pre', identifier);
  1562. break;
  1563. case 'prepatch':
  1564. // If this is already a prerelease, it will bump to the next version
  1565. // drop any prereleases that might already exist, since they are not
  1566. // relevant at this point.
  1567. this.prerelease.length = 0;
  1568. this.inc('patch', identifier);
  1569. this.inc('pre', identifier);
  1570. break;
  1571. // If the input is a non-prerelease version, this acts the same as
  1572. // prepatch.
  1573. case 'prerelease':
  1574. if (this.prerelease.length === 0)
  1575. this.inc('patch', identifier);
  1576. this.inc('pre', identifier);
  1577. break;
  1578. case 'major':
  1579. // If this is a pre-major version, bump up to the same major version.
  1580. // Otherwise increment major.
  1581. // 1.0.0-5 bumps to 1.0.0
  1582. // 1.1.0 bumps to 2.0.0
  1583. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0)
  1584. this.major++;
  1585. this.minor = 0;
  1586. this.patch = 0;
  1587. this.prerelease = [];
  1588. break;
  1589. case 'minor':
  1590. // If this is a pre-minor version, bump up to the same minor version.
  1591. // Otherwise increment minor.
  1592. // 1.2.0-5 bumps to 1.2.0
  1593. // 1.2.1 bumps to 1.3.0
  1594. if (this.patch !== 0 || this.prerelease.length === 0)
  1595. this.minor++;
  1596. this.patch = 0;
  1597. this.prerelease = [];
  1598. break;
  1599. case 'patch':
  1600. // If this is not a pre-release version, it will increment the patch.
  1601. // If it is a pre-release it will bump up to the same patch version.
  1602. // 1.2.0-5 patches to 1.2.0
  1603. // 1.2.0 patches to 1.2.1
  1604. if (this.prerelease.length === 0)
  1605. this.patch++;
  1606. this.prerelease = [];
  1607. break;
  1608. // This probably shouldn't be used publicly.
  1609. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  1610. case 'pre':
  1611. if (this.prerelease.length === 0)
  1612. this.prerelease = [0];
  1613. else {
  1614. var i = this.prerelease.length;
  1615. while (--i >= 0) {
  1616. if (typeof this.prerelease[i] === 'number') {
  1617. this.prerelease[i]++;
  1618. i = -2;
  1619. }
  1620. }
  1621. if (i === -1) // didn't increment anything
  1622. this.prerelease.push(0);
  1623. }
  1624. if (identifier) {
  1625. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  1626. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  1627. if (this.prerelease[0] === identifier) {
  1628. if (isNaN(this.prerelease[1]))
  1629. this.prerelease = [identifier, 0];
  1630. } else
  1631. this.prerelease = [identifier, 0];
  1632. }
  1633. break;
  1634. default:
  1635. throw new Error('invalid increment argument: ' + release);
  1636. }
  1637. this.format();
  1638. this.raw = this.version;
  1639. return this;
  1640. };
  1641. exports.inc = inc;
  1642. function inc(version, release, loose, identifier) {
  1643. if (typeof(loose) === 'string') {
  1644. identifier = loose;
  1645. loose = undefined;
  1646. }
  1647. try {
  1648. return new SemVer(version, loose).inc(release, identifier).version;
  1649. } catch (er) {
  1650. return null;
  1651. }
  1652. }
  1653. exports.diff = diff;
  1654. function diff(version1, version2) {
  1655. if (eq(version1, version2)) {
  1656. return null;
  1657. } else {
  1658. var v1 = parse(version1);
  1659. var v2 = parse(version2);
  1660. if (v1.prerelease.length || v2.prerelease.length) {
  1661. for (var key in v1) {
  1662. if (key === 'major' || key === 'minor' || key === 'patch') {
  1663. if (v1[key] !== v2[key]) {
  1664. return 'pre'+key;
  1665. }
  1666. }
  1667. }
  1668. return 'prerelease';
  1669. }
  1670. for (var key in v1) {
  1671. if (key === 'major' || key === 'minor' || key === 'patch') {
  1672. if (v1[key] !== v2[key]) {
  1673. return key;
  1674. }
  1675. }
  1676. }
  1677. }
  1678. }
  1679. exports.compareIdentifiers = compareIdentifiers;
  1680. var numeric = /^[0-9]+$/;
  1681. function compareIdentifiers(a, b) {
  1682. var anum = numeric.test(a);
  1683. var bnum = numeric.test(b);
  1684. if (anum && bnum) {
  1685. a = +a;
  1686. b = +b;
  1687. }
  1688. return (anum && !bnum) ? -1 :
  1689. (bnum && !anum) ? 1 :
  1690. a < b ? -1 :
  1691. a > b ? 1 :
  1692. 0;
  1693. }
  1694. exports.rcompareIdentifiers = rcompareIdentifiers;
  1695. function rcompareIdentifiers(a, b) {
  1696. return compareIdentifiers(b, a);
  1697. }
  1698. exports.major = major;
  1699. function major(a, loose) {
  1700. return new SemVer(a, loose).major;
  1701. }
  1702. exports.minor = minor;
  1703. function minor(a, loose) {
  1704. return new SemVer(a, loose).minor;
  1705. }
  1706. exports.patch = patch;
  1707. function patch(a, loose) {
  1708. return new SemVer(a, loose).patch;
  1709. }
  1710. exports.compare = compare;
  1711. function compare(a, b, loose) {
  1712. return new SemVer(a, loose).compare(new SemVer(b, loose));
  1713. }
  1714. exports.compareLoose = compareLoose;
  1715. function compareLoose(a, b) {
  1716. return compare(a, b, true);
  1717. }
  1718. exports.rcompare = rcompare;
  1719. function rcompare(a, b, loose) {
  1720. return compare(b, a, loose);
  1721. }
  1722. exports.sort = sort;
  1723. function sort(list, loose) {
  1724. return list.sort(function(a, b) {
  1725. return exports.compare(a, b, loose);
  1726. });
  1727. }
  1728. exports.rsort = rsort;
  1729. function rsort(list, loose) {
  1730. return list.sort(function(a, b) {
  1731. return exports.rcompare(a, b, loose);
  1732. });
  1733. }
  1734. exports.gt = gt;
  1735. function gt(a, b, loose) {
  1736. return compare(a, b, loose) > 0;
  1737. }
  1738. exports.lt = lt;
  1739. function lt(a, b, loose) {
  1740. return compare(a, b, loose) < 0;
  1741. }
  1742. exports.eq = eq;
  1743. function eq(a, b, loose) {
  1744. return compare(a, b, loose) === 0;
  1745. }
  1746. exports.neq = neq;
  1747. function neq(a, b, loose) {
  1748. return compare(a, b, loose) !== 0;
  1749. }
  1750. exports.gte = gte;
  1751. function gte(a, b, loose) {
  1752. return compare(a, b, loose) >= 0;
  1753. }
  1754. exports.lte = lte;
  1755. function lte(a, b, loose) {
  1756. return compare(a, b, loose) <= 0;
  1757. }
  1758. exports.cmp = cmp;
  1759. function cmp(a, op, b, loose) {
  1760. var ret;
  1761. switch (op) {
  1762. case '===':
  1763. if (typeof a === 'object') a = a.version;
  1764. if (typeof b === 'object') b = b.version;
  1765. ret = a === b;
  1766. break;
  1767. case '!==':
  1768. if (typeof a === 'object') a = a.version;
  1769. if (typeof b === 'object') b = b.version;
  1770. ret = a !== b;
  1771. break;
  1772. case '': case '=': case '==': ret = eq(a, b, loose); break;
  1773. case '!=': ret = neq(a, b, loose); break;
  1774. case '>': ret = gt(a, b, loose); break;
  1775. case '>=': ret = gte(a, b, loose); break;
  1776. case '<': ret = lt(a, b, loose); break;
  1777. case '<=': ret = lte(a, b, loose); break;
  1778. default: throw new TypeError('Invalid operator: ' + op);
  1779. }
  1780. return ret;
  1781. }
  1782. exports.Comparator = Comparator;
  1783. function Comparator(comp, loose) {
  1784. if (comp instanceof Comparator) {
  1785. if (comp.loose === loose)
  1786. return comp;
  1787. else
  1788. comp = comp.value;
  1789. }
  1790. if (!(this instanceof Comparator))
  1791. return new Comparator(comp, loose);
  1792. debug('comparator', comp, loose);
  1793. this.loose = loose;
  1794. this.parse(comp);
  1795. if (this.semver === ANY)
  1796. this.value = '';
  1797. else
  1798. this.value = this.operator + this.semver.version;
  1799. debug('comp', this);
  1800. }
  1801. var ANY = {};
  1802. Comparator.prototype.parse = function(comp) {
  1803. var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  1804. var m = comp.match(r);
  1805. if (!m)
  1806. throw new TypeError('Invalid comparator: ' + comp);
  1807. this.operator = m[1];
  1808. if (this.operator === '=')
  1809. this.operator = '';
  1810. // if it literally is just '>' or '' then allow anything.
  1811. if (!m[2])
  1812. this.semver = ANY;
  1813. else
  1814. this.semver = new SemVer(m[2], this.loose);
  1815. };
  1816. Comparator.prototype.toString = function() {
  1817. return this.value;
  1818. };
  1819. Comparator.prototype.test = function(version) {
  1820. debug('Comparator.test', version, this.loose);
  1821. if (this.semver === ANY)
  1822. return true;
  1823. if (typeof version === 'string')
  1824. version = new SemVer(version, this.loose);
  1825. return cmp(version, this.operator, this.semver, this.loose);
  1826. };
  1827. Comparator.prototype.intersects = function(comp, loose) {
  1828. if (!(comp instanceof Comparator)) {
  1829. throw new TypeError('a Comparator is required');
  1830. }
  1831. var rangeTmp;
  1832. if (this.operator === '') {
  1833. rangeTmp = new Range(comp.value, loose);
  1834. return satisfies(this.value, rangeTmp, loose);
  1835. } else if (comp.operator === '') {
  1836. rangeTmp = new Range(this.value, loose);
  1837. return satisfies(comp.semver, rangeTmp, loose);
  1838. }
  1839. var sameDirectionIncreasing =
  1840. (this.operator === '>=' || this.operator === '>') &&
  1841. (comp.operator === '>=' || comp.operator === '>');
  1842. var sameDirectionDecreasing =
  1843. (this.operator === '<=' || this.operator === '<') &&
  1844. (comp.operator === '<=' || comp.operator === '<');
  1845. var sameSemVer = this.semver.version === comp.semver.version;
  1846. var differentDirectionsInclusive =
  1847. (this.operator === '>=' || this.operator === '<=') &&
  1848. (comp.operator === '>=' || comp.operator === '<=');
  1849. var oppositeDirectionsLessThan =
  1850. cmp(this.semver, '<', comp.semver, loose) &&
  1851. ((this.operator === '>=' || this.operator === '>') &&
  1852. (comp.operator === '<=' || comp.operator === '<'));
  1853. var oppositeDirectionsGreaterThan =
  1854. cmp(this.semver, '>', comp.semver, loose) &&
  1855. ((this.operator === '<=' || this.operator === '<') &&
  1856. (comp.operator === '>=' || comp.operator === '>'));
  1857. return sameDirectionIncreasing || sameDirectionDecreasing ||
  1858. (sameSemVer && differentDirectionsInclusive) ||
  1859. oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  1860. };
  1861. exports.Range = Range;
  1862. function Range(range, loose) {
  1863. if (range instanceof Range) {
  1864. if (range.loose === loose) {
  1865. return range;
  1866. } else {
  1867. return new Range(range.raw, loose);
  1868. }
  1869. }
  1870. if (range instanceof Comparator) {
  1871. return new Range(range.value, loose);
  1872. }
  1873. if (!(this instanceof Range))
  1874. return new Range(range, loose);
  1875. this.loose = loose;
  1876. // First, split based on boolean or ||
  1877. this.raw = range;
  1878. this.set = range.split(/\s*\|\|\s*/).map(function(range) {
  1879. return this.parseRange(range.trim());
  1880. }, this).filter(function(c) {
  1881. // throw out any that are not relevant for whatever reason
  1882. return c.length;
  1883. });
  1884. if (!this.set.length) {
  1885. throw new TypeError('Invalid SemVer Range: ' + range);
  1886. }
  1887. this.format();
  1888. }
  1889. Range.prototype.format = function() {
  1890. this.range = this.set.map(function(comps) {
  1891. return comps.join(' ').trim();
  1892. }).join('||').trim();
  1893. return this.range;
  1894. };
  1895. Range.prototype.toString = function() {
  1896. return this.range;
  1897. };
  1898. Range.prototype.parseRange = function(range) {
  1899. var loose = this.loose;
  1900. range = range.trim();
  1901. debug('range', range, loose);
  1902. // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  1903. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  1904. range = range.replace(hr, hyphenReplace);
  1905. debug('hyphen replace', range);
  1906. // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  1907. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  1908. debug('comparator trim', range, re[COMPARATORTRIM]);
  1909. // `~ 1.2.3` => `~1.2.3`
  1910. range = range.replace(re[TILDETRIM], tildeTrimReplace);
  1911. // `^ 1.2.3` => `^1.2.3`
  1912. range = range.replace(re[CARETTRIM], caretTrimReplace);
  1913. // normalize spaces
  1914. range = range.split(/\s+/).join(' ');
  1915. // At this point, the range is completely trimmed and
  1916. // ready to be split into comparators.
  1917. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  1918. var set = range.split(' ').map(function(comp) {
  1919. return parseComparator(comp, loose);
  1920. }).join(' ').split(/\s+/);
  1921. if (this.loose) {
  1922. // in loose mode, throw out any that are not valid comparators
  1923. set = set.filter(function(comp) {
  1924. return !!comp.match(compRe);
  1925. });
  1926. }
  1927. set = set.map(function(comp) {
  1928. return new Comparator(comp, loose);
  1929. });
  1930. return set;
  1931. };
  1932. Range.prototype.intersects = function(range, loose) {
  1933. if (!(range instanceof Range)) {
  1934. throw new TypeError('a Range is required');
  1935. }
  1936. return this.set.some(function(thisComparators) {
  1937. return thisComparators.every(function(thisComparator) {
  1938. return range.set.some(function(rangeComparators) {
  1939. return rangeComparators.every(function(rangeComparator) {
  1940. return thisComparator.intersects(rangeComparator, loose);
  1941. });
  1942. });
  1943. });
  1944. });
  1945. };
  1946. // Mostly just for testing and legacy API reasons
  1947. exports.toComparators = toComparators;
  1948. function toComparators(range, loose) {
  1949. return new Range(range, loose).set.map(function(comp) {
  1950. return comp.map(function(c) {
  1951. return c.value;
  1952. }).join(' ').trim().split(' ');
  1953. });
  1954. }
  1955. // comprised of xranges, tildes, stars, and gtlt's at this point.
  1956. // already replaced the hyphen ranges
  1957. // turn into a set of JUST comparators.
  1958. function parseComparator(comp, loose) {
  1959. debug('comp', comp);
  1960. comp = replaceCarets(comp, loose);
  1961. debug('caret', comp);
  1962. comp = replaceTildes(comp, loose);
  1963. debug('tildes', comp);
  1964. comp = replaceXRanges(comp, loose);
  1965. debug('xrange', comp);
  1966. comp = replaceStars(comp, loose);
  1967. debug('stars', comp);
  1968. return comp;
  1969. }
  1970. function isX(id) {
  1971. return !id || id.toLowerCase() === 'x' || id === '*';
  1972. }
  1973. // ~, ~> --> * (any, kinda silly)
  1974. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  1975. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  1976. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  1977. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  1978. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  1979. function replaceTildes(comp, loose) {
  1980. return comp.trim().split(/\s+/).map(function(comp) {
  1981. return replaceTilde(comp, loose);
  1982. }).join(' ');
  1983. }
  1984. function replaceTilde(comp, loose) {
  1985. var r = loose ? re[TILDELOOSE] : re[TILDE];
  1986. return comp.replace(r, function(_, M, m, p, pr) {
  1987. debug('tilde', comp, _, M, m, p, pr);
  1988. var ret;
  1989. if (isX(M))
  1990. ret = '';
  1991. else if (isX(m))
  1992. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  1993. else if (isX(p))
  1994. // ~1.2 == >=1.2.0 <1.3.0
  1995. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  1996. else if (pr) {
  1997. debug('replaceTilde pr', pr);
  1998. if (pr.charAt(0) !== '-')
  1999. pr = '-' + pr;
  2000. ret = '>=' + M + '.' + m + '.' + p + pr +
  2001. ' <' + M + '.' + (+m + 1) + '.0';
  2002. } else
  2003. // ~1.2.3 == >=1.2.3 <1.3.0
  2004. ret = '>=' + M + '.' + m + '.' + p +
  2005. ' <' + M + '.' + (+m + 1) + '.0';
  2006. debug('tilde return', ret);
  2007. return ret;
  2008. });
  2009. }
  2010. // ^ --> * (any, kinda silly)
  2011. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  2012. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  2013. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  2014. // ^1.2.3 --> >=1.2.3 <2.0.0
  2015. // ^1.2.0 --> >=1.2.0 <2.0.0
  2016. function replaceCarets(comp, loose) {
  2017. return comp.trim().split(/\s+/).map(function(comp) {
  2018. return replaceCaret(comp, loose);
  2019. }).join(' ');
  2020. }
  2021. function replaceCaret(comp, loose) {
  2022. debug('caret', comp, loose);
  2023. var r = loose ? re[CARETLOOSE] : re[CARET];
  2024. return comp.replace(r, function(_, M, m, p, pr) {
  2025. debug('caret', comp, _, M, m, p, pr);
  2026. var ret;
  2027. if (isX(M))
  2028. ret = '';
  2029. else if (isX(m))
  2030. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  2031. else if (isX(p)) {
  2032. if (M === '0')
  2033. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  2034. else
  2035. ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  2036. } else if (pr) {
  2037. debug('replaceCaret pr', pr);
  2038. if (pr.charAt(0) !== '-')
  2039. pr = '-' + pr;
  2040. if (M === '0') {
  2041. if (m === '0')
  2042. ret = '>=' + M + '.' + m + '.' + p + pr +
  2043. ' <' + M + '.' + m + '.' + (+p + 1);
  2044. else
  2045. ret = '>=' + M + '.' + m + '.' + p + pr +
  2046. ' <' + M + '.' + (+m + 1) + '.0';
  2047. } else
  2048. ret = '>=' + M + '.' + m + '.' + p + pr +
  2049. ' <' + (+M + 1) + '.0.0';
  2050. } else {
  2051. debug('no pr');
  2052. if (M === '0') {
  2053. if (m === '0')
  2054. ret = '>=' + M + '.' + m + '.' + p +
  2055. ' <' + M + '.' + m + '.' + (+p + 1);
  2056. else
  2057. ret = '>=' + M + '.' + m + '.' + p +
  2058. ' <' + M + '.' + (+m + 1) + '.0';
  2059. } else
  2060. ret = '>=' + M + '.' + m + '.' + p +
  2061. ' <' + (+M + 1) + '.0.0';
  2062. }
  2063. debug('caret return', ret);
  2064. return ret;
  2065. });
  2066. }
  2067. function replaceXRanges(comp, loose) {
  2068. debug('replaceXRanges', comp, loose);
  2069. return comp.split(/\s+/).map(function(comp) {
  2070. return replaceXRange(comp, loose);
  2071. }).join(' ');
  2072. }
  2073. function replaceXRange(comp, loose) {
  2074. comp = comp.trim();
  2075. var r = loose ? re[XRANGELOOSE] : re[XRANGE];
  2076. return comp.replace(r, function(ret, gtlt, M, m, p, pr) {
  2077. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  2078. var xM = isX(M);
  2079. var xm = xM || isX(m);
  2080. var xp = xm || isX(p);
  2081. var anyX = xp;
  2082. if (gtlt === '=' && anyX)
  2083. gtlt = '';
  2084. if (xM) {
  2085. if (gtlt === '>' || gtlt === '<') {
  2086. // nothing is allowed
  2087. ret = '<0.0.0';
  2088. } else {
  2089. // nothing is forbidden
  2090. ret = '*';
  2091. }
  2092. } else if (gtlt && anyX) {
  2093. // replace X with 0
  2094. if (xm)
  2095. m = 0;
  2096. if (xp)
  2097. p = 0;
  2098. if (gtlt === '>') {
  2099. // >1 => >=2.0.0
  2100. // >1.2 => >=1.3.0
  2101. // >1.2.3 => >= 1.2.4
  2102. gtlt = '>=';
  2103. if (xm) {
  2104. M = +M + 1;
  2105. m = 0;
  2106. p = 0;
  2107. } else if (xp) {
  2108. m = +m + 1;
  2109. p = 0;
  2110. }
  2111. } else if (gtlt === '<=') {
  2112. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  2113. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  2114. gtlt = '<';
  2115. if (xm)
  2116. M = +M + 1;
  2117. else
  2118. m = +m + 1;
  2119. }
  2120. ret = gtlt + M + '.' + m + '.' + p;
  2121. } else if (xm) {
  2122. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  2123. } else if (xp) {
  2124. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  2125. }
  2126. debug('xRange return', ret);
  2127. return ret;
  2128. });
  2129. }
  2130. // Because * is AND-ed with everything else in the comparator,
  2131. // and '' means "any version", just remove the *s entirely.
  2132. function replaceStars(comp, loose) {
  2133. debug('replaceStars', comp, loose);
  2134. // Looseness is ignored here. star is always as loose as it gets!
  2135. return comp.trim().replace(re[STAR], '');
  2136. }
  2137. // This function is passed to string.replace(re[HYPHENRANGE])
  2138. // M, m, patch, prerelease, build
  2139. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  2140. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  2141. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  2142. function hyphenReplace($0,
  2143. from, fM, fm, fp, fpr, fb,
  2144. to, tM, tm, tp, tpr, tb) {
  2145. if (isX(fM))
  2146. from = '';
  2147. else if (isX(fm))
  2148. from = '>=' + fM + '.0.0';
  2149. else if (isX(fp))
  2150. from = '>=' + fM + '.' + fm + '.0';
  2151. else
  2152. from = '>=' + from;
  2153. if (isX(tM))
  2154. to = '';
  2155. else if (isX(tm))
  2156. to = '<' + (+tM + 1) + '.0.0';
  2157. else if (isX(tp))
  2158. to = '<' + tM + '.' + (+tm + 1) + '.0';
  2159. else if (tpr)
  2160. to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
  2161. else
  2162. to = '<=' + to;
  2163. return (from + ' ' + to).trim();
  2164. }
  2165. // if ANY of the sets match ALL of its comparators, then pass
  2166. Range.prototype.test = function(version) {
  2167. if (!version)
  2168. return false;
  2169. if (typeof version === 'string')
  2170. version = new SemVer(version, this.loose);
  2171. for (var i = 0; i < this.set.length; i++) {
  2172. if (testSet(this.set[i], version))
  2173. return true;
  2174. }
  2175. return false;
  2176. };
  2177. function testSet(set, version) {
  2178. for (var i = 0; i < set.length; i++) {
  2179. if (!set[i].test(version))
  2180. return false;
  2181. }
  2182. if (version.prerelease.length) {
  2183. // Find the set of versions that are allowed to have prereleases
  2184. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  2185. // That should allow `1.2.3-pr.2` to pass.
  2186. // However, `1.2.4-alpha.notready` should NOT be allowed,
  2187. // even though it's within the range set by the comparators.
  2188. for (var i = 0; i < set.length; i++) {
  2189. debug(set[i].semver);
  2190. if (set[i].semver === ANY)
  2191. continue;
  2192. if (set[i].semver.prerelease.length > 0) {
  2193. var allowed = set[i].semver;
  2194. if (allowed.major === version.major &&
  2195. allowed.minor === version.minor &&
  2196. allowed.patch === version.patch)
  2197. return true;
  2198. }
  2199. }
  2200. // Version has a -pre, but it's not one of the ones we like.
  2201. return false;
  2202. }
  2203. return true;
  2204. }
  2205. exports.satisfies = satisfies;
  2206. function satisfies(version, range, loose) {
  2207. try {
  2208. range = new Range(range, loose);
  2209. } catch (er) {
  2210. return false;
  2211. }
  2212. return range.test(version);
  2213. }
  2214. exports.maxSatisfying = maxSatisfying;
  2215. function maxSatisfying(versions, range, loose) {
  2216. var max = null;
  2217. var maxSV = null;
  2218. try {
  2219. var rangeObj = new Range(range, loose);
  2220. } catch (er) {
  2221. return null;
  2222. }
  2223. versions.forEach(function (v) {
  2224. if (rangeObj.test(v)) { // satisfies(v, range, loose)
  2225. if (!max || maxSV.compare(v) === -1) { // compare(max, v, true)
  2226. max = v;
  2227. maxSV = new SemVer(max, loose);
  2228. }
  2229. }
  2230. });
  2231. return max;
  2232. }
  2233. exports.minSatisfying = minSatisfying;
  2234. function minSatisfying(versions, range, loose) {
  2235. var min = null;
  2236. var minSV = null;
  2237. try {
  2238. var rangeObj = new Range(range, loose);
  2239. } catch (er) {
  2240. return null;
  2241. }
  2242. versions.forEach(function (v) {
  2243. if (rangeObj.test(v)) { // satisfies(v, range, loose)
  2244. if (!min || minSV.compare(v) === 1) { // compare(min, v, true)
  2245. min = v;
  2246. minSV = new SemVer(min, loose);
  2247. }
  2248. }
  2249. });
  2250. return min;
  2251. }
  2252. exports.validRange = validRange;
  2253. function validRange(range, loose) {
  2254. try {
  2255. // Return '*' instead of '' so that truthiness works.
  2256. // This will throw if it's invalid anyway
  2257. return new Range(range, loose).range || '*';
  2258. } catch (er) {
  2259. return null;
  2260. }
  2261. }
  2262. // Determine if version is less than all the versions possible in the range
  2263. exports.ltr = ltr;
  2264. function ltr(version, range, loose) {
  2265. return outside(version, range, '<', loose);
  2266. }
  2267. // Determine if version is greater than all the versions possible in the range.
  2268. exports.gtr = gtr;
  2269. function gtr(version, range, loose) {
  2270. return outside(version, range, '>', loose);
  2271. }
  2272. exports.outside = outside;
  2273. function outside(version, range, hilo, loose) {
  2274. version = new SemVer(version, loose);
  2275. range = new Range(range, loose);
  2276. var gtfn, ltefn, ltfn, comp, ecomp;
  2277. switch (hilo) {
  2278. case '>':
  2279. gtfn = gt;
  2280. ltefn = lte;
  2281. ltfn = lt;
  2282. comp = '>';
  2283. ecomp = '>=';
  2284. break;
  2285. case '<':
  2286. gtfn = lt;
  2287. ltefn = gte;
  2288. ltfn = gt;
  2289. comp = '<';
  2290. ecomp = '<=';
  2291. break;
  2292. default:
  2293. throw new TypeError('Must provide a hilo val of "<" or ">"');
  2294. }
  2295. // If it satisifes the range it is not outside
  2296. if (satisfies(version, range, loose)) {
  2297. return false;
  2298. }
  2299. // From now on, variable terms are as if we're in "gtr" mode.
  2300. // but note that everything is flipped for the "ltr" function.
  2301. for (var i = 0; i < range.set.length; ++i) {
  2302. var comparators = range.set[i];
  2303. var high = null;
  2304. var low = null;
  2305. comparators.forEach(function(comparator) {
  2306. if (comparator.semver === ANY) {
  2307. comparator = new Comparator('>=0.0.0');
  2308. }
  2309. high = high || comparator;
  2310. low = low || comparator;
  2311. if (gtfn(comparator.semver, high.semver, loose)) {
  2312. high = comparator;
  2313. } else if (ltfn(comparator.semver, low.semver, loose)) {
  2314. low = comparator;
  2315. }
  2316. });
  2317. // If the edge version comparator has a operator then our version
  2318. // isn't outside it
  2319. if (high.operator === comp || high.operator === ecomp) {
  2320. return false;
  2321. }
  2322. // If the lowest version comparator has an operator and our version
  2323. // is less than it then it isn't higher than the range
  2324. if ((!low.operator || low.operator === comp) &&
  2325. ltefn(version, low.semver)) {
  2326. return false;
  2327. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  2328. return false;
  2329. }
  2330. }
  2331. return true;
  2332. }
  2333. exports.prerelease = prerelease;
  2334. function prerelease(version, loose) {
  2335. var parsed = parse(version, loose);
  2336. return (parsed && parsed.prerelease.length) ? parsed.prerelease : null;
  2337. }
  2338. exports.intersects = intersects;
  2339. function intersects(r1, r2, loose) {
  2340. r1 = new Range(r1, loose);
  2341. r2 = new Range(r2, loose);
  2342. return r1.intersects(r2)
  2343. }
  2344. });
  2345. var assert$1 = true;
  2346. var buffer_ieee754 = "< 0.9.7";
  2347. var buffer = true;
  2348. var child_process = true;
  2349. var cluster = true;
  2350. var console$1 = true;
  2351. var constants = true;
  2352. var crypto = true;
  2353. var _debugger = "< 8";
  2354. var dgram = true;
  2355. var dns = true;
  2356. var domain = true;
  2357. var events$1 = true;
  2358. var freelist = "< 6";
  2359. var fs$1 = true;
  2360. var http = true;
  2361. var http2 = ">= 8.8";
  2362. var https = true;
  2363. var _http_server = ">= 0.11";
  2364. var _linklist = "< 8";
  2365. var module$1 = true;
  2366. var net = true;
  2367. var os$1 = true;
  2368. var path$1 = true;
  2369. var perf_hooks = ">= 8.5";
  2370. var process$1 = ">= 1";
  2371. var punycode = true;
  2372. var querystring = true;
  2373. var readline$1 = true;
  2374. var repl = true;
  2375. var stream = true;
  2376. var string_decoder = true;
  2377. var sys = true;
  2378. var timers = true;
  2379. var tls = true;
  2380. var tty = true;
  2381. var url$1 = true;
  2382. var util$4 = true;
  2383. var v8 = ">= 1";
  2384. var vm = true;
  2385. var zlib = true;
  2386. var core$1 = {
  2387. assert: assert$1,
  2388. buffer_ieee754: buffer_ieee754,
  2389. buffer: buffer,
  2390. child_process: child_process,
  2391. cluster: cluster,
  2392. console: console$1,
  2393. constants: constants,
  2394. crypto: crypto,
  2395. _debugger: _debugger,
  2396. dgram: dgram,
  2397. dns: dns,
  2398. domain: domain,
  2399. events: events$1,
  2400. freelist: freelist,
  2401. fs: fs$1,
  2402. http: http,
  2403. http2: http2,
  2404. https: https,
  2405. _http_server: _http_server,
  2406. _linklist: _linklist,
  2407. module: module$1,
  2408. net: net,
  2409. os: os$1,
  2410. path: path$1,
  2411. perf_hooks: perf_hooks,
  2412. process: process$1,
  2413. punycode: punycode,
  2414. querystring: querystring,
  2415. readline: readline$1,
  2416. repl: repl,
  2417. stream: stream,
  2418. string_decoder: string_decoder,
  2419. sys: sys,
  2420. timers: timers,
  2421. tls: tls,
  2422. tty: tty,
  2423. url: url$1,
  2424. util: util$4,
  2425. v8: v8,
  2426. vm: vm,
  2427. zlib: zlib
  2428. };
  2429. var core$2 = Object.freeze({
  2430. assert: assert$1,
  2431. buffer_ieee754: buffer_ieee754,
  2432. buffer: buffer,
  2433. child_process: child_process,
  2434. cluster: cluster,
  2435. console: console$1,
  2436. constants: constants,
  2437. crypto: crypto,
  2438. _debugger: _debugger,
  2439. dgram: dgram,
  2440. dns: dns,
  2441. domain: domain,
  2442. events: events$1,
  2443. freelist: freelist,
  2444. fs: fs$1,
  2445. http: http,
  2446. http2: http2,
  2447. https: https,
  2448. _http_server: _http_server,
  2449. _linklist: _linklist,
  2450. module: module$1,
  2451. net: net,
  2452. os: os$1,
  2453. path: path$1,
  2454. perf_hooks: perf_hooks,
  2455. process: process$1,
  2456. punycode: punycode,
  2457. querystring: querystring,
  2458. readline: readline$1,
  2459. repl: repl,
  2460. stream: stream,
  2461. string_decoder: string_decoder,
  2462. sys: sys,
  2463. timers: timers,
  2464. tls: tls,
  2465. tty: tty,
  2466. url: url$1,
  2467. util: util$4,
  2468. v8: v8,
  2469. vm: vm,
  2470. zlib: zlib,
  2471. default: core$1
  2472. });
  2473. var data = ( core$2 && core$1 ) || core$2;
  2474. var current = (process.versions && process.versions.node && process.versions.node.split('.')) || [];
  2475. function versionIncluded(specifier) {
  2476. if (specifier === true) { return true; }
  2477. var parts = specifier.split(' ');
  2478. var op = parts[0];
  2479. var versionParts = parts[1].split('.');
  2480. for (var i = 0; i < 3; ++i) {
  2481. var cur = Number(current[i] || 0);
  2482. var ver = Number(versionParts[i] || 0);
  2483. if (cur === ver) {
  2484. continue; // eslint-disable-line no-restricted-syntax, no-continue
  2485. }
  2486. if (op === '<') {
  2487. return cur < ver;
  2488. } else if (op === '>=') {
  2489. return cur >= ver;
  2490. } else {
  2491. return false;
  2492. }
  2493. }
  2494. return false;
  2495. }
  2496. var core = {};
  2497. for (var mod in data) { // eslint-disable-line no-restricted-syntax
  2498. if (Object.prototype.hasOwnProperty.call(data, mod)) {
  2499. core[mod] = versionIncluded(data[mod]);
  2500. }
  2501. }
  2502. var core_1 = core;
  2503. var caller = function () {
  2504. // see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
  2505. var origPrepareStackTrace = Error.prepareStackTrace;
  2506. Error.prepareStackTrace = function (_, stack) { return stack; };
  2507. var stack = (new Error()).stack;
  2508. Error.prepareStackTrace = origPrepareStackTrace;
  2509. return stack[2].getFileName();
  2510. };
  2511. var pathParse = createCommonjsModule(function (module) {
  2512. 'use strict';
  2513. var isWindows = process.platform === 'win32';
  2514. // Regex to split a windows path into three parts: [*, device, slash,
  2515. // tail] windows-only
  2516. var splitDeviceRe =
  2517. /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
  2518. // Regex to split the tail part of the above into [*, dir, basename, ext]
  2519. var splitTailRe =
  2520. /^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
  2521. var win32 = {};
  2522. // Function to split a filename into [root, dir, basename, ext]
  2523. function win32SplitPath(filename) {
  2524. // Separate device+slash from tail
  2525. var result = splitDeviceRe.exec(filename),
  2526. device = (result[1] || '') + (result[2] || ''),
  2527. tail = result[3] || '';
  2528. // Split the tail into dir, basename and extension
  2529. var result2 = splitTailRe.exec(tail),
  2530. dir = result2[1],
  2531. basename = result2[2],
  2532. ext = result2[3];
  2533. return [device, dir, basename, ext];
  2534. }
  2535. win32.parse = function(pathString) {
  2536. if (typeof pathString !== 'string') {
  2537. throw new TypeError(
  2538. "Parameter 'pathString' must be a string, not " + typeof pathString
  2539. );
  2540. }
  2541. var allParts = win32SplitPath(pathString);
  2542. if (!allParts || allParts.length !== 4) {
  2543. throw new TypeError("Invalid path '" + pathString + "'");
  2544. }
  2545. return {
  2546. root: allParts[0],
  2547. dir: allParts[0] + allParts[1].slice(0, -1),
  2548. base: allParts[2],
  2549. ext: allParts[3],
  2550. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  2551. };
  2552. };
  2553. // Split a filename into [root, dir, basename, ext], unix version
  2554. // 'root' is just a slash, or nothing.
  2555. var splitPathRe =
  2556. /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  2557. var posix = {};
  2558. function posixSplitPath(filename) {
  2559. return splitPathRe.exec(filename).slice(1);
  2560. }
  2561. posix.parse = function(pathString) {
  2562. if (typeof pathString !== 'string') {
  2563. throw new TypeError(
  2564. "Parameter 'pathString' must be a string, not " + typeof pathString
  2565. );
  2566. }
  2567. var allParts = posixSplitPath(pathString);
  2568. if (!allParts || allParts.length !== 4) {
  2569. throw new TypeError("Invalid path '" + pathString + "'");
  2570. }
  2571. allParts[1] = allParts[1] || '';
  2572. allParts[2] = allParts[2] || '';
  2573. allParts[3] = allParts[3] || '';
  2574. return {
  2575. root: allParts[0],
  2576. dir: allParts[0] + allParts[1].slice(0, -1),
  2577. base: allParts[2],
  2578. ext: allParts[3],
  2579. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  2580. };
  2581. };
  2582. if (isWindows)
  2583. module.exports = win32.parse;
  2584. else /* posix */
  2585. module.exports = posix.parse;
  2586. module.exports.posix = posix.parse;
  2587. module.exports.win32 = win32.parse;
  2588. });
  2589. var parse = path.parse || pathParse;
  2590. var nodeModulesPaths = function nodeModulesPaths(start, opts) {
  2591. var modules = opts && opts.moduleDirectory
  2592. ? [].concat(opts.moduleDirectory)
  2593. : ['node_modules'];
  2594. // ensure that `start` is an absolute path at this point,
  2595. // resolving against the process' current working directory
  2596. var absoluteStart = path.resolve(start);
  2597. if (opts && opts.preserveSymlinks === false) {
  2598. try {
  2599. absoluteStart = fs.realpathSync(absoluteStart);
  2600. } catch (err) {
  2601. if (err.code !== 'ENOENT') {
  2602. throw err;
  2603. }
  2604. }
  2605. }
  2606. var prefix = '/';
  2607. if (/^([A-Za-z]:)/.test(absoluteStart)) {
  2608. prefix = '';
  2609. } else if (/^\\\\/.test(absoluteStart)) {
  2610. prefix = '\\\\';
  2611. }
  2612. var paths = [absoluteStart];
  2613. var parsed = parse(absoluteStart);
  2614. while (parsed.dir !== paths[paths.length - 1]) {
  2615. paths.push(parsed.dir);
  2616. parsed = parse(parsed.dir);
  2617. }
  2618. var dirs = paths.reduce(function (dirs, aPath) {
  2619. return dirs.concat(modules.map(function (moduleDir) {
  2620. return path.join(prefix, aPath, moduleDir);
  2621. }));
  2622. }, []);
  2623. return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
  2624. };
  2625. var async = function resolve(x, options, callback) {
  2626. var cb = callback;
  2627. var opts = options || {};
  2628. if (typeof opts === 'function') {
  2629. cb = opts;
  2630. opts = {};
  2631. }
  2632. if (typeof x !== 'string') {
  2633. var err = new TypeError('Path must be a string.');
  2634. return process.nextTick(function () {
  2635. cb(err);
  2636. });
  2637. }
  2638. var isFile = opts.isFile || function (file, cb) {
  2639. fs.stat(file, function (err, stat) {
  2640. if (!err) {
  2641. return cb(null, stat.isFile() || stat.isFIFO());
  2642. }
  2643. if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
  2644. return cb(err);
  2645. });
  2646. };
  2647. var readFile = opts.readFile || fs.readFile;
  2648. var extensions = opts.extensions || ['.js'];
  2649. var y = opts.basedir || path.dirname(caller());
  2650. opts.paths = opts.paths || [];
  2651. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  2652. var res = path.resolve(y, x);
  2653. if (x === '..' || x.slice(-1) === '/') res += '/';
  2654. if (/\/$/.test(x) && res === y) {
  2655. loadAsDirectory(res, opts.package, onfile);
  2656. } else loadAsFile(res, opts.package, onfile);
  2657. } else loadNodeModules(x, y, function (err, n, pkg) {
  2658. if (err) cb(err);
  2659. else if (n) cb(null, n, pkg);
  2660. else if (core_1[x]) return cb(null, x);
  2661. else {
  2662. var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
  2663. moduleError.code = 'MODULE_NOT_FOUND';
  2664. cb(moduleError);
  2665. }
  2666. });
  2667. function onfile(err, m, pkg) {
  2668. if (err) cb(err);
  2669. else if (m) cb(null, m, pkg);
  2670. else loadAsDirectory(res, function (err, d, pkg) {
  2671. if (err) cb(err);
  2672. else if (d) cb(null, d, pkg);
  2673. else {
  2674. var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
  2675. moduleError.code = 'MODULE_NOT_FOUND';
  2676. cb(moduleError);
  2677. }
  2678. });
  2679. }
  2680. function loadAsFile(x, thePackage, callback) {
  2681. var loadAsFilePackage = thePackage;
  2682. var cb = callback;
  2683. if (typeof loadAsFilePackage === 'function') {
  2684. cb = loadAsFilePackage;
  2685. loadAsFilePackage = undefined;
  2686. }
  2687. var exts = [''].concat(extensions);
  2688. load(exts, x, loadAsFilePackage);
  2689. function load(exts, x, loadPackage) {
  2690. if (exts.length === 0) return cb(null, undefined, loadPackage);
  2691. var file = x + exts[0];
  2692. var pkg = loadPackage;
  2693. if (pkg) onpkg(null, pkg);
  2694. else loadpkg(path.dirname(file), onpkg);
  2695. function onpkg(err, pkg_, dir) {
  2696. pkg = pkg_;
  2697. if (err) return cb(err);
  2698. if (dir && pkg && opts.pathFilter) {
  2699. var rfile = path.relative(dir, file);
  2700. var rel = rfile.slice(0, rfile.length - exts[0].length);
  2701. var r = opts.pathFilter(pkg, x, rel);
  2702. if (r) return load(
  2703. [''].concat(extensions.slice()),
  2704. path.resolve(dir, r),
  2705. pkg
  2706. );
  2707. }
  2708. isFile(file, onex);
  2709. }
  2710. function onex(err, ex) {
  2711. if (err) return cb(err);
  2712. if (ex) return cb(null, file, pkg);
  2713. load(exts.slice(1), x, pkg);
  2714. }
  2715. }
  2716. }
  2717. function loadpkg(dir, cb) {
  2718. if (dir === '' || dir === '/') return cb(null);
  2719. if (process.platform === 'win32' && (/^\w:[/\\]*$/).test(dir)) {
  2720. return cb(null);
  2721. }
  2722. if (/[/\\]node_modules[/\\]*$/.test(dir)) return cb(null);
  2723. var pkgfile = path.join(dir, 'package.json');
  2724. isFile(pkgfile, function (err, ex) {
  2725. // on err, ex is false
  2726. if (!ex) return loadpkg(path.dirname(dir), cb);
  2727. readFile(pkgfile, function (err, body) {
  2728. if (err) cb(err);
  2729. try { var pkg = JSON.parse(body); } catch (jsonErr) {}
  2730. if (pkg && opts.packageFilter) {
  2731. pkg = opts.packageFilter(pkg, pkgfile);
  2732. }
  2733. cb(null, pkg, dir);
  2734. });
  2735. });
  2736. }
  2737. function loadAsDirectory(x, loadAsDirectoryPackage, callback) {
  2738. var cb = callback;
  2739. var fpkg = loadAsDirectoryPackage;
  2740. if (typeof fpkg === 'function') {
  2741. cb = fpkg;
  2742. fpkg = opts.package;
  2743. }
  2744. var pkgfile = path.join(x, 'package.json');
  2745. isFile(pkgfile, function (err, ex) {
  2746. if (err) return cb(err);
  2747. if (!ex) return loadAsFile(path.join(x, 'index'), fpkg, cb);
  2748. readFile(pkgfile, function (err, body) {
  2749. if (err) return cb(err);
  2750. try {
  2751. var pkg = JSON.parse(body);
  2752. } catch (jsonErr) {}
  2753. if (opts.packageFilter) {
  2754. pkg = opts.packageFilter(pkg, pkgfile);
  2755. }
  2756. if (pkg.main) {
  2757. if (pkg.main === '.' || pkg.main === './') {
  2758. pkg.main = 'index';
  2759. }
  2760. loadAsFile(path.resolve(x, pkg.main), pkg, function (err, m, pkg) {
  2761. if (err) return cb(err);
  2762. if (m) return cb(null, m, pkg);
  2763. if (!pkg) return loadAsFile(path.join(x, 'index'), pkg, cb);
  2764. var dir = path.resolve(x, pkg.main);
  2765. loadAsDirectory(dir, pkg, function (err, n, pkg) {
  2766. if (err) return cb(err);
  2767. if (n) return cb(null, n, pkg);
  2768. loadAsFile(path.join(x, 'index'), pkg, cb);
  2769. });
  2770. });
  2771. return;
  2772. }
  2773. loadAsFile(path.join(x, '/index'), pkg, cb);
  2774. });
  2775. });
  2776. }
  2777. function processDirs(cb, dirs) {
  2778. if (dirs.length === 0) return cb(null, undefined);
  2779. var dir = dirs[0];
  2780. var file = path.join(dir, x);
  2781. loadAsFile(file, undefined, onfile);
  2782. function onfile(err, m, pkg) {
  2783. if (err) return cb(err);
  2784. if (m) return cb(null, m, pkg);
  2785. loadAsDirectory(path.join(dir, x), undefined, ondir);
  2786. }
  2787. function ondir(err, n, pkg) {
  2788. if (err) return cb(err);
  2789. if (n) return cb(null, n, pkg);
  2790. processDirs(cb, dirs.slice(1));
  2791. }
  2792. }
  2793. function loadNodeModules(x, start, cb) {
  2794. processDirs(cb, nodeModulesPaths(start, opts));
  2795. }
  2796. };
  2797. var sync = function (x, options) {
  2798. if (typeof x !== 'string') {
  2799. throw new TypeError('Path must be a string.');
  2800. }
  2801. var opts = options || {};
  2802. var isFile = opts.isFile || function (file) {
  2803. try {
  2804. var stat = fs.statSync(file);
  2805. } catch (e) {
  2806. if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
  2807. throw e;
  2808. }
  2809. return stat.isFile() || stat.isFIFO();
  2810. };
  2811. var readFileSync = opts.readFileSync || fs.readFileSync;
  2812. var extensions = opts.extensions || ['.js'];
  2813. var y = opts.basedir || path.dirname(caller());
  2814. opts.paths = opts.paths || [];
  2815. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  2816. var res = path.resolve(y, x);
  2817. if (x === '..' || x.slice(-1) === '/') res += '/';
  2818. var m = loadAsFileSync(res) || loadAsDirectorySync(res);
  2819. if (m) return m;
  2820. } else {
  2821. var n = loadNodeModulesSync(x, y);
  2822. if (n) return n;
  2823. }
  2824. if (core_1[x]) return x;
  2825. var err = new Error("Cannot find module '" + x + "' from '" + y + "'");
  2826. err.code = 'MODULE_NOT_FOUND';
  2827. throw err;
  2828. function loadAsFileSync(x) {
  2829. if (isFile(x)) {
  2830. return x;
  2831. }
  2832. for (var i = 0; i < extensions.length; i++) {
  2833. var file = x + extensions[i];
  2834. if (isFile(file)) {
  2835. return file;
  2836. }
  2837. }
  2838. }
  2839. function loadAsDirectorySync(x) {
  2840. var pkgfile = path.join(x, '/package.json');
  2841. if (isFile(pkgfile)) {
  2842. try {
  2843. var body = readFileSync(pkgfile, 'UTF8');
  2844. var pkg = JSON.parse(body);
  2845. if (opts.packageFilter) {
  2846. pkg = opts.packageFilter(pkg, x);
  2847. }
  2848. if (pkg.main) {
  2849. if (pkg.main === '.' || pkg.main === './') {
  2850. pkg.main = 'index';
  2851. }
  2852. var m = loadAsFileSync(path.resolve(x, pkg.main));
  2853. if (m) return m;
  2854. var n = loadAsDirectorySync(path.resolve(x, pkg.main));
  2855. if (n) return n;
  2856. }
  2857. } catch (e) {}
  2858. }
  2859. return loadAsFileSync(path.join(x, '/index'));
  2860. }
  2861. function loadNodeModulesSync(x, start) {
  2862. var dirs = nodeModulesPaths(start, opts);
  2863. for (var i = 0; i < dirs.length; i++) {
  2864. var dir = dirs[i];
  2865. var m = loadAsFileSync(path.join(dir, '/', x));
  2866. if (m) return m;
  2867. var n = loadAsDirectorySync(path.join(dir, '/', x));
  2868. if (n) return n;
  2869. }
  2870. }
  2871. };
  2872. var resolve = createCommonjsModule(function (module, exports) {
  2873. async.core = core_1;
  2874. async.isCore = function isCore(x) { return core_1[x]; };
  2875. async.sync = sync;
  2876. exports = async;
  2877. module.exports = async;
  2878. });
  2879. var pathExists = createCommonjsModule(function (module) {
  2880. 'use strict';
  2881. module.exports = fp => new Promise(resolve => {
  2882. fs.access(fp, err => {
  2883. resolve(!err);
  2884. });
  2885. });
  2886. module.exports.sync = fp => {
  2887. try {
  2888. fs.accessSync(fp);
  2889. return true;
  2890. } catch (err) {
  2891. return false;
  2892. }
  2893. };
  2894. });
  2895. var pLimit = createCommonjsModule(function (module) {
  2896. 'use strict';
  2897. module.exports = concurrency => {
  2898. if (concurrency < 1) {
  2899. throw new TypeError('Expected `concurrency` to be a number from 1 and up');
  2900. }
  2901. const queue = [];
  2902. let activeCount = 0;
  2903. const next = () => {
  2904. activeCount--;
  2905. if (queue.length > 0) {
  2906. queue.shift()();
  2907. }
  2908. };
  2909. return fn => new Promise((resolve, reject) => {
  2910. const run = () => {
  2911. activeCount++;
  2912. fn().then(
  2913. val => {
  2914. resolve(val);
  2915. next();
  2916. },
  2917. err => {
  2918. reject(err);
  2919. next();
  2920. }
  2921. );
  2922. };
  2923. if (activeCount < concurrency) {
  2924. run();
  2925. } else {
  2926. queue.push(run);
  2927. }
  2928. });
  2929. };
  2930. });
  2931. var pLocate = createCommonjsModule(function (module) {
  2932. 'use strict';
  2933. class EndError extends Error {
  2934. constructor(value) {
  2935. super();
  2936. this.value = value;
  2937. }
  2938. }
  2939. // the input can also be a promise, so we `Promise.all()` them both
  2940. const finder = el => Promise.all(el).then(val => val[1] === true && Promise.reject(new EndError(val[0])));
  2941. module.exports = (iterable, tester, opts) => {
  2942. opts = Object.assign({
  2943. concurrency: Infinity,
  2944. preserveOrder: true
  2945. }, opts);
  2946. const limit = pLimit(opts.concurrency);
  2947. // start all the promises concurrently with optional limit
  2948. const items = Array.from(iterable).map(el => [el, limit(() => Promise.resolve(el).then(tester))]);
  2949. // check the promises either serially or concurrently
  2950. const checkLimit = pLimit(opts.preserveOrder ? 1 : Infinity);
  2951. return Promise.all(items.map(el => checkLimit(() => finder(el))))
  2952. .then(() => {})
  2953. .catch(err => err instanceof EndError ? err.value : Promise.reject(err));
  2954. };
  2955. });
  2956. var locatePath = createCommonjsModule(function (module) {
  2957. 'use strict';
  2958. module.exports = (iterable, opts) => {
  2959. opts = Object.assign({
  2960. cwd: process.cwd()
  2961. }, opts);
  2962. return pLocate(iterable, el => pathExists(path.resolve(opts.cwd, el)), opts);
  2963. };
  2964. module.exports.sync = (iterable, opts) => {
  2965. opts = Object.assign({
  2966. cwd: process.cwd()
  2967. }, opts);
  2968. for (const el of iterable) {
  2969. if (pathExists.sync(path.resolve(opts.cwd, el))) {
  2970. return el;
  2971. }
  2972. }
  2973. };
  2974. });
  2975. var findUp = createCommonjsModule(function (module) {
  2976. 'use strict';
  2977. module.exports = (filename, opts) => {
  2978. opts = opts || {};
  2979. const startDir = path.resolve(opts.cwd || '');
  2980. const root = path.parse(startDir).root;
  2981. const filenames = [].concat(filename);
  2982. return new Promise(resolve => {
  2983. (function find(dir) {
  2984. locatePath(filenames, {cwd: dir}).then(file => {
  2985. if (file) {
  2986. resolve(path.join(dir, file));
  2987. } else if (dir === root) {
  2988. resolve(null);
  2989. } else {
  2990. find(path.dirname(dir));
  2991. }
  2992. });
  2993. })(startDir);
  2994. });
  2995. };
  2996. module.exports.sync = (filename, opts) => {
  2997. opts = opts || {};
  2998. let dir = path.resolve(opts.cwd || '');
  2999. const root = path.parse(dir).root;
  3000. const filenames = [].concat(filename);
  3001. // eslint-disable-next-line no-constant-condition
  3002. while (true) {
  3003. const file = locatePath.sync(filenames, {cwd: dir});
  3004. if (file) {
  3005. return path.join(dir, file);
  3006. } else if (dir === root) {
  3007. return null;
  3008. }
  3009. dir = path.dirname(dir);
  3010. }
  3011. };
  3012. });
  3013. var stripBom = createCommonjsModule(function (module) {
  3014. 'use strict';
  3015. module.exports = x => {
  3016. if (typeof x !== 'string') {
  3017. throw new TypeError('Expected a string, got ' + typeof x);
  3018. }
  3019. // Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
  3020. // conversion translates it to FEFF (UTF-16 BOM)
  3021. if (x.charCodeAt(0) === 0xFEFF) {
  3022. return x.slice(1);
  3023. }
  3024. return x;
  3025. };
  3026. });
  3027. var isArrayish = function isArrayish(obj) {
  3028. if (!obj) {
  3029. return false;
  3030. }
  3031. return obj instanceof Array || Array.isArray(obj) ||
  3032. (obj.length >= 0 && obj.splice instanceof Function);
  3033. };
  3034. var errorEx = function errorEx(name, properties) {
  3035. if (!name || name.constructor !== String) {
  3036. properties = name || {};
  3037. name = Error.name;
  3038. }
  3039. var errorExError = function ErrorEXError(message) {
  3040. if (!this) {
  3041. return new ErrorEXError(message);
  3042. }
  3043. message = message instanceof Error
  3044. ? message.message
  3045. : (message || this.message);
  3046. Error.call(this, message);
  3047. Error.captureStackTrace(this, errorExError);
  3048. this.name = name;
  3049. Object.defineProperty(this, 'message', {
  3050. configurable: true,
  3051. enumerable: false,
  3052. get: function () {
  3053. var newMessage = message.split(/\r?\n/g);
  3054. for (var key in properties) {
  3055. if (!properties.hasOwnProperty(key)) {
  3056. continue;
  3057. }
  3058. var modifier = properties[key];
  3059. if ('message' in modifier) {
  3060. newMessage = modifier.message(this[key], newMessage) || newMessage;
  3061. if (!isArrayish(newMessage)) {
  3062. newMessage = [newMessage];
  3063. }
  3064. }
  3065. }
  3066. return newMessage.join('\n');
  3067. },
  3068. set: function (v) {
  3069. message = v;
  3070. }
  3071. });
  3072. var stackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack');
  3073. var stackGetter = stackDescriptor.get;
  3074. var stackValue = stackDescriptor.value;
  3075. delete stackDescriptor.value;
  3076. delete stackDescriptor.writable;
  3077. stackDescriptor.get = function () {
  3078. var stack = (stackGetter)
  3079. ? stackGetter.call(this).split(/\r?\n+/g)
  3080. : stackValue.split(/\r?\n+/g);
  3081. // starting in Node 7, the stack builder caches the message.
  3082. // just replace it.
  3083. stack[0] = this.name + ': ' + this.message;
  3084. var lineCount = 1;
  3085. for (var key in properties) {
  3086. if (!properties.hasOwnProperty(key)) {
  3087. continue;
  3088. }
  3089. var modifier = properties[key];
  3090. if ('line' in modifier) {
  3091. var line = modifier.line(this[key]);
  3092. if (line) {
  3093. stack.splice(lineCount++, 0, ' ' + line);
  3094. }
  3095. }
  3096. if ('stack' in modifier) {
  3097. modifier.stack(this[key], stack);
  3098. }
  3099. }
  3100. return stack.join('\n');
  3101. };
  3102. Object.defineProperty(this, 'stack', stackDescriptor);
  3103. };
  3104. if (Object.setPrototypeOf) {
  3105. Object.setPrototypeOf(errorExError.prototype, Error.prototype);
  3106. Object.setPrototypeOf(errorExError, Error);
  3107. } else {
  3108. util.inherits(errorExError, Error);
  3109. }
  3110. return errorExError;
  3111. };
  3112. errorEx.append = function (str, def) {
  3113. return {
  3114. message: function (v, message) {
  3115. v = v || def;
  3116. if (v) {
  3117. message[0] += ' ' + str.replace('%s', v.toString());
  3118. }
  3119. return message;
  3120. }
  3121. };
  3122. };
  3123. errorEx.line = function (str, def) {
  3124. return {
  3125. line: function (v) {
  3126. v = v || def;
  3127. if (v) {
  3128. return str.replace('%s', v.toString());
  3129. }
  3130. return null;
  3131. }
  3132. };
  3133. };
  3134. var errorEx_1 = errorEx;
  3135. var jsonParseBetterErrors = parseJson$2;
  3136. function parseJson$2 (txt, reviver, context) {
  3137. context = context || 20;
  3138. try {
  3139. return JSON.parse(txt, reviver)
  3140. } catch (e) {
  3141. const syntaxErr = e.message.match(/^Unexpected token.*position\s+(\d+)/i);
  3142. const errIdx = syntaxErr
  3143. ? +syntaxErr[1]
  3144. : e.message.match(/^Unexpected end of JSON.*/i)
  3145. ? txt.length - 1
  3146. : null;
  3147. if (errIdx != null) {
  3148. const start = errIdx <= context
  3149. ? 0
  3150. : errIdx - context;
  3151. const end = errIdx + context >= txt.length
  3152. ? txt.length
  3153. : errIdx + context;
  3154. e.message += ` while parsing near '${
  3155. start === 0 ? '' : '...'
  3156. }${txt.slice(start, end)}${
  3157. end === txt.length ? '' : '...'
  3158. }'`;
  3159. } else {
  3160. e.message += ` while parsing '${txt.slice(0, context * 2)}'`;
  3161. }
  3162. throw e
  3163. }
  3164. }
  3165. var parseJson = createCommonjsModule(function (module) {
  3166. 'use strict';
  3167. const JSONError = errorEx_1('JSONError', {
  3168. fileName: errorEx_1.append('in %s')
  3169. });
  3170. module.exports = (input, reviver, filename) => {
  3171. if (typeof reviver === 'string') {
  3172. filename = reviver;
  3173. reviver = null;
  3174. }
  3175. try {
  3176. try {
  3177. return JSON.parse(input, reviver);
  3178. } catch (err) {
  3179. jsonParseBetterErrors(input, reviver);
  3180. throw err;
  3181. }
  3182. } catch (err) {
  3183. err.message = err.message.replace(/\n/g, '');
  3184. const jsonErr = new JSONError(err);
  3185. if (filename) {
  3186. jsonErr.fileName = filename;
  3187. }
  3188. throw jsonErr;
  3189. }
  3190. };
  3191. });
  3192. var pify = createCommonjsModule(function (module) {
  3193. 'use strict';
  3194. const processFn = (fn, opts) => function () {
  3195. const P = opts.promiseModule;
  3196. const args = new Array(arguments.length);
  3197. for (let i = 0; i < arguments.length; i++) {
  3198. args[i] = arguments[i];
  3199. }
  3200. return new P((resolve, reject) => {
  3201. if (opts.errorFirst) {
  3202. args.push(function (err, result) {
  3203. if (opts.multiArgs) {
  3204. const results = new Array(arguments.length - 1);
  3205. for (let i = 1; i < arguments.length; i++) {
  3206. results[i - 1] = arguments[i];
  3207. }
  3208. if (err) {
  3209. results.unshift(err);
  3210. reject(results);
  3211. } else {
  3212. resolve(results);
  3213. }
  3214. } else if (err) {
  3215. reject(err);
  3216. } else {
  3217. resolve(result);
  3218. }
  3219. });
  3220. } else {
  3221. args.push(function (result) {
  3222. if (opts.multiArgs) {
  3223. const results = new Array(arguments.length - 1);
  3224. for (let i = 0; i < arguments.length; i++) {
  3225. results[i] = arguments[i];
  3226. }
  3227. resolve(results);
  3228. } else {
  3229. resolve(result);
  3230. }
  3231. });
  3232. }
  3233. fn.apply(this, args);
  3234. });
  3235. };
  3236. module.exports = (obj, opts) => {
  3237. opts = Object.assign({
  3238. exclude: [/.+(Sync|Stream)$/],
  3239. errorFirst: true,
  3240. promiseModule: Promise
  3241. }, opts);
  3242. const filter = key => {
  3243. const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);
  3244. return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
  3245. };
  3246. let ret;
  3247. if (typeof obj === 'function') {
  3248. ret = function () {
  3249. if (opts.excludeMain) {
  3250. return obj.apply(this, arguments);
  3251. }
  3252. return processFn(obj, opts).apply(this, arguments);
  3253. };
  3254. } else {
  3255. ret = Object.create(Object.getPrototypeOf(obj));
  3256. }
  3257. for (const key in obj) { // eslint-disable-line guard-for-in
  3258. const x = obj[key];
  3259. ret[key] = typeof x === 'function' && filter(key) ? processFn(x, opts) : x;
  3260. }
  3261. return ret;
  3262. };
  3263. });
  3264. const parse$1 = (data, fp) => parseJson(stripBom(data), path.relative('.', fp));
  3265. var loadJsonFile = fp => pify(fs.readFile)(fp, 'utf8').then(data => parse$1(data, fp));
  3266. var sync$2 = fp => parse$1(fs.readFileSync(fp, 'utf8'), fp);
  3267. loadJsonFile.sync = sync$2;
  3268. var pify$3 = createCommonjsModule(function (module) {
  3269. 'use strict';
  3270. const processFn = (fn, opts) => function () {
  3271. const P = opts.promiseModule;
  3272. const args = new Array(arguments.length);
  3273. for (let i = 0; i < arguments.length; i++) {
  3274. args[i] = arguments[i];
  3275. }
  3276. return new P((resolve, reject) => {
  3277. if (opts.errorFirst) {
  3278. args.push(function (err, result) {
  3279. if (opts.multiArgs) {
  3280. const results = new Array(arguments.length - 1);
  3281. for (let i = 1; i < arguments.length; i++) {
  3282. results[i - 1] = arguments[i];
  3283. }
  3284. if (err) {
  3285. results.unshift(err);
  3286. reject(results);
  3287. } else {
  3288. resolve(results);
  3289. }
  3290. } else if (err) {
  3291. reject(err);
  3292. } else {
  3293. resolve(result);
  3294. }
  3295. });
  3296. } else {
  3297. args.push(function (result) {
  3298. if (opts.multiArgs) {
  3299. const results = new Array(arguments.length - 1);
  3300. for (let i = 0; i < arguments.length; i++) {
  3301. results[i] = arguments[i];
  3302. }
  3303. resolve(results);
  3304. } else {
  3305. resolve(result);
  3306. }
  3307. });
  3308. }
  3309. fn.apply(this, args);
  3310. });
  3311. };
  3312. module.exports = (obj, opts) => {
  3313. opts = Object.assign({
  3314. exclude: [/.+(Sync|Stream)$/],
  3315. errorFirst: true,
  3316. promiseModule: Promise
  3317. }, opts);
  3318. const filter = key => {
  3319. const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);
  3320. return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
  3321. };
  3322. let ret;
  3323. if (typeof obj === 'function') {
  3324. ret = function () {
  3325. if (opts.excludeMain) {
  3326. return obj.apply(this, arguments);
  3327. }
  3328. return processFn(obj, opts).apply(this, arguments);
  3329. };
  3330. } else {
  3331. ret = Object.create(Object.getPrototypeOf(obj));
  3332. }
  3333. for (const key in obj) { // eslint-disable-line guard-for-in
  3334. const x = obj[key];
  3335. ret[key] = typeof x === 'function' && filter(key) ? processFn(x, opts) : x;
  3336. }
  3337. return ret;
  3338. };
  3339. });
  3340. function type(fn, fn2, fp) {
  3341. if (typeof fp !== 'string') {
  3342. return Promise.reject(new TypeError(`Expected a string, got ${typeof fp}`));
  3343. }
  3344. return pify$3(fs[fn])(fp)
  3345. .then(stats => stats[fn2]())
  3346. .catch(err => {
  3347. if (err.code === 'ENOENT') {
  3348. return false;
  3349. }
  3350. throw err;
  3351. });
  3352. }
  3353. function typeSync(fn, fn2, fp) {
  3354. if (typeof fp !== 'string') {
  3355. throw new TypeError(`Expected a string, got ${typeof fp}`);
  3356. }
  3357. try {
  3358. return fs[fn](fp)[fn2]();
  3359. } catch (err) {
  3360. if (err.code === 'ENOENT') {
  3361. return false;
  3362. }
  3363. throw err;
  3364. }
  3365. }
  3366. var file = type.bind(null, 'stat', 'isFile');
  3367. var dir = type.bind(null, 'stat', 'isDirectory');
  3368. var symlink = type.bind(null, 'lstat', 'isSymbolicLink');
  3369. var fileSync = typeSync.bind(null, 'statSync', 'isFile');
  3370. var dirSync = typeSync.bind(null, 'statSync', 'isDirectory');
  3371. var symlinkSync = typeSync.bind(null, 'lstatSync', 'isSymbolicLink');
  3372. var pathType = {
  3373. file: file,
  3374. dir: dir,
  3375. symlink: symlink,
  3376. fileSync: fileSync,
  3377. dirSync: dirSync,
  3378. symlinkSync: symlinkSync
  3379. };
  3380. var parser$1 = createCommonjsModule(function (module, exports) {
  3381. /* parser generated by jison 0.4.17 */
  3382. /*
  3383. Returns a Parser object of the following structure:
  3384. Parser: {
  3385. yy: {}
  3386. }
  3387. Parser.prototype: {
  3388. yy: {},
  3389. trace: function(),
  3390. symbols_: {associative list: name ==> number},
  3391. terminals_: {associative list: number ==> name},
  3392. productions_: [...],
  3393. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
  3394. table: [...],
  3395. defaultActions: {...},
  3396. parseError: function(str, hash),
  3397. parse: function(input),
  3398. lexer: {
  3399. EOF: 1,
  3400. parseError: function(str, hash),
  3401. setInput: function(input),
  3402. input: function(),
  3403. unput: function(str),
  3404. more: function(),
  3405. less: function(n),
  3406. pastInput: function(),
  3407. upcomingInput: function(),
  3408. showPosition: function(),
  3409. test_match: function(regex_match_array, rule_index),
  3410. next: function(),
  3411. lex: function(),
  3412. begin: function(condition),
  3413. popState: function(),
  3414. _currentRules: function(),
  3415. topState: function(),
  3416. pushState: function(condition),
  3417. options: {
  3418. ranges: boolean (optional: true ==> token location info will include a .range[] member)
  3419. flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
  3420. 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)
  3421. },
  3422. performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
  3423. rules: [...],
  3424. conditions: {associative list: name ==> set},
  3425. }
  3426. }
  3427. token location info (@$, _$, etc.): {
  3428. first_line: n,
  3429. last_line: n,
  3430. first_column: n,
  3431. last_column: n,
  3432. range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
  3433. }
  3434. the parseError function receives a 'hash' object with these members for lexer and parser errors: {
  3435. text: (matched text)
  3436. token: (the produced terminal token, if any)
  3437. line: (yylineno)
  3438. }
  3439. while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
  3440. loc: (yylloc)
  3441. expected: (string describing the set of expected tokens)
  3442. recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
  3443. }
  3444. */
  3445. var spdxparse = (function(){
  3446. 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];
  3447. var parser = {trace: function trace() { },
  3448. yy: {},
  3449. 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},
  3450. 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"},
  3451. productions_: [0,[3,2],[6,1],[6,2],[6,1],[6,3],[4,1],[4,3],[4,3],[4,3],[4,3]],
  3452. performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
  3453. /* this == yyval */
  3454. var $0 = $$.length - 1;
  3455. switch (yystate) {
  3456. case 1:
  3457. return this.$ = $$[$0-1]
  3458. break;
  3459. case 2: case 4: case 5:
  3460. this.$ = {license: yytext};
  3461. break;
  3462. case 3:
  3463. this.$ = {license: $$[$0-1], plus: true};
  3464. break;
  3465. case 6:
  3466. this.$ = $$[$0];
  3467. break;
  3468. case 7:
  3469. this.$ = {exception: $$[$0]};
  3470. this.$.license = $$[$0-2].license;
  3471. if ($$[$0-2].hasOwnProperty('plus')) {
  3472. this.$.plus = $$[$0-2].plus;
  3473. }
  3474. break;
  3475. case 8:
  3476. this.$ = {conjunction: 'and', left: $$[$0-2], right: $$[$0]};
  3477. break;
  3478. case 9:
  3479. this.$ = {conjunction: 'or', left: $$[$0-2], right: $$[$0]};
  3480. break;
  3481. case 10:
  3482. this.$ = $$[$0-1];
  3483. break;
  3484. }
  3485. },
  3486. 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])],
  3487. defaultActions: {8:[2,1]},
  3488. parseError: function parseError(str, hash) {
  3489. if (hash.recoverable) {
  3490. this.trace(str);
  3491. } else {
  3492. function _parseError (msg, hash) {
  3493. this.message = msg;
  3494. this.hash = hash;
  3495. }
  3496. _parseError.prototype = Error;
  3497. throw new _parseError(str, hash);
  3498. }
  3499. },
  3500. parse: function parse(input) {
  3501. var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
  3502. var args = lstack.slice.call(arguments, 1);
  3503. var lexer = Object.create(this.lexer);
  3504. var sharedState = { yy: {} };
  3505. for (var k in this.yy) {
  3506. if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
  3507. sharedState.yy[k] = this.yy[k];
  3508. }
  3509. }
  3510. lexer.setInput(input, sharedState.yy);
  3511. sharedState.yy.lexer = lexer;
  3512. sharedState.yy.parser = this;
  3513. if (typeof lexer.yylloc == 'undefined') {
  3514. lexer.yylloc = {};
  3515. }
  3516. var yyloc = lexer.yylloc;
  3517. lstack.push(yyloc);
  3518. var ranges = lexer.options && lexer.options.ranges;
  3519. if (typeof sharedState.yy.parseError === 'function') {
  3520. this.parseError = sharedState.yy.parseError;
  3521. } else {
  3522. this.parseError = Object.getPrototypeOf(this).parseError;
  3523. }
  3524. _token_stack:
  3525. var lex = function () {
  3526. var token;
  3527. token = lexer.lex() || EOF;
  3528. if (typeof token !== 'number') {
  3529. token = self.symbols_[token] || token;
  3530. }
  3531. return token;
  3532. };
  3533. var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
  3534. while (true) {
  3535. state = stack[stack.length - 1];
  3536. if (this.defaultActions[state]) {
  3537. action = this.defaultActions[state];
  3538. } else {
  3539. if (symbol === null || typeof symbol == 'undefined') {
  3540. symbol = lex();
  3541. }
  3542. action = table[state] && table[state][symbol];
  3543. }
  3544. if (typeof action === 'undefined' || !action.length || !action[0]) {
  3545. var errStr = '';
  3546. expected = [];
  3547. for (p in table[state]) {
  3548. if (this.terminals_[p] && p > TERROR) {
  3549. expected.push('\'' + this.terminals_[p] + '\'');
  3550. }
  3551. }
  3552. if (lexer.showPosition) {
  3553. errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
  3554. } else {
  3555. errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
  3556. }
  3557. this.parseError(errStr, {
  3558. text: lexer.match,
  3559. token: this.terminals_[symbol] || symbol,
  3560. line: lexer.yylineno,
  3561. loc: yyloc,
  3562. expected: expected
  3563. });
  3564. }
  3565. if (action[0] instanceof Array && action.length > 1) {
  3566. throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
  3567. }
  3568. switch (action[0]) {
  3569. case 1:
  3570. stack.push(symbol);
  3571. vstack.push(lexer.yytext);
  3572. lstack.push(lexer.yylloc);
  3573. stack.push(action[1]);
  3574. symbol = null;
  3575. if (!preErrorSymbol) {
  3576. yyleng = lexer.yyleng;
  3577. yytext = lexer.yytext;
  3578. yylineno = lexer.yylineno;
  3579. yyloc = lexer.yylloc;
  3580. if (recovering > 0) {
  3581. recovering--;
  3582. }
  3583. } else {
  3584. symbol = preErrorSymbol;
  3585. preErrorSymbol = null;
  3586. }
  3587. break;
  3588. case 2:
  3589. len = this.productions_[action[1]][1];
  3590. yyval.$ = vstack[vstack.length - len];
  3591. yyval._$ = {
  3592. first_line: lstack[lstack.length - (len || 1)].first_line,
  3593. last_line: lstack[lstack.length - 1].last_line,
  3594. first_column: lstack[lstack.length - (len || 1)].first_column,
  3595. last_column: lstack[lstack.length - 1].last_column
  3596. };
  3597. if (ranges) {
  3598. yyval._$.range = [
  3599. lstack[lstack.length - (len || 1)].range[0],
  3600. lstack[lstack.length - 1].range[1]
  3601. ];
  3602. }
  3603. r = this.performAction.apply(yyval, [
  3604. yytext,
  3605. yyleng,
  3606. yylineno,
  3607. sharedState.yy,
  3608. action[1],
  3609. vstack,
  3610. lstack
  3611. ].concat(args));
  3612. if (typeof r !== 'undefined') {
  3613. return r;
  3614. }
  3615. if (len) {
  3616. stack = stack.slice(0, -1 * len * 2);
  3617. vstack = vstack.slice(0, -1 * len);
  3618. lstack = lstack.slice(0, -1 * len);
  3619. }
  3620. stack.push(this.productions_[action[1]][0]);
  3621. vstack.push(yyval.$);
  3622. lstack.push(yyval._$);
  3623. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  3624. stack.push(newState);
  3625. break;
  3626. case 3:
  3627. return true;
  3628. }
  3629. }
  3630. return true;
  3631. }};
  3632. /* generated by jison-lex 0.3.4 */
  3633. var lexer = (function(){
  3634. var lexer = ({
  3635. EOF:1,
  3636. parseError:function parseError(str, hash) {
  3637. if (this.yy.parser) {
  3638. this.yy.parser.parseError(str, hash);
  3639. } else {
  3640. throw new Error(str);
  3641. }
  3642. },
  3643. // resets the lexer, sets new input
  3644. setInput:function (input, yy) {
  3645. this.yy = yy || this.yy || {};
  3646. this._input = input;
  3647. this._more = this._backtrack = this.done = false;
  3648. this.yylineno = this.yyleng = 0;
  3649. this.yytext = this.matched = this.match = '';
  3650. this.conditionStack = ['INITIAL'];
  3651. this.yylloc = {
  3652. first_line: 1,
  3653. first_column: 0,
  3654. last_line: 1,
  3655. last_column: 0
  3656. };
  3657. if (this.options.ranges) {
  3658. this.yylloc.range = [0,0];
  3659. }
  3660. this.offset = 0;
  3661. return this;
  3662. },
  3663. // consumes and returns one char from the input
  3664. input:function () {
  3665. var ch = this._input[0];
  3666. this.yytext += ch;
  3667. this.yyleng++;
  3668. this.offset++;
  3669. this.match += ch;
  3670. this.matched += ch;
  3671. var lines = ch.match(/(?:\r\n?|\n).*/g);
  3672. if (lines) {
  3673. this.yylineno++;
  3674. this.yylloc.last_line++;
  3675. } else {
  3676. this.yylloc.last_column++;
  3677. }
  3678. if (this.options.ranges) {
  3679. this.yylloc.range[1]++;
  3680. }
  3681. this._input = this._input.slice(1);
  3682. return ch;
  3683. },
  3684. // unshifts one char (or a string) into the input
  3685. unput:function (ch) {
  3686. var len = ch.length;
  3687. var lines = ch.split(/(?:\r\n?|\n)/g);
  3688. this._input = ch + this._input;
  3689. this.yytext = this.yytext.substr(0, this.yytext.length - len);
  3690. //this.yyleng -= len;
  3691. this.offset -= len;
  3692. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  3693. this.match = this.match.substr(0, this.match.length - 1);
  3694. this.matched = this.matched.substr(0, this.matched.length - 1);
  3695. if (lines.length - 1) {
  3696. this.yylineno -= lines.length - 1;
  3697. }
  3698. var r = this.yylloc.range;
  3699. this.yylloc = {
  3700. first_line: this.yylloc.first_line,
  3701. last_line: this.yylineno + 1,
  3702. first_column: this.yylloc.first_column,
  3703. last_column: lines ?
  3704. (lines.length === oldLines.length ? this.yylloc.first_column : 0)
  3705. + oldLines[oldLines.length - lines.length].length - lines[0].length :
  3706. this.yylloc.first_column - len
  3707. };
  3708. if (this.options.ranges) {
  3709. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  3710. }
  3711. this.yyleng = this.yytext.length;
  3712. return this;
  3713. },
  3714. // When called from action, caches matched text and appends it on next action
  3715. more:function () {
  3716. this._more = true;
  3717. return this;
  3718. },
  3719. // 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.
  3720. reject:function () {
  3721. if (this.options.backtrack_lexer) {
  3722. this._backtrack = true;
  3723. } else {
  3724. 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(), {
  3725. text: "",
  3726. token: null,
  3727. line: this.yylineno
  3728. });
  3729. }
  3730. return this;
  3731. },
  3732. // retain first n characters of the match
  3733. less:function (n) {
  3734. this.unput(this.match.slice(n));
  3735. },
  3736. // displays already matched input, i.e. for error messages
  3737. pastInput:function () {
  3738. var past = this.matched.substr(0, this.matched.length - this.match.length);
  3739. return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
  3740. },
  3741. // displays upcoming input, i.e. for error messages
  3742. upcomingInput:function () {
  3743. var next = this.match;
  3744. if (next.length < 20) {
  3745. next += this._input.substr(0, 20-next.length);
  3746. }
  3747. return (next.substr(0,20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
  3748. },
  3749. // displays the character position where the lexing error occurred, i.e. for error messages
  3750. showPosition:function () {
  3751. var pre = this.pastInput();
  3752. var c = new Array(pre.length + 1).join("-");
  3753. return pre + this.upcomingInput() + "\n" + c + "^";
  3754. },
  3755. // test the lexed token: return FALSE when not a match, otherwise return token
  3756. test_match:function (match, indexed_rule) {
  3757. var token,
  3758. lines,
  3759. backup;
  3760. if (this.options.backtrack_lexer) {
  3761. // save context
  3762. backup = {
  3763. yylineno: this.yylineno,
  3764. yylloc: {
  3765. first_line: this.yylloc.first_line,
  3766. last_line: this.last_line,
  3767. first_column: this.yylloc.first_column,
  3768. last_column: this.yylloc.last_column
  3769. },
  3770. yytext: this.yytext,
  3771. match: this.match,
  3772. matches: this.matches,
  3773. matched: this.matched,
  3774. yyleng: this.yyleng,
  3775. offset: this.offset,
  3776. _more: this._more,
  3777. _input: this._input,
  3778. yy: this.yy,
  3779. conditionStack: this.conditionStack.slice(0),
  3780. done: this.done
  3781. };
  3782. if (this.options.ranges) {
  3783. backup.yylloc.range = this.yylloc.range.slice(0);
  3784. }
  3785. }
  3786. lines = match[0].match(/(?:\r\n?|\n).*/g);
  3787. if (lines) {
  3788. this.yylineno += lines.length;
  3789. }
  3790. this.yylloc = {
  3791. first_line: this.yylloc.last_line,
  3792. last_line: this.yylineno + 1,
  3793. first_column: this.yylloc.last_column,
  3794. last_column: lines ?
  3795. lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length :
  3796. this.yylloc.last_column + match[0].length
  3797. };
  3798. this.yytext += match[0];
  3799. this.match += match[0];
  3800. this.matches = match;
  3801. this.yyleng = this.yytext.length;
  3802. if (this.options.ranges) {
  3803. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  3804. }
  3805. this._more = false;
  3806. this._backtrack = false;
  3807. this._input = this._input.slice(match[0].length);
  3808. this.matched += match[0];
  3809. token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
  3810. if (this.done && this._input) {
  3811. this.done = false;
  3812. }
  3813. if (token) {
  3814. return token;
  3815. } else if (this._backtrack) {
  3816. // recover context
  3817. for (var k in backup) {
  3818. this[k] = backup[k];
  3819. }
  3820. return false; // rule action called reject() implying the next rule should be tested instead.
  3821. }
  3822. return false;
  3823. },
  3824. // return next match in input
  3825. next:function () {
  3826. if (this.done) {
  3827. return this.EOF;
  3828. }
  3829. if (!this._input) {
  3830. this.done = true;
  3831. }
  3832. var token,
  3833. match,
  3834. tempMatch,
  3835. index;
  3836. if (!this._more) {
  3837. this.yytext = '';
  3838. this.match = '';
  3839. }
  3840. var rules = this._currentRules();
  3841. for (var i = 0; i < rules.length; i++) {
  3842. tempMatch = this._input.match(this.rules[rules[i]]);
  3843. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  3844. match = tempMatch;
  3845. index = i;
  3846. if (this.options.backtrack_lexer) {
  3847. token = this.test_match(tempMatch, rules[i]);
  3848. if (token !== false) {
  3849. return token;
  3850. } else if (this._backtrack) {
  3851. match = false;
  3852. continue; // rule action called reject() implying a rule MISmatch.
  3853. } else {
  3854. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  3855. return false;
  3856. }
  3857. } else if (!this.options.flex) {
  3858. break;
  3859. }
  3860. }
  3861. }
  3862. if (match) {
  3863. token = this.test_match(match, rules[index]);
  3864. if (token !== false) {
  3865. return token;
  3866. }
  3867. // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
  3868. return false;
  3869. }
  3870. if (this._input === "") {
  3871. return this.EOF;
  3872. } else {
  3873. return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
  3874. text: "",
  3875. token: null,
  3876. line: this.yylineno
  3877. });
  3878. }
  3879. },
  3880. // return next match that has a token
  3881. lex:function lex() {
  3882. var r = this.next();
  3883. if (r) {
  3884. return r;
  3885. } else {
  3886. return this.lex();
  3887. }
  3888. },
  3889. // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
  3890. begin:function begin(condition) {
  3891. this.conditionStack.push(condition);
  3892. },
  3893. // pop the previously active lexer condition state off the condition stack
  3894. popState:function popState() {
  3895. var n = this.conditionStack.length - 1;
  3896. if (n > 0) {
  3897. return this.conditionStack.pop();
  3898. } else {
  3899. return this.conditionStack[0];
  3900. }
  3901. },
  3902. // produce the lexer rule set which is active for the currently active lexer condition state
  3903. _currentRules:function _currentRules() {
  3904. if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
  3905. return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
  3906. } else {
  3907. return this.conditions["INITIAL"].rules;
  3908. }
  3909. },
  3910. // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
  3911. topState:function topState(n) {
  3912. n = this.conditionStack.length - 1 - Math.abs(n || 0);
  3913. if (n >= 0) {
  3914. return this.conditionStack[n];
  3915. } else {
  3916. return "INITIAL";
  3917. }
  3918. },
  3919. // alias for begin(condition)
  3920. pushState:function pushState(condition) {
  3921. this.begin(condition);
  3922. },
  3923. // return the number of states currently on the stack
  3924. stateStackSize:function stateStackSize() {
  3925. return this.conditionStack.length;
  3926. },
  3927. options: {},
  3928. performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
  3929. var YYSTATE=YY_START;
  3930. switch($avoiding_name_collisions) {
  3931. case 0:return 5
  3932. break;
  3933. case 1:/* skip whitespace */
  3934. break;
  3935. case 2:return 8
  3936. break;
  3937. case 3:return 16
  3938. break;
  3939. case 4:return 17
  3940. break;
  3941. case 5:return 11
  3942. break;
  3943. case 6:return 10
  3944. break;
  3945. case 7:return 9
  3946. break;
  3947. case 8:return 14
  3948. break;
  3949. case 9:return 15
  3950. break;
  3951. case 10:return 12
  3952. break;
  3953. case 11:return 7
  3954. break;
  3955. case 12:return 7
  3956. break;
  3957. case 13:return 7
  3958. break;
  3959. case 14:return 7
  3960. break;
  3961. case 15:return 7
  3962. break;
  3963. case 16:return 7
  3964. break;
  3965. case 17:return 7
  3966. break;
  3967. case 18:return 7
  3968. break;
  3969. case 19:return 7
  3970. break;
  3971. case 20:return 7
  3972. break;
  3973. case 21:return 7
  3974. break;
  3975. case 22:return 7
  3976. break;
  3977. case 23:return 7
  3978. break;
  3979. case 24:return 13
  3980. break;
  3981. case 25:return 13
  3982. break;
  3983. case 26:return 13
  3984. break;
  3985. case 27:return 13
  3986. break;
  3987. case 28:return 13
  3988. break;
  3989. case 29:return 13
  3990. break;
  3991. case 30:return 13
  3992. break;
  3993. case 31:return 13
  3994. break;
  3995. case 32:return 7
  3996. break;
  3997. case 33:return 13
  3998. break;
  3999. case 34:return 7
  4000. break;
  4001. case 35:return 13
  4002. break;
  4003. case 36:return 7
  4004. break;
  4005. case 37:return 13
  4006. break;
  4007. case 38:return 13
  4008. break;
  4009. case 39:return 7
  4010. break;
  4011. case 40:return 13
  4012. break;
  4013. case 41:return 13
  4014. break;
  4015. case 42:return 13
  4016. break;
  4017. case 43:return 13
  4018. break;
  4019. case 44:return 13
  4020. break;
  4021. case 45:return 7
  4022. break;
  4023. case 46:return 13
  4024. break;
  4025. case 47:return 7
  4026. break;
  4027. case 48:return 7
  4028. break;
  4029. case 49:return 7
  4030. break;
  4031. case 50:return 7
  4032. break;
  4033. case 51:return 7
  4034. break;
  4035. case 52:return 7
  4036. break;
  4037. case 53:return 7
  4038. break;
  4039. case 54:return 7
  4040. break;
  4041. case 55:return 7
  4042. break;
  4043. case 56:return 7
  4044. break;
  4045. case 57:return 7
  4046. break;
  4047. case 58:return 7
  4048. break;
  4049. case 59:return 7
  4050. break;
  4051. case 60:return 7
  4052. break;
  4053. case 61:return 7
  4054. break;
  4055. case 62:return 7
  4056. break;
  4057. case 63:return 13
  4058. break;
  4059. case 64:return 7
  4060. break;
  4061. case 65:return 7
  4062. break;
  4063. case 66:return 13
  4064. break;
  4065. case 67:return 7
  4066. break;
  4067. case 68:return 7
  4068. break;
  4069. case 69:return 7
  4070. break;
  4071. case 70:return 7
  4072. break;
  4073. case 71:return 7
  4074. break;
  4075. case 72:return 7
  4076. break;
  4077. case 73:return 13
  4078. break;
  4079. case 74:return 7
  4080. break;
  4081. case 75:return 13
  4082. break;
  4083. case 76:return 7
  4084. break;
  4085. case 77:return 7
  4086. break;
  4087. case 78:return 7
  4088. break;
  4089. case 79:return 7
  4090. break;
  4091. case 80:return 7
  4092. break;
  4093. case 81:return 7
  4094. break;
  4095. case 82:return 7
  4096. break;
  4097. case 83:return 7
  4098. break;
  4099. case 84:return 7
  4100. break;
  4101. case 85:return 7
  4102. break;
  4103. case 86:return 7
  4104. break;
  4105. case 87:return 7
  4106. break;
  4107. case 88:return 7
  4108. break;
  4109. case 89:return 7
  4110. break;
  4111. case 90:return 7
  4112. break;
  4113. case 91:return 7
  4114. break;
  4115. case 92:return 7
  4116. break;
  4117. case 93:return 7
  4118. break;
  4119. case 94:return 7
  4120. break;
  4121. case 95:return 7
  4122. break;
  4123. case 96:return 7
  4124. break;
  4125. case 97:return 7
  4126. break;
  4127. case 98:return 7
  4128. break;
  4129. case 99:return 7
  4130. break;
  4131. case 100:return 7
  4132. break;
  4133. case 101:return 7
  4134. break;
  4135. case 102:return 7
  4136. break;
  4137. case 103:return 7
  4138. break;
  4139. case 104:return 7
  4140. break;
  4141. case 105:return 7
  4142. break;
  4143. case 106:return 7
  4144. break;
  4145. case 107:return 7
  4146. break;
  4147. case 108:return 7
  4148. break;
  4149. case 109:return 7
  4150. break;
  4151. case 110:return 7
  4152. break;
  4153. case 111:return 7
  4154. break;
  4155. case 112:return 7
  4156. break;
  4157. case 113:return 7
  4158. break;
  4159. case 114:return 7
  4160. break;
  4161. case 115:return 7
  4162. break;
  4163. case 116:return 7
  4164. break;
  4165. case 117:return 7
  4166. break;
  4167. case 118:return 7
  4168. break;
  4169. case 119:return 7
  4170. break;
  4171. case 120:return 7
  4172. break;
  4173. case 121:return 7
  4174. break;
  4175. case 122:return 7
  4176. break;
  4177. case 123:return 7
  4178. break;
  4179. case 124:return 7
  4180. break;
  4181. case 125:return 7
  4182. break;
  4183. case 126:return 7
  4184. break;
  4185. case 127:return 7
  4186. break;
  4187. case 128:return 7
  4188. break;
  4189. case 129:return 7
  4190. break;
  4191. case 130:return 7
  4192. break;
  4193. case 131:return 7
  4194. break;
  4195. case 132:return 7
  4196. break;
  4197. case 133:return 7
  4198. break;
  4199. case 134:return 7
  4200. break;
  4201. case 135:return 7
  4202. break;
  4203. case 136:return 7
  4204. break;
  4205. case 137:return 7
  4206. break;
  4207. case 138:return 7
  4208. break;
  4209. case 139:return 7
  4210. break;
  4211. case 140:return 7
  4212. break;
  4213. case 141:return 7
  4214. break;
  4215. case 142:return 7
  4216. break;
  4217. case 143:return 7
  4218. break;
  4219. case 144:return 7
  4220. break;
  4221. case 145:return 7
  4222. break;
  4223. case 146:return 7
  4224. break;
  4225. case 147:return 7
  4226. break;
  4227. case 148:return 7
  4228. break;
  4229. case 149:return 7
  4230. break;
  4231. case 150:return 7
  4232. break;
  4233. case 151:return 7
  4234. break;
  4235. case 152:return 7
  4236. break;
  4237. case 153:return 7
  4238. break;
  4239. case 154:return 7
  4240. break;
  4241. case 155:return 7
  4242. break;
  4243. case 156:return 7
  4244. break;
  4245. case 157:return 7
  4246. break;
  4247. case 158:return 7
  4248. break;
  4249. case 159:return 7
  4250. break;
  4251. case 160:return 7
  4252. break;
  4253. case 161:return 7
  4254. break;
  4255. case 162:return 7
  4256. break;
  4257. case 163:return 7
  4258. break;
  4259. case 164:return 7
  4260. break;
  4261. case 165:return 7
  4262. break;
  4263. case 166:return 7
  4264. break;
  4265. case 167:return 7
  4266. break;
  4267. case 168:return 7
  4268. break;
  4269. case 169:return 7
  4270. break;
  4271. case 170:return 7
  4272. break;
  4273. case 171:return 7
  4274. break;
  4275. case 172:return 7
  4276. break;
  4277. case 173:return 7
  4278. break;
  4279. case 174:return 7
  4280. break;
  4281. case 175:return 7
  4282. break;
  4283. case 176:return 7
  4284. break;
  4285. case 177:return 7
  4286. break;
  4287. case 178:return 7
  4288. break;
  4289. case 179:return 7
  4290. break;
  4291. case 180:return 7
  4292. break;
  4293. case 181:return 7
  4294. break;
  4295. case 182:return 7
  4296. break;
  4297. case 183:return 7
  4298. break;
  4299. case 184:return 7
  4300. break;
  4301. case 185:return 7
  4302. break;
  4303. case 186:return 7
  4304. break;
  4305. case 187:return 7
  4306. break;
  4307. case 188:return 7
  4308. break;
  4309. case 189:return 7
  4310. break;
  4311. case 190:return 7
  4312. break;
  4313. case 191:return 7
  4314. break;
  4315. case 192:return 7
  4316. break;
  4317. case 193:return 7
  4318. break;
  4319. case 194:return 7
  4320. break;
  4321. case 195:return 7
  4322. break;
  4323. case 196:return 7
  4324. break;
  4325. case 197:return 7
  4326. break;
  4327. case 198:return 7
  4328. break;
  4329. case 199:return 7
  4330. break;
  4331. case 200:return 7
  4332. break;
  4333. case 201:return 7
  4334. break;
  4335. case 202:return 7
  4336. break;
  4337. case 203:return 7
  4338. break;
  4339. case 204:return 7
  4340. break;
  4341. case 205:return 7
  4342. break;
  4343. case 206:return 7
  4344. break;
  4345. case 207:return 7
  4346. break;
  4347. case 208:return 7
  4348. break;
  4349. case 209:return 7
  4350. break;
  4351. case 210:return 7
  4352. break;
  4353. case 211:return 7
  4354. break;
  4355. case 212:return 7
  4356. break;
  4357. case 213:return 7
  4358. break;
  4359. case 214:return 7
  4360. break;
  4361. case 215:return 7
  4362. break;
  4363. case 216:return 7
  4364. break;
  4365. case 217:return 7
  4366. break;
  4367. case 218:return 7
  4368. break;
  4369. case 219:return 7
  4370. break;
  4371. case 220:return 7
  4372. break;
  4373. case 221:return 7
  4374. break;
  4375. case 222:return 7
  4376. break;
  4377. case 223:return 7
  4378. break;
  4379. case 224:return 7
  4380. break;
  4381. case 225:return 7
  4382. break;
  4383. case 226:return 7
  4384. break;
  4385. case 227:return 7
  4386. break;
  4387. case 228:return 7
  4388. break;
  4389. case 229:return 7
  4390. break;
  4391. case 230:return 7
  4392. break;
  4393. case 231:return 7
  4394. break;
  4395. case 232:return 7
  4396. break;
  4397. case 233:return 7
  4398. break;
  4399. case 234:return 7
  4400. break;
  4401. case 235:return 7
  4402. break;
  4403. case 236:return 7
  4404. break;
  4405. case 237:return 7
  4406. break;
  4407. case 238:return 7
  4408. break;
  4409. case 239:return 7
  4410. break;
  4411. case 240:return 7
  4412. break;
  4413. case 241:return 7
  4414. break;
  4415. case 242:return 7
  4416. break;
  4417. case 243:return 7
  4418. break;
  4419. case 244:return 7
  4420. break;
  4421. case 245:return 7
  4422. break;
  4423. case 246:return 7
  4424. break;
  4425. case 247:return 7
  4426. break;
  4427. case 248:return 7
  4428. break;
  4429. case 249:return 7
  4430. break;
  4431. case 250:return 7
  4432. break;
  4433. case 251:return 7
  4434. break;
  4435. case 252:return 7
  4436. break;
  4437. case 253:return 7
  4438. break;
  4439. case 254:return 7
  4440. break;
  4441. case 255:return 7
  4442. break;
  4443. case 256:return 7
  4444. break;
  4445. case 257:return 7
  4446. break;
  4447. case 258:return 7
  4448. break;
  4449. case 259:return 7
  4450. break;
  4451. case 260:return 7
  4452. break;
  4453. case 261:return 7
  4454. break;
  4455. case 262:return 7
  4456. break;
  4457. case 263:return 7
  4458. break;
  4459. case 264:return 7
  4460. break;
  4461. case 265:return 7
  4462. break;
  4463. case 266:return 7
  4464. break;
  4465. case 267:return 7
  4466. break;
  4467. case 268:return 7
  4468. break;
  4469. case 269:return 7
  4470. break;
  4471. case 270:return 7
  4472. break;
  4473. case 271:return 7
  4474. break;
  4475. case 272:return 7
  4476. break;
  4477. case 273:return 7
  4478. break;
  4479. case 274:return 7
  4480. break;
  4481. case 275:return 7
  4482. break;
  4483. case 276:return 7
  4484. break;
  4485. case 277:return 7
  4486. break;
  4487. case 278:return 7
  4488. break;
  4489. case 279:return 7
  4490. break;
  4491. case 280:return 7
  4492. break;
  4493. case 281:return 7
  4494. break;
  4495. case 282:return 7
  4496. break;
  4497. case 283:return 7
  4498. break;
  4499. case 284:return 7
  4500. break;
  4501. case 285:return 7
  4502. break;
  4503. case 286:return 7
  4504. break;
  4505. case 287:return 7
  4506. break;
  4507. case 288:return 7
  4508. break;
  4509. case 289:return 7
  4510. break;
  4511. case 290:return 7
  4512. break;
  4513. case 291:return 7
  4514. break;
  4515. case 292:return 7
  4516. break;
  4517. case 293:return 7
  4518. break;
  4519. case 294:return 7
  4520. break;
  4521. case 295:return 7
  4522. break;
  4523. case 296:return 7
  4524. break;
  4525. case 297:return 7
  4526. break;
  4527. case 298:return 7
  4528. break;
  4529. case 299:return 7
  4530. break;
  4531. case 300:return 7
  4532. break;
  4533. case 301:return 7
  4534. break;
  4535. case 302:return 7
  4536. break;
  4537. case 303:return 7
  4538. break;
  4539. case 304:return 7
  4540. break;
  4541. case 305:return 7
  4542. break;
  4543. case 306:return 7
  4544. break;
  4545. case 307:return 7
  4546. break;
  4547. case 308:return 7
  4548. break;
  4549. case 309:return 7
  4550. break;
  4551. case 310:return 7
  4552. break;
  4553. case 311:return 7
  4554. break;
  4555. case 312:return 7
  4556. break;
  4557. case 313:return 7
  4558. break;
  4559. case 314:return 7
  4560. break;
  4561. case 315:return 7
  4562. break;
  4563. case 316:return 7
  4564. break;
  4565. case 317:return 7
  4566. break;
  4567. case 318:return 7
  4568. break;
  4569. case 319:return 7
  4570. break;
  4571. case 320:return 7
  4572. break;
  4573. case 321:return 7
  4574. break;
  4575. case 322:return 7
  4576. break;
  4577. case 323:return 7
  4578. break;
  4579. case 324:return 7
  4580. break;
  4581. case 325:return 7
  4582. break;
  4583. case 326:return 7
  4584. break;
  4585. case 327:return 7
  4586. break;
  4587. case 328:return 7
  4588. break;
  4589. case 329:return 7
  4590. break;
  4591. case 330:return 7
  4592. break;
  4593. case 331:return 7
  4594. break;
  4595. case 332:return 7
  4596. break;
  4597. case 333:return 7
  4598. break;
  4599. case 334:return 7
  4600. break;
  4601. case 335:return 7
  4602. break;
  4603. case 336:return 7
  4604. break;
  4605. case 337:return 7
  4606. break;
  4607. case 338:return 7
  4608. break;
  4609. case 339:return 7
  4610. break;
  4611. case 340:return 7
  4612. break;
  4613. case 341:return 7
  4614. break;
  4615. case 342:return 7
  4616. break;
  4617. case 343:return 7
  4618. break;
  4619. case 344:return 7
  4620. break;
  4621. case 345:return 7
  4622. break;
  4623. case 346:return 7
  4624. break;
  4625. case 347:return 7
  4626. break;
  4627. case 348:return 7
  4628. break;
  4629. case 349:return 7
  4630. break;
  4631. case 350:return 7
  4632. break;
  4633. case 351:return 7
  4634. break;
  4635. case 352:return 7
  4636. break;
  4637. case 353:return 7
  4638. break;
  4639. case 354:return 7
  4640. break;
  4641. case 355:return 7
  4642. break;
  4643. case 356:return 7
  4644. break;
  4645. case 357:return 7
  4646. break;
  4647. case 358:return 7
  4648. break;
  4649. case 359:return 7
  4650. break;
  4651. case 360:return 7
  4652. break;
  4653. case 361:return 7
  4654. break;
  4655. case 362:return 7
  4656. break;
  4657. case 363:return 7
  4658. break;
  4659. case 364:return 7
  4660. break;
  4661. }
  4662. },
  4663. 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)/],
  4664. 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}}
  4665. });
  4666. return lexer;
  4667. })();
  4668. parser.lexer = lexer;
  4669. function Parser () {
  4670. this.yy = {};
  4671. }
  4672. Parser.prototype = parser;parser.Parser = Parser;
  4673. return new Parser;
  4674. })();
  4675. if (typeof commonjsRequire !== 'undefined' && 'object' !== 'undefined') {
  4676. exports.parser = spdxparse;
  4677. exports.Parser = spdxparse.Parser;
  4678. exports.parse = function () { return spdxparse.parse.apply(spdxparse, arguments); };
  4679. exports.main = function commonjsMain(args) {
  4680. if (!args[1]) {
  4681. console.log('Usage: '+args[0]+' FILE');
  4682. process.exit(1);
  4683. }
  4684. var source = fs.readFileSync(path.normalize(args[1]), "utf8");
  4685. return exports.parser.parse(source);
  4686. };
  4687. if ('object' !== 'undefined' && commonjsRequire.main === module) {
  4688. exports.main(process.argv.slice(1));
  4689. }
  4690. }
  4691. });
  4692. var parser = parser$1.parser;
  4693. var spdxExpressionParse = function (argument) {
  4694. return parser.parse(argument)
  4695. };
  4696. var spdxLicenseIds = [
  4697. "Glide",
  4698. "Abstyles",
  4699. "AFL-1.1",
  4700. "AFL-1.2",
  4701. "AFL-2.0",
  4702. "AFL-2.1",
  4703. "AFL-3.0",
  4704. "AMPAS",
  4705. "APL-1.0",
  4706. "Adobe-Glyph",
  4707. "APAFML",
  4708. "Adobe-2006",
  4709. "AGPL-1.0",
  4710. "Afmparse",
  4711. "Aladdin",
  4712. "ADSL",
  4713. "AMDPLPA",
  4714. "ANTLR-PD",
  4715. "Apache-1.0",
  4716. "Apache-1.1",
  4717. "Apache-2.0",
  4718. "AML",
  4719. "APSL-1.0",
  4720. "APSL-1.1",
  4721. "APSL-1.2",
  4722. "APSL-2.0",
  4723. "Artistic-1.0",
  4724. "Artistic-1.0-Perl",
  4725. "Artistic-1.0-cl8",
  4726. "Artistic-2.0",
  4727. "AAL",
  4728. "Bahyph",
  4729. "Barr",
  4730. "Beerware",
  4731. "BitTorrent-1.0",
  4732. "BitTorrent-1.1",
  4733. "BSL-1.0",
  4734. "Borceux",
  4735. "BSD-2-Clause",
  4736. "BSD-2-Clause-FreeBSD",
  4737. "BSD-2-Clause-NetBSD",
  4738. "BSD-3-Clause",
  4739. "BSD-3-Clause-Clear",
  4740. "BSD-4-Clause",
  4741. "BSD-Protection",
  4742. "BSD-Source-Code",
  4743. "BSD-3-Clause-Attribution",
  4744. "0BSD",
  4745. "BSD-4-Clause-UC",
  4746. "bzip2-1.0.5",
  4747. "bzip2-1.0.6",
  4748. "Caldera",
  4749. "CECILL-1.0",
  4750. "CECILL-1.1",
  4751. "CECILL-2.0",
  4752. "CECILL-2.1",
  4753. "CECILL-B",
  4754. "CECILL-C",
  4755. "ClArtistic",
  4756. "MIT-CMU",
  4757. "CNRI-Jython",
  4758. "CNRI-Python",
  4759. "CNRI-Python-GPL-Compatible",
  4760. "CPOL-1.02",
  4761. "CDDL-1.0",
  4762. "CDDL-1.1",
  4763. "CPAL-1.0",
  4764. "CPL-1.0",
  4765. "CATOSL-1.1",
  4766. "Condor-1.1",
  4767. "CC-BY-1.0",
  4768. "CC-BY-2.0",
  4769. "CC-BY-2.5",
  4770. "CC-BY-3.0",
  4771. "CC-BY-4.0",
  4772. "CC-BY-ND-1.0",
  4773. "CC-BY-ND-2.0",
  4774. "CC-BY-ND-2.5",
  4775. "CC-BY-ND-3.0",
  4776. "CC-BY-ND-4.0",
  4777. "CC-BY-NC-1.0",
  4778. "CC-BY-NC-2.0",
  4779. "CC-BY-NC-2.5",
  4780. "CC-BY-NC-3.0",
  4781. "CC-BY-NC-4.0",
  4782. "CC-BY-NC-ND-1.0",
  4783. "CC-BY-NC-ND-2.0",
  4784. "CC-BY-NC-ND-2.5",
  4785. "CC-BY-NC-ND-3.0",
  4786. "CC-BY-NC-ND-4.0",
  4787. "CC-BY-NC-SA-1.0",
  4788. "CC-BY-NC-SA-2.0",
  4789. "CC-BY-NC-SA-2.5",
  4790. "CC-BY-NC-SA-3.0",
  4791. "CC-BY-NC-SA-4.0",
  4792. "CC-BY-SA-1.0",
  4793. "CC-BY-SA-2.0",
  4794. "CC-BY-SA-2.5",
  4795. "CC-BY-SA-3.0",
  4796. "CC-BY-SA-4.0",
  4797. "CC0-1.0",
  4798. "Crossword",
  4799. "CrystalStacker",
  4800. "CUA-OPL-1.0",
  4801. "Cube",
  4802. "curl",
  4803. "D-FSL-1.0",
  4804. "diffmark",
  4805. "WTFPL",
  4806. "DOC",
  4807. "Dotseqn",
  4808. "DSDP",
  4809. "dvipdfm",
  4810. "EPL-1.0",
  4811. "ECL-1.0",
  4812. "ECL-2.0",
  4813. "eGenix",
  4814. "EFL-1.0",
  4815. "EFL-2.0",
  4816. "MIT-advertising",
  4817. "MIT-enna",
  4818. "Entessa",
  4819. "ErlPL-1.1",
  4820. "EUDatagrid",
  4821. "EUPL-1.0",
  4822. "EUPL-1.1",
  4823. "Eurosym",
  4824. "Fair",
  4825. "MIT-feh",
  4826. "Frameworx-1.0",
  4827. "FreeImage",
  4828. "FTL",
  4829. "FSFAP",
  4830. "FSFUL",
  4831. "FSFULLR",
  4832. "Giftware",
  4833. "GL2PS",
  4834. "Glulxe",
  4835. "AGPL-3.0",
  4836. "GFDL-1.1",
  4837. "GFDL-1.2",
  4838. "GFDL-1.3",
  4839. "GPL-1.0",
  4840. "GPL-2.0",
  4841. "GPL-3.0",
  4842. "LGPL-2.1",
  4843. "LGPL-3.0",
  4844. "LGPL-2.0",
  4845. "gnuplot",
  4846. "gSOAP-1.3b",
  4847. "HaskellReport",
  4848. "HPND",
  4849. "IBM-pibs",
  4850. "IPL-1.0",
  4851. "ICU",
  4852. "ImageMagick",
  4853. "iMatix",
  4854. "Imlib2",
  4855. "IJG",
  4856. "Info-ZIP",
  4857. "Intel-ACPI",
  4858. "Intel",
  4859. "Interbase-1.0",
  4860. "IPA",
  4861. "ISC",
  4862. "JasPer-2.0",
  4863. "JSON",
  4864. "LPPL-1.0",
  4865. "LPPL-1.1",
  4866. "LPPL-1.2",
  4867. "LPPL-1.3a",
  4868. "LPPL-1.3c",
  4869. "Latex2e",
  4870. "BSD-3-Clause-LBNL",
  4871. "Leptonica",
  4872. "LGPLLR",
  4873. "Libpng",
  4874. "libtiff",
  4875. "LAL-1.2",
  4876. "LAL-1.3",
  4877. "LiLiQ-P-1.1",
  4878. "LiLiQ-Rplus-1.1",
  4879. "LiLiQ-R-1.1",
  4880. "LPL-1.02",
  4881. "LPL-1.0",
  4882. "MakeIndex",
  4883. "MTLL",
  4884. "MS-PL",
  4885. "MS-RL",
  4886. "MirOS",
  4887. "MITNFA",
  4888. "MIT",
  4889. "Motosoto",
  4890. "MPL-1.0",
  4891. "MPL-1.1",
  4892. "MPL-2.0",
  4893. "MPL-2.0-no-copyleft-exception",
  4894. "mpich2",
  4895. "Multics",
  4896. "Mup",
  4897. "NASA-1.3",
  4898. "Naumen",
  4899. "NBPL-1.0",
  4900. "NetCDF",
  4901. "NGPL",
  4902. "NOSL",
  4903. "NPL-1.0",
  4904. "NPL-1.1",
  4905. "Newsletr",
  4906. "NLPL",
  4907. "Nokia",
  4908. "NPOSL-3.0",
  4909. "NLOD-1.0",
  4910. "Noweb",
  4911. "NRL",
  4912. "NTP",
  4913. "Nunit",
  4914. "OCLC-2.0",
  4915. "ODbL-1.0",
  4916. "PDDL-1.0",
  4917. "OCCT-PL",
  4918. "OGTSL",
  4919. "OLDAP-2.2.2",
  4920. "OLDAP-1.1",
  4921. "OLDAP-1.2",
  4922. "OLDAP-1.3",
  4923. "OLDAP-1.4",
  4924. "OLDAP-2.0",
  4925. "OLDAP-2.0.1",
  4926. "OLDAP-2.1",
  4927. "OLDAP-2.2",
  4928. "OLDAP-2.2.1",
  4929. "OLDAP-2.3",
  4930. "OLDAP-2.4",
  4931. "OLDAP-2.5",
  4932. "OLDAP-2.6",
  4933. "OLDAP-2.7",
  4934. "OLDAP-2.8",
  4935. "OML",
  4936. "OPL-1.0",
  4937. "OSL-1.0",
  4938. "OSL-1.1",
  4939. "OSL-2.0",
  4940. "OSL-2.1",
  4941. "OSL-3.0",
  4942. "OpenSSL",
  4943. "OSET-PL-2.1",
  4944. "PHP-3.0",
  4945. "PHP-3.01",
  4946. "Plexus",
  4947. "PostgreSQL",
  4948. "psfrag",
  4949. "psutils",
  4950. "Python-2.0",
  4951. "QPL-1.0",
  4952. "Qhull",
  4953. "Rdisc",
  4954. "RPSL-1.0",
  4955. "RPL-1.1",
  4956. "RPL-1.5",
  4957. "RHeCos-1.1",
  4958. "RSCPL",
  4959. "RSA-MD",
  4960. "Ruby",
  4961. "SAX-PD",
  4962. "Saxpath",
  4963. "SCEA",
  4964. "SWL",
  4965. "SMPPL",
  4966. "Sendmail",
  4967. "SGI-B-1.0",
  4968. "SGI-B-1.1",
  4969. "SGI-B-2.0",
  4970. "OFL-1.0",
  4971. "OFL-1.1",
  4972. "SimPL-2.0",
  4973. "Sleepycat",
  4974. "SNIA",
  4975. "Spencer-86",
  4976. "Spencer-94",
  4977. "Spencer-99",
  4978. "SMLNJ",
  4979. "SugarCRM-1.1.3",
  4980. "SISSL",
  4981. "SISSL-1.2",
  4982. "SPL-1.0",
  4983. "Watcom-1.0",
  4984. "TCL",
  4985. "Unlicense",
  4986. "TMate",
  4987. "TORQUE-1.1",
  4988. "TOSL",
  4989. "Unicode-TOU",
  4990. "UPL-1.0",
  4991. "NCSA",
  4992. "Vim",
  4993. "VOSTROM",
  4994. "VSL-1.0",
  4995. "W3C-19980720",
  4996. "W3C",
  4997. "Wsuipa",
  4998. "Xnet",
  4999. "X11",
  5000. "Xerox",
  5001. "XFree86-1.1",
  5002. "xinetd",
  5003. "xpp",
  5004. "XSkat",
  5005. "YPL-1.0",
  5006. "YPL-1.1",
  5007. "Zed",
  5008. "Zend-2.0",
  5009. "Zimbra-1.3",
  5010. "Zimbra-1.4",
  5011. "Zlib",
  5012. "zlib-acknowledgement",
  5013. "ZPL-1.1",
  5014. "ZPL-2.0",
  5015. "ZPL-2.1",
  5016. "BSD-3-Clause-No-Nuclear-License",
  5017. "BSD-3-Clause-No-Nuclear-Warranty",
  5018. "BSD-3-Clause-No-Nuclear-License-2014",
  5019. "eCos-2.0",
  5020. "GPL-2.0-with-autoconf-exception",
  5021. "GPL-2.0-with-bison-exception",
  5022. "GPL-2.0-with-classpath-exception",
  5023. "GPL-2.0-with-font-exception",
  5024. "GPL-2.0-with-GCC-exception",
  5025. "GPL-3.0-with-autoconf-exception",
  5026. "GPL-3.0-with-GCC-exception",
  5027. "StandardML-NJ",
  5028. "WXwindows"
  5029. ]
  5030. ;
  5031. var spdxLicenseIds$1 = Object.freeze({
  5032. default: spdxLicenseIds
  5033. });
  5034. var licenseIDs = ( spdxLicenseIds$1 && spdxLicenseIds ) || spdxLicenseIds$1;
  5035. function valid(string) {
  5036. return licenseIDs.indexOf(string) > -1;
  5037. }
  5038. // Common transpositions of license identifier acronyms
  5039. var transpositions = [
  5040. ['APGL', 'AGPL'],
  5041. ['Gpl', 'GPL'],
  5042. ['GLP', 'GPL'],
  5043. ['APL', 'Apache'],
  5044. ['ISD', 'ISC'],
  5045. ['GLP', 'GPL'],
  5046. ['IST', 'ISC'],
  5047. ['Claude', 'Clause'],
  5048. [' or later', '+'],
  5049. [' International', ''],
  5050. ['GNU', 'GPL'],
  5051. ['GUN', 'GPL'],
  5052. ['+', ''],
  5053. ['GNU GPL', 'GPL'],
  5054. ['GNU/GPL', 'GPL'],
  5055. ['GNU GLP', 'GPL'],
  5056. ['GNU General Public License', 'GPL'],
  5057. ['Gnu public license', 'GPL'],
  5058. ['GNU Public License', 'GPL'],
  5059. ['GNU GENERAL PUBLIC LICENSE', 'GPL'],
  5060. ['MTI', 'MIT'],
  5061. ['Mozilla Public License', 'MPL'],
  5062. ['WTH', 'WTF'],
  5063. ['-License', '']
  5064. ];
  5065. var TRANSPOSED = 0;
  5066. var CORRECT = 1;
  5067. // Simple corrections to nearly valid identifiers.
  5068. var transforms = [
  5069. // e.g. 'mit'
  5070. function(argument) {
  5071. return argument.toUpperCase();
  5072. },
  5073. // e.g. 'MIT '
  5074. function(argument) {
  5075. return argument.trim();
  5076. },
  5077. // e.g. 'M.I.T.'
  5078. function(argument) {
  5079. return argument.replace(/\./g, '');
  5080. },
  5081. // e.g. 'Apache- 2.0'
  5082. function(argument) {
  5083. return argument.replace(/\s+/g, '');
  5084. },
  5085. // e.g. 'CC BY 4.0''
  5086. function(argument) {
  5087. return argument.replace(/\s+/g, '-');
  5088. },
  5089. // e.g. 'LGPLv2.1'
  5090. function(argument) {
  5091. return argument.replace('v', '-');
  5092. },
  5093. // e.g. 'Apache 2.0'
  5094. function(argument) {
  5095. return argument.replace(/,?\s*(\d)/, '-$1');
  5096. },
  5097. // e.g. 'GPL 2'
  5098. function(argument) {
  5099. return argument.replace(/,?\s*(\d)/, '-$1.0');
  5100. },
  5101. // e.g. 'Apache Version 2.0'
  5102. function(argument) {
  5103. return argument.replace(/,?\s*(V\.|v\.|V|v|Version|version)\s*(\d)/, '-$2');
  5104. },
  5105. // e.g. 'Apache Version 2'
  5106. function(argument) {
  5107. return argument.replace(/,?\s*(V\.|v\.|V|v|Version|version)\s*(\d)/, '-$2.0');
  5108. },
  5109. // e.g. 'ZLIB'
  5110. function(argument) {
  5111. return argument[0].toUpperCase() + argument.slice(1);
  5112. },
  5113. // e.g. 'MPL/2.0'
  5114. function(argument) {
  5115. return argument.replace('/', '-');
  5116. },
  5117. // e.g. 'Apache 2'
  5118. function(argument) {
  5119. return argument
  5120. .replace(/\s*V\s*(\d)/, '-$1')
  5121. .replace(/(\d)$/, '$1.0');
  5122. },
  5123. // e.g. 'GPL-2.0-'
  5124. function(argument) {
  5125. return argument.slice(0, argument.length - 1);
  5126. },
  5127. // e.g. 'GPL2'
  5128. function(argument) {
  5129. return argument.replace(/(\d)$/, '-$1.0');
  5130. },
  5131. // e.g. 'BSD 3'
  5132. function(argument) {
  5133. return argument.replace(/(-| )?(\d)$/, '-$2-Clause');
  5134. },
  5135. // e.g. 'BSD clause 3'
  5136. function(argument) {
  5137. return argument.replace(/(-| )clause(-| )(\d)/, '-$3-Clause');
  5138. },
  5139. // e.g. 'BY-NC-4.0'
  5140. function(argument) {
  5141. return 'CC-' + argument;
  5142. },
  5143. // e.g. 'BY-NC'
  5144. function(argument) {
  5145. return 'CC-' + argument + '-4.0';
  5146. },
  5147. // e.g. 'Attribution-NonCommercial'
  5148. function(argument) {
  5149. return argument
  5150. .replace('Attribution', 'BY')
  5151. .replace('NonCommercial', 'NC')
  5152. .replace('NoDerivatives', 'ND')
  5153. .replace(/ (\d)/, '-$1')
  5154. .replace(/ ?International/, '');
  5155. },
  5156. // e.g. 'Attribution-NonCommercial'
  5157. function(argument) {
  5158. return 'CC-' +
  5159. argument
  5160. .replace('Attribution', 'BY')
  5161. .replace('NonCommercial', 'NC')
  5162. .replace('NoDerivatives', 'ND')
  5163. .replace(/ (\d)/, '-$1')
  5164. .replace(/ ?International/, '') +
  5165. '-4.0';
  5166. }
  5167. ];
  5168. // If all else fails, guess that strings containing certain substrings
  5169. // meant to identify certain licenses.
  5170. var lastResorts = [
  5171. ['UNLI', 'Unlicense'],
  5172. ['WTF', 'WTFPL'],
  5173. ['2 CLAUSE', 'BSD-2-Clause'],
  5174. ['2-CLAUSE', 'BSD-2-Clause'],
  5175. ['3 CLAUSE', 'BSD-3-Clause'],
  5176. ['3-CLAUSE', 'BSD-3-Clause'],
  5177. ['AFFERO', 'AGPL-3.0'],
  5178. ['AGPL', 'AGPL-3.0'],
  5179. ['APACHE', 'Apache-2.0'],
  5180. ['ARTISTIC', 'Artistic-2.0'],
  5181. ['Affero', 'AGPL-3.0'],
  5182. ['BEER', 'Beerware'],
  5183. ['BOOST', 'BSL-1.0'],
  5184. ['BSD', 'BSD-2-Clause'],
  5185. ['ECLIPSE', 'EPL-1.0'],
  5186. ['FUCK', 'WTFPL'],
  5187. ['GNU', 'GPL-3.0'],
  5188. ['LGPL', 'LGPL-3.0'],
  5189. ['GPL', 'GPL-3.0'],
  5190. ['MIT', 'MIT'],
  5191. ['MPL', 'MPL-2.0'],
  5192. ['X11', 'X11'],
  5193. ['ZLIB', 'Zlib']
  5194. ];
  5195. var SUBSTRING = 0;
  5196. var IDENTIFIER = 1;
  5197. var validTransformation = function(identifier) {
  5198. for (var i = 0; i < transforms.length; i++) {
  5199. var transformed = transforms[i](identifier);
  5200. if (transformed !== identifier && valid(transformed)) {
  5201. return transformed;
  5202. }
  5203. }
  5204. return null;
  5205. };
  5206. var validLastResort = function(identifier) {
  5207. var upperCased = identifier.toUpperCase();
  5208. for (var i = 0; i < lastResorts.length; i++) {
  5209. var lastResort = lastResorts[i];
  5210. if (upperCased.indexOf(lastResort[SUBSTRING]) > -1) {
  5211. return lastResort[IDENTIFIER];
  5212. }
  5213. }
  5214. return null;
  5215. };
  5216. var anyCorrection = function(identifier, check) {
  5217. for (var i = 0; i < transpositions.length; i++) {
  5218. var transposition = transpositions[i];
  5219. var transposed = transposition[TRANSPOSED];
  5220. if (identifier.indexOf(transposed) > -1) {
  5221. var corrected = identifier.replace(
  5222. transposed,
  5223. transposition[CORRECT]
  5224. );
  5225. var checked = check(corrected);
  5226. if (checked !== null) {
  5227. return checked;
  5228. }
  5229. }
  5230. }
  5231. return null;
  5232. };
  5233. var spdxCorrect = function(identifier) {
  5234. identifier = identifier.replace(/\+$/, '');
  5235. if (valid(identifier)) {
  5236. return identifier;
  5237. }
  5238. var transformed = validTransformation(identifier);
  5239. if (transformed !== null) {
  5240. return transformed;
  5241. }
  5242. transformed = anyCorrection(identifier, function(argument) {
  5243. if (valid(argument)) {
  5244. return argument;
  5245. }
  5246. return validTransformation(argument);
  5247. });
  5248. if (transformed !== null) {
  5249. return transformed;
  5250. }
  5251. transformed = validLastResort(identifier);
  5252. if (transformed !== null) {
  5253. return transformed;
  5254. }
  5255. transformed = anyCorrection(identifier, validLastResort);
  5256. if (transformed !== null) {
  5257. return transformed;
  5258. }
  5259. return null;
  5260. };
  5261. var genericWarning = (
  5262. 'license should be ' +
  5263. 'a valid SPDX license expression (without "LicenseRef"), ' +
  5264. '"UNLICENSED", or ' +
  5265. '"SEE LICENSE IN <filename>"'
  5266. );
  5267. var fileReferenceRE = /^SEE LICEN[CS]E IN (.+)$/;
  5268. function startsWith(prefix, string) {
  5269. return string.slice(0, prefix.length) === prefix;
  5270. }
  5271. function usesLicenseRef(ast) {
  5272. if (ast.hasOwnProperty('license')) {
  5273. var license = ast.license;
  5274. return (
  5275. startsWith('LicenseRef', license) ||
  5276. startsWith('DocumentRef', license)
  5277. );
  5278. } else {
  5279. return (
  5280. usesLicenseRef(ast.left) ||
  5281. usesLicenseRef(ast.right)
  5282. );
  5283. }
  5284. }
  5285. var validateNpmPackageLicense = function(argument) {
  5286. var ast;
  5287. try {
  5288. ast = spdxExpressionParse(argument);
  5289. } catch (e) {
  5290. var match;
  5291. if (
  5292. argument === 'UNLICENSED' ||
  5293. argument === 'UNLICENCED'
  5294. ) {
  5295. return {
  5296. validForOldPackages: true,
  5297. validForNewPackages: true,
  5298. unlicensed: true
  5299. };
  5300. } else if (match = fileReferenceRE.exec(argument)) {
  5301. return {
  5302. validForOldPackages: true,
  5303. validForNewPackages: true,
  5304. inFile: match[1]
  5305. };
  5306. } else {
  5307. var result = {
  5308. validForOldPackages: false,
  5309. validForNewPackages: false,
  5310. warnings: [genericWarning]
  5311. };
  5312. var corrected = spdxCorrect(argument);
  5313. if (corrected) {
  5314. result.warnings.push(
  5315. 'license is similar to the valid expression "' + corrected + '"'
  5316. );
  5317. }
  5318. return result;
  5319. }
  5320. }
  5321. if (usesLicenseRef(ast)) {
  5322. return {
  5323. validForNewPackages: false,
  5324. validForOldPackages: false,
  5325. spdx: true,
  5326. warnings: [genericWarning]
  5327. };
  5328. } else {
  5329. return {
  5330. validForNewPackages: true,
  5331. validForOldPackages: true,
  5332. spdx: true
  5333. };
  5334. }
  5335. };
  5336. var gitHostInfo = createCommonjsModule(function (module) {
  5337. 'use strict';
  5338. var gitHosts = module.exports = {
  5339. github: {
  5340. // First two are insecure and generally shouldn't be used any more, but
  5341. // they are still supported.
  5342. 'protocols': [ 'git', 'http', 'git+ssh', 'git+https', 'ssh', 'https' ],
  5343. 'domain': 'github.com',
  5344. 'treepath': 'tree',
  5345. 'filetemplate': 'https://{auth@}raw.githubusercontent.com/{user}/{project}/{committish}/{path}',
  5346. 'bugstemplate': 'https://{domain}/{user}/{project}/issues',
  5347. 'gittemplate': 'git://{auth@}{domain}/{user}/{project}.git{#committish}',
  5348. 'tarballtemplate': 'https://{domain}/{user}/{project}/archive/{committish}.tar.gz'
  5349. },
  5350. bitbucket: {
  5351. 'protocols': [ 'git+ssh', 'git+https', 'ssh', 'https' ],
  5352. 'domain': 'bitbucket.org',
  5353. 'treepath': 'src',
  5354. 'tarballtemplate': 'https://{domain}/{user}/{project}/get/{committish}.tar.gz'
  5355. },
  5356. gitlab: {
  5357. 'protocols': [ 'git+ssh', 'git+https', 'ssh', 'https' ],
  5358. 'domain': 'gitlab.com',
  5359. 'treepath': 'tree',
  5360. 'docstemplate': 'https://{domain}/{user}/{project}{/tree/committish}#README',
  5361. 'bugstemplate': 'https://{domain}/{user}/{project}/issues',
  5362. 'tarballtemplate': 'https://{domain}/{user}/{project}/repository/archive.tar.gz?ref={committish}'
  5363. },
  5364. gist: {
  5365. 'protocols': [ 'git', 'git+ssh', 'git+https', 'ssh', 'https' ],
  5366. 'domain': 'gist.github.com',
  5367. 'pathmatch': /^[/](?:([^/]+)[/])?([a-z0-9]+)(?:[.]git)?$/,
  5368. 'filetemplate': 'https://gist.githubusercontent.com/{user}/{project}/raw{/committish}/{path}',
  5369. 'bugstemplate': 'https://{domain}/{project}',
  5370. 'gittemplate': 'git://{domain}/{project}.git{#committish}',
  5371. 'sshtemplate': 'git@{domain}:/{project}.git{#committish}',
  5372. 'sshurltemplate': 'git+ssh://git@{domain}/{project}.git{#committish}',
  5373. 'browsetemplate': 'https://{domain}/{project}{/committish}',
  5374. 'docstemplate': 'https://{domain}/{project}{/committish}',
  5375. 'httpstemplate': 'git+https://{domain}/{project}.git{#committish}',
  5376. 'shortcuttemplate': '{type}:{project}{#committish}',
  5377. 'pathtemplate': '{project}{#committish}',
  5378. 'tarballtemplate': 'https://{domain}/{user}/{project}/archive/{committish}.tar.gz'
  5379. }
  5380. };
  5381. var gitHostDefaults = {
  5382. 'sshtemplate': 'git@{domain}:{user}/{project}.git{#committish}',
  5383. 'sshurltemplate': 'git+ssh://git@{domain}/{user}/{project}.git{#committish}',
  5384. 'browsetemplate': 'https://{domain}/{user}/{project}{/tree/committish}',
  5385. 'docstemplate': 'https://{domain}/{user}/{project}{/tree/committish}#readme',
  5386. 'httpstemplate': 'git+https://{auth@}{domain}/{user}/{project}.git{#committish}',
  5387. 'filetemplate': 'https://{domain}/{user}/{project}/raw/{committish}/{path}',
  5388. 'shortcuttemplate': '{type}:{user}/{project}{#committish}',
  5389. 'pathtemplate': '{user}/{project}{#committish}',
  5390. 'pathmatch': /^[/]([^/]+)[/]([^/]+?)(?:[.]git|[/])?$/
  5391. };
  5392. Object.keys(gitHosts).forEach(function (name) {
  5393. Object.keys(gitHostDefaults).forEach(function (key) {
  5394. if (gitHosts[name][key]) return
  5395. gitHosts[name][key] = gitHostDefaults[key];
  5396. });
  5397. gitHosts[name].protocols_re = RegExp('^(' +
  5398. gitHosts[name].protocols.map(function (protocol) {
  5399. return protocol.replace(/([\\+*{}()[\]$^|])/g, '\\$1')
  5400. }).join('|') + '):$');
  5401. });
  5402. });
  5403. var gitHost = createCommonjsModule(function (module) {
  5404. 'use strict';
  5405. var extend = Object.assign || util._extend;
  5406. var GitHost = module.exports = function (type, user, auth, project, committish, defaultRepresentation, opts) {
  5407. var gitHostInfo$$1 = this;
  5408. gitHostInfo$$1.type = type;
  5409. Object.keys(gitHostInfo[type]).forEach(function (key) {
  5410. gitHostInfo$$1[key] = gitHostInfo[type][key];
  5411. });
  5412. gitHostInfo$$1.user = user;
  5413. gitHostInfo$$1.auth = auth;
  5414. gitHostInfo$$1.project = project;
  5415. gitHostInfo$$1.committish = committish;
  5416. gitHostInfo$$1.default = defaultRepresentation;
  5417. gitHostInfo$$1.opts = opts || {};
  5418. };
  5419. GitHost.prototype = {};
  5420. GitHost.prototype.hash = function () {
  5421. return this.committish ? '#' + this.committish : ''
  5422. };
  5423. GitHost.prototype._fill = function (template, opts) {
  5424. if (!template) return
  5425. var vars = extend({}, opts);
  5426. opts = extend(extend({}, this.opts), opts);
  5427. var self = this;
  5428. Object.keys(this).forEach(function (key) {
  5429. if (self[key] != null && vars[key] == null) vars[key] = self[key];
  5430. });
  5431. var rawAuth = vars.auth;
  5432. var rawComittish = vars.committish;
  5433. Object.keys(vars).forEach(function (key) {
  5434. vars[key] = encodeURIComponent(vars[key]);
  5435. });
  5436. vars['auth@'] = rawAuth ? rawAuth + '@' : '';
  5437. if (opts.noCommittish) {
  5438. vars['#committish'] = '';
  5439. vars['/tree/committish'] = '';
  5440. vars['/comittish'] = '';
  5441. vars.comittish = '';
  5442. } else {
  5443. vars['#committish'] = rawComittish ? '#' + rawComittish : '';
  5444. vars['/tree/committish'] = vars.committish
  5445. ? '/' + vars.treepath + '/' + vars.committish
  5446. : '';
  5447. vars['/committish'] = vars.committish ? '/' + vars.committish : '';
  5448. vars.committish = vars.committish || 'master';
  5449. }
  5450. var res = template;
  5451. Object.keys(vars).forEach(function (key) {
  5452. res = res.replace(new RegExp('[{]' + key + '[}]', 'g'), vars[key]);
  5453. });
  5454. if (opts.noGitPlus) {
  5455. return res.replace(/^git[+]/, '')
  5456. } else {
  5457. return res
  5458. }
  5459. };
  5460. GitHost.prototype.ssh = function (opts) {
  5461. return this._fill(this.sshtemplate, opts)
  5462. };
  5463. GitHost.prototype.sshurl = function (opts) {
  5464. return this._fill(this.sshurltemplate, opts)
  5465. };
  5466. GitHost.prototype.browse = function (opts) {
  5467. return this._fill(this.browsetemplate, opts)
  5468. };
  5469. GitHost.prototype.docs = function (opts) {
  5470. return this._fill(this.docstemplate, opts)
  5471. };
  5472. GitHost.prototype.bugs = function (opts) {
  5473. return this._fill(this.bugstemplate, opts)
  5474. };
  5475. GitHost.prototype.https = function (opts) {
  5476. return this._fill(this.httpstemplate, opts)
  5477. };
  5478. GitHost.prototype.git = function (opts) {
  5479. return this._fill(this.gittemplate, opts)
  5480. };
  5481. GitHost.prototype.shortcut = function (opts) {
  5482. return this._fill(this.shortcuttemplate, opts)
  5483. };
  5484. GitHost.prototype.path = function (opts) {
  5485. return this._fill(this.pathtemplate, opts)
  5486. };
  5487. GitHost.prototype.tarball = function (opts) {
  5488. return this._fill(this.tarballtemplate, opts)
  5489. };
  5490. GitHost.prototype.file = function (P, opts) {
  5491. return this._fill(this.filetemplate, extend({
  5492. path: P.replace(/^[/]+/g, '')
  5493. }, opts))
  5494. };
  5495. GitHost.prototype.getDefaultRepresentation = function () {
  5496. return this.default
  5497. };
  5498. GitHost.prototype.toString = function (opts) {
  5499. return (this[this.default] || this.sshurl).call(this, opts)
  5500. };
  5501. });
  5502. var hostedGitInfo = createCommonjsModule(function (module) {
  5503. 'use strict';
  5504. var GitHost = module.exports = gitHost;
  5505. var protocolToRepresentationMap = {
  5506. 'git+ssh': 'sshurl',
  5507. 'git+https': 'https',
  5508. 'ssh': 'sshurl',
  5509. 'git': 'git'
  5510. };
  5511. function protocolToRepresentation (protocol) {
  5512. if (protocol.substr(-1) === ':') protocol = protocol.slice(0, -1);
  5513. return protocolToRepresentationMap[protocol] || protocol
  5514. }
  5515. var authProtocols = {
  5516. 'git:': true,
  5517. 'https:': true,
  5518. 'git+https:': true,
  5519. 'http:': true,
  5520. 'git+http:': true
  5521. };
  5522. module.exports.fromUrl = function (giturl, opts) {
  5523. if (giturl == null || giturl === '') return
  5524. var url$$1 = fixupUnqualifiedGist(
  5525. isGitHubShorthand(giturl) ? 'github:' + giturl : giturl
  5526. );
  5527. var parsed = parseGitUrl(url$$1);
  5528. var shortcutMatch = url$$1.match(new RegExp('^([^:]+):(?:(?:[^@:]+(?:[^@]+)?@)?([^/]*))[/](.+?)(?:[.]git)?($|#)'));
  5529. var matches = Object.keys(gitHostInfo).map(function (gitHostName) {
  5530. try {
  5531. var gitHostInfo$$1 = gitHostInfo[gitHostName];
  5532. var auth = null;
  5533. if (parsed.auth && authProtocols[parsed.protocol]) {
  5534. auth = decodeURIComponent(parsed.auth);
  5535. }
  5536. var committish = parsed.hash ? decodeURIComponent(parsed.hash.substr(1)) : null;
  5537. var user = null;
  5538. var project = null;
  5539. var defaultRepresentation = null;
  5540. if (shortcutMatch && shortcutMatch[1] === gitHostName) {
  5541. user = shortcutMatch[2] && decodeURIComponent(shortcutMatch[2]);
  5542. project = decodeURIComponent(shortcutMatch[3]);
  5543. defaultRepresentation = 'shortcut';
  5544. } else {
  5545. if (parsed.host !== gitHostInfo$$1.domain) return
  5546. if (!gitHostInfo$$1.protocols_re.test(parsed.protocol)) return
  5547. if (!parsed.path) return
  5548. var pathmatch = gitHostInfo$$1.pathmatch;
  5549. var matched = parsed.path.match(pathmatch);
  5550. if (!matched) return
  5551. if (matched[1] != null) user = decodeURIComponent(matched[1].replace(/^:/, ''));
  5552. if (matched[2] != null) project = decodeURIComponent(matched[2]);
  5553. defaultRepresentation = protocolToRepresentation(parsed.protocol);
  5554. }
  5555. return new GitHost(gitHostName, user, auth, project, committish, defaultRepresentation, opts)
  5556. } catch (ex) {
  5557. if (!(ex instanceof URIError)) throw ex
  5558. }
  5559. }).filter(function (gitHostInfo$$1) { return gitHostInfo$$1 });
  5560. if (matches.length !== 1) return
  5561. return matches[0]
  5562. };
  5563. function isGitHubShorthand (arg) {
  5564. // Note: This does not fully test the git ref format.
  5565. // See https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
  5566. //
  5567. // The only way to do this properly would be to shell out to
  5568. // git-check-ref-format, and as this is a fast sync function,
  5569. // we don't want to do that. Just let git fail if it turns
  5570. // out that the commit-ish is invalid.
  5571. // GH usernames cannot start with . or -
  5572. return /^[^:@%/\s.-][^:@%/\s]*[/][^:@\s/%]+(?:#.*)?$/.test(arg)
  5573. }
  5574. function fixupUnqualifiedGist (giturl) {
  5575. // necessary for round-tripping gists
  5576. var parsed = url.parse(giturl);
  5577. if (parsed.protocol === 'gist:' && parsed.host && !parsed.path) {
  5578. return parsed.protocol + '/' + parsed.host
  5579. } else {
  5580. return giturl
  5581. }
  5582. }
  5583. function parseGitUrl (giturl) {
  5584. if (typeof giturl !== 'string') giturl = '' + giturl;
  5585. var matched = giturl.match(/^([^@]+)@([^:/]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/);
  5586. if (!matched) return url.parse(giturl)
  5587. return {
  5588. protocol: 'git+ssh:',
  5589. slashes: true,
  5590. auth: matched[1],
  5591. host: matched[2],
  5592. port: null,
  5593. hostname: matched[2],
  5594. hash: matched[4],
  5595. search: null,
  5596. query: null,
  5597. pathname: '/' + matched[3],
  5598. path: '/' + matched[3],
  5599. href: 'git+ssh://' + matched[1] + '@' + matched[2] +
  5600. '/' + matched[3] + (matched[4] || '')
  5601. }
  5602. }
  5603. });
  5604. var blacklist = [
  5605. 'freelist',
  5606. 'sys'
  5607. ];
  5608. var builtinModules = Object.keys(process.binding('natives')).filter(function (el) {
  5609. return !/^_|^internal|\//.test(el) && blacklist.indexOf(el) === -1;
  5610. }).sort();
  5611. var isBuiltinModule = function (str) {
  5612. if (typeof str !== 'string') {
  5613. throw new TypeError('Expected a string');
  5614. }
  5615. return builtinModules.indexOf(str) !== -1;
  5616. };
  5617. var extract_description = extractDescription;
  5618. // Extracts description from contents of a readme file in markdown format
  5619. function extractDescription (d) {
  5620. if (!d) return;
  5621. if (d === "ERROR: No README data found!") return;
  5622. // the first block of text before the first heading
  5623. // that isn't the first line heading
  5624. d = d.trim().split('\n');
  5625. for (var s = 0; d[s] && d[s].trim().match(/^(#|$)/); s ++);
  5626. var l = d.length;
  5627. for (var e = s + 1; e < l && d[e].trim(); e ++);
  5628. return d.slice(s, e).join(' ').trim()
  5629. }
  5630. 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"};
  5631. var bugs = {"web":"url","name":"url"};
  5632. var script = {"server":"start","tests":"test"};
  5633. var typos = {
  5634. topLevel: topLevel,
  5635. bugs: bugs,
  5636. script: script
  5637. };
  5638. var typos$1 = Object.freeze({
  5639. topLevel: topLevel,
  5640. bugs: bugs,
  5641. script: script,
  5642. default: typos
  5643. });
  5644. var typos$2 = ( typos$1 && typos ) || typos$1;
  5645. var fixer_1 = createCommonjsModule(function (module) {
  5646. var depTypes = ["dependencies","devDependencies","optionalDependencies"];
  5647. var fixer = module.exports = {
  5648. // default warning function
  5649. warn: function() {},
  5650. fixRepositoryField: function(data) {
  5651. if (data.repositories) {
  5652. this.warn("repositories");
  5653. data.repository = data.repositories[0];
  5654. }
  5655. if (!data.repository) return this.warn("missingRepository")
  5656. if (typeof data.repository === "string") {
  5657. data.repository = {
  5658. type: "git",
  5659. url: data.repository
  5660. };
  5661. }
  5662. var r = data.repository.url || "";
  5663. if (r) {
  5664. var hosted = hostedGitInfo.fromUrl(r);
  5665. if (hosted) {
  5666. r = data.repository.url
  5667. = hosted.getDefaultRepresentation() == "shortcut" ? hosted.https() : hosted.toString();
  5668. }
  5669. }
  5670. if (r.match(/github.com\/[^\/]+\/[^\/]+\.git\.git$/)) {
  5671. this.warn("brokenGitUrl", r);
  5672. }
  5673. }
  5674. , fixTypos: function(data) {
  5675. Object.keys(typos$2.topLevel).forEach(function (d) {
  5676. if (data.hasOwnProperty(d)) {
  5677. this.warn("typo", d, typos$2.topLevel[d]);
  5678. }
  5679. }, this);
  5680. }
  5681. , fixScriptsField: function(data) {
  5682. if (!data.scripts) return
  5683. if (typeof data.scripts !== "object") {
  5684. this.warn("nonObjectScripts");
  5685. delete data.scripts;
  5686. return
  5687. }
  5688. Object.keys(data.scripts).forEach(function (k) {
  5689. if (typeof data.scripts[k] !== "string") {
  5690. this.warn("nonStringScript");
  5691. delete data.scripts[k];
  5692. } else if (typos$2.script[k] && !data.scripts[typos$2.script[k]]) {
  5693. this.warn("typo", k, typos$2.script[k], "scripts");
  5694. }
  5695. }, this);
  5696. }
  5697. , fixFilesField: function(data) {
  5698. var files = data.files;
  5699. if (files && !Array.isArray(files)) {
  5700. this.warn("nonArrayFiles");
  5701. delete data.files;
  5702. } else if (data.files) {
  5703. data.files = data.files.filter(function(file) {
  5704. if (!file || typeof file !== "string") {
  5705. this.warn("invalidFilename", file);
  5706. return false
  5707. } else {
  5708. return true
  5709. }
  5710. }, this);
  5711. }
  5712. }
  5713. , fixBinField: function(data) {
  5714. if (!data.bin) return;
  5715. if (typeof data.bin === "string") {
  5716. var b = {};
  5717. var match;
  5718. if (match = data.name.match(/^@[^/]+[/](.*)$/)) {
  5719. b[match[1]] = data.bin;
  5720. } else {
  5721. b[data.name] = data.bin;
  5722. }
  5723. data.bin = b;
  5724. }
  5725. }
  5726. , fixManField: function(data) {
  5727. if (!data.man) return;
  5728. if (typeof data.man === "string") {
  5729. data.man = [ data.man ];
  5730. }
  5731. }
  5732. , fixBundleDependenciesField: function(data) {
  5733. var bdd = "bundledDependencies";
  5734. var bd = "bundleDependencies";
  5735. if (data[bdd] && !data[bd]) {
  5736. data[bd] = data[bdd];
  5737. delete data[bdd];
  5738. }
  5739. if (data[bd] && !Array.isArray(data[bd])) {
  5740. this.warn("nonArrayBundleDependencies");
  5741. delete data[bd];
  5742. } else if (data[bd]) {
  5743. data[bd] = data[bd].filter(function(bd) {
  5744. if (!bd || typeof bd !== 'string') {
  5745. this.warn("nonStringBundleDependency", bd);
  5746. return false
  5747. } else {
  5748. if (!data.dependencies) {
  5749. data.dependencies = {};
  5750. }
  5751. if (!data.dependencies.hasOwnProperty(bd)) {
  5752. this.warn("nonDependencyBundleDependency", bd);
  5753. data.dependencies[bd] = "*";
  5754. }
  5755. return true
  5756. }
  5757. }, this);
  5758. }
  5759. }
  5760. , fixDependencies: function(data, strict) {
  5761. var loose = !strict;
  5762. objectifyDeps(data, this.warn);
  5763. addOptionalDepsToDeps(data, this.warn);
  5764. this.fixBundleDependenciesField(data)
  5765. ;['dependencies','devDependencies'].forEach(function(deps) {
  5766. if (!(deps in data)) return
  5767. if (!data[deps] || typeof data[deps] !== "object") {
  5768. this.warn("nonObjectDependencies", deps);
  5769. delete data[deps];
  5770. return
  5771. }
  5772. Object.keys(data[deps]).forEach(function (d) {
  5773. var r = data[deps][d];
  5774. if (typeof r !== 'string') {
  5775. this.warn("nonStringDependency", d, JSON.stringify(r));
  5776. delete data[deps][d];
  5777. }
  5778. var hosted = hostedGitInfo.fromUrl(data[deps][d]);
  5779. if (hosted) data[deps][d] = hosted.toString();
  5780. }, this);
  5781. }, this);
  5782. }
  5783. , fixModulesField: function (data) {
  5784. if (data.modules) {
  5785. this.warn("deprecatedModules");
  5786. delete data.modules;
  5787. }
  5788. }
  5789. , fixKeywordsField: function (data) {
  5790. if (typeof data.keywords === "string") {
  5791. data.keywords = data.keywords.split(/,\s+/);
  5792. }
  5793. if (data.keywords && !Array.isArray(data.keywords)) {
  5794. delete data.keywords;
  5795. this.warn("nonArrayKeywords");
  5796. } else if (data.keywords) {
  5797. data.keywords = data.keywords.filter(function(kw) {
  5798. if (typeof kw !== "string" || !kw) {
  5799. this.warn("nonStringKeyword");
  5800. return false
  5801. } else {
  5802. return true
  5803. }
  5804. }, this);
  5805. }
  5806. }
  5807. , fixVersionField: function(data, strict) {
  5808. // allow "loose" semver 1.0 versions in non-strict mode
  5809. // enforce strict semver 2.0 compliance in strict mode
  5810. var loose = !strict;
  5811. if (!data.version) {
  5812. data.version = "";
  5813. return true
  5814. }
  5815. if (!semver.valid(data.version, loose)) {
  5816. throw new Error('Invalid version: "'+ data.version + '"')
  5817. }
  5818. data.version = semver.clean(data.version, loose);
  5819. return true
  5820. }
  5821. , fixPeople: function(data) {
  5822. modifyPeople(data, unParsePerson);
  5823. modifyPeople(data, parsePerson);
  5824. }
  5825. , fixNameField: function(data, options) {
  5826. if (typeof options === "boolean") options = {strict: options};
  5827. else if (typeof options === "undefined") options = {};
  5828. var strict = options.strict;
  5829. if (!data.name && !strict) {
  5830. data.name = "";
  5831. return
  5832. }
  5833. if (typeof data.name !== "string") {
  5834. throw new Error("name field must be a string.")
  5835. }
  5836. if (!strict)
  5837. data.name = data.name.trim();
  5838. ensureValidName(data.name, strict, options.allowLegacyCase);
  5839. if (isBuiltinModule(data.name))
  5840. this.warn("conflictingName", data.name);
  5841. }
  5842. , fixDescriptionField: function (data) {
  5843. if (data.description && typeof data.description !== 'string') {
  5844. this.warn("nonStringDescription");
  5845. delete data.description;
  5846. }
  5847. if (data.readme && !data.description)
  5848. data.description = extract_description(data.readme);
  5849. if(data.description === undefined) delete data.description;
  5850. if (!data.description) this.warn("missingDescription");
  5851. }
  5852. , fixReadmeField: function (data) {
  5853. if (!data.readme) {
  5854. this.warn("missingReadme");
  5855. data.readme = "ERROR: No README data found!";
  5856. }
  5857. }
  5858. , fixBugsField: function(data) {
  5859. if (!data.bugs && data.repository && data.repository.url) {
  5860. var hosted = hostedGitInfo.fromUrl(data.repository.url);
  5861. if(hosted && hosted.bugs()) {
  5862. data.bugs = {url: hosted.bugs()};
  5863. }
  5864. }
  5865. else if(data.bugs) {
  5866. var emailRe = /^.+@.*\..+$/;
  5867. if(typeof data.bugs == "string") {
  5868. if(emailRe.test(data.bugs))
  5869. data.bugs = {email:data.bugs};
  5870. else if(url.parse(data.bugs).protocol)
  5871. data.bugs = {url: data.bugs};
  5872. else
  5873. this.warn("nonEmailUrlBugsString");
  5874. }
  5875. else {
  5876. bugsTypos(data.bugs, this.warn);
  5877. var oldBugs = data.bugs;
  5878. data.bugs = {};
  5879. if(oldBugs.url) {
  5880. if(typeof(oldBugs.url) == "string" && url.parse(oldBugs.url).protocol)
  5881. data.bugs.url = oldBugs.url;
  5882. else
  5883. this.warn("nonUrlBugsUrlField");
  5884. }
  5885. if(oldBugs.email) {
  5886. if(typeof(oldBugs.email) == "string" && emailRe.test(oldBugs.email))
  5887. data.bugs.email = oldBugs.email;
  5888. else
  5889. this.warn("nonEmailBugsEmailField");
  5890. }
  5891. }
  5892. if(!data.bugs.email && !data.bugs.url) {
  5893. delete data.bugs;
  5894. this.warn("emptyNormalizedBugs");
  5895. }
  5896. }
  5897. }
  5898. , fixHomepageField: function(data) {
  5899. if (!data.homepage && data.repository && data.repository.url) {
  5900. var hosted = hostedGitInfo.fromUrl(data.repository.url);
  5901. if (hosted && hosted.docs()) data.homepage = hosted.docs();
  5902. }
  5903. if (!data.homepage) return
  5904. if(typeof data.homepage !== "string") {
  5905. this.warn("nonUrlHomepage");
  5906. return delete data.homepage
  5907. }
  5908. if(!url.parse(data.homepage).protocol) {
  5909. this.warn("missingProtocolHomepage");
  5910. data.homepage = "http://" + data.homepage;
  5911. }
  5912. }
  5913. , fixLicenseField: function(data) {
  5914. if (!data.license) {
  5915. return this.warn("missingLicense")
  5916. } else{
  5917. if (
  5918. typeof(data.license) !== 'string' ||
  5919. data.license.length < 1
  5920. ) {
  5921. this.warn("invalidLicense");
  5922. } else {
  5923. if (!validateNpmPackageLicense(data.license).validForNewPackages)
  5924. this.warn("invalidLicense");
  5925. }
  5926. }
  5927. }
  5928. };
  5929. function isValidScopedPackageName(spec) {
  5930. if (spec.charAt(0) !== '@') return false
  5931. var rest = spec.slice(1).split('/');
  5932. if (rest.length !== 2) return false
  5933. return rest[0] && rest[1] &&
  5934. rest[0] === encodeURIComponent(rest[0]) &&
  5935. rest[1] === encodeURIComponent(rest[1])
  5936. }
  5937. function isCorrectlyEncodedName(spec) {
  5938. return !spec.match(/[\/@\s\+%:]/) &&
  5939. spec === encodeURIComponent(spec)
  5940. }
  5941. function ensureValidName (name, strict, allowLegacyCase) {
  5942. if (name.charAt(0) === "." ||
  5943. !(isValidScopedPackageName(name) || isCorrectlyEncodedName(name)) ||
  5944. (strict && (!allowLegacyCase) && name !== name.toLowerCase()) ||
  5945. name.toLowerCase() === "node_modules" ||
  5946. name.toLowerCase() === "favicon.ico") {
  5947. throw new Error("Invalid name: " + JSON.stringify(name))
  5948. }
  5949. }
  5950. function modifyPeople (data, fn) {
  5951. if (data.author) data.author = fn(data.author)
  5952. ;["maintainers", "contributors"].forEach(function (set) {
  5953. if (!Array.isArray(data[set])) return;
  5954. data[set] = data[set].map(fn);
  5955. });
  5956. return data
  5957. }
  5958. function unParsePerson (person) {
  5959. if (typeof person === "string") return person
  5960. var name = person.name || "";
  5961. var u = person.url || person.web;
  5962. var url$$1 = u ? (" ("+u+")") : "";
  5963. var e = person.email || person.mail;
  5964. var email = e ? (" <"+e+">") : "";
  5965. return name+email+url$$1
  5966. }
  5967. function parsePerson (person) {
  5968. if (typeof person !== "string") return person
  5969. var name = person.match(/^([^\(<]+)/);
  5970. var url$$1 = person.match(/\(([^\)]+)\)/);
  5971. var email = person.match(/<([^>]+)>/);
  5972. var obj = {};
  5973. if (name && name[0].trim()) obj.name = name[0].trim();
  5974. if (email) obj.email = email[1];
  5975. if (url$$1) obj.url = url$$1[1];
  5976. return obj
  5977. }
  5978. function addOptionalDepsToDeps (data, warn) {
  5979. var o = data.optionalDependencies;
  5980. if (!o) return;
  5981. var d = data.dependencies || {};
  5982. Object.keys(o).forEach(function (k) {
  5983. d[k] = o[k];
  5984. });
  5985. data.dependencies = d;
  5986. }
  5987. function depObjectify (deps, type, warn) {
  5988. if (!deps) return {}
  5989. if (typeof deps === "string") {
  5990. deps = deps.trim().split(/[\n\r\s\t ,]+/);
  5991. }
  5992. if (!Array.isArray(deps)) return deps
  5993. warn("deprecatedArrayDependencies", type);
  5994. var o = {};
  5995. deps.filter(function (d) {
  5996. return typeof d === "string"
  5997. }).forEach(function(d) {
  5998. d = d.trim().split(/(:?[@\s><=])/);
  5999. var dn = d.shift();
  6000. var dv = d.join("");
  6001. dv = dv.trim();
  6002. dv = dv.replace(/^@/, "");
  6003. o[dn] = dv;
  6004. });
  6005. return o
  6006. }
  6007. function objectifyDeps (data, warn) {
  6008. depTypes.forEach(function (type) {
  6009. if (!data[type]) return;
  6010. data[type] = depObjectify(data[type], type, warn);
  6011. });
  6012. }
  6013. function bugsTypos(bugs, warn) {
  6014. if (!bugs) return
  6015. Object.keys(bugs).forEach(function (k) {
  6016. if (typos$2.bugs[k]) {
  6017. warn("typo", k, typos$2.bugs[k], "bugs");
  6018. bugs[typos$2.bugs[k]] = bugs[k];
  6019. delete bugs[k];
  6020. }
  6021. });
  6022. }
  6023. });
  6024. var repositories = "'repositories' (plural) Not supported. Please pick one as the 'repository' field";
  6025. var missingRepository = "No repository field.";
  6026. var brokenGitUrl = "Probably broken git url: %s";
  6027. var nonObjectScripts = "scripts must be an object";
  6028. var nonStringScript = "script values must be string commands";
  6029. var nonArrayFiles = "Invalid 'files' member";
  6030. var invalidFilename = "Invalid filename in 'files' list: %s";
  6031. var nonArrayBundleDependencies = "Invalid 'bundleDependencies' list. Must be array of package names";
  6032. var nonStringBundleDependency = "Invalid bundleDependencies member: %s";
  6033. var nonDependencyBundleDependency = "Non-dependency in bundleDependencies: %s";
  6034. var nonObjectDependencies = "%s field must be an object";
  6035. var nonStringDependency = "Invalid dependency: %s %s";
  6036. var deprecatedArrayDependencies = "specifying %s as array is deprecated";
  6037. var deprecatedModules = "modules field is deprecated";
  6038. var nonArrayKeywords = "keywords should be an array of strings";
  6039. var nonStringKeyword = "keywords should be an array of strings";
  6040. var conflictingName = "%s is also the name of a node core module.";
  6041. var nonStringDescription = "'description' field should be a string";
  6042. var missingDescription = "No description";
  6043. var missingReadme = "No README data";
  6044. var missingLicense = "No license field.";
  6045. var nonEmailUrlBugsString = "Bug string field must be url, email, or {email,url}";
  6046. var nonUrlBugsUrlField = "bugs.url field must be a string url. Deleted.";
  6047. var nonEmailBugsEmailField = "bugs.email field must be a string email. Deleted.";
  6048. var emptyNormalizedBugs = "Normalized value of bugs field is an empty object. Deleted.";
  6049. var nonUrlHomepage = "homepage field must be a string url. Deleted.";
  6050. var invalidLicense = "license should be a valid SPDX license expression";
  6051. var missingProtocolHomepage = "homepage field must start with a protocol.";
  6052. var typo = "%s should probably be %s.";
  6053. var warning_messages = {
  6054. repositories: repositories,
  6055. missingRepository: missingRepository,
  6056. brokenGitUrl: brokenGitUrl,
  6057. nonObjectScripts: nonObjectScripts,
  6058. nonStringScript: nonStringScript,
  6059. nonArrayFiles: nonArrayFiles,
  6060. invalidFilename: invalidFilename,
  6061. nonArrayBundleDependencies: nonArrayBundleDependencies,
  6062. nonStringBundleDependency: nonStringBundleDependency,
  6063. nonDependencyBundleDependency: nonDependencyBundleDependency,
  6064. nonObjectDependencies: nonObjectDependencies,
  6065. nonStringDependency: nonStringDependency,
  6066. deprecatedArrayDependencies: deprecatedArrayDependencies,
  6067. deprecatedModules: deprecatedModules,
  6068. nonArrayKeywords: nonArrayKeywords,
  6069. nonStringKeyword: nonStringKeyword,
  6070. conflictingName: conflictingName,
  6071. nonStringDescription: nonStringDescription,
  6072. missingDescription: missingDescription,
  6073. missingReadme: missingReadme,
  6074. missingLicense: missingLicense,
  6075. nonEmailUrlBugsString: nonEmailUrlBugsString,
  6076. nonUrlBugsUrlField: nonUrlBugsUrlField,
  6077. nonEmailBugsEmailField: nonEmailBugsEmailField,
  6078. emptyNormalizedBugs: emptyNormalizedBugs,
  6079. nonUrlHomepage: nonUrlHomepage,
  6080. invalidLicense: invalidLicense,
  6081. missingProtocolHomepage: missingProtocolHomepage,
  6082. typo: typo
  6083. };
  6084. var warning_messages$1 = Object.freeze({
  6085. repositories: repositories,
  6086. missingRepository: missingRepository,
  6087. brokenGitUrl: brokenGitUrl,
  6088. nonObjectScripts: nonObjectScripts,
  6089. nonStringScript: nonStringScript,
  6090. nonArrayFiles: nonArrayFiles,
  6091. invalidFilename: invalidFilename,
  6092. nonArrayBundleDependencies: nonArrayBundleDependencies,
  6093. nonStringBundleDependency: nonStringBundleDependency,
  6094. nonDependencyBundleDependency: nonDependencyBundleDependency,
  6095. nonObjectDependencies: nonObjectDependencies,
  6096. nonStringDependency: nonStringDependency,
  6097. deprecatedArrayDependencies: deprecatedArrayDependencies,
  6098. deprecatedModules: deprecatedModules,
  6099. nonArrayKeywords: nonArrayKeywords,
  6100. nonStringKeyword: nonStringKeyword,
  6101. conflictingName: conflictingName,
  6102. nonStringDescription: nonStringDescription,
  6103. missingDescription: missingDescription,
  6104. missingReadme: missingReadme,
  6105. missingLicense: missingLicense,
  6106. nonEmailUrlBugsString: nonEmailUrlBugsString,
  6107. nonUrlBugsUrlField: nonUrlBugsUrlField,
  6108. nonEmailBugsEmailField: nonEmailBugsEmailField,
  6109. emptyNormalizedBugs: emptyNormalizedBugs,
  6110. nonUrlHomepage: nonUrlHomepage,
  6111. invalidLicense: invalidLicense,
  6112. missingProtocolHomepage: missingProtocolHomepage,
  6113. typo: typo,
  6114. default: warning_messages
  6115. });
  6116. var messages = ( warning_messages$1 && warning_messages ) || warning_messages$1;
  6117. var make_warning = function() {
  6118. var args = Array.prototype.slice.call(arguments, 0);
  6119. var warningName = args.shift();
  6120. if (warningName == "typo") {
  6121. return makeTypoWarning.apply(null,args)
  6122. }
  6123. else {
  6124. var msgTemplate = messages[warningName] ? messages[warningName] : warningName + ": '%s'";
  6125. args.unshift(msgTemplate);
  6126. return util.format.apply(null, args)
  6127. }
  6128. };
  6129. function makeTypoWarning (providedName, probableName, field) {
  6130. if (field) {
  6131. providedName = field + "['" + providedName + "']";
  6132. probableName = field + "['" + probableName + "']";
  6133. }
  6134. return util.format(messages.typo, providedName, probableName)
  6135. }
  6136. var normalize_1 = normalize;
  6137. normalize.fixer = fixer_1;
  6138. var fieldsToFix = ['name','version','description','repository','modules','scripts'
  6139. ,'files','bin','man','bugs','keywords','readme','homepage','license'];
  6140. var otherThingsToFix = ['dependencies','people', 'typos'];
  6141. var thingsToFix = fieldsToFix.map(function(fieldName) {
  6142. return ucFirst(fieldName) + "Field"
  6143. });
  6144. // two ways to do this in CoffeeScript on only one line, sub-70 chars:
  6145. // thingsToFix = fieldsToFix.map (name) -> ucFirst(name) + "Field"
  6146. // thingsToFix = (ucFirst(name) + "Field" for name in fieldsToFix)
  6147. thingsToFix = thingsToFix.concat(otherThingsToFix);
  6148. function normalize (data, warn, strict) {
  6149. if(warn === true) warn = null, strict = true;
  6150. if(!strict) strict = false;
  6151. if(!warn || data.private) warn = function(msg) { /* noop */ };
  6152. if (data.scripts &&
  6153. data.scripts.install === "node-gyp rebuild" &&
  6154. !data.scripts.preinstall) {
  6155. data.gypfile = true;
  6156. }
  6157. fixer_1.warn = function() { warn(make_warning.apply(null, arguments)); };
  6158. thingsToFix.forEach(function(thingName) {
  6159. fixer_1["fix" + ucFirst(thingName)](data, strict);
  6160. });
  6161. data._id = data.name + "@" + data.version;
  6162. }
  6163. function ucFirst (string) {
  6164. return string.charAt(0).toUpperCase() + string.slice(1);
  6165. }
  6166. var readPkg = createCommonjsModule(function (module) {
  6167. 'use strict';
  6168. module.exports = (fp, opts) => {
  6169. if (typeof fp !== 'string') {
  6170. opts = fp;
  6171. fp = '.';
  6172. }
  6173. opts = opts || {};
  6174. return pathType.dir(fp)
  6175. .then(isDir => {
  6176. if (isDir) {
  6177. fp = path.join(fp, 'package.json');
  6178. }
  6179. return loadJsonFile(fp);
  6180. })
  6181. .then(x => {
  6182. if (opts.normalize !== false) {
  6183. normalize_1(x);
  6184. }
  6185. return x;
  6186. });
  6187. };
  6188. module.exports.sync = (fp, opts) => {
  6189. if (typeof fp !== 'string') {
  6190. opts = fp;
  6191. fp = '.';
  6192. }
  6193. opts = opts || {};
  6194. fp = pathType.dirSync(fp) ? path.join(fp, 'package.json') : fp;
  6195. const x = loadJsonFile.sync(fp);
  6196. if (opts.normalize !== false) {
  6197. normalize_1(x);
  6198. }
  6199. return x;
  6200. };
  6201. });
  6202. var readPkgUp = createCommonjsModule(function (module) {
  6203. 'use strict';
  6204. module.exports = opts => {
  6205. return findUp('package.json', opts).then(fp => {
  6206. if (!fp) {
  6207. return {};
  6208. }
  6209. return readPkg(fp, opts).then(pkg => ({pkg, path: fp}));
  6210. });
  6211. };
  6212. module.exports.sync = opts => {
  6213. const fp = findUp.sync('package.json', opts);
  6214. if (!fp) {
  6215. return {};
  6216. }
  6217. return {
  6218. pkg: readPkg.sync(fp, opts),
  6219. path: fp
  6220. };
  6221. };
  6222. });
  6223. function assertDoc(val) {
  6224. /* istanbul ignore if */
  6225. if (
  6226. !(typeof val === "string" || (val != null && typeof val.type === "string"))
  6227. ) {
  6228. throw new Error(
  6229. "Value " + JSON.stringify(val) + " is not a valid document"
  6230. );
  6231. }
  6232. }
  6233. function concat$2(parts) {
  6234. if (process.env.NODE_ENV !== "production") {
  6235. parts.forEach(assertDoc);
  6236. }
  6237. // We cannot do this until we change `printJSXElement` to not
  6238. // access the internals of a document directly.
  6239. // if(parts.length === 1) {
  6240. // // If it's a single document, no need to concat it.
  6241. // return parts[0];
  6242. // }
  6243. return { type: "concat", parts };
  6244. }
  6245. function indent$2(contents) {
  6246. if (process.env.NODE_ENV !== "production") {
  6247. assertDoc(contents);
  6248. }
  6249. return { type: "indent", contents };
  6250. }
  6251. function align$1(n, contents) {
  6252. if (process.env.NODE_ENV !== "production") {
  6253. assertDoc(contents);
  6254. }
  6255. return { type: "align", contents, n };
  6256. }
  6257. function group$1(contents, opts) {
  6258. opts = opts || {};
  6259. if (process.env.NODE_ENV !== "production") {
  6260. assertDoc(contents);
  6261. }
  6262. return {
  6263. type: "group",
  6264. contents: contents,
  6265. break: !!opts.shouldBreak,
  6266. expandedStates: opts.expandedStates
  6267. };
  6268. }
  6269. function dedentToRoot(contents) {
  6270. return align$1(-Infinity, contents);
  6271. }
  6272. function markAsRoot(contents) {
  6273. return align$1({ type: "root" }, contents);
  6274. }
  6275. function dedent$1(contents) {
  6276. return align$1(-1, contents);
  6277. }
  6278. function conditionalGroup$1(states, opts) {
  6279. return group$1(
  6280. states[0],
  6281. Object.assign(opts || {}, { expandedStates: states })
  6282. );
  6283. }
  6284. function fill$1(parts) {
  6285. if (process.env.NODE_ENV !== "production") {
  6286. parts.forEach(assertDoc);
  6287. }
  6288. return { type: "fill", parts };
  6289. }
  6290. function ifBreak$1(breakContents, flatContents) {
  6291. if (process.env.NODE_ENV !== "production") {
  6292. if (breakContents) {
  6293. assertDoc(breakContents);
  6294. }
  6295. if (flatContents) {
  6296. assertDoc(flatContents);
  6297. }
  6298. }
  6299. return { type: "if-break", breakContents, flatContents };
  6300. }
  6301. function lineSuffix$1(contents) {
  6302. if (process.env.NODE_ENV !== "production") {
  6303. assertDoc(contents);
  6304. }
  6305. return { type: "line-suffix", contents };
  6306. }
  6307. const lineSuffixBoundary$1 = { type: "line-suffix-boundary" };
  6308. const breakParent$2 = { type: "break-parent" };
  6309. const line$1 = { type: "line" };
  6310. const softline$1 = { type: "line", soft: true };
  6311. const hardline$2 = concat$2([{ type: "line", hard: true }, breakParent$2]);
  6312. const literalline$1 = concat$2([
  6313. { type: "line", hard: true, literal: true },
  6314. breakParent$2
  6315. ]);
  6316. const cursor$1 = { type: "cursor", placeholder: Symbol("cursor") };
  6317. function join$2(sep, arr) {
  6318. const res = [];
  6319. for (let i = 0; i < arr.length; i++) {
  6320. if (i !== 0) {
  6321. res.push(sep);
  6322. }
  6323. res.push(arr[i]);
  6324. }
  6325. return concat$2(res);
  6326. }
  6327. function addAlignmentToDoc$1(doc, size, tabWidth) {
  6328. let aligned = doc;
  6329. if (size > 0) {
  6330. // Use indent to add tabs for all the levels of tabs we need
  6331. for (let i = 0; i < Math.floor(size / tabWidth); ++i) {
  6332. aligned = indent$2(aligned);
  6333. }
  6334. // Use align for all the spaces that are needed
  6335. aligned = align$1(size % tabWidth, aligned);
  6336. // size is absolute from 0 and not relative to the current
  6337. // indentation, so we use -Infinity to reset the indentation to 0
  6338. aligned = align$1(-Infinity, aligned);
  6339. }
  6340. return aligned;
  6341. }
  6342. var docBuilders$2 = {
  6343. concat: concat$2,
  6344. join: join$2,
  6345. line: line$1,
  6346. softline: softline$1,
  6347. hardline: hardline$2,
  6348. literalline: literalline$1,
  6349. group: group$1,
  6350. conditionalGroup: conditionalGroup$1,
  6351. fill: fill$1,
  6352. lineSuffix: lineSuffix$1,
  6353. lineSuffixBoundary: lineSuffixBoundary$1,
  6354. cursor: cursor$1,
  6355. breakParent: breakParent$2,
  6356. ifBreak: ifBreak$1,
  6357. indent: indent$2,
  6358. align: align$1,
  6359. addAlignmentToDoc: addAlignmentToDoc$1,
  6360. markAsRoot,
  6361. dedentToRoot,
  6362. dedent: dedent$1
  6363. };
  6364. const concat$3 = docBuilders$2.concat;
  6365. const fill$2 = docBuilders$2.fill;
  6366. const cursor$2 = docBuilders$2.cursor;
  6367. const MODE_BREAK = 1;
  6368. const MODE_FLAT = 2;
  6369. function rootIndent() {
  6370. return { value: "", length: 0, queue: [] };
  6371. }
  6372. function makeIndent(ind, options) {
  6373. return generateInd(ind, { type: "indent" }, options);
  6374. }
  6375. function makeAlign(ind, n, options) {
  6376. return n === -Infinity
  6377. ? ind.root || rootIndent()
  6378. : n < 0
  6379. ? generateInd(ind, { type: "dedent" }, options)
  6380. : !n
  6381. ? ind
  6382. : n.type === "root"
  6383. ? Object.assign({}, ind, { root: ind })
  6384. : typeof n === "string"
  6385. ? generateInd(ind, { type: "stringAlign", n }, options)
  6386. : generateInd(ind, { type: "numberAlign", n }, options);
  6387. }
  6388. function generateInd(ind, newPart, options) {
  6389. const queue =
  6390. newPart.type === "dedent"
  6391. ? ind.queue.slice(0, -1)
  6392. : ind.queue.concat(newPart);
  6393. let value = "";
  6394. let length = 0;
  6395. let lastTabs = 0;
  6396. let lastSpaces = 0;
  6397. for (const part of queue) {
  6398. switch (part.type) {
  6399. case "indent":
  6400. flush();
  6401. if (options.useTabs) {
  6402. addTabs(1);
  6403. } else {
  6404. addSpaces(options.tabWidth);
  6405. }
  6406. break;
  6407. case "stringAlign":
  6408. flush();
  6409. value += part.n;
  6410. length += part.n.length;
  6411. break;
  6412. case "numberAlign":
  6413. lastTabs += 1;
  6414. lastSpaces += part.n;
  6415. break;
  6416. /* istanbul ignore next */
  6417. default:
  6418. throw new Error(`Unexpected type '${part.type}'`);
  6419. }
  6420. }
  6421. flushSpaces();
  6422. return Object.assign({}, ind, { value, length, queue });
  6423. function addTabs(count) {
  6424. value += "\t".repeat(count);
  6425. length += options.tabWidth * count;
  6426. }
  6427. function addSpaces(count) {
  6428. value += " ".repeat(count);
  6429. length += count;
  6430. }
  6431. function flush() {
  6432. if (options.useTabs) {
  6433. flushTabs();
  6434. } else {
  6435. flushSpaces();
  6436. }
  6437. }
  6438. function flushTabs() {
  6439. if (lastTabs > 0) {
  6440. addTabs(lastTabs);
  6441. }
  6442. resetLast();
  6443. }
  6444. function flushSpaces() {
  6445. if (lastSpaces > 0) {
  6446. addSpaces(lastSpaces);
  6447. }
  6448. resetLast();
  6449. }
  6450. function resetLast() {
  6451. lastTabs = 0;
  6452. lastSpaces = 0;
  6453. }
  6454. }
  6455. function fits(next, restCommands, width, options, mustBeFlat) {
  6456. let restIdx = restCommands.length;
  6457. const cmds = [next];
  6458. while (width >= 0) {
  6459. if (cmds.length === 0) {
  6460. if (restIdx === 0) {
  6461. return true;
  6462. }
  6463. cmds.push(restCommands[restIdx - 1]);
  6464. restIdx--;
  6465. continue;
  6466. }
  6467. const x = cmds.pop();
  6468. const ind = x[0];
  6469. const mode = x[1];
  6470. const doc = x[2];
  6471. if (typeof doc === "string") {
  6472. width -= util$1.getStringWidth(doc);
  6473. } else {
  6474. switch (doc.type) {
  6475. case "concat":
  6476. for (let i = doc.parts.length - 1; i >= 0; i--) {
  6477. cmds.push([ind, mode, doc.parts[i]]);
  6478. }
  6479. break;
  6480. case "indent":
  6481. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  6482. break;
  6483. case "align":
  6484. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  6485. break;
  6486. case "group":
  6487. if (mustBeFlat && doc.break) {
  6488. return false;
  6489. }
  6490. cmds.push([ind, doc.break ? MODE_BREAK : mode, doc.contents]);
  6491. break;
  6492. case "fill":
  6493. for (let i = doc.parts.length - 1; i >= 0; i--) {
  6494. cmds.push([ind, mode, doc.parts[i]]);
  6495. }
  6496. break;
  6497. case "if-break":
  6498. if (mode === MODE_BREAK) {
  6499. if (doc.breakContents) {
  6500. cmds.push([ind, mode, doc.breakContents]);
  6501. }
  6502. }
  6503. if (mode === MODE_FLAT) {
  6504. if (doc.flatContents) {
  6505. cmds.push([ind, mode, doc.flatContents]);
  6506. }
  6507. }
  6508. break;
  6509. case "line":
  6510. switch (mode) {
  6511. // fallthrough
  6512. case MODE_FLAT:
  6513. if (!doc.hard) {
  6514. if (!doc.soft) {
  6515. width -= 1;
  6516. }
  6517. break;
  6518. }
  6519. return true;
  6520. case MODE_BREAK:
  6521. return true;
  6522. }
  6523. break;
  6524. }
  6525. }
  6526. }
  6527. return false;
  6528. }
  6529. function printDocToString$1(doc, options) {
  6530. const width = options.printWidth;
  6531. const newLine = options.newLine || "\n";
  6532. let pos = 0;
  6533. // cmds is basically a stack. We've turned a recursive call into a
  6534. // while loop which is much faster. The while loop below adds new
  6535. // cmds to the array instead of recursively calling `print`.
  6536. const cmds = [[rootIndent(), MODE_BREAK, doc]];
  6537. const out = [];
  6538. let shouldRemeasure = false;
  6539. let lineSuffix = [];
  6540. while (cmds.length !== 0) {
  6541. const x = cmds.pop();
  6542. const ind = x[0];
  6543. const mode = x[1];
  6544. const doc = x[2];
  6545. if (typeof doc === "string") {
  6546. out.push(doc);
  6547. pos += util$1.getStringWidth(doc);
  6548. } else {
  6549. switch (doc.type) {
  6550. case "cursor":
  6551. out.push(cursor$2.placeholder);
  6552. break;
  6553. case "concat":
  6554. for (let i = doc.parts.length - 1; i >= 0; i--) {
  6555. cmds.push([ind, mode, doc.parts[i]]);
  6556. }
  6557. break;
  6558. case "indent":
  6559. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  6560. break;
  6561. case "align":
  6562. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  6563. break;
  6564. case "group":
  6565. switch (mode) {
  6566. case MODE_FLAT:
  6567. if (!shouldRemeasure) {
  6568. cmds.push([
  6569. ind,
  6570. doc.break ? MODE_BREAK : MODE_FLAT,
  6571. doc.contents
  6572. ]);
  6573. break;
  6574. }
  6575. // fallthrough
  6576. case MODE_BREAK: {
  6577. shouldRemeasure = false;
  6578. const next = [ind, MODE_FLAT, doc.contents];
  6579. const rem = width - pos;
  6580. if (!doc.break && fits(next, cmds, rem, options)) {
  6581. cmds.push(next);
  6582. } else {
  6583. // Expanded states are a rare case where a document
  6584. // can manually provide multiple representations of
  6585. // itself. It provides an array of documents
  6586. // going from the least expanded (most flattened)
  6587. // representation first to the most expanded. If a
  6588. // group has these, we need to manually go through
  6589. // these states and find the first one that fits.
  6590. if (doc.expandedStates) {
  6591. const mostExpanded =
  6592. doc.expandedStates[doc.expandedStates.length - 1];
  6593. if (doc.break) {
  6594. cmds.push([ind, MODE_BREAK, mostExpanded]);
  6595. break;
  6596. } else {
  6597. for (let i = 1; i < doc.expandedStates.length + 1; i++) {
  6598. if (i >= doc.expandedStates.length) {
  6599. cmds.push([ind, MODE_BREAK, mostExpanded]);
  6600. break;
  6601. } else {
  6602. const state = doc.expandedStates[i];
  6603. const cmd = [ind, MODE_FLAT, state];
  6604. if (fits(cmd, cmds, rem, options)) {
  6605. cmds.push(cmd);
  6606. break;
  6607. }
  6608. }
  6609. }
  6610. }
  6611. } else {
  6612. cmds.push([ind, MODE_BREAK, doc.contents]);
  6613. }
  6614. }
  6615. break;
  6616. }
  6617. }
  6618. break;
  6619. // Fills each line with as much code as possible before moving to a new
  6620. // line with the same indentation.
  6621. //
  6622. // Expects doc.parts to be an array of alternating content and
  6623. // whitespace. The whitespace contains the linebreaks.
  6624. //
  6625. // For example:
  6626. // ["I", line, "love", line, "monkeys"]
  6627. // or
  6628. // [{ type: group, ... }, softline, { type: group, ... }]
  6629. //
  6630. // It uses this parts structure to handle three main layout cases:
  6631. // * The first two content items fit on the same line without
  6632. // breaking
  6633. // -> output the first content item and the whitespace "flat".
  6634. // * Only the first content item fits on the line without breaking
  6635. // -> output the first content item "flat" and the whitespace with
  6636. // "break".
  6637. // * Neither content item fits on the line without breaking
  6638. // -> output the first content item and the whitespace with "break".
  6639. case "fill": {
  6640. const rem = width - pos;
  6641. const parts = doc.parts;
  6642. if (parts.length === 0) {
  6643. break;
  6644. }
  6645. const content = parts[0];
  6646. const contentFlatCmd = [ind, MODE_FLAT, content];
  6647. const contentBreakCmd = [ind, MODE_BREAK, content];
  6648. const contentFits = fits(contentFlatCmd, [], rem, options, true);
  6649. if (parts.length === 1) {
  6650. if (contentFits) {
  6651. cmds.push(contentFlatCmd);
  6652. } else {
  6653. cmds.push(contentBreakCmd);
  6654. }
  6655. break;
  6656. }
  6657. const whitespace = parts[1];
  6658. const whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
  6659. const whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
  6660. if (parts.length === 2) {
  6661. if (contentFits) {
  6662. cmds.push(whitespaceFlatCmd);
  6663. cmds.push(contentFlatCmd);
  6664. } else {
  6665. cmds.push(whitespaceBreakCmd);
  6666. cmds.push(contentBreakCmd);
  6667. }
  6668. break;
  6669. }
  6670. // At this point we've handled the first pair (context, separator)
  6671. // and will create a new fill doc for the rest of the content.
  6672. // Ideally we wouldn't mutate the array here but coping all the
  6673. // elements to a new array would make this algorithm quadratic,
  6674. // which is unusable for large arrays (e.g. large texts in JSX).
  6675. parts.splice(0, 2);
  6676. const remainingCmd = [ind, mode, fill$2(parts)];
  6677. const secondContent = parts[0];
  6678. const firstAndSecondContentFlatCmd = [
  6679. ind,
  6680. MODE_FLAT,
  6681. concat$3([content, whitespace, secondContent])
  6682. ];
  6683. const firstAndSecondContentFits = fits(
  6684. firstAndSecondContentFlatCmd,
  6685. [],
  6686. rem,
  6687. options,
  6688. true
  6689. );
  6690. if (firstAndSecondContentFits) {
  6691. cmds.push(remainingCmd);
  6692. cmds.push(whitespaceFlatCmd);
  6693. cmds.push(contentFlatCmd);
  6694. } else if (contentFits) {
  6695. cmds.push(remainingCmd);
  6696. cmds.push(whitespaceBreakCmd);
  6697. cmds.push(contentFlatCmd);
  6698. } else {
  6699. cmds.push(remainingCmd);
  6700. cmds.push(whitespaceBreakCmd);
  6701. cmds.push(contentBreakCmd);
  6702. }
  6703. break;
  6704. }
  6705. case "if-break":
  6706. if (mode === MODE_BREAK) {
  6707. if (doc.breakContents) {
  6708. cmds.push([ind, mode, doc.breakContents]);
  6709. }
  6710. }
  6711. if (mode === MODE_FLAT) {
  6712. if (doc.flatContents) {
  6713. cmds.push([ind, mode, doc.flatContents]);
  6714. }
  6715. }
  6716. break;
  6717. case "line-suffix":
  6718. lineSuffix.push([ind, mode, doc.contents]);
  6719. break;
  6720. case "line-suffix-boundary":
  6721. if (lineSuffix.length > 0) {
  6722. cmds.push([ind, mode, { type: "line", hard: true }]);
  6723. }
  6724. break;
  6725. case "line":
  6726. switch (mode) {
  6727. case MODE_FLAT:
  6728. if (!doc.hard) {
  6729. if (!doc.soft) {
  6730. out.push(" ");
  6731. pos += 1;
  6732. }
  6733. break;
  6734. } else {
  6735. // This line was forced into the output even if we
  6736. // were in flattened mode, so we need to tell the next
  6737. // group that no matter what, it needs to remeasure
  6738. // because the previous measurement didn't accurately
  6739. // capture the entire expression (this is necessary
  6740. // for nested groups)
  6741. shouldRemeasure = true;
  6742. }
  6743. // fallthrough
  6744. case MODE_BREAK:
  6745. if (lineSuffix.length) {
  6746. cmds.push([ind, mode, doc]);
  6747. [].push.apply(cmds, lineSuffix.reverse());
  6748. lineSuffix = [];
  6749. break;
  6750. }
  6751. if (doc.literal) {
  6752. if (ind.root) {
  6753. out.push(newLine, ind.root.value);
  6754. pos = ind.root.length;
  6755. } else {
  6756. out.push(newLine);
  6757. pos = 0;
  6758. }
  6759. } else {
  6760. if (out.length > 0) {
  6761. // Trim whitespace at the end of line
  6762. while (
  6763. out.length > 0 &&
  6764. out[out.length - 1].match(/^[^\S\n]*$/)
  6765. ) {
  6766. out.pop();
  6767. }
  6768. if (
  6769. out.length &&
  6770. (options.parser !== "markdown" ||
  6771. // preserve markdown's `break` node (two trailing spaces)
  6772. !/\S {2}$/.test(out[out.length - 1]))
  6773. ) {
  6774. out[out.length - 1] = out[out.length - 1].replace(
  6775. /[^\S\n]*$/,
  6776. ""
  6777. );
  6778. }
  6779. }
  6780. out.push(newLine + ind.value);
  6781. pos = ind.length;
  6782. }
  6783. break;
  6784. }
  6785. break;
  6786. default:
  6787. }
  6788. }
  6789. }
  6790. const cursorPlaceholderIndex = out.indexOf(cursor$2.placeholder);
  6791. if (cursorPlaceholderIndex !== -1) {
  6792. const beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
  6793. const afterCursor = out.slice(cursorPlaceholderIndex + 1).join("");
  6794. return {
  6795. formatted: beforeCursor + afterCursor,
  6796. cursor: beforeCursor.length
  6797. };
  6798. }
  6799. return { formatted: out.join("") };
  6800. }
  6801. var docPrinter = { printDocToString: printDocToString$1 };
  6802. function flattenDoc(doc) {
  6803. if (doc.type === "concat") {
  6804. const res = [];
  6805. for (let i = 0; i < doc.parts.length; ++i) {
  6806. const doc2 = doc.parts[i];
  6807. if (typeof doc2 !== "string" && doc2.type === "concat") {
  6808. [].push.apply(res, flattenDoc(doc2).parts);
  6809. } else {
  6810. const flattened = flattenDoc(doc2);
  6811. if (flattened !== "") {
  6812. res.push(flattened);
  6813. }
  6814. }
  6815. }
  6816. return Object.assign({}, doc, { parts: res });
  6817. } else if (doc.type === "if-break") {
  6818. return Object.assign({}, doc, {
  6819. breakContents:
  6820. doc.breakContents != null ? flattenDoc(doc.breakContents) : null,
  6821. flatContents:
  6822. doc.flatContents != null ? flattenDoc(doc.flatContents) : null
  6823. });
  6824. } else if (doc.type === "group") {
  6825. return Object.assign({}, doc, {
  6826. contents: flattenDoc(doc.contents),
  6827. expandedStates: doc.expandedStates
  6828. ? doc.expandedStates.map(flattenDoc)
  6829. : doc.expandedStates
  6830. });
  6831. } else if (doc.contents) {
  6832. return Object.assign({}, doc, { contents: flattenDoc(doc.contents) });
  6833. }
  6834. return doc;
  6835. }
  6836. function printDoc(doc) {
  6837. if (typeof doc === "string") {
  6838. return JSON.stringify(doc);
  6839. }
  6840. if (doc.type === "line") {
  6841. if (doc.literalline) {
  6842. return "literalline";
  6843. }
  6844. if (doc.hard) {
  6845. return "hardline";
  6846. }
  6847. if (doc.soft) {
  6848. return "softline";
  6849. }
  6850. return "line";
  6851. }
  6852. if (doc.type === "break-parent") {
  6853. return "breakParent";
  6854. }
  6855. if (doc.type === "concat") {
  6856. return "[" + doc.parts.map(printDoc).join(", ") + "]";
  6857. }
  6858. if (doc.type === "indent") {
  6859. return "indent(" + printDoc(doc.contents) + ")";
  6860. }
  6861. if (doc.type === "align") {
  6862. return doc.n === -Infinity
  6863. ? "dedentToRoot(" + printDoc(doc.contents) + ")"
  6864. : doc.n < 0
  6865. ? "dedent(" + printDoc(doc.contents) + ")"
  6866. : doc.n.type === "root"
  6867. ? "markAsRoot(" + printDoc(doc.contents) + ")"
  6868. : "align(" +
  6869. JSON.stringify(doc.n) +
  6870. ", " +
  6871. printDoc(doc.contents) +
  6872. ")";
  6873. }
  6874. if (doc.type === "if-break") {
  6875. return (
  6876. "ifBreak(" +
  6877. printDoc(doc.breakContents) +
  6878. (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") +
  6879. ")"
  6880. );
  6881. }
  6882. if (doc.type === "group") {
  6883. if (doc.expandedStates) {
  6884. return (
  6885. "conditionalGroup(" +
  6886. "[" +
  6887. doc.expandedStates.map(printDoc).join(",") +
  6888. "])"
  6889. );
  6890. }
  6891. return (
  6892. (doc.break ? "wrappedGroup" : "group") +
  6893. "(" +
  6894. printDoc(doc.contents) +
  6895. ")"
  6896. );
  6897. }
  6898. if (doc.type === "fill") {
  6899. return "fill" + "(" + doc.parts.map(printDoc).join(", ") + ")";
  6900. }
  6901. if (doc.type === "line-suffix") {
  6902. return "lineSuffix(" + printDoc(doc.contents) + ")";
  6903. }
  6904. if (doc.type === "line-suffix-boundary") {
  6905. return "lineSuffixBoundary";
  6906. }
  6907. throw new Error("Unknown doc type " + doc.type);
  6908. }
  6909. var docDebug = {
  6910. printDocToDebug: function(doc) {
  6911. return printDoc(flattenDoc(doc));
  6912. }
  6913. };
  6914. var doc = {
  6915. builders: docBuilders$2,
  6916. printer: docPrinter,
  6917. utils: docUtils,
  6918. debug: docDebug
  6919. };
  6920. const docBuilders$1 = doc.builders;
  6921. const concat$1 = docBuilders$1.concat;
  6922. const hardline$1 = docBuilders$1.hardline;
  6923. const breakParent$1 = docBuilders$1.breakParent;
  6924. const indent$1 = docBuilders$1.indent;
  6925. const lineSuffix = docBuilders$1.lineSuffix;
  6926. const join$1 = docBuilders$1.join;
  6927. const cursor = docBuilders$1.cursor;
  6928. const childNodesCacheKey = Symbol("child-nodes");
  6929. const addLeadingComment$1 = utilShared.addLeadingComment;
  6930. const addTrailingComment$1 = utilShared.addTrailingComment;
  6931. const addDanglingComment$1 = utilShared.addDanglingComment;
  6932. function getSortedChildNodes(node, text, options, resultArray) {
  6933. if (!node) {
  6934. return;
  6935. }
  6936. const printer = options.printer;
  6937. const locStart = options.locStart;
  6938. const locEnd = options.locEnd;
  6939. if (resultArray) {
  6940. if (node && printer.canAttachComment && printer.canAttachComment(node)) {
  6941. // This reverse insertion sort almost always takes constant
  6942. // time because we almost always (maybe always?) append the
  6943. // nodes in order anyway.
  6944. let i;
  6945. for (i = resultArray.length - 1; i >= 0; --i) {
  6946. if (
  6947. locStart(resultArray[i]) <= locStart(node) &&
  6948. locEnd(resultArray[i]) <= locEnd(node)
  6949. ) {
  6950. break;
  6951. }
  6952. }
  6953. resultArray.splice(i + 1, 0, node);
  6954. return;
  6955. }
  6956. } else if (node[childNodesCacheKey]) {
  6957. return node[childNodesCacheKey];
  6958. }
  6959. let childNodes;
  6960. if (printer.getCommentChildNodes) {
  6961. childNodes = printer.getCommentChildNodes(node);
  6962. } else if (node && typeof node === "object") {
  6963. childNodes = Object.keys(node)
  6964. .filter(
  6965. n =>
  6966. n !== "enclosingNode" &&
  6967. n !== "precedingNode" &&
  6968. n !== "followingNode"
  6969. )
  6970. .map(n => node[n]);
  6971. }
  6972. if (!childNodes) {
  6973. return;
  6974. }
  6975. if (!resultArray) {
  6976. Object.defineProperty(node, childNodesCacheKey, {
  6977. value: (resultArray = []),
  6978. enumerable: false
  6979. });
  6980. }
  6981. childNodes.forEach(childNode => {
  6982. getSortedChildNodes(childNode, text, options, resultArray);
  6983. });
  6984. return resultArray;
  6985. }
  6986. // As efficiently as possible, decorate the comment object with
  6987. // .precedingNode, .enclosingNode, and/or .followingNode properties, at
  6988. // least one of which is guaranteed to be defined.
  6989. function decorateComment(node, comment, text, options) {
  6990. const locStart = options.locStart;
  6991. const locEnd = options.locEnd;
  6992. const childNodes = getSortedChildNodes(node, text, options);
  6993. let precedingNode;
  6994. let followingNode;
  6995. // Time to dust off the old binary search robes and wizard hat.
  6996. let left = 0;
  6997. let right = childNodes.length;
  6998. while (left < right) {
  6999. const middle = (left + right) >> 1;
  7000. const child = childNodes[middle];
  7001. if (
  7002. locStart(child) - locStart(comment) <= 0 &&
  7003. locEnd(comment) - locEnd(child) <= 0
  7004. ) {
  7005. // The comment is completely contained by this child node.
  7006. comment.enclosingNode = child;
  7007. decorateComment(child, comment, text, options);
  7008. return; // Abandon the binary search at this level.
  7009. }
  7010. if (locEnd(child) - locStart(comment) <= 0) {
  7011. // This child node falls completely before the comment.
  7012. // Because we will never consider this node or any nodes
  7013. // before it again, this node must be the closest preceding
  7014. // node we have encountered so far.
  7015. precedingNode = child;
  7016. left = middle + 1;
  7017. continue;
  7018. }
  7019. if (locEnd(comment) - locStart(child) <= 0) {
  7020. // This child node falls completely after the comment.
  7021. // Because we will never consider this node or any nodes after
  7022. // it again, this node must be the closest following node we
  7023. // have encountered so far.
  7024. followingNode = child;
  7025. right = middle;
  7026. continue;
  7027. }
  7028. /* istanbul ignore next */
  7029. throw new Error("Comment location overlaps with node location");
  7030. }
  7031. // We don't want comments inside of different expressions inside of the same
  7032. // template literal to move to another expression.
  7033. if (
  7034. comment.enclosingNode &&
  7035. comment.enclosingNode.type === "TemplateLiteral"
  7036. ) {
  7037. const quasis = comment.enclosingNode.quasis;
  7038. const commentIndex = findExpressionIndexForComment(
  7039. quasis,
  7040. comment,
  7041. options
  7042. );
  7043. if (
  7044. precedingNode &&
  7045. findExpressionIndexForComment(quasis, precedingNode, options) !==
  7046. commentIndex
  7047. ) {
  7048. precedingNode = null;
  7049. }
  7050. if (
  7051. followingNode &&
  7052. findExpressionIndexForComment(quasis, followingNode, options) !==
  7053. commentIndex
  7054. ) {
  7055. followingNode = null;
  7056. }
  7057. }
  7058. if (precedingNode) {
  7059. comment.precedingNode = precedingNode;
  7060. }
  7061. if (followingNode) {
  7062. comment.followingNode = followingNode;
  7063. }
  7064. }
  7065. function attach(comments, ast, text, options) {
  7066. if (!Array.isArray(comments)) {
  7067. return;
  7068. }
  7069. const tiesToBreak = [];
  7070. const locStart = options.locStart;
  7071. const locEnd = options.locEnd;
  7072. comments.forEach((comment, i) => {
  7073. if (options.parser === "json" && locStart(comment) - locStart(ast) <= 0) {
  7074. addLeadingComment$1(ast, comment);
  7075. return;
  7076. }
  7077. decorateComment(ast, comment, text, options);
  7078. const precedingNode = comment.precedingNode;
  7079. const enclosingNode = comment.enclosingNode;
  7080. const followingNode = comment.followingNode;
  7081. const pluginHandleOwnLineComment =
  7082. options.printer.handleComments && options.printer.handleComments.ownLine
  7083. ? options.printer.handleComments.ownLine
  7084. : () => false;
  7085. const pluginHandleEndOfLineComment =
  7086. options.printer.handleComments && options.printer.handleComments.endOfLine
  7087. ? options.printer.handleComments.endOfLine
  7088. : () => false;
  7089. const pluginHandleRemainingComment =
  7090. options.printer.handleComments && options.printer.handleComments.remaining
  7091. ? options.printer.handleComments.remaining
  7092. : () => false;
  7093. const isLastComment = comments.length - 1 === i;
  7094. if (util$1.hasNewline(text, locStart(comment), { backwards: true })) {
  7095. // If a comment exists on its own line, prefer a leading comment.
  7096. // We also need to check if it's the first line of the file.
  7097. if (
  7098. pluginHandleOwnLineComment(comment, text, options, ast, isLastComment)
  7099. ) {
  7100. // We're good
  7101. } else if (followingNode) {
  7102. // Always a leading comment.
  7103. addLeadingComment$1(followingNode, comment);
  7104. } else if (precedingNode) {
  7105. addTrailingComment$1(precedingNode, comment);
  7106. } else if (enclosingNode) {
  7107. addDanglingComment$1(enclosingNode, comment);
  7108. } else {
  7109. // There are no nodes, let's attach it to the root of the ast
  7110. /* istanbul ignore next */
  7111. addDanglingComment$1(ast, comment);
  7112. }
  7113. } else if (util$1.hasNewline(text, locEnd(comment))) {
  7114. if (
  7115. pluginHandleEndOfLineComment(comment, text, options, ast, isLastComment)
  7116. ) {
  7117. // We're good
  7118. } else if (precedingNode) {
  7119. // There is content before this comment on the same line, but
  7120. // none after it, so prefer a trailing comment of the previous node.
  7121. addTrailingComment$1(precedingNode, comment);
  7122. } else if (followingNode) {
  7123. addLeadingComment$1(followingNode, comment);
  7124. } else if (enclosingNode) {
  7125. addDanglingComment$1(enclosingNode, comment);
  7126. } else {
  7127. // There are no nodes, let's attach it to the root of the ast
  7128. /* istanbul ignore next */
  7129. addDanglingComment$1(ast, comment);
  7130. }
  7131. } else {
  7132. if (
  7133. pluginHandleRemainingComment(comment, text, options, ast, isLastComment)
  7134. ) {
  7135. // We're good
  7136. } else if (precedingNode && followingNode) {
  7137. // Otherwise, text exists both before and after the comment on
  7138. // the same line. If there is both a preceding and following
  7139. // node, use a tie-breaking algorithm to determine if it should
  7140. // be attached to the next or previous node. In the last case,
  7141. // simply attach the right node;
  7142. const tieCount = tiesToBreak.length;
  7143. if (tieCount > 0) {
  7144. const lastTie = tiesToBreak[tieCount - 1];
  7145. if (lastTie.followingNode !== comment.followingNode) {
  7146. breakTies(tiesToBreak, text, options);
  7147. }
  7148. }
  7149. tiesToBreak.push(comment);
  7150. } else if (precedingNode) {
  7151. addTrailingComment$1(precedingNode, comment);
  7152. } else if (followingNode) {
  7153. addLeadingComment$1(followingNode, comment);
  7154. } else if (enclosingNode) {
  7155. addDanglingComment$1(enclosingNode, comment);
  7156. } else {
  7157. // There are no nodes, let's attach it to the root of the ast
  7158. /* istanbul ignore next */
  7159. addDanglingComment$1(ast, comment);
  7160. }
  7161. }
  7162. });
  7163. breakTies(tiesToBreak, text, options);
  7164. comments.forEach(comment => {
  7165. // These node references were useful for breaking ties, but we
  7166. // don't need them anymore, and they create cycles in the AST that
  7167. // may lead to infinite recursion if we don't delete them here.
  7168. delete comment.precedingNode;
  7169. delete comment.enclosingNode;
  7170. delete comment.followingNode;
  7171. });
  7172. }
  7173. function breakTies(tiesToBreak, text, options) {
  7174. const tieCount = tiesToBreak.length;
  7175. if (tieCount === 0) {
  7176. return;
  7177. }
  7178. const precedingNode = tiesToBreak[0].precedingNode;
  7179. const followingNode = tiesToBreak[0].followingNode;
  7180. let gapEndPos = options.locStart(followingNode);
  7181. // Iterate backwards through tiesToBreak, examining the gaps
  7182. // between the tied comments. In order to qualify as leading, a
  7183. // comment must be separated from followingNode by an unbroken series of
  7184. // gaps (or other comments). Gaps should only contain whitespace or open
  7185. // parentheses.
  7186. let indexOfFirstLeadingComment;
  7187. for (
  7188. indexOfFirstLeadingComment = tieCount;
  7189. indexOfFirstLeadingComment > 0;
  7190. --indexOfFirstLeadingComment
  7191. ) {
  7192. const comment = tiesToBreak[indexOfFirstLeadingComment - 1];
  7193. assert.strictEqual(comment.precedingNode, precedingNode);
  7194. assert.strictEqual(comment.followingNode, followingNode);
  7195. const gap = text.slice(options.locEnd(comment), gapEndPos).trim();
  7196. if (gap === "" || /^\(+$/.test(gap)) {
  7197. gapEndPos = options.locStart(comment);
  7198. } else {
  7199. // The gap string contained something other than whitespace or open
  7200. // parentheses.
  7201. break;
  7202. }
  7203. }
  7204. tiesToBreak.forEach((comment, i) => {
  7205. if (i < indexOfFirstLeadingComment) {
  7206. addTrailingComment$1(precedingNode, comment);
  7207. } else {
  7208. addLeadingComment$1(followingNode, comment);
  7209. }
  7210. });
  7211. tiesToBreak.length = 0;
  7212. }
  7213. function printComment$1(commentPath, options) {
  7214. const comment = commentPath.getValue();
  7215. comment.printed = true;
  7216. return options.printer.printComment(commentPath, options);
  7217. }
  7218. function findExpressionIndexForComment(quasis, comment, options) {
  7219. const startPos = options.locStart(comment) - 1;
  7220. for (let i = 1; i < quasis.length; ++i) {
  7221. if (startPos < getQuasiRange(quasis[i]).start) {
  7222. return i - 1;
  7223. }
  7224. }
  7225. // We haven't found it, it probably means that some of the locations are off.
  7226. // Let's just return the first one.
  7227. /* istanbul ignore next */
  7228. return 0;
  7229. }
  7230. function getQuasiRange(expr) {
  7231. if (expr.start !== undefined) {
  7232. // Babylon
  7233. return { start: expr.start, end: expr.end };
  7234. }
  7235. // Flow
  7236. return { start: expr.range[0], end: expr.range[1] };
  7237. }
  7238. function printLeadingComment(commentPath, print, options) {
  7239. const comment = commentPath.getValue();
  7240. const contents = printComment$1(commentPath, options);
  7241. if (!contents) {
  7242. return "";
  7243. }
  7244. const isBlock = util$1.isBlockComment(comment);
  7245. // Leading block comments should see if they need to stay on the
  7246. // same line or not.
  7247. if (isBlock) {
  7248. return concat$1([
  7249. contents,
  7250. util$1.hasNewline(options.originalText, options.locEnd(comment))
  7251. ? hardline$1
  7252. : " "
  7253. ]);
  7254. }
  7255. return concat$1([contents, hardline$1]);
  7256. }
  7257. function printTrailingComment(commentPath, print, options) {
  7258. const comment = commentPath.getValue();
  7259. const contents = printComment$1(commentPath, options);
  7260. if (!contents) {
  7261. return "";
  7262. }
  7263. const isBlock = util$1.isBlockComment(comment);
  7264. // We don't want the line to break
  7265. // when the parentParentNode is a ClassDeclaration/-Expression
  7266. // And the parentNode is in the superClass property
  7267. const parentNode = commentPath.getNode(1);
  7268. const parentParentNode = commentPath.getNode(2);
  7269. const isParentSuperClass =
  7270. parentParentNode &&
  7271. (parentParentNode.type === "ClassDeclaration" ||
  7272. parentParentNode.type === "ClassExpression") &&
  7273. parentParentNode.superClass === parentNode;
  7274. if (
  7275. util$1.hasNewline(options.originalText, options.locStart(comment), {
  7276. backwards: true
  7277. })
  7278. ) {
  7279. // This allows comments at the end of nested structures:
  7280. // {
  7281. // x: 1,
  7282. // y: 2
  7283. // // A comment
  7284. // }
  7285. // Those kinds of comments are almost always leading comments, but
  7286. // here it doesn't go "outside" the block and turns it into a
  7287. // trailing comment for `2`. We can simulate the above by checking
  7288. // if this a comment on its own line; normal trailing comments are
  7289. // always at the end of another expression.
  7290. const isLineBeforeEmpty = util$1.isPreviousLineEmpty(
  7291. options.originalText,
  7292. comment,
  7293. options.locStart
  7294. );
  7295. return lineSuffix(
  7296. concat$1([hardline$1, isLineBeforeEmpty ? hardline$1 : "", contents])
  7297. );
  7298. } else if (isBlock || isParentSuperClass) {
  7299. // Trailing block comments never need a newline
  7300. return concat$1([" ", contents]);
  7301. }
  7302. return concat$1([lineSuffix(" " + contents), !isBlock ? breakParent$1 : ""]);
  7303. }
  7304. function printDanglingComments(path$$1, options, sameIndent, filter) {
  7305. const parts = [];
  7306. const node = path$$1.getValue();
  7307. if (!node || !node.comments) {
  7308. return "";
  7309. }
  7310. path$$1.each(commentPath => {
  7311. const comment = commentPath.getValue();
  7312. if (
  7313. comment &&
  7314. !comment.leading &&
  7315. !comment.trailing &&
  7316. (!filter || filter(comment))
  7317. ) {
  7318. parts.push(printComment$1(commentPath, options));
  7319. }
  7320. }, "comments");
  7321. if (parts.length === 0) {
  7322. return "";
  7323. }
  7324. if (sameIndent) {
  7325. return join$1(hardline$1, parts);
  7326. }
  7327. return indent$1(concat$1([hardline$1, join$1(hardline$1, parts)]));
  7328. }
  7329. function prependCursorPlaceholder(path$$1, options, printed) {
  7330. if (path$$1.getNode() === options.cursorNode && path$$1.getValue()) {
  7331. return concat$1([cursor, printed]);
  7332. }
  7333. return printed;
  7334. }
  7335. function printComments(path$$1, print, options, needsSemi) {
  7336. const value = path$$1.getValue();
  7337. const printed = print(path$$1);
  7338. const comments = value && value.comments;
  7339. if (!comments || comments.length === 0) {
  7340. return prependCursorPlaceholder(path$$1, options, printed);
  7341. }
  7342. const leadingParts = [];
  7343. const trailingParts = [needsSemi ? ";" : "", printed];
  7344. path$$1.each(commentPath => {
  7345. const comment = commentPath.getValue();
  7346. const leading = comment.leading;
  7347. const trailing = comment.trailing;
  7348. if (leading) {
  7349. const contents = printLeadingComment(commentPath, print, options);
  7350. if (!contents) {
  7351. return;
  7352. }
  7353. leadingParts.push(contents);
  7354. const text = options.originalText;
  7355. if (
  7356. util$1.hasNewline(
  7357. text,
  7358. util$1.skipNewline(text, options.locEnd(comment))
  7359. )
  7360. ) {
  7361. leadingParts.push(hardline$1);
  7362. }
  7363. } else if (trailing) {
  7364. trailingParts.push(printTrailingComment(commentPath, print, options));
  7365. }
  7366. }, "comments");
  7367. return prependCursorPlaceholder(
  7368. path$$1,
  7369. options,
  7370. concat$1(leadingParts.concat(trailingParts))
  7371. );
  7372. }
  7373. var comments = {
  7374. attach,
  7375. printComments,
  7376. printDanglingComments,
  7377. getSortedChildNodes
  7378. };
  7379. var ast = createCommonjsModule(function (module) {
  7380. /*
  7381. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7382. Redistribution and use in source and binary forms, with or without
  7383. modification, are permitted provided that the following conditions are met:
  7384. * Redistributions of source code must retain the above copyright
  7385. notice, this list of conditions and the following disclaimer.
  7386. * Redistributions in binary form must reproduce the above copyright
  7387. notice, this list of conditions and the following disclaimer in the
  7388. documentation and/or other materials provided with the distribution.
  7389. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
  7390. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7391. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7392. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7393. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7394. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7395. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7396. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7397. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7398. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7399. */
  7400. (function () {
  7401. 'use strict';
  7402. function isExpression(node) {
  7403. if (node == null) { return false; }
  7404. switch (node.type) {
  7405. case 'ArrayExpression':
  7406. case 'AssignmentExpression':
  7407. case 'BinaryExpression':
  7408. case 'CallExpression':
  7409. case 'ConditionalExpression':
  7410. case 'FunctionExpression':
  7411. case 'Identifier':
  7412. case 'Literal':
  7413. case 'LogicalExpression':
  7414. case 'MemberExpression':
  7415. case 'NewExpression':
  7416. case 'ObjectExpression':
  7417. case 'SequenceExpression':
  7418. case 'ThisExpression':
  7419. case 'UnaryExpression':
  7420. case 'UpdateExpression':
  7421. return true;
  7422. }
  7423. return false;
  7424. }
  7425. function isIterationStatement(node) {
  7426. if (node == null) { return false; }
  7427. switch (node.type) {
  7428. case 'DoWhileStatement':
  7429. case 'ForInStatement':
  7430. case 'ForStatement':
  7431. case 'WhileStatement':
  7432. return true;
  7433. }
  7434. return false;
  7435. }
  7436. function isStatement(node) {
  7437. if (node == null) { return false; }
  7438. switch (node.type) {
  7439. case 'BlockStatement':
  7440. case 'BreakStatement':
  7441. case 'ContinueStatement':
  7442. case 'DebuggerStatement':
  7443. case 'DoWhileStatement':
  7444. case 'EmptyStatement':
  7445. case 'ExpressionStatement':
  7446. case 'ForInStatement':
  7447. case 'ForStatement':
  7448. case 'IfStatement':
  7449. case 'LabeledStatement':
  7450. case 'ReturnStatement':
  7451. case 'SwitchStatement':
  7452. case 'ThrowStatement':
  7453. case 'TryStatement':
  7454. case 'VariableDeclaration':
  7455. case 'WhileStatement':
  7456. case 'WithStatement':
  7457. return true;
  7458. }
  7459. return false;
  7460. }
  7461. function isSourceElement(node) {
  7462. return isStatement(node) || node != null && node.type === 'FunctionDeclaration';
  7463. }
  7464. function trailingStatement(node) {
  7465. switch (node.type) {
  7466. case 'IfStatement':
  7467. if (node.alternate != null) {
  7468. return node.alternate;
  7469. }
  7470. return node.consequent;
  7471. case 'LabeledStatement':
  7472. case 'ForStatement':
  7473. case 'ForInStatement':
  7474. case 'WhileStatement':
  7475. case 'WithStatement':
  7476. return node.body;
  7477. }
  7478. return null;
  7479. }
  7480. function isProblematicIfStatement(node) {
  7481. var current;
  7482. if (node.type !== 'IfStatement') {
  7483. return false;
  7484. }
  7485. if (node.alternate == null) {
  7486. return false;
  7487. }
  7488. current = node.consequent;
  7489. do {
  7490. if (current.type === 'IfStatement') {
  7491. if (current.alternate == null) {
  7492. return true;
  7493. }
  7494. }
  7495. current = trailingStatement(current);
  7496. } while (current);
  7497. return false;
  7498. }
  7499. module.exports = {
  7500. isExpression: isExpression,
  7501. isStatement: isStatement,
  7502. isIterationStatement: isIterationStatement,
  7503. isSourceElement: isSourceElement,
  7504. isProblematicIfStatement: isProblematicIfStatement,
  7505. trailingStatement: trailingStatement
  7506. };
  7507. }());
  7508. /* vim: set sw=4 ts=4 et tw=80 : */
  7509. });
  7510. var code = createCommonjsModule(function (module) {
  7511. /*
  7512. Copyright (C) 2013-2014 Yusuke Suzuki <utatane.tea@gmail.com>
  7513. Copyright (C) 2014 Ivan Nikulin <ifaaan@gmail.com>
  7514. Redistribution and use in source and binary forms, with or without
  7515. modification, are permitted provided that the following conditions are met:
  7516. * Redistributions of source code must retain the above copyright
  7517. notice, this list of conditions and the following disclaimer.
  7518. * Redistributions in binary form must reproduce the above copyright
  7519. notice, this list of conditions and the following disclaimer in the
  7520. documentation and/or other materials provided with the distribution.
  7521. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7522. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7523. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7524. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7525. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7526. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7527. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7528. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7529. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7530. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7531. */
  7532. (function () {
  7533. 'use strict';
  7534. var ES6Regex, ES5Regex, NON_ASCII_WHITESPACES, IDENTIFIER_START, IDENTIFIER_PART, ch;
  7535. // See `tools/generate-identifier-regex.js`.
  7536. ES5Regex = {
  7537. // ECMAScript 5.1/Unicode v7.0.0 NonAsciiIdentifierStart:
  7538. 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]/,
  7539. // ECMAScript 5.1/Unicode v7.0.0 NonAsciiIdentifierPart:
  7540. 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]/
  7541. };
  7542. ES6Regex = {
  7543. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierStart:
  7544. 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]/,
  7545. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierPart:
  7546. 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]/
  7547. };
  7548. function isDecimalDigit(ch) {
  7549. return 0x30 <= ch && ch <= 0x39; // 0..9
  7550. }
  7551. function isHexDigit(ch) {
  7552. return 0x30 <= ch && ch <= 0x39 || // 0..9
  7553. 0x61 <= ch && ch <= 0x66 || // a..f
  7554. 0x41 <= ch && ch <= 0x46; // A..F
  7555. }
  7556. function isOctalDigit(ch) {
  7557. return ch >= 0x30 && ch <= 0x37; // 0..7
  7558. }
  7559. // 7.2 White Space
  7560. NON_ASCII_WHITESPACES = [
  7561. 0x1680, 0x180E,
  7562. 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A,
  7563. 0x202F, 0x205F,
  7564. 0x3000,
  7565. 0xFEFF
  7566. ];
  7567. function isWhiteSpace(ch) {
  7568. return ch === 0x20 || ch === 0x09 || ch === 0x0B || ch === 0x0C || ch === 0xA0 ||
  7569. ch >= 0x1680 && NON_ASCII_WHITESPACES.indexOf(ch) >= 0;
  7570. }
  7571. // 7.3 Line Terminators
  7572. function isLineTerminator(ch) {
  7573. return ch === 0x0A || ch === 0x0D || ch === 0x2028 || ch === 0x2029;
  7574. }
  7575. // 7.6 Identifier Names and Identifiers
  7576. function fromCodePoint(cp) {
  7577. if (cp <= 0xFFFF) { return String.fromCharCode(cp); }
  7578. var cu1 = String.fromCharCode(Math.floor((cp - 0x10000) / 0x400) + 0xD800);
  7579. var cu2 = String.fromCharCode(((cp - 0x10000) % 0x400) + 0xDC00);
  7580. return cu1 + cu2;
  7581. }
  7582. IDENTIFIER_START = new Array(0x80);
  7583. for(ch = 0; ch < 0x80; ++ch) {
  7584. IDENTIFIER_START[ch] =
  7585. ch >= 0x61 && ch <= 0x7A || // a..z
  7586. ch >= 0x41 && ch <= 0x5A || // A..Z
  7587. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  7588. }
  7589. IDENTIFIER_PART = new Array(0x80);
  7590. for(ch = 0; ch < 0x80; ++ch) {
  7591. IDENTIFIER_PART[ch] =
  7592. ch >= 0x61 && ch <= 0x7A || // a..z
  7593. ch >= 0x41 && ch <= 0x5A || // A..Z
  7594. ch >= 0x30 && ch <= 0x39 || // 0..9
  7595. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  7596. }
  7597. function isIdentifierStartES5(ch) {
  7598. return ch < 0x80 ? IDENTIFIER_START[ch] : ES5Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  7599. }
  7600. function isIdentifierPartES5(ch) {
  7601. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES5Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  7602. }
  7603. function isIdentifierStartES6(ch) {
  7604. return ch < 0x80 ? IDENTIFIER_START[ch] : ES6Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  7605. }
  7606. function isIdentifierPartES6(ch) {
  7607. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES6Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  7608. }
  7609. module.exports = {
  7610. isDecimalDigit: isDecimalDigit,
  7611. isHexDigit: isHexDigit,
  7612. isOctalDigit: isOctalDigit,
  7613. isWhiteSpace: isWhiteSpace,
  7614. isLineTerminator: isLineTerminator,
  7615. isIdentifierStartES5: isIdentifierStartES5,
  7616. isIdentifierPartES5: isIdentifierPartES5,
  7617. isIdentifierStartES6: isIdentifierStartES6,
  7618. isIdentifierPartES6: isIdentifierPartES6
  7619. };
  7620. }());
  7621. /* vim: set sw=4 ts=4 et tw=80 : */
  7622. });
  7623. var keyword = createCommonjsModule(function (module) {
  7624. /*
  7625. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7626. Redistribution and use in source and binary forms, with or without
  7627. modification, are permitted provided that the following conditions are met:
  7628. * Redistributions of source code must retain the above copyright
  7629. notice, this list of conditions and the following disclaimer.
  7630. * Redistributions in binary form must reproduce the above copyright
  7631. notice, this list of conditions and the following disclaimer in the
  7632. documentation and/or other materials provided with the distribution.
  7633. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7634. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7635. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7636. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7637. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7638. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7639. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7640. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7641. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7642. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7643. */
  7644. (function () {
  7645. 'use strict';
  7646. var code$$1 = code;
  7647. function isStrictModeReservedWordES6(id) {
  7648. switch (id) {
  7649. case 'implements':
  7650. case 'interface':
  7651. case 'package':
  7652. case 'private':
  7653. case 'protected':
  7654. case 'public':
  7655. case 'static':
  7656. case 'let':
  7657. return true;
  7658. default:
  7659. return false;
  7660. }
  7661. }
  7662. function isKeywordES5(id, strict) {
  7663. // yield should not be treated as keyword under non-strict mode.
  7664. if (!strict && id === 'yield') {
  7665. return false;
  7666. }
  7667. return isKeywordES6(id, strict);
  7668. }
  7669. function isKeywordES6(id, strict) {
  7670. if (strict && isStrictModeReservedWordES6(id)) {
  7671. return true;
  7672. }
  7673. switch (id.length) {
  7674. case 2:
  7675. return (id === 'if') || (id === 'in') || (id === 'do');
  7676. case 3:
  7677. return (id === 'var') || (id === 'for') || (id === 'new') || (id === 'try');
  7678. case 4:
  7679. return (id === 'this') || (id === 'else') || (id === 'case') ||
  7680. (id === 'void') || (id === 'with') || (id === 'enum');
  7681. case 5:
  7682. return (id === 'while') || (id === 'break') || (id === 'catch') ||
  7683. (id === 'throw') || (id === 'const') || (id === 'yield') ||
  7684. (id === 'class') || (id === 'super');
  7685. case 6:
  7686. return (id === 'return') || (id === 'typeof') || (id === 'delete') ||
  7687. (id === 'switch') || (id === 'export') || (id === 'import');
  7688. case 7:
  7689. return (id === 'default') || (id === 'finally') || (id === 'extends');
  7690. case 8:
  7691. return (id === 'function') || (id === 'continue') || (id === 'debugger');
  7692. case 10:
  7693. return (id === 'instanceof');
  7694. default:
  7695. return false;
  7696. }
  7697. }
  7698. function isReservedWordES5(id, strict) {
  7699. return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);
  7700. }
  7701. function isReservedWordES6(id, strict) {
  7702. return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);
  7703. }
  7704. function isRestrictedWord(id) {
  7705. return id === 'eval' || id === 'arguments';
  7706. }
  7707. function isIdentifierNameES5(id) {
  7708. var i, iz, ch;
  7709. if (id.length === 0) { return false; }
  7710. ch = id.charCodeAt(0);
  7711. if (!code$$1.isIdentifierStartES5(ch)) {
  7712. return false;
  7713. }
  7714. for (i = 1, iz = id.length; i < iz; ++i) {
  7715. ch = id.charCodeAt(i);
  7716. if (!code$$1.isIdentifierPartES5(ch)) {
  7717. return false;
  7718. }
  7719. }
  7720. return true;
  7721. }
  7722. function decodeUtf16(lead, trail) {
  7723. return (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  7724. }
  7725. function isIdentifierNameES6(id) {
  7726. var i, iz, ch, lowCh, check;
  7727. if (id.length === 0) { return false; }
  7728. check = code$$1.isIdentifierStartES6;
  7729. for (i = 0, iz = id.length; i < iz; ++i) {
  7730. ch = id.charCodeAt(i);
  7731. if (0xD800 <= ch && ch <= 0xDBFF) {
  7732. ++i;
  7733. if (i >= iz) { return false; }
  7734. lowCh = id.charCodeAt(i);
  7735. if (!(0xDC00 <= lowCh && lowCh <= 0xDFFF)) {
  7736. return false;
  7737. }
  7738. ch = decodeUtf16(ch, lowCh);
  7739. }
  7740. if (!check(ch)) {
  7741. return false;
  7742. }
  7743. check = code$$1.isIdentifierPartES6;
  7744. }
  7745. return true;
  7746. }
  7747. function isIdentifierES5(id, strict) {
  7748. return isIdentifierNameES5(id) && !isReservedWordES5(id, strict);
  7749. }
  7750. function isIdentifierES6(id, strict) {
  7751. return isIdentifierNameES6(id) && !isReservedWordES6(id, strict);
  7752. }
  7753. module.exports = {
  7754. isKeywordES5: isKeywordES5,
  7755. isKeywordES6: isKeywordES6,
  7756. isReservedWordES5: isReservedWordES5,
  7757. isReservedWordES6: isReservedWordES6,
  7758. isRestrictedWord: isRestrictedWord,
  7759. isIdentifierNameES5: isIdentifierNameES5,
  7760. isIdentifierNameES6: isIdentifierNameES6,
  7761. isIdentifierES5: isIdentifierES5,
  7762. isIdentifierES6: isIdentifierES6
  7763. };
  7764. }());
  7765. /* vim: set sw=4 ts=4 et tw=80 : */
  7766. });
  7767. var utils$2 = createCommonjsModule(function (module, exports) {
  7768. /*
  7769. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  7770. Redistribution and use in source and binary forms, with or without
  7771. modification, are permitted provided that the following conditions are met:
  7772. * Redistributions of source code must retain the above copyright
  7773. notice, this list of conditions and the following disclaimer.
  7774. * Redistributions in binary form must reproduce the above copyright
  7775. notice, this list of conditions and the following disclaimer in the
  7776. documentation and/or other materials provided with the distribution.
  7777. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  7778. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  7779. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  7780. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  7781. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  7782. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  7783. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  7784. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  7785. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  7786. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7787. */
  7788. (function () {
  7789. 'use strict';
  7790. exports.ast = ast;
  7791. exports.code = code;
  7792. exports.keyword = keyword;
  7793. }());
  7794. /* vim: set sw=4 ts=4 et tw=80 : */
  7795. });
  7796. const doc$2 = doc;
  7797. const docUtils$4 = doc$2.utils;
  7798. const docBuilders$5 = doc$2.builders;
  7799. const indent$3 = docBuilders$5.indent;
  7800. const join$3 = docBuilders$5.join;
  7801. const hardline$3 = docBuilders$5.hardline;
  7802. const softline$2 = docBuilders$5.softline;
  7803. const literalline$2 = docBuilders$5.literalline;
  7804. const concat$4 = docBuilders$5.concat;
  7805. const dedentToRoot$1 = docBuilders$5.dedentToRoot;
  7806. function embed(path$$1, print, textToDoc /*, options */) {
  7807. const node = path$$1.getValue();
  7808. const parent = path$$1.getParentNode();
  7809. const parentParent = path$$1.getParentNode(1);
  7810. switch (node.type) {
  7811. case "TemplateLiteral": {
  7812. const isCss = [isStyledJsx, isStyledComponents, isCssProp].some(isIt =>
  7813. isIt(path$$1)
  7814. );
  7815. if (isCss) {
  7816. // Get full template literal with expressions replaced by placeholders
  7817. const rawQuasis = node.quasis.map(q => q.value.raw);
  7818. let placeholderID = 0;
  7819. const text = rawQuasis.reduce((prevVal, currVal, idx) => {
  7820. return idx == 0
  7821. ? currVal
  7822. : prevVal +
  7823. "@prettier-placeholder-" +
  7824. placeholderID++ +
  7825. "-id" +
  7826. currVal;
  7827. }, "");
  7828. const doc$$2 = textToDoc(text, { parser: "css" });
  7829. return transformCssDoc(doc$$2, path$$1, print);
  7830. }
  7831. /*
  7832. * react-relay and graphql-tag
  7833. * graphql`...`
  7834. * graphql.experimental`...`
  7835. * gql`...`
  7836. *
  7837. * This intentionally excludes Relay Classic tags, as Prettier does not
  7838. * support Relay Classic formatting.
  7839. */
  7840. if (
  7841. parent &&
  7842. ((parent.type === "TaggedTemplateExpression" &&
  7843. ((parent.tag.type === "MemberExpression" &&
  7844. parent.tag.object.name === "graphql" &&
  7845. parent.tag.property.name === "experimental") ||
  7846. (parent.tag.type === "Identifier" &&
  7847. (parent.tag.name === "gql" || parent.tag.name === "graphql")))) ||
  7848. (parent.type === "CallExpression" &&
  7849. parent.callee.type === "Identifier" &&
  7850. parent.callee.name === "graphql"))
  7851. ) {
  7852. const expressionDocs = node.expressions
  7853. ? path$$1.map(print, "expressions")
  7854. : [];
  7855. const numQuasis = node.quasis.length;
  7856. if (numQuasis === 1 && node.quasis[0].value.raw.trim() === "") {
  7857. return "``";
  7858. }
  7859. const parts = [];
  7860. for (let i = 0; i < numQuasis; i++) {
  7861. const templateElement = node.quasis[i];
  7862. const isFirst = i === 0;
  7863. const isLast = i === numQuasis - 1;
  7864. const text = templateElement.value.cooked;
  7865. // Bail out if any of the quasis have an invalid escape sequence
  7866. // (which would make the `cooked` value be `null` or `undefined`)
  7867. if (typeof text !== "string") {
  7868. return null;
  7869. }
  7870. const lines = text.split("\n");
  7871. const numLines = lines.length;
  7872. const expressionDoc = expressionDocs[i];
  7873. const startsWithBlankLine =
  7874. numLines > 2 && lines[0].trim() === "" && lines[1].trim() === "";
  7875. const endsWithBlankLine =
  7876. numLines > 2 &&
  7877. lines[numLines - 1].trim() === "" &&
  7878. lines[numLines - 2].trim() === "";
  7879. const commentsAndWhitespaceOnly = lines.every(line =>
  7880. /^\s*(?:#[^\r\n]*)?$/.test(line)
  7881. );
  7882. // Bail out if an interpolation occurs within a comment.
  7883. if (!isLast && /#[^\r\n]*$/.test(lines[numLines - 1])) {
  7884. return null;
  7885. }
  7886. let doc$$2 = null;
  7887. if (commentsAndWhitespaceOnly) {
  7888. doc$$2 = printGraphqlComments(lines);
  7889. } else {
  7890. try {
  7891. doc$$2 = docUtils$4.stripTrailingHardline(
  7892. textToDoc(text, { parser: "graphql" })
  7893. );
  7894. } catch (error) {
  7895. if (process.env.PRETTIER_DEBUG) {
  7896. throw error;
  7897. }
  7898. // Bail if any part fails to parse.
  7899. return null;
  7900. }
  7901. }
  7902. if (doc$$2) {
  7903. doc$$2 = escapeBackticks(doc$$2);
  7904. if (!isFirst && startsWithBlankLine) {
  7905. parts.push("");
  7906. }
  7907. parts.push(doc$$2);
  7908. if (!isLast && endsWithBlankLine) {
  7909. parts.push("");
  7910. }
  7911. } else if (!isFirst && !isLast && startsWithBlankLine) {
  7912. parts.push("");
  7913. }
  7914. if (expressionDoc) {
  7915. parts.push(concat$4(["${", expressionDoc, "}"]));
  7916. }
  7917. }
  7918. return concat$4([
  7919. "`",
  7920. indent$3(concat$4([hardline$3, join$3(hardline$3, parts)])),
  7921. hardline$3,
  7922. "`"
  7923. ]);
  7924. }
  7925. break;
  7926. }
  7927. case "TemplateElement": {
  7928. /**
  7929. * md`...`
  7930. * markdown`...`
  7931. */
  7932. if (
  7933. parentParent &&
  7934. (parentParent.type === "TaggedTemplateExpression" &&
  7935. parent.quasis.length === 1 &&
  7936. (parentParent.tag.type === "Identifier" &&
  7937. (parentParent.tag.name === "md" ||
  7938. parentParent.tag.name === "markdown")))
  7939. ) {
  7940. const text = parent.quasis[0].value.cooked;
  7941. const indentation = getIndentation(text);
  7942. const hasIndent = indentation !== "";
  7943. return concat$4([
  7944. hasIndent
  7945. ? indent$3(
  7946. concat$4([
  7947. softline$2,
  7948. printMarkdown(
  7949. text.replace(new RegExp(`^${indentation}`, "gm"), "")
  7950. )
  7951. ])
  7952. )
  7953. : concat$4([literalline$2, dedentToRoot$1(printMarkdown(text))]),
  7954. softline$2
  7955. ]);
  7956. }
  7957. break;
  7958. }
  7959. }
  7960. function printMarkdown(text) {
  7961. const doc$$2 = textToDoc(text, { parser: "markdown", __inJsTemplate: true });
  7962. return docUtils$4.stripTrailingHardline(escapeBackticks(doc$$2));
  7963. }
  7964. }
  7965. function getIndentation(str) {
  7966. const firstMatchedIndent = str.match(/^([^\S\n]*)\S/m);
  7967. return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
  7968. }
  7969. function escapeBackticks(doc$$2) {
  7970. return docUtils$4.mapDoc(doc$$2, currentDoc => {
  7971. if (!currentDoc.parts) {
  7972. return currentDoc;
  7973. }
  7974. const parts = [];
  7975. currentDoc.parts.forEach(part => {
  7976. if (typeof part === "string") {
  7977. parts.push(part.replace(/`/g, "\\`"));
  7978. } else {
  7979. parts.push(part);
  7980. }
  7981. });
  7982. return Object.assign({}, currentDoc, { parts });
  7983. });
  7984. }
  7985. function transformCssDoc(quasisDoc, path$$1, print) {
  7986. const parentNode = path$$1.getValue();
  7987. const isEmpty =
  7988. parentNode.quasis.length === 1 && !parentNode.quasis[0].value.raw.trim();
  7989. if (isEmpty) {
  7990. return "``";
  7991. }
  7992. const expressionDocs = parentNode.expressions
  7993. ? path$$1.map(print, "expressions")
  7994. : [];
  7995. const newDoc = replacePlaceholders(quasisDoc, expressionDocs);
  7996. /* istanbul ignore if */
  7997. if (!newDoc) {
  7998. throw new Error("Couldn't insert all the expressions");
  7999. }
  8000. return concat$4([
  8001. "`",
  8002. indent$3(concat$4([hardline$3, docUtils$4.stripTrailingHardline(newDoc)])),
  8003. softline$2,
  8004. "`"
  8005. ]);
  8006. }
  8007. // Search all the placeholders in the quasisDoc tree
  8008. // and replace them with the expression docs one by one
  8009. // returns a new doc with all the placeholders replaced,
  8010. // or null if it couldn't replace any expression
  8011. function replacePlaceholders(quasisDoc, expressionDocs) {
  8012. if (!expressionDocs || !expressionDocs.length) {
  8013. return quasisDoc;
  8014. }
  8015. const expressions = expressionDocs.slice();
  8016. let replaceCounter = 0;
  8017. const newDoc = docUtils$4.mapDoc(quasisDoc, doc$$2 => {
  8018. if (!doc$$2 || !doc$$2.parts || !doc$$2.parts.length) {
  8019. return doc$$2;
  8020. }
  8021. let parts = doc$$2.parts;
  8022. const atIndex = parts.indexOf("@");
  8023. const placeholderIndex = atIndex + 1;
  8024. if (
  8025. atIndex > -1 &&
  8026. typeof parts[placeholderIndex] === "string" &&
  8027. parts[placeholderIndex].startsWith("prettier-placeholder")
  8028. ) {
  8029. // If placeholder is split, join it
  8030. const at = parts[atIndex];
  8031. const placeholder = parts[placeholderIndex];
  8032. const rest = parts.slice(placeholderIndex + 1);
  8033. parts = parts
  8034. .slice(0, atIndex)
  8035. .concat([at + placeholder])
  8036. .concat(rest);
  8037. }
  8038. const atPlaceholderIndex = parts.findIndex(
  8039. part =>
  8040. typeof part === "string" && part.startsWith("@prettier-placeholder")
  8041. );
  8042. if (atPlaceholderIndex > -1) {
  8043. const placeholder = parts[atPlaceholderIndex];
  8044. const rest = parts.slice(atPlaceholderIndex + 1);
  8045. const placeholderMatch = placeholder.match(
  8046. /@prettier-placeholder-(.+)-id([\s\S]*)/
  8047. );
  8048. const placeholderID = placeholderMatch[1];
  8049. // When the expression has a suffix appended, like:
  8050. // animation: linear ${time}s ease-out;
  8051. const suffix = placeholderMatch[2];
  8052. const expression = expressions[placeholderID];
  8053. replaceCounter++;
  8054. parts = parts
  8055. .slice(0, atPlaceholderIndex)
  8056. .concat(["${", expression, "}" + suffix])
  8057. .concat(rest);
  8058. }
  8059. return Object.assign({}, doc$$2, {
  8060. parts: parts
  8061. });
  8062. });
  8063. return expressions.length === replaceCounter ? newDoc : null;
  8064. }
  8065. function printGraphqlComments(lines) {
  8066. const parts = [];
  8067. let seenComment = false;
  8068. lines.map(textLine => textLine.trim()).forEach((textLine, i, array) => {
  8069. // Lines are either whitespace only, or a comment (with poential whitespace
  8070. // around it). Drop whitespace-only lines.
  8071. if (textLine === "") {
  8072. return;
  8073. }
  8074. if (array[i - 1] === "" && seenComment) {
  8075. // If a non-first comment is preceded by a blank (whitespace only) line,
  8076. // add in a blank line.
  8077. parts.push(concat$4([hardline$3, textLine]));
  8078. } else {
  8079. parts.push(textLine);
  8080. }
  8081. seenComment = true;
  8082. });
  8083. // If `lines` was whitespace only, return `null`.
  8084. return parts.length === 0 ? null : join$3(hardline$3, parts);
  8085. }
  8086. /**
  8087. * Template literal in this context:
  8088. * <style jsx>{`div{color:red}`}</style>
  8089. */
  8090. function isStyledJsx(path$$1) {
  8091. const node = path$$1.getValue();
  8092. const parent = path$$1.getParentNode();
  8093. const parentParent = path$$1.getParentNode(1);
  8094. return (
  8095. parentParent &&
  8096. node.quasis &&
  8097. parent.type === "JSXExpressionContainer" &&
  8098. parentParent.type === "JSXElement" &&
  8099. parentParent.openingElement.name.name === "style" &&
  8100. parentParent.openingElement.attributes.some(
  8101. attribute => attribute.name.name === "jsx"
  8102. )
  8103. );
  8104. }
  8105. /**
  8106. * styled-components template literals
  8107. */
  8108. function isStyledComponents(path$$1) {
  8109. const parent = path$$1.getParentNode();
  8110. if (!parent || parent.type !== "TaggedTemplateExpression") {
  8111. return false;
  8112. }
  8113. const tag = parent.tag;
  8114. switch (tag.type) {
  8115. case "MemberExpression":
  8116. return (
  8117. // styled.foo``
  8118. isStyledIdentifier(tag.object) ||
  8119. // Component.extend``
  8120. (/^[A-Z]/.test(tag.object.name) && tag.property.name === "extend")
  8121. );
  8122. case "CallExpression":
  8123. return (
  8124. // styled(Component)``
  8125. isStyledIdentifier(tag.callee) ||
  8126. (tag.callee.type === "MemberExpression" &&
  8127. // styled.foo.attr({})``
  8128. ((tag.callee.object.type === "MemberExpression" &&
  8129. isStyledIdentifier(tag.callee.object.object)) ||
  8130. // styled(Component).attr({})``
  8131. (tag.callee.object.type === "CallExpression" &&
  8132. isStyledIdentifier(tag.callee.object.callee))))
  8133. );
  8134. case "Identifier":
  8135. // css``
  8136. return tag.name === "css";
  8137. default:
  8138. return false;
  8139. }
  8140. }
  8141. /**
  8142. * JSX element with CSS prop
  8143. */
  8144. function isCssProp(path$$1) {
  8145. const parent = path$$1.getParentNode();
  8146. const parentParent = path$$1.getParentNode(1);
  8147. return (
  8148. parentParent &&
  8149. parent.type === "JSXExpressionContainer" &&
  8150. parentParent.type === "JSXAttribute" &&
  8151. parentParent.name.type === "JSXIdentifier" &&
  8152. parentParent.name.name === "css"
  8153. );
  8154. }
  8155. function isStyledIdentifier(node) {
  8156. return node.type === "Identifier" && node.name === "styled";
  8157. }
  8158. var embed_1 = embed;
  8159. function clean(ast, newObj, parent) {
  8160. // We remove extra `;` and add them when needed
  8161. if (ast.type === "EmptyStatement") {
  8162. return null;
  8163. }
  8164. // We move text around, including whitespaces and add {" "}
  8165. if (ast.type === "JSXText") {
  8166. return null;
  8167. }
  8168. if (
  8169. ast.type === "JSXExpressionContainer" &&
  8170. ast.expression.type === "Literal" &&
  8171. ast.expression.value === " "
  8172. ) {
  8173. return null;
  8174. }
  8175. // (TypeScript) Ignore `static` in `constructor(static p) {}`
  8176. // and `export` in `constructor(export p) {}`
  8177. if (
  8178. ast.type === "TSParameterProperty" &&
  8179. ast.accessibility === null &&
  8180. !ast.readonly
  8181. ) {
  8182. return {
  8183. type: "Identifier",
  8184. name: ast.parameter.name,
  8185. typeAnnotation: newObj.parameter.typeAnnotation,
  8186. decorators: newObj.decorators
  8187. };
  8188. }
  8189. // (TypeScript) ignore empty `specifiers` array
  8190. if (
  8191. ast.type === "TSNamespaceExportDeclaration" &&
  8192. ast.specifiers &&
  8193. ast.specifiers.length === 0
  8194. ) {
  8195. delete newObj.specifiers;
  8196. }
  8197. // (TypeScript) bypass TSParenthesizedType
  8198. if (
  8199. ast.type === "TSParenthesizedType" &&
  8200. ast.typeAnnotation.type === "TSTypeAnnotation"
  8201. ) {
  8202. return newObj.typeAnnotation.typeAnnotation;
  8203. }
  8204. // We convert <div></div> to <div />
  8205. if (ast.type === "JSXOpeningElement") {
  8206. delete newObj.selfClosing;
  8207. }
  8208. if (ast.type === "JSXElement") {
  8209. delete newObj.closingElement;
  8210. }
  8211. // We change {'key': value} into {key: value}
  8212. if (
  8213. (ast.type === "Property" ||
  8214. ast.type === "MethodDefinition" ||
  8215. ast.type === "ClassProperty" ||
  8216. ast.type === "TSPropertySignature" ||
  8217. ast.type === "ObjectTypeProperty") &&
  8218. typeof ast.key === "object" &&
  8219. ast.key &&
  8220. (ast.key.type === "Literal" || ast.key.type === "Identifier")
  8221. ) {
  8222. delete newObj.key;
  8223. }
  8224. // Remove raw and cooked values from TemplateElement when it's CSS
  8225. // styled-jsx
  8226. if (
  8227. ast.type === "JSXElement" &&
  8228. ast.openingElement.name.name === "style" &&
  8229. ast.openingElement.attributes.some(attr => attr.name.name === "jsx")
  8230. ) {
  8231. const templateLiterals = newObj.children
  8232. .filter(
  8233. child =>
  8234. child.type === "JSXExpressionContainer" &&
  8235. child.expression.type === "TemplateLiteral"
  8236. )
  8237. .map(container => container.expression);
  8238. const quasis = templateLiterals.reduce(
  8239. (quasis, templateLiteral) => quasis.concat(templateLiteral.quasis),
  8240. []
  8241. );
  8242. quasis.forEach(q => delete q.value);
  8243. }
  8244. // CSS template literals in css prop
  8245. if (
  8246. ast.type === "JSXAttribute" &&
  8247. ast.name.name === "css" &&
  8248. ast.value.type === "JSXExpressionContainer" &&
  8249. ast.value.expression.type === "TemplateLiteral"
  8250. ) {
  8251. newObj.value.expression.quasis.forEach(q => delete q.value);
  8252. }
  8253. // styled-components, graphql, markdown
  8254. if (
  8255. ast.type === "TaggedTemplateExpression" &&
  8256. (ast.tag.type === "MemberExpression" ||
  8257. (ast.tag.type === "Identifier" &&
  8258. (ast.tag.name === "gql" ||
  8259. ast.tag.name === "graphql" ||
  8260. ast.tag.name === "css" ||
  8261. ast.tag.name === "md" ||
  8262. ast.tag.name === "markdown")) ||
  8263. ast.tag.type === "CallExpression")
  8264. ) {
  8265. newObj.quasi.quasis.forEach(quasi => delete quasi.value);
  8266. }
  8267. if (
  8268. ast.type === "TemplateLiteral" &&
  8269. parent.type === "CallExpression" &&
  8270. parent.callee.name === "graphql"
  8271. ) {
  8272. newObj.quasis.forEach(quasi => delete quasi.value);
  8273. }
  8274. }
  8275. var clean_1 = clean;
  8276. var detectNewline = createCommonjsModule(function (module) {
  8277. 'use strict';
  8278. module.exports = function (str) {
  8279. if (typeof str !== 'string') {
  8280. throw new TypeError('Expected a string');
  8281. }
  8282. var newlines = (str.match(/(?:\r?\n)/g) || []);
  8283. if (newlines.length === 0) {
  8284. return null;
  8285. }
  8286. var crlf = newlines.filter(function (el) {
  8287. return el === '\r\n';
  8288. }).length;
  8289. var lf = newlines.length - crlf;
  8290. return crlf > lf ? '\r\n' : '\n';
  8291. };
  8292. module.exports.graceful = function (str) {
  8293. return module.exports(str) || '\n';
  8294. };
  8295. });
  8296. var build = createCommonjsModule(function (module, exports) {
  8297. 'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.
  8298. extract = extract;exports.
  8299. strip = strip;exports.
  8300. parse = parse;exports.
  8301. parseWithComments = parseWithComments;exports.
  8302. 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 };} /**
  8303. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  8304. *
  8305. * This source code is licensed under the MIT license found in the
  8306. * LICENSE file in the root directory of this source tree.
  8307. *
  8308. *
  8309. */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
  8310. 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
  8311. 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 = '/**';
  8312. const start = ' *';
  8313. const tail = ' */';
  8314. const keys = Object.keys(pragmas);
  8315. const printedObject = keys.
  8316. map(key => printKeyValues(key, pragmas[key])).
  8317. reduce((arr, next) => arr.concat(next), []).
  8318. map(keyValue => start + ' ' + keyValue + line).
  8319. join('');
  8320. if (!comments) {
  8321. if (keys.length === 0) {
  8322. return '';
  8323. }
  8324. if (keys.length === 1 && !Array.isArray(pragmas[keys[0]])) {
  8325. const value = pragmas[keys[0]];
  8326. return `${head} ${printKeyValues(keys[0], value)[0]}${tail}`;
  8327. }
  8328. }
  8329. const printedComments =
  8330. comments.
  8331. split(line).
  8332. map(textLine => `${start} ${textLine}`).
  8333. join(line) + line;
  8334. return (
  8335. head +
  8336. line + (
  8337. comments ? printedComments : '') + (
  8338. comments && keys.length ? start + line : '') +
  8339. printedObject +
  8340. tail);
  8341. }
  8342. function printKeyValues(key, valueOrArray) {
  8343. return [].concat(valueOrArray).map(value => `@${key} ${value}`.trim());
  8344. }
  8345. });
  8346. unwrapExports(build);
  8347. function hasPragma$1(text) {
  8348. const pragmas = Object.keys(build.parse(build.extract(text)));
  8349. return pragmas.indexOf("prettier") !== -1 || pragmas.indexOf("format") !== -1;
  8350. }
  8351. function insertPragma$1(text) {
  8352. const parsedDocblock = build.parseWithComments(build.extract(text));
  8353. const pragmas = Object.assign({ format: "" }, parsedDocblock.pragmas);
  8354. const newDocblock = build.print({
  8355. pragmas,
  8356. comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, "") // remove leading newlines
  8357. });
  8358. const strippedText = build.strip(text);
  8359. const separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n";
  8360. return newDocblock + separatingNewlines + strippedText;
  8361. }
  8362. var pragma = {
  8363. hasPragma: hasPragma$1,
  8364. insertPragma: insertPragma$1
  8365. };
  8366. const addLeadingComment$2 = utilShared.addLeadingComment;
  8367. const addTrailingComment$2 = utilShared.addTrailingComment;
  8368. const addDanglingComment$2 = utilShared.addDanglingComment;
  8369. function handleOwnLineComment(comment, text, options, ast, isLastComment) {
  8370. const precedingNode = comment.precedingNode;
  8371. const enclosingNode = comment.enclosingNode;
  8372. const followingNode = comment.followingNode;
  8373. if (
  8374. handleLastFunctionArgComments(
  8375. text,
  8376. precedingNode,
  8377. enclosingNode,
  8378. followingNode,
  8379. comment,
  8380. options
  8381. ) ||
  8382. handleMemberExpressionComments(enclosingNode, followingNode, comment) ||
  8383. handleIfStatementComments(
  8384. text,
  8385. precedingNode,
  8386. enclosingNode,
  8387. followingNode,
  8388. comment,
  8389. options
  8390. ) ||
  8391. handleTryStatementComments(enclosingNode, followingNode, comment) ||
  8392. handleClassComments(enclosingNode, precedingNode, followingNode, comment) ||
  8393. handleImportSpecifierComments(enclosingNode, comment) ||
  8394. handleForComments(enclosingNode, precedingNode, comment) ||
  8395. handleUnionTypeComments(
  8396. precedingNode,
  8397. enclosingNode,
  8398. followingNode,
  8399. comment
  8400. ) ||
  8401. handleOnlyComments(enclosingNode, ast, comment, isLastComment) ||
  8402. handleImportDeclarationComments(
  8403. text,
  8404. enclosingNode,
  8405. precedingNode,
  8406. comment,
  8407. options
  8408. ) ||
  8409. handleAssignmentPatternComments(enclosingNode, comment) ||
  8410. handleMethodNameComments(
  8411. text,
  8412. enclosingNode,
  8413. precedingNode,
  8414. comment,
  8415. options
  8416. )
  8417. ) {
  8418. return true;
  8419. }
  8420. return false;
  8421. }
  8422. function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
  8423. const precedingNode = comment.precedingNode;
  8424. const enclosingNode = comment.enclosingNode;
  8425. const followingNode = comment.followingNode;
  8426. if (
  8427. handleLastFunctionArgComments(
  8428. text,
  8429. precedingNode,
  8430. enclosingNode,
  8431. followingNode,
  8432. comment,
  8433. options
  8434. ) ||
  8435. handleConditionalExpressionComments(
  8436. enclosingNode,
  8437. precedingNode,
  8438. followingNode,
  8439. comment,
  8440. text,
  8441. options
  8442. ) ||
  8443. handleImportSpecifierComments(enclosingNode, comment) ||
  8444. handleIfStatementComments(
  8445. text,
  8446. precedingNode,
  8447. enclosingNode,
  8448. followingNode,
  8449. comment,
  8450. options
  8451. ) ||
  8452. handleClassComments(enclosingNode, precedingNode, followingNode, comment) ||
  8453. handleLabeledStatementComments(enclosingNode, comment) ||
  8454. handleCallExpressionComments(precedingNode, enclosingNode, comment) ||
  8455. handlePropertyComments(enclosingNode, comment) ||
  8456. handleOnlyComments(enclosingNode, ast, comment, isLastComment) ||
  8457. handleTypeAliasComments(enclosingNode, followingNode, comment) ||
  8458. handleVariableDeclaratorComments(enclosingNode, followingNode, comment)
  8459. ) {
  8460. return true;
  8461. }
  8462. return false;
  8463. }
  8464. function handleRemainingComment(comment, text, options, ast, isLastComment) {
  8465. const precedingNode = comment.precedingNode;
  8466. const enclosingNode = comment.enclosingNode;
  8467. const followingNode = comment.followingNode;
  8468. if (
  8469. handleIfStatementComments(
  8470. text,
  8471. precedingNode,
  8472. enclosingNode,
  8473. followingNode,
  8474. comment,
  8475. options
  8476. ) ||
  8477. handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) ||
  8478. handleCommentInEmptyParens(text, enclosingNode, comment, options) ||
  8479. handleMethodNameComments(
  8480. text,
  8481. enclosingNode,
  8482. precedingNode,
  8483. comment,
  8484. options
  8485. ) ||
  8486. handleOnlyComments(enclosingNode, ast, comment, isLastComment) ||
  8487. handleCommentAfterArrowParams(text, enclosingNode, comment, options) ||
  8488. handleFunctionNameComments(
  8489. text,
  8490. enclosingNode,
  8491. precedingNode,
  8492. comment,
  8493. options
  8494. ) ||
  8495. handleBreakAndContinueStatementComments(enclosingNode, comment)
  8496. ) {
  8497. return true;
  8498. }
  8499. return false;
  8500. }
  8501. function addBlockStatementFirstComment(node, comment) {
  8502. const body = node.body.filter(n => n.type !== "EmptyStatement");
  8503. if (body.length === 0) {
  8504. addDanglingComment$2(node, comment);
  8505. } else {
  8506. addLeadingComment$2(body[0], comment);
  8507. }
  8508. }
  8509. function addBlockOrNotComment(node, comment) {
  8510. if (node.type === "BlockStatement") {
  8511. addBlockStatementFirstComment(node, comment);
  8512. } else {
  8513. addLeadingComment$2(node, comment);
  8514. }
  8515. }
  8516. // There are often comments before the else clause of if statements like
  8517. //
  8518. // if (1) { ... }
  8519. // // comment
  8520. // else { ... }
  8521. //
  8522. // They are being attached as leading comments of the BlockExpression which
  8523. // is not well printed. What we want is to instead move the comment inside
  8524. // of the block and make it leadingComment of the first element of the block
  8525. // or dangling comment of the block if there is nothing inside
  8526. //
  8527. // if (1) { ... }
  8528. // else {
  8529. // // comment
  8530. // ...
  8531. // }
  8532. function handleIfStatementComments(
  8533. text,
  8534. precedingNode,
  8535. enclosingNode,
  8536. followingNode,
  8537. comment,
  8538. options
  8539. ) {
  8540. if (
  8541. !enclosingNode ||
  8542. enclosingNode.type !== "IfStatement" ||
  8543. !followingNode
  8544. ) {
  8545. return false;
  8546. }
  8547. // We unfortunately have no way using the AST or location of nodes to know
  8548. // if the comment is positioned before the condition parenthesis:
  8549. // if (a /* comment */) {}
  8550. // The only workaround I found is to look at the next character to see if
  8551. // it is a ).
  8552. const nextCharacter = util$1.getNextNonSpaceNonCommentCharacter(
  8553. text,
  8554. comment,
  8555. options.locEnd
  8556. );
  8557. if (nextCharacter === ")") {
  8558. addTrailingComment$2(precedingNode, comment);
  8559. return true;
  8560. }
  8561. // Comments before `else`:
  8562. // - treat as trailing comments of the consequent, if it's a BlockStatement
  8563. // - treat as a dangling comment otherwise
  8564. if (
  8565. precedingNode === enclosingNode.consequent &&
  8566. followingNode === enclosingNode.alternate
  8567. ) {
  8568. if (precedingNode.type === "BlockStatement") {
  8569. addTrailingComment$2(precedingNode, comment);
  8570. } else {
  8571. addDanglingComment$2(enclosingNode, comment);
  8572. }
  8573. return true;
  8574. }
  8575. if (followingNode.type === "BlockStatement") {
  8576. addBlockStatementFirstComment(followingNode, comment);
  8577. return true;
  8578. }
  8579. if (followingNode.type === "IfStatement") {
  8580. addBlockOrNotComment(followingNode.consequent, comment);
  8581. return true;
  8582. }
  8583. // For comments positioned after the condition parenthesis in an if statement
  8584. // before the consequent with or without brackets on, such as
  8585. // if (a) /* comment */ {} or if (a) /* comment */ true,
  8586. // we look at the next character to see if it is a { or if the following node
  8587. // is the consequent for the if statement
  8588. if (nextCharacter === "{" || enclosingNode.consequent === followingNode) {
  8589. addLeadingComment$2(followingNode, comment);
  8590. return true;
  8591. }
  8592. return false;
  8593. }
  8594. // Same as IfStatement but for TryStatement
  8595. function handleTryStatementComments(enclosingNode, followingNode, comment) {
  8596. if (
  8597. !enclosingNode ||
  8598. enclosingNode.type !== "TryStatement" ||
  8599. !followingNode
  8600. ) {
  8601. return false;
  8602. }
  8603. if (followingNode.type === "BlockStatement") {
  8604. addBlockStatementFirstComment(followingNode, comment);
  8605. return true;
  8606. }
  8607. if (followingNode.type === "TryStatement") {
  8608. addBlockOrNotComment(followingNode.finalizer, comment);
  8609. return true;
  8610. }
  8611. if (followingNode.type === "CatchClause") {
  8612. addBlockOrNotComment(followingNode.body, comment);
  8613. return true;
  8614. }
  8615. return false;
  8616. }
  8617. function handleMemberExpressionComments(enclosingNode, followingNode, comment) {
  8618. if (
  8619. enclosingNode &&
  8620. enclosingNode.type === "MemberExpression" &&
  8621. followingNode &&
  8622. followingNode.type === "Identifier"
  8623. ) {
  8624. addLeadingComment$2(enclosingNode, comment);
  8625. return true;
  8626. }
  8627. return false;
  8628. }
  8629. function handleConditionalExpressionComments(
  8630. enclosingNode,
  8631. precedingNode,
  8632. followingNode,
  8633. comment,
  8634. text,
  8635. options
  8636. ) {
  8637. const isSameLineAsPrecedingNode =
  8638. precedingNode &&
  8639. !util$1.hasNewlineInRange(
  8640. text,
  8641. options.locEnd(precedingNode),
  8642. options.locStart(comment)
  8643. );
  8644. if (
  8645. (!precedingNode || !isSameLineAsPrecedingNode) &&
  8646. enclosingNode &&
  8647. enclosingNode.type === "ConditionalExpression" &&
  8648. followingNode
  8649. ) {
  8650. addLeadingComment$2(followingNode, comment);
  8651. return true;
  8652. }
  8653. return false;
  8654. }
  8655. function handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) {
  8656. if (
  8657. enclosingNode &&
  8658. (enclosingNode.type === "ObjectProperty" ||
  8659. enclosingNode.type === "Property") &&
  8660. enclosingNode.shorthand &&
  8661. enclosingNode.key === precedingNode &&
  8662. enclosingNode.value.type === "AssignmentPattern"
  8663. ) {
  8664. addTrailingComment$2(enclosingNode.value.left, comment);
  8665. return true;
  8666. }
  8667. return false;
  8668. }
  8669. function handleClassComments(
  8670. enclosingNode,
  8671. precedingNode,
  8672. followingNode,
  8673. comment
  8674. ) {
  8675. if (
  8676. enclosingNode &&
  8677. (enclosingNode.type === "ClassDeclaration" ||
  8678. enclosingNode.type === "ClassExpression") &&
  8679. (enclosingNode.decorators && enclosingNode.decorators.length > 0) &&
  8680. !(followingNode && followingNode.type === "Decorator")
  8681. ) {
  8682. if (!enclosingNode.decorators || enclosingNode.decorators.length === 0) {
  8683. addLeadingComment$2(enclosingNode, comment);
  8684. } else {
  8685. addTrailingComment$2(
  8686. enclosingNode.decorators[enclosingNode.decorators.length - 1],
  8687. comment
  8688. );
  8689. }
  8690. return true;
  8691. }
  8692. return false;
  8693. }
  8694. function handleMethodNameComments(
  8695. text,
  8696. enclosingNode,
  8697. precedingNode,
  8698. comment,
  8699. options
  8700. ) {
  8701. // This is only needed for estree parsers (flow, typescript) to attach
  8702. // after a method name:
  8703. // obj = { fn /*comment*/() {} };
  8704. if (
  8705. enclosingNode &&
  8706. precedingNode &&
  8707. (enclosingNode.type === "Property" ||
  8708. enclosingNode.type === "MethodDefinition") &&
  8709. precedingNode.type === "Identifier" &&
  8710. enclosingNode.key === precedingNode &&
  8711. // special Property case: { key: /*comment*/(value) };
  8712. // comment should be attached to value instead of key
  8713. util$1.getNextNonSpaceNonCommentCharacter(
  8714. text,
  8715. precedingNode,
  8716. options.locEnd
  8717. ) !== ":"
  8718. ) {
  8719. addTrailingComment$2(precedingNode, comment);
  8720. return true;
  8721. }
  8722. // Print comments between decorators and class methods as a trailing comment
  8723. // on the decorator node instead of the method node
  8724. if (
  8725. precedingNode &&
  8726. enclosingNode &&
  8727. precedingNode.type === "Decorator" &&
  8728. (enclosingNode.type === "ClassMethod" ||
  8729. enclosingNode.type === "ClassProperty" ||
  8730. enclosingNode.type === "TSAbstractClassProperty" ||
  8731. enclosingNode.type === "TSAbstractMethodDefinition" ||
  8732. enclosingNode.type === "MethodDefinition")
  8733. ) {
  8734. addTrailingComment$2(precedingNode, comment);
  8735. return true;
  8736. }
  8737. return false;
  8738. }
  8739. function handleFunctionNameComments(
  8740. text,
  8741. enclosingNode,
  8742. precedingNode,
  8743. comment,
  8744. options
  8745. ) {
  8746. if (
  8747. util$1.getNextNonSpaceNonCommentCharacter(
  8748. text,
  8749. comment,
  8750. options.locEnd
  8751. ) !== "("
  8752. ) {
  8753. return false;
  8754. }
  8755. if (
  8756. precedingNode &&
  8757. enclosingNode &&
  8758. (enclosingNode.type === "FunctionDeclaration" ||
  8759. enclosingNode.type === "FunctionExpression" ||
  8760. enclosingNode.type === "ClassMethod" ||
  8761. enclosingNode.type === "MethodDefinition" ||
  8762. enclosingNode.type === "ObjectMethod")
  8763. ) {
  8764. addTrailingComment$2(precedingNode, comment);
  8765. return true;
  8766. }
  8767. return false;
  8768. }
  8769. function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
  8770. if (!(enclosingNode && enclosingNode.type === "ArrowFunctionExpression")) {
  8771. return false;
  8772. }
  8773. const index = utilShared.getNextNonSpaceNonCommentCharacterIndex(
  8774. text,
  8775. comment,
  8776. options
  8777. );
  8778. if (text.substr(index, 2) === "=>") {
  8779. addDanglingComment$2(enclosingNode, comment);
  8780. return true;
  8781. }
  8782. return false;
  8783. }
  8784. function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
  8785. if (
  8786. util$1.getNextNonSpaceNonCommentCharacter(
  8787. text,
  8788. comment,
  8789. options.locEnd
  8790. ) !== ")"
  8791. ) {
  8792. return false;
  8793. }
  8794. // Only add dangling comments to fix the case when no params are present,
  8795. // i.e. a function without any argument.
  8796. if (
  8797. enclosingNode &&
  8798. (((enclosingNode.type === "FunctionDeclaration" ||
  8799. enclosingNode.type === "FunctionExpression" ||
  8800. (enclosingNode.type === "ArrowFunctionExpression" &&
  8801. (enclosingNode.body.type !== "CallExpression" ||
  8802. enclosingNode.body.arguments.length === 0)) ||
  8803. enclosingNode.type === "ClassMethod" ||
  8804. enclosingNode.type === "ObjectMethod") &&
  8805. enclosingNode.params.length === 0) ||
  8806. (enclosingNode.type === "CallExpression" &&
  8807. enclosingNode.arguments.length === 0))
  8808. ) {
  8809. addDanglingComment$2(enclosingNode, comment);
  8810. return true;
  8811. }
  8812. if (
  8813. enclosingNode &&
  8814. (enclosingNode.type === "MethodDefinition" &&
  8815. enclosingNode.value.params.length === 0)
  8816. ) {
  8817. addDanglingComment$2(enclosingNode.value, comment);
  8818. return true;
  8819. }
  8820. return false;
  8821. }
  8822. function handleLastFunctionArgComments(
  8823. text,
  8824. precedingNode,
  8825. enclosingNode,
  8826. followingNode,
  8827. comment,
  8828. options
  8829. ) {
  8830. // Type definitions functions
  8831. if (
  8832. precedingNode &&
  8833. precedingNode.type === "FunctionTypeParam" &&
  8834. enclosingNode &&
  8835. enclosingNode.type === "FunctionTypeAnnotation" &&
  8836. followingNode &&
  8837. followingNode.type !== "FunctionTypeParam"
  8838. ) {
  8839. addTrailingComment$2(precedingNode, comment);
  8840. return true;
  8841. }
  8842. // Real functions
  8843. if (
  8844. precedingNode &&
  8845. (precedingNode.type === "Identifier" ||
  8846. precedingNode.type === "AssignmentPattern") &&
  8847. enclosingNode &&
  8848. (enclosingNode.type === "ArrowFunctionExpression" ||
  8849. enclosingNode.type === "FunctionExpression" ||
  8850. enclosingNode.type === "FunctionDeclaration" ||
  8851. enclosingNode.type === "ObjectMethod" ||
  8852. enclosingNode.type === "ClassMethod") &&
  8853. util$1.getNextNonSpaceNonCommentCharacter(
  8854. text,
  8855. comment,
  8856. options.locEnd
  8857. ) === ")"
  8858. ) {
  8859. addTrailingComment$2(precedingNode, comment);
  8860. return true;
  8861. }
  8862. return false;
  8863. }
  8864. function handleImportSpecifierComments(enclosingNode, comment) {
  8865. if (enclosingNode && enclosingNode.type === "ImportSpecifier") {
  8866. addLeadingComment$2(enclosingNode, comment);
  8867. return true;
  8868. }
  8869. return false;
  8870. }
  8871. function handleLabeledStatementComments(enclosingNode, comment) {
  8872. if (enclosingNode && enclosingNode.type === "LabeledStatement") {
  8873. addLeadingComment$2(enclosingNode, comment);
  8874. return true;
  8875. }
  8876. return false;
  8877. }
  8878. function handleBreakAndContinueStatementComments(enclosingNode, comment) {
  8879. if (
  8880. enclosingNode &&
  8881. (enclosingNode.type === "ContinueStatement" ||
  8882. enclosingNode.type === "BreakStatement") &&
  8883. !enclosingNode.label
  8884. ) {
  8885. addTrailingComment$2(enclosingNode, comment);
  8886. return true;
  8887. }
  8888. return false;
  8889. }
  8890. function handleCallExpressionComments(precedingNode, enclosingNode, comment) {
  8891. if (
  8892. enclosingNode &&
  8893. enclosingNode.type === "CallExpression" &&
  8894. precedingNode &&
  8895. enclosingNode.callee === precedingNode &&
  8896. enclosingNode.arguments.length > 0
  8897. ) {
  8898. addLeadingComment$2(enclosingNode.arguments[0], comment);
  8899. return true;
  8900. }
  8901. return false;
  8902. }
  8903. function handleUnionTypeComments(
  8904. precedingNode,
  8905. enclosingNode,
  8906. followingNode,
  8907. comment
  8908. ) {
  8909. if (
  8910. enclosingNode &&
  8911. (enclosingNode.type === "UnionTypeAnnotation" ||
  8912. enclosingNode.type === "TSUnionType")
  8913. ) {
  8914. addTrailingComment$2(precedingNode, comment);
  8915. return true;
  8916. }
  8917. return false;
  8918. }
  8919. function handlePropertyComments(enclosingNode, comment) {
  8920. if (
  8921. enclosingNode &&
  8922. (enclosingNode.type === "Property" ||
  8923. enclosingNode.type === "ObjectProperty")
  8924. ) {
  8925. addLeadingComment$2(enclosingNode, comment);
  8926. return true;
  8927. }
  8928. return false;
  8929. }
  8930. function handleOnlyComments(enclosingNode, ast, comment, isLastComment) {
  8931. // With Flow the enclosingNode is undefined so use the AST instead.
  8932. if (ast && ast.body && ast.body.length === 0) {
  8933. if (isLastComment) {
  8934. addDanglingComment$2(ast, comment);
  8935. } else {
  8936. addLeadingComment$2(ast, comment);
  8937. }
  8938. return true;
  8939. } else if (
  8940. enclosingNode &&
  8941. enclosingNode.type === "Program" &&
  8942. enclosingNode.body.length === 0 &&
  8943. enclosingNode.directives &&
  8944. enclosingNode.directives.length === 0
  8945. ) {
  8946. if (isLastComment) {
  8947. addDanglingComment$2(enclosingNode, comment);
  8948. } else {
  8949. addLeadingComment$2(enclosingNode, comment);
  8950. }
  8951. return true;
  8952. }
  8953. return false;
  8954. }
  8955. function handleForComments(enclosingNode, precedingNode, comment) {
  8956. if (
  8957. enclosingNode &&
  8958. (enclosingNode.type === "ForInStatement" ||
  8959. enclosingNode.type === "ForOfStatement")
  8960. ) {
  8961. addLeadingComment$2(enclosingNode, comment);
  8962. return true;
  8963. }
  8964. return false;
  8965. }
  8966. function handleImportDeclarationComments(
  8967. text,
  8968. enclosingNode,
  8969. precedingNode,
  8970. comment,
  8971. options
  8972. ) {
  8973. if (
  8974. precedingNode &&
  8975. enclosingNode &&
  8976. enclosingNode.type === "ImportDeclaration" &&
  8977. util$1.hasNewline(text, options.locEnd(comment))
  8978. ) {
  8979. addTrailingComment$2(precedingNode, comment);
  8980. return true;
  8981. }
  8982. return false;
  8983. }
  8984. function handleAssignmentPatternComments(enclosingNode, comment) {
  8985. if (enclosingNode && enclosingNode.type === "AssignmentPattern") {
  8986. addLeadingComment$2(enclosingNode, comment);
  8987. return true;
  8988. }
  8989. return false;
  8990. }
  8991. function handleTypeAliasComments(enclosingNode, followingNode, comment) {
  8992. if (enclosingNode && enclosingNode.type === "TypeAlias") {
  8993. addLeadingComment$2(enclosingNode, comment);
  8994. return true;
  8995. }
  8996. return false;
  8997. }
  8998. function handleVariableDeclaratorComments(
  8999. enclosingNode,
  9000. followingNode,
  9001. comment
  9002. ) {
  9003. if (
  9004. enclosingNode &&
  9005. enclosingNode.type === "VariableDeclarator" &&
  9006. followingNode &&
  9007. (followingNode.type === "ObjectExpression" ||
  9008. followingNode.type === "ArrayExpression")
  9009. ) {
  9010. addLeadingComment$2(followingNode, comment);
  9011. return true;
  9012. }
  9013. return false;
  9014. }
  9015. var comments$2 = {
  9016. handleOwnLineComment,
  9017. handleEndOfLineComment,
  9018. handleRemainingComment
  9019. };
  9020. function needsParens(path$$1, options) {
  9021. const parent = path$$1.getParentNode();
  9022. if (!parent) {
  9023. return false;
  9024. }
  9025. const name = path$$1.getName();
  9026. const node = path$$1.getNode();
  9027. // If the value of this path is some child of a Node and not a Node
  9028. // itself, then it doesn't need parentheses. Only Node objects (in
  9029. // fact, only Expression nodes) need parentheses.
  9030. if (path$$1.getValue() !== node) {
  9031. return false;
  9032. }
  9033. // Only statements don't need parentheses.
  9034. if (isStatement(node)) {
  9035. return false;
  9036. }
  9037. // Closure compiler requires that type casted expressions to be surrounded by
  9038. // parentheses.
  9039. if (
  9040. util$1.hasClosureCompilerTypeCastComment(
  9041. options.originalText,
  9042. node,
  9043. options.locEnd
  9044. )
  9045. ) {
  9046. return true;
  9047. }
  9048. // Identifiers never need parentheses.
  9049. if (node.type === "Identifier") {
  9050. return false;
  9051. }
  9052. if (parent.type === "ParenthesizedExpression") {
  9053. return false;
  9054. }
  9055. // Add parens around the extends clause of a class. It is needed for almost
  9056. // all expressions.
  9057. if (
  9058. (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") &&
  9059. parent.superClass === node &&
  9060. (node.type === "ArrowFunctionExpression" ||
  9061. node.type === "AssignmentExpression" ||
  9062. node.type === "AwaitExpression" ||
  9063. node.type === "BinaryExpression" ||
  9064. node.type === "ConditionalExpression" ||
  9065. node.type === "LogicalExpression" ||
  9066. node.type === "NewExpression" ||
  9067. node.type === "ObjectExpression" ||
  9068. node.type === "ParenthesizedExpression" ||
  9069. node.type === "SequenceExpression" ||
  9070. node.type === "TaggedTemplateExpression" ||
  9071. node.type === "UnaryExpression" ||
  9072. node.type === "UpdateExpression" ||
  9073. node.type === "YieldExpression")
  9074. ) {
  9075. return true;
  9076. }
  9077. if (
  9078. (parent.type === "ArrowFunctionExpression" &&
  9079. parent.body === node &&
  9080. node.type !== "SequenceExpression" && // these have parens added anyway
  9081. util$1.startsWithNoLookaheadToken(
  9082. node,
  9083. /* forbidFunctionAndClass */ false
  9084. )) ||
  9085. (parent.type === "ExpressionStatement" &&
  9086. util$1.startsWithNoLookaheadToken(node, /* forbidFunctionAndClass */ true))
  9087. ) {
  9088. return true;
  9089. }
  9090. switch (node.type) {
  9091. case "CallExpression": {
  9092. let firstParentNotMemberExpression = parent;
  9093. let i = 0;
  9094. while (
  9095. firstParentNotMemberExpression &&
  9096. firstParentNotMemberExpression.type === "MemberExpression"
  9097. ) {
  9098. firstParentNotMemberExpression = path$$1.getParentNode(++i);
  9099. }
  9100. if (
  9101. firstParentNotMemberExpression.type === "NewExpression" &&
  9102. firstParentNotMemberExpression.callee === path$$1.getParentNode(i - 1)
  9103. ) {
  9104. return true;
  9105. }
  9106. return false;
  9107. }
  9108. case "SpreadElement":
  9109. case "SpreadProperty":
  9110. return (
  9111. parent.type === "MemberExpression" &&
  9112. name === "object" &&
  9113. parent.object === node
  9114. );
  9115. case "UpdateExpression":
  9116. if (parent.type === "UnaryExpression") {
  9117. return (
  9118. node.prefix &&
  9119. ((node.operator === "++" && parent.operator === "+") ||
  9120. (node.operator === "--" && parent.operator === "-"))
  9121. );
  9122. }
  9123. // else fallthrough
  9124. case "UnaryExpression":
  9125. switch (parent.type) {
  9126. case "UnaryExpression":
  9127. return (
  9128. node.operator === parent.operator &&
  9129. (node.operator === "+" || node.operator === "-")
  9130. );
  9131. case "MemberExpression":
  9132. return name === "object" && parent.object === node;
  9133. case "TaggedTemplateExpression":
  9134. return true;
  9135. case "NewExpression":
  9136. case "CallExpression":
  9137. return name === "callee" && parent.callee === node;
  9138. case "BinaryExpression":
  9139. return parent.operator === "**" && name === "left";
  9140. case "TSNonNullExpression":
  9141. return true;
  9142. default:
  9143. return false;
  9144. }
  9145. case "BinaryExpression": {
  9146. if (parent.type === "UpdateExpression") {
  9147. return true;
  9148. }
  9149. const isLeftOfAForStatement = node => {
  9150. let i = 0;
  9151. while (node) {
  9152. const parent = path$$1.getParentNode(i++);
  9153. if (!parent) {
  9154. return false;
  9155. }
  9156. if (parent.type === "ForStatement" && parent.init === node) {
  9157. return true;
  9158. }
  9159. node = parent;
  9160. }
  9161. return false;
  9162. };
  9163. if (node.operator === "in" && isLeftOfAForStatement(node)) {
  9164. return true;
  9165. }
  9166. }
  9167. // fallthrough
  9168. case "TSTypeAssertionExpression":
  9169. case "TSAsExpression":
  9170. case "LogicalExpression":
  9171. switch (parent.type) {
  9172. case "ConditionalExpression":
  9173. return node.type === "TSAsExpression";
  9174. case "CallExpression":
  9175. case "NewExpression":
  9176. return name === "callee" && parent.callee === node;
  9177. case "ClassDeclaration":
  9178. case "TSAbstractClassDeclaration":
  9179. return name === "superClass" && parent.superClass === node;
  9180. case "TSTypeAssertionExpression":
  9181. case "TaggedTemplateExpression":
  9182. case "UnaryExpression":
  9183. case "SpreadElement":
  9184. case "SpreadProperty":
  9185. case "ExperimentalSpreadProperty":
  9186. case "BindExpression":
  9187. case "AwaitExpression":
  9188. case "TSAsExpression":
  9189. case "TSNonNullExpression":
  9190. case "UpdateExpression":
  9191. return true;
  9192. case "MemberExpression":
  9193. return name === "object" && parent.object === node;
  9194. case "AssignmentExpression":
  9195. return (
  9196. parent.left === node &&
  9197. (node.type === "TSTypeAssertionExpression" ||
  9198. node.type === "TSAsExpression")
  9199. );
  9200. case "Decorator":
  9201. return (
  9202. parent.expression === node &&
  9203. (node.type === "TSTypeAssertionExpression" ||
  9204. node.type === "TSAsExpression")
  9205. );
  9206. case "BinaryExpression":
  9207. case "LogicalExpression": {
  9208. if (!node.operator && node.type !== "TSTypeAssertionExpression") {
  9209. return true;
  9210. }
  9211. const po = parent.operator;
  9212. const pp = util$1.getPrecedence(po);
  9213. const no = node.operator;
  9214. const np = util$1.getPrecedence(no);
  9215. if (pp > np) {
  9216. return true;
  9217. }
  9218. if ((po === "||" || po === "??") && no === "&&") {
  9219. return true;
  9220. }
  9221. if (pp === np && name === "right") {
  9222. assert.strictEqual(parent.right, node);
  9223. return true;
  9224. }
  9225. if (pp === np && !util$1.shouldFlatten(po, no)) {
  9226. return true;
  9227. }
  9228. // Add parenthesis when working with binary operators
  9229. // It's not stricly needed but helps with code understanding
  9230. if (util$1.isBitwiseOperator(po)) {
  9231. return true;
  9232. }
  9233. return false;
  9234. }
  9235. default:
  9236. return false;
  9237. }
  9238. case "TSParenthesizedType": {
  9239. const grandParent = path$$1.getParentNode(1);
  9240. if (
  9241. (parent.type === "TSTypeParameter" ||
  9242. parent.type === "TypeParameter" ||
  9243. parent.type === "VariableDeclarator" ||
  9244. parent.type === "TSTypeAnnotation" ||
  9245. parent.type === "GenericTypeAnnotation" ||
  9246. parent.type === "TSTypeReference") &&
  9247. (node.typeAnnotation.type === "TSTypeAnnotation" &&
  9248. node.typeAnnotation.typeAnnotation.type !== "TSFunctionType" &&
  9249. grandParent.type !== "TSTypeOperator")
  9250. ) {
  9251. return false;
  9252. }
  9253. // Delegate to inner TSParenthesizedType
  9254. if (node.typeAnnotation.type === "TSParenthesizedType") {
  9255. return false;
  9256. }
  9257. return true;
  9258. }
  9259. case "SequenceExpression":
  9260. switch (parent.type) {
  9261. case "ReturnStatement":
  9262. return false;
  9263. case "ForStatement":
  9264. // Although parentheses wouldn't hurt around sequence
  9265. // expressions in the head of for loops, traditional style
  9266. // dictates that e.g. i++, j++ should not be wrapped with
  9267. // parentheses.
  9268. return false;
  9269. case "ExpressionStatement":
  9270. return name !== "expression";
  9271. case "ArrowFunctionExpression":
  9272. // We do need parentheses, but SequenceExpressions are handled
  9273. // specially when printing bodies of arrow functions.
  9274. return name !== "body";
  9275. default:
  9276. // Otherwise err on the side of overparenthesization, adding
  9277. // explicit exceptions above if this proves overzealous.
  9278. return true;
  9279. }
  9280. case "YieldExpression":
  9281. if (
  9282. parent.type === "UnaryExpression" ||
  9283. parent.type === "AwaitExpression" ||
  9284. parent.type === "TSAsExpression" ||
  9285. parent.type === "TSNonNullExpression"
  9286. ) {
  9287. return true;
  9288. }
  9289. // else fallthrough
  9290. case "AwaitExpression":
  9291. switch (parent.type) {
  9292. case "TaggedTemplateExpression":
  9293. case "UnaryExpression":
  9294. case "BinaryExpression":
  9295. case "LogicalExpression":
  9296. case "SpreadElement":
  9297. case "SpreadProperty":
  9298. case "ExperimentalSpreadProperty":
  9299. case "TSAsExpression":
  9300. case "TSNonNullExpression":
  9301. return true;
  9302. case "MemberExpression":
  9303. return parent.object === node;
  9304. case "NewExpression":
  9305. case "CallExpression":
  9306. return parent.callee === node;
  9307. case "ConditionalExpression":
  9308. return parent.test === node;
  9309. default:
  9310. return false;
  9311. }
  9312. case "ArrayTypeAnnotation":
  9313. return parent.type === "NullableTypeAnnotation";
  9314. case "IntersectionTypeAnnotation":
  9315. case "UnionTypeAnnotation":
  9316. return (
  9317. parent.type === "ArrayTypeAnnotation" ||
  9318. parent.type === "NullableTypeAnnotation" ||
  9319. parent.type === "IntersectionTypeAnnotation" ||
  9320. parent.type === "UnionTypeAnnotation"
  9321. );
  9322. case "NullableTypeAnnotation":
  9323. return parent.type === "ArrayTypeAnnotation";
  9324. case "FunctionTypeAnnotation":
  9325. return (
  9326. parent.type === "UnionTypeAnnotation" ||
  9327. parent.type === "IntersectionTypeAnnotation" ||
  9328. parent.type === "ArrayTypeAnnotation"
  9329. );
  9330. case "StringLiteral":
  9331. case "NumericLiteral":
  9332. case "Literal":
  9333. if (
  9334. typeof node.value === "string" &&
  9335. parent.type === "ExpressionStatement" &&
  9336. // TypeScript workaround for eslint/typescript-eslint-parser#267
  9337. // See corresponding workaround in printer.js case: "Literal"
  9338. ((options.parser !== "typescript" && !parent.directive) ||
  9339. (options.parser === "typescript" &&
  9340. options.originalText.substr(options.locStart(node) - 1, 1) === "("))
  9341. ) {
  9342. // To avoid becoming a directive
  9343. const grandParent = path$$1.getParentNode(1);
  9344. return (
  9345. grandParent.type === "Program" ||
  9346. grandParent.type === "BlockStatement"
  9347. );
  9348. }
  9349. return (
  9350. parent.type === "MemberExpression" &&
  9351. typeof node.value === "number" &&
  9352. name === "object" &&
  9353. parent.object === node
  9354. );
  9355. case "AssignmentExpression": {
  9356. const grandParent = path$$1.getParentNode(1);
  9357. if (parent.type === "ArrowFunctionExpression" && parent.body === node) {
  9358. return true;
  9359. } else if (
  9360. parent.type === "ClassProperty" &&
  9361. parent.key === node &&
  9362. parent.computed
  9363. ) {
  9364. return false;
  9365. } else if (
  9366. parent.type === "TSPropertySignature" &&
  9367. parent.name === node
  9368. ) {
  9369. return false;
  9370. } else if (
  9371. parent.type === "ForStatement" &&
  9372. (parent.init === node || parent.update === node)
  9373. ) {
  9374. return false;
  9375. } else if (parent.type === "ExpressionStatement") {
  9376. return node.left.type === "ObjectPattern";
  9377. } else if (parent.type === "TSPropertySignature" && parent.key === node) {
  9378. return false;
  9379. } else if (parent.type === "AssignmentExpression") {
  9380. return false;
  9381. } else if (
  9382. parent.type === "SequenceExpression" &&
  9383. grandParent &&
  9384. grandParent.type === "ForStatement" &&
  9385. (grandParent.init === parent || grandParent.update === parent)
  9386. ) {
  9387. return false;
  9388. }
  9389. return true;
  9390. }
  9391. case "ConditionalExpression":
  9392. switch (parent.type) {
  9393. case "TaggedTemplateExpression":
  9394. case "UnaryExpression":
  9395. case "SpreadElement":
  9396. case "SpreadProperty":
  9397. case "ExperimentalSpreadProperty":
  9398. case "BinaryExpression":
  9399. case "LogicalExpression":
  9400. case "ExportDefaultDeclaration":
  9401. case "AwaitExpression":
  9402. case "JSXSpreadAttribute":
  9403. case "TSTypeAssertionExpression":
  9404. case "TypeCastExpression":
  9405. case "TSAsExpression":
  9406. case "TSNonNullExpression":
  9407. return true;
  9408. case "NewExpression":
  9409. case "CallExpression":
  9410. return name === "callee" && parent.callee === node;
  9411. case "ConditionalExpression":
  9412. return name === "test" && parent.test === node;
  9413. case "MemberExpression":
  9414. return name === "object" && parent.object === node;
  9415. default:
  9416. return false;
  9417. }
  9418. case "FunctionExpression":
  9419. switch (parent.type) {
  9420. case "CallExpression":
  9421. return name === "callee"; // Not strictly necessary, but it's clearer to the reader if IIFEs are wrapped in parentheses.
  9422. case "TaggedTemplateExpression":
  9423. return true; // This is basically a kind of IIFE.
  9424. case "ExportDefaultDeclaration":
  9425. return true;
  9426. default:
  9427. return false;
  9428. }
  9429. case "ArrowFunctionExpression":
  9430. switch (parent.type) {
  9431. case "CallExpression":
  9432. return name === "callee";
  9433. case "NewExpression":
  9434. return name === "callee";
  9435. case "MemberExpression":
  9436. return name === "object";
  9437. case "TSAsExpression":
  9438. case "BindExpression":
  9439. case "TaggedTemplateExpression":
  9440. case "UnaryExpression":
  9441. case "LogicalExpression":
  9442. case "BinaryExpression":
  9443. case "AwaitExpression":
  9444. case "TSTypeAssertionExpression":
  9445. return true;
  9446. case "ConditionalExpression":
  9447. return name === "test";
  9448. default:
  9449. return false;
  9450. }
  9451. case "ClassExpression":
  9452. return parent.type === "ExportDefaultDeclaration";
  9453. }
  9454. return false;
  9455. }
  9456. function isStatement(node) {
  9457. return (
  9458. node.type === "BlockStatement" ||
  9459. node.type === "BreakStatement" ||
  9460. node.type === "ClassBody" ||
  9461. node.type === "ClassDeclaration" ||
  9462. node.type === "ClassMethod" ||
  9463. node.type === "ClassProperty" ||
  9464. node.type === "ClassPrivateProperty" ||
  9465. node.type === "ContinueStatement" ||
  9466. node.type === "DebuggerStatement" ||
  9467. node.type === "DeclareClass" ||
  9468. node.type === "DeclareExportAllDeclaration" ||
  9469. node.type === "DeclareExportDeclaration" ||
  9470. node.type === "DeclareFunction" ||
  9471. node.type === "DeclareInterface" ||
  9472. node.type === "DeclareModule" ||
  9473. node.type === "DeclareModuleExports" ||
  9474. node.type === "DeclareVariable" ||
  9475. node.type === "DoWhileStatement" ||
  9476. node.type === "ExportAllDeclaration" ||
  9477. node.type === "ExportDefaultDeclaration" ||
  9478. node.type === "ExportNamedDeclaration" ||
  9479. node.type === "ExpressionStatement" ||
  9480. node.type === "ForAwaitStatement" ||
  9481. node.type === "ForInStatement" ||
  9482. node.type === "ForOfStatement" ||
  9483. node.type === "ForStatement" ||
  9484. node.type === "FunctionDeclaration" ||
  9485. node.type === "IfStatement" ||
  9486. node.type === "ImportDeclaration" ||
  9487. node.type === "InterfaceDeclaration" ||
  9488. node.type === "LabeledStatement" ||
  9489. node.type === "MethodDefinition" ||
  9490. node.type === "ReturnStatement" ||
  9491. node.type === "SwitchStatement" ||
  9492. node.type === "ThrowStatement" ||
  9493. node.type === "TryStatement" ||
  9494. node.type === "TSAbstractClassDeclaration" ||
  9495. node.type === "TSEnumDeclaration" ||
  9496. node.type === "TSImportEqualsDeclaration" ||
  9497. node.type === "TSInterfaceDeclaration" ||
  9498. node.type === "TSModuleDeclaration" ||
  9499. node.type === "TSNamespaceExportDeclaration" ||
  9500. node.type === "TypeAlias" ||
  9501. node.type === "VariableDeclaration" ||
  9502. node.type === "WhileStatement" ||
  9503. node.type === "WithStatement"
  9504. );
  9505. }
  9506. var needsParens_1 = needsParens;
  9507. // TODO(azz): anything that imports from main shouldn't be in a `language-*` dir.
  9508. const isIdentifierName = utils$2.keyword.isIdentifierNameES6;
  9509. const insertPragma = pragma.insertPragma;
  9510. const docBuilders = doc.builders;
  9511. const concat = docBuilders.concat;
  9512. const join = docBuilders.join;
  9513. const line = docBuilders.line;
  9514. const hardline = docBuilders.hardline;
  9515. const softline = docBuilders.softline;
  9516. const literalline = docBuilders.literalline;
  9517. const group = docBuilders.group;
  9518. const indent = docBuilders.indent;
  9519. const align = docBuilders.align;
  9520. const conditionalGroup = docBuilders.conditionalGroup;
  9521. const fill = docBuilders.fill;
  9522. const ifBreak = docBuilders.ifBreak;
  9523. const breakParent = docBuilders.breakParent;
  9524. const lineSuffixBoundary = docBuilders.lineSuffixBoundary;
  9525. const addAlignmentToDoc = docBuilders.addAlignmentToDoc;
  9526. const dedent = docBuilders.dedent;
  9527. const docUtils$3 = doc.utils;
  9528. const willBreak$1 = docUtils$3.willBreak;
  9529. const isLineNext$1 = docUtils$3.isLineNext;
  9530. const isEmpty$1 = docUtils$3.isEmpty;
  9531. function shouldPrintComma(options, level) {
  9532. level = level || "es5";
  9533. switch (options.trailingComma) {
  9534. case "all":
  9535. if (level === "all") {
  9536. return true;
  9537. }
  9538. // fallthrough
  9539. case "es5":
  9540. if (level === "es5") {
  9541. return true;
  9542. }
  9543. // fallthrough
  9544. case "none":
  9545. default:
  9546. return false;
  9547. }
  9548. }
  9549. function genericPrint(path$$1, options, printPath, args) {
  9550. const node = path$$1.getValue();
  9551. let needsParens = false;
  9552. const linesWithoutParens = printPathNoParens(path$$1, options, printPath, args);
  9553. if (!node || isEmpty$1(linesWithoutParens)) {
  9554. return linesWithoutParens;
  9555. }
  9556. const decorators = [];
  9557. if (
  9558. node.decorators &&
  9559. node.decorators.length > 0 &&
  9560. // If the parent node is an export declaration, it will be
  9561. // responsible for printing node.decorators.
  9562. !util$1.getParentExportDeclaration(path$$1)
  9563. ) {
  9564. let separator = hardline;
  9565. path$$1.each(decoratorPath => {
  9566. let prefix = "@";
  9567. let decorator = decoratorPath.getValue();
  9568. if (decorator.expression) {
  9569. decorator = decorator.expression;
  9570. prefix = "";
  9571. }
  9572. if (
  9573. node.decorators.length === 1 &&
  9574. node.type !== "ClassDeclaration" &&
  9575. node.type !== "MethodDefinition" &&
  9576. node.type !== "ClassMethod" &&
  9577. (decorator.type === "Identifier" ||
  9578. decorator.type === "MemberExpression" ||
  9579. (decorator.type === "CallExpression" &&
  9580. (decorator.arguments.length === 0 ||
  9581. (decorator.arguments.length === 1 &&
  9582. (isStringLiteral(decorator.arguments[0]) ||
  9583. decorator.arguments[0].type === "Identifier" ||
  9584. decorator.arguments[0].type === "MemberExpression")))))
  9585. ) {
  9586. separator = line;
  9587. }
  9588. decorators.push(prefix, printPath(decoratorPath), separator);
  9589. }, "decorators");
  9590. } else if (
  9591. util$1.isExportDeclaration(node) &&
  9592. node.declaration &&
  9593. node.declaration.decorators
  9594. ) {
  9595. // Export declarations are responsible for printing any decorators
  9596. // that logically apply to node.declaration.
  9597. path$$1.each(
  9598. decoratorPath => {
  9599. const decorator = decoratorPath.getValue();
  9600. const prefix = decorator.type === "Decorator" ? "" : "@";
  9601. decorators.push(prefix, printPath(decoratorPath), hardline);
  9602. },
  9603. "declaration",
  9604. "decorators"
  9605. );
  9606. } else {
  9607. // Nodes with decorators can't have parentheses, so we can avoid
  9608. // computing pathNeedsParens() except in this case.
  9609. needsParens = needsParens_1(path$$1, options);
  9610. }
  9611. const parts = [];
  9612. if (needsParens) {
  9613. parts.unshift("(");
  9614. }
  9615. parts.push(linesWithoutParens);
  9616. if (needsParens) {
  9617. parts.push(")");
  9618. }
  9619. if (decorators.length > 0) {
  9620. return group(concat(decorators.concat(parts)));
  9621. }
  9622. return concat(parts);
  9623. }
  9624. function hasPrettierIgnore(path$$1) {
  9625. return util$1.hasIgnoreComment(path$$1) || hasJsxIgnoreComment(path$$1);
  9626. }
  9627. function hasJsxIgnoreComment(path$$1) {
  9628. const node = path$$1.getValue();
  9629. const parent = path$$1.getParentNode();
  9630. if (!parent || !node || !isJSXNode(node) || !isJSXNode(parent)) {
  9631. return false;
  9632. }
  9633. // Lookup the previous sibling, ignoring any empty JSXText elements
  9634. const index = parent.children.indexOf(node);
  9635. let prevSibling = null;
  9636. for (let i = index; i > 0; i--) {
  9637. const candidate = parent.children[i - 1];
  9638. if (candidate.type === "JSXText" && !isMeaningfulJSXText(candidate)) {
  9639. continue;
  9640. }
  9641. prevSibling = candidate;
  9642. break;
  9643. }
  9644. return (
  9645. prevSibling &&
  9646. prevSibling.type === "JSXExpressionContainer" &&
  9647. prevSibling.expression.type === "JSXEmptyExpression" &&
  9648. prevSibling.expression.comments &&
  9649. prevSibling.expression.comments.find(
  9650. comment => comment.value.trim() === "prettier-ignore"
  9651. )
  9652. );
  9653. }
  9654. // The following is the shared logic for
  9655. // ternary operators, namely ConditionalExpression
  9656. // and TSConditionalType
  9657. function formatTernaryOperator(path$$1, options, print, operatorOptions) {
  9658. const n = path$$1.getValue();
  9659. const parts = [];
  9660. const operatorOpts = Object.assign(
  9661. {
  9662. beforeParts: () => [""],
  9663. afterParts: () => [""],
  9664. shouldCheckJsx: true,
  9665. operatorName: "ConditionalExpression",
  9666. consequentNode: "consequent",
  9667. alternateNode: "alternate",
  9668. testNode: "test",
  9669. breakNested: true
  9670. },
  9671. operatorOptions || {}
  9672. );
  9673. // We print a ConditionalExpression in either "JSX mode" or "normal mode".
  9674. // See tests/jsx/conditional-expression.js for more info.
  9675. let jsxMode = false;
  9676. const parent = path$$1.getParentNode();
  9677. let forceNoIndent = parent.type === operatorOpts.operatorName;
  9678. // Find the outermost non-ConditionalExpression parent, and the outermost
  9679. // ConditionalExpression parent. We'll use these to determine if we should
  9680. // print in JSX mode.
  9681. let currentParent;
  9682. let previousParent;
  9683. let i = 0;
  9684. do {
  9685. previousParent = currentParent || n;
  9686. currentParent = path$$1.getParentNode(i);
  9687. i++;
  9688. } while (currentParent && currentParent.type === operatorOpts.operatorName);
  9689. const firstNonConditionalParent = currentParent || parent;
  9690. const lastConditionalParent = previousParent;
  9691. if (
  9692. (operatorOpts.shouldCheckJsx && isJSXNode(n[operatorOpts.testNode])) ||
  9693. isJSXNode(n[operatorOpts.consequentNode]) ||
  9694. isJSXNode(n[operatorOpts.alternateNode]) ||
  9695. conditionalExpressionChainContainsJSX(lastConditionalParent)
  9696. ) {
  9697. jsxMode = true;
  9698. forceNoIndent = true;
  9699. // Even though they don't need parens, we wrap (almost) everything in
  9700. // parens when using ?: within JSX, because the parens are analogous to
  9701. // curly braces in an if statement.
  9702. const wrap = doc$$1 =>
  9703. concat([
  9704. ifBreak("(", ""),
  9705. indent(concat([softline, doc$$1])),
  9706. softline,
  9707. ifBreak(")", "")
  9708. ]);
  9709. // The only things we don't wrap are:
  9710. // * Nested conditional expressions in alternates
  9711. // * null
  9712. const isNull = node =>
  9713. node.type === "NullLiteral" ||
  9714. (node.type === "Literal" && node.value === null);
  9715. parts.push(
  9716. " ? ",
  9717. isNull(n[operatorOpts.consequentNode])
  9718. ? path$$1.call(print, operatorOpts.consequentNode)
  9719. : wrap(path$$1.call(print, operatorOpts.consequentNode)),
  9720. " : ",
  9721. n[operatorOpts.alternateNode].type === operatorOpts.operatorName ||
  9722. isNull(n[operatorOpts.alternateNode])
  9723. ? path$$1.call(print, operatorOpts.alternateNode)
  9724. : wrap(path$$1.call(print, operatorOpts.alternateNode))
  9725. );
  9726. } else {
  9727. // normal mode
  9728. const part = concat([
  9729. line,
  9730. "? ",
  9731. n[operatorOpts.consequentNode].type === operatorOpts.operatorName
  9732. ? ifBreak("", "(")
  9733. : "",
  9734. align(2, path$$1.call(print, operatorOpts.consequentNode)),
  9735. n[operatorOpts.consequentNode].type === operatorOpts.operatorName
  9736. ? ifBreak("", ")")
  9737. : "",
  9738. line,
  9739. ": ",
  9740. align(2, path$$1.call(print, operatorOpts.alternateNode))
  9741. ]);
  9742. parts.push(
  9743. parent.type === operatorOpts.operatorName
  9744. ? options.useTabs
  9745. ? dedent(indent(part))
  9746. : align(Math.max(0, options.tabWidth - 2), part)
  9747. : part
  9748. );
  9749. }
  9750. // We want a whole chain of ConditionalExpressions to all
  9751. // break if any of them break. That means we should only group around the
  9752. // outer-most ConditionalExpression.
  9753. const maybeGroup = doc$$1 =>
  9754. operatorOpts.breakNested
  9755. ? parent === firstNonConditionalParent
  9756. ? group(doc$$1)
  9757. : doc$$1
  9758. : group(doc$$1); // Always group in normal mode.
  9759. // Break the closing paren to keep the chain right after it:
  9760. // (a
  9761. // ? b
  9762. // : c
  9763. // ).call()
  9764. const breakClosingParen =
  9765. !jsxMode && parent.type === "MemberExpression" && !parent.computed;
  9766. return maybeGroup(
  9767. concat(
  9768. [].concat(
  9769. operatorOpts.beforeParts(),
  9770. forceNoIndent ? concat(parts) : indent(concat(parts)),
  9771. operatorOpts.afterParts(breakClosingParen)
  9772. )
  9773. )
  9774. );
  9775. }
  9776. function getTypeScriptMappedTypeModifier(tokenNode, keyword) {
  9777. if (tokenNode.type === "TSPlusToken") {
  9778. return "+" + keyword;
  9779. } else if (tokenNode.type === "TSMinusToken") {
  9780. return "-" + keyword;
  9781. }
  9782. return keyword;
  9783. }
  9784. function printPathNoParens(path$$1, options, print, args) {
  9785. const n = path$$1.getValue();
  9786. const semi = options.semi ? ";" : "";
  9787. if (!n) {
  9788. return "";
  9789. }
  9790. if (typeof n === "string") {
  9791. return n;
  9792. }
  9793. let parts = [];
  9794. switch (n.type) {
  9795. case "File":
  9796. return path$$1.call(print, "program");
  9797. case "Program":
  9798. // Babel 6
  9799. if (n.directives) {
  9800. path$$1.each(childPath => {
  9801. parts.push(print(childPath), semi, hardline);
  9802. if (
  9803. utilShared.isNextLineEmpty(
  9804. options.originalText,
  9805. childPath.getValue(),
  9806. options
  9807. )
  9808. ) {
  9809. parts.push(hardline);
  9810. }
  9811. }, "directives");
  9812. }
  9813. parts.push(
  9814. path$$1.call(bodyPath => {
  9815. return printStatementSequence(bodyPath, options, print);
  9816. }, "body")
  9817. );
  9818. parts.push(
  9819. comments.printDanglingComments(path$$1, options, /* sameIndent */ true)
  9820. );
  9821. // Only force a trailing newline if there were any contents.
  9822. if (n.body.length || n.comments) {
  9823. parts.push(hardline);
  9824. }
  9825. return concat(parts);
  9826. // Babel extension.
  9827. case "EmptyStatement":
  9828. return "";
  9829. case "ExpressionStatement":
  9830. // Detect Flow-parsed directives
  9831. if (n.directive) {
  9832. return concat([nodeStr(n.expression, options, true), semi]);
  9833. }
  9834. // Do not append semicolon after the only JSX element in a program
  9835. return concat([
  9836. path$$1.call(print, "expression"),
  9837. isTheOnlyJSXElementInMarkdown(options, path$$1) ? "" : semi
  9838. ]); // Babel extension.
  9839. case "ParenthesizedExpression":
  9840. return concat(["(", path$$1.call(print, "expression"), ")"]);
  9841. case "AssignmentExpression":
  9842. return printAssignment(
  9843. n.left,
  9844. path$$1.call(print, "left"),
  9845. concat([" ", n.operator]),
  9846. n.right,
  9847. path$$1.call(print, "right"),
  9848. options
  9849. );
  9850. case "BinaryExpression":
  9851. case "LogicalExpression": {
  9852. const parent = path$$1.getParentNode();
  9853. const parentParent = path$$1.getParentNode(1);
  9854. const isInsideParenthesis =
  9855. n !== parent.body &&
  9856. (parent.type === "IfStatement" ||
  9857. parent.type === "WhileStatement" ||
  9858. parent.type === "DoWhileStatement");
  9859. const parts = printBinaryishExpressions(
  9860. path$$1,
  9861. print,
  9862. options,
  9863. /* isNested */ false,
  9864. isInsideParenthesis
  9865. );
  9866. // if (
  9867. // this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft
  9868. // ) {
  9869. //
  9870. // looks super weird, we want to break the children if the parent breaks
  9871. //
  9872. // if (
  9873. // this.hasPlugin("dynamicImports") &&
  9874. // this.lookahead().type === tt.parenLeft
  9875. // ) {
  9876. if (isInsideParenthesis) {
  9877. return concat(parts);
  9878. }
  9879. // Break between the parens in unaries or in a member expression, i.e.
  9880. //
  9881. // (
  9882. // a &&
  9883. // b &&
  9884. // c
  9885. // ).call()
  9886. if (
  9887. parent.type === "UnaryExpression" ||
  9888. (parent.type === "MemberExpression" && !parent.computed)
  9889. ) {
  9890. return group(
  9891. concat([indent(concat([softline, concat(parts)])), softline])
  9892. );
  9893. }
  9894. // Avoid indenting sub-expressions in some cases where the first sub-expression is already
  9895. // indented accordingly. We should indent sub-expressions where the first case isn't indented.
  9896. const shouldNotIndent =
  9897. parent.type === "ReturnStatement" ||
  9898. (parent.type === "JSXExpressionContainer" &&
  9899. parentParent.type === "JSXAttribute") ||
  9900. (n === parent.body && parent.type === "ArrowFunctionExpression") ||
  9901. (n !== parent.body && parent.type === "ForStatement") ||
  9902. (parent.type === "ConditionalExpression" &&
  9903. parentParent.type !== "ReturnStatement");
  9904. const shouldIndentIfInlining =
  9905. parent.type === "AssignmentExpression" ||
  9906. parent.type === "VariableDeclarator" ||
  9907. parent.type === "ClassProperty" ||
  9908. parent.type === "TSAbstractClassProperty" ||
  9909. parent.type === "ClassPrivateProperty" ||
  9910. parent.type === "ObjectProperty" ||
  9911. parent.type === "Property";
  9912. const samePrecedenceSubExpression =
  9913. isBinaryish(n.left) &&
  9914. util$1.shouldFlatten(n.operator, n.left.operator);
  9915. if (
  9916. shouldNotIndent ||
  9917. (shouldInlineLogicalExpression(n) && !samePrecedenceSubExpression) ||
  9918. (!shouldInlineLogicalExpression(n) && shouldIndentIfInlining)
  9919. ) {
  9920. return group(concat(parts));
  9921. }
  9922. const rest = concat(parts.slice(1));
  9923. return group(
  9924. concat([
  9925. // Don't include the initial expression in the indentation
  9926. // level. The first item is guaranteed to be the first
  9927. // left-most expression.
  9928. parts.length > 0 ? parts[0] : "",
  9929. indent(rest)
  9930. ])
  9931. );
  9932. }
  9933. case "AssignmentPattern":
  9934. return concat([
  9935. path$$1.call(print, "left"),
  9936. " = ",
  9937. path$$1.call(print, "right")
  9938. ]);
  9939. case "TSTypeAssertionExpression":
  9940. return concat([
  9941. "<",
  9942. path$$1.call(print, "typeAnnotation"),
  9943. ">",
  9944. path$$1.call(print, "expression")
  9945. ]);
  9946. case "MemberExpression": {
  9947. const parent = path$$1.getParentNode();
  9948. let firstNonMemberParent;
  9949. let i = 0;
  9950. do {
  9951. firstNonMemberParent = path$$1.getParentNode(i);
  9952. i++;
  9953. } while (
  9954. firstNonMemberParent &&
  9955. (firstNonMemberParent.type === "MemberExpression" ||
  9956. firstNonMemberParent.type === "TSNonNullExpression")
  9957. );
  9958. const shouldInline =
  9959. (firstNonMemberParent &&
  9960. (firstNonMemberParent.type === "NewExpression" ||
  9961. (firstNonMemberParent.type === "VariableDeclarator" &&
  9962. firstNonMemberParent.id.type !== "Identifier") ||
  9963. (firstNonMemberParent.type === "AssignmentExpression" &&
  9964. firstNonMemberParent.left.type !== "Identifier"))) ||
  9965. n.computed ||
  9966. (n.object.type === "Identifier" &&
  9967. n.property.type === "Identifier" &&
  9968. parent.type !== "MemberExpression");
  9969. return concat([
  9970. path$$1.call(print, "object"),
  9971. shouldInline
  9972. ? printMemberLookup(path$$1, options, print)
  9973. : group(
  9974. indent(
  9975. concat([softline, printMemberLookup(path$$1, options, print)])
  9976. )
  9977. )
  9978. ]);
  9979. }
  9980. case "MetaProperty":
  9981. return concat([
  9982. path$$1.call(print, "meta"),
  9983. ".",
  9984. path$$1.call(print, "property")
  9985. ]);
  9986. case "BindExpression":
  9987. if (n.object) {
  9988. parts.push(path$$1.call(print, "object"));
  9989. }
  9990. parts.push(printBindExpressionCallee(path$$1, options, print));
  9991. return concat(parts);
  9992. case "Identifier": {
  9993. return concat([
  9994. n.name,
  9995. printOptionalToken(path$$1),
  9996. printTypeAnnotation(path$$1, options, print)
  9997. ]);
  9998. }
  9999. case "SpreadElement":
  10000. case "SpreadElementPattern":
  10001. case "RestProperty":
  10002. case "ExperimentalRestProperty":
  10003. case "ExperimentalSpreadProperty":
  10004. case "SpreadProperty":
  10005. case "SpreadPropertyPattern":
  10006. case "RestElement":
  10007. case "ObjectTypeSpreadProperty":
  10008. return concat([
  10009. "...",
  10010. path$$1.call(print, "argument"),
  10011. printTypeAnnotation(path$$1, options, print)
  10012. ]);
  10013. case "FunctionDeclaration":
  10014. case "FunctionExpression":
  10015. if (isNodeStartingWithDeclare(n, options)) {
  10016. parts.push("declare ");
  10017. }
  10018. parts.push(printFunctionDeclaration(path$$1, print, options));
  10019. if (!n.body) {
  10020. parts.push(semi);
  10021. }
  10022. return concat(parts);
  10023. case "ArrowFunctionExpression": {
  10024. if (n.async) {
  10025. parts.push("async ");
  10026. }
  10027. if (shouldPrintParamsWithoutParens(path$$1, options)) {
  10028. parts.push(path$$1.call(print, "params", 0));
  10029. } else {
  10030. parts.push(
  10031. group(
  10032. concat([
  10033. printFunctionParams(
  10034. path$$1,
  10035. print,
  10036. options,
  10037. /* expandLast */ args &&
  10038. (args.expandLastArg || args.expandFirstArg),
  10039. /* printTypeParams */ true
  10040. ),
  10041. printReturnType(path$$1, print, options)
  10042. ])
  10043. )
  10044. );
  10045. }
  10046. const dangling = comments.printDanglingComments(
  10047. path$$1,
  10048. options,
  10049. /* sameIndent */ true,
  10050. comment => {
  10051. const nextCharacter = utilShared.getNextNonSpaceNonCommentCharacterIndex(
  10052. options.originalText,
  10053. comment,
  10054. options
  10055. );
  10056. return options.originalText.substr(nextCharacter, 2) === "=>";
  10057. }
  10058. );
  10059. if (dangling) {
  10060. parts.push(" ", dangling);
  10061. }
  10062. parts.push(" =>");
  10063. const body = path$$1.call(bodyPath => print(bodyPath, args), "body");
  10064. // We want to always keep these types of nodes on the same line
  10065. // as the arrow.
  10066. if (
  10067. !hasLeadingOwnLineComment(options.originalText, n.body, options) &&
  10068. (n.body.type === "ArrayExpression" ||
  10069. n.body.type === "ObjectExpression" ||
  10070. n.body.type === "BlockStatement" ||
  10071. isJSXNode(n.body) ||
  10072. isTemplateOnItsOwnLine(n.body, options.originalText, options) ||
  10073. n.body.type === "ArrowFunctionExpression")
  10074. ) {
  10075. return group(concat([concat(parts), " ", body]));
  10076. }
  10077. // We handle sequence expressions as the body of arrows specially,
  10078. // so that the required parentheses end up on their own lines.
  10079. if (n.body.type === "SequenceExpression") {
  10080. return group(
  10081. concat([
  10082. concat(parts),
  10083. group(
  10084. concat([" (", indent(concat([softline, body])), softline, ")"])
  10085. )
  10086. ])
  10087. );
  10088. }
  10089. // if the arrow function is expanded as last argument, we are adding a
  10090. // level of indentation and need to add a softline to align the closing )
  10091. // with the opening (, or if it's inside a JSXExpression (e.g. an attribute)
  10092. // we should align the expression's closing } with the line with the opening {.
  10093. const shouldAddSoftLine =
  10094. ((args && args.expandLastArg) ||
  10095. path$$1.getParentNode().type === "JSXExpressionContainer") &&
  10096. !(n.comments && n.comments.length);
  10097. const printTrailingComma =
  10098. args && args.expandLastArg && shouldPrintComma(options, "all");
  10099. // In order to avoid confusion between
  10100. // a => a ? a : a
  10101. // a <= a ? a : a
  10102. const shouldAddParens =
  10103. n.body.type === "ConditionalExpression" &&
  10104. !util$1.startsWithNoLookaheadToken(
  10105. n.body,
  10106. /* forbidFunctionAndClass */ false
  10107. );
  10108. return group(
  10109. concat([
  10110. concat(parts),
  10111. group(
  10112. concat([
  10113. indent(
  10114. concat([
  10115. line,
  10116. shouldAddParens ? ifBreak("", "(") : "",
  10117. body,
  10118. shouldAddParens ? ifBreak("", ")") : ""
  10119. ])
  10120. ),
  10121. shouldAddSoftLine
  10122. ? concat([ifBreak(printTrailingComma ? "," : ""), softline])
  10123. : ""
  10124. ])
  10125. )
  10126. ])
  10127. );
  10128. }
  10129. case "MethodDefinition":
  10130. case "TSAbstractMethodDefinition":
  10131. if (n.accessibility) {
  10132. parts.push(n.accessibility + " ");
  10133. }
  10134. if (n.static) {
  10135. parts.push("static ");
  10136. }
  10137. if (n.type === "TSAbstractMethodDefinition") {
  10138. parts.push("abstract ");
  10139. }
  10140. parts.push(printMethod(path$$1, options, print));
  10141. return concat(parts);
  10142. case "YieldExpression":
  10143. parts.push("yield");
  10144. if (n.delegate) {
  10145. parts.push("*");
  10146. }
  10147. if (n.argument) {
  10148. parts.push(" ", path$$1.call(print, "argument"));
  10149. }
  10150. return concat(parts);
  10151. case "AwaitExpression":
  10152. return concat(["await ", path$$1.call(print, "argument")]);
  10153. case "ImportSpecifier":
  10154. if (n.importKind) {
  10155. parts.push(path$$1.call(print, "importKind"), " ");
  10156. }
  10157. parts.push(path$$1.call(print, "imported"));
  10158. if (n.local && n.local.name !== n.imported.name) {
  10159. parts.push(" as ", path$$1.call(print, "local"));
  10160. }
  10161. return concat(parts);
  10162. case "ExportSpecifier":
  10163. parts.push(path$$1.call(print, "local"));
  10164. if (n.exported && n.exported.name !== n.local.name) {
  10165. parts.push(" as ", path$$1.call(print, "exported"));
  10166. }
  10167. return concat(parts);
  10168. case "ImportNamespaceSpecifier":
  10169. parts.push("* as ");
  10170. if (n.local) {
  10171. parts.push(path$$1.call(print, "local"));
  10172. } else if (n.id) {
  10173. parts.push(path$$1.call(print, "id"));
  10174. }
  10175. return concat(parts);
  10176. case "ImportDefaultSpecifier":
  10177. if (n.local) {
  10178. return path$$1.call(print, "local");
  10179. }
  10180. return path$$1.call(print, "id");
  10181. case "TSExportAssignment":
  10182. return concat(["export = ", path$$1.call(print, "expression"), semi]);
  10183. case "ExportDefaultDeclaration":
  10184. case "ExportNamedDeclaration":
  10185. return printExportDeclaration(path$$1, options, print);
  10186. case "ExportAllDeclaration":
  10187. parts.push("export ");
  10188. if (n.exportKind === "type") {
  10189. parts.push("type ");
  10190. }
  10191. parts.push("* from ", path$$1.call(print, "source"), semi);
  10192. return concat(parts);
  10193. case "ExportNamespaceSpecifier":
  10194. case "ExportDefaultSpecifier":
  10195. return path$$1.call(print, "exported");
  10196. case "ImportDeclaration": {
  10197. parts.push("import ");
  10198. if (n.importKind && n.importKind !== "value") {
  10199. parts.push(n.importKind + " ");
  10200. }
  10201. const standalones = [];
  10202. const grouped = [];
  10203. if (n.specifiers && n.specifiers.length > 0) {
  10204. path$$1.each(specifierPath => {
  10205. const value = specifierPath.getValue();
  10206. if (
  10207. value.type === "ImportDefaultSpecifier" ||
  10208. value.type === "ImportNamespaceSpecifier"
  10209. ) {
  10210. standalones.push(print(specifierPath));
  10211. } else {
  10212. grouped.push(print(specifierPath));
  10213. }
  10214. }, "specifiers");
  10215. if (standalones.length > 0) {
  10216. parts.push(join(", ", standalones));
  10217. }
  10218. if (standalones.length > 0 && grouped.length > 0) {
  10219. parts.push(", ");
  10220. }
  10221. if (
  10222. grouped.length === 1 &&
  10223. standalones.length === 0 &&
  10224. n.specifiers &&
  10225. !n.specifiers.some(node => node.comments)
  10226. ) {
  10227. parts.push(
  10228. concat([
  10229. "{",
  10230. options.bracketSpacing ? " " : "",
  10231. concat(grouped),
  10232. options.bracketSpacing ? " " : "",
  10233. "}"
  10234. ])
  10235. );
  10236. } else if (grouped.length >= 1) {
  10237. parts.push(
  10238. group(
  10239. concat([
  10240. "{",
  10241. indent(
  10242. concat([
  10243. options.bracketSpacing ? line : softline,
  10244. join(concat([",", line]), grouped)
  10245. ])
  10246. ),
  10247. ifBreak(shouldPrintComma(options) ? "," : ""),
  10248. options.bracketSpacing ? line : softline,
  10249. "}"
  10250. ])
  10251. )
  10252. );
  10253. }
  10254. parts.push(" from ");
  10255. } else if (
  10256. (n.importKind && n.importKind === "type") ||
  10257. // import {} from 'x'
  10258. /{\s*}/.test(
  10259. options.originalText.slice(
  10260. options.locStart(n),
  10261. options.locStart(n.source)
  10262. )
  10263. )
  10264. ) {
  10265. parts.push("{} from ");
  10266. }
  10267. parts.push(path$$1.call(print, "source"), semi);
  10268. return concat(parts);
  10269. }
  10270. case "Import":
  10271. return "import";
  10272. case "BlockStatement": {
  10273. const naked = path$$1.call(bodyPath => {
  10274. return printStatementSequence(bodyPath, options, print);
  10275. }, "body");
  10276. const hasContent = n.body.find(node => node.type !== "EmptyStatement");
  10277. const hasDirectives = n.directives && n.directives.length > 0;
  10278. const parent = path$$1.getParentNode();
  10279. const parentParent = path$$1.getParentNode(1);
  10280. if (
  10281. !hasContent &&
  10282. !hasDirectives &&
  10283. !hasDanglingComments(n) &&
  10284. (parent.type === "ArrowFunctionExpression" ||
  10285. parent.type === "FunctionExpression" ||
  10286. parent.type === "FunctionDeclaration" ||
  10287. parent.type === "ObjectMethod" ||
  10288. parent.type === "ClassMethod" ||
  10289. parent.type === "ForStatement" ||
  10290. parent.type === "WhileStatement" ||
  10291. parent.type === "DoWhileStatement" ||
  10292. (parent.type === "CatchClause" && !parentParent.finalizer))
  10293. ) {
  10294. return "{}";
  10295. }
  10296. parts.push("{");
  10297. // Babel 6
  10298. if (hasDirectives) {
  10299. path$$1.each(childPath => {
  10300. parts.push(indent(concat([hardline, print(childPath), semi])));
  10301. if (
  10302. utilShared.isNextLineEmpty(
  10303. options.originalText,
  10304. childPath.getValue(),
  10305. options
  10306. )
  10307. ) {
  10308. parts.push(hardline);
  10309. }
  10310. }, "directives");
  10311. }
  10312. if (hasContent) {
  10313. parts.push(indent(concat([hardline, naked])));
  10314. }
  10315. parts.push(comments.printDanglingComments(path$$1, options));
  10316. parts.push(hardline, "}");
  10317. return concat(parts);
  10318. }
  10319. case "ReturnStatement":
  10320. parts.push("return");
  10321. if (n.argument) {
  10322. if (returnArgumentHasLeadingComment(options, n.argument)) {
  10323. parts.push(
  10324. concat([
  10325. " (",
  10326. indent(concat([hardline, path$$1.call(print, "argument")])),
  10327. hardline,
  10328. ")"
  10329. ])
  10330. );
  10331. } else if (
  10332. n.argument.type === "LogicalExpression" ||
  10333. n.argument.type === "BinaryExpression" ||
  10334. n.argument.type === "SequenceExpression"
  10335. ) {
  10336. parts.push(
  10337. group(
  10338. concat([
  10339. ifBreak(" (", " "),
  10340. indent(concat([softline, path$$1.call(print, "argument")])),
  10341. softline,
  10342. ifBreak(")")
  10343. ])
  10344. )
  10345. );
  10346. } else {
  10347. parts.push(" ", path$$1.call(print, "argument"));
  10348. }
  10349. }
  10350. if (hasDanglingComments(n)) {
  10351. parts.push(
  10352. " ",
  10353. comments.printDanglingComments(path$$1, options, /* sameIndent */ true)
  10354. );
  10355. }
  10356. parts.push(semi);
  10357. return concat(parts);
  10358. case "NewExpression":
  10359. case "CallExpression": {
  10360. const isNew = n.type === "NewExpression";
  10361. const optional = printOptionalToken(path$$1);
  10362. if (
  10363. // We want to keep CommonJS- and AMD-style require calls, and AMD-style
  10364. // define calls, as a unit.
  10365. // e.g. `define(["some/lib", (lib) => {`
  10366. (!isNew &&
  10367. n.callee.type === "Identifier" &&
  10368. (n.callee.name === "require" || n.callee.name === "define")) ||
  10369. n.callee.type === "Import" ||
  10370. // Template literals as single arguments
  10371. (n.arguments.length === 1 &&
  10372. isTemplateOnItsOwnLine(
  10373. n.arguments[0],
  10374. options.originalText,
  10375. options
  10376. )) ||
  10377. // Keep test declarations on a single line
  10378. // e.g. `it('long name', () => {`
  10379. (!isNew && isTestCall(n, path$$1.getParentNode()))
  10380. ) {
  10381. return concat([
  10382. isNew ? "new " : "",
  10383. path$$1.call(print, "callee"),
  10384. optional,
  10385. path$$1.call(print, "typeParameters"),
  10386. concat(["(", join(", ", path$$1.map(print, "arguments")), ")"])
  10387. ]);
  10388. }
  10389. // We detect calls on member lookups and possibly print them in a
  10390. // special chain format. See `printMemberChain` for more info.
  10391. if (!isNew && isMemberish(n.callee)) {
  10392. return printMemberChain(path$$1, options, print);
  10393. }
  10394. return concat([
  10395. isNew ? "new " : "",
  10396. path$$1.call(print, "callee"),
  10397. optional,
  10398. printFunctionTypeParameters(path$$1, options, print),
  10399. printArgumentsList(path$$1, options, print)
  10400. ]);
  10401. }
  10402. case "TSInterfaceDeclaration":
  10403. if (isNodeStartingWithDeclare(n, options)) {
  10404. parts.push("declare ");
  10405. }
  10406. parts.push(
  10407. n.abstract ? "abstract " : "",
  10408. printTypeScriptModifiers(path$$1, options, print),
  10409. "interface ",
  10410. path$$1.call(print, "id"),
  10411. n.typeParameters ? path$$1.call(print, "typeParameters") : "",
  10412. " "
  10413. );
  10414. if (n.heritage.length) {
  10415. parts.push(
  10416. group(
  10417. indent(
  10418. concat([
  10419. softline,
  10420. "extends ",
  10421. indent(join(concat([",", line]), path$$1.map(print, "heritage"))),
  10422. " "
  10423. ])
  10424. )
  10425. )
  10426. );
  10427. }
  10428. parts.push(path$$1.call(print, "body"));
  10429. return concat(parts);
  10430. case "ObjectExpression":
  10431. case "ObjectPattern":
  10432. case "ObjectTypeAnnotation":
  10433. case "TSInterfaceBody":
  10434. case "TSTypeLiteral": {
  10435. const isTypeAnnotation = n.type === "ObjectTypeAnnotation";
  10436. const parent = path$$1.getParentNode(0);
  10437. const shouldBreak =
  10438. n.type === "TSInterfaceBody" ||
  10439. (n.type === "ObjectPattern" &&
  10440. parent.type !== "FunctionDeclaration" &&
  10441. parent.type !== "FunctionExpression" &&
  10442. parent.type !== "ArrowFunctionExpression" &&
  10443. parent.type !== "AssignmentPattern" &&
  10444. n.properties.some(
  10445. property =>
  10446. property.value &&
  10447. (property.value.type === "ObjectPattern" ||
  10448. property.value.type === "ArrayPattern")
  10449. )) ||
  10450. (n.type !== "ObjectPattern" &&
  10451. util$1.hasNewlineInRange(
  10452. options.originalText,
  10453. options.locStart(n),
  10454. options.locEnd(n)
  10455. ));
  10456. const isFlowInterfaceLikeBody =
  10457. isTypeAnnotation &&
  10458. parent &&
  10459. (parent.type === "InterfaceDeclaration" ||
  10460. parent.type === "DeclareInterface" ||
  10461. parent.type === "DeclareClass") &&
  10462. path$$1.getName() === "body";
  10463. const separator = isFlowInterfaceLikeBody
  10464. ? ";"
  10465. : n.type === "TSInterfaceBody" || n.type === "TSTypeLiteral"
  10466. ? ifBreak(semi, ";")
  10467. : ",";
  10468. const fields = [];
  10469. const leftBrace = n.exact ? "{|" : "{";
  10470. const rightBrace = n.exact ? "|}" : "}";
  10471. let propertiesField;
  10472. if (n.type === "TSTypeLiteral") {
  10473. propertiesField = "members";
  10474. } else if (n.type === "TSInterfaceBody") {
  10475. propertiesField = "body";
  10476. } else {
  10477. propertiesField = "properties";
  10478. }
  10479. if (isTypeAnnotation) {
  10480. fields.push("indexers", "callProperties");
  10481. }
  10482. fields.push(propertiesField);
  10483. // Unfortunately, things are grouped together in the ast can be
  10484. // interleaved in the source code. So we need to reorder them before
  10485. // printing them.
  10486. const propsAndLoc = [];
  10487. fields.forEach(field => {
  10488. path$$1.each(childPath => {
  10489. const node = childPath.getValue();
  10490. propsAndLoc.push({
  10491. node: node,
  10492. printed: print(childPath),
  10493. loc: options.locStart(node)
  10494. });
  10495. }, field);
  10496. });
  10497. let separatorParts = [];
  10498. const props = propsAndLoc.sort((a, b) => a.loc - b.loc).map(prop => {
  10499. const result = concat(separatorParts.concat(group(prop.printed)));
  10500. separatorParts = [separator, line];
  10501. if (
  10502. prop.node.type === "TSPropertySignature" &&
  10503. util$1.hasNodeIgnoreComment(prop.node)
  10504. ) {
  10505. separatorParts.shift();
  10506. }
  10507. if (
  10508. utilShared.isNextLineEmpty(options.originalText, prop.node, options)
  10509. ) {
  10510. separatorParts.push(hardline);
  10511. }
  10512. return result;
  10513. });
  10514. const lastElem = util$1.getLast(n[propertiesField]);
  10515. const canHaveTrailingSeparator = !(
  10516. lastElem &&
  10517. (lastElem.type === "RestProperty" ||
  10518. lastElem.type === "RestElement" ||
  10519. lastElem.type === "ExperimentalRestProperty" ||
  10520. util$1.hasNodeIgnoreComment(lastElem))
  10521. );
  10522. let content;
  10523. if (props.length === 0 && !n.typeAnnotation) {
  10524. if (!hasDanglingComments(n)) {
  10525. return concat([leftBrace, rightBrace]);
  10526. }
  10527. content = group(
  10528. concat([
  10529. leftBrace,
  10530. comments.printDanglingComments(path$$1, options),
  10531. softline,
  10532. rightBrace,
  10533. printOptionalToken(path$$1)
  10534. ])
  10535. );
  10536. } else {
  10537. content = concat([
  10538. leftBrace,
  10539. indent(
  10540. concat([options.bracketSpacing ? line : softline, concat(props)])
  10541. ),
  10542. ifBreak(
  10543. canHaveTrailingSeparator &&
  10544. (separator !== "," || shouldPrintComma(options))
  10545. ? separator
  10546. : ""
  10547. ),
  10548. concat([options.bracketSpacing ? line : softline, rightBrace]),
  10549. printOptionalToken(path$$1),
  10550. printTypeAnnotation(path$$1, options, print)
  10551. ]);
  10552. }
  10553. // If we inline the object as first argument of the parent, we don't want
  10554. // to create another group so that the object breaks before the return
  10555. // type
  10556. const parentParentParent = path$$1.getParentNode(2);
  10557. if (
  10558. (n.type === "ObjectPattern" &&
  10559. parent &&
  10560. shouldHugArguments(parent) &&
  10561. parent.params[0] === n) ||
  10562. (shouldHugType(n) &&
  10563. parentParentParent &&
  10564. shouldHugArguments(parentParentParent) &&
  10565. parentParentParent.params[0].typeAnnotation &&
  10566. parentParentParent.params[0].typeAnnotation.typeAnnotation === n)
  10567. ) {
  10568. return content;
  10569. }
  10570. return group(content, { shouldBreak });
  10571. }
  10572. // Babel 6
  10573. case "ObjectProperty": // Non-standard AST node type.
  10574. case "Property":
  10575. if (n.method || n.kind === "get" || n.kind === "set") {
  10576. return printMethod(path$$1, options, print);
  10577. }
  10578. if (n.shorthand) {
  10579. parts.push(path$$1.call(print, "value"));
  10580. } else {
  10581. let printedLeft;
  10582. if (n.computed) {
  10583. printedLeft = concat(["[", path$$1.call(print, "key"), "]"]);
  10584. } else {
  10585. printedLeft = printPropertyKey(path$$1, options, print);
  10586. }
  10587. parts.push(
  10588. printAssignment(
  10589. n.key,
  10590. printedLeft,
  10591. ":",
  10592. n.value,
  10593. path$$1.call(print, "value"),
  10594. options
  10595. )
  10596. );
  10597. }
  10598. return concat(parts); // Babel 6
  10599. case "ClassMethod":
  10600. if (n.static) {
  10601. parts.push("static ");
  10602. }
  10603. parts = parts.concat(printObjectMethod(path$$1, options, print));
  10604. return concat(parts); // Babel 6
  10605. case "ObjectMethod":
  10606. return printObjectMethod(path$$1, options, print);
  10607. case "Decorator":
  10608. return concat(["@", path$$1.call(print, "expression")]);
  10609. case "ArrayExpression":
  10610. case "ArrayPattern":
  10611. if (n.elements.length === 0) {
  10612. if (!hasDanglingComments(n)) {
  10613. parts.push("[]");
  10614. } else {
  10615. parts.push(
  10616. group(
  10617. concat([
  10618. "[",
  10619. comments.printDanglingComments(path$$1, options),
  10620. softline,
  10621. "]"
  10622. ])
  10623. )
  10624. );
  10625. }
  10626. } else {
  10627. const lastElem = util$1.getLast(n.elements);
  10628. const canHaveTrailingComma = !(
  10629. lastElem && lastElem.type === "RestElement"
  10630. );
  10631. // JavaScript allows you to have empty elements in an array which
  10632. // changes its length based on the number of commas. The algorithm
  10633. // is that if the last argument is null, we need to force insert
  10634. // a comma to ensure JavaScript recognizes it.
  10635. // [,].length === 1
  10636. // [1,].length === 1
  10637. // [1,,].length === 2
  10638. //
  10639. // Note that privateUtil.getLast returns null if the array is empty, but
  10640. // we already check for an empty array just above so we are safe
  10641. const needsForcedTrailingComma =
  10642. canHaveTrailingComma && lastElem === null;
  10643. parts.push(
  10644. group(
  10645. concat([
  10646. "[",
  10647. indent(
  10648. concat([
  10649. softline,
  10650. printArrayItems(path$$1, options, "elements", print)
  10651. ])
  10652. ),
  10653. needsForcedTrailingComma ? "," : "",
  10654. ifBreak(
  10655. canHaveTrailingComma &&
  10656. !needsForcedTrailingComma &&
  10657. shouldPrintComma(options)
  10658. ? ","
  10659. : ""
  10660. ),
  10661. comments.printDanglingComments(
  10662. path$$1,
  10663. options,
  10664. /* sameIndent */ true
  10665. ),
  10666. softline,
  10667. "]"
  10668. ])
  10669. )
  10670. );
  10671. }
  10672. parts.push(
  10673. printOptionalToken(path$$1),
  10674. printTypeAnnotation(path$$1, options, print)
  10675. );
  10676. return concat(parts);
  10677. case "SequenceExpression": {
  10678. const parent = path$$1.getParentNode(0);
  10679. if (
  10680. parent.type === "ExpressionStatement" ||
  10681. parent.type === "ForStatement"
  10682. ) {
  10683. // For ExpressionStatements and for-loop heads, which are among
  10684. // the few places a SequenceExpression appears unparenthesized, we want
  10685. // to indent expressions after the first.
  10686. const parts = [];
  10687. path$$1.each(p => {
  10688. if (p.getName() === 0) {
  10689. parts.push(print(p));
  10690. } else {
  10691. parts.push(",", indent(concat([line, print(p)])));
  10692. }
  10693. }, "expressions");
  10694. return group(concat(parts));
  10695. }
  10696. return group(
  10697. concat([join(concat([",", line]), path$$1.map(print, "expressions"))])
  10698. );
  10699. }
  10700. case "ThisExpression":
  10701. return "this";
  10702. case "Super":
  10703. return "super";
  10704. case "NullLiteral": // Babel 6 Literal split
  10705. return "null";
  10706. case "RegExpLiteral": // Babel 6 Literal split
  10707. return printRegex(n);
  10708. case "NumericLiteral": // Babel 6 Literal split
  10709. return util$1.printNumber(n.extra.raw);
  10710. case "BooleanLiteral": // Babel 6 Literal split
  10711. case "StringLiteral": // Babel 6 Literal split
  10712. case "Literal": {
  10713. if (n.regex) {
  10714. return printRegex(n.regex);
  10715. }
  10716. if (typeof n.value === "number") {
  10717. return util$1.printNumber(n.raw);
  10718. }
  10719. if (typeof n.value !== "string") {
  10720. return "" + n.value;
  10721. }
  10722. // TypeScript workaround for eslint/typescript-eslint-parser#267
  10723. // See corresponding workaround in needs-parens.js
  10724. const grandParent = path$$1.getParentNode(1);
  10725. const isTypeScriptDirective =
  10726. options.parser === "typescript" &&
  10727. typeof n.value === "string" &&
  10728. grandParent &&
  10729. (grandParent.type === "Program" ||
  10730. grandParent.type === "BlockStatement");
  10731. return nodeStr(n, options, isTypeScriptDirective);
  10732. }
  10733. case "Directive":
  10734. return path$$1.call(print, "value"); // Babel 6
  10735. case "DirectiveLiteral":
  10736. return nodeStr(n, options);
  10737. case "UnaryExpression":
  10738. parts.push(n.operator);
  10739. if (/[a-z]$/.test(n.operator)) {
  10740. parts.push(" ");
  10741. }
  10742. parts.push(path$$1.call(print, "argument"));
  10743. return concat(parts);
  10744. case "UpdateExpression":
  10745. parts.push(path$$1.call(print, "argument"), n.operator);
  10746. if (n.prefix) {
  10747. parts.reverse();
  10748. }
  10749. return concat(parts);
  10750. case "ConditionalExpression":
  10751. return formatTernaryOperator(path$$1, options, print, {
  10752. beforeParts: () => [path$$1.call(print, "test")],
  10753. afterParts: breakClosingParen => [breakClosingParen ? softline : ""]
  10754. });
  10755. case "VariableDeclaration": {
  10756. const printed = path$$1.map(childPath => {
  10757. return print(childPath);
  10758. }, "declarations");
  10759. // We generally want to terminate all variable declarations with a
  10760. // semicolon, except when they in the () part of for loops.
  10761. const parentNode = path$$1.getParentNode();
  10762. const isParentForLoop =
  10763. parentNode.type === "ForStatement" ||
  10764. parentNode.type === "ForInStatement" ||
  10765. parentNode.type === "ForOfStatement" ||
  10766. parentNode.type === "ForAwaitStatement";
  10767. const hasValue = n.declarations.some(decl => decl.init);
  10768. let firstVariable;
  10769. if (printed.length === 1) {
  10770. firstVariable = printed[0];
  10771. } else if (printed.length > 1) {
  10772. // Indent first var to comply with eslint one-var rule
  10773. firstVariable = indent(printed[0]);
  10774. }
  10775. parts = [
  10776. isNodeStartingWithDeclare(n, options) ? "declare " : "",
  10777. n.kind,
  10778. firstVariable ? concat([" ", firstVariable]) : "",
  10779. indent(
  10780. concat(
  10781. printed
  10782. .slice(1)
  10783. .map(p =>
  10784. concat([",", hasValue && !isParentForLoop ? hardline : line, p])
  10785. )
  10786. )
  10787. )
  10788. ];
  10789. if (!(isParentForLoop && parentNode.body !== n)) {
  10790. parts.push(semi);
  10791. }
  10792. return group(concat(parts));
  10793. }
  10794. case "VariableDeclarator":
  10795. return printAssignment(
  10796. n.id,
  10797. concat([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]),
  10798. " =",
  10799. n.init,
  10800. n.init && path$$1.call(print, "init"),
  10801. options
  10802. );
  10803. case "WithStatement":
  10804. return group(
  10805. concat([
  10806. "with (",
  10807. path$$1.call(print, "object"),
  10808. ")",
  10809. adjustClause(n.body, path$$1.call(print, "body"))
  10810. ])
  10811. );
  10812. case "IfStatement": {
  10813. const con = adjustClause(n.consequent, path$$1.call(print, "consequent"));
  10814. const opening = group(
  10815. concat([
  10816. "if (",
  10817. group(
  10818. concat([
  10819. indent(concat([softline, path$$1.call(print, "test")])),
  10820. softline
  10821. ])
  10822. ),
  10823. ")",
  10824. con
  10825. ])
  10826. );
  10827. parts.push(opening);
  10828. if (n.alternate) {
  10829. const commentOnOwnLine =
  10830. (hasTrailingComment(n.consequent) &&
  10831. n.consequent.comments.some(
  10832. comment =>
  10833. comment.trailing && !util$1.isBlockComment(comment)
  10834. )) ||
  10835. needsHardlineAfterDanglingComment(n);
  10836. const elseOnSameLine =
  10837. n.consequent.type === "BlockStatement" && !commentOnOwnLine;
  10838. parts.push(elseOnSameLine ? " " : hardline);
  10839. if (hasDanglingComments(n)) {
  10840. parts.push(
  10841. comments.printDanglingComments(path$$1, options, true),
  10842. commentOnOwnLine ? hardline : " "
  10843. );
  10844. }
  10845. parts.push(
  10846. "else",
  10847. group(
  10848. adjustClause(
  10849. n.alternate,
  10850. path$$1.call(print, "alternate"),
  10851. n.alternate.type === "IfStatement"
  10852. )
  10853. )
  10854. );
  10855. }
  10856. return concat(parts);
  10857. }
  10858. case "ForStatement": {
  10859. const body = adjustClause(n.body, path$$1.call(print, "body"));
  10860. // We want to keep dangling comments above the loop to stay consistent.
  10861. // Any comment positioned between the for statement and the parentheses
  10862. // is going to be printed before the statement.
  10863. const dangling = comments.printDanglingComments(
  10864. path$$1,
  10865. options,
  10866. /* sameLine */ true
  10867. );
  10868. const printedComments = dangling ? concat([dangling, softline]) : "";
  10869. if (!n.init && !n.test && !n.update) {
  10870. return concat([printedComments, group(concat(["for (;;)", body]))]);
  10871. }
  10872. return concat([
  10873. printedComments,
  10874. group(
  10875. concat([
  10876. "for (",
  10877. group(
  10878. concat([
  10879. indent(
  10880. concat([
  10881. softline,
  10882. path$$1.call(print, "init"),
  10883. ";",
  10884. line,
  10885. path$$1.call(print, "test"),
  10886. ";",
  10887. line,
  10888. path$$1.call(print, "update")
  10889. ])
  10890. ),
  10891. softline
  10892. ])
  10893. ),
  10894. ")",
  10895. body
  10896. ])
  10897. )
  10898. ]);
  10899. }
  10900. case "WhileStatement":
  10901. return group(
  10902. concat([
  10903. "while (",
  10904. group(
  10905. concat([
  10906. indent(concat([softline, path$$1.call(print, "test")])),
  10907. softline
  10908. ])
  10909. ),
  10910. ")",
  10911. adjustClause(n.body, path$$1.call(print, "body"))
  10912. ])
  10913. );
  10914. case "ForInStatement":
  10915. // Note: esprima can't actually parse "for each (".
  10916. return group(
  10917. concat([
  10918. n.each ? "for each (" : "for (",
  10919. path$$1.call(print, "left"),
  10920. " in ",
  10921. path$$1.call(print, "right"),
  10922. ")",
  10923. adjustClause(n.body, path$$1.call(print, "body"))
  10924. ])
  10925. );
  10926. case "ForOfStatement":
  10927. case "ForAwaitStatement": {
  10928. // Babylon 7 removed ForAwaitStatement in favor of ForOfStatement
  10929. // with `"await": true`:
  10930. // https://github.com/estree/estree/pull/138
  10931. const isAwait = n.type === "ForAwaitStatement" || n.await;
  10932. return group(
  10933. concat([
  10934. "for",
  10935. isAwait ? " await" : "",
  10936. " (",
  10937. path$$1.call(print, "left"),
  10938. " of ",
  10939. path$$1.call(print, "right"),
  10940. ")",
  10941. adjustClause(n.body, path$$1.call(print, "body"))
  10942. ])
  10943. );
  10944. }
  10945. case "DoWhileStatement": {
  10946. const clause = adjustClause(n.body, path$$1.call(print, "body"));
  10947. const doBody = group(concat(["do", clause]));
  10948. parts = [doBody];
  10949. if (n.body.type === "BlockStatement") {
  10950. parts.push(" ");
  10951. } else {
  10952. parts.push(hardline);
  10953. }
  10954. parts.push("while (");
  10955. parts.push(
  10956. group(
  10957. concat([
  10958. indent(concat([softline, path$$1.call(print, "test")])),
  10959. softline
  10960. ])
  10961. ),
  10962. ")",
  10963. semi
  10964. );
  10965. return concat(parts);
  10966. }
  10967. case "DoExpression":
  10968. return concat(["do ", path$$1.call(print, "body")]);
  10969. case "BreakStatement":
  10970. parts.push("break");
  10971. if (n.label) {
  10972. parts.push(" ", path$$1.call(print, "label"));
  10973. }
  10974. parts.push(semi);
  10975. return concat(parts);
  10976. case "ContinueStatement":
  10977. parts.push("continue");
  10978. if (n.label) {
  10979. parts.push(" ", path$$1.call(print, "label"));
  10980. }
  10981. parts.push(semi);
  10982. return concat(parts);
  10983. case "LabeledStatement":
  10984. if (n.body.type === "EmptyStatement") {
  10985. return concat([path$$1.call(print, "label"), ":;"]);
  10986. }
  10987. return concat([
  10988. path$$1.call(print, "label"),
  10989. ": ",
  10990. path$$1.call(print, "body")
  10991. ]);
  10992. case "TryStatement":
  10993. return concat([
  10994. "try ",
  10995. path$$1.call(print, "block"),
  10996. n.handler ? concat([" ", path$$1.call(print, "handler")]) : "",
  10997. n.finalizer ? concat([" finally ", path$$1.call(print, "finalizer")]) : ""
  10998. ]);
  10999. case "CatchClause":
  11000. return concat([
  11001. "catch ",
  11002. n.param ? concat(["(", path$$1.call(print, "param"), ") "]) : "",
  11003. path$$1.call(print, "body")
  11004. ]);
  11005. case "ThrowStatement":
  11006. return concat(["throw ", path$$1.call(print, "argument"), semi]);
  11007. // Note: ignoring n.lexical because it has no printing consequences.
  11008. case "SwitchStatement":
  11009. return concat([
  11010. group(
  11011. concat([
  11012. "switch (",
  11013. indent(concat([softline, path$$1.call(print, "discriminant")])),
  11014. softline,
  11015. ")"
  11016. ])
  11017. ),
  11018. " {",
  11019. n.cases.length > 0
  11020. ? indent(
  11021. concat([
  11022. hardline,
  11023. join(
  11024. hardline,
  11025. path$$1.map(casePath => {
  11026. const caseNode = casePath.getValue();
  11027. return concat([
  11028. casePath.call(print),
  11029. n.cases.indexOf(caseNode) !== n.cases.length - 1 &&
  11030. utilShared.isNextLineEmpty(
  11031. options.originalText,
  11032. caseNode,
  11033. options
  11034. )
  11035. ? hardline
  11036. : ""
  11037. ]);
  11038. }, "cases")
  11039. )
  11040. ])
  11041. )
  11042. : "",
  11043. hardline,
  11044. "}"
  11045. ]);
  11046. case "SwitchCase": {
  11047. if (n.test) {
  11048. parts.push("case ", path$$1.call(print, "test"), ":");
  11049. } else {
  11050. parts.push("default:");
  11051. }
  11052. const consequent = n.consequent.filter(
  11053. node => node.type !== "EmptyStatement"
  11054. );
  11055. if (consequent.length > 0) {
  11056. const cons = path$$1.call(consequentPath => {
  11057. return printStatementSequence(consequentPath, options, print);
  11058. }, "consequent");
  11059. parts.push(
  11060. consequent.length === 1 && consequent[0].type === "BlockStatement"
  11061. ? concat([" ", cons])
  11062. : indent(concat([hardline, cons]))
  11063. );
  11064. }
  11065. return concat(parts);
  11066. }
  11067. // JSX extensions below.
  11068. case "DebuggerStatement":
  11069. return concat(["debugger", semi]);
  11070. case "JSXAttribute":
  11071. parts.push(path$$1.call(print, "name"));
  11072. if (n.value) {
  11073. let res;
  11074. if (isStringLiteral(n.value)) {
  11075. const value = rawText(n.value);
  11076. res = '"' + value.slice(1, -1).replace(/"/g, "&quot;") + '"';
  11077. } else {
  11078. res = path$$1.call(print, "value");
  11079. }
  11080. parts.push("=", res);
  11081. }
  11082. return concat(parts);
  11083. case "JSXIdentifier":
  11084. // Can be removed when this is fixed:
  11085. // https://github.com/eslint/typescript-eslint-parser/issues/337
  11086. if (!n.name) {
  11087. return "this";
  11088. }
  11089. return "" + n.name;
  11090. case "JSXNamespacedName":
  11091. return join(":", [
  11092. path$$1.call(print, "namespace"),
  11093. path$$1.call(print, "name")
  11094. ]);
  11095. case "JSXMemberExpression":
  11096. return join(".", [
  11097. path$$1.call(print, "object"),
  11098. path$$1.call(print, "property")
  11099. ]);
  11100. case "TSQualifiedName":
  11101. return join(".", [path$$1.call(print, "left"), path$$1.call(print, "right")]);
  11102. case "JSXSpreadAttribute":
  11103. case "JSXSpreadChild": {
  11104. return concat([
  11105. "{",
  11106. path$$1.call(p => {
  11107. const printed = concat(["...", print(p)]);
  11108. const n = p.getValue();
  11109. if (!n.comments || !n.comments.length) {
  11110. return printed;
  11111. }
  11112. return concat([
  11113. indent(
  11114. concat([
  11115. softline,
  11116. comments.printComments(p, () => printed, options)
  11117. ])
  11118. ),
  11119. softline
  11120. ]);
  11121. }, n.type === "JSXSpreadAttribute" ? "argument" : "expression"),
  11122. "}"
  11123. ]);
  11124. }
  11125. case "JSXExpressionContainer": {
  11126. const parent = path$$1.getParentNode(0);
  11127. const preventInline =
  11128. parent.type === "JSXAttribute" &&
  11129. n.expression.comments &&
  11130. n.expression.comments.length > 0;
  11131. const shouldInline =
  11132. !preventInline &&
  11133. (n.expression.type === "ArrayExpression" ||
  11134. n.expression.type === "ObjectExpression" ||
  11135. n.expression.type === "ArrowFunctionExpression" ||
  11136. n.expression.type === "CallExpression" ||
  11137. n.expression.type === "FunctionExpression" ||
  11138. n.expression.type === "JSXEmptyExpression" ||
  11139. n.expression.type === "TemplateLiteral" ||
  11140. n.expression.type === "TaggedTemplateExpression" ||
  11141. n.expression.type === "DoExpression" ||
  11142. (isJSXNode(parent) &&
  11143. (n.expression.type === "ConditionalExpression" ||
  11144. isBinaryish(n.expression))));
  11145. if (shouldInline) {
  11146. return group(
  11147. concat(["{", path$$1.call(print, "expression"), lineSuffixBoundary, "}"])
  11148. );
  11149. }
  11150. return group(
  11151. concat([
  11152. "{",
  11153. indent(concat([softline, path$$1.call(print, "expression")])),
  11154. softline,
  11155. lineSuffixBoundary,
  11156. "}"
  11157. ])
  11158. );
  11159. }
  11160. case "JSXFragment":
  11161. case "TSJsxFragment":
  11162. case "JSXElement": {
  11163. const elem = comments.printComments(
  11164. path$$1,
  11165. () => printJSXElement(path$$1, options, print),
  11166. options
  11167. );
  11168. return maybeWrapJSXElementInParens(path$$1, elem);
  11169. }
  11170. case "JSXOpeningElement": {
  11171. const n = path$$1.getValue();
  11172. const nameHasComments =
  11173. n.name && n.name.comments && n.name.comments.length > 0;
  11174. // Don't break self-closing elements with no attributes and no comments
  11175. if (n.selfClosing && !n.attributes.length && !nameHasComments) {
  11176. return concat(["<", path$$1.call(print, "name"), " />"]);
  11177. }
  11178. // don't break up opening elements with a single long text attribute
  11179. if (
  11180. n.attributes &&
  11181. n.attributes.length === 1 &&
  11182. n.attributes[0].value &&
  11183. isStringLiteral(n.attributes[0].value) &&
  11184. !n.attributes[0].value.value.includes("\n") &&
  11185. // We should break for the following cases:
  11186. // <div
  11187. // // comment
  11188. // attr="value"
  11189. // >
  11190. // <div
  11191. // attr="value"
  11192. // // comment
  11193. // >
  11194. !nameHasComments &&
  11195. (!n.attributes[0].comments || !n.attributes[0].comments.length)
  11196. ) {
  11197. return group(
  11198. concat([
  11199. "<",
  11200. path$$1.call(print, "name"),
  11201. " ",
  11202. concat(path$$1.map(print, "attributes")),
  11203. n.selfClosing ? " />" : ">"
  11204. ])
  11205. );
  11206. }
  11207. const lastAttrHasTrailingComments =
  11208. n.attributes.length &&
  11209. hasTrailingComment(util$1.getLast(n.attributes));
  11210. const bracketSameLine =
  11211. options.jsxBracketSameLine &&
  11212. // We should print the bracket in a new line for the following cases:
  11213. // <div
  11214. // // comment
  11215. // >
  11216. // <div
  11217. // attr // comment
  11218. // >
  11219. (!nameHasComments || n.attributes.length) &&
  11220. !lastAttrHasTrailingComments;
  11221. // We should print the opening element expanded if any prop value is a
  11222. // string literal with newlines
  11223. const shouldBreak =
  11224. n.attributes &&
  11225. n.attributes.some(
  11226. attr =>
  11227. attr.value &&
  11228. isStringLiteral(attr.value) &&
  11229. attr.value.value.includes("\n")
  11230. );
  11231. return group(
  11232. concat([
  11233. "<",
  11234. path$$1.call(print, "name"),
  11235. concat([
  11236. indent(
  11237. concat(
  11238. path$$1.map(attr => concat([line, print(attr)]), "attributes")
  11239. )
  11240. ),
  11241. n.selfClosing ? line : bracketSameLine ? ">" : softline
  11242. ]),
  11243. n.selfClosing ? "/>" : bracketSameLine ? "" : ">"
  11244. ]),
  11245. { shouldBreak }
  11246. );
  11247. }
  11248. case "JSXClosingElement":
  11249. return concat(["</", path$$1.call(print, "name"), ">"]);
  11250. case "JSXOpeningFragment":
  11251. case "JSXClosingFragment":
  11252. case "TSJsxOpeningFragment":
  11253. case "TSJsxClosingFragment": {
  11254. const hasComment = n.comments && n.comments.length;
  11255. const hasOwnLineComment =
  11256. hasComment && !n.comments.every(util$1.isBlockComment);
  11257. const isOpeningFragment =
  11258. n.type === "JSXOpeningFragment" || n.type === "TSJsxOpeningFragment";
  11259. return concat([
  11260. isOpeningFragment ? "<" : "</",
  11261. indent(
  11262. concat([
  11263. hasOwnLineComment
  11264. ? hardline
  11265. : hasComment && !isOpeningFragment
  11266. ? " "
  11267. : "",
  11268. comments.printDanglingComments(path$$1, options, true)
  11269. ])
  11270. ),
  11271. hasOwnLineComment ? hardline : "",
  11272. ">"
  11273. ]);
  11274. }
  11275. case "JSXText":
  11276. /* istanbul ignore next */
  11277. throw new Error("JSXTest should be handled by JSXElement");
  11278. case "JSXEmptyExpression": {
  11279. const requiresHardline =
  11280. n.comments && !n.comments.every(util$1.isBlockComment);
  11281. return concat([
  11282. comments.printDanglingComments(
  11283. path$$1,
  11284. options,
  11285. /* sameIndent */ !requiresHardline
  11286. ),
  11287. requiresHardline ? hardline : ""
  11288. ]);
  11289. }
  11290. case "ClassBody":
  11291. if (!n.comments && n.body.length === 0) {
  11292. return "{}";
  11293. }
  11294. return concat([
  11295. "{",
  11296. n.body.length > 0
  11297. ? indent(
  11298. concat([
  11299. hardline,
  11300. path$$1.call(bodyPath => {
  11301. return printStatementSequence(bodyPath, options, print);
  11302. }, "body")
  11303. ])
  11304. )
  11305. : comments.printDanglingComments(path$$1, options),
  11306. hardline,
  11307. "}"
  11308. ]);
  11309. case "ClassProperty":
  11310. case "TSAbstractClassProperty":
  11311. case "ClassPrivateProperty": {
  11312. if (n.accessibility) {
  11313. parts.push(n.accessibility + " ");
  11314. }
  11315. if (n.static) {
  11316. parts.push("static ");
  11317. }
  11318. if (n.type === "TSAbstractClassProperty") {
  11319. parts.push("abstract ");
  11320. }
  11321. if (n.readonly) {
  11322. parts.push("readonly ");
  11323. }
  11324. const variance = getFlowVariance(n);
  11325. if (variance) {
  11326. parts.push(variance);
  11327. }
  11328. if (n.computed) {
  11329. parts.push("[", path$$1.call(print, "key"), "]");
  11330. } else {
  11331. parts.push(printPropertyKey(path$$1, options, print));
  11332. }
  11333. parts.push(printTypeAnnotation(path$$1, options, print));
  11334. if (n.value) {
  11335. parts.push(
  11336. " =",
  11337. printAssignmentRight(
  11338. n.value,
  11339. path$$1.call(print, "value"),
  11340. false, // canBreak
  11341. options
  11342. )
  11343. );
  11344. }
  11345. parts.push(semi);
  11346. return concat(parts);
  11347. }
  11348. case "ClassDeclaration":
  11349. case "ClassExpression":
  11350. case "TSAbstractClassDeclaration":
  11351. if (isNodeStartingWithDeclare(n, options)) {
  11352. parts.push("declare ");
  11353. }
  11354. parts.push(concat(printClass(path$$1, options, print)));
  11355. return concat(parts);
  11356. case "TSInterfaceHeritage":
  11357. parts.push(path$$1.call(print, "id"));
  11358. if (n.typeParameters) {
  11359. parts.push(path$$1.call(print, "typeParameters"));
  11360. }
  11361. return concat(parts);
  11362. case "TemplateElement":
  11363. return join(literalline, n.value.raw.split(/\r?\n/g));
  11364. case "TemplateLiteral": {
  11365. const expressions = path$$1.map(print, "expressions");
  11366. parts.push("`");
  11367. path$$1.each(childPath => {
  11368. const i = childPath.getName();
  11369. parts.push(print(childPath));
  11370. if (i < expressions.length) {
  11371. // For a template literal of the following form:
  11372. // `someQuery {
  11373. // ${call({
  11374. // a,
  11375. // b,
  11376. // })}
  11377. // }`
  11378. // the expression is on its own line (there is a \n in the previous
  11379. // quasi literal), therefore we want to indent the JavaScript
  11380. // expression inside at the beginning of ${ instead of the beginning
  11381. // of the `.
  11382. const tabWidth = options.tabWidth;
  11383. const indentSize = util$1.getIndentSize(
  11384. childPath.getValue().value.raw,
  11385. tabWidth
  11386. );
  11387. let printed = expressions[i];
  11388. if (
  11389. (n.expressions[i].comments && n.expressions[i].comments.length) ||
  11390. n.expressions[i].type === "MemberExpression" ||
  11391. n.expressions[i].type === "ConditionalExpression"
  11392. ) {
  11393. printed = concat([indent(concat([softline, printed])), softline]);
  11394. }
  11395. const aligned = addAlignmentToDoc(printed, indentSize, tabWidth);
  11396. parts.push(group(concat(["${", aligned, lineSuffixBoundary, "}"])));
  11397. }
  11398. }, "quasis");
  11399. parts.push("`");
  11400. return concat(parts);
  11401. }
  11402. // These types are unprintable because they serve as abstract
  11403. // supertypes for other (printable) types.
  11404. case "TaggedTemplateExpression":
  11405. return concat([path$$1.call(print, "tag"), path$$1.call(print, "quasi")]);
  11406. case "Node":
  11407. case "Printable":
  11408. case "SourceLocation":
  11409. case "Position":
  11410. case "Statement":
  11411. case "Function":
  11412. case "Pattern":
  11413. case "Expression":
  11414. case "Declaration":
  11415. case "Specifier":
  11416. case "NamedSpecifier":
  11417. case "Comment":
  11418. case "MemberTypeAnnotation": // Flow
  11419. case "Type":
  11420. /* istanbul ignore next */
  11421. throw new Error("unprintable type: " + JSON.stringify(n.type));
  11422. // Type Annotations for Facebook Flow, typically stripped out or
  11423. // transformed away before printing.
  11424. case "TypeAnnotation":
  11425. case "TSTypeAnnotation":
  11426. if (n.typeAnnotation) {
  11427. return path$$1.call(print, "typeAnnotation");
  11428. }
  11429. /* istanbul ignore next */
  11430. return "";
  11431. case "TSTupleType":
  11432. case "TupleTypeAnnotation": {
  11433. const typesField = n.type === "TSTupleType" ? "elementTypes" : "types";
  11434. return group(
  11435. concat([
  11436. "[",
  11437. indent(
  11438. concat([
  11439. softline,
  11440. printArrayItems(path$$1, options, typesField, print)
  11441. ])
  11442. ),
  11443. // TypeScript doesn't support trailing commas in tuple types
  11444. n.type === "TSTupleType"
  11445. ? ""
  11446. : ifBreak(shouldPrintComma(options) ? "," : ""),
  11447. comments.printDanglingComments(path$$1, options, /* sameIndent */ true),
  11448. softline,
  11449. "]"
  11450. ])
  11451. );
  11452. }
  11453. case "ExistsTypeAnnotation":
  11454. return "*";
  11455. case "EmptyTypeAnnotation":
  11456. return "empty";
  11457. case "AnyTypeAnnotation":
  11458. return "any";
  11459. case "MixedTypeAnnotation":
  11460. return "mixed";
  11461. case "ArrayTypeAnnotation":
  11462. return concat([path$$1.call(print, "elementType"), "[]"]);
  11463. case "BooleanTypeAnnotation":
  11464. return "boolean";
  11465. case "BooleanLiteralTypeAnnotation":
  11466. return "" + n.value;
  11467. case "DeclareClass":
  11468. return printFlowDeclaration(path$$1, printClass(path$$1, options, print));
  11469. case "DeclareFunction":
  11470. // For TypeScript the DeclareFunction node shares the AST
  11471. // structure with FunctionDeclaration
  11472. if (n.params) {
  11473. return concat([
  11474. "declare ",
  11475. printFunctionDeclaration(path$$1, print, options),
  11476. semi
  11477. ]);
  11478. }
  11479. return printFlowDeclaration(path$$1, [
  11480. "function ",
  11481. path$$1.call(print, "id"),
  11482. n.predicate ? " " : "",
  11483. path$$1.call(print, "predicate"),
  11484. semi
  11485. ]);
  11486. case "DeclareModule":
  11487. return printFlowDeclaration(path$$1, [
  11488. "module ",
  11489. path$$1.call(print, "id"),
  11490. " ",
  11491. path$$1.call(print, "body")
  11492. ]);
  11493. case "DeclareModuleExports":
  11494. return printFlowDeclaration(path$$1, [
  11495. "module.exports",
  11496. ": ",
  11497. path$$1.call(print, "typeAnnotation"),
  11498. semi
  11499. ]);
  11500. case "DeclareVariable":
  11501. return printFlowDeclaration(path$$1, ["var ", path$$1.call(print, "id"), semi]);
  11502. case "DeclareExportAllDeclaration":
  11503. return concat(["declare export * from ", path$$1.call(print, "source")]);
  11504. case "DeclareExportDeclaration":
  11505. return concat(["declare ", printExportDeclaration(path$$1, options, print)]);
  11506. case "DeclareOpaqueType":
  11507. case "OpaqueType": {
  11508. parts.push(
  11509. "opaque type ",
  11510. path$$1.call(print, "id"),
  11511. path$$1.call(print, "typeParameters")
  11512. );
  11513. if (n.supertype) {
  11514. parts.push(": ", path$$1.call(print, "supertype"));
  11515. }
  11516. if (n.impltype) {
  11517. parts.push(" = ", path$$1.call(print, "impltype"));
  11518. }
  11519. parts.push(semi);
  11520. if (n.type === "DeclareOpaqueType") {
  11521. return printFlowDeclaration(path$$1, parts);
  11522. }
  11523. return concat(parts);
  11524. }
  11525. case "FunctionTypeAnnotation":
  11526. case "TSFunctionType": {
  11527. // FunctionTypeAnnotation is ambiguous:
  11528. // declare function foo(a: B): void; OR
  11529. // var A: (a: B) => void;
  11530. const parent = path$$1.getParentNode(0);
  11531. const parentParent = path$$1.getParentNode(1);
  11532. const parentParentParent = path$$1.getParentNode(2);
  11533. let isArrowFunctionTypeAnnotation =
  11534. n.type === "TSFunctionType" ||
  11535. !(
  11536. (parent.type === "ObjectTypeProperty" &&
  11537. !getFlowVariance(parent) &&
  11538. !parent.optional &&
  11539. options.locStart(parent) === options.locStart(n)) ||
  11540. parent.type === "ObjectTypeCallProperty" ||
  11541. (parentParentParent && parentParentParent.type === "DeclareFunction")
  11542. );
  11543. let needsColon =
  11544. isArrowFunctionTypeAnnotation &&
  11545. (parent.type === "TypeAnnotation" ||
  11546. parent.type === "TSTypeAnnotation");
  11547. // Sadly we can't put it inside of FastPath::needsColon because we are
  11548. // printing ":" as part of the expression and it would put parenthesis
  11549. // around :(
  11550. const needsParens =
  11551. needsColon &&
  11552. isArrowFunctionTypeAnnotation &&
  11553. (parent.type === "TypeAnnotation" ||
  11554. parent.type === "TSTypeAnnotation") &&
  11555. parentParent.type === "ArrowFunctionExpression";
  11556. if (isObjectTypePropertyAFunction(parent, options)) {
  11557. isArrowFunctionTypeAnnotation = true;
  11558. needsColon = true;
  11559. }
  11560. if (needsParens) {
  11561. parts.push("(");
  11562. }
  11563. parts.push(
  11564. printFunctionParams(
  11565. path$$1,
  11566. print,
  11567. options,
  11568. /* expandArg */ false,
  11569. /* printTypeParams */ true
  11570. )
  11571. );
  11572. // The returnType is not wrapped in a TypeAnnotation, so the colon
  11573. // needs to be added separately.
  11574. if (n.returnType || n.predicate || n.typeAnnotation) {
  11575. parts.push(
  11576. isArrowFunctionTypeAnnotation ? " => " : ": ",
  11577. path$$1.call(print, "returnType"),
  11578. path$$1.call(print, "predicate"),
  11579. path$$1.call(print, "typeAnnotation")
  11580. );
  11581. }
  11582. if (needsParens) {
  11583. parts.push(")");
  11584. }
  11585. return group(concat(parts));
  11586. }
  11587. case "FunctionTypeParam":
  11588. return concat([
  11589. path$$1.call(print, "name"),
  11590. printOptionalToken(path$$1),
  11591. n.name ? ": " : "",
  11592. path$$1.call(print, "typeAnnotation")
  11593. ]);
  11594. case "GenericTypeAnnotation":
  11595. return concat([
  11596. path$$1.call(print, "id"),
  11597. path$$1.call(print, "typeParameters")
  11598. ]);
  11599. case "DeclareInterface":
  11600. case "InterfaceDeclaration": {
  11601. if (
  11602. n.type === "DeclareInterface" ||
  11603. isNodeStartingWithDeclare(n, options)
  11604. ) {
  11605. parts.push("declare ");
  11606. }
  11607. parts.push(
  11608. "interface ",
  11609. path$$1.call(print, "id"),
  11610. path$$1.call(print, "typeParameters")
  11611. );
  11612. if (n["extends"].length > 0) {
  11613. parts.push(
  11614. group(
  11615. indent(
  11616. concat([line, "extends ", join(", ", path$$1.map(print, "extends"))])
  11617. )
  11618. )
  11619. );
  11620. }
  11621. parts.push(" ");
  11622. parts.push(path$$1.call(print, "body"));
  11623. return group(concat(parts));
  11624. }
  11625. case "ClassImplements":
  11626. case "InterfaceExtends":
  11627. return concat([
  11628. path$$1.call(print, "id"),
  11629. path$$1.call(print, "typeParameters")
  11630. ]);
  11631. case "TSIntersectionType":
  11632. case "IntersectionTypeAnnotation": {
  11633. const types = path$$1.map(print, "types");
  11634. const result = [];
  11635. let wasIndented = false;
  11636. for (let i = 0; i < types.length; ++i) {
  11637. if (i === 0) {
  11638. result.push(types[i]);
  11639. } else if (isObjectType(n.types[i - 1]) && isObjectType(n.types[i])) {
  11640. // If both are objects, don't indent
  11641. result.push(
  11642. concat([" & ", wasIndented ? indent(types[i]) : types[i]])
  11643. );
  11644. } else if (!isObjectType(n.types[i - 1]) && !isObjectType(n.types[i])) {
  11645. // If no object is involved, go to the next line if it breaks
  11646. result.push(indent(concat([" &", line, types[i]])));
  11647. } else {
  11648. // If you go from object to non-object or vis-versa, then inline it
  11649. if (i > 1) {
  11650. wasIndented = true;
  11651. }
  11652. result.push(" & ", i > 1 ? indent(types[i]) : types[i]);
  11653. }
  11654. }
  11655. return group(concat(result));
  11656. }
  11657. case "TSUnionType":
  11658. case "UnionTypeAnnotation": {
  11659. // single-line variation
  11660. // A | B | C
  11661. // multi-line variation
  11662. // | A
  11663. // | B
  11664. // | C
  11665. const parent = path$$1.getParentNode();
  11666. // If there's a leading comment, the parent is doing the indentation
  11667. const shouldIndent =
  11668. parent.type !== "TypeParameterInstantiation" &&
  11669. parent.type !== "TSTypeParameterInstantiation" &&
  11670. parent.type !== "GenericTypeAnnotation" &&
  11671. parent.type !== "TSTypeReference" &&
  11672. !(parent.type === "FunctionTypeParam" && !parent.name) &&
  11673. !(
  11674. (parent.type === "TypeAlias" ||
  11675. parent.type === "VariableDeclarator") &&
  11676. hasLeadingOwnLineComment(options.originalText, n, options)
  11677. );
  11678. // {
  11679. // a: string
  11680. // } | null | void
  11681. // should be inlined and not be printed in the multi-line variant
  11682. const shouldHug = shouldHugType(n);
  11683. // We want to align the children but without its comment, so it looks like
  11684. // | child1
  11685. // // comment
  11686. // | child2
  11687. const printed = path$$1.map(typePath => {
  11688. let printedType = typePath.call(print);
  11689. if (!shouldHug) {
  11690. printedType = align(2, printedType);
  11691. }
  11692. return comments.printComments(typePath, () => printedType, options);
  11693. }, "types");
  11694. if (shouldHug) {
  11695. return join(" | ", printed);
  11696. }
  11697. const code = concat([
  11698. ifBreak(concat([shouldIndent ? line : "", "| "])),
  11699. join(concat([line, "| "]), printed)
  11700. ]);
  11701. let hasParens;
  11702. if (n.type === "TSUnionType") {
  11703. const greatGrandParent = path$$1.getParentNode(2);
  11704. const greatGreatGrandParent = path$$1.getParentNode(3);
  11705. hasParens =
  11706. greatGrandParent &&
  11707. greatGrandParent.type === "TSParenthesizedType" &&
  11708. greatGreatGrandParent &&
  11709. (greatGreatGrandParent.type === "TSUnionType" ||
  11710. greatGreatGrandParent.type === "TSIntersectionType");
  11711. } else {
  11712. hasParens = needsParens_1(path$$1, options);
  11713. }
  11714. if (hasParens) {
  11715. return group(concat([indent(code), softline]));
  11716. }
  11717. return group(shouldIndent ? indent(code) : code);
  11718. }
  11719. case "NullableTypeAnnotation":
  11720. return concat(["?", path$$1.call(print, "typeAnnotation")]);
  11721. case "TSNullKeyword":
  11722. case "NullLiteralTypeAnnotation":
  11723. return "null";
  11724. case "ThisTypeAnnotation":
  11725. return "this";
  11726. case "NumberTypeAnnotation":
  11727. return "number";
  11728. case "ObjectTypeCallProperty":
  11729. if (n.static) {
  11730. parts.push("static ");
  11731. }
  11732. parts.push(path$$1.call(print, "value"));
  11733. return concat(parts);
  11734. case "ObjectTypeIndexer": {
  11735. const variance = getFlowVariance(n);
  11736. return concat([
  11737. variance || "",
  11738. "[",
  11739. path$$1.call(print, "id"),
  11740. n.id ? ": " : "",
  11741. path$$1.call(print, "key"),
  11742. "]: ",
  11743. path$$1.call(print, "value")
  11744. ]);
  11745. }
  11746. case "ObjectTypeProperty": {
  11747. const variance = getFlowVariance(n);
  11748. return concat([
  11749. n.static ? "static " : "",
  11750. isGetterOrSetter(n) ? n.kind + " " : "",
  11751. variance || "",
  11752. printPropertyKey(path$$1, options, print),
  11753. printOptionalToken(path$$1),
  11754. isFunctionNotation(n, options) ? "" : ": ",
  11755. path$$1.call(print, "value")
  11756. ]);
  11757. }
  11758. case "QualifiedTypeIdentifier":
  11759. return concat([
  11760. path$$1.call(print, "qualification"),
  11761. ".",
  11762. path$$1.call(print, "id")
  11763. ]);
  11764. case "StringLiteralTypeAnnotation":
  11765. return nodeStr(n, options);
  11766. case "NumberLiteralTypeAnnotation":
  11767. assert.strictEqual(typeof n.value, "number");
  11768. if (n.extra != null) {
  11769. return util$1.printNumber(n.extra.raw);
  11770. }
  11771. return util$1.printNumber(n.raw);
  11772. case "StringTypeAnnotation":
  11773. return "string";
  11774. case "DeclareTypeAlias":
  11775. case "TypeAlias": {
  11776. if (
  11777. n.type === "DeclareTypeAlias" ||
  11778. isNodeStartingWithDeclare(n, options)
  11779. ) {
  11780. parts.push("declare ");
  11781. }
  11782. const canBreak = n.right.type === "StringLiteralTypeAnnotation";
  11783. const printed = printAssignmentRight(
  11784. n.right,
  11785. path$$1.call(print, "right"),
  11786. canBreak,
  11787. options
  11788. );
  11789. parts.push(
  11790. "type ",
  11791. path$$1.call(print, "id"),
  11792. path$$1.call(print, "typeParameters"),
  11793. " =",
  11794. printed,
  11795. semi
  11796. );
  11797. return group(concat(parts));
  11798. }
  11799. case "TypeCastExpression":
  11800. return concat([
  11801. "(",
  11802. path$$1.call(print, "expression"),
  11803. ": ",
  11804. path$$1.call(print, "typeAnnotation"),
  11805. ")"
  11806. ]);
  11807. case "TypeParameterDeclaration":
  11808. case "TypeParameterInstantiation":
  11809. case "TSTypeParameterDeclaration":
  11810. case "TSTypeParameterInstantiation":
  11811. return printTypeParameters(path$$1, options, print, "params");
  11812. case "TSTypeParameter":
  11813. case "TypeParameter": {
  11814. const parent = path$$1.getParentNode();
  11815. if (parent.type === "TSMappedType") {
  11816. parts.push(path$$1.call(print, "name"));
  11817. if (n.constraint) {
  11818. parts.push(" in ", path$$1.call(print, "constraint"));
  11819. }
  11820. return concat(parts);
  11821. }
  11822. const variance = getFlowVariance(n);
  11823. if (variance) {
  11824. parts.push(variance);
  11825. }
  11826. parts.push(path$$1.call(print, "name"));
  11827. if (n.bound) {
  11828. parts.push(": ");
  11829. parts.push(path$$1.call(print, "bound"));
  11830. }
  11831. if (n.constraint) {
  11832. parts.push(" extends ", path$$1.call(print, "constraint"));
  11833. }
  11834. if (n["default"]) {
  11835. parts.push(" = ", path$$1.call(print, "default"));
  11836. }
  11837. return concat(parts);
  11838. }
  11839. case "TypeofTypeAnnotation":
  11840. return concat(["typeof ", path$$1.call(print, "argument")]);
  11841. case "VoidTypeAnnotation":
  11842. return "void";
  11843. case "InferredPredicate":
  11844. return "%checks";
  11845. // Unhandled types below. If encountered, nodes of these types should
  11846. // be either left alone or desugared into AST types that are fully
  11847. // supported by the pretty-printer.
  11848. case "DeclaredPredicate":
  11849. return concat(["%checks(", path$$1.call(print, "value"), ")"]);
  11850. case "TSAbstractKeyword":
  11851. return "abstract";
  11852. case "TSAnyKeyword":
  11853. return "any";
  11854. case "TSAsyncKeyword":
  11855. return "async";
  11856. case "TSBooleanKeyword":
  11857. return "boolean";
  11858. case "TSConstKeyword":
  11859. return "const";
  11860. case "TSDeclareKeyword":
  11861. return "declare";
  11862. case "TSExportKeyword":
  11863. return "export";
  11864. case "TSNeverKeyword":
  11865. return "never";
  11866. case "TSNumberKeyword":
  11867. return "number";
  11868. case "TSObjectKeyword":
  11869. return "object";
  11870. case "TSProtectedKeyword":
  11871. return "protected";
  11872. case "TSPrivateKeyword":
  11873. return "private";
  11874. case "TSPublicKeyword":
  11875. return "public";
  11876. case "TSReadonlyKeyword":
  11877. return "readonly";
  11878. case "TSSymbolKeyword":
  11879. return "symbol";
  11880. case "TSStaticKeyword":
  11881. return "static";
  11882. case "TSStringKeyword":
  11883. return "string";
  11884. case "TSUndefinedKeyword":
  11885. return "undefined";
  11886. case "TSVoidKeyword":
  11887. return "void";
  11888. case "TSAsExpression":
  11889. return concat([
  11890. path$$1.call(print, "expression"),
  11891. " as ",
  11892. path$$1.call(print, "typeAnnotation")
  11893. ]);
  11894. case "TSArrayType":
  11895. return concat([path$$1.call(print, "elementType"), "[]"]);
  11896. case "TSPropertySignature": {
  11897. if (n.export) {
  11898. parts.push("export ");
  11899. }
  11900. if (n.accessibility) {
  11901. parts.push(n.accessibility + " ");
  11902. }
  11903. if (n.static) {
  11904. parts.push("static ");
  11905. }
  11906. if (n.readonly) {
  11907. parts.push("readonly ");
  11908. }
  11909. if (n.computed) {
  11910. parts.push("[");
  11911. }
  11912. parts.push(printPropertyKey(path$$1, options, print));
  11913. if (n.computed) {
  11914. parts.push("]");
  11915. }
  11916. parts.push(printOptionalToken(path$$1));
  11917. if (n.typeAnnotation) {
  11918. parts.push(": ");
  11919. parts.push(path$$1.call(print, "typeAnnotation"));
  11920. }
  11921. // This isn't valid semantically, but it's in the AST so we can print it.
  11922. if (n.initializer) {
  11923. parts.push(" = ", path$$1.call(print, "initializer"));
  11924. }
  11925. return concat(parts);
  11926. }
  11927. case "TSParameterProperty":
  11928. if (n.accessibility) {
  11929. parts.push(n.accessibility + " ");
  11930. }
  11931. if (n.export) {
  11932. parts.push("export ");
  11933. }
  11934. if (n.static) {
  11935. parts.push("static ");
  11936. }
  11937. if (n.readonly) {
  11938. parts.push("readonly ");
  11939. }
  11940. parts.push(path$$1.call(print, "parameter"));
  11941. return concat(parts);
  11942. case "TSTypeReference":
  11943. return concat([
  11944. path$$1.call(print, "typeName"),
  11945. printTypeParameters(path$$1, options, print, "typeParameters")
  11946. ]);
  11947. case "TSTypeQuery":
  11948. return concat(["typeof ", path$$1.call(print, "exprName")]);
  11949. case "TSParenthesizedType": {
  11950. return path$$1.call(print, "typeAnnotation");
  11951. }
  11952. case "TSIndexSignature": {
  11953. const parent = path$$1.getParentNode();
  11954. return concat([
  11955. n.export ? "export " : "",
  11956. n.accessibility ? concat([n.accessibility, " "]) : "",
  11957. n.static ? "static " : "",
  11958. n.readonly ? "readonly " : "",
  11959. "[",
  11960. path$$1.call(print, "index"),
  11961. "]: ",
  11962. path$$1.call(print, "typeAnnotation"),
  11963. parent.type === "ClassBody" ? semi : ""
  11964. ]);
  11965. }
  11966. case "TSTypePredicate":
  11967. return concat([
  11968. path$$1.call(print, "parameterName"),
  11969. " is ",
  11970. path$$1.call(print, "typeAnnotation")
  11971. ]);
  11972. case "TSNonNullExpression":
  11973. return concat([path$$1.call(print, "expression"), "!"]);
  11974. case "TSThisType":
  11975. return "this";
  11976. case "TSLastTypeNode":
  11977. return path$$1.call(print, "literal");
  11978. case "TSIndexedAccessType":
  11979. return concat([
  11980. path$$1.call(print, "objectType"),
  11981. "[",
  11982. path$$1.call(print, "indexType"),
  11983. "]"
  11984. ]);
  11985. case "TSConstructSignature":
  11986. case "TSConstructorType":
  11987. case "TSCallSignature": {
  11988. if (n.type !== "TSCallSignature") {
  11989. parts.push("new ");
  11990. }
  11991. parts.push(
  11992. group(
  11993. printFunctionParams(
  11994. path$$1,
  11995. print,
  11996. options,
  11997. /* expandArg */ false,
  11998. /* printTypeParams */ true
  11999. )
  12000. )
  12001. );
  12002. if (n.typeAnnotation) {
  12003. const isType = n.type === "TSConstructorType";
  12004. parts.push(isType ? " => " : ": ", path$$1.call(print, "typeAnnotation"));
  12005. }
  12006. return concat(parts);
  12007. }
  12008. case "TSTypeOperator":
  12009. return concat([n.operator, " ", path$$1.call(print, "typeAnnotation")]);
  12010. case "TSMappedType":
  12011. return group(
  12012. concat([
  12013. "{",
  12014. indent(
  12015. concat([
  12016. options.bracketSpacing ? line : softline,
  12017. n.readonlyToken
  12018. ? concat([
  12019. getTypeScriptMappedTypeModifier(
  12020. n.readonlyToken,
  12021. "readonly"
  12022. ),
  12023. " "
  12024. ])
  12025. : "",
  12026. printTypeScriptModifiers(path$$1, options, print),
  12027. "[",
  12028. path$$1.call(print, "typeParameter"),
  12029. "]",
  12030. n.questionToken
  12031. ? getTypeScriptMappedTypeModifier(n.questionToken, "?")
  12032. : "",
  12033. ": ",
  12034. path$$1.call(print, "typeAnnotation")
  12035. ])
  12036. ),
  12037. comments.printDanglingComments(path$$1, options, /* sameIndent */ true),
  12038. options.bracketSpacing ? line : softline,
  12039. "}"
  12040. ])
  12041. );
  12042. case "TSMethodSignature":
  12043. parts.push(
  12044. n.accessibility ? concat([n.accessibility, " "]) : "",
  12045. n.export ? "export " : "",
  12046. n.static ? "static " : "",
  12047. n.readonly ? "readonly " : "",
  12048. n.computed ? "[" : "",
  12049. path$$1.call(print, "key"),
  12050. n.computed ? "]" : "",
  12051. printOptionalToken(path$$1),
  12052. printFunctionParams(
  12053. path$$1,
  12054. print,
  12055. options,
  12056. /* expandArg */ false,
  12057. /* printTypeParams */ true
  12058. )
  12059. );
  12060. if (n.typeAnnotation) {
  12061. parts.push(": ", path$$1.call(print, "typeAnnotation"));
  12062. }
  12063. return group(concat(parts));
  12064. case "TSNamespaceExportDeclaration":
  12065. parts.push("export as namespace ", path$$1.call(print, "name"));
  12066. if (options.semi) {
  12067. parts.push(";");
  12068. }
  12069. return group(concat(parts));
  12070. case "TSEnumDeclaration":
  12071. if (isNodeStartingWithDeclare(n, options)) {
  12072. parts.push("declare ");
  12073. }
  12074. if (n.modifiers) {
  12075. parts.push(printTypeScriptModifiers(path$$1, options, print));
  12076. }
  12077. if (n.const) {
  12078. parts.push("const ");
  12079. }
  12080. parts.push("enum ", path$$1.call(print, "id"), " ");
  12081. if (n.members.length === 0) {
  12082. parts.push(
  12083. group(
  12084. concat([
  12085. "{",
  12086. comments.printDanglingComments(path$$1, options),
  12087. softline,
  12088. "}"
  12089. ])
  12090. )
  12091. );
  12092. } else {
  12093. parts.push(
  12094. group(
  12095. concat([
  12096. "{",
  12097. indent(
  12098. concat([
  12099. hardline,
  12100. printArrayItems(path$$1, options, "members", print),
  12101. shouldPrintComma(options, "es5") ? "," : ""
  12102. ])
  12103. ),
  12104. comments.printDanglingComments(
  12105. path$$1,
  12106. options,
  12107. /* sameIndent */ true
  12108. ),
  12109. hardline,
  12110. "}"
  12111. ])
  12112. )
  12113. );
  12114. }
  12115. return concat(parts);
  12116. case "TSEnumMember":
  12117. parts.push(path$$1.call(print, "id"));
  12118. if (n.initializer) {
  12119. parts.push(" = ", path$$1.call(print, "initializer"));
  12120. }
  12121. return concat(parts);
  12122. case "TSImportEqualsDeclaration":
  12123. parts.push(
  12124. printTypeScriptModifiers(path$$1, options, print),
  12125. "import ",
  12126. path$$1.call(print, "name"),
  12127. " = ",
  12128. path$$1.call(print, "moduleReference")
  12129. );
  12130. if (options.semi) {
  12131. parts.push(";");
  12132. }
  12133. return group(concat(parts));
  12134. case "TSExternalModuleReference":
  12135. return concat(["require(", path$$1.call(print, "expression"), ")"]);
  12136. case "TSModuleDeclaration": {
  12137. const parent = path$$1.getParentNode();
  12138. const isExternalModule = isLiteral(n.id);
  12139. const parentIsDeclaration = parent.type === "TSModuleDeclaration";
  12140. const bodyIsDeclaration = n.body && n.body.type === "TSModuleDeclaration";
  12141. if (parentIsDeclaration) {
  12142. parts.push(".");
  12143. } else {
  12144. if (n.declare === true) {
  12145. parts.push("declare ");
  12146. }
  12147. parts.push(printTypeScriptModifiers(path$$1, options, print));
  12148. // Global declaration looks like this:
  12149. // (declare)? global { ... }
  12150. const isGlobalDeclaration =
  12151. n.id.type === "Identifier" &&
  12152. n.id.name === "global" &&
  12153. !/namespace|module/.test(
  12154. options.originalText.slice(
  12155. options.locStart(n),
  12156. options.locStart(n.id)
  12157. )
  12158. );
  12159. if (!isGlobalDeclaration) {
  12160. parts.push(isExternalModule ? "module " : "namespace ");
  12161. }
  12162. }
  12163. parts.push(path$$1.call(print, "id"));
  12164. if (bodyIsDeclaration) {
  12165. parts.push(path$$1.call(print, "body"));
  12166. } else if (n.body) {
  12167. parts.push(
  12168. " {",
  12169. indent(
  12170. concat([
  12171. line,
  12172. path$$1.call(
  12173. bodyPath =>
  12174. comments.printDanglingComments(bodyPath, options, true),
  12175. "body"
  12176. ),
  12177. group(path$$1.call(print, "body"))
  12178. ])
  12179. ),
  12180. line,
  12181. "}"
  12182. );
  12183. } else {
  12184. parts.push(semi);
  12185. }
  12186. return concat(parts);
  12187. }
  12188. case "TSModuleBlock":
  12189. return path$$1.call(bodyPath => {
  12190. return printStatementSequence(bodyPath, options, print);
  12191. }, "body");
  12192. case "PrivateName":
  12193. return concat(["#", path$$1.call(print, "id")]);
  12194. case "TSConditionalType":
  12195. return formatTernaryOperator(path$$1, options, print, {
  12196. beforeParts: () => [
  12197. path$$1.call(print, "checkType"),
  12198. " ",
  12199. "extends",
  12200. " ",
  12201. path$$1.call(print, "extendsType")
  12202. ],
  12203. shouldCheckJsx: false,
  12204. operatorName: "TSConditionalType",
  12205. consequentNode: "trueType",
  12206. alternateNode: "falseType",
  12207. testNode: "checkType",
  12208. breakNested: false
  12209. });
  12210. case "TSInferType":
  12211. return concat(["infer", " ", path$$1.call(print, "typeParameter")]);
  12212. default:
  12213. /* istanbul ignore next */
  12214. throw new Error("unknown type: " + JSON.stringify(n.type));
  12215. }
  12216. }
  12217. function printStatementSequence(path$$1, options, print) {
  12218. const printed = [];
  12219. const bodyNode = path$$1.getNode();
  12220. const isClass = bodyNode.type === "ClassBody";
  12221. path$$1.map((stmtPath, i) => {
  12222. const stmt = stmtPath.getValue();
  12223. // Just in case the AST has been modified to contain falsy
  12224. // "statements," it's safer simply to skip them.
  12225. /* istanbul ignore if */
  12226. if (!stmt) {
  12227. return;
  12228. }
  12229. // Skip printing EmptyStatement nodes to avoid leaving stray
  12230. // semicolons lying around.
  12231. if (stmt.type === "EmptyStatement") {
  12232. return;
  12233. }
  12234. const stmtPrinted = print(stmtPath);
  12235. const text = options.originalText;
  12236. const parts = [];
  12237. // in no-semi mode, prepend statement with semicolon if it might break ASI
  12238. // don't prepend the only JSX element in a program with semicolon
  12239. if (
  12240. !options.semi &&
  12241. !isClass &&
  12242. !isTheOnlyJSXElementInMarkdown(options, stmtPath) &&
  12243. stmtNeedsASIProtection(stmtPath, options)
  12244. ) {
  12245. if (stmt.comments && stmt.comments.some(comment => comment.leading)) {
  12246. parts.push(print(stmtPath, { needsSemi: true }));
  12247. } else {
  12248. parts.push(";", stmtPrinted);
  12249. }
  12250. } else {
  12251. parts.push(stmtPrinted);
  12252. }
  12253. if (!options.semi && isClass) {
  12254. if (classPropMayCauseASIProblems(stmtPath)) {
  12255. parts.push(";");
  12256. } else if (stmt.type === "ClassProperty") {
  12257. const nextChild = bodyNode.body[i + 1];
  12258. if (classChildNeedsASIProtection(nextChild)) {
  12259. parts.push(";");
  12260. }
  12261. }
  12262. }
  12263. if (
  12264. utilShared.isNextLineEmpty(text, stmt, options) &&
  12265. !isLastStatement(stmtPath)
  12266. ) {
  12267. parts.push(hardline);
  12268. }
  12269. printed.push(concat(parts));
  12270. });
  12271. return join(hardline, printed);
  12272. }
  12273. function printPropertyKey(path$$1, options, print) {
  12274. const node = path$$1.getNode();
  12275. const key = node.key;
  12276. if (
  12277. isStringLiteral(key) &&
  12278. isIdentifierName(key.value) &&
  12279. !node.computed &&
  12280. options.parser !== "json"
  12281. ) {
  12282. // 'a' -> a
  12283. return path$$1.call(
  12284. keyPath => comments.printComments(keyPath, () => key.value, options),
  12285. "key"
  12286. );
  12287. }
  12288. return path$$1.call(print, "key");
  12289. }
  12290. function printMethod(path$$1, options, print) {
  12291. const node = path$$1.getNode();
  12292. const semi = options.semi ? ";" : "";
  12293. const kind = node.kind;
  12294. const parts = [];
  12295. if (node.type === "ObjectMethod" || node.type === "ClassMethod") {
  12296. node.value = node;
  12297. }
  12298. if (node.value.async) {
  12299. parts.push("async ");
  12300. }
  12301. if (!kind || kind === "init" || kind === "method" || kind === "constructor") {
  12302. if (node.value.generator) {
  12303. parts.push("*");
  12304. }
  12305. } else {
  12306. assert.ok(kind === "get" || kind === "set");
  12307. parts.push(kind, " ");
  12308. }
  12309. let key = printPropertyKey(path$$1, options, print);
  12310. if (node.computed) {
  12311. key = concat(["[", key, "]"]);
  12312. }
  12313. parts.push(
  12314. key,
  12315. concat(
  12316. path$$1.call(
  12317. valuePath => [
  12318. printFunctionTypeParameters(valuePath, options, print),
  12319. group(
  12320. concat([
  12321. printFunctionParams(valuePath, print, options),
  12322. printReturnType(valuePath, print, options)
  12323. ])
  12324. )
  12325. ],
  12326. "value"
  12327. )
  12328. )
  12329. );
  12330. if (!node.value.body || node.value.body.length === 0) {
  12331. parts.push(semi);
  12332. } else {
  12333. parts.push(" ", path$$1.call(print, "value", "body"));
  12334. }
  12335. return concat(parts);
  12336. }
  12337. function couldGroupArg(arg) {
  12338. return (
  12339. (arg.type === "ObjectExpression" &&
  12340. (arg.properties.length > 0 || arg.comments)) ||
  12341. (arg.type === "ArrayExpression" &&
  12342. (arg.elements.length > 0 || arg.comments)) ||
  12343. arg.type === "TSTypeAssertionExpression" ||
  12344. arg.type === "TSAsExpression" ||
  12345. arg.type === "FunctionExpression" ||
  12346. (arg.type === "ArrowFunctionExpression" &&
  12347. (arg.body.type === "BlockStatement" ||
  12348. arg.body.type === "ArrowFunctionExpression" ||
  12349. arg.body.type === "ObjectExpression" ||
  12350. arg.body.type === "ArrayExpression" ||
  12351. arg.body.type === "CallExpression" ||
  12352. isJSXNode(arg.body)))
  12353. );
  12354. }
  12355. function shouldGroupLastArg(args) {
  12356. const lastArg = util$1.getLast(args);
  12357. const penultimateArg = util$1.getPenultimate(args);
  12358. return (
  12359. !hasLeadingComment(lastArg) &&
  12360. !hasTrailingComment(lastArg) &&
  12361. couldGroupArg(lastArg) &&
  12362. // If the last two arguments are of the same type,
  12363. // disable last element expansion.
  12364. (!penultimateArg || penultimateArg.type !== lastArg.type)
  12365. );
  12366. }
  12367. function shouldGroupFirstArg(args) {
  12368. if (args.length !== 2) {
  12369. return false;
  12370. }
  12371. const firstArg = args[0];
  12372. const secondArg = args[1];
  12373. return (
  12374. (!firstArg.comments || !firstArg.comments.length) &&
  12375. (firstArg.type === "FunctionExpression" ||
  12376. (firstArg.type === "ArrowFunctionExpression" &&
  12377. firstArg.body.type === "BlockStatement")) &&
  12378. !couldGroupArg(secondArg)
  12379. );
  12380. }
  12381. function printArgumentsList(path$$1, options, print) {
  12382. const args = path$$1.getValue().arguments;
  12383. if (args.length === 0) {
  12384. return concat([
  12385. "(",
  12386. comments.printDanglingComments(path$$1, options, /* sameIndent */ true),
  12387. ")"
  12388. ]);
  12389. }
  12390. let anyArgEmptyLine = false;
  12391. let hasEmptyLineFollowingFirstArg = false;
  12392. const lastArgIndex = args.length - 1;
  12393. const printedArguments = path$$1.map((argPath, index) => {
  12394. const arg = argPath.getNode();
  12395. const parts = [print(argPath)];
  12396. if (index === lastArgIndex) {
  12397. // do nothing
  12398. } else if (utilShared.isNextLineEmpty(options.originalText, arg, options)) {
  12399. if (index === 0) {
  12400. hasEmptyLineFollowingFirstArg = true;
  12401. }
  12402. anyArgEmptyLine = true;
  12403. parts.push(",", hardline, hardline);
  12404. } else {
  12405. parts.push(",", line);
  12406. }
  12407. return concat(parts);
  12408. }, "arguments");
  12409. const shouldGroupFirst = shouldGroupFirstArg(args);
  12410. const shouldGroupLast = shouldGroupLastArg(args);
  12411. if (shouldGroupFirst || shouldGroupLast) {
  12412. const shouldBreak =
  12413. (shouldGroupFirst
  12414. ? printedArguments.slice(1).some(willBreak$1)
  12415. : printedArguments.slice(0, -1).some(willBreak$1)) || anyArgEmptyLine;
  12416. // We want to print the last argument with a special flag
  12417. let printedExpanded;
  12418. let i = 0;
  12419. path$$1.each(argPath => {
  12420. if (shouldGroupFirst && i === 0) {
  12421. printedExpanded = [
  12422. concat([
  12423. argPath.call(p => print(p, { expandFirstArg: true })),
  12424. printedArguments.length > 1 ? "," : "",
  12425. hasEmptyLineFollowingFirstArg ? hardline : line,
  12426. hasEmptyLineFollowingFirstArg ? hardline : ""
  12427. ])
  12428. ].concat(printedArguments.slice(1));
  12429. }
  12430. if (shouldGroupLast && i === args.length - 1) {
  12431. printedExpanded = printedArguments
  12432. .slice(0, -1)
  12433. .concat(argPath.call(p => print(p, { expandLastArg: true })));
  12434. }
  12435. i++;
  12436. }, "arguments");
  12437. const somePrintedArgumentsWillBreak = printedArguments.some(willBreak$1);
  12438. const maybeTrailingComma = shouldPrintComma(options, "all") ? "," : "";
  12439. return concat([
  12440. somePrintedArgumentsWillBreak ? breakParent : "",
  12441. conditionalGroup(
  12442. [
  12443. concat([
  12444. ifBreak(
  12445. indent(concat(["(", softline, concat(printedExpanded)])),
  12446. concat(["(", concat(printedExpanded)])
  12447. ),
  12448. somePrintedArgumentsWillBreak
  12449. ? concat([ifBreak(maybeTrailingComma), softline])
  12450. : "",
  12451. ")"
  12452. ]),
  12453. shouldGroupFirst
  12454. ? concat([
  12455. "(",
  12456. group(printedExpanded[0], { shouldBreak: true }),
  12457. concat(printedExpanded.slice(1)),
  12458. ")"
  12459. ])
  12460. : concat([
  12461. "(",
  12462. concat(printedArguments.slice(0, -1)),
  12463. group(util$1.getLast(printedExpanded), {
  12464. shouldBreak: true
  12465. }),
  12466. ")"
  12467. ]),
  12468. group(
  12469. concat([
  12470. "(",
  12471. indent(concat([line, concat(printedArguments)])),
  12472. maybeTrailingComma,
  12473. line,
  12474. ")"
  12475. ]),
  12476. { shouldBreak: true }
  12477. )
  12478. ],
  12479. { shouldBreak }
  12480. )
  12481. ]);
  12482. }
  12483. return group(
  12484. concat([
  12485. "(",
  12486. indent(concat([softline, concat(printedArguments)])),
  12487. ifBreak(shouldPrintComma(options, "all") ? "," : ""),
  12488. softline,
  12489. ")"
  12490. ]),
  12491. { shouldBreak: printedArguments.some(willBreak$1) || anyArgEmptyLine }
  12492. );
  12493. }
  12494. function printTypeAnnotation(path$$1, options, print) {
  12495. const node = path$$1.getValue();
  12496. if (!node.typeAnnotation) {
  12497. return "";
  12498. }
  12499. const parentNode = path$$1.getParentNode();
  12500. const isDefinite =
  12501. node.definite ||
  12502. (parentNode &&
  12503. parentNode.type === "VariableDeclarator" &&
  12504. parentNode.definite);
  12505. const isFunctionDeclarationIdentifier =
  12506. parentNode.type === "DeclareFunction" && parentNode.id === node;
  12507. if (
  12508. isFlowAnnotationComment(options.originalText, node.typeAnnotation, options)
  12509. ) {
  12510. return concat([" /*: ", path$$1.call(print, "typeAnnotation"), " */"]);
  12511. }
  12512. return concat([
  12513. isFunctionDeclarationIdentifier ? "" : isDefinite ? "!: " : ": ",
  12514. path$$1.call(print, "typeAnnotation")
  12515. ]);
  12516. }
  12517. function printFunctionTypeParameters(path$$1, options, print) {
  12518. const fun = path$$1.getValue();
  12519. if (fun.typeParameters) {
  12520. return path$$1.call(print, "typeParameters");
  12521. }
  12522. return "";
  12523. }
  12524. function printFunctionParams(path$$1, print, options, expandArg, printTypeParams) {
  12525. const fun = path$$1.getValue();
  12526. const paramsField = fun.parameters ? "parameters" : "params";
  12527. const typeParams = printTypeParams
  12528. ? printFunctionTypeParameters(path$$1, options, print)
  12529. : "";
  12530. let printed = [];
  12531. if (fun[paramsField]) {
  12532. printed = path$$1.map(print, paramsField);
  12533. }
  12534. if (fun.rest) {
  12535. printed.push(concat(["...", path$$1.call(print, "rest")]));
  12536. }
  12537. if (printed.length === 0) {
  12538. return concat([
  12539. typeParams,
  12540. "(",
  12541. comments.printDanglingComments(
  12542. path$$1,
  12543. options,
  12544. /* sameIndent */ true,
  12545. comment =>
  12546. util$1.getNextNonSpaceNonCommentCharacter(
  12547. options.originalText,
  12548. comment,
  12549. options.locEnd
  12550. ) === ")"
  12551. ),
  12552. ")"
  12553. ]);
  12554. }
  12555. const lastParam = util$1.getLast(fun[paramsField]);
  12556. // If the parent is a call with the first/last argument expansion and this is the
  12557. // params of the first/last argument, we dont want the arguments to break and instead
  12558. // want the whole expression to be on a new line.
  12559. //
  12560. // Good: Bad:
  12561. // verylongcall( verylongcall((
  12562. // (a, b) => { a,
  12563. // } b,
  12564. // }) ) => {
  12565. // })
  12566. if (
  12567. expandArg &&
  12568. !(fun[paramsField] && fun[paramsField].some(n => n.comments))
  12569. ) {
  12570. return group(
  12571. concat([
  12572. docUtils$3.removeLines(typeParams),
  12573. "(",
  12574. join(", ", printed.map(docUtils$3.removeLines)),
  12575. ")"
  12576. ])
  12577. );
  12578. }
  12579. // Single object destructuring should hug
  12580. //
  12581. // function({
  12582. // a,
  12583. // b,
  12584. // c
  12585. // }) {}
  12586. if (shouldHugArguments(fun)) {
  12587. return concat([typeParams, "(", join(", ", printed), ")"]);
  12588. }
  12589. const parent = path$$1.getParentNode();
  12590. // don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})`
  12591. if (parent.type === "CallExpression" && isTestCall(parent)) {
  12592. return concat([typeParams, "(", join(", ", printed), ")"]);
  12593. }
  12594. const flowTypeAnnotations = [
  12595. "AnyTypeAnnotation",
  12596. "NullLiteralTypeAnnotation",
  12597. "GenericTypeAnnotation",
  12598. "ThisTypeAnnotation",
  12599. "NumberTypeAnnotation",
  12600. "VoidTypeAnnotation",
  12601. "EmptyTypeAnnotation",
  12602. "MixedTypeAnnotation",
  12603. "BooleanTypeAnnotation",
  12604. "BooleanLiteralTypeAnnotation",
  12605. "StringTypeAnnotation"
  12606. ];
  12607. const isFlowShorthandWithOneArg =
  12608. (isObjectTypePropertyAFunction(parent, options) ||
  12609. isTypeAnnotationAFunction(parent, options) ||
  12610. parent.type === "TypeAlias" ||
  12611. parent.type === "UnionTypeAnnotation" ||
  12612. parent.type === "TSUnionType" ||
  12613. parent.type === "IntersectionTypeAnnotation" ||
  12614. (parent.type === "FunctionTypeAnnotation" &&
  12615. parent.returnType === fun)) &&
  12616. fun[paramsField].length === 1 &&
  12617. fun[paramsField][0].name === null &&
  12618. fun[paramsField][0].typeAnnotation &&
  12619. fun.typeParameters === null &&
  12620. flowTypeAnnotations.indexOf(fun[paramsField][0].typeAnnotation.type) !==
  12621. -1 &&
  12622. !(
  12623. fun[paramsField][0].typeAnnotation.type === "GenericTypeAnnotation" &&
  12624. fun[paramsField][0].typeAnnotation.typeParameters
  12625. ) &&
  12626. !fun.rest;
  12627. if (isFlowShorthandWithOneArg) {
  12628. if (options.arrowParens === "always") {
  12629. return concat(["(", concat(printed), ")"]);
  12630. }
  12631. return concat(printed);
  12632. }
  12633. const canHaveTrailingComma =
  12634. !(lastParam && lastParam.type === "RestElement") && !fun.rest;
  12635. return concat([
  12636. typeParams,
  12637. "(",
  12638. indent(concat([softline, join(concat([",", line]), printed)])),
  12639. ifBreak(
  12640. canHaveTrailingComma && shouldPrintComma(options, "all") ? "," : ""
  12641. ),
  12642. softline,
  12643. ")"
  12644. ]);
  12645. }
  12646. function shouldPrintParamsWithoutParens(path$$1, options) {
  12647. if (options.arrowParens === "always") {
  12648. return false;
  12649. }
  12650. if (options.arrowParens === "avoid") {
  12651. const node = path$$1.getValue();
  12652. return canPrintParamsWithoutParens(node);
  12653. }
  12654. // Fallback default; should be unreachable
  12655. return false;
  12656. }
  12657. function canPrintParamsWithoutParens(node) {
  12658. return (
  12659. node.params.length === 1 &&
  12660. !node.rest &&
  12661. !node.typeParameters &&
  12662. !hasDanglingComments(node) &&
  12663. node.params[0].type === "Identifier" &&
  12664. !node.params[0].typeAnnotation &&
  12665. !node.params[0].comments &&
  12666. !node.params[0].optional &&
  12667. !node.predicate &&
  12668. !node.returnType
  12669. );
  12670. }
  12671. function printFunctionDeclaration(path$$1, print, options) {
  12672. const n = path$$1.getValue();
  12673. const parts = [];
  12674. if (n.async) {
  12675. parts.push("async ");
  12676. }
  12677. parts.push("function");
  12678. if (n.generator) {
  12679. parts.push("*");
  12680. }
  12681. if (n.id) {
  12682. parts.push(" ", path$$1.call(print, "id"));
  12683. }
  12684. parts.push(
  12685. printFunctionTypeParameters(path$$1, options, print),
  12686. group(
  12687. concat([
  12688. printFunctionParams(path$$1, print, options),
  12689. printReturnType(path$$1, print, options)
  12690. ])
  12691. ),
  12692. n.body ? " " : "",
  12693. path$$1.call(print, "body")
  12694. );
  12695. return concat(parts);
  12696. }
  12697. function printObjectMethod(path$$1, options, print) {
  12698. const objMethod = path$$1.getValue();
  12699. const parts = [];
  12700. if (objMethod.async) {
  12701. parts.push("async ");
  12702. }
  12703. if (objMethod.generator) {
  12704. parts.push("*");
  12705. }
  12706. if (
  12707. objMethod.method ||
  12708. objMethod.kind === "get" ||
  12709. objMethod.kind === "set"
  12710. ) {
  12711. return printMethod(path$$1, options, print);
  12712. }
  12713. const key = printPropertyKey(path$$1, options, print);
  12714. if (objMethod.computed) {
  12715. parts.push("[", key, "]");
  12716. } else {
  12717. parts.push(key);
  12718. }
  12719. parts.push(
  12720. printFunctionTypeParameters(path$$1, options, print),
  12721. group(
  12722. concat([
  12723. printFunctionParams(path$$1, print, options),
  12724. printReturnType(path$$1, print, options)
  12725. ])
  12726. ),
  12727. " ",
  12728. path$$1.call(print, "body")
  12729. );
  12730. return concat(parts);
  12731. }
  12732. function printReturnType(path$$1, print, options) {
  12733. const n = path$$1.getValue();
  12734. const returnType = path$$1.call(print, "returnType");
  12735. if (
  12736. n.returnType &&
  12737. isFlowAnnotationComment(options.originalText, n.returnType, options)
  12738. ) {
  12739. return concat([" /*: ", returnType, " */"]);
  12740. }
  12741. const parts = [returnType];
  12742. // prepend colon to TypeScript type annotation
  12743. if (n.returnType && n.returnType.typeAnnotation) {
  12744. parts.unshift(": ");
  12745. }
  12746. if (n.predicate) {
  12747. // The return type will already add the colon, but otherwise we
  12748. // need to do it ourselves
  12749. parts.push(n.returnType ? " " : ": ", path$$1.call(print, "predicate"));
  12750. }
  12751. return concat(parts);
  12752. }
  12753. function printExportDeclaration(path$$1, options, print) {
  12754. const decl = path$$1.getValue();
  12755. const semi = options.semi ? ";" : "";
  12756. const parts = ["export "];
  12757. const isDefault = decl["default"] || decl.type === "ExportDefaultDeclaration";
  12758. if (isDefault) {
  12759. parts.push("default ");
  12760. }
  12761. parts.push(
  12762. comments.printDanglingComments(path$$1, options, /* sameIndent */ true)
  12763. );
  12764. if (needsHardlineAfterDanglingComment(decl)) {
  12765. parts.push(hardline);
  12766. }
  12767. if (decl.declaration) {
  12768. parts.push(path$$1.call(print, "declaration"));
  12769. if (
  12770. isDefault &&
  12771. (decl.declaration.type !== "ClassDeclaration" &&
  12772. decl.declaration.type !== "FunctionDeclaration" &&
  12773. decl.declaration.type !== "TSAbstractClassDeclaration" &&
  12774. decl.declaration.type !== "TSInterfaceDeclaration" &&
  12775. decl.declaration.type !== "DeclareClass" &&
  12776. decl.declaration.type !== "DeclareFunction")
  12777. ) {
  12778. parts.push(semi);
  12779. }
  12780. } else {
  12781. if (decl.specifiers && decl.specifiers.length > 0) {
  12782. const specifiers = [];
  12783. const defaultSpecifiers = [];
  12784. const namespaceSpecifiers = [];
  12785. path$$1.each(specifierPath => {
  12786. const specifierType = path$$1.getValue().type;
  12787. if (specifierType === "ExportSpecifier") {
  12788. specifiers.push(print(specifierPath));
  12789. } else if (specifierType === "ExportDefaultSpecifier") {
  12790. defaultSpecifiers.push(print(specifierPath));
  12791. } else if (specifierType === "ExportNamespaceSpecifier") {
  12792. namespaceSpecifiers.push(concat(["* as ", print(specifierPath)]));
  12793. }
  12794. }, "specifiers");
  12795. const isNamespaceFollowed =
  12796. namespaceSpecifiers.length !== 0 && specifiers.length !== 0;
  12797. const isDefaultFollowed =
  12798. defaultSpecifiers.length !== 0 &&
  12799. (namespaceSpecifiers.length !== 0 || specifiers.length !== 0);
  12800. parts.push(
  12801. decl.exportKind === "type" ? "type " : "",
  12802. concat(defaultSpecifiers),
  12803. concat([isDefaultFollowed ? ", " : ""]),
  12804. concat(namespaceSpecifiers),
  12805. concat([isNamespaceFollowed ? ", " : ""]),
  12806. specifiers.length !== 0
  12807. ? group(
  12808. concat([
  12809. "{",
  12810. indent(
  12811. concat([
  12812. options.bracketSpacing ? line : softline,
  12813. join(concat([",", line]), specifiers)
  12814. ])
  12815. ),
  12816. ifBreak(shouldPrintComma(options) ? "," : ""),
  12817. options.bracketSpacing ? line : softline,
  12818. "}"
  12819. ])
  12820. )
  12821. : ""
  12822. );
  12823. } else {
  12824. parts.push("{}");
  12825. }
  12826. if (decl.source) {
  12827. parts.push(" from ", path$$1.call(print, "source"));
  12828. }
  12829. parts.push(semi);
  12830. }
  12831. return concat(parts);
  12832. }
  12833. function printFlowDeclaration(path$$1, parts) {
  12834. const parentExportDecl = util$1.getParentExportDeclaration(path$$1);
  12835. if (parentExportDecl) {
  12836. assert.strictEqual(parentExportDecl.type, "DeclareExportDeclaration");
  12837. } else {
  12838. // If the parent node has type DeclareExportDeclaration, then it
  12839. // will be responsible for printing the "declare" token. Otherwise
  12840. // it needs to be printed with this non-exported declaration node.
  12841. parts.unshift("declare ");
  12842. }
  12843. return concat(parts);
  12844. }
  12845. function getFlowVariance(path$$1) {
  12846. if (!path$$1.variance) {
  12847. return null;
  12848. }
  12849. // Babylon 7.0 currently uses variance node type, and flow should
  12850. // follow suit soon:
  12851. // https://github.com/babel/babel/issues/4722
  12852. const variance = path$$1.variance.kind || path$$1.variance;
  12853. switch (variance) {
  12854. case "plus":
  12855. return "+";
  12856. case "minus":
  12857. return "-";
  12858. default:
  12859. /* istanbul ignore next */
  12860. return variance;
  12861. }
  12862. }
  12863. function printTypeScriptModifiers(path$$1, options, print) {
  12864. const n = path$$1.getValue();
  12865. if (!n.modifiers || !n.modifiers.length) {
  12866. return "";
  12867. }
  12868. return concat([join(" ", path$$1.map(print, "modifiers")), " "]);
  12869. }
  12870. function printTypeParameters(path$$1, options, print, paramsKey) {
  12871. const n = path$$1.getValue();
  12872. if (!n[paramsKey]) {
  12873. return "";
  12874. }
  12875. // for TypeParameterDeclaration typeParameters is a single node
  12876. if (!Array.isArray(n[paramsKey])) {
  12877. return path$$1.call(print, paramsKey);
  12878. }
  12879. const grandparent = path$$1.getNode(2);
  12880. const isParameterInTestCall =
  12881. grandparent != null &&
  12882. grandparent.type === "CallExpression" &&
  12883. isTestCall(grandparent);
  12884. const shouldInline =
  12885. isParameterInTestCall ||
  12886. n[paramsKey].length === 0 ||
  12887. (n[paramsKey].length === 1 &&
  12888. (shouldHugType(n[paramsKey][0]) ||
  12889. (n[paramsKey][0].type === "GenericTypeAnnotation" &&
  12890. shouldHugType(n[paramsKey][0].id)) ||
  12891. (n[paramsKey][0].type === "TSTypeReference" &&
  12892. shouldHugType(n[paramsKey][0].typeName)) ||
  12893. n[paramsKey][0].type === "NullableTypeAnnotation"));
  12894. if (shouldInline) {
  12895. return concat(["<", join(", ", path$$1.map(print, paramsKey)), ">"]);
  12896. }
  12897. return group(
  12898. concat([
  12899. "<",
  12900. indent(
  12901. concat([
  12902. softline,
  12903. join(concat([",", line]), path$$1.map(print, paramsKey))
  12904. ])
  12905. ),
  12906. ifBreak(
  12907. options.parser !== "typescript" && shouldPrintComma(options, "all")
  12908. ? ","
  12909. : ""
  12910. ),
  12911. softline,
  12912. ">"
  12913. ])
  12914. );
  12915. }
  12916. function printClass(path$$1, options, print) {
  12917. const n = path$$1.getValue();
  12918. const parts = [];
  12919. if (n.type === "TSAbstractClassDeclaration") {
  12920. parts.push("abstract ");
  12921. }
  12922. parts.push("class");
  12923. if (n.id) {
  12924. parts.push(" ", path$$1.call(print, "id"));
  12925. }
  12926. parts.push(path$$1.call(print, "typeParameters"));
  12927. const partsGroup = [];
  12928. if (n.superClass) {
  12929. const printed = concat([
  12930. "extends ",
  12931. path$$1.call(print, "superClass"),
  12932. path$$1.call(print, "superTypeParameters")
  12933. ]);
  12934. // Keep old behaviour of extends in same line
  12935. // If there is only on extends and there are not comments
  12936. if (
  12937. (!n.implements || n.implements.length === 0) &&
  12938. (!n.superClass.comments || n.superClass.comments.length === 0)
  12939. ) {
  12940. parts.push(
  12941. concat([
  12942. " ",
  12943. path$$1.call(
  12944. superClass =>
  12945. comments.printComments(superClass, () => printed, options),
  12946. "superClass"
  12947. )
  12948. ])
  12949. );
  12950. } else {
  12951. partsGroup.push(
  12952. group(
  12953. concat([
  12954. line,
  12955. path$$1.call(
  12956. superClass =>
  12957. comments.printComments(superClass, () => printed, options),
  12958. "superClass"
  12959. )
  12960. ])
  12961. )
  12962. );
  12963. }
  12964. } else if (n.extends && n.extends.length > 0) {
  12965. parts.push(" extends ", join(", ", path$$1.map(print, "extends")));
  12966. }
  12967. if (n["implements"] && n["implements"].length > 0) {
  12968. partsGroup.push(
  12969. line,
  12970. "implements",
  12971. group(
  12972. indent(
  12973. concat([
  12974. line,
  12975. join(concat([",", line]), path$$1.map(print, "implements"))
  12976. ])
  12977. )
  12978. )
  12979. );
  12980. }
  12981. if (n["mixins"] && n["mixins"].length > 0) {
  12982. partsGroup.push(
  12983. line,
  12984. "mixins ",
  12985. group(indent(join(concat([",", line]), path$$1.map(print, "mixins"))))
  12986. );
  12987. }
  12988. if (partsGroup.length > 0) {
  12989. parts.push(group(indent(concat(partsGroup))));
  12990. }
  12991. if (
  12992. n.body &&
  12993. n.body.comments &&
  12994. hasLeadingOwnLineComment(options.originalText, n.body, options)
  12995. ) {
  12996. parts.push(hardline);
  12997. } else {
  12998. parts.push(" ");
  12999. }
  13000. parts.push(path$$1.call(print, "body"));
  13001. return parts;
  13002. }
  13003. function printOptionalToken(path$$1) {
  13004. const node = path$$1.getValue();
  13005. if (!node.optional) {
  13006. return "";
  13007. }
  13008. if (
  13009. node.type === "CallExpression" ||
  13010. (node.type === "MemberExpression" && node.computed)
  13011. ) {
  13012. return "?.";
  13013. }
  13014. return "?";
  13015. }
  13016. function printMemberLookup(path$$1, options, print) {
  13017. const property = path$$1.call(print, "property");
  13018. const n = path$$1.getValue();
  13019. const optional = printOptionalToken(path$$1);
  13020. if (!n.computed) {
  13021. return concat([optional, ".", property]);
  13022. }
  13023. if (!n.property || isNumericLiteral(n.property)) {
  13024. return concat([optional, "[", property, "]"]);
  13025. }
  13026. return group(
  13027. concat([optional, "[", indent(concat([softline, property])), softline, "]"])
  13028. );
  13029. }
  13030. function printBindExpressionCallee(path$$1, options, print) {
  13031. return concat(["::", path$$1.call(print, "callee")]);
  13032. }
  13033. // We detect calls on member expressions specially to format a
  13034. // common pattern better. The pattern we are looking for is this:
  13035. //
  13036. // arr
  13037. // .map(x => x + 1)
  13038. // .filter(x => x > 10)
  13039. // .some(x => x % 2)
  13040. //
  13041. // The way it is structured in the AST is via a nested sequence of
  13042. // MemberExpression and CallExpression. We need to traverse the AST
  13043. // and make groups out of it to print it in the desired way.
  13044. function printMemberChain(path$$1, options, print) {
  13045. // The first phase is to linearize the AST by traversing it down.
  13046. //
  13047. // a().b()
  13048. // has the following AST structure:
  13049. // CallExpression(MemberExpression(CallExpression(Identifier)))
  13050. // and we transform it into
  13051. // [Identifier, CallExpression, MemberExpression, CallExpression]
  13052. const printedNodes = [];
  13053. // Here we try to retain one typed empty line after each call expression or
  13054. // the first group whether it is in parentheses or not
  13055. function shouldInsertEmptyLineAfter(node) {
  13056. const originalText = options.originalText;
  13057. const nextCharIndex = utilShared.getNextNonSpaceNonCommentCharacterIndex(
  13058. originalText,
  13059. node,
  13060. options
  13061. );
  13062. const nextChar = originalText.charAt(nextCharIndex);
  13063. // if it is cut off by a parenthesis, we only account for one typed empty
  13064. // line after that parenthesis
  13065. if (nextChar == ")") {
  13066. return utilShared.isNextLineEmptyAfterIndex(
  13067. originalText,
  13068. nextCharIndex + 1,
  13069. options
  13070. );
  13071. }
  13072. return utilShared.isNextLineEmpty(originalText, node, options);
  13073. }
  13074. function rec(path$$1) {
  13075. const node = path$$1.getValue();
  13076. if (
  13077. node.type === "CallExpression" &&
  13078. (isMemberish(node.callee) || node.callee.type === "CallExpression")
  13079. ) {
  13080. printedNodes.unshift({
  13081. node: node,
  13082. printed: concat([
  13083. comments.printComments(
  13084. path$$1,
  13085. () =>
  13086. concat([
  13087. printOptionalToken(path$$1),
  13088. printFunctionTypeParameters(path$$1, options, print),
  13089. printArgumentsList(path$$1, options, print)
  13090. ]),
  13091. options
  13092. ),
  13093. shouldInsertEmptyLineAfter(node) ? hardline : ""
  13094. ])
  13095. });
  13096. path$$1.call(callee => rec(callee), "callee");
  13097. } else if (isMemberish(node)) {
  13098. printedNodes.unshift({
  13099. node: node,
  13100. printed: comments.printComments(
  13101. path$$1,
  13102. () =>
  13103. node.type === "MemberExpression"
  13104. ? printMemberLookup(path$$1, options, print)
  13105. : printBindExpressionCallee(path$$1, options, print),
  13106. options
  13107. )
  13108. });
  13109. path$$1.call(object => rec(object), "object");
  13110. } else if (node.type === "TSNonNullExpression") {
  13111. printedNodes.unshift({
  13112. node: node,
  13113. printed: comments.printComments(path$$1, () => "!", options)
  13114. });
  13115. path$$1.call(expression => rec(expression), "expression");
  13116. } else {
  13117. printedNodes.unshift({
  13118. node: node,
  13119. printed: path$$1.call(print)
  13120. });
  13121. }
  13122. }
  13123. // Note: the comments of the root node have already been printed, so we
  13124. // need to extract this first call without printing them as they would
  13125. // if handled inside of the recursive call.
  13126. const node = path$$1.getValue();
  13127. printedNodes.unshift({
  13128. node,
  13129. printed: concat([
  13130. printOptionalToken(path$$1),
  13131. printFunctionTypeParameters(path$$1, options, print),
  13132. printArgumentsList(path$$1, options, print)
  13133. ])
  13134. });
  13135. path$$1.call(callee => rec(callee), "callee");
  13136. // Once we have a linear list of printed nodes, we want to create groups out
  13137. // of it.
  13138. //
  13139. // a().b.c().d().e
  13140. // will be grouped as
  13141. // [
  13142. // [Identifier, CallExpression],
  13143. // [MemberExpression, MemberExpression, CallExpression],
  13144. // [MemberExpression, CallExpression],
  13145. // [MemberExpression],
  13146. // ]
  13147. // so that we can print it as
  13148. // a()
  13149. // .b.c()
  13150. // .d()
  13151. // .e
  13152. // The first group is the first node followed by
  13153. // - as many CallExpression as possible
  13154. // < fn()()() >.something()
  13155. // - as many array acessors as possible
  13156. // < fn()[0][1][2] >.something()
  13157. // - then, as many MemberExpression as possible but the last one
  13158. // < this.items >.something()
  13159. const groups = [];
  13160. let currentGroup = [printedNodes[0]];
  13161. let i = 1;
  13162. for (; i < printedNodes.length; ++i) {
  13163. if (
  13164. printedNodes[i].node.type === "TSNonNullExpression" ||
  13165. printedNodes[i].node.type === "CallExpression" ||
  13166. (printedNodes[i].node.type === "MemberExpression" &&
  13167. printedNodes[i].node.computed &&
  13168. isNumericLiteral(printedNodes[i].node.property))
  13169. ) {
  13170. currentGroup.push(printedNodes[i]);
  13171. } else {
  13172. break;
  13173. }
  13174. }
  13175. if (printedNodes[0].node.type !== "CallExpression") {
  13176. for (; i + 1 < printedNodes.length; ++i) {
  13177. if (
  13178. isMemberish(printedNodes[i].node) &&
  13179. isMemberish(printedNodes[i + 1].node)
  13180. ) {
  13181. currentGroup.push(printedNodes[i]);
  13182. } else {
  13183. break;
  13184. }
  13185. }
  13186. }
  13187. groups.push(currentGroup);
  13188. currentGroup = [];
  13189. // Then, each following group is a sequence of MemberExpression followed by
  13190. // a sequence of CallExpression. To compute it, we keep adding things to the
  13191. // group until we has seen a CallExpression in the past and reach a
  13192. // MemberExpression
  13193. let hasSeenCallExpression = false;
  13194. for (; i < printedNodes.length; ++i) {
  13195. if (hasSeenCallExpression && isMemberish(printedNodes[i].node)) {
  13196. // [0] should be appended at the end of the group instead of the
  13197. // beginning of the next one
  13198. if (
  13199. printedNodes[i].node.computed &&
  13200. isNumericLiteral(printedNodes[i].node.property)
  13201. ) {
  13202. currentGroup.push(printedNodes[i]);
  13203. continue;
  13204. }
  13205. groups.push(currentGroup);
  13206. currentGroup = [];
  13207. hasSeenCallExpression = false;
  13208. }
  13209. if (printedNodes[i].node.type === "CallExpression") {
  13210. hasSeenCallExpression = true;
  13211. }
  13212. currentGroup.push(printedNodes[i]);
  13213. if (
  13214. printedNodes[i].node.comments &&
  13215. printedNodes[i].node.comments.some(comment => comment.trailing)
  13216. ) {
  13217. groups.push(currentGroup);
  13218. currentGroup = [];
  13219. hasSeenCallExpression = false;
  13220. }
  13221. }
  13222. if (currentGroup.length > 0) {
  13223. groups.push(currentGroup);
  13224. }
  13225. // There are cases like Object.keys(), Observable.of(), _.values() where
  13226. // they are the subject of all the chained calls and therefore should
  13227. // be kept on the same line:
  13228. //
  13229. // Object.keys(items)
  13230. // .filter(x => x)
  13231. // .map(x => x)
  13232. //
  13233. // In order to detect those cases, we use an heuristic: if the first
  13234. // node is just an identifier with the name starting with a capital
  13235. // letter, just a sequence of _$ or this. The rationale is that they are
  13236. // likely to be factories.
  13237. function isFactory(name) {
  13238. return name.match(/(^[A-Z])|^[_$]+$/);
  13239. }
  13240. const shouldMerge =
  13241. groups.length >= 2 &&
  13242. !groups[1][0].node.comments &&
  13243. ((groups[0].length === 1 &&
  13244. (groups[0][0].node.type === "ThisExpression" ||
  13245. (groups[0][0].node.type === "Identifier" &&
  13246. (isFactory(groups[0][0].node.name) ||
  13247. (groups[1].length && groups[1][0].node.computed))))) ||
  13248. (groups[0].length > 1 &&
  13249. groups[0][groups[0].length - 1].node.type === "MemberExpression" &&
  13250. groups[0][groups[0].length - 1].node.property.type === "Identifier" &&
  13251. (isFactory(groups[0][groups[0].length - 1].node.property.name) ||
  13252. (groups[1].length && groups[1][0].node.computed))));
  13253. function printGroup(printedGroup) {
  13254. return concat(printedGroup.map(tuple => tuple.printed));
  13255. }
  13256. function printIndentedGroup(groups) {
  13257. if (groups.length === 0) {
  13258. return "";
  13259. }
  13260. return indent(
  13261. group(concat([hardline, join(hardline, groups.map(printGroup))]))
  13262. );
  13263. }
  13264. const printedGroups = groups.map(printGroup);
  13265. const oneLine = concat(printedGroups);
  13266. const cutoff = shouldMerge ? 3 : 2;
  13267. const flatGroups = groups
  13268. .slice(0, cutoff)
  13269. .reduce((res, group) => res.concat(group), []);
  13270. const hasComment =
  13271. flatGroups.slice(1, -1).some(node => hasLeadingComment(node.node)) ||
  13272. flatGroups.slice(0, -1).some(node => hasTrailingComment(node.node)) ||
  13273. (groups[cutoff] && hasLeadingComment(groups[cutoff][0].node));
  13274. // If we only have a single `.`, we shouldn't do anything fancy and just
  13275. // render everything concatenated together.
  13276. if (groups.length <= cutoff && !hasComment) {
  13277. return group(oneLine);
  13278. }
  13279. // Find out the last node in the first group and check if it has an
  13280. // empty line after
  13281. const lastNodeBeforeIndent = util$1.getLast(
  13282. shouldMerge ? groups.slice(1, 2)[0] : groups[0]
  13283. ).node;
  13284. const shouldHaveEmptyLineBeforeIndent =
  13285. lastNodeBeforeIndent.type !== "CallExpression" &&
  13286. shouldInsertEmptyLineAfter(lastNodeBeforeIndent);
  13287. const expanded = concat([
  13288. printGroup(groups[0]),
  13289. shouldMerge ? concat(groups.slice(1, 2).map(printGroup)) : "",
  13290. shouldHaveEmptyLineBeforeIndent ? hardline : "",
  13291. printIndentedGroup(groups.slice(shouldMerge ? 2 : 1))
  13292. ]);
  13293. const callExpressionCount = printedNodes.filter(
  13294. tuple => tuple.node.type === "CallExpression"
  13295. ).length;
  13296. // We don't want to print in one line if there's:
  13297. // * A comment.
  13298. // * 3 or more chained calls.
  13299. // * Any group but the last one has a hard line.
  13300. // If the last group is a function it's okay to inline if it fits.
  13301. if (
  13302. hasComment ||
  13303. callExpressionCount >= 3 ||
  13304. printedGroups.slice(0, -1).some(willBreak$1)
  13305. ) {
  13306. return group(expanded);
  13307. }
  13308. return concat([
  13309. // We only need to check `oneLine` because if `expanded` is chosen
  13310. // that means that the parent group has already been broken
  13311. // naturally
  13312. willBreak$1(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent : "",
  13313. conditionalGroup([oneLine, expanded])
  13314. ]);
  13315. }
  13316. function isJSXNode(node) {
  13317. return (
  13318. node.type === "JSXElement" ||
  13319. node.type === "JSXFragment" ||
  13320. node.type === "TSJsxFragment"
  13321. );
  13322. }
  13323. function isEmptyJSXElement(node) {
  13324. if (node.children.length === 0) {
  13325. return true;
  13326. }
  13327. if (node.children.length > 1) {
  13328. return false;
  13329. }
  13330. // if there is one text child and does not contain any meaningful text
  13331. // we can treat the element as empty.
  13332. const child = node.children[0];
  13333. return isLiteral(child) && !isMeaningfulJSXText(child);
  13334. }
  13335. // Only space, newline, carriage return, and tab are treated as whitespace
  13336. // inside JSX.
  13337. const jsxWhitespaceChars = " \n\r\t";
  13338. const containsNonJsxWhitespaceRegex = new RegExp(
  13339. "[^" + jsxWhitespaceChars + "]"
  13340. );
  13341. const matchJsxWhitespaceRegex = new RegExp("([" + jsxWhitespaceChars + "]+)");
  13342. // Meaningful if it contains non-whitespace characters,
  13343. // or it contains whitespace without a new line.
  13344. function isMeaningfulJSXText(node) {
  13345. return (
  13346. isLiteral(node) &&
  13347. (containsNonJsxWhitespaceRegex.test(rawText(node)) ||
  13348. !/\n/.test(rawText(node)))
  13349. );
  13350. }
  13351. function conditionalExpressionChainContainsJSX(node) {
  13352. return Boolean(getConditionalChainContents(node).find(isJSXNode));
  13353. }
  13354. // If we have nested conditional expressions, we want to print them in JSX mode
  13355. // if there's at least one JSXElement somewhere in the tree.
  13356. //
  13357. // A conditional expression chain like this should be printed in normal mode,
  13358. // because there aren't JSXElements anywhere in it:
  13359. //
  13360. // isA ? "A" : isB ? "B" : isC ? "C" : "Unknown";
  13361. //
  13362. // But a conditional expression chain like this should be printed in JSX mode,
  13363. // because there is a JSXElement in the last ConditionalExpression:
  13364. //
  13365. // isA ? "A" : isB ? "B" : isC ? "C" : <span className="warning">Unknown</span>;
  13366. //
  13367. // This type of ConditionalExpression chain is structured like this in the AST:
  13368. //
  13369. // ConditionalExpression {
  13370. // test: ...,
  13371. // consequent: ...,
  13372. // alternate: ConditionalExpression {
  13373. // test: ...,
  13374. // consequent: ...,
  13375. // alternate: ConditionalExpression {
  13376. // test: ...,
  13377. // consequent: ...,
  13378. // alternate: ...,
  13379. // }
  13380. // }
  13381. // }
  13382. //
  13383. // We want to traverse over that shape and convert it into a flat structure so
  13384. // that we can find if there's a JSXElement somewhere inside.
  13385. function getConditionalChainContents(node) {
  13386. // Given this code:
  13387. //
  13388. // // Using a ConditionalExpression as the consequent is uncommon, but should
  13389. // // be handled.
  13390. // A ? B : C ? D : E ? F ? G : H : I
  13391. //
  13392. // which has this AST:
  13393. //
  13394. // ConditionalExpression {
  13395. // test: Identifier(A),
  13396. // consequent: Identifier(B),
  13397. // alternate: ConditionalExpression {
  13398. // test: Identifier(C),
  13399. // consequent: Identifier(D),
  13400. // alternate: ConditionalExpression {
  13401. // test: Identifier(E),
  13402. // consequent: ConditionalExpression {
  13403. // test: Identifier(F),
  13404. // consequent: Identifier(G),
  13405. // alternate: Identifier(H),
  13406. // },
  13407. // alternate: Identifier(I),
  13408. // }
  13409. // }
  13410. // }
  13411. //
  13412. // we should return this Array:
  13413. //
  13414. // [
  13415. // Identifier(A),
  13416. // Identifier(B),
  13417. // Identifier(C),
  13418. // Identifier(D),
  13419. // Identifier(E),
  13420. // Identifier(F),
  13421. // Identifier(G),
  13422. // Identifier(H),
  13423. // Identifier(I)
  13424. // ];
  13425. //
  13426. // This loses the information about whether each node was the test,
  13427. // consequent, or alternate, but we don't care about that here- we are only
  13428. // flattening this structure to find if there's any JSXElements inside.
  13429. const nonConditionalExpressions = [];
  13430. function recurse(node) {
  13431. if (node.type === "ConditionalExpression") {
  13432. recurse(node.test);
  13433. recurse(node.consequent);
  13434. recurse(node.alternate);
  13435. } else {
  13436. nonConditionalExpressions.push(node);
  13437. }
  13438. }
  13439. recurse(node);
  13440. return nonConditionalExpressions;
  13441. }
  13442. // Detect an expression node representing `{" "}`
  13443. function isJSXWhitespaceExpression(node) {
  13444. return (
  13445. node.type === "JSXExpressionContainer" &&
  13446. isLiteral(node.expression) &&
  13447. node.expression.value === " " &&
  13448. !node.expression.comments
  13449. );
  13450. }
  13451. // JSX Children are strange, mostly for two reasons:
  13452. // 1. JSX reads newlines into string values, instead of skipping them like JS
  13453. // 2. up to one whitespace between elements within a line is significant,
  13454. // but not between lines.
  13455. //
  13456. // Leading, trailing, and lone whitespace all need to
  13457. // turn themselves into the rather ugly `{' '}` when breaking.
  13458. //
  13459. // We print JSX using the `fill` doc primitive.
  13460. // This requires that we give it an array of alternating
  13461. // content and whitespace elements.
  13462. // To ensure this we add dummy `""` content elements as needed.
  13463. function printJSXChildren(path$$1, options, print, jsxWhitespace) {
  13464. const n = path$$1.getValue();
  13465. const children = [];
  13466. // using `map` instead of `each` because it provides `i`
  13467. path$$1.map((childPath, i) => {
  13468. const child = childPath.getValue();
  13469. if (isLiteral(child)) {
  13470. const text = rawText(child);
  13471. // Contains a non-whitespace character
  13472. if (isMeaningfulJSXText(child)) {
  13473. const words = text.split(matchJsxWhitespaceRegex);
  13474. // Starts with whitespace
  13475. if (words[0] === "") {
  13476. children.push("");
  13477. words.shift();
  13478. if (/\n/.test(words[0])) {
  13479. children.push(hardline);
  13480. } else {
  13481. children.push(jsxWhitespace);
  13482. }
  13483. words.shift();
  13484. }
  13485. let endWhitespace;
  13486. // Ends with whitespace
  13487. if (util$1.getLast(words) === "") {
  13488. words.pop();
  13489. endWhitespace = words.pop();
  13490. }
  13491. // This was whitespace only without a new line.
  13492. if (words.length === 0) {
  13493. return;
  13494. }
  13495. words.forEach((word, i) => {
  13496. if (i % 2 === 1) {
  13497. children.push(line);
  13498. } else {
  13499. children.push(word);
  13500. }
  13501. });
  13502. if (endWhitespace !== undefined) {
  13503. if (/\n/.test(endWhitespace)) {
  13504. children.push(hardline);
  13505. } else {
  13506. children.push(jsxWhitespace);
  13507. }
  13508. } else {
  13509. // Ideally this would be a `hardline` to allow a break between
  13510. // tags and text.
  13511. // Unfortunately Facebook have a custom translation pipeline
  13512. // (https://github.com/prettier/prettier/issues/1581#issuecomment-300975032)
  13513. // that uses the JSX syntax, but does not follow the React whitespace
  13514. // rules.
  13515. // Ensuring that we never have a break between tags and text in JSX
  13516. // will allow Facebook to adopt Prettier without too much of an
  13517. // adverse effect on formatting algorithm.
  13518. children.push("");
  13519. }
  13520. } else if (/\n/.test(text)) {
  13521. // Keep (up to one) blank line between tags/expressions/text.
  13522. // Note: We don't keep blank lines between text elements.
  13523. if (text.match(/\n/g).length > 1) {
  13524. children.push("");
  13525. children.push(hardline);
  13526. }
  13527. } else {
  13528. children.push("");
  13529. children.push(jsxWhitespace);
  13530. }
  13531. } else {
  13532. const printedChild = print(childPath);
  13533. children.push(printedChild);
  13534. const next = n.children[i + 1];
  13535. const directlyFollowedByMeaningfulText =
  13536. next && isMeaningfulJSXText(next) && !/^[ \n\r\t]/.test(rawText(next));
  13537. if (directlyFollowedByMeaningfulText) {
  13538. // Potentially this could be a hardline as well.
  13539. // See the comment above about the Facebook translation pipeline as
  13540. // to why this is an empty string.
  13541. children.push("");
  13542. } else {
  13543. children.push(hardline);
  13544. }
  13545. }
  13546. }, "children");
  13547. return children;
  13548. }
  13549. // JSX expands children from the inside-out, instead of the outside-in.
  13550. // This is both to break children before attributes,
  13551. // and to ensure that when children break, their parents do as well.
  13552. //
  13553. // Any element that is written without any newlines and fits on a single line
  13554. // is left that way.
  13555. // Not only that, any user-written-line containing multiple JSX siblings
  13556. // should also be kept on one line if possible,
  13557. // so each user-written-line is wrapped in its own group.
  13558. //
  13559. // Elements that contain newlines or don't fit on a single line (recursively)
  13560. // are fully-split, using hardline and shouldBreak: true.
  13561. //
  13562. // To support that case properly, all leading and trailing spaces
  13563. // are stripped from the list of children, and replaced with a single hardline.
  13564. function printJSXElement(path$$1, options, print) {
  13565. const n = path$$1.getValue();
  13566. // Turn <div></div> into <div />
  13567. if (n.type === "JSXElement" && isEmptyJSXElement(n)) {
  13568. n.openingElement.selfClosing = true;
  13569. return path$$1.call(print, "openingElement");
  13570. }
  13571. const openingLines =
  13572. n.type === "JSXElement"
  13573. ? path$$1.call(print, "openingElement")
  13574. : path$$1.call(print, "openingFragment");
  13575. const closingLines =
  13576. n.type === "JSXElement"
  13577. ? path$$1.call(print, "closingElement")
  13578. : path$$1.call(print, "closingFragment");
  13579. if (
  13580. n.children.length === 1 &&
  13581. n.children[0].type === "JSXExpressionContainer" &&
  13582. (n.children[0].expression.type === "TemplateLiteral" ||
  13583. n.children[0].expression.type === "TaggedTemplateExpression")
  13584. ) {
  13585. return concat([
  13586. openingLines,
  13587. concat(path$$1.map(print, "children")),
  13588. closingLines
  13589. ]);
  13590. }
  13591. // Convert `{" "}` to text nodes containing a space.
  13592. // This makes it easy to turn them into `jsxWhitespace` which
  13593. // can then print as either a space or `{" "}` when breaking.
  13594. n.children = n.children.map(child => {
  13595. if (isJSXWhitespaceExpression(child)) {
  13596. return {
  13597. type: "JSXText",
  13598. value: " ",
  13599. raw: " "
  13600. };
  13601. }
  13602. return child;
  13603. });
  13604. const containsTag = n.children.filter(isJSXNode).length > 0;
  13605. const containsMultipleExpressions =
  13606. n.children.filter(child => child.type === "JSXExpressionContainer").length >
  13607. 1;
  13608. const containsMultipleAttributes =
  13609. n.type === "JSXElement" && n.openingElement.attributes.length > 1;
  13610. // Record any breaks. Should never go from true to false, only false to true.
  13611. let forcedBreak =
  13612. willBreak$1(openingLines) ||
  13613. containsTag ||
  13614. containsMultipleAttributes ||
  13615. containsMultipleExpressions;
  13616. const rawJsxWhitespace = options.singleQuote ? "{' '}" : '{" "}';
  13617. const jsxWhitespace = ifBreak(concat([rawJsxWhitespace, softline]), " ");
  13618. const children = printJSXChildren(path$$1, options, print, jsxWhitespace);
  13619. const containsText =
  13620. n.children.filter(child => isMeaningfulJSXText(child)).length > 0;
  13621. // We can end up we multiple whitespace elements with empty string
  13622. // content between them.
  13623. // We need to remove empty whitespace and softlines before JSX whitespace
  13624. // to get the correct output.
  13625. for (let i = children.length - 2; i >= 0; i--) {
  13626. const isPairOfEmptyStrings = children[i] === "" && children[i + 1] === "";
  13627. const isPairOfHardlines =
  13628. children[i] === hardline &&
  13629. children[i + 1] === "" &&
  13630. children[i + 2] === hardline;
  13631. const isLineFollowedByJSXWhitespace =
  13632. (children[i] === softline || children[i] === hardline) &&
  13633. children[i + 1] === "" &&
  13634. children[i + 2] === jsxWhitespace;
  13635. const isJSXWhitespaceFollowedByLine =
  13636. children[i] === jsxWhitespace &&
  13637. children[i + 1] === "" &&
  13638. (children[i + 2] === softline || children[i + 2] === hardline);
  13639. const isDoubleJSXWhitespace =
  13640. children[i] === jsxWhitespace &&
  13641. children[i + 1] === "" &&
  13642. children[i + 2] === jsxWhitespace;
  13643. if (
  13644. (isPairOfHardlines && containsText) ||
  13645. isPairOfEmptyStrings ||
  13646. isLineFollowedByJSXWhitespace ||
  13647. isDoubleJSXWhitespace
  13648. ) {
  13649. children.splice(i, 2);
  13650. } else if (isJSXWhitespaceFollowedByLine) {
  13651. children.splice(i + 1, 2);
  13652. }
  13653. }
  13654. // Trim trailing lines (or empty strings)
  13655. while (
  13656. children.length &&
  13657. (isLineNext$1(util$1.getLast(children)) ||
  13658. isEmpty$1(util$1.getLast(children)))
  13659. ) {
  13660. children.pop();
  13661. }
  13662. // Trim leading lines (or empty strings)
  13663. while (
  13664. children.length &&
  13665. (isLineNext$1(children[0]) || isEmpty$1(children[0])) &&
  13666. (isLineNext$1(children[1]) || isEmpty$1(children[1]))
  13667. ) {
  13668. children.shift();
  13669. children.shift();
  13670. }
  13671. // Tweak how we format children if outputting this element over multiple lines.
  13672. // Also detect whether we will force this element to output over multiple lines.
  13673. const multilineChildren = [];
  13674. children.forEach((child, i) => {
  13675. // There are a number of situations where we need to ensure we display
  13676. // whitespace as `{" "}` when outputting this element over multiple lines.
  13677. if (child === jsxWhitespace) {
  13678. if (i === 1 && children[i - 1] === "") {
  13679. if (children.length === 2) {
  13680. // Solitary whitespace
  13681. multilineChildren.push(rawJsxWhitespace);
  13682. return;
  13683. }
  13684. // Leading whitespace
  13685. multilineChildren.push(concat([rawJsxWhitespace, hardline]));
  13686. return;
  13687. } else if (i === children.length - 1) {
  13688. // Trailing whitespace
  13689. multilineChildren.push(rawJsxWhitespace);
  13690. return;
  13691. } else if (children[i - 1] === "" && children[i - 2] === hardline) {
  13692. // Whitespace after line break
  13693. multilineChildren.push(rawJsxWhitespace);
  13694. return;
  13695. }
  13696. }
  13697. multilineChildren.push(child);
  13698. if (willBreak$1(child)) {
  13699. forcedBreak = true;
  13700. }
  13701. });
  13702. // If there is text we use `fill` to fit as much onto each line as possible.
  13703. // When there is no text (just tags and expressions) we use `group`
  13704. // to output each on a separate line.
  13705. const content = containsText
  13706. ? fill(multilineChildren)
  13707. : group(concat(multilineChildren), { shouldBreak: true });
  13708. const multiLineElem = group(
  13709. concat([
  13710. openingLines,
  13711. indent(concat([hardline, content])),
  13712. hardline,
  13713. closingLines
  13714. ])
  13715. );
  13716. if (forcedBreak) {
  13717. return multiLineElem;
  13718. }
  13719. return conditionalGroup([
  13720. group(concat([openingLines, concat(children), closingLines])),
  13721. multiLineElem
  13722. ]);
  13723. }
  13724. function maybeWrapJSXElementInParens(path$$1, elem) {
  13725. const parent = path$$1.getParentNode();
  13726. if (!parent) {
  13727. return elem;
  13728. }
  13729. const NO_WRAP_PARENTS = {
  13730. ArrayExpression: true,
  13731. JSXAttribute: true,
  13732. JSXElement: true,
  13733. JSXExpressionContainer: true,
  13734. JSXFragment: true,
  13735. TSJsxFragment: true,
  13736. ExpressionStatement: true,
  13737. CallExpression: true,
  13738. ConditionalExpression: true
  13739. };
  13740. if (NO_WRAP_PARENTS[parent.type]) {
  13741. return elem;
  13742. }
  13743. return group(
  13744. concat([
  13745. ifBreak("("),
  13746. indent(concat([softline, elem])),
  13747. softline,
  13748. ifBreak(")")
  13749. ])
  13750. );
  13751. }
  13752. function isBinaryish(node) {
  13753. return node.type === "BinaryExpression" || node.type === "LogicalExpression";
  13754. }
  13755. function isMemberish(node) {
  13756. return (
  13757. node.type === "MemberExpression" ||
  13758. (node.type === "BindExpression" && node.object)
  13759. );
  13760. }
  13761. function shouldInlineLogicalExpression(node) {
  13762. if (node.type !== "LogicalExpression") {
  13763. return false;
  13764. }
  13765. if (
  13766. node.right.type === "ObjectExpression" &&
  13767. node.right.properties.length !== 0
  13768. ) {
  13769. return true;
  13770. }
  13771. if (
  13772. node.right.type === "ArrayExpression" &&
  13773. node.right.elements.length !== 0
  13774. ) {
  13775. return true;
  13776. }
  13777. if (isJSXNode(node.right)) {
  13778. return true;
  13779. }
  13780. return false;
  13781. }
  13782. // For binary expressions to be consistent, we need to group
  13783. // subsequent operators with the same precedence level under a single
  13784. // group. Otherwise they will be nested such that some of them break
  13785. // onto new lines but not all. Operators with the same precedence
  13786. // level should either all break or not. Because we group them by
  13787. // precedence level and the AST is structured based on precedence
  13788. // level, things are naturally broken up correctly, i.e. `&&` is
  13789. // broken before `+`.
  13790. function printBinaryishExpressions(
  13791. path$$1,
  13792. print,
  13793. options,
  13794. isNested,
  13795. isInsideParenthesis
  13796. ) {
  13797. let parts = [];
  13798. const node = path$$1.getValue();
  13799. // We treat BinaryExpression and LogicalExpression nodes the same.
  13800. if (isBinaryish(node)) {
  13801. // Put all operators with the same precedence level in the same
  13802. // group. The reason we only need to do this with the `left`
  13803. // expression is because given an expression like `1 + 2 - 3`, it
  13804. // is always parsed like `((1 + 2) - 3)`, meaning the `left` side
  13805. // is where the rest of the expression will exist. Binary
  13806. // expressions on the right side mean they have a difference
  13807. // precedence level and should be treated as a separate group, so
  13808. // print them normally. (This doesn't hold for the `**` operator,
  13809. // which is unique in that it is right-associative.)
  13810. if (util$1.shouldFlatten(node.operator, node.left.operator)) {
  13811. // Flatten them out by recursively calling this function.
  13812. parts = parts.concat(
  13813. path$$1.call(
  13814. left =>
  13815. printBinaryishExpressions(
  13816. left,
  13817. print,
  13818. options,
  13819. /* isNested */ true,
  13820. isInsideParenthesis
  13821. ),
  13822. "left"
  13823. )
  13824. );
  13825. } else {
  13826. parts.push(path$$1.call(print, "left"));
  13827. }
  13828. const shouldInline = shouldInlineLogicalExpression(node);
  13829. const lineBeforeOperator = node.operator === "|>";
  13830. const right = shouldInline
  13831. ? concat([node.operator, " ", path$$1.call(print, "right")])
  13832. : concat([
  13833. lineBeforeOperator ? softline : "",
  13834. node.operator,
  13835. lineBeforeOperator ? " " : line,
  13836. path$$1.call(print, "right")
  13837. ]);
  13838. // If there's only a single binary expression, we want to create a group
  13839. // in order to avoid having a small right part like -1 be on its own line.
  13840. const parent = path$$1.getParentNode();
  13841. const shouldGroup =
  13842. !(isInsideParenthesis && node.type === "LogicalExpression") &&
  13843. parent.type !== node.type &&
  13844. node.left.type !== node.type &&
  13845. node.right.type !== node.type;
  13846. parts.push(" ", shouldGroup ? group(right) : right);
  13847. // The root comments are already printed, but we need to manually print
  13848. // the other ones since we don't call the normal print on BinaryExpression,
  13849. // only for the left and right parts
  13850. if (isNested && node.comments) {
  13851. parts = comments.printComments(path$$1, () => concat(parts), options);
  13852. }
  13853. } else {
  13854. // Our stopping case. Simply print the node normally.
  13855. parts.push(path$$1.call(print));
  13856. }
  13857. return parts;
  13858. }
  13859. function printAssignmentRight(rightNode, printedRight, canBreak, options) {
  13860. if (hasLeadingOwnLineComment(options.originalText, rightNode, options)) {
  13861. return indent(concat([hardline, printedRight]));
  13862. }
  13863. if (canBreak) {
  13864. return indent(concat([line, printedRight]));
  13865. }
  13866. return concat([" ", printedRight]);
  13867. }
  13868. function printAssignment(
  13869. leftNode,
  13870. printedLeft,
  13871. operator,
  13872. rightNode,
  13873. printedRight,
  13874. options
  13875. ) {
  13876. if (!rightNode) {
  13877. return printedLeft;
  13878. }
  13879. const canBreak =
  13880. (isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode)) ||
  13881. (rightNode.type === "ConditionalExpression" &&
  13882. isBinaryish(rightNode.test) &&
  13883. !shouldInlineLogicalExpression(rightNode.test)) ||
  13884. ((leftNode.type === "Identifier" ||
  13885. isStringLiteral(leftNode) ||
  13886. leftNode.type === "MemberExpression") &&
  13887. (isStringLiteral(rightNode) || isMemberExpressionChain(rightNode)));
  13888. const printed = printAssignmentRight(
  13889. rightNode,
  13890. printedRight,
  13891. canBreak,
  13892. options
  13893. );
  13894. return group(concat([printedLeft, operator, printed]));
  13895. }
  13896. function adjustClause(node, clause, forceSpace) {
  13897. if (node.type === "EmptyStatement") {
  13898. return ";";
  13899. }
  13900. if (node.type === "BlockStatement" || forceSpace) {
  13901. return concat([" ", clause]);
  13902. }
  13903. return indent(concat([line, clause]));
  13904. }
  13905. function nodeStr(node, options, isFlowOrTypeScriptDirectiveLiteral) {
  13906. const raw = rawText(node);
  13907. const isDirectiveLiteral =
  13908. isFlowOrTypeScriptDirectiveLiteral || node.type === "DirectiveLiteral";
  13909. return util$1.printString(raw, options, isDirectiveLiteral);
  13910. }
  13911. function printRegex(node) {
  13912. const flags = node.flags
  13913. .split("")
  13914. .sort()
  13915. .join("");
  13916. return `/${node.pattern}/${flags}`;
  13917. }
  13918. function isLastStatement(path$$1) {
  13919. const parent = path$$1.getParentNode();
  13920. if (!parent) {
  13921. return true;
  13922. }
  13923. const node = path$$1.getValue();
  13924. const body = (parent.body || parent.consequent).filter(
  13925. stmt => stmt.type !== "EmptyStatement"
  13926. );
  13927. return body && body[body.length - 1] === node;
  13928. }
  13929. function hasLeadingComment(node) {
  13930. return node.comments && node.comments.some(comment => comment.leading);
  13931. }
  13932. function hasTrailingComment(node) {
  13933. return node.comments && node.comments.some(comment => comment.trailing);
  13934. }
  13935. function hasLeadingOwnLineComment(text, node, options) {
  13936. if (isJSXNode(node)) {
  13937. return util$1.hasNodeIgnoreComment(node);
  13938. }
  13939. const res =
  13940. node.comments &&
  13941. node.comments.some(
  13942. comment =>
  13943. comment.leading && util$1.hasNewline(text, options.locEnd(comment))
  13944. );
  13945. return res;
  13946. }
  13947. function hasNakedLeftSide(node) {
  13948. return (
  13949. node.type === "AssignmentExpression" ||
  13950. node.type === "BinaryExpression" ||
  13951. node.type === "LogicalExpression" ||
  13952. node.type === "ConditionalExpression" ||
  13953. node.type === "CallExpression" ||
  13954. node.type === "MemberExpression" ||
  13955. node.type === "SequenceExpression" ||
  13956. node.type === "TaggedTemplateExpression" ||
  13957. (node.type === "BindExpression" && !node.object) ||
  13958. (node.type === "UpdateExpression" && !node.prefix)
  13959. );
  13960. }
  13961. function isFlowAnnotationComment(text, typeAnnotation, options) {
  13962. const start = options.locStart(typeAnnotation);
  13963. const end = util$1.skipWhitespace(text, options.locEnd(typeAnnotation));
  13964. return text.substr(start, 2) === "/*" && text.substr(end, 2) === "*/";
  13965. }
  13966. function getLeftSide(node) {
  13967. if (node.expressions) {
  13968. return node.expressions[0];
  13969. }
  13970. return (
  13971. node.left ||
  13972. node.test ||
  13973. node.callee ||
  13974. node.object ||
  13975. node.tag ||
  13976. node.argument ||
  13977. node.expression
  13978. );
  13979. }
  13980. function getLeftSidePathName(path$$1, node) {
  13981. if (node.expressions) {
  13982. return ["expressions", 0];
  13983. }
  13984. if (node.left) {
  13985. return ["left"];
  13986. }
  13987. if (node.test) {
  13988. return ["test"];
  13989. }
  13990. if (node.callee) {
  13991. return ["callee"];
  13992. }
  13993. if (node.object) {
  13994. return ["object"];
  13995. }
  13996. if (node.tag) {
  13997. return ["tag"];
  13998. }
  13999. if (node.argument) {
  14000. return ["argument"];
  14001. }
  14002. if (node.expression) {
  14003. return ["expression"];
  14004. }
  14005. throw new Error("Unexpected node has no left side", node);
  14006. }
  14007. function exprNeedsASIProtection(path$$1, options) {
  14008. const node = path$$1.getValue();
  14009. const maybeASIProblem =
  14010. needsParens_1(path$$1, options) ||
  14011. node.type === "ParenthesizedExpression" ||
  14012. node.type === "TypeCastExpression" ||
  14013. (node.type === "ArrowFunctionExpression" &&
  14014. !shouldPrintParamsWithoutParens(path$$1, options)) ||
  14015. node.type === "ArrayExpression" ||
  14016. node.type === "ArrayPattern" ||
  14017. (node.type === "UnaryExpression" &&
  14018. node.prefix &&
  14019. (node.operator === "+" || node.operator === "-")) ||
  14020. node.type === "TemplateLiteral" ||
  14021. node.type === "TemplateElement" ||
  14022. isJSXNode(node) ||
  14023. node.type === "BindExpression" ||
  14024. node.type === "RegExpLiteral" ||
  14025. (node.type === "Literal" && node.pattern) ||
  14026. (node.type === "Literal" && node.regex);
  14027. if (maybeASIProblem) {
  14028. return true;
  14029. }
  14030. if (!hasNakedLeftSide(node)) {
  14031. return false;
  14032. }
  14033. return path$$1.call.apply(
  14034. path$$1,
  14035. [childPath => exprNeedsASIProtection(childPath, options)].concat(
  14036. getLeftSidePathName(path$$1, node)
  14037. )
  14038. );
  14039. }
  14040. function stmtNeedsASIProtection(path$$1, options) {
  14041. const node = path$$1.getNode();
  14042. if (node.type !== "ExpressionStatement") {
  14043. return false;
  14044. }
  14045. return path$$1.call(
  14046. childPath => exprNeedsASIProtection(childPath, options),
  14047. "expression"
  14048. );
  14049. }
  14050. function classPropMayCauseASIProblems(path$$1) {
  14051. const node = path$$1.getNode();
  14052. if (node.type !== "ClassProperty") {
  14053. return false;
  14054. }
  14055. const name = node.key && node.key.name;
  14056. // this isn't actually possible yet with most parsers available today
  14057. // so isn't properly tested yet.
  14058. if (
  14059. (name === "static" || name === "get" || name === "set") &&
  14060. !node.value &&
  14061. !node.typeAnnotation
  14062. ) {
  14063. return true;
  14064. }
  14065. }
  14066. function classChildNeedsASIProtection(node) {
  14067. if (!node) {
  14068. return;
  14069. }
  14070. if (!node.computed) {
  14071. const name = node.key && node.key.name;
  14072. if (name === "in" || name === "instanceof") {
  14073. return true;
  14074. }
  14075. }
  14076. switch (node.type) {
  14077. case "ClassProperty":
  14078. case "TSAbstractClassProperty":
  14079. return node.computed;
  14080. case "MethodDefinition": // Flow
  14081. case "TSAbstractMethodDefinition": // TypeScript
  14082. case "ClassMethod": {
  14083. // Babylon
  14084. const isAsync = node.value ? node.value.async : node.async;
  14085. const isGenerator = node.value ? node.value.generator : node.generator;
  14086. if (
  14087. isAsync ||
  14088. node.static ||
  14089. node.kind === "get" ||
  14090. node.kind === "set"
  14091. ) {
  14092. return false;
  14093. }
  14094. if (node.computed || isGenerator) {
  14095. return true;
  14096. }
  14097. return false;
  14098. }
  14099. default:
  14100. /* istanbul ignore next */
  14101. return false;
  14102. }
  14103. }
  14104. // This recurses the return argument, looking for the first token
  14105. // (the leftmost leaf node) and, if it (or its parents) has any
  14106. // leadingComments, returns true (so it can be wrapped in parens).
  14107. function returnArgumentHasLeadingComment(options, argument) {
  14108. if (hasLeadingOwnLineComment(options.originalText, argument, options)) {
  14109. return true;
  14110. }
  14111. if (hasNakedLeftSide(argument)) {
  14112. let leftMost = argument;
  14113. let newLeftMost;
  14114. while ((newLeftMost = getLeftSide(leftMost))) {
  14115. leftMost = newLeftMost;
  14116. if (hasLeadingOwnLineComment(options.originalText, leftMost, options)) {
  14117. return true;
  14118. }
  14119. }
  14120. }
  14121. return false;
  14122. }
  14123. function isMemberExpressionChain(node) {
  14124. if (node.type !== "MemberExpression") {
  14125. return false;
  14126. }
  14127. if (node.object.type === "Identifier") {
  14128. return true;
  14129. }
  14130. return isMemberExpressionChain(node.object);
  14131. }
  14132. // Hack to differentiate between the following two which have the same ast
  14133. // type T = { method: () => void };
  14134. // type T = { method(): void };
  14135. function isObjectTypePropertyAFunction(node, options) {
  14136. return (
  14137. node.type === "ObjectTypeProperty" &&
  14138. node.value.type === "FunctionTypeAnnotation" &&
  14139. !node.static &&
  14140. !isFunctionNotation(node, options)
  14141. );
  14142. }
  14143. // TODO: This is a bad hack and we need a better way to distinguish between
  14144. // arrow functions and otherwise
  14145. function isFunctionNotation(node, options) {
  14146. return isGetterOrSetter(node) || sameLocStart(node, node.value, options);
  14147. }
  14148. function isGetterOrSetter(node) {
  14149. return node.kind === "get" || node.kind === "set";
  14150. }
  14151. function sameLocStart(nodeA, nodeB, options) {
  14152. return options.locStart(nodeA) === options.locStart(nodeB);
  14153. }
  14154. // Hack to differentiate between the following two which have the same ast
  14155. // declare function f(a): void;
  14156. // var f: (a) => void;
  14157. function isTypeAnnotationAFunction(node, options) {
  14158. return (
  14159. (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") &&
  14160. node.typeAnnotation.type === "FunctionTypeAnnotation" &&
  14161. !node.static &&
  14162. !sameLocStart(node, node.typeAnnotation, options)
  14163. );
  14164. }
  14165. function isNodeStartingWithDeclare(node, options) {
  14166. if (!(options.parser === "flow" || options.parser === "typescript")) {
  14167. return false;
  14168. }
  14169. return (
  14170. options.originalText
  14171. .slice(0, options.locStart(node))
  14172. .match(/declare[ \t]*$/) ||
  14173. options.originalText
  14174. .slice(node.range[0], node.range[1])
  14175. .startsWith("declare ")
  14176. );
  14177. }
  14178. function shouldHugType(node) {
  14179. if (isObjectType(node)) {
  14180. return true;
  14181. }
  14182. if (node.type === "UnionTypeAnnotation" || node.type === "TSUnionType") {
  14183. const voidCount = node.types.filter(
  14184. n =>
  14185. n.type === "VoidTypeAnnotation" ||
  14186. n.type === "TSVoidKeyword" ||
  14187. n.type === "NullLiteralTypeAnnotation" ||
  14188. n.type === "TSNullKeyword"
  14189. ).length;
  14190. const objectCount = node.types.filter(
  14191. n =>
  14192. n.type === "ObjectTypeAnnotation" ||
  14193. n.type === "TSTypeLiteral" ||
  14194. // This is a bit aggressive but captures Array<{x}>
  14195. n.type === "GenericTypeAnnotation" ||
  14196. n.type === "TSTypeReference"
  14197. ).length;
  14198. if (node.types.length - 1 === voidCount && objectCount > 0) {
  14199. return true;
  14200. }
  14201. }
  14202. return false;
  14203. }
  14204. function shouldHugArguments(fun) {
  14205. return (
  14206. fun &&
  14207. fun.params &&
  14208. fun.params.length === 1 &&
  14209. !fun.params[0].comments &&
  14210. (fun.params[0].type === "ObjectPattern" ||
  14211. fun.params[0].type === "ArrayPattern" ||
  14212. (fun.params[0].type === "Identifier" &&
  14213. fun.params[0].typeAnnotation &&
  14214. (fun.params[0].typeAnnotation.type === "TypeAnnotation" ||
  14215. fun.params[0].typeAnnotation.type === "TSTypeAnnotation") &&
  14216. isObjectType(fun.params[0].typeAnnotation.typeAnnotation)) ||
  14217. (fun.params[0].type === "FunctionTypeParam" &&
  14218. isObjectType(fun.params[0].typeAnnotation)) ||
  14219. (fun.params[0].type === "AssignmentPattern" &&
  14220. (fun.params[0].left.type === "ObjectPattern" ||
  14221. fun.params[0].left.type === "ArrayPattern") &&
  14222. (fun.params[0].right.type === "Identifier" ||
  14223. (fun.params[0].right.type === "ObjectExpression" &&
  14224. fun.params[0].right.properties.length === 0) ||
  14225. (fun.params[0].right.type === "ArrayExpression" &&
  14226. fun.params[0].right.elements.length === 0)))) &&
  14227. !fun.rest
  14228. );
  14229. }
  14230. function templateLiteralHasNewLines(template) {
  14231. return template.quasis.some(quasi => quasi.value.raw.includes("\n"));
  14232. }
  14233. function isTemplateOnItsOwnLine(n, text, options) {
  14234. return (
  14235. ((n.type === "TemplateLiteral" && templateLiteralHasNewLines(n)) ||
  14236. (n.type === "TaggedTemplateExpression" &&
  14237. templateLiteralHasNewLines(n.quasi))) &&
  14238. !util$1.hasNewline(text, options.locStart(n), { backwards: true })
  14239. );
  14240. }
  14241. function printArrayItems(path$$1, options, printPath, print) {
  14242. const printedElements = [];
  14243. let separatorParts = [];
  14244. path$$1.each(childPath => {
  14245. printedElements.push(concat(separatorParts));
  14246. printedElements.push(group(print(childPath)));
  14247. separatorParts = [",", line];
  14248. if (
  14249. childPath.getValue() &&
  14250. utilShared.isNextLineEmpty(
  14251. options.originalText,
  14252. childPath.getValue(),
  14253. options
  14254. )
  14255. ) {
  14256. separatorParts.push(softline);
  14257. }
  14258. }, printPath);
  14259. return concat(printedElements);
  14260. }
  14261. function hasDanglingComments(node) {
  14262. return (
  14263. node.comments &&
  14264. node.comments.some(comment => !comment.leading && !comment.trailing)
  14265. );
  14266. }
  14267. function needsHardlineAfterDanglingComment(node) {
  14268. if (!node.comments) {
  14269. return false;
  14270. }
  14271. const lastDanglingComment = util$1.getLast(
  14272. node.comments.filter(comment => !comment.leading && !comment.trailing)
  14273. );
  14274. return (
  14275. lastDanglingComment && !util$1.isBlockComment(lastDanglingComment)
  14276. );
  14277. }
  14278. function isLiteral(node) {
  14279. return (
  14280. node.type === "BooleanLiteral" ||
  14281. node.type === "DirectiveLiteral" ||
  14282. node.type === "Literal" ||
  14283. node.type === "NullLiteral" ||
  14284. node.type === "NumericLiteral" ||
  14285. node.type === "RegExpLiteral" ||
  14286. node.type === "StringLiteral" ||
  14287. node.type === "TemplateLiteral" ||
  14288. node.type === "TSTypeLiteral" ||
  14289. node.type === "JSXText"
  14290. );
  14291. }
  14292. function isNumericLiteral(node) {
  14293. return (
  14294. node.type === "NumericLiteral" ||
  14295. (node.type === "Literal" && typeof node.value === "number")
  14296. );
  14297. }
  14298. function isStringLiteral(node) {
  14299. return (
  14300. node.type === "StringLiteral" ||
  14301. (node.type === "Literal" && typeof node.value === "string")
  14302. );
  14303. }
  14304. function isObjectType(n) {
  14305. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral";
  14306. }
  14307. // eg; `describe("some string", (done) => {})`
  14308. function isTestCall(n, parent) {
  14309. const unitTestRe = /^(skip|(f|x)?(it|describe|test))$/;
  14310. if (n.arguments.length === 1) {
  14311. if (
  14312. n.callee.type === "Identifier" &&
  14313. n.callee.name === "async" &&
  14314. parent &&
  14315. parent.type === "CallExpression" &&
  14316. isTestCall(parent)
  14317. ) {
  14318. return isFunctionOrArrowExpression(n.arguments[0].type);
  14319. }
  14320. if (isUnitTestSetUp(n)) {
  14321. return (
  14322. isFunctionOrArrowExpression(n.arguments[0].type) ||
  14323. isIdentiferAsync(n.arguments[0])
  14324. );
  14325. }
  14326. } else if (n.arguments.length === 2) {
  14327. if (
  14328. ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name)) ||
  14329. isSkipOrOnlyBlock(n)) &&
  14330. (isTemplateLiteral(n.arguments[0]) || isStringLiteral(n.arguments[0]))
  14331. ) {
  14332. return (
  14333. (isFunctionOrArrowExpression(n.arguments[1].type) &&
  14334. n.arguments[1].params.length <= 1) ||
  14335. isIdentiferAsync(n.arguments[1])
  14336. );
  14337. }
  14338. }
  14339. return false;
  14340. }
  14341. function isSkipOrOnlyBlock(node) {
  14342. const unitTestRe = /^(skip|(f|x)?(it|describe|test))$/;
  14343. return (
  14344. node.callee.type === "MemberExpression" &&
  14345. node.callee.object.type === "Identifier" &&
  14346. node.callee.property.type === "Identifier" &&
  14347. unitTestRe.test(node.callee.object.name) &&
  14348. (node.callee.property.name === "only" ||
  14349. node.callee.property.name === "skip")
  14350. );
  14351. }
  14352. function isTemplateLiteral(node) {
  14353. return node.type === "TemplateLiteral";
  14354. }
  14355. function isIdentiferAsync(node) {
  14356. return (
  14357. node.type === "CallExpression" &&
  14358. node.callee.type === "Identifier" &&
  14359. node.callee.name === "async"
  14360. );
  14361. }
  14362. function isFunctionOrArrowExpression(type) {
  14363. return type === "FunctionExpression" || type === "ArrowFunctionExpression";
  14364. }
  14365. function isUnitTestSetUp(n) {
  14366. const unitTestSetUpRe = /^(before|after)(Each|All)$/;
  14367. return (
  14368. n.callee.type === "Identifier" &&
  14369. unitTestSetUpRe.test(n.callee.name) &&
  14370. n.arguments.length === 1
  14371. );
  14372. }
  14373. function isTheOnlyJSXElementInMarkdown(options, path$$1) {
  14374. if (options.parentParser !== "markdown") {
  14375. return false;
  14376. }
  14377. const node = path$$1.getNode();
  14378. if (!node.expression || !isJSXNode(node.expression)) {
  14379. return false;
  14380. }
  14381. const parent = path$$1.getParentNode();
  14382. return parent.type === "Program" && parent.body.length == 1;
  14383. }
  14384. function willPrintOwnComments(path$$1) {
  14385. const node = path$$1.getValue();
  14386. const parent = path$$1.getParentNode();
  14387. return (
  14388. ((node && isJSXNode(node)) ||
  14389. (parent &&
  14390. (parent.type === "JSXSpreadAttribute" ||
  14391. parent.type === "JSXSpreadChild" ||
  14392. parent.type === "UnionTypeAnnotation" ||
  14393. parent.type === "TSUnionType" ||
  14394. ((parent.type === "ClassDeclaration" ||
  14395. parent.type === "ClassExpression") &&
  14396. parent.superClass === node)))) &&
  14397. !util$1.hasIgnoreComment(path$$1)
  14398. );
  14399. }
  14400. function canAttachComment(node) {
  14401. return (
  14402. node.type &&
  14403. node.type !== "CommentBlock" &&
  14404. node.type !== "CommentLine" &&
  14405. node.type !== "Line" &&
  14406. node.type !== "Block" &&
  14407. node.type !== "EmptyStatement" &&
  14408. node.type !== "TemplateElement" &&
  14409. node.type !== "Import" &&
  14410. !(node.callee && node.callee.type === "Import")
  14411. );
  14412. }
  14413. function printComment(commentPath, options) {
  14414. const comment = commentPath.getValue();
  14415. switch (comment.type) {
  14416. case "CommentBlock":
  14417. case "Block": {
  14418. if (isJsDocComment(comment)) {
  14419. return printJsDocComment(comment);
  14420. }
  14421. const isInsideFlowComment =
  14422. options.originalText.substr(options.locEnd(comment) - 3, 3) === "*-/";
  14423. return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
  14424. }
  14425. case "CommentLine":
  14426. case "Line":
  14427. // Print shebangs with the proper comment characters
  14428. if (
  14429. options.originalText.slice(options.locStart(comment)).startsWith("#!")
  14430. ) {
  14431. return "#!" + comment.value.trimRight();
  14432. }
  14433. return "//" + comment.value.trimRight();
  14434. default:
  14435. throw new Error("Not a comment: " + JSON.stringify(comment));
  14436. }
  14437. }
  14438. function isJsDocComment(comment) {
  14439. const lines = comment.value.split("\n");
  14440. return (
  14441. lines.length > 1 &&
  14442. lines.slice(0, lines.length - 1).every(line => line.trim()[0] === "*")
  14443. );
  14444. }
  14445. function printJsDocComment(comment) {
  14446. const lines = comment.value.split("\n");
  14447. return concat([
  14448. "/*",
  14449. join(
  14450. hardline,
  14451. lines.map(
  14452. (line, index) =>
  14453. (index > 0 ? " " : "") +
  14454. (index < lines.length - 1 ? line.trim() : line.trimLeft())
  14455. )
  14456. ),
  14457. "*/"
  14458. ]);
  14459. }
  14460. function rawText(node) {
  14461. return node.extra ? node.extra.raw : node.raw;
  14462. }
  14463. var printerEstree = {
  14464. print: genericPrint,
  14465. embed: embed_1,
  14466. insertPragma,
  14467. massageAstNode: clean_1,
  14468. hasPrettierIgnore,
  14469. willPrintOwnComments,
  14470. canAttachComment,
  14471. printComment,
  14472. handleComments: {
  14473. ownLine: comments$2.handleOwnLineComment,
  14474. endOfLine: comments$2.handleEndOfLineComment,
  14475. remaining: comments$2.handleRemainingComment
  14476. }
  14477. };
  14478. const CATEGORY_JAVASCRIPT = "JavaScript";
  14479. // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js
  14480. var options = {
  14481. arrowParens: {
  14482. since: "1.9.0",
  14483. category: CATEGORY_JAVASCRIPT,
  14484. type: "choice",
  14485. default: "avoid",
  14486. description: "Include parentheses around a sole arrow function parameter.",
  14487. choices: [
  14488. {
  14489. value: "avoid",
  14490. description: "Omit parens when possible. Example: `x => x`"
  14491. },
  14492. {
  14493. value: "always",
  14494. description: "Always include parens. Example: `(x) => x`"
  14495. }
  14496. ]
  14497. },
  14498. bracketSpacing: {
  14499. since: "0.0.0",
  14500. category: CATEGORY_JAVASCRIPT,
  14501. type: "boolean",
  14502. default: true,
  14503. description: "Print spaces between brackets.",
  14504. oppositeDescription: "Do not print spaces between brackets."
  14505. },
  14506. jsxBracketSameLine: {
  14507. since: "0.17.0",
  14508. category: CATEGORY_JAVASCRIPT,
  14509. type: "boolean",
  14510. default: false,
  14511. description: "Put > on the last line instead of at a new line."
  14512. },
  14513. semi: {
  14514. since: "1.0.0",
  14515. category: CATEGORY_JAVASCRIPT,
  14516. type: "boolean",
  14517. default: true,
  14518. description: "Print semicolons.",
  14519. oppositeDescription:
  14520. "Do not print semicolons, except at the beginning of lines which may need them."
  14521. },
  14522. singleQuote: {
  14523. since: "0.0.0",
  14524. category: CATEGORY_JAVASCRIPT,
  14525. type: "boolean",
  14526. default: false,
  14527. description: "Use single quotes instead of double quotes."
  14528. },
  14529. trailingComma: {
  14530. since: "0.0.0",
  14531. category: CATEGORY_JAVASCRIPT,
  14532. type: "choice",
  14533. default: [
  14534. { since: "0.0.0", value: false },
  14535. { since: "0.19.0", value: "none" }
  14536. ],
  14537. description: "Print trailing commas wherever possible when multi-line.",
  14538. choices: [
  14539. { value: "none", description: "No trailing commas." },
  14540. {
  14541. value: "es5",
  14542. description:
  14543. "Trailing commas where valid in ES5 (objects, arrays, etc.)"
  14544. },
  14545. {
  14546. value: "all",
  14547. description:
  14548. "Trailing commas wherever possible (including function arguments)."
  14549. },
  14550. { value: true, deprecated: "0.19.0", redirect: "es5" },
  14551. { value: false, deprecated: "0.19.0", redirect: "none" }
  14552. ]
  14553. }
  14554. };
  14555. const hasPragma = pragma.hasPragma;
  14556. // Based on:
  14557. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  14558. const locStart = function(node) {
  14559. // Handle nodes with decorators. They should start at the first decorator
  14560. if (
  14561. node.declaration &&
  14562. node.declaration.decorators &&
  14563. node.declaration.decorators.length > 0
  14564. ) {
  14565. return locStart(node.declaration.decorators[0]);
  14566. }
  14567. if (node.decorators && node.decorators.length > 0) {
  14568. return locStart(node.decorators[0]);
  14569. }
  14570. if (node.__location) {
  14571. return node.__location.startOffset;
  14572. }
  14573. if (node.range) {
  14574. return node.range[0];
  14575. }
  14576. if (typeof node.start === "number") {
  14577. return node.start;
  14578. }
  14579. if (node.loc) {
  14580. return node.loc.start;
  14581. }
  14582. return null;
  14583. };
  14584. const locEnd = function(node) {
  14585. const endNode = node.nodes && util$1.getLast(node.nodes);
  14586. if (endNode && node.source && !node.source.end) {
  14587. node = endNode;
  14588. }
  14589. let loc;
  14590. if (node.range) {
  14591. loc = node.range[1];
  14592. } else if (typeof node.end === "number") {
  14593. loc = node.end;
  14594. }
  14595. if (node.__location) {
  14596. return node.__location.endOffset;
  14597. }
  14598. if (node.typeAnnotation) {
  14599. return Math.max(loc, locEnd(node.typeAnnotation));
  14600. }
  14601. if (node.loc && !loc) {
  14602. return node.loc.end;
  14603. }
  14604. return loc;
  14605. };
  14606. const languages = [
  14607. {
  14608. name: "JavaScript",
  14609. since: "0.0.0",
  14610. parsers: ["babylon", "flow"],
  14611. group: "JavaScript",
  14612. tmScope: "source.js",
  14613. aceMode: "javascript",
  14614. codemirrorMode: "javascript",
  14615. codemirrorMimeType: "text/javascript",
  14616. aliases: ["js", "node"],
  14617. extensions: [
  14618. ".js",
  14619. "._js",
  14620. ".bones",
  14621. ".es",
  14622. ".es6",
  14623. ".frag",
  14624. ".gs",
  14625. ".jake",
  14626. ".jsb",
  14627. ".jscad",
  14628. ".jsfl",
  14629. ".jsm",
  14630. ".jss",
  14631. ".mjs",
  14632. ".njs",
  14633. ".pac",
  14634. ".sjs",
  14635. ".ssjs",
  14636. ".xsjs",
  14637. ".xsjslib"
  14638. ],
  14639. filenames: ["Jakefile"],
  14640. linguistLanguageId: 183,
  14641. vscodeLanguageIds: ["javascript"]
  14642. },
  14643. {
  14644. name: "JSX",
  14645. since: "0.0.0",
  14646. parsers: ["babylon", "flow"],
  14647. group: "JavaScript",
  14648. extensions: [".jsx"],
  14649. tmScope: "source.js.jsx",
  14650. aceMode: "javascript",
  14651. codemirrorMode: "jsx",
  14652. codemirrorMimeType: "text/jsx",
  14653. liguistLanguageId: 178,
  14654. vscodeLanguageIds: ["javascriptreact"]
  14655. },
  14656. {
  14657. name: "TypeScript",
  14658. since: "1.4.0",
  14659. parsers: ["typescript-eslint"],
  14660. group: "JavaScript",
  14661. aliases: ["ts"],
  14662. extensions: [".ts", ".tsx"],
  14663. tmScope: "source.ts",
  14664. aceMode: "typescript",
  14665. codemirrorMode: "javascript",
  14666. codemirrorMimeType: "application/typescript",
  14667. liguistLanguageId: 378,
  14668. vscodeLanguageIds: ["typescript", "typescriptreact"]
  14669. },
  14670. {
  14671. name: "JSON",
  14672. since: "1.5.0",
  14673. parsers: ["json"],
  14674. group: "JavaScript",
  14675. tmScope: "source.json",
  14676. aceMode: "json",
  14677. codemirrorMode: "javascript",
  14678. codemirrorMimeType: "application/json",
  14679. extensions: [
  14680. ".json",
  14681. ".json5",
  14682. ".geojson",
  14683. ".JSON-tmLanguage",
  14684. ".topojson"
  14685. ],
  14686. filenames: [
  14687. ".arcconfig",
  14688. ".jshintrc",
  14689. ".babelrc",
  14690. ".eslintrc",
  14691. ".prettierrc",
  14692. "composer.lock",
  14693. "mcmod.info"
  14694. ],
  14695. linguistLanguageId: 174,
  14696. vscodeLanguageIds: ["json", "jsonc"]
  14697. }
  14698. ];
  14699. const typescript = {
  14700. get parse() {
  14701. return require("./parser-typescript");
  14702. },
  14703. astFormat: "estree",
  14704. hasPragma,
  14705. locStart,
  14706. locEnd
  14707. };
  14708. const babylon = {
  14709. get parse() {
  14710. return require("./parser-babylon");
  14711. },
  14712. astFormat: "estree",
  14713. hasPragma,
  14714. locStart,
  14715. locEnd
  14716. };
  14717. const parsers = {
  14718. babylon,
  14719. json: Object.assign({}, babylon, {
  14720. hasPragma() {
  14721. return false;
  14722. }
  14723. }),
  14724. flow: {
  14725. get parse() {
  14726. return require("./parser-flow");
  14727. },
  14728. astFormat: "estree",
  14729. hasPragma,
  14730. locStart,
  14731. locEnd
  14732. },
  14733. "typescript-eslint": typescript,
  14734. // TODO: Delete this in 2.0
  14735. typescript
  14736. };
  14737. const printers = {
  14738. estree: printerEstree
  14739. };
  14740. var languageJs = {
  14741. languages,
  14742. options,
  14743. parsers,
  14744. printers,
  14745. locStart,
  14746. locEnd
  14747. };
  14748. var index$1 = [
  14749. "a",
  14750. "abbr",
  14751. "acronym",
  14752. "address",
  14753. "applet",
  14754. "area",
  14755. "article",
  14756. "aside",
  14757. "audio",
  14758. "b",
  14759. "base",
  14760. "basefont",
  14761. "bdi",
  14762. "bdo",
  14763. "bgsound",
  14764. "big",
  14765. "blink",
  14766. "blockquote",
  14767. "body",
  14768. "br",
  14769. "button",
  14770. "canvas",
  14771. "caption",
  14772. "center",
  14773. "cite",
  14774. "code",
  14775. "col",
  14776. "colgroup",
  14777. "command",
  14778. "content",
  14779. "data",
  14780. "datalist",
  14781. "dd",
  14782. "del",
  14783. "details",
  14784. "dfn",
  14785. "dialog",
  14786. "dir",
  14787. "div",
  14788. "dl",
  14789. "dt",
  14790. "element",
  14791. "em",
  14792. "embed",
  14793. "fieldset",
  14794. "figcaption",
  14795. "figure",
  14796. "font",
  14797. "footer",
  14798. "form",
  14799. "frame",
  14800. "frameset",
  14801. "h1",
  14802. "h2",
  14803. "h3",
  14804. "h4",
  14805. "h5",
  14806. "h6",
  14807. "head",
  14808. "header",
  14809. "hgroup",
  14810. "hr",
  14811. "html",
  14812. "i",
  14813. "iframe",
  14814. "image",
  14815. "img",
  14816. "input",
  14817. "ins",
  14818. "isindex",
  14819. "kbd",
  14820. "keygen",
  14821. "label",
  14822. "legend",
  14823. "li",
  14824. "link",
  14825. "listing",
  14826. "main",
  14827. "map",
  14828. "mark",
  14829. "marquee",
  14830. "math",
  14831. "menu",
  14832. "menuitem",
  14833. "meta",
  14834. "meter",
  14835. "multicol",
  14836. "nav",
  14837. "nextid",
  14838. "nobr",
  14839. "noembed",
  14840. "noframes",
  14841. "noscript",
  14842. "object",
  14843. "ol",
  14844. "optgroup",
  14845. "option",
  14846. "output",
  14847. "p",
  14848. "param",
  14849. "picture",
  14850. "plaintext",
  14851. "pre",
  14852. "progress",
  14853. "q",
  14854. "rb",
  14855. "rbc",
  14856. "rp",
  14857. "rt",
  14858. "rtc",
  14859. "ruby",
  14860. "s",
  14861. "samp",
  14862. "script",
  14863. "section",
  14864. "select",
  14865. "shadow",
  14866. "slot",
  14867. "small",
  14868. "source",
  14869. "spacer",
  14870. "span",
  14871. "strike",
  14872. "strong",
  14873. "style",
  14874. "sub",
  14875. "summary",
  14876. "sup",
  14877. "svg",
  14878. "table",
  14879. "tbody",
  14880. "td",
  14881. "template",
  14882. "textarea",
  14883. "tfoot",
  14884. "th",
  14885. "thead",
  14886. "time",
  14887. "title",
  14888. "tr",
  14889. "track",
  14890. "tt",
  14891. "u",
  14892. "ul",
  14893. "var",
  14894. "video",
  14895. "wbr",
  14896. "xmp"
  14897. ]
  14898. ;
  14899. var htmlTagNames = Object.freeze({
  14900. default: index$1
  14901. });
  14902. var htmlTagNames$1 = ( htmlTagNames && index$1 ) || htmlTagNames;
  14903. function clean$2(ast, newObj) {
  14904. if (
  14905. ast.type === "media-query" ||
  14906. ast.type === "media-query-list" ||
  14907. ast.type === "media-feature-expression"
  14908. ) {
  14909. delete newObj.value;
  14910. }
  14911. if (ast.type === "css-rule") {
  14912. delete newObj.params;
  14913. }
  14914. if (ast.type === "selector-combinator") {
  14915. newObj.value = newObj.value.replace(/\s+/g, " ");
  14916. }
  14917. if (ast.type === "media-feature") {
  14918. newObj.value = newObj.value.replace(/ /g, "");
  14919. }
  14920. if (
  14921. (ast.type === "value-word" &&
  14922. ((ast.isColor && ast.isHex) ||
  14923. ["initial", "inherit", "unset", "revert"].indexOf(
  14924. newObj.value.replace().toLowerCase()
  14925. ) !== -1)) ||
  14926. ast.type === "media-feature" ||
  14927. ast.type === "selector-root-invalid" ||
  14928. ast.type === "selector-pseudo"
  14929. ) {
  14930. newObj.value = newObj.value.toLowerCase();
  14931. }
  14932. if (ast.type === "css-decl") {
  14933. newObj.prop = newObj.prop.toLowerCase();
  14934. }
  14935. if (ast.type === "css-atrule" || ast.type === "css-import") {
  14936. newObj.name = newObj.name.toLowerCase();
  14937. }
  14938. if (ast.type === "value-number") {
  14939. newObj.unit = newObj.unit.toLowerCase();
  14940. }
  14941. if (
  14942. (ast.type === "media-feature" ||
  14943. ast.type === "media-keyword" ||
  14944. ast.type === "media-type" ||
  14945. ast.type === "media-unknown" ||
  14946. ast.type === "media-url" ||
  14947. ast.type === "media-value" ||
  14948. ast.type === "selector-root-invalid" ||
  14949. ast.type === "selector-attribute" ||
  14950. ast.type === "selector-string" ||
  14951. ast.type === "selector-class" ||
  14952. ast.type === "selector-combinator" ||
  14953. ast.type === "value-string") &&
  14954. newObj.value
  14955. ) {
  14956. newObj.value = cleanCSSStrings(newObj.value);
  14957. }
  14958. if (ast.type === "css-import" && newObj.importPath) {
  14959. newObj.importPath = cleanCSSStrings(newObj.importPath);
  14960. }
  14961. if (ast.type === "selector-attribute") {
  14962. newObj.attribute = newObj.attribute.trim();
  14963. if (newObj.namespace) {
  14964. if (typeof newObj.namespace === "string") {
  14965. newObj.namespace = newObj.namespace.trim();
  14966. if (newObj.namespace.length === 0) {
  14967. newObj.namespace = true;
  14968. }
  14969. }
  14970. }
  14971. if (newObj.value) {
  14972. newObj.value = newObj.value.trim().replace(/^['"]|['"]$/g, "");
  14973. delete newObj.quoted;
  14974. }
  14975. }
  14976. if (
  14977. (ast.type === "media-value" ||
  14978. ast.type === "media-type" ||
  14979. ast.type === "value-number" ||
  14980. ast.type === "selector-root-invalid" ||
  14981. ast.type === "selector-class" ||
  14982. ast.type === "selector-combinator" ||
  14983. ast.type === "selector-tag") &&
  14984. newObj.value
  14985. ) {
  14986. newObj.value = newObj.value.replace(
  14987. /([\d.eE+-]+)([a-zA-Z]*)/g,
  14988. (match, numStr, unit) => {
  14989. const num = Number(numStr);
  14990. return isNaN(num) ? match : num + unit.toLowerCase();
  14991. }
  14992. );
  14993. }
  14994. if (ast.type === "media-url") {
  14995. newObj.value = newObj.value
  14996. .replace(/^url\(\s+/gi, "url(")
  14997. .replace(/\s+\)$/gi, ")");
  14998. }
  14999. if (ast.type === "selector-tag") {
  15000. const lowercasedValue = ast.value.toLowerCase();
  15001. if (htmlTagNames$1.indexOf(lowercasedValue) !== -1) {
  15002. newObj.value = lowercasedValue;
  15003. }
  15004. if (["from", "to"].indexOf(lowercasedValue) !== -1) {
  15005. newObj.value = lowercasedValue;
  15006. }
  15007. }
  15008. }
  15009. function cleanCSSStrings(value) {
  15010. return value.replace(/'/g, '"').replace(/\\([^a-fA-F\d])/g, "$1");
  15011. }
  15012. var clean_1$2 = clean$2;
  15013. const docBuilders$6 = doc.builders;
  15014. const concat$5 = docBuilders$6.concat;
  15015. const join$4 = docBuilders$6.join;
  15016. const line$2 = docBuilders$6.line;
  15017. const hardline$4 = docBuilders$6.hardline;
  15018. const softline$3 = docBuilders$6.softline;
  15019. const group$2 = docBuilders$6.group;
  15020. const fill$3 = docBuilders$6.fill;
  15021. const indent$4 = docBuilders$6.indent;
  15022. const removeLines$1 = doc.utils.removeLines;
  15023. function genericPrint$1(path$$1, options, print) {
  15024. const node = path$$1.getValue();
  15025. /* istanbul ignore if */
  15026. if (!node) {
  15027. return "";
  15028. }
  15029. if (typeof node === "string") {
  15030. return node;
  15031. }
  15032. switch (node.type) {
  15033. case "css-comment-yaml":
  15034. return node.value;
  15035. case "css-root": {
  15036. const nodes = printNodeSequence(path$$1, options, print);
  15037. if (nodes.parts.length) {
  15038. return concat$5([nodes, hardline$4]);
  15039. }
  15040. return nodes;
  15041. }
  15042. case "css-comment": {
  15043. if (node.raws.content) {
  15044. return node.raws.content;
  15045. }
  15046. const text = options.originalText.slice(
  15047. options.locStart(node),
  15048. options.locEnd(node)
  15049. );
  15050. const rawText = node.raws.text || node.text;
  15051. // Workaround a bug where the location is off.
  15052. // https://github.com/postcss/postcss-scss/issues/63
  15053. if (text.indexOf(rawText) === -1) {
  15054. if (node.raws.inline) {
  15055. return concat$5(["// ", rawText]);
  15056. }
  15057. return concat$5(["/* ", rawText, " */"]);
  15058. }
  15059. return text;
  15060. }
  15061. case "css-rule": {
  15062. return concat$5([
  15063. path$$1.call(print, "selector"),
  15064. node.important ? " !important" : "",
  15065. node.nodes
  15066. ? concat$5([
  15067. " {",
  15068. node.nodes.length > 0
  15069. ? indent$4(
  15070. concat$5([hardline$4, printNodeSequence(path$$1, options, print)])
  15071. )
  15072. : "",
  15073. hardline$4,
  15074. "}",
  15075. isDetachedRulesetDeclaration(node) ? ";" : ""
  15076. ])
  15077. : ";"
  15078. ]);
  15079. }
  15080. case "css-decl": {
  15081. // When the following less construct &:extend(.foo); is parsed with scss,
  15082. // it will put a space after `:` and break it. Ideally we should parse
  15083. // less files with less, but we can hardcode this to work with scss as
  15084. // well.
  15085. const isValueExtend =
  15086. node.value.type === "value-root" &&
  15087. node.value.group.type === "value-value" &&
  15088. node.value.group.group.type === "value-func" &&
  15089. node.value.group.group.value === "extend";
  15090. const isComposed =
  15091. node.value.type === "value-root" &&
  15092. node.value.group.type === "value-value" &&
  15093. node.prop === "composes";
  15094. const ruleAncestorNode = getAncestorNode(path$$1, "css-rule");
  15095. const isiCSS =
  15096. ruleAncestorNode &&
  15097. ruleAncestorNode.raws.selector &&
  15098. (ruleAncestorNode.raws.selector.startsWith(":import") ||
  15099. ruleAncestorNode.raws.selector.startsWith(":export"));
  15100. return concat$5([
  15101. node.raws.before.replace(/[\s;]/g, ""),
  15102. isiCSS ? node.prop : maybeToLowerCase(node.prop),
  15103. node.raws.between.trim() === ":" ? ":" : node.raws.between.trim(),
  15104. isValueExtend ? "" : " ",
  15105. isComposed
  15106. ? removeLines$1(path$$1.call(print, "value"))
  15107. : path$$1.call(print, "value"),
  15108. node.raws.important
  15109. ? node.raws.important.replace(/\s*!\s*important/i, " !important")
  15110. : node.important
  15111. ? " !important"
  15112. : "",
  15113. node.raws.scssDefault
  15114. ? node.raws.scssDefault.replace(/\s*!default/i, " !default")
  15115. : node.scssDefault
  15116. ? " !default"
  15117. : "",
  15118. node.raws.scssGlobal
  15119. ? node.raws.scssGlobal.replace(/\s*!global/i, " !global")
  15120. : node.scssGlobal
  15121. ? " !global"
  15122. : "",
  15123. node.nodes
  15124. ? concat$5([
  15125. " {",
  15126. indent$4(
  15127. concat$5([softline$3, printNodeSequence(path$$1, options, print)])
  15128. ),
  15129. softline$3,
  15130. "}"
  15131. ])
  15132. : ";"
  15133. ]);
  15134. }
  15135. case "css-atrule": {
  15136. const hasParams =
  15137. node.params &&
  15138. !(node.params.type === "media-query-list" && node.params.value === "");
  15139. const isDetachedRulesetCall = hasParams && /^\(\s*\)$/.test(node.params);
  15140. const hasParensAround =
  15141. node.value &&
  15142. node.value.group.group.type === "value-paren_group" &&
  15143. node.value.group.group.open !== null &&
  15144. node.value.group.group.close !== null;
  15145. return concat$5([
  15146. "@",
  15147. // If a Less file ends up being parsed with the SCSS parser, Less
  15148. // variable declarations will be parsed as atrules with names ending
  15149. // with a colon, so keep the original case then.
  15150. isDetachedRulesetCall || node.name.endsWith(":")
  15151. ? node.name
  15152. : maybeToLowerCase(node.name),
  15153. hasParams
  15154. ? concat$5([
  15155. isDetachedRulesetCall ? "" : " ",
  15156. path$$1.call(print, "params")
  15157. ])
  15158. : "",
  15159. node.selector
  15160. ? indent$4(concat$5([" ", path$$1.call(print, "selector")]))
  15161. : "",
  15162. node.value
  15163. ? group$2(
  15164. concat$5([
  15165. " ",
  15166. path$$1.call(print, "value"),
  15167. isControlDirectiveNode(node)
  15168. ? hasParensAround
  15169. ? " "
  15170. : line$2
  15171. : ""
  15172. ])
  15173. )
  15174. : node.name === "else"
  15175. ? " "
  15176. : "",
  15177. node.nodes
  15178. ? concat$5([
  15179. isControlDirectiveNode(node) ? "" : " ",
  15180. "{",
  15181. indent$4(
  15182. concat$5([
  15183. node.nodes.length > 0 ? softline$3 : "",
  15184. printNodeSequence(path$$1, options, print)
  15185. ])
  15186. ),
  15187. softline$3,
  15188. "}"
  15189. ])
  15190. : ";"
  15191. ]);
  15192. }
  15193. case "css-import": {
  15194. return concat$5([
  15195. "@",
  15196. maybeToLowerCase(node.name),
  15197. " ",
  15198. node.directives ? concat$5([node.directives, " "]) : "",
  15199. adjustStrings(node.importPath, options),
  15200. node.nodes.length > 0
  15201. ? concat$5([
  15202. " {",
  15203. indent$4(
  15204. concat$5([softline$3, printNodeSequence(path$$1, options, print)])
  15205. ),
  15206. softline$3,
  15207. "}"
  15208. ])
  15209. : ";"
  15210. ]);
  15211. }
  15212. // postcss-media-query-parser
  15213. case "media-query-list": {
  15214. const parts = [];
  15215. path$$1.each(childPath => {
  15216. const node = childPath.getValue();
  15217. if (node.type === "media-query" && node.value === "") {
  15218. return;
  15219. }
  15220. parts.push(childPath.call(print));
  15221. }, "nodes");
  15222. return group$2(indent$4(join$4(line$2, parts)));
  15223. }
  15224. case "media-query": {
  15225. return concat$5([
  15226. join$4(" ", path$$1.map(print, "nodes")),
  15227. isLastNode(path$$1, node) ? "" : ","
  15228. ]);
  15229. }
  15230. case "media-type": {
  15231. const atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
  15232. if (
  15233. atRuleAncestorNode &&
  15234. atRuleAncestorNode.name.toLowerCase() === "charset"
  15235. ) {
  15236. return node.value;
  15237. }
  15238. return adjustNumbers(adjustStrings(node.value, options));
  15239. }
  15240. case "media-feature-expression": {
  15241. if (!node.nodes) {
  15242. return node.value;
  15243. }
  15244. return concat$5(["(", concat$5(path$$1.map(print, "nodes")), ")"]);
  15245. }
  15246. case "media-feature": {
  15247. return maybeToLowerCase(
  15248. adjustStrings(node.value.replace(/ +/g, " "), options)
  15249. );
  15250. }
  15251. case "media-colon": {
  15252. return concat$5([node.value, " "]);
  15253. }
  15254. case "media-value": {
  15255. return adjustNumbers(adjustStrings(node.value, options));
  15256. }
  15257. case "media-keyword": {
  15258. return adjustStrings(node.value, options);
  15259. }
  15260. case "media-url": {
  15261. return adjustStrings(
  15262. node.value.replace(/^url\(\s+/gi, "url(").replace(/\s+\)$/gi, ")"),
  15263. options
  15264. );
  15265. }
  15266. case "media-unknown": {
  15267. return adjustStrings(node.value, options);
  15268. }
  15269. // postcss-selector-parser
  15270. case "selector-root-invalid": {
  15271. // This is likely a SCSS nested property: `background: { color: red; }`.
  15272. return adjustNumbers(
  15273. adjustStrings(maybeToLowerCase(node.value), options)
  15274. );
  15275. }
  15276. case "selector-root": {
  15277. const atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
  15278. const insideAtRuleNode =
  15279. atRuleAncestorNode &&
  15280. ["extend", "custom-selector", "nest"].indexOf(
  15281. atRuleAncestorNode.name
  15282. ) !== -1;
  15283. return group$2(
  15284. concat$5([
  15285. atRuleAncestorNode && atRuleAncestorNode.name === "custom-selector"
  15286. ? concat$5([atRuleAncestorNode.customSelector, line$2])
  15287. : "",
  15288. join$4(
  15289. concat$5([",", insideAtRuleNode ? line$2 : hardline$4]),
  15290. path$$1.map(print, "nodes")
  15291. )
  15292. ])
  15293. );
  15294. }
  15295. case "selector-comment": {
  15296. return node.value;
  15297. }
  15298. case "selector-string": {
  15299. return adjustStrings(node.value, options);
  15300. }
  15301. case "selector-tag": {
  15302. const parentNode = path$$1.getParentNode();
  15303. const index = parentNode && parentNode.nodes.indexOf(node);
  15304. const prevNode = index && parentNode.nodes[index - 1];
  15305. return concat$5([
  15306. node.namespace
  15307. ? concat$5([node.namespace === true ? "" : node.namespace.trim(), "|"])
  15308. : "",
  15309. prevNode.type === "selector-nesting"
  15310. ? node.value
  15311. : adjustNumbers(
  15312. isHTMLTag(node.value) ||
  15313. isKeyframeAtRuleKeywords(path$$1, node.value)
  15314. ? node.value.toLowerCase()
  15315. : node.value
  15316. )
  15317. ]);
  15318. }
  15319. case "selector-id": {
  15320. return concat$5(["#", node.value]);
  15321. }
  15322. case "selector-class": {
  15323. return concat$5([".", adjustNumbers(adjustStrings(node.value, options))]);
  15324. }
  15325. case "selector-attribute": {
  15326. return concat$5([
  15327. "[",
  15328. node.namespace
  15329. ? concat$5([node.namespace === true ? "" : node.namespace.trim(), "|"])
  15330. : "",
  15331. node.attribute.trim(),
  15332. node.operator ? node.operator : "",
  15333. node.value
  15334. ? quoteAttributeValue(
  15335. adjustStrings(node.value.trim(), options),
  15336. options
  15337. )
  15338. : "",
  15339. node.insensitive ? " i" : "",
  15340. "]"
  15341. ]);
  15342. }
  15343. case "selector-combinator": {
  15344. if (
  15345. node.value === "+" ||
  15346. node.value === ">" ||
  15347. node.value === "~" ||
  15348. node.value === ">>>"
  15349. ) {
  15350. const parentNode = path$$1.getParentNode();
  15351. const leading =
  15352. parentNode.type === "selector-selector" &&
  15353. parentNode.nodes[0] === node
  15354. ? ""
  15355. : line$2;
  15356. return concat$5([leading, node.value, isLastNode(path$$1, node) ? "" : " "]);
  15357. }
  15358. const leading = node.value.trim().startsWith("(") ? line$2 : "";
  15359. const value =
  15360. adjustNumbers(adjustStrings(node.value.trim(), options)) || line$2;
  15361. return concat$5([leading, value]);
  15362. }
  15363. case "selector-universal": {
  15364. return concat$5([
  15365. node.namespace
  15366. ? concat$5([node.namespace === true ? "" : node.namespace.trim(), "|"])
  15367. : "",
  15368. adjustNumbers(node.value)
  15369. ]);
  15370. }
  15371. case "selector-selector": {
  15372. return group$2(indent$4(concat$5(path$$1.map(print, "nodes"))));
  15373. }
  15374. case "selector-pseudo": {
  15375. return concat$5([
  15376. maybeToLowerCase(node.value),
  15377. node.nodes && node.nodes.length > 0
  15378. ? concat$5(["(", join$4(", ", path$$1.map(print, "nodes")), ")"])
  15379. : ""
  15380. ]);
  15381. }
  15382. case "selector-nesting": {
  15383. return node.value;
  15384. }
  15385. // postcss-values-parser
  15386. case "value-root": {
  15387. return path$$1.call(print, "group");
  15388. }
  15389. case "value-comment": {
  15390. return concat$5([
  15391. node.inline ? "//" : "/*",
  15392. node.value,
  15393. node.inline ? "" : "*/"
  15394. ]);
  15395. }
  15396. case "value-comma_group": {
  15397. const parentNode = path$$1.getParentNode();
  15398. const declAncestorNode = getAncestorNode(path$$1, "css-decl");
  15399. const declAncestorProp =
  15400. declAncestorNode &&
  15401. declAncestorNode.prop &&
  15402. declAncestorNode.prop.toLowerCase();
  15403. const isGridValue =
  15404. declAncestorProp &&
  15405. parentNode.type === "value-value" &&
  15406. (declAncestorProp === "grid" ||
  15407. declAncestorProp.startsWith("grid-template"));
  15408. const atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
  15409. const isControlDirective =
  15410. atRuleAncestorNode && isControlDirectiveNode(atRuleAncestorNode);
  15411. const printed = path$$1.map(print, "groups");
  15412. const parts = [];
  15413. const functionAncestorNode = getAncestorNode(path$$1, "value-func");
  15414. const insideInFunction =
  15415. functionAncestorNode && functionAncestorNode.value;
  15416. const insideURLFunction =
  15417. insideInFunction && functionAncestorNode.value.toLowerCase() === "url";
  15418. let didBreak = false;
  15419. for (let i = 0; i < node.groups.length; ++i) {
  15420. parts.push(printed[i]);
  15421. // Ignore value inside `url()`
  15422. if (insideURLFunction) {
  15423. continue;
  15424. }
  15425. const iPrevNode = node.groups[i - 1];
  15426. const iNode = node.groups[i];
  15427. const iNextNode = node.groups[i + 1];
  15428. const iNextNextNode = node.groups[i + 2];
  15429. // Ignore after latest node (i.e. before semicolon)
  15430. if (!iNextNode) {
  15431. continue;
  15432. }
  15433. // Ignore colon
  15434. if (iNode.value === ":") {
  15435. continue;
  15436. }
  15437. // Ignore `@` in Less (i.e. `@@var;`)
  15438. if (iNode.type === "value-atword" && iNode.value === "") {
  15439. continue;
  15440. }
  15441. // Ignore `~` in Less (i.e. `content: ~"^//* some horrible but needed css hack";`)
  15442. if (iNode.value === "~") {
  15443. continue;
  15444. }
  15445. if (
  15446. (iPrevNode &&
  15447. iPrevNode.type === "value-comment" &&
  15448. iPrevNode.inline) ||
  15449. (iNextNode.type === "value-comment" && iNextNode.inline)
  15450. ) {
  15451. continue;
  15452. }
  15453. const isHash = iNode.type === "value-word" && iNode.value === "#";
  15454. const isLeftCurlyBrace =
  15455. iNode.type === "value-word" && iNode.value === "{";
  15456. const isNextLeftCurlyBrace =
  15457. iNextNode.type === "value-word" && iNextNode.value === "{";
  15458. const isRightCurlyBrace =
  15459. iNode.type === "value-word" && iNode.value === "}";
  15460. const isNextRightCurlyBrace =
  15461. iNextNode.type === "value-word" && iNextNode.value === "}";
  15462. // Ignore interpolation in SCSS (i.e. ``#{variable}``)
  15463. if (
  15464. isHash ||
  15465. isLeftCurlyBrace ||
  15466. isNextRightCurlyBrace ||
  15467. (isNextLeftCurlyBrace &&
  15468. iNextNode.raws &&
  15469. iNextNode.raws.before === "") ||
  15470. (isRightCurlyBrace && iNextNode.raws && iNextNode.raws.before === "")
  15471. ) {
  15472. continue;
  15473. }
  15474. const isNextHash =
  15475. iNextNode.type === "value-word" && iNextNode.value === "#";
  15476. const isMathOperator = isMathOperatorNode(iNode);
  15477. const isNextMathOperator = isMathOperatorNode(iNextNode);
  15478. const isMultiplication =
  15479. !isNextHash && isMathOperator && iNode.value === "*";
  15480. const isNextMultiplication =
  15481. !isRightCurlyBrace && isNextMathOperator && iNextNode.value === "*";
  15482. const isDivision = !isNextHash && isMathOperator && iNode.value === "/";
  15483. const isNextDivision =
  15484. !isRightCurlyBrace && isNextMathOperator && iNextNode.value === "/";
  15485. const isAddition = !isNextHash && isMathOperator && iNode.value === "+";
  15486. const isNextAddition =
  15487. !isRightCurlyBrace && isNextMathOperator && iNextNode.value === "+";
  15488. const isPrevFunction = iPrevNode && iPrevNode.type === "value-func";
  15489. const isFunction = iNode.type === "value-func";
  15490. const isNextFunction = iNextNode.type === "value-func";
  15491. const isNextNextFunction =
  15492. iNextNextNode && iNextNextNode.type === "value-func";
  15493. const isPrevWord =
  15494. iPrevNode &&
  15495. ["value-word", "value-atword"].indexOf(iPrevNode.type) !== -1;
  15496. const isWord =
  15497. ["value-word", "value-atword"].indexOf(iNode.type) !== -1;
  15498. const isNextWord =
  15499. ["value-word", "value-atword"].indexOf(iNextNode.type) !== -1;
  15500. const isNextNextWord =
  15501. iNextNextNode &&
  15502. ["value-word", "value-atword"].indexOf(iNextNextNode.type) !== -1;
  15503. // Math operators
  15504. const insideCalcFunction =
  15505. insideInFunction &&
  15506. functionAncestorNode.value.toLowerCase() === "calc";
  15507. const hasSpaceBeforeOperator =
  15508. isNextNextFunction || isNextNextWord || isFunction || isWord;
  15509. const hasSpaceAfterOperator =
  15510. isNextFunction || isNextWord || isPrevFunction || isPrevWord;
  15511. if (
  15512. (isMathOperator || isNextMathOperator) &&
  15513. // Multiplication
  15514. !isMultiplication &&
  15515. !isNextMultiplication &&
  15516. // Division
  15517. !(isNextDivision && (hasSpaceBeforeOperator || insideCalcFunction)) &&
  15518. !(isDivision && (hasSpaceAfterOperator || insideCalcFunction)) &&
  15519. // Addition
  15520. !(isNextAddition && hasSpaceBeforeOperator) &&
  15521. !(isAddition && hasSpaceAfterOperator)
  15522. ) {
  15523. const isNextParenGroup = isParenGroupNode(iNextNode);
  15524. const isNextValueNumber = iNextNode.type === "value-number";
  15525. if (
  15526. (iNextNode.raws && iNextNode.raws.before === "") ||
  15527. (isMathOperator &&
  15528. (isNextParenGroup ||
  15529. isNextWord ||
  15530. isNextValueNumber ||
  15531. isMathOperatorNode(iNextNode)) &&
  15532. (!iPrevNode || (iPrevNode && isMathOperatorNode(iPrevNode))))
  15533. ) {
  15534. continue;
  15535. }
  15536. }
  15537. const isEqualityOperator =
  15538. isControlDirective && isEqualityOperatorNode(iNode);
  15539. const isRelationalOperator =
  15540. isControlDirective && isRelationalOperatorNode(iNode);
  15541. const isNextEqualityOperator =
  15542. isControlDirective && isEqualityOperatorNode(iNextNode);
  15543. const isNextRelationalOperator =
  15544. isControlDirective && isRelationalOperatorNode(iNextNode);
  15545. const isNextIfElseKeyword =
  15546. isControlDirective && isIfElseKeywordNode(iNextNode);
  15547. const isEachKeyword = isControlDirective && isEachKeywordNode(iNode);
  15548. const isNextEachKeyword =
  15549. isControlDirective && isEachKeywordNode(iNextNode);
  15550. const isForKeyword =
  15551. atRuleAncestorNode &&
  15552. atRuleAncestorNode.name === "for" &&
  15553. isForKeywordNode(iNode);
  15554. const isNextForKeyword =
  15555. isControlDirective && isForKeywordNode(iNextNode);
  15556. const IsNextColon = iNextNode.value === ":";
  15557. if (isGridValue) {
  15558. if (iNode.source.start.line !== iNextNode.source.start.line) {
  15559. parts.push(hardline$4);
  15560. didBreak = true;
  15561. } else {
  15562. parts.push(" ");
  15563. }
  15564. } else if (iNode.type === "value-comment" && iNode.inline) {
  15565. parts.push(hardline$4);
  15566. } else if (
  15567. isNextMathOperator ||
  15568. isNextEqualityOperator ||
  15569. isNextRelationalOperator ||
  15570. isNextIfElseKeyword ||
  15571. isForKeyword ||
  15572. isEachKeyword
  15573. ) {
  15574. parts.push(" ");
  15575. } else if (
  15576. !IsNextColon ||
  15577. isEqualityOperator ||
  15578. isRelationalOperator ||
  15579. isNextForKeyword ||
  15580. isNextEachKeyword
  15581. ) {
  15582. parts.push(line$2);
  15583. }
  15584. }
  15585. if (didBreak) {
  15586. parts.unshift(hardline$4);
  15587. }
  15588. if (isControlDirective) {
  15589. return group$2(indent$4(concat$5(parts)));
  15590. }
  15591. return group$2(indent$4(fill$3(parts)));
  15592. }
  15593. case "value-paren_group": {
  15594. const parentNode = path$$1.getParentNode();
  15595. const isURLCall =
  15596. parentNode &&
  15597. parentNode.type === "value-func" &&
  15598. parentNode.value === "url";
  15599. if (
  15600. isURLCall &&
  15601. (node.groups.length === 1 ||
  15602. (node.groups.length > 0 &&
  15603. node.groups[0].type === "value-comma_group" &&
  15604. node.groups[0].groups.length > 0 &&
  15605. node.groups[0].groups[0].type === "value-word" &&
  15606. node.groups[0].groups[0].value.startsWith("data:")))
  15607. ) {
  15608. return concat$5([
  15609. node.open ? path$$1.call(print, "open") : "",
  15610. join$4(",", path$$1.map(print, "groups")),
  15611. node.close ? path$$1.call(print, "close") : ""
  15612. ]);
  15613. }
  15614. if (!node.open) {
  15615. const printed = path$$1.map(print, "groups");
  15616. const res = [];
  15617. for (let i = 0; i < printed.length; i++) {
  15618. if (i !== 0) {
  15619. res.push(concat$5([",", line$2]));
  15620. }
  15621. res.push(printed[i]);
  15622. }
  15623. return group$2(indent$4(fill$3(res)));
  15624. }
  15625. const declNode = path$$1.getParentNode(2);
  15626. const isMap =
  15627. declNode &&
  15628. declNode.type === "css-decl" &&
  15629. declNode.prop.startsWith("$");
  15630. return group$2(
  15631. concat$5([
  15632. node.open ? path$$1.call(print, "open") : "",
  15633. indent$4(
  15634. concat$5([
  15635. softline$3,
  15636. join$4(
  15637. concat$5([",", isMap ? hardline$4 : line$2]),
  15638. path$$1.map(print, "groups")
  15639. )
  15640. ])
  15641. ),
  15642. softline$3,
  15643. node.close ? path$$1.call(print, "close") : ""
  15644. ])
  15645. );
  15646. }
  15647. case "value-value": {
  15648. return path$$1.call(print, "group");
  15649. }
  15650. case "value-func": {
  15651. return concat$5([node.value, path$$1.call(print, "group")]);
  15652. }
  15653. case "value-paren": {
  15654. return node.value;
  15655. }
  15656. case "value-number": {
  15657. return concat$5([printNumber$1(node.value), maybeToLowerCase(node.unit)]);
  15658. }
  15659. case "value-operator": {
  15660. return node.value;
  15661. }
  15662. case "value-word": {
  15663. if ((node.isColor && node.isHex) || isWideKeywords(node.value)) {
  15664. return node.value.toLowerCase();
  15665. }
  15666. return node.value;
  15667. }
  15668. case "value-colon": {
  15669. return concat$5([node.value, insideURLFunctionNode(path$$1) ? "" : line$2]);
  15670. }
  15671. case "value-comma": {
  15672. return concat$5([node.value, " "]);
  15673. }
  15674. case "value-string": {
  15675. return util$1.printString(
  15676. node.raws.quote + node.value + node.raws.quote,
  15677. options
  15678. );
  15679. }
  15680. case "value-atword": {
  15681. return concat$5(["@", node.value]);
  15682. }
  15683. case "value-unicode-range": {
  15684. return node.value;
  15685. }
  15686. default:
  15687. /* istanbul ignore next */
  15688. throw new Error(`Unknown postcss type ${JSON.stringify(node.type)}`);
  15689. }
  15690. }
  15691. function isLastNode(path$$1, node) {
  15692. const parentNode = path$$1.getParentNode();
  15693. if (!parentNode) {
  15694. return false;
  15695. }
  15696. const nodes = parentNode.nodes;
  15697. return nodes && nodes.indexOf(node) === nodes.length - 1;
  15698. }
  15699. function isDetachedRulesetDeclaration(node) {
  15700. // If a Less file ends up being parsed with the SCSS parser, Less
  15701. // variable declarations will be parsed as atrules with names ending
  15702. // with a colon, so keep the original case then.
  15703. return (
  15704. node.selector &&
  15705. node.selector.type !== "selector-root-invalid" &&
  15706. ((typeof node.selector === "string" && /^@.+:.*$/.test(node.selector)) ||
  15707. (node.selector.value && /^@.+:.*$/.test(node.selector.value)))
  15708. );
  15709. }
  15710. function isKeyframeAtRuleKeywords(path$$1, value) {
  15711. const atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
  15712. return (
  15713. atRuleAncestorNode &&
  15714. atRuleAncestorNode.name &&
  15715. atRuleAncestorNode.name.toLowerCase().endsWith("keyframes") &&
  15716. ["from", "to"].indexOf(value.toLowerCase()) !== -1
  15717. );
  15718. }
  15719. function isHTMLTag(value) {
  15720. return htmlTagNames$1.indexOf(value.toLowerCase()) !== -1;
  15721. }
  15722. function insideURLFunctionNode(path$$1) {
  15723. const funcAncestorNode = getAncestorNode(path$$1, "value-func");
  15724. return (
  15725. funcAncestorNode &&
  15726. funcAncestorNode.value &&
  15727. funcAncestorNode.value === "url"
  15728. );
  15729. }
  15730. function isParenGroupNode(node) {
  15731. return node.type && node.type === "value-paren_group";
  15732. }
  15733. function isForKeywordNode(node) {
  15734. return (
  15735. node.type &&
  15736. node.type === "value-word" &&
  15737. node.value &&
  15738. ["from", "through", "end"].indexOf(node.value) !== -1
  15739. );
  15740. }
  15741. function isIfElseKeywordNode(node) {
  15742. return (
  15743. node.type &&
  15744. node.type === "value-word" &&
  15745. node.value &&
  15746. ["and", "or", "not"].indexOf(node.value) !== -1
  15747. );
  15748. }
  15749. function isEachKeywordNode(node) {
  15750. return (
  15751. node.type &&
  15752. node.type === "value-word" &&
  15753. node.value &&
  15754. ["in"].indexOf(node.value) !== -1
  15755. );
  15756. }
  15757. function isMathOperatorNode(node) {
  15758. return (
  15759. node.type &&
  15760. node.type === "value-operator" &&
  15761. node.value &&
  15762. ["+", "-", "/", "*", "%"].indexOf(node.value) !== -1
  15763. );
  15764. }
  15765. function isEqualityOperatorNode(node) {
  15766. return (
  15767. node.type &&
  15768. node.type === "value-word" &&
  15769. node.value &&
  15770. ["==", "!="].indexOf(node.value) !== -1
  15771. );
  15772. }
  15773. function isRelationalOperatorNode(node) {
  15774. return (
  15775. node.type &&
  15776. node.type === "value-word" &&
  15777. node.value &&
  15778. ["<", ">", "<=", ">="].indexOf(node.value) !== -1
  15779. );
  15780. }
  15781. function isControlDirectiveNode(node) {
  15782. return (
  15783. node.type &&
  15784. node.type === "css-atrule" &&
  15785. node.name &&
  15786. (node.name === "if" ||
  15787. node.name === "else" ||
  15788. node.name === "for" ||
  15789. node.name === "each" ||
  15790. node.name === "while")
  15791. );
  15792. }
  15793. function getAncestorCounter(path$$1, typeOrTypes) {
  15794. const types = [].concat(typeOrTypes);
  15795. let counter = -1;
  15796. let ancestorNode;
  15797. while ((ancestorNode = path$$1.getParentNode(++counter))) {
  15798. if (types.indexOf(ancestorNode.type) !== -1) {
  15799. return counter;
  15800. }
  15801. }
  15802. return -1;
  15803. }
  15804. function getAncestorNode(path$$1, typeOrTypes) {
  15805. const counter = getAncestorCounter(path$$1, typeOrTypes);
  15806. return counter === -1 ? null : path$$1.getParentNode(counter);
  15807. }
  15808. function printNodeSequence(path$$1, options, print) {
  15809. const node = path$$1.getValue();
  15810. const parts = [];
  15811. let i = 0;
  15812. path$$1.map(pathChild => {
  15813. const prevNode = node.nodes[i - 1];
  15814. if (
  15815. prevNode &&
  15816. prevNode.type === "css-comment" &&
  15817. prevNode.text.trim() === "prettier-ignore"
  15818. ) {
  15819. const childNode = pathChild.getValue();
  15820. parts.push(
  15821. options.originalText.slice(
  15822. options.locStart(childNode),
  15823. options.locEnd(childNode)
  15824. )
  15825. );
  15826. } else {
  15827. parts.push(pathChild.call(print));
  15828. }
  15829. if (i !== node.nodes.length - 1) {
  15830. if (
  15831. (node.nodes[i + 1].type === "css-comment" &&
  15832. !util$1.hasNewline(
  15833. options.originalText,
  15834. options.locStart(node.nodes[i + 1]),
  15835. { backwards: true }
  15836. )) ||
  15837. (node.nodes[i + 1].type === "css-atrule" &&
  15838. node.nodes[i + 1].name === "else" &&
  15839. node.nodes[i].type !== "css-comment")
  15840. ) {
  15841. parts.push(" ");
  15842. } else {
  15843. parts.push(hardline$4);
  15844. if (
  15845. utilShared.isNextLineEmpty(
  15846. options.originalText,
  15847. pathChild.getValue(),
  15848. options
  15849. )
  15850. ) {
  15851. parts.push(hardline$4);
  15852. }
  15853. }
  15854. }
  15855. i++;
  15856. }, "nodes");
  15857. return concat$5(parts);
  15858. }
  15859. const STRING_REGEX = /(['"])(?:(?!\1)[^\\]|\\[\s\S])*\1/g;
  15860. const NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g;
  15861. const STANDARD_UNIT_REGEX = /[a-zA-Z]+/g;
  15862. const WORD_PART_REGEX = /[$@]?[a-zA-Z_\u0080-\uFFFF][\w\-\u0080-\uFFFF]*/g;
  15863. const ADJUST_NUMBERS_REGEX = RegExp(
  15864. STRING_REGEX.source +
  15865. `|` +
  15866. `(${WORD_PART_REGEX.source})?` +
  15867. `(${NUMBER_REGEX.source})` +
  15868. `(${STANDARD_UNIT_REGEX.source})?`,
  15869. "g"
  15870. );
  15871. function adjustStrings(value, options) {
  15872. return value.replace(STRING_REGEX, match =>
  15873. util$1.printString(match, options)
  15874. );
  15875. }
  15876. function quoteAttributeValue(value, options) {
  15877. const quote = options.singleQuote ? "'" : '"';
  15878. return value.includes('"') || value.includes("'")
  15879. ? value
  15880. : quote + value + quote;
  15881. }
  15882. function adjustNumbers(value) {
  15883. return value.replace(
  15884. ADJUST_NUMBERS_REGEX,
  15885. (match, quote, wordPart, number, unit) =>
  15886. !wordPart && number
  15887. ? (wordPart || "") + printNumber$1(number) + maybeToLowerCase(unit || "")
  15888. : match
  15889. );
  15890. }
  15891. function printNumber$1(rawNumber) {
  15892. return (
  15893. util$1
  15894. .printNumber(rawNumber)
  15895. // Remove trailing `.0`.
  15896. .replace(/\.0(?=$|e)/, "")
  15897. );
  15898. }
  15899. function maybeToLowerCase(value) {
  15900. return value.includes("$") ||
  15901. value.includes("@") ||
  15902. value.includes("#") ||
  15903. value.startsWith("%") ||
  15904. value.startsWith("--") ||
  15905. value.startsWith(":--") ||
  15906. (value.includes("(") && value.includes(")"))
  15907. ? value
  15908. : value.toLowerCase();
  15909. }
  15910. function isWideKeywords(value) {
  15911. return (
  15912. ["initial", "inherit", "unset", "revert"].indexOf(
  15913. value.replace().toLowerCase()
  15914. ) !== -1
  15915. );
  15916. }
  15917. var printerPostcss = {
  15918. print: genericPrint$1,
  15919. hasPrettierIgnore: util$1.hasIgnoreComment,
  15920. massageAstNode: clean_1$2
  15921. };
  15922. // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js
  15923. var options$2 = {
  15924. singleQuote: options.singleQuote
  15925. };
  15926. const lineColumnToIndex$1 = util$1.lineColumnToIndex;
  15927. const getLast$1 = util$1.getLast;
  15928. // Based on:
  15929. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  15930. const languages$1 = [
  15931. {
  15932. name: "CSS",
  15933. since: "1.4.0",
  15934. parsers: ["css"],
  15935. group: "CSS",
  15936. tmScope: "source.css",
  15937. aceMode: "css",
  15938. codemirrorMode: "css",
  15939. codemirrorMimeType: "text/css",
  15940. extensions: [".css", ".pcss", ".postcss"],
  15941. liguistLanguageId: 50,
  15942. vscodeLanguageIds: ["css", "postcss"]
  15943. },
  15944. {
  15945. name: "Less",
  15946. since: "1.4.0",
  15947. parsers: ["less"],
  15948. group: "CSS",
  15949. extensions: [".less"],
  15950. tmScope: "source.css.less",
  15951. aceMode: "less",
  15952. codemirrorMode: "css",
  15953. codemirrorMimeType: "text/css",
  15954. liguistLanguageId: 198,
  15955. vscodeLanguageIds: ["less"]
  15956. },
  15957. {
  15958. name: "SCSS",
  15959. since: "1.4.0",
  15960. parsers: ["scss"],
  15961. group: "CSS",
  15962. tmScope: "source.scss",
  15963. aceMode: "scss",
  15964. codemirrorMode: "css",
  15965. codemirrorMimeType: "text/x-scss",
  15966. extensions: [".scss"],
  15967. liguistLanguageId: 329,
  15968. vscodeLanguageIds: ["scss"]
  15969. }
  15970. ];
  15971. const postcss = {
  15972. get parse() {
  15973. return require("./parser-postcss");
  15974. },
  15975. astFormat: "postcss",
  15976. locEnd: function(node) {
  15977. const endNode = node.nodes && getLast$1(node.nodes);
  15978. if (endNode && node.source && !node.source.end) {
  15979. node = endNode;
  15980. }
  15981. if (node.source) {
  15982. return lineColumnToIndex$1(node.source.end, node.source.input.css);
  15983. }
  15984. return null;
  15985. },
  15986. locStart: function(node) {
  15987. if (node.source) {
  15988. return lineColumnToIndex$1(node.source.start, node.source.input.css) - 1;
  15989. }
  15990. return null;
  15991. }
  15992. };
  15993. // TODO: switch these to just `postcss` and use `language` instead.
  15994. const parsers$1 = {
  15995. css: postcss,
  15996. less: postcss,
  15997. scss: postcss
  15998. };
  15999. const printers$1 = {
  16000. postcss: printerPostcss
  16001. };
  16002. var languageCss = {
  16003. languages: languages$1,
  16004. options: options$2,
  16005. parsers: parsers$1,
  16006. printers: printers$1
  16007. };
  16008. const concat$6 = docBuilders$2.concat;
  16009. const join$5 = docBuilders$2.join;
  16010. const softline$4 = docBuilders$2.softline;
  16011. const hardline$5 = docBuilders$2.hardline;
  16012. const line$3 = docBuilders$2.line;
  16013. const group$3 = docBuilders$2.group;
  16014. const indent$5 = docBuilders$2.indent;
  16015. const ifBreak$2 = docBuilders$2.ifBreak;
  16016. // http://w3c.github.io/html/single-page.html#void-elements
  16017. const voidTags = [
  16018. "area",
  16019. "base",
  16020. "br",
  16021. "col",
  16022. "embed",
  16023. "hr",
  16024. "img",
  16025. "input",
  16026. "link",
  16027. "meta",
  16028. "param",
  16029. "source",
  16030. "track",
  16031. "wbr"
  16032. ];
  16033. // Formatter based on @glimmerjs/syntax's built-in test formatter:
  16034. // https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts
  16035. function print(path$$1, options, print) {
  16036. const n = path$$1.getValue();
  16037. /* istanbul ignore if*/
  16038. if (!n) {
  16039. return "";
  16040. }
  16041. switch (n.type) {
  16042. case "Program": {
  16043. return group$3(
  16044. join$5(softline$4, path$$1.map(print, "body").filter(text => text !== ""))
  16045. );
  16046. }
  16047. case "ElementNode": {
  16048. const isVoid = voidTags.indexOf(n.tag) !== -1;
  16049. const closeTag = isVoid ? concat$6([" />", softline$4]) : ">";
  16050. const hasChildren = n.children.length > 0;
  16051. const getParams = (path$$1, print) =>
  16052. indent$5(
  16053. concat$6([
  16054. n.attributes.length ? line$3 : "",
  16055. join$5(line$3, path$$1.map(print, "attributes")),
  16056. n.modifiers.length ? line$3 : "",
  16057. join$5(line$3, path$$1.map(print, "modifiers")),
  16058. n.comments.length ? line$3 : "",
  16059. join$5(line$3, path$$1.map(print, "comments"))
  16060. ])
  16061. );
  16062. // The problem here is that I want to not break at all if the children
  16063. // would not break but I need to force an indent, so I use a hardline.
  16064. /**
  16065. * What happens now:
  16066. * <div>
  16067. * Hello
  16068. * </div>
  16069. * ==>
  16070. * <div>Hello</div>
  16071. * This is due to me using hasChildren to decide to put the hardline in.
  16072. * I would rather use a {DOES THE WHOLE THING NEED TO BREAK}
  16073. */
  16074. return concat$6([
  16075. group$3(
  16076. concat$6([
  16077. "<",
  16078. n.tag,
  16079. getParams(path$$1, print),
  16080. ifBreak$2(softline$4, ""),
  16081. closeTag
  16082. ])
  16083. ),
  16084. group$3(
  16085. concat$6([
  16086. indent$5(join$5(softline$4, [""].concat(path$$1.map(print, "children")))),
  16087. ifBreak$2(hasChildren ? hardline$5 : "", ""),
  16088. !isVoid ? concat$6(["</", n.tag, ">"]) : ""
  16089. ])
  16090. )
  16091. ]);
  16092. }
  16093. case "BlockStatement": {
  16094. const pp = path$$1.getParentNode(1);
  16095. const isElseIf =
  16096. pp &&
  16097. pp.inverse &&
  16098. pp.inverse.body[0] === n &&
  16099. pp.inverse.body[0].path.parts[0] === "if";
  16100. const hasElseIf =
  16101. n.inverse &&
  16102. n.inverse.body[0] &&
  16103. n.inverse.body[0].type === "BlockStatement" &&
  16104. n.inverse.body[0].path.parts[0] === "if";
  16105. const indentElse = hasElseIf ? a => a : indent$5;
  16106. if (n.inverse) {
  16107. return concat$6([
  16108. isElseIf
  16109. ? concat$6(["{{else ", printPathParams(path$$1, print), "}}"])
  16110. : printOpenBlock(path$$1, print),
  16111. indent$5(concat$6([hardline$5, path$$1.call(print, "program")])),
  16112. n.inverse && !hasElseIf ? concat$6([hardline$5, "{{else}}"]) : "",
  16113. n.inverse
  16114. ? indentElse(concat$6([hardline$5, path$$1.call(print, "inverse")]))
  16115. : "",
  16116. isElseIf ? "" : concat$6([hardline$5, printCloseBlock(path$$1, print)])
  16117. ]);
  16118. } else if (isElseIf) {
  16119. return concat$6([
  16120. concat$6(["{{else ", printPathParams(path$$1, print), "}}"]),
  16121. indent$5(concat$6([hardline$5, path$$1.call(print, "program")]))
  16122. ]);
  16123. }
  16124. /**
  16125. * I want this boolean to be: if params are going to cause a break,
  16126. * not that it has params.
  16127. */
  16128. const hasParams = n.params.length > 0 || n.hash.pairs.length > 0;
  16129. const hasChildren = n.program.body.length > 0;
  16130. return concat$6([
  16131. printOpenBlock(path$$1, print),
  16132. group$3(
  16133. concat$6([
  16134. indent$5(concat$6([softline$4, path$$1.call(print, "program")])),
  16135. hasParams && hasChildren ? hardline$5 : "",
  16136. printCloseBlock(path$$1, print)
  16137. ])
  16138. )
  16139. ]);
  16140. }
  16141. case "ElementModifierStatement":
  16142. case "MustacheStatement": {
  16143. const pp = path$$1.getParentNode(1);
  16144. const isConcat = pp && pp.type === "ConcatStatement";
  16145. return group$3(
  16146. concat$6([
  16147. /*n.escaped ? "{{{" : */ "{{",
  16148. printPathParams(path$$1, print),
  16149. isConcat ? "" : softline$4,
  16150. /*.escaped ? "}}}" :*/ "}}"
  16151. ])
  16152. );
  16153. }
  16154. case "SubExpression": {
  16155. return group$3(
  16156. concat$6([
  16157. "(",
  16158. printPath(path$$1, print),
  16159. indent$5(concat$6([line$3, group$3(join$5(line$3, getParams(path$$1, print)))])),
  16160. softline$4,
  16161. ")"
  16162. ])
  16163. );
  16164. }
  16165. case "AttrNode": {
  16166. const quote = n.value.type === "TextNode" ? '"' : "";
  16167. return concat$6([n.name, "=", quote, path$$1.call(print, "value"), quote]);
  16168. }
  16169. case "ConcatStatement": {
  16170. return concat$6([
  16171. '"',
  16172. group$3(
  16173. indent$5(
  16174. join$5(
  16175. softline$4,
  16176. path$$1
  16177. .map(partPath => print(partPath), "parts")
  16178. .filter(a => a !== "")
  16179. )
  16180. )
  16181. ),
  16182. '"'
  16183. ]);
  16184. }
  16185. case "Hash": {
  16186. return concat$6([join$5(line$3, path$$1.map(print, "pairs"))]);
  16187. }
  16188. case "HashPair": {
  16189. return concat$6([n.key, "=", path$$1.call(print, "value")]);
  16190. }
  16191. case "TextNode": {
  16192. return n.chars.replace(/^\s+/, "").replace(/\s+$/, "");
  16193. }
  16194. case "MustacheCommentStatement": {
  16195. const dashes = n.value.indexOf("}}") > -1 ? "--" : "";
  16196. return concat$6(["{{!", dashes, n.value, dashes, "}}"]);
  16197. }
  16198. case "PathExpression": {
  16199. return n.original;
  16200. }
  16201. case "BooleanLiteral": {
  16202. return String(n.value);
  16203. }
  16204. case "CommentStatement": {
  16205. return concat$6(["<!--", n.value, "-->"]);
  16206. }
  16207. case "StringLiteral": {
  16208. return `"${n.value}"`;
  16209. }
  16210. case "NumberLiteral": {
  16211. return String(n.value);
  16212. }
  16213. case "UndefinedLiteral": {
  16214. return "undefined";
  16215. }
  16216. case "NullLiteral": {
  16217. return "null";
  16218. }
  16219. /* istanbul ignore next */
  16220. default:
  16221. throw new Error("unknown glimmer type: " + JSON.stringify(n.type));
  16222. }
  16223. }
  16224. function printPath(path$$1, print) {
  16225. return path$$1.call(print, "path");
  16226. }
  16227. function getParams(path$$1, print) {
  16228. const node = path$$1.getValue();
  16229. let parts = [];
  16230. if (node.params.length > 0) {
  16231. parts = parts.concat(path$$1.map(print, "params"));
  16232. }
  16233. if (node.hash && node.hash.pairs.length > 0) {
  16234. parts.push(path$$1.call(print, "hash"));
  16235. }
  16236. return parts;
  16237. }
  16238. function printPathParams(path$$1, print) {
  16239. let parts = [];
  16240. parts.push(printPath(path$$1, print));
  16241. parts = parts.concat(getParams(path$$1, print));
  16242. return indent$5(group$3(join$5(line$3, parts)));
  16243. }
  16244. function printBlockParams(path$$1) {
  16245. const block = path$$1.getValue();
  16246. if (!block.program || !block.program.blockParams.length) {
  16247. return "";
  16248. }
  16249. return concat$6([" as |", block.program.blockParams.join(" "), "|"]);
  16250. }
  16251. function printOpenBlock(path$$1, print) {
  16252. return group$3(
  16253. concat$6([
  16254. "{{#",
  16255. printPathParams(path$$1, print),
  16256. printBlockParams(path$$1, print),
  16257. softline$4,
  16258. "}}"
  16259. ])
  16260. );
  16261. }
  16262. function printCloseBlock(path$$1, print) {
  16263. return concat$6(["{{/", path$$1.call(print, "path"), "}}"]);
  16264. }
  16265. function clean$4(ast, newObj) {
  16266. // (Glimmer/HTML) ignore TextNode whitespace
  16267. if (ast.type === "TextNode") {
  16268. if (ast.chars.replace(/\s+/, "") === "") {
  16269. return null;
  16270. }
  16271. newObj.chars = ast.chars.replace(/^\s+/, "").replace(/\s+$/, "");
  16272. }
  16273. }
  16274. var printerGlimmer = {
  16275. print,
  16276. massageAstNode: clean$4
  16277. };
  16278. // Based on:
  16279. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  16280. const languages$2 = [
  16281. {
  16282. type: "markup",
  16283. group: "HTML",
  16284. aliases: ["hbs", "htmlbars"],
  16285. extensions: [".handlebars", ".hbs"],
  16286. tm_scope: "text.html.handlebars",
  16287. ace_mode: "handlebars",
  16288. language_id: 155,
  16289. since: null // unreleased
  16290. }
  16291. ];
  16292. const parsers$2 = {
  16293. glimmer: {
  16294. get parse() {
  16295. return require("./parser-glimmer");
  16296. },
  16297. astFormat: "glimmer",
  16298. locEnd: function(node) {
  16299. return node.loc && node.loc.end;
  16300. },
  16301. locStart: function(node) {
  16302. return node.loc && node.loc.start;
  16303. }
  16304. }
  16305. };
  16306. const printers$2 = {
  16307. glimmer: printerGlimmer
  16308. };
  16309. var languageHandlebars = {
  16310. languages: languages$2,
  16311. parsers: parsers$2,
  16312. printers: printers$2
  16313. };
  16314. const docBuilders$7 = doc.builders;
  16315. const concat$7 = docBuilders$7.concat;
  16316. const join$6 = docBuilders$7.join;
  16317. const hardline$6 = docBuilders$7.hardline;
  16318. const line$4 = docBuilders$7.line;
  16319. const softline$5 = docBuilders$7.softline;
  16320. const group$4 = docBuilders$7.group;
  16321. const indent$6 = docBuilders$7.indent;
  16322. const ifBreak$3 = docBuilders$7.ifBreak;
  16323. function genericPrint$2(path$$1, options, print) {
  16324. const n = path$$1.getValue();
  16325. if (!n) {
  16326. return "";
  16327. }
  16328. if (typeof n === "string") {
  16329. return n;
  16330. }
  16331. switch (n.kind) {
  16332. case "Document": {
  16333. return concat$7([
  16334. join$6(concat$7([hardline$6, hardline$6]), path$$1.map(print, "definitions")),
  16335. hardline$6
  16336. ]);
  16337. }
  16338. case "OperationDefinition": {
  16339. const hasOperation = options.originalText[options.locStart(n)] !== "{";
  16340. const hasName = !!n.name;
  16341. return concat$7([
  16342. hasOperation ? n.operation : "",
  16343. hasOperation && hasName ? concat$7([" ", path$$1.call(print, "name")]) : "",
  16344. n.variableDefinitions && n.variableDefinitions.length
  16345. ? group$4(
  16346. concat$7([
  16347. "(",
  16348. indent$6(
  16349. concat$7([
  16350. softline$5,
  16351. join$6(
  16352. concat$7([ifBreak$3("", ", "), softline$5]),
  16353. path$$1.map(print, "variableDefinitions")
  16354. )
  16355. ])
  16356. ),
  16357. softline$5,
  16358. ")"
  16359. ])
  16360. )
  16361. : "",
  16362. printDirectives(path$$1, print, n),
  16363. n.selectionSet ? (!hasOperation && !hasName ? "" : " ") : "",
  16364. path$$1.call(print, "selectionSet")
  16365. ]);
  16366. }
  16367. case "FragmentDefinition": {
  16368. return concat$7([
  16369. "fragment ",
  16370. path$$1.call(print, "name"),
  16371. " on ",
  16372. path$$1.call(print, "typeCondition"),
  16373. printDirectives(path$$1, print, n),
  16374. " ",
  16375. path$$1.call(print, "selectionSet")
  16376. ]);
  16377. }
  16378. case "SelectionSet": {
  16379. return concat$7([
  16380. "{",
  16381. indent$6(
  16382. concat$7([
  16383. hardline$6,
  16384. join$6(
  16385. hardline$6,
  16386. path$$1.call(
  16387. selectionsPath => printSequence(selectionsPath, options, print),
  16388. "selections"
  16389. )
  16390. )
  16391. ])
  16392. ),
  16393. hardline$6,
  16394. "}"
  16395. ]);
  16396. }
  16397. case "Field": {
  16398. return group$4(
  16399. concat$7([
  16400. n.alias ? concat$7([path$$1.call(print, "alias"), ": "]) : "",
  16401. path$$1.call(print, "name"),
  16402. n.arguments.length > 0
  16403. ? group$4(
  16404. concat$7([
  16405. "(",
  16406. indent$6(
  16407. concat$7([
  16408. softline$5,
  16409. join$6(
  16410. concat$7([ifBreak$3("", ", "), softline$5]),
  16411. path$$1.call(
  16412. argsPath => printSequence(argsPath, options, print),
  16413. "arguments"
  16414. )
  16415. )
  16416. ])
  16417. ),
  16418. softline$5,
  16419. ")"
  16420. ])
  16421. )
  16422. : "",
  16423. printDirectives(path$$1, print, n),
  16424. n.selectionSet ? " " : "",
  16425. path$$1.call(print, "selectionSet")
  16426. ])
  16427. );
  16428. }
  16429. case "Name": {
  16430. return n.value;
  16431. }
  16432. case "StringValue": {
  16433. if (n.block) {
  16434. return concat$7([
  16435. '"""',
  16436. hardline$6,
  16437. join$6(hardline$6, n.value.replace(/"""/g, "\\$&").split("\n")),
  16438. hardline$6,
  16439. '"""'
  16440. ]);
  16441. }
  16442. return concat$7(['"', n.value.replace(/["\\]/g, "\\$&"), '"']);
  16443. }
  16444. case "IntValue":
  16445. case "FloatValue":
  16446. case "EnumValue": {
  16447. return n.value;
  16448. }
  16449. case "BooleanValue": {
  16450. return n.value ? "true" : "false";
  16451. }
  16452. case "NullValue": {
  16453. return "null";
  16454. }
  16455. case "Variable": {
  16456. return concat$7(["$", path$$1.call(print, "name")]);
  16457. }
  16458. case "ListValue": {
  16459. return group$4(
  16460. concat$7([
  16461. "[",
  16462. indent$6(
  16463. concat$7([
  16464. softline$5,
  16465. join$6(
  16466. concat$7([ifBreak$3("", ", "), softline$5]),
  16467. path$$1.map(print, "values")
  16468. )
  16469. ])
  16470. ),
  16471. softline$5,
  16472. "]"
  16473. ])
  16474. );
  16475. }
  16476. case "ObjectValue": {
  16477. return group$4(
  16478. concat$7([
  16479. "{",
  16480. options.bracketSpacing && n.fields.length > 0 ? " " : "",
  16481. indent$6(
  16482. concat$7([
  16483. softline$5,
  16484. join$6(
  16485. concat$7([ifBreak$3("", ", "), softline$5]),
  16486. path$$1.map(print, "fields")
  16487. )
  16488. ])
  16489. ),
  16490. softline$5,
  16491. ifBreak$3("", options.bracketSpacing && n.fields.length > 0 ? " " : ""),
  16492. "}"
  16493. ])
  16494. );
  16495. }
  16496. case "ObjectField":
  16497. case "Argument": {
  16498. return concat$7([
  16499. path$$1.call(print, "name"),
  16500. ": ",
  16501. path$$1.call(print, "value")
  16502. ]);
  16503. }
  16504. case "Directive": {
  16505. return concat$7([
  16506. "@",
  16507. path$$1.call(print, "name"),
  16508. n.arguments.length > 0
  16509. ? group$4(
  16510. concat$7([
  16511. "(",
  16512. indent$6(
  16513. concat$7([
  16514. softline$5,
  16515. join$6(
  16516. concat$7([ifBreak$3("", ", "), softline$5]),
  16517. path$$1.call(
  16518. argsPath => printSequence(argsPath, options, print),
  16519. "arguments"
  16520. )
  16521. )
  16522. ])
  16523. ),
  16524. softline$5,
  16525. ")"
  16526. ])
  16527. )
  16528. : ""
  16529. ]);
  16530. }
  16531. case "NamedType": {
  16532. return path$$1.call(print, "name");
  16533. }
  16534. case "VariableDefinition": {
  16535. return concat$7([
  16536. path$$1.call(print, "variable"),
  16537. ": ",
  16538. path$$1.call(print, "type"),
  16539. n.defaultValue ? concat$7([" = ", path$$1.call(print, "defaultValue")]) : ""
  16540. ]);
  16541. }
  16542. case "TypeExtensionDefinition": {
  16543. return concat$7(["extend ", path$$1.call(print, "definition")]);
  16544. }
  16545. case "ObjectTypeExtension":
  16546. case "ObjectTypeDefinition": {
  16547. return concat$7([
  16548. path$$1.call(print, "description"),
  16549. n.description ? hardline$6 : "",
  16550. n.kind === "ObjectTypeExtension" ? "extend " : "",
  16551. "type ",
  16552. path$$1.call(print, "name"),
  16553. n.interfaces.length > 0
  16554. ? concat$7([
  16555. " implements ",
  16556. join$6(
  16557. determineInterfaceSeparator(
  16558. options.originalText.substr(
  16559. options.locStart(n),
  16560. options.locEnd(n)
  16561. )
  16562. ),
  16563. path$$1.map(print, "interfaces")
  16564. )
  16565. ])
  16566. : "",
  16567. printDirectives(path$$1, print, n),
  16568. n.fields.length > 0
  16569. ? concat$7([
  16570. " {",
  16571. indent$6(
  16572. concat$7([
  16573. hardline$6,
  16574. join$6(
  16575. hardline$6,
  16576. path$$1.call(
  16577. fieldsPath => printSequence(fieldsPath, options, print),
  16578. "fields"
  16579. )
  16580. )
  16581. ])
  16582. ),
  16583. hardline$6,
  16584. "}"
  16585. ])
  16586. : ""
  16587. ]);
  16588. }
  16589. case "FieldDefinition": {
  16590. return concat$7([
  16591. path$$1.call(print, "description"),
  16592. n.description ? hardline$6 : "",
  16593. path$$1.call(print, "name"),
  16594. n.arguments.length > 0
  16595. ? group$4(
  16596. concat$7([
  16597. "(",
  16598. indent$6(
  16599. concat$7([
  16600. softline$5,
  16601. join$6(
  16602. concat$7([ifBreak$3("", ", "), softline$5]),
  16603. path$$1.call(
  16604. argsPath => printSequence(argsPath, options, print),
  16605. "arguments"
  16606. )
  16607. )
  16608. ])
  16609. ),
  16610. softline$5,
  16611. ")"
  16612. ])
  16613. )
  16614. : "",
  16615. ": ",
  16616. path$$1.call(print, "type"),
  16617. printDirectives(path$$1, print, n)
  16618. ]);
  16619. }
  16620. case "DirectiveDefinition": {
  16621. return concat$7([
  16622. path$$1.call(print, "description"),
  16623. n.description ? hardline$6 : "",
  16624. "directive ",
  16625. "@",
  16626. path$$1.call(print, "name"),
  16627. n.arguments.length > 0
  16628. ? group$4(
  16629. concat$7([
  16630. "(",
  16631. indent$6(
  16632. concat$7([
  16633. softline$5,
  16634. join$6(
  16635. concat$7([ifBreak$3("", ", "), softline$5]),
  16636. path$$1.call(
  16637. argsPath => printSequence(argsPath, options, print),
  16638. "arguments"
  16639. )
  16640. )
  16641. ])
  16642. ),
  16643. softline$5,
  16644. ")"
  16645. ])
  16646. )
  16647. : "",
  16648. concat$7([" on ", join$6(" | ", path$$1.map(print, "locations"))])
  16649. ]);
  16650. }
  16651. case "EnumTypeExtension":
  16652. case "EnumTypeDefinition": {
  16653. return concat$7([
  16654. path$$1.call(print, "description"),
  16655. n.description ? hardline$6 : "",
  16656. n.kind === "EnumTypeExtension" ? "extend " : "",
  16657. "enum ",
  16658. path$$1.call(print, "name"),
  16659. printDirectives(path$$1, print, n),
  16660. n.values.length > 0
  16661. ? concat$7([
  16662. " {",
  16663. indent$6(
  16664. concat$7([
  16665. hardline$6,
  16666. join$6(
  16667. hardline$6,
  16668. path$$1.call(
  16669. valuesPath => printSequence(valuesPath, options, print),
  16670. "values"
  16671. )
  16672. )
  16673. ])
  16674. ),
  16675. hardline$6,
  16676. "}"
  16677. ])
  16678. : ""
  16679. ]);
  16680. }
  16681. case "EnumValueDefinition": {
  16682. return concat$7([
  16683. path$$1.call(print, "description"),
  16684. n.description ? hardline$6 : "",
  16685. path$$1.call(print, "name"),
  16686. printDirectives(path$$1, print, n)
  16687. ]);
  16688. }
  16689. case "InputValueDefinition": {
  16690. return concat$7([
  16691. path$$1.call(print, "description"),
  16692. n.description ? (n.description.block ? hardline$6 : line$4) : "",
  16693. path$$1.call(print, "name"),
  16694. ": ",
  16695. path$$1.call(print, "type"),
  16696. n.defaultValue ? concat$7([" = ", path$$1.call(print, "defaultValue")]) : "",
  16697. printDirectives(path$$1, print, n)
  16698. ]);
  16699. }
  16700. case "InputObjectTypeExtension":
  16701. case "InputObjectTypeDefinition": {
  16702. return concat$7([
  16703. path$$1.call(print, "description"),
  16704. n.description ? hardline$6 : "",
  16705. n.kind === "InputObjectTypeExtension" ? "extend " : "",
  16706. "input ",
  16707. path$$1.call(print, "name"),
  16708. printDirectives(path$$1, print, n),
  16709. n.fields.length > 0
  16710. ? concat$7([
  16711. " {",
  16712. indent$6(
  16713. concat$7([
  16714. hardline$6,
  16715. join$6(
  16716. hardline$6,
  16717. path$$1.call(
  16718. fieldsPath => printSequence(fieldsPath, options, print),
  16719. "fields"
  16720. )
  16721. )
  16722. ])
  16723. ),
  16724. hardline$6,
  16725. "}"
  16726. ])
  16727. : ""
  16728. ]);
  16729. }
  16730. case "SchemaDefinition": {
  16731. return concat$7([
  16732. "schema",
  16733. printDirectives(path$$1, print, n),
  16734. " {",
  16735. n.operationTypes.length > 0
  16736. ? indent$6(
  16737. concat$7([
  16738. hardline$6,
  16739. join$6(
  16740. hardline$6,
  16741. path$$1.call(
  16742. opsPath => printSequence(opsPath, options, print),
  16743. "operationTypes"
  16744. )
  16745. )
  16746. ])
  16747. )
  16748. : "",
  16749. hardline$6,
  16750. "}"
  16751. ]);
  16752. }
  16753. case "OperationTypeDefinition": {
  16754. return concat$7([
  16755. path$$1.call(print, "operation"),
  16756. ": ",
  16757. path$$1.call(print, "type")
  16758. ]);
  16759. }
  16760. case "InterfaceTypeExtension":
  16761. case "InterfaceTypeDefinition": {
  16762. return concat$7([
  16763. path$$1.call(print, "description"),
  16764. n.description ? hardline$6 : "",
  16765. n.kind === "InterfaceTypeExtension" ? "extend " : "",
  16766. "interface ",
  16767. path$$1.call(print, "name"),
  16768. printDirectives(path$$1, print, n),
  16769. n.fields.length > 0
  16770. ? concat$7([
  16771. " {",
  16772. indent$6(
  16773. concat$7([
  16774. hardline$6,
  16775. join$6(
  16776. hardline$6,
  16777. path$$1.call(
  16778. fieldsPath => printSequence(fieldsPath, options, print),
  16779. "fields"
  16780. )
  16781. )
  16782. ])
  16783. ),
  16784. hardline$6,
  16785. "}"
  16786. ])
  16787. : ""
  16788. ]);
  16789. }
  16790. case "FragmentSpread": {
  16791. return concat$7([
  16792. "...",
  16793. path$$1.call(print, "name"),
  16794. printDirectives(path$$1, print, n)
  16795. ]);
  16796. }
  16797. case "InlineFragment": {
  16798. return concat$7([
  16799. "...",
  16800. n.typeCondition
  16801. ? concat$7([" on ", path$$1.call(print, "typeCondition")])
  16802. : "",
  16803. printDirectives(path$$1, print, n),
  16804. " ",
  16805. path$$1.call(print, "selectionSet")
  16806. ]);
  16807. }
  16808. case "UnionTypeExtension":
  16809. case "UnionTypeDefinition": {
  16810. return group$4(
  16811. concat$7([
  16812. path$$1.call(print, "description"),
  16813. n.description ? hardline$6 : "",
  16814. group$4(
  16815. concat$7([
  16816. n.kind === "UnionTypeExtension" ? "extend " : "",
  16817. "union ",
  16818. path$$1.call(print, "name"),
  16819. printDirectives(path$$1, print, n),
  16820. n.types.length > 0
  16821. ? concat$7([
  16822. " =",
  16823. ifBreak$3("", " "),
  16824. indent$6(
  16825. concat$7([
  16826. ifBreak$3(concat$7([line$4, " "])),
  16827. join$6(concat$7([line$4, "| "]), path$$1.map(print, "types"))
  16828. ])
  16829. )
  16830. ])
  16831. : ""
  16832. ])
  16833. )
  16834. ])
  16835. );
  16836. }
  16837. case "ScalarTypeExtension":
  16838. case "ScalarTypeDefinition": {
  16839. return concat$7([
  16840. path$$1.call(print, "description"),
  16841. n.description ? hardline$6 : "",
  16842. n.kind === "ScalarTypeExtension" ? "extend " : "",
  16843. "scalar ",
  16844. path$$1.call(print, "name"),
  16845. printDirectives(path$$1, print, n)
  16846. ]);
  16847. }
  16848. case "NonNullType": {
  16849. return concat$7([path$$1.call(print, "type"), "!"]);
  16850. }
  16851. case "ListType": {
  16852. return concat$7(["[", path$$1.call(print, "type"), "]"]);
  16853. }
  16854. default:
  16855. /* istanbul ignore next */
  16856. throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
  16857. }
  16858. }
  16859. function printDirectives(path$$1, print, n) {
  16860. if (n.directives.length === 0) {
  16861. return "";
  16862. }
  16863. return concat$7([
  16864. " ",
  16865. group$4(
  16866. indent$6(
  16867. concat$7([
  16868. softline$5,
  16869. join$6(
  16870. concat$7([ifBreak$3("", " "), softline$5]),
  16871. path$$1.map(print, "directives")
  16872. )
  16873. ])
  16874. )
  16875. )
  16876. ]);
  16877. }
  16878. function printSequence(sequencePath, options, print) {
  16879. const count = sequencePath.getValue().length;
  16880. return sequencePath.map((path$$1, i) => {
  16881. const printed = print(path$$1);
  16882. if (
  16883. utilShared.isNextLineEmpty(
  16884. options.originalText,
  16885. path$$1.getValue(),
  16886. options
  16887. ) &&
  16888. i < count - 1
  16889. ) {
  16890. return concat$7([printed, hardline$6]);
  16891. }
  16892. return printed;
  16893. });
  16894. }
  16895. function canAttachComment$1(node) {
  16896. return node.kind && node.kind !== "Comment";
  16897. }
  16898. function printComment$2(commentPath) {
  16899. const comment = commentPath.getValue();
  16900. switch (comment.kind) {
  16901. case "Comment":
  16902. return "#" + comment.value.trimRight();
  16903. default:
  16904. throw new Error("Not a comment: " + JSON.stringify(comment));
  16905. }
  16906. }
  16907. function determineInterfaceSeparator(originalSource) {
  16908. const start = originalSource.indexOf("implements");
  16909. if (start === -1) {
  16910. throw new Error("Must implement interfaces: " + originalSource);
  16911. }
  16912. let end = originalSource.indexOf("{");
  16913. if (end === -1) {
  16914. end = originalSource.length;
  16915. }
  16916. return originalSource.substr(start, end).includes("&") ? " & " : ", ";
  16917. }
  16918. var printerGraphql = {
  16919. print: genericPrint$2,
  16920. hasPrettierIgnore: util$1.hasIgnoreComment,
  16921. printComment: printComment$2,
  16922. canAttachComment: canAttachComment$1
  16923. };
  16924. // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js
  16925. var options$5 = {
  16926. bracketSpacing: options.bracketSpacing
  16927. };
  16928. // Based on:
  16929. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  16930. const languages$3 = [
  16931. {
  16932. name: "GraphQL",
  16933. since: "1.5.0",
  16934. parsers: ["graphql"],
  16935. extensions: [".graphql", ".gql"],
  16936. tmScope: "source.graphql",
  16937. aceMode: "text",
  16938. liguistLanguageId: 139,
  16939. vscodeLanguageIds: ["graphql"]
  16940. }
  16941. ];
  16942. const parsers$3 = {
  16943. graphql: {
  16944. get parse() {
  16945. return require("./parser-graphql");
  16946. },
  16947. astFormat: "graphql",
  16948. locStart: function(node) {
  16949. if (typeof node.start === "number") {
  16950. return node.start;
  16951. }
  16952. return node.loc && node.loc.start;
  16953. },
  16954. locEnd: function(node) {
  16955. if (typeof node.end === "number") {
  16956. return node.end;
  16957. }
  16958. return node.loc && node.loc.end;
  16959. }
  16960. }
  16961. };
  16962. const printers$3 = {
  16963. graphql: printerGraphql
  16964. };
  16965. var languageGraphql = {
  16966. languages: languages$3,
  16967. options: options$5,
  16968. parsers: parsers$3,
  16969. printers: printers$3
  16970. };
  16971. const docBuilders$9 = doc.builders;
  16972. const hardline$8 = docBuilders$9.hardline;
  16973. const literalline$3 = docBuilders$9.literalline;
  16974. const concat$9 = docBuilders$9.concat;
  16975. const markAsRoot$1 = docBuilders$9.markAsRoot;
  16976. function embed$2(path$$1, print, textToDoc, options) {
  16977. const node = path$$1.getValue();
  16978. if (node.type === "code" && node.lang !== null) {
  16979. // only look for the first string so as to support [markdown-preview-enhanced](https://shd101wyy.github.io/markdown-preview-enhanced/#/code-chunk)
  16980. const lang = node.lang.split(/\s/, 1)[0];
  16981. const parser = getParserName(lang);
  16982. if (parser) {
  16983. const styleUnit = options.__inJsTemplate ? "~" : "`";
  16984. const style = styleUnit.repeat(
  16985. Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1)
  16986. );
  16987. const doc$$2 = textToDoc(node.value, { parser });
  16988. return markAsRoot$1(
  16989. concat$9([
  16990. style,
  16991. node.lang,
  16992. hardline$8,
  16993. replaceNewlinesWithLiterallines(doc$$2),
  16994. style
  16995. ])
  16996. );
  16997. }
  16998. }
  16999. return null;
  17000. function getParserName(lang) {
  17001. const supportInfo = support.getSupportInfo(null, {
  17002. plugins: options.plugins,
  17003. pluginsLoaded: true
  17004. });
  17005. const language = supportInfo.languages.find(
  17006. language =>
  17007. language.name.toLowerCase() === lang ||
  17008. (language.extensions &&
  17009. language.extensions.find(ext => ext.substring(1) === lang))
  17010. );
  17011. if (language) {
  17012. return language.parsers[0];
  17013. }
  17014. return null;
  17015. }
  17016. function replaceNewlinesWithLiterallines(doc$$2) {
  17017. return docUtils.mapDoc(
  17018. doc$$2,
  17019. currentDoc =>
  17020. typeof currentDoc === "string" && currentDoc.includes("\n")
  17021. ? concat$9(
  17022. currentDoc
  17023. .split(/(\n)/g)
  17024. .map((v, i) => (i % 2 === 0 ? v : literalline$3))
  17025. )
  17026. : currentDoc
  17027. );
  17028. }
  17029. }
  17030. var embed_1$2 = embed$2;
  17031. var pragma$2 = createCommonjsModule(function (module) {
  17032. "use strict";
  17033. const pragmas = ["format", "prettier"];
  17034. function startWithPragma(text) {
  17035. const pragma = `@(${pragmas.join("|")})`;
  17036. const regex = new RegExp(
  17037. [
  17038. `<!--\\s*${pragma}\\s*-->`,
  17039. `<!--.*\n[\\s\\S]*(^|\n)[^\\S\n]*${pragma}[^\\S\n]*($|\n)[\\s\\S]*\n.*-->`
  17040. ].join("|"),
  17041. "m"
  17042. );
  17043. const matched = text.match(regex);
  17044. return matched && matched.index === 0;
  17045. }
  17046. function extract(text) {
  17047. // yaml (---) and toml (+++)
  17048. const matched = text.match(
  17049. /^((---|\+\+\+)(?:\n[\s\S]*?\n|\n)\2(?:\n|$))?([\s\S]*)/
  17050. );
  17051. const frontMatter = matched[1];
  17052. const mainContent = matched[3];
  17053. return { frontMatter, mainContent };
  17054. }
  17055. module.exports = {
  17056. startWithPragma,
  17057. hasPragma: text => startWithPragma(extract(text).mainContent.trimLeft()),
  17058. insertPragma: text => {
  17059. const extracted = extract(text);
  17060. const pragma = `<!-- @${pragmas[0]} -->`;
  17061. return extracted.frontMatter
  17062. ? `${extracted.frontMatter}\n\n${pragma}\n\n${extracted.mainContent}`
  17063. : `${pragma}\n\n${extracted.mainContent}`;
  17064. }
  17065. };
  17066. });
  17067. const docBuilders$8 = doc.builders;
  17068. const concat$8 = docBuilders$8.concat;
  17069. const join$7 = docBuilders$8.join;
  17070. const line$5 = docBuilders$8.line;
  17071. const hardline$7 = docBuilders$8.hardline;
  17072. const softline$6 = docBuilders$8.softline;
  17073. const fill$4 = docBuilders$8.fill;
  17074. const align$2 = docBuilders$8.align;
  17075. const group$5 = docBuilders$8.group;
  17076. const printDocToString$2 = doc.printer.printDocToString;
  17077. const SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link"];
  17078. const SIBLING_NODE_TYPES = ["listItem", "definition", "footnoteDefinition"];
  17079. const INLINE_NODE_TYPES = [
  17080. "inlineCode",
  17081. "emphasis",
  17082. "strong",
  17083. "delete",
  17084. "link",
  17085. "linkReference",
  17086. "image",
  17087. "imageReference",
  17088. "footnote",
  17089. "footnoteReference",
  17090. "sentence",
  17091. "whitespace",
  17092. "word",
  17093. "break"
  17094. ];
  17095. const INLINE_NODE_WRAPPER_TYPES = INLINE_NODE_TYPES.concat([
  17096. "tableCell",
  17097. "paragraph",
  17098. "heading"
  17099. ]);
  17100. function genericPrint$3(path$$1, options, print) {
  17101. const node = path$$1.getValue();
  17102. if (shouldRemainTheSameContent(path$$1)) {
  17103. return concat$8(
  17104. util$1
  17105. .splitText(
  17106. options.originalText.slice(
  17107. node.position.start.offset,
  17108. node.position.end.offset
  17109. )
  17110. )
  17111. .map(
  17112. node =>
  17113. node.type === "word"
  17114. ? node.value
  17115. : node.value === ""
  17116. ? ""
  17117. : printLine(path$$1, node.value, options)
  17118. )
  17119. );
  17120. }
  17121. switch (node.type) {
  17122. case "root":
  17123. return concat$8([normalizeDoc(printRoot(path$$1, options, print)), hardline$7]);
  17124. case "paragraph":
  17125. return printChildren(path$$1, options, print, {
  17126. postprocessor: fill$4
  17127. });
  17128. case "sentence":
  17129. return printChildren(path$$1, options, print);
  17130. case "word":
  17131. return node.value
  17132. .replace(/[*]/g, "\\*") // escape all `*`
  17133. .replace(
  17134. new RegExp(
  17135. [
  17136. `(^|[${util$1.punctuationCharRange}])(_+)`,
  17137. `(_+)([${util$1.punctuationCharRange}]|$)`
  17138. ].join("|"),
  17139. "g"
  17140. ),
  17141. (_, text1, underscore1, underscore2, text2) =>
  17142. (underscore1
  17143. ? `${text1}${underscore1}`
  17144. : `${underscore2}${text2}`
  17145. ).replace(/_/g, "\\_")
  17146. ); // escape all `_` except concating with non-punctuation, e.g. `1_2_3` is not considered emphasis
  17147. case "whitespace": {
  17148. const parentNode = path$$1.getParentNode();
  17149. const index = parentNode.children.indexOf(node);
  17150. const nextNode = parentNode.children[index + 1];
  17151. const proseWrap =
  17152. // leading char that may cause different syntax
  17153. nextNode && /^>|^([-+*]|#{1,6}|[0-9]+[.)])$/.test(nextNode.value)
  17154. ? "never"
  17155. : options.proseWrap;
  17156. return printLine(path$$1, node.value, { proseWrap });
  17157. }
  17158. case "emphasis": {
  17159. const parentNode = path$$1.getParentNode();
  17160. const index = parentNode.children.indexOf(node);
  17161. const prevNode = parentNode.children[index - 1];
  17162. const nextNode = parentNode.children[index + 1];
  17163. const hasPrevOrNextWord = // `1*2*3` is considered emphais but `1_2_3` is not
  17164. (prevNode &&
  17165. prevNode.type === "sentence" &&
  17166. prevNode.children.length > 0 &&
  17167. util$1.getLast(prevNode.children).type === "word" &&
  17168. !util$1.getLast(prevNode.children).hasTrailingPunctuation) ||
  17169. (nextNode &&
  17170. nextNode.type === "sentence" &&
  17171. nextNode.children.length > 0 &&
  17172. nextNode.children[0].type === "word" &&
  17173. !nextNode.children[0].hasLeadingPunctuation);
  17174. const style =
  17175. hasPrevOrNextWord || getAncestorNode$1(path$$1, "emphasis") ? "*" : "_";
  17176. return concat$8([style, printChildren(path$$1, options, print), style]);
  17177. }
  17178. case "strong":
  17179. return concat$8(["**", printChildren(path$$1, options, print), "**"]);
  17180. case "delete":
  17181. return concat$8(["~~", printChildren(path$$1, options, print), "~~"]);
  17182. case "inlineCode": {
  17183. const backtickCount = util$1.getMaxContinuousCount(node.value, "`");
  17184. const style = backtickCount === 1 ? "``" : "`";
  17185. const gap = backtickCount ? " " : "";
  17186. return concat$8([style, gap, node.value, gap, style]);
  17187. }
  17188. case "link":
  17189. switch (options.originalText[node.position.start.offset]) {
  17190. case "<":
  17191. return concat$8(["<", node.url, ">"]);
  17192. case "[":
  17193. return concat$8([
  17194. "[",
  17195. printChildren(path$$1, options, print),
  17196. "](",
  17197. printUrl(node.url, ")"),
  17198. printTitle(node.title, options),
  17199. ")"
  17200. ]);
  17201. default:
  17202. return options.originalText.slice(
  17203. node.position.start.offset,
  17204. node.position.end.offset
  17205. );
  17206. }
  17207. case "image":
  17208. return concat$8([
  17209. "![",
  17210. node.alt || "",
  17211. "](",
  17212. printUrl(node.url, ")"),
  17213. printTitle(node.title, options),
  17214. ")"
  17215. ]);
  17216. case "blockquote":
  17217. return concat$8(["> ", align$2("> ", printChildren(path$$1, options, print))]);
  17218. case "heading":
  17219. return concat$8([
  17220. "#".repeat(node.depth) + " ",
  17221. printChildren(path$$1, options, print)
  17222. ]);
  17223. case "code": {
  17224. if (
  17225. // the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it
  17226. /^\n?( {4,}|\t)/.test(
  17227. options.originalText.slice(
  17228. node.position.start.offset,
  17229. node.position.end.offset
  17230. )
  17231. )
  17232. ) {
  17233. // indented code block
  17234. const alignment = " ".repeat(4);
  17235. return align$2(
  17236. alignment,
  17237. concat$8([alignment, join$7(hardline$7, node.value.split("\n"))])
  17238. );
  17239. }
  17240. // fenced code block
  17241. const styleUnit = options.__inJsTemplate ? "~" : "`";
  17242. const style = styleUnit.repeat(
  17243. Math.max(
  17244. 3,
  17245. util$1.getMaxContinuousCount(node.value, styleUnit) + 1
  17246. )
  17247. );
  17248. return concat$8([
  17249. style,
  17250. node.lang || "",
  17251. hardline$7,
  17252. join$7(hardline$7, node.value.split("\n")),
  17253. hardline$7,
  17254. style
  17255. ]);
  17256. }
  17257. case "yaml":
  17258. case "toml": {
  17259. const style = node.type === "yaml" ? "---" : "+++";
  17260. return node.value
  17261. ? concat$8([style, hardline$7, node.value, hardline$7, style])
  17262. : concat$8([style, hardline$7, style]);
  17263. }
  17264. case "html": {
  17265. const parentNode = path$$1.getParentNode();
  17266. return replaceNewlinesWithHardlines(
  17267. parentNode.type === "root" &&
  17268. util$1.getLast(parentNode.children) === node
  17269. ? node.value.trimRight()
  17270. : node.value
  17271. );
  17272. }
  17273. case "list": {
  17274. const nthSiblingIndex = getNthListSiblingIndex(
  17275. node,
  17276. path$$1.getParentNode()
  17277. );
  17278. const isGitDiffFriendlyOrderedList =
  17279. node.ordered &&
  17280. node.children.length > 1 &&
  17281. /^\s*1(\.|\))/.test(
  17282. options.originalText.slice(
  17283. node.children[1].position.start.offset,
  17284. node.children[1].position.end.offset
  17285. )
  17286. );
  17287. return printChildren(path$$1, options, print, {
  17288. processor: (childPath, index) => {
  17289. const prefix = getPrefix();
  17290. return concat$8([
  17291. prefix,
  17292. align$2(
  17293. " ".repeat(prefix.length),
  17294. printListItem(childPath, options, print, prefix)
  17295. )
  17296. ]);
  17297. function getPrefix() {
  17298. const rawPrefix = node.ordered
  17299. ? (index === 0
  17300. ? node.start
  17301. : isGitDiffFriendlyOrderedList
  17302. ? 1
  17303. : node.start + index) +
  17304. (nthSiblingIndex % 2 === 0 ? ". " : ") ")
  17305. : nthSiblingIndex % 2 === 0
  17306. ? "* "
  17307. : "- ";
  17308. // do not print trailing spaces for empty list item since it might be treated as `break` node
  17309. // by [doc-printer](https://github.com/prettier/prettier/blob/1.10.2/src/doc/doc-printer.js#L395-L405),
  17310. // we don't want to preserve unnecessary trailing spaces.
  17311. const listItem = childPath.getValue();
  17312. return listItem.children.length
  17313. ? alignListPrefix(rawPrefix, options)
  17314. : rawPrefix;
  17315. }
  17316. }
  17317. });
  17318. }
  17319. case "thematicBreak": {
  17320. const counter = getAncestorCounter$1(path$$1, "list");
  17321. if (counter === -1) {
  17322. return "---";
  17323. }
  17324. const nthSiblingIndex = getNthListSiblingIndex(
  17325. path$$1.getParentNode(counter),
  17326. path$$1.getParentNode(counter + 1)
  17327. );
  17328. return nthSiblingIndex % 2 === 0 ? "---" : "***";
  17329. }
  17330. case "linkReference":
  17331. return concat$8([
  17332. "[",
  17333. printChildren(path$$1, options, print),
  17334. "]",
  17335. node.referenceType === "full"
  17336. ? concat$8(["[", node.identifier, "]"])
  17337. : node.referenceType === "collapsed"
  17338. ? "[]"
  17339. : ""
  17340. ]);
  17341. case "imageReference":
  17342. switch (node.referenceType) {
  17343. case "full":
  17344. return concat$8(["![", node.alt || "", "][", node.identifier, "]"]);
  17345. default:
  17346. return concat$8([
  17347. "![",
  17348. node.alt,
  17349. "]",
  17350. node.referenceType === "collapsed" ? "[]" : ""
  17351. ]);
  17352. }
  17353. case "definition":
  17354. return concat$8([
  17355. "[",
  17356. node.identifier,
  17357. "]: ",
  17358. printUrl(node.url),
  17359. printTitle(node.title, options)
  17360. ]);
  17361. case "footnote":
  17362. return concat$8(["[^", printChildren(path$$1, options, print), "]"]);
  17363. case "footnoteReference":
  17364. return concat$8(["[^", node.identifier, "]"]);
  17365. case "footnoteDefinition": {
  17366. const nextNode = path$$1.getParentNode().children[path$$1.getName() + 1];
  17367. return concat$8([
  17368. "[^",
  17369. node.identifier,
  17370. "]: ",
  17371. group$5(
  17372. concat$8([
  17373. align$2(
  17374. " ".repeat(options.tabWidth),
  17375. printChildren(path$$1, options, print, {
  17376. processor: (childPath, index) =>
  17377. index === 0
  17378. ? group$5(concat$8([softline$6, softline$6, childPath.call(print)]))
  17379. : childPath.call(print)
  17380. })
  17381. ),
  17382. nextNode && nextNode.type === "footnoteDefinition" ? softline$6 : ""
  17383. ])
  17384. )
  17385. ]);
  17386. }
  17387. case "table":
  17388. return printTable(path$$1, options, print);
  17389. case "tableCell":
  17390. return printChildren(path$$1, options, print);
  17391. case "break":
  17392. return concat$8([
  17393. /\s/.test(options.originalText[node.position.start.offset])
  17394. ? " "
  17395. : "\\",
  17396. hardline$7
  17397. ]);
  17398. case "tableRow": // handled in "table"
  17399. case "listItem": // handled in "list"
  17400. default:
  17401. throw new Error(`Unknown markdown type ${JSON.stringify(node.type)}`);
  17402. }
  17403. }
  17404. function printListItem(path$$1, options, print, listPrefix) {
  17405. const node = path$$1.getValue();
  17406. const prefix = node.checked === null ? "" : node.checked ? "[x] " : "[ ] ";
  17407. return concat$8([
  17408. prefix,
  17409. printChildren(path$$1, options, print, {
  17410. processor: (childPath, index) => {
  17411. if (index === 0 && childPath.getValue().type !== "list") {
  17412. return align$2(" ".repeat(prefix.length), childPath.call(print));
  17413. }
  17414. const alignment = " ".repeat(
  17415. clamp(options.tabWidth - listPrefix.length, 0, 3) // 4+ will cause indented code block
  17416. );
  17417. return concat$8([alignment, align$2(alignment, childPath.call(print))]);
  17418. }
  17419. })
  17420. ]);
  17421. }
  17422. function alignListPrefix(prefix, options) {
  17423. const additionalSpaces = getAdditionalSpaces();
  17424. return (
  17425. prefix +
  17426. " ".repeat(
  17427. additionalSpaces >= 4 ? 0 : additionalSpaces // 4+ will cause indented code block
  17428. )
  17429. );
  17430. function getAdditionalSpaces() {
  17431. const restSpaces = prefix.length % options.tabWidth;
  17432. return restSpaces === 0 ? 0 : options.tabWidth - restSpaces;
  17433. }
  17434. }
  17435. function getNthListSiblingIndex(node, parentNode) {
  17436. return getNthSiblingIndex(
  17437. node,
  17438. parentNode,
  17439. siblingNode => siblingNode.ordered === node.ordered
  17440. );
  17441. }
  17442. function replaceNewlinesWithHardlines(str) {
  17443. return join$7(hardline$7, str.split("\n"));
  17444. }
  17445. function getNthSiblingIndex(node, parentNode, condition) {
  17446. condition = condition || (() => true);
  17447. let index = -1;
  17448. for (const childNode of parentNode.children) {
  17449. if (childNode.type === node.type && condition(childNode)) {
  17450. index++;
  17451. } else {
  17452. index = -1;
  17453. }
  17454. if (childNode === node) {
  17455. return index;
  17456. }
  17457. }
  17458. }
  17459. function getAncestorCounter$1(path$$1, typeOrTypes) {
  17460. const types = [].concat(typeOrTypes);
  17461. let counter = -1;
  17462. let ancestorNode;
  17463. while ((ancestorNode = path$$1.getParentNode(++counter))) {
  17464. if (types.indexOf(ancestorNode.type) !== -1) {
  17465. return counter;
  17466. }
  17467. }
  17468. return -1;
  17469. }
  17470. function getAncestorNode$1(path$$1, typeOrTypes) {
  17471. const counter = getAncestorCounter$1(path$$1, typeOrTypes);
  17472. return counter === -1 ? null : path$$1.getParentNode(counter);
  17473. }
  17474. function printLine(path$$1, value, options) {
  17475. if (options.proseWrap === "preserve" && value === "\n") {
  17476. return hardline$7;
  17477. }
  17478. const isBreakable =
  17479. options.proseWrap === "always" &&
  17480. !getAncestorNode$1(path$$1, SINGLE_LINE_NODE_TYPES);
  17481. return value !== ""
  17482. ? isBreakable
  17483. ? line$5
  17484. : " "
  17485. : isBreakable
  17486. ? softline$6
  17487. : "";
  17488. }
  17489. function printTable(path$$1, options, print) {
  17490. const node = path$$1.getValue();
  17491. const contents = []; // { [rowIndex: number]: { [columnIndex: number]: string } }
  17492. path$$1.map(rowPath => {
  17493. const rowContents = [];
  17494. rowPath.map(cellPath => {
  17495. rowContents.push(
  17496. printDocToString$2(cellPath.call(print), options).formatted
  17497. );
  17498. }, "children");
  17499. contents.push(rowContents);
  17500. }, "children");
  17501. const columnMaxWidths = contents.reduce(
  17502. (currentWidths, rowContents) =>
  17503. currentWidths.map((width, columnIndex) =>
  17504. Math.max(width, util$1.getStringWidth(rowContents[columnIndex]))
  17505. ),
  17506. contents[0].map(() => 3) // minimum width = 3 (---, :--, :-:, --:)
  17507. );
  17508. return join$7(hardline$7, [
  17509. printRow(contents[0]),
  17510. printSeparator(),
  17511. join$7(hardline$7, contents.slice(1).map(printRow))
  17512. ]);
  17513. function printSeparator() {
  17514. return concat$8([
  17515. "| ",
  17516. join$7(
  17517. " | ",
  17518. columnMaxWidths.map((width, index) => {
  17519. switch (node.align[index]) {
  17520. case "left":
  17521. return ":" + "-".repeat(width - 1);
  17522. case "right":
  17523. return "-".repeat(width - 1) + ":";
  17524. case "center":
  17525. return ":" + "-".repeat(width - 2) + ":";
  17526. default:
  17527. return "-".repeat(width);
  17528. }
  17529. })
  17530. ),
  17531. " |"
  17532. ]);
  17533. }
  17534. function printRow(rowContents) {
  17535. return concat$8([
  17536. "| ",
  17537. join$7(
  17538. " | ",
  17539. rowContents.map((rowContent, columnIndex) => {
  17540. switch (node.align[columnIndex]) {
  17541. case "right":
  17542. return alignRight(rowContent, columnMaxWidths[columnIndex]);
  17543. case "center":
  17544. return alignCenter(rowContent, columnMaxWidths[columnIndex]);
  17545. default:
  17546. return alignLeft(rowContent, columnMaxWidths[columnIndex]);
  17547. }
  17548. })
  17549. ),
  17550. " |"
  17551. ]);
  17552. }
  17553. function alignLeft(text, width) {
  17554. return concat$8([text, " ".repeat(width - util$1.getStringWidth(text))]);
  17555. }
  17556. function alignRight(text, width) {
  17557. return concat$8([" ".repeat(width - util$1.getStringWidth(text)), text]);
  17558. }
  17559. function alignCenter(text, width) {
  17560. const spaces = width - util$1.getStringWidth(text);
  17561. const left = Math.floor(spaces / 2);
  17562. const right = spaces - left;
  17563. return concat$8([" ".repeat(left), text, " ".repeat(right)]);
  17564. }
  17565. }
  17566. function printRoot(path$$1, options, print) {
  17567. /** @typedef {{ index: number, offset: number }} IgnorePosition */
  17568. /** @type {Array<{start: IgnorePosition, end: IgnorePosition}>} */
  17569. const ignoreRanges = [];
  17570. /** @type {IgnorePosition | null} */
  17571. let ignoreStart = null;
  17572. const children = path$$1.getValue().children;
  17573. children.forEach((childNode, index) => {
  17574. switch (isPrettierIgnore(childNode)) {
  17575. case "start":
  17576. if (ignoreStart === null) {
  17577. ignoreStart = { index, offset: childNode.position.end.offset };
  17578. }
  17579. break;
  17580. case "end":
  17581. if (ignoreStart !== null) {
  17582. ignoreRanges.push({
  17583. start: ignoreStart,
  17584. end: { index, offset: childNode.position.start.offset }
  17585. });
  17586. ignoreStart = null;
  17587. }
  17588. break;
  17589. default:
  17590. // do nothing
  17591. break;
  17592. }
  17593. });
  17594. return printChildren(path$$1, options, print, {
  17595. processor: (childPath, index) => {
  17596. if (ignoreRanges.length !== 0) {
  17597. const ignoreRange = ignoreRanges[0];
  17598. if (index === ignoreRange.start.index) {
  17599. return concat$8([
  17600. children[ignoreRange.start.index].value,
  17601. options.originalText.slice(
  17602. ignoreRange.start.offset,
  17603. ignoreRange.end.offset
  17604. ),
  17605. children[ignoreRange.end.index].value
  17606. ]);
  17607. }
  17608. if (ignoreRange.start.index < index && index < ignoreRange.end.index) {
  17609. return false;
  17610. }
  17611. if (index === ignoreRange.end.index) {
  17612. ignoreRanges.shift();
  17613. return false;
  17614. }
  17615. }
  17616. return childPath.call(print);
  17617. }
  17618. });
  17619. }
  17620. function printChildren(path$$1, options, print, events$$1) {
  17621. events$$1 = events$$1 || {};
  17622. const postprocessor = events$$1.postprocessor || concat$8;
  17623. const processor = events$$1.processor || (childPath => childPath.call(print));
  17624. const node = path$$1.getValue();
  17625. const parts = [];
  17626. let lastChildNode;
  17627. path$$1.map((childPath, index) => {
  17628. const childNode = childPath.getValue();
  17629. const result = processor(childPath, index);
  17630. if (result !== false) {
  17631. const data = {
  17632. parts,
  17633. prevNode: lastChildNode,
  17634. parentNode: node,
  17635. options
  17636. };
  17637. if (!shouldNotPrePrintHardline(childNode, data)) {
  17638. parts.push(hardline$7);
  17639. if (
  17640. shouldPrePrintDoubleHardline(childNode, data) ||
  17641. shouldPrePrintTripleHardline(childNode, data)
  17642. ) {
  17643. parts.push(hardline$7);
  17644. }
  17645. if (shouldPrePrintTripleHardline(childNode, data)) {
  17646. parts.push(hardline$7);
  17647. }
  17648. }
  17649. parts.push(result);
  17650. lastChildNode = childNode;
  17651. }
  17652. }, "children");
  17653. return postprocessor(parts);
  17654. }
  17655. /** @return {false | 'next' | 'start' | 'end'} */
  17656. function isPrettierIgnore(node) {
  17657. if (node.type !== "html") {
  17658. return false;
  17659. }
  17660. const match = node.value.match(
  17661. /^<!--\s*prettier-ignore(?:-(start|end))?\s*-->$/
  17662. );
  17663. return match === null ? false : match[1] ? match[1] : "next";
  17664. }
  17665. function shouldNotPrePrintHardline(node, data) {
  17666. const isFirstNode = data.parts.length === 0;
  17667. const isInlineNode = INLINE_NODE_TYPES.indexOf(node.type) !== -1;
  17668. const isInlineHTML =
  17669. node.type === "html" &&
  17670. INLINE_NODE_WRAPPER_TYPES.indexOf(data.parentNode.type) !== -1;
  17671. return isFirstNode || isInlineNode || isInlineHTML;
  17672. }
  17673. function shouldPrePrintDoubleHardline(node, data) {
  17674. const isSequence = (data.prevNode && data.prevNode.type) === node.type;
  17675. const isSiblingNode =
  17676. isSequence && SIBLING_NODE_TYPES.indexOf(node.type) !== -1;
  17677. const isInTightListItem =
  17678. data.parentNode.type === "listItem" && !data.parentNode.loose;
  17679. const isPrevNodeLooseListItem =
  17680. data.prevNode && data.prevNode.type === "listItem" && data.prevNode.loose;
  17681. const isPrevNodePrettierIgnore = isPrettierIgnore(data.prevNode) === "next";
  17682. return (
  17683. isPrevNodeLooseListItem ||
  17684. !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore)
  17685. );
  17686. }
  17687. function shouldPrePrintTripleHardline(node, data) {
  17688. const isPrevNodeList = data.prevNode && data.prevNode.type === "list";
  17689. const isIndentedCode =
  17690. node.type === "code" &&
  17691. /\s/.test(data.options.originalText[node.position.start.offset]);
  17692. return isPrevNodeList && isIndentedCode;
  17693. }
  17694. function shouldRemainTheSameContent(path$$1) {
  17695. const ancestorNode = getAncestorNode$1(path$$1, [
  17696. "linkReference",
  17697. "imageReference"
  17698. ]);
  17699. return (
  17700. ancestorNode &&
  17701. (ancestorNode.type !== "linkReference" ||
  17702. ancestorNode.referenceType !== "full")
  17703. );
  17704. }
  17705. function normalizeDoc(doc$$2) {
  17706. return docUtils.mapDoc(doc$$2, currentDoc => {
  17707. if (!currentDoc.parts) {
  17708. return currentDoc;
  17709. }
  17710. if (currentDoc.type === "concat" && currentDoc.parts.length === 1) {
  17711. return currentDoc.parts[0];
  17712. }
  17713. const parts = [];
  17714. currentDoc.parts.forEach(part => {
  17715. if (part.type === "concat") {
  17716. parts.push.apply(parts, part.parts);
  17717. } else if (part !== "") {
  17718. parts.push(part);
  17719. }
  17720. });
  17721. return Object.assign({}, currentDoc, {
  17722. parts: normalizeParts(parts)
  17723. });
  17724. });
  17725. }
  17726. function printUrl(url$$1, dangerousCharOrChars) {
  17727. const dangerousChars = [" "].concat(dangerousCharOrChars || []);
  17728. return new RegExp(dangerousChars.map(x => `\\${x}`).join("|")).test(url$$1)
  17729. ? `<${url$$1}>`
  17730. : url$$1;
  17731. }
  17732. function printTitle(title, options) {
  17733. if (!title) {
  17734. return "";
  17735. }
  17736. if (title.includes('"') && title.includes("'") && !title.includes(")")) {
  17737. return ` (${title})`; // avoid escaped quotes
  17738. }
  17739. // faster than using RegExps: https://jsperf.com/performance-of-match-vs-split
  17740. const singleCount = title.split("'").length - 1;
  17741. const doubleCount = title.split('"').length - 1;
  17742. const quote =
  17743. singleCount > doubleCount
  17744. ? '"'
  17745. : doubleCount > singleCount
  17746. ? "'"
  17747. : options.singleQuote
  17748. ? "'"
  17749. : '"';
  17750. title = title.replace(new RegExp(`(${quote})`, "g"), "\\$1");
  17751. return ` ${quote}${title}${quote}`;
  17752. }
  17753. function normalizeParts(parts) {
  17754. return parts.reduce((current, part) => {
  17755. const lastPart = util$1.getLast(current);
  17756. if (typeof lastPart === "string" && typeof part === "string") {
  17757. current.splice(-1, 1, lastPart + part);
  17758. } else {
  17759. current.push(part);
  17760. }
  17761. return current;
  17762. }, []);
  17763. }
  17764. function clamp(value, min, max) {
  17765. return value < min ? min : value > max ? max : value;
  17766. }
  17767. function clean$5(ast, newObj, parent) {
  17768. // for codeblock
  17769. if (ast.type === "code") {
  17770. delete newObj.value;
  17771. }
  17772. // for whitespace: "\n" and " " are considered the same
  17773. if (ast.type === "whitespace" && ast.value === "\n") {
  17774. newObj.value = " ";
  17775. }
  17776. // for insert pragma
  17777. if (
  17778. parent &&
  17779. parent.type === "root" &&
  17780. (parent.children[0] === ast ||
  17781. ((parent.children[0].type === "yaml" ||
  17782. parent.children[0].type === "toml") &&
  17783. parent.children[1] === ast)) &&
  17784. ast.type === "html" &&
  17785. pragma$2.startWithPragma(ast.value)
  17786. ) {
  17787. return null;
  17788. }
  17789. }
  17790. function hasPrettierIgnore$1(path$$1) {
  17791. const index = +path$$1.getName();
  17792. if (index === 0) {
  17793. return false;
  17794. }
  17795. const prevNode = path$$1.getParentNode().children[index - 1];
  17796. return isPrettierIgnore(prevNode) === "next";
  17797. }
  17798. var printerMarkdown = {
  17799. print: genericPrint$3,
  17800. embed: embed_1$2,
  17801. massageAstNode: clean$5,
  17802. hasPrettierIgnore: hasPrettierIgnore$1,
  17803. insertPragma: pragma$2.insertPragma
  17804. };
  17805. const CATEGORY_MARKDOWN = "Markdown";
  17806. // format based on https://github.com/prettier/prettier/blob/master/src/common/support.js
  17807. var options$8 = {
  17808. proseWrap: {
  17809. since: "1.8.2",
  17810. category: CATEGORY_MARKDOWN,
  17811. type: "choice",
  17812. default: [
  17813. { since: "1.8.2", value: true },
  17814. { since: "1.9.0", value: "preserve" }
  17815. ],
  17816. description: "How to wrap prose. (markdown)",
  17817. choices: [
  17818. {
  17819. since: "1.9.0",
  17820. value: "always",
  17821. description: "Wrap prose if it exceeds the print width."
  17822. },
  17823. {
  17824. since: "1.9.0",
  17825. value: "never",
  17826. description: "Do not wrap prose."
  17827. },
  17828. {
  17829. since: "1.9.0",
  17830. value: "preserve",
  17831. description: "Wrap prose as-is."
  17832. },
  17833. { value: false, deprecated: "1.9.0", redirect: "never" },
  17834. { value: true, deprecated: "1.9.0", redirect: "always" }
  17835. ]
  17836. },
  17837. singleQuote: options.singleQuote
  17838. };
  17839. // Based on:
  17840. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  17841. const languages$4 = [
  17842. {
  17843. name: "Markdown",
  17844. since: "1.8.0",
  17845. parsers: ["remark"],
  17846. aliases: ["pandoc"],
  17847. aceMode: "markdown",
  17848. codemirrorMode: "gfm",
  17849. codemirrorMimeType: "text/x-gfm",
  17850. wrap: true,
  17851. extensions: [
  17852. ".md",
  17853. ".markdown",
  17854. ".mdown",
  17855. ".mdwn",
  17856. ".mkd",
  17857. ".mkdn",
  17858. ".mkdown",
  17859. ".ron",
  17860. ".workbook"
  17861. ],
  17862. filenames: ["README"],
  17863. tmScope: "source.gfm",
  17864. linguistLanguageId: 222,
  17865. vscodeLanguageIds: ["markdown"]
  17866. }
  17867. ];
  17868. const remark = {
  17869. get parse() {
  17870. return require("./parser-markdown");
  17871. },
  17872. astFormat: "mdast",
  17873. hasPragma: pragma$2.hasPragma,
  17874. locStart: node => node.position.start.offset,
  17875. locEnd: node => node.position.end.offset
  17876. };
  17877. const parsers$4 = {
  17878. remark,
  17879. // TODO: Delete this in 2.0
  17880. markdown: remark
  17881. };
  17882. const printers$4 = {
  17883. mdast: printerMarkdown
  17884. };
  17885. var languageMarkdown = {
  17886. languages: languages$4,
  17887. options: options$8,
  17888. parsers: parsers$4,
  17889. printers: printers$4
  17890. };
  17891. const docUtils$5 = doc.utils;
  17892. const docBuilders$11 = doc.builders;
  17893. const hardline$10 = docBuilders$11.hardline;
  17894. const concat$11 = docBuilders$11.concat;
  17895. function embed$4(path$$1, print, textToDoc, options) {
  17896. const node = path$$1.getValue();
  17897. switch (node.type) {
  17898. case "text": {
  17899. const parent = path$$1.getParentNode();
  17900. // Inline JavaScript
  17901. if (
  17902. parent.type === "script" &&
  17903. ((!parent.attribs.lang && !parent.attribs.lang) ||
  17904. parent.attribs.type === "text/javascript" ||
  17905. parent.attribs.type === "application/javascript")
  17906. ) {
  17907. const parser = options.parser === "flow" ? "flow" : "babylon";
  17908. const doc$$2 = textToDoc(getText(options, node), { parser });
  17909. return concat$11([hardline$10, doc$$2]);
  17910. }
  17911. // Inline TypeScript
  17912. if (
  17913. parent.type === "script" &&
  17914. (parent.attribs.type === "application/x-typescript" ||
  17915. parent.attribs.lang === "ts")
  17916. ) {
  17917. const doc$$2 = textToDoc(
  17918. getText(options, node),
  17919. { parser: "typescript" },
  17920. options
  17921. );
  17922. return concat$11([hardline$10, doc$$2]);
  17923. }
  17924. // Inline Styles
  17925. if (parent.type === "style") {
  17926. const doc$$2 = textToDoc(getText(options, node), { parser: "css" });
  17927. return concat$11([hardline$10, docUtils$5.stripTrailingHardline(doc$$2)]);
  17928. }
  17929. break;
  17930. }
  17931. case "attribute": {
  17932. /*
  17933. * Vue binding sytax: JS expressions
  17934. * :class="{ 'some-key': value }"
  17935. * v-bind:id="'list-' + id"
  17936. * v-if="foo && !bar"
  17937. * @click="someFunction()"
  17938. */
  17939. if (/(^@)|(^v-)|:/.test(node.key) && !/^\w+$/.test(node.value)) {
  17940. const doc$$2 = textToDoc(node.value, {
  17941. parser: parseJavaScriptExpression,
  17942. // Use singleQuote since HTML attributes use double-quotes.
  17943. // TODO(azz): We still need to do an entity escape on the attribute.
  17944. singleQuote: true
  17945. });
  17946. return concat$11([
  17947. node.key,
  17948. '="',
  17949. util$1.hasNewlineInRange(node.value, 0, node.value.length)
  17950. ? doc$$2
  17951. : docUtils$5.removeLines(doc$$2),
  17952. '"'
  17953. ]);
  17954. }
  17955. }
  17956. }
  17957. }
  17958. function parseJavaScriptExpression(text, parsers) {
  17959. // Force parsing as an expression
  17960. const ast = parsers.babylon(`(${text})`);
  17961. // Extract expression from the declaration
  17962. return {
  17963. type: "File",
  17964. program: ast.program.body[0].expression
  17965. };
  17966. }
  17967. function getText(options, node) {
  17968. return options.originalText.slice(
  17969. options.locStart(node),
  17970. options.locEnd(node)
  17971. );
  17972. }
  17973. var embed_1$4 = embed$4;
  17974. const docBuilders$10 = doc.builders;
  17975. const concat$10 = docBuilders$10.concat;
  17976. const join$8 = docBuilders$10.join;
  17977. const hardline$9 = docBuilders$10.hardline;
  17978. const line$6 = docBuilders$10.line;
  17979. const softline$7 = docBuilders$10.softline;
  17980. const group$6 = docBuilders$10.group;
  17981. const indent$7 = docBuilders$10.indent;
  17982. // http://w3c.github.io/html/single-page.html#void-elements
  17983. const voidTags$1 = {
  17984. area: true,
  17985. base: true,
  17986. br: true,
  17987. col: true,
  17988. embed: true,
  17989. hr: true,
  17990. img: true,
  17991. input: true,
  17992. link: true,
  17993. meta: true,
  17994. param: true,
  17995. source: true,
  17996. track: true,
  17997. wbr: true
  17998. };
  17999. function genericPrint$4(path$$1, options, print) {
  18000. const n = path$$1.getValue();
  18001. if (!n) {
  18002. return "";
  18003. }
  18004. if (typeof n === "string") {
  18005. return n;
  18006. }
  18007. switch (n.type) {
  18008. case "root": {
  18009. return printChildren$1(path$$1, print);
  18010. }
  18011. case "directive": {
  18012. return concat$10(["<", n.data, ">", hardline$9]);
  18013. }
  18014. case "text": {
  18015. return n.data.replace(/\s+/g, " ").trim();
  18016. }
  18017. case "script":
  18018. case "style":
  18019. case "tag": {
  18020. const selfClose = voidTags$1[n.name] ? ">" : " />";
  18021. const children = printChildren$1(path$$1, print);
  18022. const hasNewline = util$1.hasNewlineInRange(
  18023. options.originalText,
  18024. options.locStart(n),
  18025. options.locEnd(n)
  18026. );
  18027. return group$6(
  18028. concat$10([
  18029. hasNewline ? hardline$9 : "",
  18030. "<",
  18031. n.name,
  18032. printAttributes(path$$1, print),
  18033. n.children.length ? ">" : selfClose,
  18034. n.name.toLowerCase() === "html"
  18035. ? concat$10([hardline$9, children])
  18036. : indent$7(children),
  18037. n.children.length ? concat$10([softline$7, "</", n.name, ">"]) : hardline$9
  18038. ])
  18039. );
  18040. }
  18041. case "comment": {
  18042. return concat$10(["<!-- ", n.data.trim(), " -->"]);
  18043. }
  18044. case "attribute": {
  18045. if (!n.value) {
  18046. return n.key;
  18047. }
  18048. return concat$10([n.key, '="', n.value, '"']);
  18049. }
  18050. default:
  18051. /* istanbul ignore next */
  18052. throw new Error("unknown htmlparser2 type: " + n.type);
  18053. }
  18054. }
  18055. function printAttributes(path$$1, print) {
  18056. const node = path$$1.getValue();
  18057. return concat$10([
  18058. node.attributes.length ? " " : "",
  18059. indent$7(join$8(line$6, path$$1.map(print, "attributes")))
  18060. ]);
  18061. }
  18062. function printChildren$1(path$$1, print) {
  18063. const children = [];
  18064. path$$1.each(childPath => {
  18065. const child = childPath.getValue();
  18066. if (child.type !== "text") {
  18067. children.push(hardline$9);
  18068. }
  18069. children.push(childPath.call(print));
  18070. }, "children");
  18071. return concat$10(children);
  18072. }
  18073. var printerHtmlparser2 = {
  18074. print: genericPrint$4,
  18075. embed: embed_1$4,
  18076. hasPrettierIgnore: util$1.hasIgnoreComment
  18077. };
  18078. // Based on:
  18079. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  18080. const languages$5 = [
  18081. {
  18082. name: "HTML",
  18083. since: null, // unreleased
  18084. parsers: ["parse5"],
  18085. group: "HTML",
  18086. tmScope: "text.html.basic",
  18087. aceMode: "html",
  18088. codemirrorMode: "htmlmixed",
  18089. codemirrorMimeType: "text/html",
  18090. aliases: ["xhtml"],
  18091. extensions: [".html", ".htm", ".html.hl", ".inc", ".st", ".xht", ".xhtml"],
  18092. linguistLanguageId: 146,
  18093. vscodeLanguageIds: ["html"]
  18094. }
  18095. ];
  18096. const parsers$5 = {
  18097. parse5: {
  18098. get parse() {
  18099. return require("./parser-parse5");
  18100. },
  18101. astFormat: "htmlparser2",
  18102. locEnd: function(node) {
  18103. return node.__location && node.__location.endOffset;
  18104. },
  18105. locStart: function(node) {
  18106. return node.__location && node.__location.startOffset;
  18107. }
  18108. }
  18109. };
  18110. const printers$5 = {
  18111. htmlparser2: printerHtmlparser2
  18112. };
  18113. var languageHtml = {
  18114. languages: languages$5,
  18115. parsers: parsers$5,
  18116. printers: printers$5
  18117. };
  18118. const docBuilders$13 = doc.builders;
  18119. const concat$13 = docBuilders$13.concat;
  18120. const hardline$12 = docBuilders$13.hardline;
  18121. function embed$6(path$$1, print, textToDoc, options) {
  18122. const node = path$$1.getValue();
  18123. const parent = path$$1.getParentNode();
  18124. if (!parent || parent.tag !== "root" || node.unary) {
  18125. return null;
  18126. }
  18127. let parser;
  18128. if (node.tag === "style") {
  18129. const langAttr = node.attrs.find(attr => attr.name === "lang");
  18130. if (!langAttr || langAttr.value === "postcss") {
  18131. parser = "css";
  18132. } else if (langAttr.value === "scss") {
  18133. parser = "scss";
  18134. } else if (langAttr.value === "less") {
  18135. parser = "less";
  18136. }
  18137. }
  18138. if (node.tag === "script") {
  18139. const langAttr = node.attrs.find(attr => attr.name === "lang");
  18140. if (!langAttr) {
  18141. parser = "babylon";
  18142. } else if (langAttr.value === "ts" || langAttr.value === "tsx") {
  18143. parser = "typescript";
  18144. }
  18145. }
  18146. if (!parser) {
  18147. return null;
  18148. }
  18149. return concat$13([
  18150. options.originalText.slice(node.start, node.contentStart),
  18151. hardline$12,
  18152. textToDoc(options.originalText.slice(node.contentStart, node.contentEnd), {
  18153. parser
  18154. }),
  18155. options.originalText.slice(node.contentEnd, node.end)
  18156. ]);
  18157. }
  18158. var embed_1$6 = embed$6;
  18159. const docBuilders$12 = doc.builders;
  18160. const concat$12 = docBuilders$12.concat;
  18161. const hardline$11 = docBuilders$12.hardline;
  18162. function genericPrint$5(path$$1, options, print) {
  18163. const n = path$$1.getValue();
  18164. const res = [];
  18165. let index = n.start;
  18166. path$$1.each(childPath => {
  18167. const child = childPath.getValue();
  18168. res.push(options.originalText.slice(index, child.start));
  18169. res.push(childPath.call(print));
  18170. index = child.end;
  18171. }, "children");
  18172. // If there are no children, we just print the node from start to end.
  18173. // Otherwise, index should point to the end of the last child, and we
  18174. // need to print the closing tag.
  18175. res.push(options.originalText.slice(index, n.end));
  18176. // Only force a trailing newline if there were any contents.
  18177. if (n.tag === "root" && n.children.length) {
  18178. res.push(hardline$11);
  18179. }
  18180. return concat$12(res);
  18181. }
  18182. const clean$6 = (ast, newObj) => {
  18183. delete newObj.contentStart;
  18184. delete newObj.contentEnd;
  18185. };
  18186. var printerVue = {
  18187. print: genericPrint$5,
  18188. embed: embed_1$6,
  18189. massageAstNode: clean$6
  18190. };
  18191. // Based on:
  18192. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  18193. const languages$6 = [
  18194. {
  18195. name: "Vue",
  18196. since: "1.10.0",
  18197. parsers: ["vue"],
  18198. group: "HTML",
  18199. tmScope: "text.html.vue",
  18200. aceMode: "html",
  18201. codemirrorMode: "htmlmixed",
  18202. codemirrorMimeType: "text/html",
  18203. extensions: [".vue"],
  18204. linguistLanguageId: 146,
  18205. vscodeLanguageIds: ["vue"]
  18206. }
  18207. ];
  18208. const parsers$6 = {
  18209. vue: {
  18210. get parse() {
  18211. return require("./parser-vue");
  18212. },
  18213. astFormat: "vue"
  18214. }
  18215. };
  18216. const printers$6 = {
  18217. vue: printerVue
  18218. };
  18219. var languageVue = {
  18220. languages: languages$6,
  18221. parsers: parsers$6,
  18222. printers: printers$6
  18223. };
  18224. function loadPlugins(plugins) {
  18225. plugins = plugins || [];
  18226. const internalPlugins = [
  18227. languageJs,
  18228. languageCss,
  18229. languageHandlebars,
  18230. languageGraphql,
  18231. languageMarkdown,
  18232. languageHtml,
  18233. languageVue
  18234. ];
  18235. const externalPlugins = plugins
  18236. .concat(
  18237. getPluginsFromPackage(
  18238. readPkgUp.sync({
  18239. normalize: false
  18240. }).pkg
  18241. )
  18242. )
  18243. .map(plugin => {
  18244. if (typeof plugin !== "string") {
  18245. return plugin;
  18246. }
  18247. const pluginPath = resolve.sync(plugin, { basedir: process.cwd() });
  18248. return Object.assign({ name: plugin }, require(pluginPath));
  18249. });
  18250. return deduplicate(internalPlugins.concat(externalPlugins));
  18251. }
  18252. function getPluginsFromPackage(pkg) {
  18253. if (!pkg) {
  18254. return [];
  18255. }
  18256. const deps = Object.assign({}, pkg.dependencies, pkg.devDependencies);
  18257. return Object.keys(deps).filter(
  18258. dep =>
  18259. dep.startsWith("prettier-plugin-") || dep.startsWith("@prettier/plugin-")
  18260. );
  18261. }
  18262. function deduplicate(items) {
  18263. const uniqItems = [];
  18264. for (const item of items) {
  18265. if (uniqItems.indexOf(item) < 0) {
  18266. uniqItems.push(item);
  18267. }
  18268. }
  18269. return uniqItems;
  18270. }
  18271. var loadPlugins_1 = loadPlugins;
  18272. const CATEGORY_CONFIG = "Config";
  18273. const CATEGORY_EDITOR = "Editor";
  18274. const CATEGORY_FORMAT = "Format";
  18275. const CATEGORY_OTHER = "Other";
  18276. const CATEGORY_OUTPUT = "Output";
  18277. const categoryOrder = [
  18278. CATEGORY_OUTPUT,
  18279. CATEGORY_FORMAT,
  18280. CATEGORY_CONFIG,
  18281. CATEGORY_EDITOR,
  18282. CATEGORY_OTHER
  18283. ];
  18284. /**
  18285. * {
  18286. * [optionName]: {
  18287. * // The type of the option. For 'choice', see also `choices` below.
  18288. * // When passing a type other than the ones listed below, the option is
  18289. * // treated as taking any string as argument, and `--option <${type}>` will
  18290. * // be displayed in --help.
  18291. * type: "boolean" | "choice" | "int" | string;
  18292. *
  18293. * // Default value to be passed to the minimist option `default`.
  18294. * default?: any;
  18295. *
  18296. * // Alias name to be passed to the minimist option `alias`.
  18297. * alias?: string;
  18298. *
  18299. * // For grouping options by category in --help.
  18300. * category?: string;
  18301. *
  18302. * // Description to be displayed in --help. If omitted, the option won't be
  18303. * // shown at all in --help (but see also `oppositeDescription` below).
  18304. * description?: string;
  18305. *
  18306. * // Description for `--no-${name}` to be displayed in --help. If omitted,
  18307. * // `--no-${name}` won't be shown.
  18308. * oppositeDescription?: string;
  18309. *
  18310. * // Indicate if this option is simply passed to the API.
  18311. * // true: use camelified name as the API option name.
  18312. * // string: use this value as the API option name.
  18313. * forwardToApi?: boolean | string;
  18314. *
  18315. * // Indicate that a CLI flag should be an array when forwarded to the API.
  18316. * array?: boolean;
  18317. *
  18318. * // Specify available choices for validation. They will also be displayed
  18319. * // in --help as <a|b|c>.
  18320. * // Use an object instead of a string if a choice is deprecated and should
  18321. * // be treated as `redirect` instead, or if you'd like to add description for
  18322. * // the choice.
  18323. * choices?: Array<
  18324. * | string
  18325. * | { value: string, description?: string, deprecated?: boolean, redirect?: string }
  18326. * >;
  18327. *
  18328. * // If the option has a value that is an exception to the regular value
  18329. * // constraints, indicate that value here (or use a function for more
  18330. * // flexibility).
  18331. * exception?: ((value: any) => boolean);
  18332. *
  18333. * // Indicate that the option is deprecated. Use a string to add an extra
  18334. * // message to --help for the option, for example to suggest a replacement
  18335. * // option.
  18336. * deprecated?: true | string;
  18337. * }
  18338. * }
  18339. *
  18340. * Note: The options below are sorted alphabetically.
  18341. */
  18342. const options$11 = {
  18343. color: {
  18344. // The supports-color package (a sub sub dependency) looks directly at
  18345. // `process.argv` for `--no-color` and such-like options. The reason it is
  18346. // listed here is to avoid "Ignored unknown option: --no-color" warnings.
  18347. // See https://github.com/chalk/supports-color/#info for more information.
  18348. type: "boolean",
  18349. default: true,
  18350. description: "Colorize error messages.",
  18351. oppositeDescription: "Do not colorize error messages."
  18352. },
  18353. config: {
  18354. type: "path",
  18355. category: CATEGORY_CONFIG,
  18356. description:
  18357. "Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js).",
  18358. oppositeDescription: "Do not look for a configuration file."
  18359. },
  18360. "config-precedence": {
  18361. type: "choice",
  18362. category: CATEGORY_CONFIG,
  18363. default: "cli-override",
  18364. choices: [
  18365. {
  18366. value: "cli-override",
  18367. description: "CLI options take precedence over config file"
  18368. },
  18369. {
  18370. value: "file-override",
  18371. description: "Config file take precedence over CLI options"
  18372. },
  18373. {
  18374. value: "prefer-file",
  18375. description: dedent_1`
  18376. If a config file is found will evaluate it and ignore other CLI options.
  18377. If no config file is found CLI options will evaluate as normal.
  18378. `
  18379. }
  18380. ],
  18381. description:
  18382. "Define in which order config files and CLI options should be evaluated."
  18383. },
  18384. "debug-check": {
  18385. type: "boolean"
  18386. },
  18387. "debug-print-doc": {
  18388. type: "boolean"
  18389. },
  18390. editorconfig: {
  18391. type: "boolean",
  18392. category: CATEGORY_CONFIG,
  18393. description: "Take .editorconfig into account when parsing configuration.",
  18394. oppositeDescription:
  18395. "Don't take .editorconfig into account when parsing configuration.",
  18396. default: true
  18397. },
  18398. "find-config-path": {
  18399. type: "path",
  18400. category: CATEGORY_CONFIG,
  18401. description:
  18402. "Find and print the path to a configuration file for the given input file."
  18403. },
  18404. help: {
  18405. type: "flag",
  18406. alias: "h",
  18407. description: dedent_1`
  18408. Show CLI usage, or details about the given flag.
  18409. Example: --help write
  18410. `
  18411. },
  18412. "ignore-path": {
  18413. type: "path",
  18414. category: CATEGORY_CONFIG,
  18415. default: ".prettierignore",
  18416. description: "Path to a file with patterns describing files to ignore."
  18417. },
  18418. "list-different": {
  18419. type: "boolean",
  18420. category: CATEGORY_OUTPUT,
  18421. alias: "l",
  18422. description:
  18423. "Print the names of files that are different from Prettier's formatting."
  18424. },
  18425. loglevel: {
  18426. type: "choice",
  18427. description: "What level of logs to report.",
  18428. default: "log",
  18429. choices: ["silent", "error", "warn", "log", "debug"]
  18430. },
  18431. stdin: {
  18432. type: "boolean",
  18433. description: "Force reading input from stdin."
  18434. },
  18435. "support-info": {
  18436. type: "boolean",
  18437. description: "Print support information as JSON."
  18438. },
  18439. version: {
  18440. type: "boolean",
  18441. alias: "v",
  18442. description: "Print Prettier version."
  18443. },
  18444. "with-node-modules": {
  18445. type: "boolean",
  18446. category: CATEGORY_CONFIG,
  18447. description: "Process files inside 'node_modules' directory."
  18448. },
  18449. write: {
  18450. type: "boolean",
  18451. category: CATEGORY_OUTPUT,
  18452. description: "Edit files in-place. (Beware!)"
  18453. }
  18454. };
  18455. const usageSummary = dedent_1`
  18456. Usage: prettier [options] [file/glob ...]
  18457. By default, output is written to stdout.
  18458. Stdin is read if it is piped to Prettier and no files are given.
  18459. `;
  18460. var constant = {
  18461. CATEGORY_CONFIG,
  18462. CATEGORY_EDITOR,
  18463. CATEGORY_FORMAT,
  18464. CATEGORY_OTHER,
  18465. CATEGORY_OUTPUT,
  18466. categoryOrder,
  18467. options: options$11,
  18468. usageSummary
  18469. };
  18470. var require$$0$11 = ( _package$1 && _package ) || _package$1;
  18471. const currentVersion = require$$0$11.version;
  18472. const CATEGORY_GLOBAL = "Global";
  18473. const CATEGORY_SPECIAL = "Special";
  18474. /**
  18475. * @typedef {Object} OptionInfo
  18476. * @property {string} since - available since version
  18477. * @property {string} category
  18478. * @property {'int' | 'boolean' | 'choice' | 'path'} type
  18479. * @property {boolean} array - indicate it's an array of the specified type
  18480. * @property {boolean?} deprecated - deprecated since version
  18481. * @property {OptionRedirectInfo?} redirect - redirect deprecated option
  18482. * @property {string} description
  18483. * @property {string?} oppositeDescription - for `false` option
  18484. * @property {OptionValueInfo} default
  18485. * @property {OptionRangeInfo?} range - for type int
  18486. * @property {OptionChoiceInfo?} choices - for type choice
  18487. * @property {(value: any) => boolean} exception
  18488. *
  18489. * @typedef {number | boolean | string} OptionValue
  18490. * @typedef {OptionValue | [{ value: OptionValue[] }] | Array<{ since: string, value: OptionValue}>} OptionValueInfo
  18491. *
  18492. * @typedef {Object} OptionRedirectInfo
  18493. * @property {string} option
  18494. * @property {OptionValue} value
  18495. *
  18496. * @typedef {Object} OptionRangeInfo
  18497. * @property {number} start - recommended range start
  18498. * @property {number} end - recommended range end
  18499. * @property {number} step - recommended range step
  18500. *
  18501. * @typedef {Object} OptionChoiceInfo
  18502. * @property {boolean | string} value - boolean for the option that is originally boolean type
  18503. * @property {string?} description - undefined if redirect
  18504. * @property {string?} since - undefined if available since the first version of the option
  18505. * @property {string?} deprecated - deprecated since version
  18506. * @property {OptionValueInfo?} redirect - redirect deprecated value
  18507. *
  18508. * @property {string?} cliName
  18509. * @property {string?} cliCategory
  18510. * @property {string?} cliDescription
  18511. */
  18512. /** @type {{ [name: string]: OptionInfo } */
  18513. const supportOptions = {
  18514. cursorOffset: {
  18515. since: "1.4.0",
  18516. category: CATEGORY_SPECIAL,
  18517. type: "int",
  18518. default: -1,
  18519. range: { start: -1, end: Infinity, step: 1 },
  18520. description: dedent_1`
  18521. Print (to stderr) where a cursor at the given position would move to after formatting.
  18522. This option cannot be used with --range-start and --range-end.
  18523. `,
  18524. cliCategory: constant.CATEGORY_EDITOR
  18525. },
  18526. filepath: {
  18527. since: "1.4.0",
  18528. category: CATEGORY_SPECIAL,
  18529. type: "path",
  18530. default: undefined,
  18531. description:
  18532. "Specify the input filepath. This will be used to do parser inference.",
  18533. cliName: "stdin-filepath",
  18534. cliCategory: constant.CATEGORY_OTHER,
  18535. cliDescription: "Path to the file to pretend that stdin comes from."
  18536. },
  18537. insertPragma: {
  18538. since: "1.8.0",
  18539. category: CATEGORY_SPECIAL,
  18540. type: "boolean",
  18541. default: false,
  18542. description: "Insert @format pragma into file's first docblock comment.",
  18543. cliCategory: constant.CATEGORY_OTHER
  18544. },
  18545. parser: {
  18546. since: "0.0.10",
  18547. category: CATEGORY_GLOBAL,
  18548. type: "choice",
  18549. default: "babylon",
  18550. description: "Which parser to use.",
  18551. exception: value =>
  18552. typeof value === "string" || typeof value === "function",
  18553. choices: [
  18554. { value: "flow", description: "Flow" },
  18555. { value: "babylon", description: "JavaScript" },
  18556. { value: "typescript", since: "1.4.0", description: "TypeScript" },
  18557. { value: "css", since: "1.7.1", description: "CSS" },
  18558. {
  18559. value: "postcss",
  18560. since: "1.4.0",
  18561. description: "CSS/Less/SCSS",
  18562. deprecated: "1.7.1",
  18563. redirect: "css"
  18564. },
  18565. { value: "less", since: "1.7.1", description: "Less" },
  18566. { value: "scss", since: "1.7.1", description: "SCSS" },
  18567. { value: "json", since: "1.5.0", description: "JSON" },
  18568. { value: "graphql", since: "1.5.0", description: "GraphQL" },
  18569. { value: "markdown", since: "1.8.0", description: "Markdown" },
  18570. { value: "vue", since: "1.10.0", description: "Vue" }
  18571. ]
  18572. },
  18573. plugins: {
  18574. since: "1.10.0",
  18575. type: "path",
  18576. array: true,
  18577. default: [{ value: [] }],
  18578. category: CATEGORY_GLOBAL,
  18579. description:
  18580. "Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
  18581. exception: value => typeof value === "string" || typeof value === "object",
  18582. cliName: "plugin",
  18583. cliCategory: constant.CATEGORY_CONFIG
  18584. },
  18585. printWidth: {
  18586. since: "0.0.0",
  18587. category: CATEGORY_GLOBAL,
  18588. type: "int",
  18589. default: 80,
  18590. description: "The line length where Prettier will try wrap.",
  18591. range: { start: 0, end: Infinity, step: 1 }
  18592. },
  18593. rangeEnd: {
  18594. since: "1.4.0",
  18595. category: CATEGORY_SPECIAL,
  18596. type: "int",
  18597. default: Infinity,
  18598. range: { start: 0, end: Infinity, step: 1 },
  18599. description: dedent_1`
  18600. Format code ending at a given character offset (exclusive).
  18601. The range will extend forwards to the end of the selected statement.
  18602. This option cannot be used with --cursor-offset.
  18603. `,
  18604. cliCategory: constant.CATEGORY_EDITOR
  18605. },
  18606. rangeStart: {
  18607. since: "1.4.0",
  18608. category: CATEGORY_SPECIAL,
  18609. type: "int",
  18610. default: 0,
  18611. range: { start: 0, end: Infinity, step: 1 },
  18612. description: dedent_1`
  18613. Format code starting at a given character offset.
  18614. The range will extend backwards to the start of the first line containing the selected statement.
  18615. This option cannot be used with --cursor-offset.
  18616. `,
  18617. cliCategory: constant.CATEGORY_EDITOR
  18618. },
  18619. requirePragma: {
  18620. since: "1.7.0",
  18621. category: CATEGORY_SPECIAL,
  18622. type: "boolean",
  18623. default: false,
  18624. description: dedent_1`
  18625. Require either '@prettier' or '@format' to be present in the file's first docblock comment
  18626. in order for it to be formatted.
  18627. `,
  18628. cliCategory: constant.CATEGORY_OTHER
  18629. },
  18630. tabWidth: {
  18631. type: "int",
  18632. category: CATEGORY_GLOBAL,
  18633. default: 2,
  18634. description: "Number of spaces per indentation level.",
  18635. range: { start: 0, end: Infinity, step: 1 }
  18636. },
  18637. useFlowParser: {
  18638. since: "0.0.0",
  18639. category: CATEGORY_GLOBAL,
  18640. type: "boolean",
  18641. default: false,
  18642. deprecated: "0.0.10",
  18643. description: "Use flow parser.",
  18644. redirect: { option: "parser", value: "flow" },
  18645. cliName: "flow-parser"
  18646. },
  18647. useTabs: {
  18648. since: "1.0.0",
  18649. category: CATEGORY_GLOBAL,
  18650. type: "boolean",
  18651. default: false,
  18652. description: "Indent with tabs instead of spaces."
  18653. }
  18654. };
  18655. function getSupportInfo$1(version, opts) {
  18656. opts = Object.assign(
  18657. {
  18658. plugins: [],
  18659. pluginsLoaded: false,
  18660. showUnreleased: false,
  18661. showDeprecated: false,
  18662. showInternal: false
  18663. },
  18664. opts
  18665. );
  18666. if (!version) {
  18667. version = currentVersion;
  18668. }
  18669. const plugins = opts.pluginsLoaded ? opts.plugins : loadPlugins_1(opts.plugins);
  18670. const options = util$1
  18671. .arrayify(
  18672. Object.assign(
  18673. plugins.reduce(
  18674. (currentOptions, plugin) =>
  18675. Object.assign(currentOptions, plugin.options),
  18676. {}
  18677. ),
  18678. supportOptions
  18679. ),
  18680. "name"
  18681. )
  18682. .sort((a, b) => (a.name === b.name ? 0 : a.name < b.name ? -1 : 1))
  18683. .filter(filterSince)
  18684. .filter(filterDeprecated)
  18685. .map(mapDeprecated)
  18686. .map(mapInternal)
  18687. .map(option => {
  18688. const newOption = Object.assign({}, option);
  18689. if (Array.isArray(newOption.default)) {
  18690. newOption.default =
  18691. newOption.default.length === 1
  18692. ? newOption.default[0].value
  18693. : newOption.default
  18694. .filter(filterSince)
  18695. .sort((info1, info2) =>
  18696. semver.compare(info2.since, info1.since)
  18697. )[0].value;
  18698. }
  18699. if (Array.isArray(newOption.choices)) {
  18700. newOption.choices = newOption.choices
  18701. .filter(filterSince)
  18702. .filter(filterDeprecated)
  18703. .map(mapDeprecated);
  18704. }
  18705. return newOption;
  18706. })
  18707. .map(option => {
  18708. const filteredPlugins = plugins.filter(
  18709. plugin => plugin.defaultOptions && plugin.defaultOptions[option.name]
  18710. );
  18711. const pluginDefaults = filteredPlugins.reduce((reduced, plugin) => {
  18712. reduced[plugin.name] = plugin.defaultOptions[option.name];
  18713. return reduced;
  18714. }, {});
  18715. return Object.assign(option, { pluginDefaults });
  18716. });
  18717. const usePostCssParser = semver.lt(version, "1.7.1");
  18718. const languages = plugins
  18719. .reduce((all, plugin) => all.concat(plugin.languages), [])
  18720. .filter(
  18721. language =>
  18722. language.since
  18723. ? semver.gte(version, language.since)
  18724. : language.since !== null
  18725. )
  18726. .map(language => {
  18727. // Prevent breaking changes
  18728. if (language.name === "Markdown") {
  18729. return Object.assign({}, language, {
  18730. parsers: ["markdown"]
  18731. });
  18732. }
  18733. if (language.name === "TypeScript") {
  18734. return Object.assign({}, language, {
  18735. parsers: ["typescript"]
  18736. });
  18737. }
  18738. if (usePostCssParser && language.group === "CSS") {
  18739. return Object.assign({}, language, {
  18740. parsers: ["postcss"]
  18741. });
  18742. }
  18743. return language;
  18744. });
  18745. return { languages, options };
  18746. function filterSince(object) {
  18747. return (
  18748. opts.showUnreleased ||
  18749. !("since" in object) ||
  18750. (object.since && semver.gte(version, object.since))
  18751. );
  18752. }
  18753. function filterDeprecated(object) {
  18754. return (
  18755. opts.showDeprecated ||
  18756. !("deprecated" in object) ||
  18757. (object.deprecated && semver.lt(version, object.deprecated))
  18758. );
  18759. }
  18760. function mapDeprecated(object) {
  18761. if (!object.deprecated || opts.showDeprecated) {
  18762. return object;
  18763. }
  18764. const newObject = Object.assign({}, object);
  18765. delete newObject.deprecated;
  18766. delete newObject.redirect;
  18767. return newObject;
  18768. }
  18769. function mapInternal(object) {
  18770. if (opts.showInternal) {
  18771. return object;
  18772. }
  18773. const newObject = Object.assign({}, object);
  18774. delete newObject.cliName;
  18775. delete newObject.cliCategory;
  18776. delete newObject.cliDescription;
  18777. return newObject;
  18778. }
  18779. }
  18780. var support = {
  18781. getSupportInfo: getSupportInfo$1
  18782. };
  18783. function FastPath(value) {
  18784. assert.ok(this instanceof FastPath);
  18785. this.stack = [value];
  18786. }
  18787. // The name of the current property is always the penultimate element of
  18788. // this.stack, and always a String.
  18789. FastPath.prototype.getName = function getName() {
  18790. const s = this.stack;
  18791. const len = s.length;
  18792. if (len > 1) {
  18793. return s[len - 2];
  18794. }
  18795. // Since the name is always a string, null is a safe sentinel value to
  18796. // return if we do not know the name of the (root) value.
  18797. /* istanbul ignore next */
  18798. return null;
  18799. };
  18800. // The value of the current property is always the final element of
  18801. // this.stack.
  18802. FastPath.prototype.getValue = function getValue() {
  18803. const s = this.stack;
  18804. return s[s.length - 1];
  18805. };
  18806. function getNodeHelper(path$$1, count) {
  18807. const s = path$$1.stack;
  18808. for (let i = s.length - 1; i >= 0; i -= 2) {
  18809. const value = s[i];
  18810. if (value && !Array.isArray(value) && --count < 0) {
  18811. return value;
  18812. }
  18813. }
  18814. return null;
  18815. }
  18816. FastPath.prototype.getNode = function getNode(count) {
  18817. return getNodeHelper(this, ~~count);
  18818. };
  18819. FastPath.prototype.getParentNode = function getParentNode(count) {
  18820. return getNodeHelper(this, ~~count + 1);
  18821. };
  18822. // Temporarily push properties named by string arguments given after the
  18823. // callback function onto this.stack, then call the callback with a
  18824. // reference to this (modified) FastPath object. Note that the stack will
  18825. // be restored to its original state after the callback is finished, so it
  18826. // is probably a mistake to retain a reference to the path.
  18827. FastPath.prototype.call = function call(callback /*, name1, name2, ... */) {
  18828. const s = this.stack;
  18829. const origLen = s.length;
  18830. let value = s[origLen - 1];
  18831. const argc = arguments.length;
  18832. for (let i = 1; i < argc; ++i) {
  18833. const name = arguments[i];
  18834. value = value[name];
  18835. s.push(name, value);
  18836. }
  18837. const result = callback(this);
  18838. s.length = origLen;
  18839. return result;
  18840. };
  18841. // Similar to FastPath.prototype.call, except that the value obtained by
  18842. // accessing this.getValue()[name1][name2]... should be array-like. The
  18843. // callback will be called with a reference to this path object for each
  18844. // element of the array.
  18845. FastPath.prototype.each = function each(callback /*, name1, name2, ... */) {
  18846. const s = this.stack;
  18847. const origLen = s.length;
  18848. let value = s[origLen - 1];
  18849. const argc = arguments.length;
  18850. for (let i = 1; i < argc; ++i) {
  18851. const name = arguments[i];
  18852. value = value[name];
  18853. s.push(name, value);
  18854. }
  18855. for (let i = 0; i < value.length; ++i) {
  18856. if (i in value) {
  18857. s.push(i, value[i]);
  18858. // If the callback needs to know the value of i, call
  18859. // path.getName(), assuming path is the parameter name.
  18860. callback(this);
  18861. s.length -= 2;
  18862. }
  18863. }
  18864. s.length = origLen;
  18865. };
  18866. // Similar to FastPath.prototype.each, except that the results of the
  18867. // callback function invocations are stored in an array and returned at
  18868. // the end of the iteration.
  18869. FastPath.prototype.map = function map(callback /*, name1, name2, ... */) {
  18870. const s = this.stack;
  18871. const origLen = s.length;
  18872. let value = s[origLen - 1];
  18873. const argc = arguments.length;
  18874. for (let i = 1; i < argc; ++i) {
  18875. const name = arguments[i];
  18876. value = value[name];
  18877. s.push(name, value);
  18878. }
  18879. const result = new Array(value.length);
  18880. for (let i = 0; i < value.length; ++i) {
  18881. if (i in value) {
  18882. s.push(i, value[i]);
  18883. result[i] = callback(this, i);
  18884. s.length -= 2;
  18885. }
  18886. }
  18887. s.length = origLen;
  18888. return result;
  18889. };
  18890. var fastPath = FastPath;
  18891. /* eslint-disable no-nested-ternary */
  18892. var arr = [];
  18893. var charCodeCache = [];
  18894. var leven = function (a, b) {
  18895. if (a === b) {
  18896. return 0;
  18897. }
  18898. var swap = a;
  18899. // Swapping the strings if `a` is longer than `b` so we know which one is the
  18900. // shortest & which one is the longest
  18901. if (a.length > b.length) {
  18902. a = b;
  18903. b = swap;
  18904. }
  18905. var aLen = a.length;
  18906. var bLen = b.length;
  18907. if (aLen === 0) {
  18908. return bLen;
  18909. }
  18910. if (bLen === 0) {
  18911. return aLen;
  18912. }
  18913. // Performing suffix trimming:
  18914. // We can linearly drop suffix common to both strings since they
  18915. // don't increase distance at all
  18916. // Note: `~-` is the bitwise way to perform a `- 1` operation
  18917. while (aLen > 0 && (a.charCodeAt(~-aLen) === b.charCodeAt(~-bLen))) {
  18918. aLen--;
  18919. bLen--;
  18920. }
  18921. if (aLen === 0) {
  18922. return bLen;
  18923. }
  18924. // Performing prefix trimming
  18925. // We can linearly drop prefix common to both strings since they
  18926. // don't increase distance at all
  18927. var start = 0;
  18928. while (start < aLen && (a.charCodeAt(start) === b.charCodeAt(start))) {
  18929. start++;
  18930. }
  18931. aLen -= start;
  18932. bLen -= start;
  18933. if (aLen === 0) {
  18934. return bLen;
  18935. }
  18936. var bCharCode;
  18937. var ret;
  18938. var tmp;
  18939. var tmp2;
  18940. var i = 0;
  18941. var j = 0;
  18942. while (i < aLen) {
  18943. charCodeCache[start + i] = a.charCodeAt(start + i);
  18944. arr[i] = ++i;
  18945. }
  18946. while (j < bLen) {
  18947. bCharCode = b.charCodeAt(start + j);
  18948. tmp = j++;
  18949. ret = j;
  18950. for (i = 0; i < aLen; i++) {
  18951. tmp2 = bCharCode === charCodeCache[start + i] ? tmp : tmp + 1;
  18952. tmp = arr[i];
  18953. ret = arr[i] = tmp > ret ? tmp2 > ret ? ret + 1 : tmp2 : tmp2 > tmp ? tmp + 1 : tmp2;
  18954. }
  18955. }
  18956. return ret;
  18957. };
  18958. function apiDescriptor(name, value) {
  18959. return arguments.length === 1
  18960. ? JSON.stringify(name)
  18961. : `\`{ ${apiDescriptor(name)}: ${JSON.stringify(value)} }\``;
  18962. }
  18963. function cliDescriptor(name, value) {
  18964. return value === false
  18965. ? `\`--no-${name}\``
  18966. : value === true || arguments.length === 1
  18967. ? `\`--${name}\``
  18968. : value === ""
  18969. ? `\`--${name}\` without an argument`
  18970. : `\`--${name}=${value}\``;
  18971. }
  18972. var optionsDescriptor = {
  18973. apiDescriptor,
  18974. cliDescriptor
  18975. };
  18976. function validateOption(value, optionInfo, opts) {
  18977. opts = opts || {};
  18978. const descriptor = opts.descriptor || optionsDescriptor.apiDescriptor;
  18979. if (
  18980. typeof optionInfo.exception === "function" &&
  18981. optionInfo.exception(value)
  18982. ) {
  18983. return;
  18984. }
  18985. try {
  18986. validateOptionType(value, optionInfo);
  18987. } catch (error) {
  18988. throw new Error(
  18989. `Invalid \`${descriptor(optionInfo.name)}\` value. ${
  18990. error.message
  18991. }, but received \`${JSON.stringify(value)}\`.`
  18992. );
  18993. }
  18994. }
  18995. function validateOptionType(value, optionInfo) {
  18996. if (optionInfo.array) {
  18997. if (!Array.isArray(value)) {
  18998. throw new Error(`Expected an array`);
  18999. }
  19000. value.forEach(v =>
  19001. validateOptionType(v, Object.assign({}, optionInfo, { array: false }))
  19002. );
  19003. } else {
  19004. switch (optionInfo.type) {
  19005. case "int":
  19006. validateIntOption(value);
  19007. break;
  19008. case "boolean":
  19009. validateBooleanOption(value);
  19010. break;
  19011. case "choice":
  19012. validateChoiceOption(value, optionInfo.choices);
  19013. break;
  19014. }
  19015. }
  19016. }
  19017. function validateBooleanOption(value) {
  19018. if (typeof value !== "boolean") {
  19019. throw new Error(`Expected a boolean`);
  19020. }
  19021. }
  19022. function validateIntOption(value) {
  19023. if (
  19024. !(
  19025. typeof value === "number" &&
  19026. Math.floor(value) === value &&
  19027. value >= 0 &&
  19028. value !== Infinity
  19029. )
  19030. ) {
  19031. throw new Error(`Expected an integer`);
  19032. }
  19033. }
  19034. function validateChoiceOption(value, choiceInfos) {
  19035. if (!choiceInfos.some(choiceInfo => choiceInfo.value === value)) {
  19036. const choices = choiceInfos
  19037. .filter(choiceInfo => !choiceInfo.deprecated)
  19038. .map(choiceInfo => JSON.stringify(choiceInfo.value))
  19039. .sort();
  19040. const head = choices.slice(0, -2);
  19041. const tail = choices.slice(-2);
  19042. throw new Error(`Expected ${head.concat(tail.join(" or ")).join(", ")}`);
  19043. }
  19044. }
  19045. var optionsValidator = { validateOption };
  19046. function normalizeOptions$1(options, optionInfos, opts) {
  19047. opts = opts || {};
  19048. const logger =
  19049. opts.logger === false
  19050. ? { warn() {} }
  19051. : opts.logger !== undefined
  19052. ? opts.logger
  19053. : console;
  19054. const descriptor = opts.descriptor || optionsDescriptor.apiDescriptor;
  19055. const passThrough = opts.passThrough || [];
  19056. const optionInfoMap = optionInfos.reduce(
  19057. (reduced, optionInfo) =>
  19058. Object.assign(reduced, { [optionInfo.name]: optionInfo }),
  19059. {}
  19060. );
  19061. const normalizedOptions = Object.keys(options).reduce((newOptions, key) => {
  19062. const optionInfo = optionInfoMap[key];
  19063. let optionName = key;
  19064. let optionValue = options[key];
  19065. if (!optionInfo) {
  19066. if (passThrough === true || passThrough.indexOf(optionName) !== -1) {
  19067. newOptions[optionName] = optionValue;
  19068. } else {
  19069. logger.warn(
  19070. createUnknownOptionMessage(
  19071. optionName,
  19072. optionValue,
  19073. optionInfos,
  19074. descriptor
  19075. )
  19076. );
  19077. }
  19078. return newOptions;
  19079. }
  19080. if (!optionInfo.deprecated) {
  19081. optionValue = normalizeOption(optionValue, optionInfo);
  19082. } else if (typeof optionInfo.redirect === "string") {
  19083. logger.warn(createRedirectOptionMessage(optionInfo, descriptor));
  19084. optionName = optionInfo.redirect;
  19085. } else if (optionValue) {
  19086. logger.warn(createRedirectOptionMessage(optionInfo, descriptor));
  19087. optionValue = optionInfo.redirect.value;
  19088. optionName = optionInfo.redirect.option;
  19089. }
  19090. if (optionInfo.choices) {
  19091. const choiceInfo = optionInfo.choices.find(
  19092. choice => choice.value === optionValue
  19093. );
  19094. if (choiceInfo && choiceInfo.deprecated) {
  19095. logger.warn(
  19096. createRedirectChoiceMessage(optionInfo, choiceInfo, descriptor)
  19097. );
  19098. optionValue = choiceInfo.redirect;
  19099. }
  19100. }
  19101. if (optionInfo.array && !Array.isArray(optionValue)) {
  19102. optionValue = [optionValue];
  19103. }
  19104. if (optionValue !== optionInfo.default) {
  19105. optionsValidator.validateOption(optionValue, optionInfoMap[optionName], {
  19106. descriptor
  19107. });
  19108. }
  19109. newOptions[optionName] = optionValue;
  19110. return newOptions;
  19111. }, {});
  19112. return normalizedOptions;
  19113. }
  19114. function normalizeOption(option, optionInfo) {
  19115. return optionInfo.type === "int" ? Number(option) : option;
  19116. }
  19117. function createUnknownOptionMessage(key, value, optionInfos, descriptor) {
  19118. const messages = [`Ignored unknown option ${descriptor(key, value)}.`];
  19119. const suggestedOptionInfo = optionInfos.find(
  19120. optionInfo => leven(optionInfo.name, key) < 3
  19121. );
  19122. if (suggestedOptionInfo) {
  19123. messages.push(`Did you mean ${JSON.stringify(suggestedOptionInfo.name)}?`);
  19124. }
  19125. return messages.join(" ");
  19126. }
  19127. function createRedirectOptionMessage(optionInfo, descriptor) {
  19128. return `${descriptor(
  19129. optionInfo.name
  19130. )} is deprecated. Prettier now treats it as ${
  19131. typeof optionInfo.redirect === "string"
  19132. ? descriptor(optionInfo.redirect)
  19133. : descriptor(optionInfo.redirect.option, optionInfo.redirect.value)
  19134. }.`;
  19135. }
  19136. function createRedirectChoiceMessage(optionInfo, choiceInfo, descriptor) {
  19137. return `${descriptor(
  19138. optionInfo.name,
  19139. choiceInfo.value
  19140. )} is deprecated. Prettier now treats it as ${descriptor(
  19141. optionInfo.name,
  19142. choiceInfo.redirect
  19143. )}.`;
  19144. }
  19145. function normalizeApiOptions(options, optionInfos, opts) {
  19146. return normalizeOptions$1(
  19147. options,
  19148. optionInfos,
  19149. Object.assign({ descriptor: optionsDescriptor.apiDescriptor }, opts)
  19150. );
  19151. }
  19152. function normalizeCliOptions(options, optionInfos, opts) {
  19153. const args = options["_"] || [];
  19154. const newOptions = normalizeOptions$1(
  19155. Object.keys(options).reduce(
  19156. (reduced, key) =>
  19157. Object.assign(
  19158. reduced,
  19159. key.length === 1 // omit alias
  19160. ? null
  19161. : { [key]: options[key] }
  19162. ),
  19163. {}
  19164. ),
  19165. optionInfos,
  19166. Object.assign({ descriptor: optionsDescriptor.cliDescriptor }, opts)
  19167. );
  19168. newOptions["_"] = args;
  19169. return newOptions;
  19170. }
  19171. var optionsNormalizer = {
  19172. normalizeApiOptions,
  19173. normalizeCliOptions
  19174. };
  19175. class ConfigError$1 extends Error {}
  19176. class DebugError extends Error {}
  19177. var errors = {
  19178. ConfigError: ConfigError$1,
  19179. DebugError
  19180. };
  19181. var jsTokens = createCommonjsModule(function (module, exports) {
  19182. // Copyright 2014, 2015, 2016, 2017 Simon Lydell
  19183. // License: MIT. (See LICENSE.)
  19184. Object.defineProperty(exports, "__esModule", {
  19185. value: true
  19186. });
  19187. // This regex comes from regex.coffee, and is inserted here by generate-index.js
  19188. // (run `npm run build`).
  19189. 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;
  19190. exports.matchToToken = function(match) {
  19191. var token = {type: "invalid", value: match[0]};
  19192. if (match[ 1]) token.type = "string" , token.closed = !!(match[3] || match[4]);
  19193. else if (match[ 5]) token.type = "comment";
  19194. else if (match[ 6]) token.type = "comment", token.closed = !!match[7];
  19195. else if (match[ 8]) token.type = "regex";
  19196. else if (match[ 9]) token.type = "number";
  19197. else if (match[10]) token.type = "name";
  19198. else if (match[11]) token.type = "punctuator";
  19199. else if (match[12]) token.type = "whitespace";
  19200. return token
  19201. };
  19202. });
  19203. unwrapExports(jsTokens);
  19204. var colorName = {
  19205. "aliceblue": [240, 248, 255],
  19206. "antiquewhite": [250, 235, 215],
  19207. "aqua": [0, 255, 255],
  19208. "aquamarine": [127, 255, 212],
  19209. "azure": [240, 255, 255],
  19210. "beige": [245, 245, 220],
  19211. "bisque": [255, 228, 196],
  19212. "black": [0, 0, 0],
  19213. "blanchedalmond": [255, 235, 205],
  19214. "blue": [0, 0, 255],
  19215. "blueviolet": [138, 43, 226],
  19216. "brown": [165, 42, 42],
  19217. "burlywood": [222, 184, 135],
  19218. "cadetblue": [95, 158, 160],
  19219. "chartreuse": [127, 255, 0],
  19220. "chocolate": [210, 105, 30],
  19221. "coral": [255, 127, 80],
  19222. "cornflowerblue": [100, 149, 237],
  19223. "cornsilk": [255, 248, 220],
  19224. "crimson": [220, 20, 60],
  19225. "cyan": [0, 255, 255],
  19226. "darkblue": [0, 0, 139],
  19227. "darkcyan": [0, 139, 139],
  19228. "darkgoldenrod": [184, 134, 11],
  19229. "darkgray": [169, 169, 169],
  19230. "darkgreen": [0, 100, 0],
  19231. "darkgrey": [169, 169, 169],
  19232. "darkkhaki": [189, 183, 107],
  19233. "darkmagenta": [139, 0, 139],
  19234. "darkolivegreen": [85, 107, 47],
  19235. "darkorange": [255, 140, 0],
  19236. "darkorchid": [153, 50, 204],
  19237. "darkred": [139, 0, 0],
  19238. "darksalmon": [233, 150, 122],
  19239. "darkseagreen": [143, 188, 143],
  19240. "darkslateblue": [72, 61, 139],
  19241. "darkslategray": [47, 79, 79],
  19242. "darkslategrey": [47, 79, 79],
  19243. "darkturquoise": [0, 206, 209],
  19244. "darkviolet": [148, 0, 211],
  19245. "deeppink": [255, 20, 147],
  19246. "deepskyblue": [0, 191, 255],
  19247. "dimgray": [105, 105, 105],
  19248. "dimgrey": [105, 105, 105],
  19249. "dodgerblue": [30, 144, 255],
  19250. "firebrick": [178, 34, 34],
  19251. "floralwhite": [255, 250, 240],
  19252. "forestgreen": [34, 139, 34],
  19253. "fuchsia": [255, 0, 255],
  19254. "gainsboro": [220, 220, 220],
  19255. "ghostwhite": [248, 248, 255],
  19256. "gold": [255, 215, 0],
  19257. "goldenrod": [218, 165, 32],
  19258. "gray": [128, 128, 128],
  19259. "green": [0, 128, 0],
  19260. "greenyellow": [173, 255, 47],
  19261. "grey": [128, 128, 128],
  19262. "honeydew": [240, 255, 240],
  19263. "hotpink": [255, 105, 180],
  19264. "indianred": [205, 92, 92],
  19265. "indigo": [75, 0, 130],
  19266. "ivory": [255, 255, 240],
  19267. "khaki": [240, 230, 140],
  19268. "lavender": [230, 230, 250],
  19269. "lavenderblush": [255, 240, 245],
  19270. "lawngreen": [124, 252, 0],
  19271. "lemonchiffon": [255, 250, 205],
  19272. "lightblue": [173, 216, 230],
  19273. "lightcoral": [240, 128, 128],
  19274. "lightcyan": [224, 255, 255],
  19275. "lightgoldenrodyellow": [250, 250, 210],
  19276. "lightgray": [211, 211, 211],
  19277. "lightgreen": [144, 238, 144],
  19278. "lightgrey": [211, 211, 211],
  19279. "lightpink": [255, 182, 193],
  19280. "lightsalmon": [255, 160, 122],
  19281. "lightseagreen": [32, 178, 170],
  19282. "lightskyblue": [135, 206, 250],
  19283. "lightslategray": [119, 136, 153],
  19284. "lightslategrey": [119, 136, 153],
  19285. "lightsteelblue": [176, 196, 222],
  19286. "lightyellow": [255, 255, 224],
  19287. "lime": [0, 255, 0],
  19288. "limegreen": [50, 205, 50],
  19289. "linen": [250, 240, 230],
  19290. "magenta": [255, 0, 255],
  19291. "maroon": [128, 0, 0],
  19292. "mediumaquamarine": [102, 205, 170],
  19293. "mediumblue": [0, 0, 205],
  19294. "mediumorchid": [186, 85, 211],
  19295. "mediumpurple": [147, 112, 219],
  19296. "mediumseagreen": [60, 179, 113],
  19297. "mediumslateblue": [123, 104, 238],
  19298. "mediumspringgreen": [0, 250, 154],
  19299. "mediumturquoise": [72, 209, 204],
  19300. "mediumvioletred": [199, 21, 133],
  19301. "midnightblue": [25, 25, 112],
  19302. "mintcream": [245, 255, 250],
  19303. "mistyrose": [255, 228, 225],
  19304. "moccasin": [255, 228, 181],
  19305. "navajowhite": [255, 222, 173],
  19306. "navy": [0, 0, 128],
  19307. "oldlace": [253, 245, 230],
  19308. "olive": [128, 128, 0],
  19309. "olivedrab": [107, 142, 35],
  19310. "orange": [255, 165, 0],
  19311. "orangered": [255, 69, 0],
  19312. "orchid": [218, 112, 214],
  19313. "palegoldenrod": [238, 232, 170],
  19314. "palegreen": [152, 251, 152],
  19315. "paleturquoise": [175, 238, 238],
  19316. "palevioletred": [219, 112, 147],
  19317. "papayawhip": [255, 239, 213],
  19318. "peachpuff": [255, 218, 185],
  19319. "peru": [205, 133, 63],
  19320. "pink": [255, 192, 203],
  19321. "plum": [221, 160, 221],
  19322. "powderblue": [176, 224, 230],
  19323. "purple": [128, 0, 128],
  19324. "rebeccapurple": [102, 51, 153],
  19325. "red": [255, 0, 0],
  19326. "rosybrown": [188, 143, 143],
  19327. "royalblue": [65, 105, 225],
  19328. "saddlebrown": [139, 69, 19],
  19329. "salmon": [250, 128, 114],
  19330. "sandybrown": [244, 164, 96],
  19331. "seagreen": [46, 139, 87],
  19332. "seashell": [255, 245, 238],
  19333. "sienna": [160, 82, 45],
  19334. "silver": [192, 192, 192],
  19335. "skyblue": [135, 206, 235],
  19336. "slateblue": [106, 90, 205],
  19337. "slategray": [112, 128, 144],
  19338. "slategrey": [112, 128, 144],
  19339. "snow": [255, 250, 250],
  19340. "springgreen": [0, 255, 127],
  19341. "steelblue": [70, 130, 180],
  19342. "tan": [210, 180, 140],
  19343. "teal": [0, 128, 128],
  19344. "thistle": [216, 191, 216],
  19345. "tomato": [255, 99, 71],
  19346. "turquoise": [64, 224, 208],
  19347. "violet": [238, 130, 238],
  19348. "wheat": [245, 222, 179],
  19349. "white": [255, 255, 255],
  19350. "whitesmoke": [245, 245, 245],
  19351. "yellow": [255, 255, 0],
  19352. "yellowgreen": [154, 205, 50]
  19353. };
  19354. var conversions = createCommonjsModule(function (module) {
  19355. /* MIT license */
  19356. // NOTE: conversions should only return primitive values (i.e. arrays, or
  19357. // values that give correct `typeof` results).
  19358. // do not use box values types (i.e. Number(), String(), etc.)
  19359. var reverseKeywords = {};
  19360. for (var key in colorName) {
  19361. if (colorName.hasOwnProperty(key)) {
  19362. reverseKeywords[colorName[key]] = key;
  19363. }
  19364. }
  19365. var convert = module.exports = {
  19366. rgb: {channels: 3, labels: 'rgb'},
  19367. hsl: {channels: 3, labels: 'hsl'},
  19368. hsv: {channels: 3, labels: 'hsv'},
  19369. hwb: {channels: 3, labels: 'hwb'},
  19370. cmyk: {channels: 4, labels: 'cmyk'},
  19371. xyz: {channels: 3, labels: 'xyz'},
  19372. lab: {channels: 3, labels: 'lab'},
  19373. lch: {channels: 3, labels: 'lch'},
  19374. hex: {channels: 1, labels: ['hex']},
  19375. keyword: {channels: 1, labels: ['keyword']},
  19376. ansi16: {channels: 1, labels: ['ansi16']},
  19377. ansi256: {channels: 1, labels: ['ansi256']},
  19378. hcg: {channels: 3, labels: ['h', 'c', 'g']},
  19379. apple: {channels: 3, labels: ['r16', 'g16', 'b16']},
  19380. gray: {channels: 1, labels: ['gray']}
  19381. };
  19382. // hide .channels and .labels properties
  19383. for (var model in convert) {
  19384. if (convert.hasOwnProperty(model)) {
  19385. if (!('channels' in convert[model])) {
  19386. throw new Error('missing channels property: ' + model);
  19387. }
  19388. if (!('labels' in convert[model])) {
  19389. throw new Error('missing channel labels property: ' + model);
  19390. }
  19391. if (convert[model].labels.length !== convert[model].channels) {
  19392. throw new Error('channel and label counts mismatch: ' + model);
  19393. }
  19394. var channels = convert[model].channels;
  19395. var labels = convert[model].labels;
  19396. delete convert[model].channels;
  19397. delete convert[model].labels;
  19398. Object.defineProperty(convert[model], 'channels', {value: channels});
  19399. Object.defineProperty(convert[model], 'labels', {value: labels});
  19400. }
  19401. }
  19402. convert.rgb.hsl = function (rgb) {
  19403. var r = rgb[0] / 255;
  19404. var g = rgb[1] / 255;
  19405. var b = rgb[2] / 255;
  19406. var min = Math.min(r, g, b);
  19407. var max = Math.max(r, g, b);
  19408. var delta = max - min;
  19409. var h;
  19410. var s;
  19411. var l;
  19412. if (max === min) {
  19413. h = 0;
  19414. } else if (r === max) {
  19415. h = (g - b) / delta;
  19416. } else if (g === max) {
  19417. h = 2 + (b - r) / delta;
  19418. } else if (b === max) {
  19419. h = 4 + (r - g) / delta;
  19420. }
  19421. h = Math.min(h * 60, 360);
  19422. if (h < 0) {
  19423. h += 360;
  19424. }
  19425. l = (min + max) / 2;
  19426. if (max === min) {
  19427. s = 0;
  19428. } else if (l <= 0.5) {
  19429. s = delta / (max + min);
  19430. } else {
  19431. s = delta / (2 - max - min);
  19432. }
  19433. return [h, s * 100, l * 100];
  19434. };
  19435. convert.rgb.hsv = function (rgb) {
  19436. var r = rgb[0];
  19437. var g = rgb[1];
  19438. var b = rgb[2];
  19439. var min = Math.min(r, g, b);
  19440. var max = Math.max(r, g, b);
  19441. var delta = max - min;
  19442. var h;
  19443. var s;
  19444. var v;
  19445. if (max === 0) {
  19446. s = 0;
  19447. } else {
  19448. s = (delta / max * 1000) / 10;
  19449. }
  19450. if (max === min) {
  19451. h = 0;
  19452. } else if (r === max) {
  19453. h = (g - b) / delta;
  19454. } else if (g === max) {
  19455. h = 2 + (b - r) / delta;
  19456. } else if (b === max) {
  19457. h = 4 + (r - g) / delta;
  19458. }
  19459. h = Math.min(h * 60, 360);
  19460. if (h < 0) {
  19461. h += 360;
  19462. }
  19463. v = ((max / 255) * 1000) / 10;
  19464. return [h, s, v];
  19465. };
  19466. convert.rgb.hwb = function (rgb) {
  19467. var r = rgb[0];
  19468. var g = rgb[1];
  19469. var b = rgb[2];
  19470. var h = convert.rgb.hsl(rgb)[0];
  19471. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  19472. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  19473. return [h, w * 100, b * 100];
  19474. };
  19475. convert.rgb.cmyk = function (rgb) {
  19476. var r = rgb[0] / 255;
  19477. var g = rgb[1] / 255;
  19478. var b = rgb[2] / 255;
  19479. var c;
  19480. var m;
  19481. var y;
  19482. var k;
  19483. k = Math.min(1 - r, 1 - g, 1 - b);
  19484. c = (1 - r - k) / (1 - k) || 0;
  19485. m = (1 - g - k) / (1 - k) || 0;
  19486. y = (1 - b - k) / (1 - k) || 0;
  19487. return [c * 100, m * 100, y * 100, k * 100];
  19488. };
  19489. /**
  19490. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  19491. * */
  19492. function comparativeDistance(x, y) {
  19493. return (
  19494. Math.pow(x[0] - y[0], 2) +
  19495. Math.pow(x[1] - y[1], 2) +
  19496. Math.pow(x[2] - y[2], 2)
  19497. );
  19498. }
  19499. convert.rgb.keyword = function (rgb) {
  19500. var reversed = reverseKeywords[rgb];
  19501. if (reversed) {
  19502. return reversed;
  19503. }
  19504. var currentClosestDistance = Infinity;
  19505. var currentClosestKeyword;
  19506. for (var keyword in colorName) {
  19507. if (colorName.hasOwnProperty(keyword)) {
  19508. var value = colorName[keyword];
  19509. // Compute comparative distance
  19510. var distance = comparativeDistance(rgb, value);
  19511. // Check if its less, if so set as closest
  19512. if (distance < currentClosestDistance) {
  19513. currentClosestDistance = distance;
  19514. currentClosestKeyword = keyword;
  19515. }
  19516. }
  19517. }
  19518. return currentClosestKeyword;
  19519. };
  19520. convert.keyword.rgb = function (keyword) {
  19521. return colorName[keyword];
  19522. };
  19523. convert.rgb.xyz = function (rgb) {
  19524. var r = rgb[0] / 255;
  19525. var g = rgb[1] / 255;
  19526. var b = rgb[2] / 255;
  19527. // assume sRGB
  19528. r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
  19529. g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
  19530. b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
  19531. var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
  19532. var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
  19533. var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
  19534. return [x * 100, y * 100, z * 100];
  19535. };
  19536. convert.rgb.lab = function (rgb) {
  19537. var xyz = convert.rgb.xyz(rgb);
  19538. var x = xyz[0];
  19539. var y = xyz[1];
  19540. var z = xyz[2];
  19541. var l;
  19542. var a;
  19543. var b;
  19544. x /= 95.047;
  19545. y /= 100;
  19546. z /= 108.883;
  19547. x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116);
  19548. y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116);
  19549. z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116);
  19550. l = (116 * y) - 16;
  19551. a = 500 * (x - y);
  19552. b = 200 * (y - z);
  19553. return [l, a, b];
  19554. };
  19555. convert.hsl.rgb = function (hsl) {
  19556. var h = hsl[0] / 360;
  19557. var s = hsl[1] / 100;
  19558. var l = hsl[2] / 100;
  19559. var t1;
  19560. var t2;
  19561. var t3;
  19562. var rgb;
  19563. var val;
  19564. if (s === 0) {
  19565. val = l * 255;
  19566. return [val, val, val];
  19567. }
  19568. if (l < 0.5) {
  19569. t2 = l * (1 + s);
  19570. } else {
  19571. t2 = l + s - l * s;
  19572. }
  19573. t1 = 2 * l - t2;
  19574. rgb = [0, 0, 0];
  19575. for (var i = 0; i < 3; i++) {
  19576. t3 = h + 1 / 3 * -(i - 1);
  19577. if (t3 < 0) {
  19578. t3++;
  19579. }
  19580. if (t3 > 1) {
  19581. t3--;
  19582. }
  19583. if (6 * t3 < 1) {
  19584. val = t1 + (t2 - t1) * 6 * t3;
  19585. } else if (2 * t3 < 1) {
  19586. val = t2;
  19587. } else if (3 * t3 < 2) {
  19588. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  19589. } else {
  19590. val = t1;
  19591. }
  19592. rgb[i] = val * 255;
  19593. }
  19594. return rgb;
  19595. };
  19596. convert.hsl.hsv = function (hsl) {
  19597. var h = hsl[0];
  19598. var s = hsl[1] / 100;
  19599. var l = hsl[2] / 100;
  19600. var smin = s;
  19601. var lmin = Math.max(l, 0.01);
  19602. var sv;
  19603. var v;
  19604. l *= 2;
  19605. s *= (l <= 1) ? l : 2 - l;
  19606. smin *= lmin <= 1 ? lmin : 2 - lmin;
  19607. v = (l + s) / 2;
  19608. sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s);
  19609. return [h, sv * 100, v * 100];
  19610. };
  19611. convert.hsv.rgb = function (hsv) {
  19612. var h = hsv[0] / 60;
  19613. var s = hsv[1] / 100;
  19614. var v = hsv[2] / 100;
  19615. var hi = Math.floor(h) % 6;
  19616. var f = h - Math.floor(h);
  19617. var p = 255 * v * (1 - s);
  19618. var q = 255 * v * (1 - (s * f));
  19619. var t = 255 * v * (1 - (s * (1 - f)));
  19620. v *= 255;
  19621. switch (hi) {
  19622. case 0:
  19623. return [v, t, p];
  19624. case 1:
  19625. return [q, v, p];
  19626. case 2:
  19627. return [p, v, t];
  19628. case 3:
  19629. return [p, q, v];
  19630. case 4:
  19631. return [t, p, v];
  19632. case 5:
  19633. return [v, p, q];
  19634. }
  19635. };
  19636. convert.hsv.hsl = function (hsv) {
  19637. var h = hsv[0];
  19638. var s = hsv[1] / 100;
  19639. var v = hsv[2] / 100;
  19640. var vmin = Math.max(v, 0.01);
  19641. var lmin;
  19642. var sl;
  19643. var l;
  19644. l = (2 - s) * v;
  19645. lmin = (2 - s) * vmin;
  19646. sl = s * vmin;
  19647. sl /= (lmin <= 1) ? lmin : 2 - lmin;
  19648. sl = sl || 0;
  19649. l /= 2;
  19650. return [h, sl * 100, l * 100];
  19651. };
  19652. // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  19653. convert.hwb.rgb = function (hwb) {
  19654. var h = hwb[0] / 360;
  19655. var wh = hwb[1] / 100;
  19656. var bl = hwb[2] / 100;
  19657. var ratio = wh + bl;
  19658. var i;
  19659. var v;
  19660. var f;
  19661. var n;
  19662. // wh + bl cant be > 1
  19663. if (ratio > 1) {
  19664. wh /= ratio;
  19665. bl /= ratio;
  19666. }
  19667. i = Math.floor(6 * h);
  19668. v = 1 - bl;
  19669. f = 6 * h - i;
  19670. if ((i & 0x01) !== 0) {
  19671. f = 1 - f;
  19672. }
  19673. n = wh + f * (v - wh); // linear interpolation
  19674. var r;
  19675. var g;
  19676. var b;
  19677. switch (i) {
  19678. default:
  19679. case 6:
  19680. case 0: r = v; g = n; b = wh; break;
  19681. case 1: r = n; g = v; b = wh; break;
  19682. case 2: r = wh; g = v; b = n; break;
  19683. case 3: r = wh; g = n; b = v; break;
  19684. case 4: r = n; g = wh; b = v; break;
  19685. case 5: r = v; g = wh; b = n; break;
  19686. }
  19687. return [r * 255, g * 255, b * 255];
  19688. };
  19689. convert.cmyk.rgb = function (cmyk) {
  19690. var c = cmyk[0] / 100;
  19691. var m = cmyk[1] / 100;
  19692. var y = cmyk[2] / 100;
  19693. var k = cmyk[3] / 100;
  19694. var r;
  19695. var g;
  19696. var b;
  19697. r = 1 - Math.min(1, c * (1 - k) + k);
  19698. g = 1 - Math.min(1, m * (1 - k) + k);
  19699. b = 1 - Math.min(1, y * (1 - k) + k);
  19700. return [r * 255, g * 255, b * 255];
  19701. };
  19702. convert.xyz.rgb = function (xyz) {
  19703. var x = xyz[0] / 100;
  19704. var y = xyz[1] / 100;
  19705. var z = xyz[2] / 100;
  19706. var r;
  19707. var g;
  19708. var b;
  19709. r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
  19710. g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
  19711. b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
  19712. // assume sRGB
  19713. r = r > 0.0031308
  19714. ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
  19715. : r * 12.92;
  19716. g = g > 0.0031308
  19717. ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
  19718. : g * 12.92;
  19719. b = b > 0.0031308
  19720. ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
  19721. : b * 12.92;
  19722. r = Math.min(Math.max(0, r), 1);
  19723. g = Math.min(Math.max(0, g), 1);
  19724. b = Math.min(Math.max(0, b), 1);
  19725. return [r * 255, g * 255, b * 255];
  19726. };
  19727. convert.xyz.lab = function (xyz) {
  19728. var x = xyz[0];
  19729. var y = xyz[1];
  19730. var z = xyz[2];
  19731. var l;
  19732. var a;
  19733. var b;
  19734. x /= 95.047;
  19735. y /= 100;
  19736. z /= 108.883;
  19737. x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116);
  19738. y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116);
  19739. z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116);
  19740. l = (116 * y) - 16;
  19741. a = 500 * (x - y);
  19742. b = 200 * (y - z);
  19743. return [l, a, b];
  19744. };
  19745. convert.lab.xyz = function (lab) {
  19746. var l = lab[0];
  19747. var a = lab[1];
  19748. var b = lab[2];
  19749. var x;
  19750. var y;
  19751. var z;
  19752. y = (l + 16) / 116;
  19753. x = a / 500 + y;
  19754. z = y - b / 200;
  19755. var y2 = Math.pow(y, 3);
  19756. var x2 = Math.pow(x, 3);
  19757. var z2 = Math.pow(z, 3);
  19758. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  19759. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  19760. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  19761. x *= 95.047;
  19762. y *= 100;
  19763. z *= 108.883;
  19764. return [x, y, z];
  19765. };
  19766. convert.lab.lch = function (lab) {
  19767. var l = lab[0];
  19768. var a = lab[1];
  19769. var b = lab[2];
  19770. var hr;
  19771. var h;
  19772. var c;
  19773. hr = Math.atan2(b, a);
  19774. h = hr * 360 / 2 / Math.PI;
  19775. if (h < 0) {
  19776. h += 360;
  19777. }
  19778. c = Math.sqrt(a * a + b * b);
  19779. return [l, c, h];
  19780. };
  19781. convert.lch.lab = function (lch) {
  19782. var l = lch[0];
  19783. var c = lch[1];
  19784. var h = lch[2];
  19785. var a;
  19786. var b;
  19787. var hr;
  19788. hr = h / 360 * 2 * Math.PI;
  19789. a = c * Math.cos(hr);
  19790. b = c * Math.sin(hr);
  19791. return [l, a, b];
  19792. };
  19793. convert.rgb.ansi16 = function (args) {
  19794. var r = args[0];
  19795. var g = args[1];
  19796. var b = args[2];
  19797. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  19798. value = Math.round(value / 50);
  19799. if (value === 0) {
  19800. return 30;
  19801. }
  19802. var ansi = 30
  19803. + ((Math.round(b / 255) << 2)
  19804. | (Math.round(g / 255) << 1)
  19805. | Math.round(r / 255));
  19806. if (value === 2) {
  19807. ansi += 60;
  19808. }
  19809. return ansi;
  19810. };
  19811. convert.hsv.ansi16 = function (args) {
  19812. // optimization here; we already know the value and don't need to get
  19813. // it converted for us.
  19814. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  19815. };
  19816. convert.rgb.ansi256 = function (args) {
  19817. var r = args[0];
  19818. var g = args[1];
  19819. var b = args[2];
  19820. // we use the extended greyscale palette here, with the exception of
  19821. // black and white. normal palette only has 4 greyscale shades.
  19822. if (r === g && g === b) {
  19823. if (r < 8) {
  19824. return 16;
  19825. }
  19826. if (r > 248) {
  19827. return 231;
  19828. }
  19829. return Math.round(((r - 8) / 247) * 24) + 232;
  19830. }
  19831. var ansi = 16
  19832. + (36 * Math.round(r / 255 * 5))
  19833. + (6 * Math.round(g / 255 * 5))
  19834. + Math.round(b / 255 * 5);
  19835. return ansi;
  19836. };
  19837. convert.ansi16.rgb = function (args) {
  19838. var color = args % 10;
  19839. // handle greyscale
  19840. if (color === 0 || color === 7) {
  19841. if (args > 50) {
  19842. color += 3.5;
  19843. }
  19844. color = color / 10.5 * 255;
  19845. return [color, color, color];
  19846. }
  19847. var mult = (~~(args > 50) + 1) * 0.5;
  19848. var r = ((color & 1) * mult) * 255;
  19849. var g = (((color >> 1) & 1) * mult) * 255;
  19850. var b = (((color >> 2) & 1) * mult) * 255;
  19851. return [r, g, b];
  19852. };
  19853. convert.ansi256.rgb = function (args) {
  19854. // handle greyscale
  19855. if (args >= 232) {
  19856. var c = (args - 232) * 10 + 8;
  19857. return [c, c, c];
  19858. }
  19859. args -= 16;
  19860. var rem;
  19861. var r = Math.floor(args / 36) / 5 * 255;
  19862. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  19863. var b = (rem % 6) / 5 * 255;
  19864. return [r, g, b];
  19865. };
  19866. convert.rgb.hex = function (args) {
  19867. var integer = ((Math.round(args[0]) & 0xFF) << 16)
  19868. + ((Math.round(args[1]) & 0xFF) << 8)
  19869. + (Math.round(args[2]) & 0xFF);
  19870. var string = integer.toString(16).toUpperCase();
  19871. return '000000'.substring(string.length) + string;
  19872. };
  19873. convert.hex.rgb = function (args) {
  19874. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  19875. if (!match) {
  19876. return [0, 0, 0];
  19877. }
  19878. var colorString = match[0];
  19879. if (match[0].length === 3) {
  19880. colorString = colorString.split('').map(function (char) {
  19881. return char + char;
  19882. }).join('');
  19883. }
  19884. var integer = parseInt(colorString, 16);
  19885. var r = (integer >> 16) & 0xFF;
  19886. var g = (integer >> 8) & 0xFF;
  19887. var b = integer & 0xFF;
  19888. return [r, g, b];
  19889. };
  19890. convert.rgb.hcg = function (rgb) {
  19891. var r = rgb[0] / 255;
  19892. var g = rgb[1] / 255;
  19893. var b = rgb[2] / 255;
  19894. var max = Math.max(Math.max(r, g), b);
  19895. var min = Math.min(Math.min(r, g), b);
  19896. var chroma = (max - min);
  19897. var grayscale;
  19898. var hue;
  19899. if (chroma < 1) {
  19900. grayscale = min / (1 - chroma);
  19901. } else {
  19902. grayscale = 0;
  19903. }
  19904. if (chroma <= 0) {
  19905. hue = 0;
  19906. } else
  19907. if (max === r) {
  19908. hue = ((g - b) / chroma) % 6;
  19909. } else
  19910. if (max === g) {
  19911. hue = 2 + (b - r) / chroma;
  19912. } else {
  19913. hue = 4 + (r - g) / chroma + 4;
  19914. }
  19915. hue /= 6;
  19916. hue %= 1;
  19917. return [hue * 360, chroma * 100, grayscale * 100];
  19918. };
  19919. convert.hsl.hcg = function (hsl) {
  19920. var s = hsl[1] / 100;
  19921. var l = hsl[2] / 100;
  19922. var c = 1;
  19923. var f = 0;
  19924. if (l < 0.5) {
  19925. c = 2.0 * s * l;
  19926. } else {
  19927. c = 2.0 * s * (1.0 - l);
  19928. }
  19929. if (c < 1.0) {
  19930. f = (l - 0.5 * c) / (1.0 - c);
  19931. }
  19932. return [hsl[0], c * 100, f * 100];
  19933. };
  19934. convert.hsv.hcg = function (hsv) {
  19935. var s = hsv[1] / 100;
  19936. var v = hsv[2] / 100;
  19937. var c = s * v;
  19938. var f = 0;
  19939. if (c < 1.0) {
  19940. f = (v - c) / (1 - c);
  19941. }
  19942. return [hsv[0], c * 100, f * 100];
  19943. };
  19944. convert.hcg.rgb = function (hcg) {
  19945. var h = hcg[0] / 360;
  19946. var c = hcg[1] / 100;
  19947. var g = hcg[2] / 100;
  19948. if (c === 0.0) {
  19949. return [g * 255, g * 255, g * 255];
  19950. }
  19951. var pure = [0, 0, 0];
  19952. var hi = (h % 1) * 6;
  19953. var v = hi % 1;
  19954. var w = 1 - v;
  19955. var mg = 0;
  19956. switch (Math.floor(hi)) {
  19957. case 0:
  19958. pure[0] = 1; pure[1] = v; pure[2] = 0; break;
  19959. case 1:
  19960. pure[0] = w; pure[1] = 1; pure[2] = 0; break;
  19961. case 2:
  19962. pure[0] = 0; pure[1] = 1; pure[2] = v; break;
  19963. case 3:
  19964. pure[0] = 0; pure[1] = w; pure[2] = 1; break;
  19965. case 4:
  19966. pure[0] = v; pure[1] = 0; pure[2] = 1; break;
  19967. default:
  19968. pure[0] = 1; pure[1] = 0; pure[2] = w;
  19969. }
  19970. mg = (1.0 - c) * g;
  19971. return [
  19972. (c * pure[0] + mg) * 255,
  19973. (c * pure[1] + mg) * 255,
  19974. (c * pure[2] + mg) * 255
  19975. ];
  19976. };
  19977. convert.hcg.hsv = function (hcg) {
  19978. var c = hcg[1] / 100;
  19979. var g = hcg[2] / 100;
  19980. var v = c + g * (1.0 - c);
  19981. var f = 0;
  19982. if (v > 0.0) {
  19983. f = c / v;
  19984. }
  19985. return [hcg[0], f * 100, v * 100];
  19986. };
  19987. convert.hcg.hsl = function (hcg) {
  19988. var c = hcg[1] / 100;
  19989. var g = hcg[2] / 100;
  19990. var l = g * (1.0 - c) + 0.5 * c;
  19991. var s = 0;
  19992. if (l > 0.0 && l < 0.5) {
  19993. s = c / (2 * l);
  19994. } else
  19995. if (l >= 0.5 && l < 1.0) {
  19996. s = c / (2 * (1 - l));
  19997. }
  19998. return [hcg[0], s * 100, l * 100];
  19999. };
  20000. convert.hcg.hwb = function (hcg) {
  20001. var c = hcg[1] / 100;
  20002. var g = hcg[2] / 100;
  20003. var v = c + g * (1.0 - c);
  20004. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  20005. };
  20006. convert.hwb.hcg = function (hwb) {
  20007. var w = hwb[1] / 100;
  20008. var b = hwb[2] / 100;
  20009. var v = 1 - b;
  20010. var c = v - w;
  20011. var g = 0;
  20012. if (c < 1) {
  20013. g = (v - c) / (1 - c);
  20014. }
  20015. return [hwb[0], c * 100, g * 100];
  20016. };
  20017. convert.apple.rgb = function (apple) {
  20018. return [(apple[0] / 65535) * 255, (apple[1] / 65535) * 255, (apple[2] / 65535) * 255];
  20019. };
  20020. convert.rgb.apple = function (rgb) {
  20021. return [(rgb[0] / 255) * 65535, (rgb[1] / 255) * 65535, (rgb[2] / 255) * 65535];
  20022. };
  20023. convert.gray.rgb = function (args) {
  20024. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  20025. };
  20026. convert.gray.hsl = convert.gray.hsv = function (args) {
  20027. return [0, 0, args[0]];
  20028. };
  20029. convert.gray.hwb = function (gray) {
  20030. return [0, 100, gray[0]];
  20031. };
  20032. convert.gray.cmyk = function (gray) {
  20033. return [0, 0, 0, gray[0]];
  20034. };
  20035. convert.gray.lab = function (gray) {
  20036. return [gray[0], 0, 0];
  20037. };
  20038. convert.gray.hex = function (gray) {
  20039. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  20040. var integer = (val << 16) + (val << 8) + val;
  20041. var string = integer.toString(16).toUpperCase();
  20042. return '000000'.substring(string.length) + string;
  20043. };
  20044. convert.rgb.gray = function (rgb) {
  20045. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  20046. return [val / 255 * 100];
  20047. };
  20048. });
  20049. /*
  20050. this function routes a model to all other models.
  20051. all functions that are routed have a property `.conversion` attached
  20052. to the returned synthetic function. This property is an array
  20053. of strings, each with the steps in between the 'from' and 'to'
  20054. color models (inclusive).
  20055. conversions that are not possible simply are not included.
  20056. */
  20057. // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  20058. var models$1 = Object.keys(conversions);
  20059. function buildGraph() {
  20060. var graph = {};
  20061. for (var len = models$1.length, i = 0; i < len; i++) {
  20062. graph[models$1[i]] = {
  20063. // http://jsperf.com/1-vs-infinity
  20064. // micro-opt, but this is simple.
  20065. distance: -1,
  20066. parent: null
  20067. };
  20068. }
  20069. return graph;
  20070. }
  20071. // https://en.wikipedia.org/wiki/Breadth-first_search
  20072. function deriveBFS(fromModel) {
  20073. var graph = buildGraph();
  20074. var queue = [fromModel]; // unshift -> queue -> pop
  20075. graph[fromModel].distance = 0;
  20076. while (queue.length) {
  20077. var current = queue.pop();
  20078. var adjacents = Object.keys(conversions[current]);
  20079. for (var len = adjacents.length, i = 0; i < len; i++) {
  20080. var adjacent = adjacents[i];
  20081. var node = graph[adjacent];
  20082. if (node.distance === -1) {
  20083. node.distance = graph[current].distance + 1;
  20084. node.parent = current;
  20085. queue.unshift(adjacent);
  20086. }
  20087. }
  20088. }
  20089. return graph;
  20090. }
  20091. function link(from, to) {
  20092. return function (args) {
  20093. return to(from(args));
  20094. };
  20095. }
  20096. function wrapConversion(toModel, graph) {
  20097. var path$$1 = [graph[toModel].parent, toModel];
  20098. var fn = conversions[graph[toModel].parent][toModel];
  20099. var cur = graph[toModel].parent;
  20100. while (graph[cur].parent) {
  20101. path$$1.unshift(graph[cur].parent);
  20102. fn = link(conversions[graph[cur].parent][cur], fn);
  20103. cur = graph[cur].parent;
  20104. }
  20105. fn.conversion = path$$1;
  20106. return fn;
  20107. }
  20108. var route = function (fromModel) {
  20109. var graph = deriveBFS(fromModel);
  20110. var conversion = {};
  20111. var models = Object.keys(graph);
  20112. for (var len = models.length, i = 0; i < len; i++) {
  20113. var toModel = models[i];
  20114. var node = graph[toModel];
  20115. if (node.parent === null) {
  20116. // no possible conversion, or this node is the source model.
  20117. continue;
  20118. }
  20119. conversion[toModel] = wrapConversion(toModel, graph);
  20120. }
  20121. return conversion;
  20122. };
  20123. var convert = {};
  20124. var models = Object.keys(conversions);
  20125. function wrapRaw(fn) {
  20126. var wrappedFn = function (args) {
  20127. if (args === undefined || args === null) {
  20128. return args;
  20129. }
  20130. if (arguments.length > 1) {
  20131. args = Array.prototype.slice.call(arguments);
  20132. }
  20133. return fn(args);
  20134. };
  20135. // preserve .conversion property if there is one
  20136. if ('conversion' in fn) {
  20137. wrappedFn.conversion = fn.conversion;
  20138. }
  20139. return wrappedFn;
  20140. }
  20141. function wrapRounded(fn) {
  20142. var wrappedFn = function (args) {
  20143. if (args === undefined || args === null) {
  20144. return args;
  20145. }
  20146. if (arguments.length > 1) {
  20147. args = Array.prototype.slice.call(arguments);
  20148. }
  20149. var result = fn(args);
  20150. // we're assuming the result is an array here.
  20151. // see notice in conversions.js; don't use box types
  20152. // in conversion functions.
  20153. if (typeof result === 'object') {
  20154. for (var len = result.length, i = 0; i < len; i++) {
  20155. result[i] = Math.round(result[i]);
  20156. }
  20157. }
  20158. return result;
  20159. };
  20160. // preserve .conversion property if there is one
  20161. if ('conversion' in fn) {
  20162. wrappedFn.conversion = fn.conversion;
  20163. }
  20164. return wrappedFn;
  20165. }
  20166. models.forEach(function (fromModel) {
  20167. convert[fromModel] = {};
  20168. Object.defineProperty(convert[fromModel], 'channels', {value: conversions[fromModel].channels});
  20169. Object.defineProperty(convert[fromModel], 'labels', {value: conversions[fromModel].labels});
  20170. var routes = route(fromModel);
  20171. var routeModels = Object.keys(routes);
  20172. routeModels.forEach(function (toModel) {
  20173. var fn = routes[toModel];
  20174. convert[fromModel][toModel] = wrapRounded(fn);
  20175. convert[fromModel][toModel].raw = wrapRaw(fn);
  20176. });
  20177. });
  20178. var colorConvert = convert;
  20179. var ansiStyles = createCommonjsModule(function (module) {
  20180. 'use strict';
  20181. const wrapAnsi16 = (fn, offset) => function () {
  20182. const code = fn.apply(colorConvert, arguments);
  20183. return `\u001B[${code + offset}m`;
  20184. };
  20185. const wrapAnsi256 = (fn, offset) => function () {
  20186. const code = fn.apply(colorConvert, arguments);
  20187. return `\u001B[${38 + offset};5;${code}m`;
  20188. };
  20189. const wrapAnsi16m = (fn, offset) => function () {
  20190. const rgb = fn.apply(colorConvert, arguments);
  20191. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  20192. };
  20193. function assembleStyles() {
  20194. const styles = {
  20195. modifier: {
  20196. reset: [0, 0],
  20197. // 21 isn't widely supported and 22 does the same thing
  20198. bold: [1, 22],
  20199. dim: [2, 22],
  20200. italic: [3, 23],
  20201. underline: [4, 24],
  20202. inverse: [7, 27],
  20203. hidden: [8, 28],
  20204. strikethrough: [9, 29]
  20205. },
  20206. color: {
  20207. black: [30, 39],
  20208. red: [31, 39],
  20209. green: [32, 39],
  20210. yellow: [33, 39],
  20211. blue: [34, 39],
  20212. magenta: [35, 39],
  20213. cyan: [36, 39],
  20214. white: [37, 39],
  20215. gray: [90, 39],
  20216. // Bright color
  20217. redBright: [91, 39],
  20218. greenBright: [92, 39],
  20219. yellowBright: [93, 39],
  20220. blueBright: [94, 39],
  20221. magentaBright: [95, 39],
  20222. cyanBright: [96, 39],
  20223. whiteBright: [97, 39]
  20224. },
  20225. bgColor: {
  20226. bgBlack: [40, 49],
  20227. bgRed: [41, 49],
  20228. bgGreen: [42, 49],
  20229. bgYellow: [43, 49],
  20230. bgBlue: [44, 49],
  20231. bgMagenta: [45, 49],
  20232. bgCyan: [46, 49],
  20233. bgWhite: [47, 49],
  20234. // Bright color
  20235. bgBlackBright: [100, 49],
  20236. bgRedBright: [101, 49],
  20237. bgGreenBright: [102, 49],
  20238. bgYellowBright: [103, 49],
  20239. bgBlueBright: [104, 49],
  20240. bgMagentaBright: [105, 49],
  20241. bgCyanBright: [106, 49],
  20242. bgWhiteBright: [107, 49]
  20243. }
  20244. };
  20245. // Fix humans
  20246. styles.color.grey = styles.color.gray;
  20247. Object.keys(styles).forEach(groupName => {
  20248. const group = styles[groupName];
  20249. Object.keys(group).forEach(styleName => {
  20250. const style = group[styleName];
  20251. styles[styleName] = {
  20252. open: `\u001B[${style[0]}m`,
  20253. close: `\u001B[${style[1]}m`
  20254. };
  20255. group[styleName] = styles[styleName];
  20256. });
  20257. Object.defineProperty(styles, groupName, {
  20258. value: group,
  20259. enumerable: false
  20260. });
  20261. });
  20262. const rgb2rgb = (r, g, b) => [r, g, b];
  20263. styles.color.close = '\u001B[39m';
  20264. styles.bgColor.close = '\u001B[49m';
  20265. styles.color.ansi = {};
  20266. styles.color.ansi256 = {};
  20267. styles.color.ansi16m = {
  20268. rgb: wrapAnsi16m(rgb2rgb, 0)
  20269. };
  20270. styles.bgColor.ansi = {};
  20271. styles.bgColor.ansi256 = {};
  20272. styles.bgColor.ansi16m = {
  20273. rgb: wrapAnsi16m(rgb2rgb, 10)
  20274. };
  20275. for (const key of Object.keys(colorConvert)) {
  20276. if (typeof colorConvert[key] !== 'object') {
  20277. continue;
  20278. }
  20279. const suite = colorConvert[key];
  20280. if ('ansi16' in suite) {
  20281. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  20282. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  20283. }
  20284. if ('ansi256' in suite) {
  20285. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  20286. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  20287. }
  20288. if ('rgb' in suite) {
  20289. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  20290. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  20291. }
  20292. }
  20293. return styles;
  20294. }
  20295. Object.defineProperty(module, 'exports', {
  20296. enumerable: true,
  20297. get: assembleStyles
  20298. });
  20299. });
  20300. var hasFlag = function (flag, argv) {
  20301. argv = argv || process.argv;
  20302. var terminatorPos = argv.indexOf('--');
  20303. var prefix = /^-{1,2}/.test(flag) ? '' : '--';
  20304. var pos = argv.indexOf(prefix + flag);
  20305. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  20306. };
  20307. var supportsColor = createCommonjsModule(function (module) {
  20308. 'use strict';
  20309. const env = process.env;
  20310. const support = level => {
  20311. if (level === 0) {
  20312. return false;
  20313. }
  20314. return {
  20315. level,
  20316. hasBasic: true,
  20317. has256: level >= 2,
  20318. has16m: level >= 3
  20319. };
  20320. };
  20321. let supportLevel = (() => {
  20322. if (hasFlag('no-color') ||
  20323. hasFlag('no-colors') ||
  20324. hasFlag('color=false')) {
  20325. return 0;
  20326. }
  20327. if (hasFlag('color=16m') ||
  20328. hasFlag('color=full') ||
  20329. hasFlag('color=truecolor')) {
  20330. return 3;
  20331. }
  20332. if (hasFlag('color=256')) {
  20333. return 2;
  20334. }
  20335. if (hasFlag('color') ||
  20336. hasFlag('colors') ||
  20337. hasFlag('color=true') ||
  20338. hasFlag('color=always')) {
  20339. return 1;
  20340. }
  20341. if (process.stdout && !process.stdout.isTTY) {
  20342. return 0;
  20343. }
  20344. if (process.platform === 'win32') {
  20345. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  20346. // libuv that enables 256 color output on Windows. Anything earlier and it
  20347. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  20348. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  20349. // release that supports 256 colors.
  20350. const osRelease = os.release().split('.');
  20351. if (
  20352. Number(process.version.split('.')[0]) >= 8 &&
  20353. Number(osRelease[0]) >= 10 &&
  20354. Number(osRelease[2]) >= 10586
  20355. ) {
  20356. return 2;
  20357. }
  20358. return 1;
  20359. }
  20360. if ('CI' in env) {
  20361. if ('TRAVIS' in env || env.CI === 'Travis' || 'CIRCLECI' in env) {
  20362. return 1;
  20363. }
  20364. return 0;
  20365. }
  20366. if ('TEAMCITY_VERSION' in env) {
  20367. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  20368. }
  20369. if ('TERM_PROGRAM' in env) {
  20370. const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  20371. switch (env.TERM_PROGRAM) {
  20372. case 'iTerm.app':
  20373. return version >= 3 ? 3 : 2;
  20374. case 'Hyper':
  20375. return 3;
  20376. case 'Apple_Terminal':
  20377. return 2;
  20378. // No default
  20379. }
  20380. }
  20381. if (/^(screen|xterm)-256(?:color)?/.test(env.TERM)) {
  20382. return 2;
  20383. }
  20384. if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) {
  20385. return 1;
  20386. }
  20387. if ('COLORTERM' in env) {
  20388. return 1;
  20389. }
  20390. if (env.TERM === 'dumb') {
  20391. return 0;
  20392. }
  20393. return 0;
  20394. })();
  20395. if ('FORCE_COLOR' in env) {
  20396. supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : (supportLevel || 1);
  20397. }
  20398. module.exports = process && support(supportLevel);
  20399. });
  20400. var templates = createCommonjsModule(function (module) {
  20401. 'use strict';
  20402. const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  20403. const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  20404. const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  20405. const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  20406. const ESCAPES = new Map([
  20407. ['n', '\n'],
  20408. ['r', '\r'],
  20409. ['t', '\t'],
  20410. ['b', '\b'],
  20411. ['f', '\f'],
  20412. ['v', '\v'],
  20413. ['0', '\0'],
  20414. ['\\', '\\'],
  20415. ['e', '\u001B'],
  20416. ['a', '\u0007']
  20417. ]);
  20418. function unescape(c) {
  20419. if ((c[0] === 'u' && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
  20420. return String.fromCharCode(parseInt(c.slice(1), 16));
  20421. }
  20422. return ESCAPES.get(c) || c;
  20423. }
  20424. function parseArguments(name, args) {
  20425. const results = [];
  20426. const chunks = args.trim().split(/\s*,\s*/g);
  20427. let matches;
  20428. for (const chunk of chunks) {
  20429. if (!isNaN(chunk)) {
  20430. results.push(Number(chunk));
  20431. } else if ((matches = chunk.match(STRING_REGEX))) {
  20432. results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr));
  20433. } else {
  20434. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  20435. }
  20436. }
  20437. return results;
  20438. }
  20439. function parseStyle(style) {
  20440. STYLE_REGEX.lastIndex = 0;
  20441. const results = [];
  20442. let matches;
  20443. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  20444. const name = matches[1];
  20445. if (matches[2]) {
  20446. const args = parseArguments(name, matches[2]);
  20447. results.push([name].concat(args));
  20448. } else {
  20449. results.push([name]);
  20450. }
  20451. }
  20452. return results;
  20453. }
  20454. function buildStyle(chalk, styles) {
  20455. const enabled = {};
  20456. for (const layer of styles) {
  20457. for (const style of layer.styles) {
  20458. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  20459. }
  20460. }
  20461. let current = chalk;
  20462. for (const styleName of Object.keys(enabled)) {
  20463. if (Array.isArray(enabled[styleName])) {
  20464. if (!(styleName in current)) {
  20465. throw new Error(`Unknown Chalk style: ${styleName}`);
  20466. }
  20467. if (enabled[styleName].length > 0) {
  20468. current = current[styleName].apply(current, enabled[styleName]);
  20469. } else {
  20470. current = current[styleName];
  20471. }
  20472. }
  20473. }
  20474. return current;
  20475. }
  20476. module.exports = (chalk, tmp) => {
  20477. const styles = [];
  20478. const chunks = [];
  20479. let chunk = [];
  20480. // eslint-disable-next-line max-params
  20481. tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => {
  20482. if (escapeChar) {
  20483. chunk.push(unescape(escapeChar));
  20484. } else if (style) {
  20485. const str = chunk.join('');
  20486. chunk = [];
  20487. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  20488. styles.push({inverse, styles: parseStyle(style)});
  20489. } else if (close) {
  20490. if (styles.length === 0) {
  20491. throw new Error('Found extraneous } in Chalk template literal');
  20492. }
  20493. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  20494. chunk = [];
  20495. styles.pop();
  20496. } else {
  20497. chunk.push(chr);
  20498. }
  20499. });
  20500. chunks.push(chunk.join(''));
  20501. if (styles.length > 0) {
  20502. const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  20503. throw new Error(errMsg);
  20504. }
  20505. return chunks.join('');
  20506. };
  20507. });
  20508. var chalk = createCommonjsModule(function (module) {
  20509. 'use strict';
  20510. const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
  20511. // `supportsColor.level` → `ansiStyles.color[name]` mapping
  20512. const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
  20513. // `color-convert` models to exclude from the Chalk API due to conflicts and such
  20514. const skipModels = new Set(['gray']);
  20515. const styles = Object.create(null);
  20516. function applyOptions(obj, options) {
  20517. options = options || {};
  20518. // Detect level if not set manually
  20519. const scLevel = supportsColor ? supportsColor.level : 0;
  20520. obj.level = options.level === undefined ? scLevel : options.level;
  20521. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  20522. }
  20523. function Chalk(options) {
  20524. // We check for this.template here since calling `chalk.constructor()`
  20525. // by itself will have a `this` of a previously constructed chalk object
  20526. if (!this || !(this instanceof Chalk) || this.template) {
  20527. const chalk = {};
  20528. applyOptions(chalk, options);
  20529. chalk.template = function () {
  20530. const args = [].slice.call(arguments);
  20531. return chalkTag.apply(null, [chalk.template].concat(args));
  20532. };
  20533. Object.setPrototypeOf(chalk, Chalk.prototype);
  20534. Object.setPrototypeOf(chalk.template, chalk);
  20535. chalk.template.constructor = Chalk;
  20536. return chalk.template;
  20537. }
  20538. applyOptions(this, options);
  20539. }
  20540. // Use bright blue on Windows as the normal blue color is illegible
  20541. if (isSimpleWindowsTerm) {
  20542. ansiStyles.blue.open = '\u001B[94m';
  20543. }
  20544. for (const key of Object.keys(ansiStyles)) {
  20545. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  20546. styles[key] = {
  20547. get() {
  20548. const codes = ansiStyles[key];
  20549. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  20550. }
  20551. };
  20552. }
  20553. styles.visible = {
  20554. get() {
  20555. return build.call(this, this._styles || [], true, 'visible');
  20556. }
  20557. };
  20558. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  20559. for (const model of Object.keys(ansiStyles.color.ansi)) {
  20560. if (skipModels.has(model)) {
  20561. continue;
  20562. }
  20563. styles[model] = {
  20564. get() {
  20565. const level = this.level;
  20566. return function () {
  20567. const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  20568. const codes = {
  20569. open,
  20570. close: ansiStyles.color.close,
  20571. closeRe: ansiStyles.color.closeRe
  20572. };
  20573. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  20574. };
  20575. }
  20576. };
  20577. }
  20578. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  20579. for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
  20580. if (skipModels.has(model)) {
  20581. continue;
  20582. }
  20583. const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  20584. styles[bgModel] = {
  20585. get() {
  20586. const level = this.level;
  20587. return function () {
  20588. const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  20589. const codes = {
  20590. open,
  20591. close: ansiStyles.bgColor.close,
  20592. closeRe: ansiStyles.bgColor.closeRe
  20593. };
  20594. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  20595. };
  20596. }
  20597. };
  20598. }
  20599. const proto = Object.defineProperties(() => {}, styles);
  20600. function build(_styles, _empty, key) {
  20601. const builder = function () {
  20602. return applyStyle.apply(builder, arguments);
  20603. };
  20604. builder._styles = _styles;
  20605. builder._empty = _empty;
  20606. const self = this;
  20607. Object.defineProperty(builder, 'level', {
  20608. enumerable: true,
  20609. get() {
  20610. return self.level;
  20611. },
  20612. set(level) {
  20613. self.level = level;
  20614. }
  20615. });
  20616. Object.defineProperty(builder, 'enabled', {
  20617. enumerable: true,
  20618. get() {
  20619. return self.enabled;
  20620. },
  20621. set(enabled) {
  20622. self.enabled = enabled;
  20623. }
  20624. });
  20625. // See below for fix regarding invisible grey/dim combination on Windows
  20626. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey';
  20627. // `__proto__` is used because we must return a function, but there is
  20628. // no way to create a function with a different prototype
  20629. builder.__proto__ = proto; // eslint-disable-line no-proto
  20630. return builder;
  20631. }
  20632. function applyStyle() {
  20633. // Support varags, but simply cast to string in case there's only one arg
  20634. const args = arguments;
  20635. const argsLen = args.length;
  20636. let str = String(arguments[0]);
  20637. if (argsLen === 0) {
  20638. return '';
  20639. }
  20640. if (argsLen > 1) {
  20641. // Don't slice `arguments`, it prevents V8 optimizations
  20642. for (let a = 1; a < argsLen; a++) {
  20643. str += ' ' + args[a];
  20644. }
  20645. }
  20646. if (!this.enabled || this.level <= 0 || !str) {
  20647. return this._empty ? '' : str;
  20648. }
  20649. // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  20650. // see https://github.com/chalk/chalk/issues/58
  20651. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  20652. const originalDim = ansiStyles.dim.open;
  20653. if (isSimpleWindowsTerm && this.hasGrey) {
  20654. ansiStyles.dim.open = '';
  20655. }
  20656. for (const code of this._styles.slice().reverse()) {
  20657. // Replace any instances already present with a re-opening code
  20658. // otherwise only the part of the string until said closing code
  20659. // will be colored, and the rest will simply be 'plain'.
  20660. str = code.open + str.replace(code.closeRe, code.open) + code.close;
  20661. // Close the styling before a linebreak and reopen
  20662. // after next line to fix a bleed issue on macOS
  20663. // https://github.com/chalk/chalk/pull/92
  20664. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  20665. }
  20666. // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  20667. ansiStyles.dim.open = originalDim;
  20668. return str;
  20669. }
  20670. function chalkTag(chalk, strings) {
  20671. if (!Array.isArray(strings)) {
  20672. // If chalk() was called by itself or with a string,
  20673. // return the string itself as a string.
  20674. return [].slice.call(arguments, 1).join(' ');
  20675. }
  20676. const args = [].slice.call(arguments, 2);
  20677. const parts = [strings.raw[0]];
  20678. for (let i = 1; i < strings.length; i++) {
  20679. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  20680. parts.push(String(strings.raw[i]));
  20681. }
  20682. return templates(chalk, parts.join(''));
  20683. }
  20684. Object.defineProperties(Chalk.prototype, styles);
  20685. module.exports = Chalk(); // eslint-disable-line new-cap
  20686. module.exports.supportsColor = supportsColor;
  20687. module.exports.default = module.exports; // For TypeScript
  20688. });
  20689. var lib$5 = createCommonjsModule(function (module, exports) {
  20690. "use strict";
  20691. exports.__esModule = true;
  20692. exports.shouldHighlight = shouldHighlight;
  20693. exports.getChalk = getChalk;
  20694. exports.default = highlight;
  20695. var _jsTokens = _interopRequireWildcard(jsTokens);
  20696. var _esutils = _interopRequireDefault(utils$2);
  20697. var _chalk = _interopRequireDefault(chalk);
  20698. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  20699. 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; } }
  20700. function getDefs(chalk$$1) {
  20701. return {
  20702. keyword: chalk$$1.cyan,
  20703. capitalized: chalk$$1.yellow,
  20704. jsx_tag: chalk$$1.yellow,
  20705. punctuator: chalk$$1.yellow,
  20706. number: chalk$$1.magenta,
  20707. string: chalk$$1.green,
  20708. regex: chalk$$1.magenta,
  20709. comment: chalk$$1.grey,
  20710. invalid: chalk$$1.white.bgRed.bold
  20711. };
  20712. }
  20713. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  20714. var JSX_TAG = /^[a-z][\w-]*$/i;
  20715. var BRACKET = /^[()[\]{}]$/;
  20716. function getTokenType(match) {
  20717. var _match$slice = match.slice(-2),
  20718. offset = _match$slice[0],
  20719. text = _match$slice[1];
  20720. var token = (0, _jsTokens.matchToToken)(match);
  20721. if (token.type === "name") {
  20722. if (_esutils.default.keyword.isReservedWordES6(token.value)) {
  20723. return "keyword";
  20724. }
  20725. if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
  20726. return "jsx_tag";
  20727. }
  20728. if (token.value[0] !== token.value[0].toLowerCase()) {
  20729. return "capitalized";
  20730. }
  20731. }
  20732. if (token.type === "punctuator" && BRACKET.test(token.value)) {
  20733. return "bracket";
  20734. }
  20735. if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
  20736. return "punctuator";
  20737. }
  20738. return token.type;
  20739. }
  20740. function highlightTokens(defs, text) {
  20741. return text.replace(_jsTokens.default, function () {
  20742. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  20743. args[_key] = arguments[_key];
  20744. }
  20745. var type = getTokenType(args);
  20746. var colorize = defs[type];
  20747. if (colorize) {
  20748. return args[0].split(NEWLINE).map(function (str) {
  20749. return colorize(str);
  20750. }).join("\n");
  20751. } else {
  20752. return args[0];
  20753. }
  20754. });
  20755. }
  20756. function shouldHighlight(options) {
  20757. return _chalk.default.supportsColor || options.forceColor;
  20758. }
  20759. function getChalk(options) {
  20760. var chalk$$1 = _chalk.default;
  20761. if (options.forceColor) {
  20762. chalk$$1 = new _chalk.default.constructor({
  20763. enabled: true,
  20764. level: 1
  20765. });
  20766. }
  20767. return chalk$$1;
  20768. }
  20769. function highlight(code, options) {
  20770. if (options === void 0) {
  20771. options = {};
  20772. }
  20773. if (shouldHighlight(options)) {
  20774. var chalk$$1 = getChalk(options);
  20775. var defs = getDefs(chalk$$1);
  20776. return highlightTokens(defs, code);
  20777. } else {
  20778. return code;
  20779. }
  20780. }
  20781. });
  20782. unwrapExports(lib$5);
  20783. var lib$4 = createCommonjsModule(function (module, exports) {
  20784. "use strict";
  20785. exports.__esModule = true;
  20786. exports.codeFrameColumns = codeFrameColumns;
  20787. exports.default = _default;
  20788. var _highlight = _interopRequireWildcard(lib$5);
  20789. 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; } }
  20790. var deprecationWarningShown = false;
  20791. function getDefs(chalk) {
  20792. return {
  20793. gutter: chalk.grey,
  20794. marker: chalk.red.bold,
  20795. message: chalk.red.bold
  20796. };
  20797. }
  20798. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  20799. function getMarkerLines(loc, source, opts) {
  20800. var startLoc = Object.assign({}, {
  20801. column: 0,
  20802. line: -1
  20803. }, loc.start);
  20804. var endLoc = Object.assign({}, startLoc, loc.end);
  20805. var _ref = opts || {},
  20806. _ref$linesAbove = _ref.linesAbove,
  20807. linesAbove = _ref$linesAbove === void 0 ? 2 : _ref$linesAbove,
  20808. _ref$linesBelow = _ref.linesBelow,
  20809. linesBelow = _ref$linesBelow === void 0 ? 3 : _ref$linesBelow;
  20810. var startLine = startLoc.line;
  20811. var startColumn = startLoc.column;
  20812. var endLine = endLoc.line;
  20813. var endColumn = endLoc.column;
  20814. var start = Math.max(startLine - (linesAbove + 1), 0);
  20815. var end = Math.min(source.length, endLine + linesBelow);
  20816. if (startLine === -1) {
  20817. start = 0;
  20818. }
  20819. if (endLine === -1) {
  20820. end = source.length;
  20821. }
  20822. var lineDiff = endLine - startLine;
  20823. var markerLines = {};
  20824. if (lineDiff) {
  20825. for (var i = 0; i <= lineDiff; i++) {
  20826. var lineNumber = i + startLine;
  20827. if (!startColumn) {
  20828. markerLines[lineNumber] = true;
  20829. } else if (i === 0) {
  20830. var sourceLength = source[lineNumber - 1].length;
  20831. markerLines[lineNumber] = [startColumn, sourceLength - startColumn];
  20832. } else if (i === lineDiff) {
  20833. markerLines[lineNumber] = [0, endColumn];
  20834. } else {
  20835. var _sourceLength = source[lineNumber - i].length;
  20836. markerLines[lineNumber] = [0, _sourceLength];
  20837. }
  20838. }
  20839. } else {
  20840. if (startColumn === endColumn) {
  20841. if (startColumn) {
  20842. markerLines[startLine] = [startColumn, 0];
  20843. } else {
  20844. markerLines[startLine] = true;
  20845. }
  20846. } else {
  20847. markerLines[startLine] = [startColumn, endColumn - startColumn];
  20848. }
  20849. }
  20850. return {
  20851. start: start,
  20852. end: end,
  20853. markerLines: markerLines
  20854. };
  20855. }
  20856. function codeFrameColumns(rawLines, loc, opts) {
  20857. if (opts === void 0) {
  20858. opts = {};
  20859. }
  20860. var highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight.shouldHighlight)(opts);
  20861. var chalk = (0, _highlight.getChalk)(opts);
  20862. var defs = getDefs(chalk);
  20863. var maybeHighlight = function maybeHighlight(chalkFn, string) {
  20864. return highlighted ? chalkFn(string) : string;
  20865. };
  20866. if (highlighted) rawLines = (0, _highlight.default)(rawLines, opts);
  20867. var lines = rawLines.split(NEWLINE);
  20868. var _getMarkerLines = getMarkerLines(loc, lines, opts),
  20869. start = _getMarkerLines.start,
  20870. end = _getMarkerLines.end,
  20871. markerLines = _getMarkerLines.markerLines;
  20872. var hasColumns = loc.start && typeof loc.start.column === "number";
  20873. var numberMaxWidth = String(end).length;
  20874. var frame = lines.slice(start, end).map(function (line, index) {
  20875. var number = start + 1 + index;
  20876. var paddedNumber = (" " + number).slice(-numberMaxWidth);
  20877. var gutter = " " + paddedNumber + " | ";
  20878. var hasMarker = markerLines[number];
  20879. var lastMarkerLine = !markerLines[number + 1];
  20880. if (hasMarker) {
  20881. var markerLine = "";
  20882. if (Array.isArray(hasMarker)) {
  20883. var markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  20884. var numberOfMarkers = hasMarker[1] || 1;
  20885. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  20886. if (lastMarkerLine && opts.message) {
  20887. markerLine += " " + maybeHighlight(defs.message, opts.message);
  20888. }
  20889. }
  20890. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
  20891. } else {
  20892. return " " + maybeHighlight(defs.gutter, gutter) + line;
  20893. }
  20894. }).join("\n");
  20895. if (opts.message && !hasColumns) {
  20896. frame = "" + " ".repeat(numberMaxWidth + 1) + opts.message + "\n" + frame;
  20897. }
  20898. if (highlighted) {
  20899. return chalk.reset(frame);
  20900. } else {
  20901. return frame;
  20902. }
  20903. }
  20904. function _default(rawLines, lineNumber, colNumber, opts) {
  20905. if (opts === void 0) {
  20906. opts = {};
  20907. }
  20908. if (!deprecationWarningShown) {
  20909. deprecationWarningShown = true;
  20910. var deprecationError = new Error("Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.");
  20911. deprecationError.name = "DeprecationWarning";
  20912. if (process.emitWarning) {
  20913. process.emitWarning(deprecationError);
  20914. } else {
  20915. console.warn(deprecationError);
  20916. }
  20917. }
  20918. colNumber = Math.max(colNumber, 0);
  20919. var location = {
  20920. start: {
  20921. column: colNumber,
  20922. line: lineNumber
  20923. }
  20924. };
  20925. return codeFrameColumns(rawLines, location, opts);
  20926. }
  20927. });
  20928. unwrapExports(lib$4);
  20929. const ConfigError = errors.ConfigError;
  20930. const locStart$1 = languageJs.locStart;
  20931. const locEnd$1 = languageJs.locEnd;
  20932. function getParsers(options) {
  20933. return options.plugins.reduce(
  20934. (parsers, plugin) => Object.assign({}, parsers, plugin.parsers),
  20935. {}
  20936. );
  20937. }
  20938. function resolveParser$1(opts, parsers) {
  20939. parsers = parsers || getParsers(opts);
  20940. if (typeof opts.parser === "function") {
  20941. // Custom parser API always works with JavaScript.
  20942. return {
  20943. parse: opts.parser,
  20944. astFormat: "estree",
  20945. locStart: locStart$1,
  20946. locEnd: locEnd$1
  20947. };
  20948. }
  20949. if (typeof opts.parser === "string") {
  20950. if (parsers.hasOwnProperty(opts.parser)) {
  20951. return parsers[opts.parser];
  20952. }
  20953. try {
  20954. return {
  20955. parse: require(path.resolve(process.cwd(), opts.parser)),
  20956. astFormat: "estree",
  20957. locStart: locStart$1,
  20958. locEnd: locEnd$1
  20959. };
  20960. } catch (err) {
  20961. /* istanbul ignore next */
  20962. throw new ConfigError(`Couldn't resolve parser "${opts.parser}"`);
  20963. }
  20964. }
  20965. /* istanbul ignore next */
  20966. return parsers.babylon;
  20967. }
  20968. function parse$3(text, opts) {
  20969. const parsers = getParsers(opts);
  20970. // Copy the "parse" function from parser to a new object whose values are
  20971. // functions. Use defineProperty()/getOwnPropertyDescriptor() such that we
  20972. // don't invoke the parser.parse getters.
  20973. const parsersForCustomParserApi = Object.keys(parsers).reduce(
  20974. (object, parserName) =>
  20975. Object.defineProperty(
  20976. object,
  20977. parserName,
  20978. Object.getOwnPropertyDescriptor(parsers[parserName], "parse")
  20979. ),
  20980. {}
  20981. );
  20982. const parser = resolveParser$1(opts, parsers);
  20983. try {
  20984. if (parser.preprocess) {
  20985. text = parser.preprocess(text, opts);
  20986. }
  20987. return {
  20988. text,
  20989. ast: parser.parse(text, parsersForCustomParserApi, opts)
  20990. };
  20991. } catch (error) {
  20992. const loc = error.loc;
  20993. if (loc) {
  20994. const codeFrame = lib$4;
  20995. error.codeFrame = codeFrame.codeFrameColumns(text, loc, {
  20996. highlightCode: true
  20997. });
  20998. error.message += "\n" + error.codeFrame;
  20999. throw error;
  21000. }
  21001. /* istanbul ignore next */
  21002. throw error.stack;
  21003. }
  21004. }
  21005. var parser$3 = { parse: parse$3, resolveParser: resolveParser$1 };
  21006. function getPlugin(options) {
  21007. const astFormat = options.astFormat;
  21008. if (!astFormat) {
  21009. throw new Error("getPlugin() requires astFormat to be set");
  21010. }
  21011. const printerPlugin = options.plugins.find(
  21012. plugin => plugin.printers[astFormat]
  21013. );
  21014. if (!printerPlugin) {
  21015. throw new Error(`Couldn't find plugin for AST format "${astFormat}"`);
  21016. }
  21017. return printerPlugin;
  21018. }
  21019. var getPlugin_1 = getPlugin;
  21020. const getSupportInfo$2 = support.getSupportInfo;
  21021. const resolveParser = parser$3.resolveParser;
  21022. const hiddenDefaults = {
  21023. astFormat: "estree",
  21024. printer: {},
  21025. locStart: null,
  21026. locEnd: null
  21027. };
  21028. // Copy options and fill in default values.
  21029. function normalize$2(options, opts) {
  21030. opts = opts || {};
  21031. const rawOptions = Object.assign({}, options);
  21032. const plugins = loadPlugins_1(rawOptions.plugins);
  21033. rawOptions.plugins = plugins;
  21034. const supportOptions = getSupportInfo$2(null, {
  21035. plugins,
  21036. pluginsLoaded: true,
  21037. showUnreleased: true,
  21038. showDeprecated: true
  21039. }).options;
  21040. const defaults = supportOptions.reduce(
  21041. (reduced, optionInfo) =>
  21042. Object.assign(reduced, { [optionInfo.name]: optionInfo.default }),
  21043. Object.assign({}, hiddenDefaults)
  21044. );
  21045. if (opts.inferParser !== false) {
  21046. if (
  21047. rawOptions.filepath &&
  21048. (!rawOptions.parser || rawOptions.parser === defaults.parser)
  21049. ) {
  21050. const inferredParser = inferParser(
  21051. rawOptions.filepath,
  21052. rawOptions.plugins
  21053. );
  21054. if (inferredParser) {
  21055. rawOptions.parser = inferredParser;
  21056. }
  21057. }
  21058. }
  21059. const parser = resolveParser(
  21060. !rawOptions.parser
  21061. ? rawOptions
  21062. : // handle deprecated parsers
  21063. optionsNormalizer.normalizeApiOptions(
  21064. rawOptions,
  21065. [supportOptions.find(x => x.name === "parser")],
  21066. { passThrough: true, logger: false }
  21067. )
  21068. );
  21069. rawOptions.astFormat = parser.astFormat;
  21070. rawOptions.locEnd = parser.locEnd;
  21071. rawOptions.locStart = parser.locStart;
  21072. const plugin = getPlugin_1(rawOptions);
  21073. rawOptions.printer = plugin.printers[rawOptions.astFormat];
  21074. const pluginDefaults = supportOptions
  21075. .filter(
  21076. optionInfo =>
  21077. optionInfo.pluginDefaults && optionInfo.pluginDefaults[plugin.name]
  21078. )
  21079. .reduce(
  21080. (reduced, optionInfo) =>
  21081. Object.assign(reduced, {
  21082. [optionInfo.name]: optionInfo.pluginDefaults[plugin.name]
  21083. }),
  21084. {}
  21085. );
  21086. const mixedDefaults = Object.assign({}, defaults, pluginDefaults);
  21087. Object.keys(mixedDefaults).forEach(k => {
  21088. if (rawOptions[k] == null) {
  21089. rawOptions[k] = mixedDefaults[k];
  21090. }
  21091. });
  21092. if (rawOptions.parser === "json") {
  21093. rawOptions.trailingComma = "none";
  21094. }
  21095. return optionsNormalizer.normalizeApiOptions(
  21096. rawOptions,
  21097. supportOptions,
  21098. Object.assign({ passThrough: Object.keys(hiddenDefaults) }, opts)
  21099. );
  21100. }
  21101. function inferParser(filepath, plugins) {
  21102. const extension = path.extname(filepath);
  21103. const filename = path.basename(filepath).toLowerCase();
  21104. const language = getSupportInfo$2(null, {
  21105. plugins,
  21106. pluginsLoaded: true
  21107. }).languages.find(
  21108. language =>
  21109. language.since !== null &&
  21110. (language.extensions.indexOf(extension) > -1 ||
  21111. (language.filenames &&
  21112. language.filenames.find(name => name.toLowerCase() === filename)))
  21113. );
  21114. return language && language.parsers[0];
  21115. }
  21116. var options$12 = { normalize: normalize$2, hiddenDefaults };
  21117. const normalize$1 = options$12.normalize;
  21118. function printSubtree(path$$1, print, options) {
  21119. if (options.printer.embed) {
  21120. return options.printer.embed(
  21121. path$$1,
  21122. print,
  21123. (text, partialNextOptions) =>
  21124. textToDoc(text, partialNextOptions, options),
  21125. options
  21126. );
  21127. }
  21128. }
  21129. function textToDoc(text, partialNextOptions, parentOptions) {
  21130. const nextOptions = normalize$1(
  21131. Object.assign({}, parentOptions, partialNextOptions, {
  21132. parentParser: parentOptions.parser,
  21133. originalText: text
  21134. }),
  21135. { passThrough: true, inferParser: false }
  21136. );
  21137. const result = parser$3.parse(text, nextOptions);
  21138. const ast = result.ast;
  21139. text = result.text;
  21140. const astComments = ast.comments;
  21141. delete ast.comments;
  21142. comments.attach(astComments, ast, text, nextOptions);
  21143. return astToDoc(ast, nextOptions);
  21144. }
  21145. var multiparser = {
  21146. printSubtree
  21147. };
  21148. const doc$3 = doc;
  21149. const docBuilders$14 = doc$3.builders;
  21150. const concat$14 = docBuilders$14.concat;
  21151. const hardline$13 = docBuilders$14.hardline;
  21152. const addAlignmentToDoc$2 = docBuilders$14.addAlignmentToDoc;
  21153. const docUtils$6 = doc$3.utils;
  21154. function printAstToDoc(ast, options, addAlignmentSize) {
  21155. addAlignmentSize = addAlignmentSize || 0;
  21156. const printer = options.printer;
  21157. const cache = new Map();
  21158. function printGenerically(path$$1, args) {
  21159. const node = path$$1.getValue();
  21160. const shouldCache = node && typeof node === "object" && args === undefined;
  21161. if (shouldCache && cache.has(node)) {
  21162. return cache.get(node);
  21163. }
  21164. // We let JSXElement print its comments itself because it adds () around
  21165. // UnionTypeAnnotation has to align the child without the comments
  21166. let res;
  21167. if (printer.willPrintOwnComments && printer.willPrintOwnComments(path$$1)) {
  21168. res = genericPrint$6(path$$1, options, printGenerically, args);
  21169. } else {
  21170. res = comments.printComments(
  21171. path$$1,
  21172. p => genericPrint$6(p, options, printGenerically, args),
  21173. options,
  21174. args && args.needsSemi
  21175. );
  21176. }
  21177. if (shouldCache) {
  21178. cache.set(node, res);
  21179. }
  21180. return res;
  21181. }
  21182. let doc$$2 = printGenerically(new fastPath(ast));
  21183. if (addAlignmentSize > 0) {
  21184. // Add a hardline to make the indents take effect
  21185. // It should be removed in index.js format()
  21186. doc$$2 = addAlignmentToDoc$2(
  21187. docUtils$6.removeLines(concat$14([hardline$13, doc$$2])),
  21188. addAlignmentSize,
  21189. options.tabWidth
  21190. );
  21191. }
  21192. docUtils$6.propagateBreaks(doc$$2);
  21193. if (options.parser === "json") {
  21194. doc$$2 = concat$14([doc$$2, hardline$13]);
  21195. }
  21196. return doc$$2;
  21197. }
  21198. function genericPrint$6(path$$1, options, printPath, args) {
  21199. assert.ok(path$$1 instanceof fastPath);
  21200. const node = path$$1.getValue();
  21201. const printer = options.printer;
  21202. // Escape hatch
  21203. if (printer.hasPrettierIgnore && printer.hasPrettierIgnore(path$$1)) {
  21204. return options.originalText.slice(
  21205. options.locStart(node),
  21206. options.locEnd(node)
  21207. );
  21208. }
  21209. if (node) {
  21210. try {
  21211. // Potentially switch to a different parser
  21212. const sub = multiparser.printSubtree(path$$1, printPath, options);
  21213. if (sub) {
  21214. return sub;
  21215. }
  21216. } catch (error) {
  21217. /* istanbul ignore if */
  21218. if (process.env.PRETTIER_DEBUG) {
  21219. throw error;
  21220. }
  21221. // Continue with current parser
  21222. }
  21223. }
  21224. return printer.print(path$$1, options, printPath, args);
  21225. }
  21226. var astToDoc = printAstToDoc;
  21227. var concatMap = function (xs, fn) {
  21228. var res = [];
  21229. for (var i = 0; i < xs.length; i++) {
  21230. var x = fn(xs[i], i);
  21231. if (isArray(x)) res.push.apply(res, x);
  21232. else res.push(x);
  21233. }
  21234. return res;
  21235. };
  21236. var isArray = Array.isArray || function (xs) {
  21237. return Object.prototype.toString.call(xs) === '[object Array]';
  21238. };
  21239. var balancedMatch = balanced;
  21240. function balanced(a, b, str) {
  21241. if (a instanceof RegExp) a = maybeMatch(a, str);
  21242. if (b instanceof RegExp) b = maybeMatch(b, str);
  21243. var r = range(a, b, str);
  21244. return r && {
  21245. start: r[0],
  21246. end: r[1],
  21247. pre: str.slice(0, r[0]),
  21248. body: str.slice(r[0] + a.length, r[1]),
  21249. post: str.slice(r[1] + b.length)
  21250. };
  21251. }
  21252. function maybeMatch(reg, str) {
  21253. var m = str.match(reg);
  21254. return m ? m[0] : null;
  21255. }
  21256. balanced.range = range;
  21257. function range(a, b, str) {
  21258. var begs, beg, left, right, result;
  21259. var ai = str.indexOf(a);
  21260. var bi = str.indexOf(b, ai + 1);
  21261. var i = ai;
  21262. if (ai >= 0 && bi > 0) {
  21263. begs = [];
  21264. left = str.length;
  21265. while (i >= 0 && !result) {
  21266. if (i == ai) {
  21267. begs.push(i);
  21268. ai = str.indexOf(a, i + 1);
  21269. } else if (begs.length == 1) {
  21270. result = [ begs.pop(), bi ];
  21271. } else {
  21272. beg = begs.pop();
  21273. if (beg < left) {
  21274. left = beg;
  21275. right = bi;
  21276. }
  21277. bi = str.indexOf(b, i + 1);
  21278. }
  21279. i = ai < bi && ai >= 0 ? ai : bi;
  21280. }
  21281. if (begs.length) {
  21282. result = [ left, right ];
  21283. }
  21284. }
  21285. return result;
  21286. }
  21287. var braceExpansion = expandTop;
  21288. var escSlash = '\0SLASH'+Math.random()+'\0';
  21289. var escOpen = '\0OPEN'+Math.random()+'\0';
  21290. var escClose = '\0CLOSE'+Math.random()+'\0';
  21291. var escComma = '\0COMMA'+Math.random()+'\0';
  21292. var escPeriod = '\0PERIOD'+Math.random()+'\0';
  21293. function numeric(str) {
  21294. return parseInt(str, 10) == str
  21295. ? parseInt(str, 10)
  21296. : str.charCodeAt(0);
  21297. }
  21298. function escapeBraces(str) {
  21299. return str.split('\\\\').join(escSlash)
  21300. .split('\\{').join(escOpen)
  21301. .split('\\}').join(escClose)
  21302. .split('\\,').join(escComma)
  21303. .split('\\.').join(escPeriod);
  21304. }
  21305. function unescapeBraces(str) {
  21306. return str.split(escSlash).join('\\')
  21307. .split(escOpen).join('{')
  21308. .split(escClose).join('}')
  21309. .split(escComma).join(',')
  21310. .split(escPeriod).join('.');
  21311. }
  21312. // Basically just str.split(","), but handling cases
  21313. // where we have nested braced sections, which should be
  21314. // treated as individual members, like {a,{b,c},d}
  21315. function parseCommaParts(str) {
  21316. if (!str)
  21317. return [''];
  21318. var parts = [];
  21319. var m = balancedMatch('{', '}', str);
  21320. if (!m)
  21321. return str.split(',');
  21322. var pre = m.pre;
  21323. var body = m.body;
  21324. var post = m.post;
  21325. var p = pre.split(',');
  21326. p[p.length-1] += '{' + body + '}';
  21327. var postParts = parseCommaParts(post);
  21328. if (post.length) {
  21329. p[p.length-1] += postParts.shift();
  21330. p.push.apply(p, postParts);
  21331. }
  21332. parts.push.apply(parts, p);
  21333. return parts;
  21334. }
  21335. function expandTop(str) {
  21336. if (!str)
  21337. return [];
  21338. // I don't know why Bash 4.3 does this, but it does.
  21339. // Anything starting with {} will have the first two bytes preserved
  21340. // but *only* at the top level, so {},a}b will not expand to anything,
  21341. // but a{},b}c will be expanded to [a}c,abc].
  21342. // One could argue that this is a bug in Bash, but since the goal of
  21343. // this module is to match Bash's rules, we escape a leading {}
  21344. if (str.substr(0, 2) === '{}') {
  21345. str = '\\{\\}' + str.substr(2);
  21346. }
  21347. return expand(escapeBraces(str), true).map(unescapeBraces);
  21348. }
  21349. function embrace(str) {
  21350. return '{' + str + '}';
  21351. }
  21352. function isPadded(el) {
  21353. return /^-?0\d/.test(el);
  21354. }
  21355. function lte(i, y) {
  21356. return i <= y;
  21357. }
  21358. function gte(i, y) {
  21359. return i >= y;
  21360. }
  21361. function expand(str, isTop) {
  21362. var expansions = [];
  21363. var m = balancedMatch('{', '}', str);
  21364. if (!m || /\$$/.test(m.pre)) return [str];
  21365. var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
  21366. var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
  21367. var isSequence = isNumericSequence || isAlphaSequence;
  21368. var isOptions = m.body.indexOf(',') >= 0;
  21369. if (!isSequence && !isOptions) {
  21370. // {a},b}
  21371. if (m.post.match(/,.*\}/)) {
  21372. str = m.pre + '{' + m.body + escClose + m.post;
  21373. return expand(str);
  21374. }
  21375. return [str];
  21376. }
  21377. var n;
  21378. if (isSequence) {
  21379. n = m.body.split(/\.\./);
  21380. } else {
  21381. n = parseCommaParts(m.body);
  21382. if (n.length === 1) {
  21383. // x{{a,b}}y ==> x{a}y x{b}y
  21384. n = expand(n[0], false).map(embrace);
  21385. if (n.length === 1) {
  21386. var post = m.post.length
  21387. ? expand(m.post, false)
  21388. : [''];
  21389. return post.map(function(p) {
  21390. return m.pre + n[0] + p;
  21391. });
  21392. }
  21393. }
  21394. }
  21395. // at this point, n is the parts, and we know it's not a comma set
  21396. // with a single entry.
  21397. // no need to expand pre, since it is guaranteed to be free of brace-sets
  21398. var pre = m.pre;
  21399. var post = m.post.length
  21400. ? expand(m.post, false)
  21401. : [''];
  21402. var N;
  21403. if (isSequence) {
  21404. var x = numeric(n[0]);
  21405. var y = numeric(n[1]);
  21406. var width = Math.max(n[0].length, n[1].length);
  21407. var incr = n.length == 3
  21408. ? Math.abs(numeric(n[2]))
  21409. : 1;
  21410. var test = lte;
  21411. var reverse = y < x;
  21412. if (reverse) {
  21413. incr *= -1;
  21414. test = gte;
  21415. }
  21416. var pad = n.some(isPadded);
  21417. N = [];
  21418. for (var i = x; test(i, y); i += incr) {
  21419. var c;
  21420. if (isAlphaSequence) {
  21421. c = String.fromCharCode(i);
  21422. if (c === '\\')
  21423. c = '';
  21424. } else {
  21425. c = String(i);
  21426. if (pad) {
  21427. var need = width - c.length;
  21428. if (need > 0) {
  21429. var z = new Array(need + 1).join('0');
  21430. if (i < 0)
  21431. c = '-' + z + c.slice(1);
  21432. else
  21433. c = z + c;
  21434. }
  21435. }
  21436. }
  21437. N.push(c);
  21438. }
  21439. } else {
  21440. N = concatMap(n, function(el) { return expand(el, false) });
  21441. }
  21442. for (var j = 0; j < N.length; j++) {
  21443. for (var k = 0; k < post.length; k++) {
  21444. var expansion = pre + N[j] + post[k];
  21445. if (!isTop || isSequence || expansion)
  21446. expansions.push(expansion);
  21447. }
  21448. }
  21449. return expansions;
  21450. }
  21451. var minimatch_1 = minimatch;
  21452. minimatch.Minimatch = Minimatch;
  21453. var path$3 = { sep: '/' };
  21454. try {
  21455. path$3 = path;
  21456. } catch (er) {}
  21457. var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
  21458. var plTypes = {
  21459. '!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
  21460. '?': { open: '(?:', close: ')?' },
  21461. '+': { open: '(?:', close: ')+' },
  21462. '*': { open: '(?:', close: ')*' },
  21463. '@': { open: '(?:', close: ')' }
  21464. };
  21465. // any single thing other than /
  21466. // don't need to escape / when using new RegExp()
  21467. var qmark = '[^/]';
  21468. // * => any number of characters
  21469. var star = qmark + '*?';
  21470. // ** when dots are allowed. Anything goes, except .. and .
  21471. // not (^ or / followed by one or two dots followed by $ or /),
  21472. // followed by anything, any number of times.
  21473. var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?';
  21474. // not a ^ or / followed by a dot,
  21475. // followed by anything, any number of times.
  21476. var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?';
  21477. // characters that need to be escaped in RegExp.
  21478. var reSpecials = charSet('().*{}+?[]^$\\!');
  21479. // "abc" -> { a:true, b:true, c:true }
  21480. function charSet (s) {
  21481. return s.split('').reduce(function (set, c) {
  21482. set[c] = true;
  21483. return set
  21484. }, {})
  21485. }
  21486. // normalizes slashes.
  21487. var slashSplit = /\/+/;
  21488. minimatch.filter = filter;
  21489. function filter (pattern, options) {
  21490. options = options || {};
  21491. return function (p, i, list) {
  21492. return minimatch(p, pattern, options)
  21493. }
  21494. }
  21495. function ext (a, b) {
  21496. a = a || {};
  21497. b = b || {};
  21498. var t = {};
  21499. Object.keys(b).forEach(function (k) {
  21500. t[k] = b[k];
  21501. });
  21502. Object.keys(a).forEach(function (k) {
  21503. t[k] = a[k];
  21504. });
  21505. return t
  21506. }
  21507. minimatch.defaults = function (def) {
  21508. if (!def || !Object.keys(def).length) return minimatch
  21509. var orig = minimatch;
  21510. var m = function minimatch (p, pattern, options) {
  21511. return orig.minimatch(p, pattern, ext(def, options))
  21512. };
  21513. m.Minimatch = function Minimatch (pattern, options) {
  21514. return new orig.Minimatch(pattern, ext(def, options))
  21515. };
  21516. return m
  21517. };
  21518. Minimatch.defaults = function (def) {
  21519. if (!def || !Object.keys(def).length) return Minimatch
  21520. return minimatch.defaults(def).Minimatch
  21521. };
  21522. function minimatch (p, pattern, options) {
  21523. if (typeof pattern !== 'string') {
  21524. throw new TypeError('glob pattern string required')
  21525. }
  21526. if (!options) options = {};
  21527. // shortcut: comments match nothing.
  21528. if (!options.nocomment && pattern.charAt(0) === '#') {
  21529. return false
  21530. }
  21531. // "" only matches ""
  21532. if (pattern.trim() === '') return p === ''
  21533. return new Minimatch(pattern, options).match(p)
  21534. }
  21535. function Minimatch (pattern, options) {
  21536. if (!(this instanceof Minimatch)) {
  21537. return new Minimatch(pattern, options)
  21538. }
  21539. if (typeof pattern !== 'string') {
  21540. throw new TypeError('glob pattern string required')
  21541. }
  21542. if (!options) options = {};
  21543. pattern = pattern.trim();
  21544. // windows support: need to use /, not \
  21545. if (path$3.sep !== '/') {
  21546. pattern = pattern.split(path$3.sep).join('/');
  21547. }
  21548. this.options = options;
  21549. this.set = [];
  21550. this.pattern = pattern;
  21551. this.regexp = null;
  21552. this.negate = false;
  21553. this.comment = false;
  21554. this.empty = false;
  21555. // make the set of regexps etc.
  21556. this.make();
  21557. }
  21558. Minimatch.prototype.debug = function () {};
  21559. Minimatch.prototype.make = make;
  21560. function make () {
  21561. // don't do it more than once.
  21562. if (this._made) return
  21563. var pattern = this.pattern;
  21564. var options = this.options;
  21565. // empty patterns and comments match nothing.
  21566. if (!options.nocomment && pattern.charAt(0) === '#') {
  21567. this.comment = true;
  21568. return
  21569. }
  21570. if (!pattern) {
  21571. this.empty = true;
  21572. return
  21573. }
  21574. // step 1: figure out negation, etc.
  21575. this.parseNegate();
  21576. // step 2: expand braces
  21577. var set = this.globSet = this.braceExpand();
  21578. if (options.debug) this.debug = console.error;
  21579. this.debug(this.pattern, set);
  21580. // step 3: now we have a set, so turn each one into a series of path-portion
  21581. // matching patterns.
  21582. // These will be regexps, except in the case of "**", which is
  21583. // set to the GLOBSTAR object for globstar behavior,
  21584. // and will not contain any / characters
  21585. set = this.globParts = set.map(function (s) {
  21586. return s.split(slashSplit)
  21587. });
  21588. this.debug(this.pattern, set);
  21589. // glob --> regexps
  21590. set = set.map(function (s, si, set) {
  21591. return s.map(this.parse, this)
  21592. }, this);
  21593. this.debug(this.pattern, set);
  21594. // filter out everything that didn't compile properly.
  21595. set = set.filter(function (s) {
  21596. return s.indexOf(false) === -1
  21597. });
  21598. this.debug(this.pattern, set);
  21599. this.set = set;
  21600. }
  21601. Minimatch.prototype.parseNegate = parseNegate;
  21602. function parseNegate () {
  21603. var pattern = this.pattern;
  21604. var negate = false;
  21605. var options = this.options;
  21606. var negateOffset = 0;
  21607. if (options.nonegate) return
  21608. for (var i = 0, l = pattern.length
  21609. ; i < l && pattern.charAt(i) === '!'
  21610. ; i++) {
  21611. negate = !negate;
  21612. negateOffset++;
  21613. }
  21614. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  21615. this.negate = negate;
  21616. }
  21617. // Brace expansion:
  21618. // a{b,c}d -> abd acd
  21619. // a{b,}c -> abc ac
  21620. // a{0..3}d -> a0d a1d a2d a3d
  21621. // a{b,c{d,e}f}g -> abg acdfg acefg
  21622. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  21623. //
  21624. // Invalid sets are not expanded.
  21625. // a{2..}b -> a{2..}b
  21626. // a{b}c -> a{b}c
  21627. minimatch.braceExpand = function (pattern, options) {
  21628. return braceExpand(pattern, options)
  21629. };
  21630. Minimatch.prototype.braceExpand = braceExpand;
  21631. function braceExpand (pattern, options) {
  21632. if (!options) {
  21633. if (this instanceof Minimatch) {
  21634. options = this.options;
  21635. } else {
  21636. options = {};
  21637. }
  21638. }
  21639. pattern = typeof pattern === 'undefined'
  21640. ? this.pattern : pattern;
  21641. if (typeof pattern === 'undefined') {
  21642. throw new TypeError('undefined pattern')
  21643. }
  21644. if (options.nobrace ||
  21645. !pattern.match(/\{.*\}/)) {
  21646. // shortcut. no need to expand.
  21647. return [pattern]
  21648. }
  21649. return braceExpansion(pattern)
  21650. }
  21651. // parse a component of the expanded set.
  21652. // At this point, no pattern may contain "/" in it
  21653. // so we're going to return a 2d array, where each entry is the full
  21654. // pattern, split on '/', and then turned into a regular expression.
  21655. // A regexp is made at the end which joins each array with an
  21656. // escaped /, and another full one which joins each regexp with |.
  21657. //
  21658. // Following the lead of Bash 4.1, note that "**" only has special meaning
  21659. // when it is the *only* thing in a path portion. Otherwise, any series
  21660. // of * is equivalent to a single *. Globstar behavior is enabled by
  21661. // default, and can be disabled by setting options.noglobstar.
  21662. Minimatch.prototype.parse = parse$4;
  21663. var SUBPARSE = {};
  21664. function parse$4 (pattern, isSub) {
  21665. if (pattern.length > 1024 * 64) {
  21666. throw new TypeError('pattern is too long')
  21667. }
  21668. var options = this.options;
  21669. // shortcuts
  21670. if (!options.noglobstar && pattern === '**') return GLOBSTAR
  21671. if (pattern === '') return ''
  21672. var re = '';
  21673. var hasMagic = !!options.nocase;
  21674. var escaping = false;
  21675. // ? => one single character
  21676. var patternListStack = [];
  21677. var negativeLists = [];
  21678. var stateChar;
  21679. var inClass = false;
  21680. var reClassStart = -1;
  21681. var classStart = -1;
  21682. // . and .. never match anything that doesn't start with .,
  21683. // even when options.dot is set.
  21684. var patternStart = pattern.charAt(0) === '.' ? '' // anything
  21685. // not (start or / followed by . or .. followed by / or end)
  21686. : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
  21687. : '(?!\\.)';
  21688. var self = this;
  21689. function clearStateChar () {
  21690. if (stateChar) {
  21691. // we had some state-tracking character
  21692. // that wasn't consumed by this pass.
  21693. switch (stateChar) {
  21694. case '*':
  21695. re += star;
  21696. hasMagic = true;
  21697. break
  21698. case '?':
  21699. re += qmark;
  21700. hasMagic = true;
  21701. break
  21702. default:
  21703. re += '\\' + stateChar;
  21704. break
  21705. }
  21706. self.debug('clearStateChar %j %j', stateChar, re);
  21707. stateChar = false;
  21708. }
  21709. }
  21710. for (var i = 0, len = pattern.length, c
  21711. ; (i < len) && (c = pattern.charAt(i))
  21712. ; i++) {
  21713. this.debug('%s\t%s %s %j', pattern, i, re, c);
  21714. // skip over any that are escaped.
  21715. if (escaping && reSpecials[c]) {
  21716. re += '\\' + c;
  21717. escaping = false;
  21718. continue
  21719. }
  21720. switch (c) {
  21721. case '/':
  21722. // completely not allowed, even escaped.
  21723. // Should already be path-split by now.
  21724. return false
  21725. case '\\':
  21726. clearStateChar();
  21727. escaping = true;
  21728. continue
  21729. // the various stateChar values
  21730. // for the "extglob" stuff.
  21731. case '?':
  21732. case '*':
  21733. case '+':
  21734. case '@':
  21735. case '!':
  21736. this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c);
  21737. // all of those are literals inside a class, except that
  21738. // the glob [!a] means [^a] in regexp
  21739. if (inClass) {
  21740. this.debug(' in class');
  21741. if (c === '!' && i === classStart + 1) c = '^';
  21742. re += c;
  21743. continue
  21744. }
  21745. // if we already have a stateChar, then it means
  21746. // that there was something like ** or +? in there.
  21747. // Handle the stateChar, then proceed with this one.
  21748. self.debug('call clearStateChar %j', stateChar);
  21749. clearStateChar();
  21750. stateChar = c;
  21751. // if extglob is disabled, then +(asdf|foo) isn't a thing.
  21752. // just clear the statechar *now*, rather than even diving into
  21753. // the patternList stuff.
  21754. if (options.noext) clearStateChar();
  21755. continue
  21756. case '(':
  21757. if (inClass) {
  21758. re += '(';
  21759. continue
  21760. }
  21761. if (!stateChar) {
  21762. re += '\\(';
  21763. continue
  21764. }
  21765. patternListStack.push({
  21766. type: stateChar,
  21767. start: i - 1,
  21768. reStart: re.length,
  21769. open: plTypes[stateChar].open,
  21770. close: plTypes[stateChar].close
  21771. });
  21772. // negation is (?:(?!js)[^/]*)
  21773. re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
  21774. this.debug('plType %j %j', stateChar, re);
  21775. stateChar = false;
  21776. continue
  21777. case ')':
  21778. if (inClass || !patternListStack.length) {
  21779. re += '\\)';
  21780. continue
  21781. }
  21782. clearStateChar();
  21783. hasMagic = true;
  21784. var pl = patternListStack.pop();
  21785. // negation is (?:(?!js)[^/]*)
  21786. // The others are (?:<pattern>)<type>
  21787. re += pl.close;
  21788. if (pl.type === '!') {
  21789. negativeLists.push(pl);
  21790. }
  21791. pl.reEnd = re.length;
  21792. continue
  21793. case '|':
  21794. if (inClass || !patternListStack.length || escaping) {
  21795. re += '\\|';
  21796. escaping = false;
  21797. continue
  21798. }
  21799. clearStateChar();
  21800. re += '|';
  21801. continue
  21802. // these are mostly the same in regexp and glob
  21803. case '[':
  21804. // swallow any state-tracking char before the [
  21805. clearStateChar();
  21806. if (inClass) {
  21807. re += '\\' + c;
  21808. continue
  21809. }
  21810. inClass = true;
  21811. classStart = i;
  21812. reClassStart = re.length;
  21813. re += c;
  21814. continue
  21815. case ']':
  21816. // a right bracket shall lose its special
  21817. // meaning and represent itself in
  21818. // a bracket expression if it occurs
  21819. // first in the list. -- POSIX.2 2.8.3.2
  21820. if (i === classStart + 1 || !inClass) {
  21821. re += '\\' + c;
  21822. escaping = false;
  21823. continue
  21824. }
  21825. // handle the case where we left a class open.
  21826. // "[z-a]" is valid, equivalent to "\[z-a\]"
  21827. if (inClass) {
  21828. // split where the last [ was, make sure we don't have
  21829. // an invalid re. if so, re-walk the contents of the
  21830. // would-be class to re-translate any characters that
  21831. // were passed through as-is
  21832. // TODO: It would probably be faster to determine this
  21833. // without a try/catch and a new RegExp, but it's tricky
  21834. // to do safely. For now, this is safe and works.
  21835. var cs = pattern.substring(classStart + 1, i);
  21836. try {
  21837. RegExp('[' + cs + ']');
  21838. } catch (er) {
  21839. // not a valid class!
  21840. var sp = this.parse(cs, SUBPARSE);
  21841. re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
  21842. hasMagic = hasMagic || sp[1];
  21843. inClass = false;
  21844. continue
  21845. }
  21846. }
  21847. // finish up the class.
  21848. hasMagic = true;
  21849. inClass = false;
  21850. re += c;
  21851. continue
  21852. default:
  21853. // swallow any state char that wasn't consumed
  21854. clearStateChar();
  21855. if (escaping) {
  21856. // no need
  21857. escaping = false;
  21858. } else if (reSpecials[c]
  21859. && !(c === '^' && inClass)) {
  21860. re += '\\';
  21861. }
  21862. re += c;
  21863. } // switch
  21864. } // for
  21865. // handle the case where we left a class open.
  21866. // "[abc" is valid, equivalent to "\[abc"
  21867. if (inClass) {
  21868. // split where the last [ was, and escape it
  21869. // this is a huge pita. We now have to re-walk
  21870. // the contents of the would-be class to re-translate
  21871. // any characters that were passed through as-is
  21872. cs = pattern.substr(classStart + 1);
  21873. sp = this.parse(cs, SUBPARSE);
  21874. re = re.substr(0, reClassStart) + '\\[' + sp[0];
  21875. hasMagic = hasMagic || sp[1];
  21876. }
  21877. // handle the case where we had a +( thing at the *end*
  21878. // of the pattern.
  21879. // each pattern list stack adds 3 chars, and we need to go through
  21880. // and escape any | chars that were passed through as-is for the regexp.
  21881. // Go through and escape them, taking care not to double-escape any
  21882. // | chars that were already escaped.
  21883. for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
  21884. var tail = re.slice(pl.reStart + pl.open.length);
  21885. this.debug('setting tail', re, pl);
  21886. // maybe some even number of \, then maybe 1 \, followed by a |
  21887. tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
  21888. if (!$2) {
  21889. // the | isn't already escaped, so escape it.
  21890. $2 = '\\';
  21891. }
  21892. // need to escape all those slashes *again*, without escaping the
  21893. // one that we need for escaping the | character. As it works out,
  21894. // escaping an even number of slashes can be done by simply repeating
  21895. // it exactly after itself. That's why this trick works.
  21896. //
  21897. // I am sorry that you have to see this.
  21898. return $1 + $1 + $2 + '|'
  21899. });
  21900. this.debug('tail=%j\n %s', tail, tail, pl, re);
  21901. var t = pl.type === '*' ? star
  21902. : pl.type === '?' ? qmark
  21903. : '\\' + pl.type;
  21904. hasMagic = true;
  21905. re = re.slice(0, pl.reStart) + t + '\\(' + tail;
  21906. }
  21907. // handle trailing things that only matter at the very end.
  21908. clearStateChar();
  21909. if (escaping) {
  21910. // trailing \\
  21911. re += '\\\\';
  21912. }
  21913. // only need to apply the nodot start if the re starts with
  21914. // something that could conceivably capture a dot
  21915. var addPatternStart = false;
  21916. switch (re.charAt(0)) {
  21917. case '.':
  21918. case '[':
  21919. case '(': addPatternStart = true;
  21920. }
  21921. // Hack to work around lack of negative lookbehind in JS
  21922. // A pattern like: *.!(x).!(y|z) needs to ensure that a name
  21923. // like 'a.xyz.yz' doesn't match. So, the first negative
  21924. // lookahead, has to look ALL the way ahead, to the end of
  21925. // the pattern.
  21926. for (var n = negativeLists.length - 1; n > -1; n--) {
  21927. var nl = negativeLists[n];
  21928. var nlBefore = re.slice(0, nl.reStart);
  21929. var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
  21930. var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
  21931. var nlAfter = re.slice(nl.reEnd);
  21932. nlLast += nlAfter;
  21933. // Handle nested stuff like *(*.js|!(*.json)), where open parens
  21934. // mean that we should *not* include the ) in the bit that is considered
  21935. // "after" the negated section.
  21936. var openParensBefore = nlBefore.split('(').length - 1;
  21937. var cleanAfter = nlAfter;
  21938. for (i = 0; i < openParensBefore; i++) {
  21939. cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
  21940. }
  21941. nlAfter = cleanAfter;
  21942. var dollar = '';
  21943. if (nlAfter === '' && isSub !== SUBPARSE) {
  21944. dollar = '$';
  21945. }
  21946. var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
  21947. re = newRe;
  21948. }
  21949. // if the re is not "" at this point, then we need to make sure
  21950. // it doesn't match against an empty path part.
  21951. // Otherwise a/* will match a/, which it should not.
  21952. if (re !== '' && hasMagic) {
  21953. re = '(?=.)' + re;
  21954. }
  21955. if (addPatternStart) {
  21956. re = patternStart + re;
  21957. }
  21958. // parsing just a piece of a larger pattern.
  21959. if (isSub === SUBPARSE) {
  21960. return [re, hasMagic]
  21961. }
  21962. // skip the regexp for non-magical patterns
  21963. // unescape anything in it, though, so that it'll be
  21964. // an exact match against a file etc.
  21965. if (!hasMagic) {
  21966. return globUnescape(pattern)
  21967. }
  21968. var flags = options.nocase ? 'i' : '';
  21969. try {
  21970. var regExp = new RegExp('^' + re + '$', flags);
  21971. } catch (er) {
  21972. // If it was an invalid regular expression, then it can't match
  21973. // anything. This trick looks for a character after the end of
  21974. // the string, which is of course impossible, except in multi-line
  21975. // mode, but it's not a /m regex.
  21976. return new RegExp('$.')
  21977. }
  21978. regExp._glob = pattern;
  21979. regExp._src = re;
  21980. return regExp
  21981. }
  21982. minimatch.makeRe = function (pattern, options) {
  21983. return new Minimatch(pattern, options || {}).makeRe()
  21984. };
  21985. Minimatch.prototype.makeRe = makeRe;
  21986. function makeRe () {
  21987. if (this.regexp || this.regexp === false) return this.regexp
  21988. // at this point, this.set is a 2d array of partial
  21989. // pattern strings, or "**".
  21990. //
  21991. // It's better to use .match(). This function shouldn't
  21992. // be used, really, but it's pretty convenient sometimes,
  21993. // when you just want to work with a regex.
  21994. var set = this.set;
  21995. if (!set.length) {
  21996. this.regexp = false;
  21997. return this.regexp
  21998. }
  21999. var options = this.options;
  22000. var twoStar = options.noglobstar ? star
  22001. : options.dot ? twoStarDot
  22002. : twoStarNoDot;
  22003. var flags = options.nocase ? 'i' : '';
  22004. var re = set.map(function (pattern) {
  22005. return pattern.map(function (p) {
  22006. return (p === GLOBSTAR) ? twoStar
  22007. : (typeof p === 'string') ? regExpEscape(p)
  22008. : p._src
  22009. }).join('\\\/')
  22010. }).join('|');
  22011. // must match entire pattern
  22012. // ending in a * or ** will make it less strict.
  22013. re = '^(?:' + re + ')$';
  22014. // can match anything, as long as it's not this.
  22015. if (this.negate) re = '^(?!' + re + ').*$';
  22016. try {
  22017. this.regexp = new RegExp(re, flags);
  22018. } catch (ex) {
  22019. this.regexp = false;
  22020. }
  22021. return this.regexp
  22022. }
  22023. minimatch.match = function (list, pattern, options) {
  22024. options = options || {};
  22025. var mm = new Minimatch(pattern, options);
  22026. list = list.filter(function (f) {
  22027. return mm.match(f)
  22028. });
  22029. if (mm.options.nonull && !list.length) {
  22030. list.push(pattern);
  22031. }
  22032. return list
  22033. };
  22034. Minimatch.prototype.match = match;
  22035. function match (f, partial) {
  22036. this.debug('match', f, this.pattern);
  22037. // short-circuit in the case of busted things.
  22038. // comments, etc.
  22039. if (this.comment) return false
  22040. if (this.empty) return f === ''
  22041. if (f === '/' && partial) return true
  22042. var options = this.options;
  22043. // windows: need to use /, not \
  22044. if (path$3.sep !== '/') {
  22045. f = f.split(path$3.sep).join('/');
  22046. }
  22047. // treat the test path as a set of pathparts.
  22048. f = f.split(slashSplit);
  22049. this.debug(this.pattern, 'split', f);
  22050. // just ONE of the pattern sets in this.set needs to match
  22051. // in order for it to be valid. If negating, then just one
  22052. // match means that we have failed.
  22053. // Either way, return on the first hit.
  22054. var set = this.set;
  22055. this.debug(this.pattern, 'set', set);
  22056. // Find the basename of the path by looking for the last non-empty segment
  22057. var filename;
  22058. var i;
  22059. for (i = f.length - 1; i >= 0; i--) {
  22060. filename = f[i];
  22061. if (filename) break
  22062. }
  22063. for (i = 0; i < set.length; i++) {
  22064. var pattern = set[i];
  22065. var file = f;
  22066. if (options.matchBase && pattern.length === 1) {
  22067. file = [filename];
  22068. }
  22069. var hit = this.matchOne(file, pattern, partial);
  22070. if (hit) {
  22071. if (options.flipNegate) return true
  22072. return !this.negate
  22073. }
  22074. }
  22075. // didn't get any hits. this is success if it's a negative
  22076. // pattern, failure otherwise.
  22077. if (options.flipNegate) return false
  22078. return this.negate
  22079. }
  22080. // set partial to true to test if, for example,
  22081. // "/a/b" matches the start of "/*/b/*/d"
  22082. // Partial means, if you run out of file before you run
  22083. // out of pattern, then that's fine, as long as all
  22084. // the parts match.
  22085. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  22086. var options = this.options;
  22087. this.debug('matchOne',
  22088. { 'this': this, file: file, pattern: pattern });
  22089. this.debug('matchOne', file.length, pattern.length);
  22090. for (var fi = 0,
  22091. pi = 0,
  22092. fl = file.length,
  22093. pl = pattern.length
  22094. ; (fi < fl) && (pi < pl)
  22095. ; fi++, pi++) {
  22096. this.debug('matchOne loop');
  22097. var p = pattern[pi];
  22098. var f = file[fi];
  22099. this.debug(pattern, p, f);
  22100. // should be impossible.
  22101. // some invalid regexp stuff in the set.
  22102. if (p === false) return false
  22103. if (p === GLOBSTAR) {
  22104. this.debug('GLOBSTAR', [pattern, p, f]);
  22105. // "**"
  22106. // a/**/b/**/c would match the following:
  22107. // a/b/x/y/z/c
  22108. // a/x/y/z/b/c
  22109. // a/b/x/b/x/c
  22110. // a/b/c
  22111. // To do this, take the rest of the pattern after
  22112. // the **, and see if it would match the file remainder.
  22113. // If so, return success.
  22114. // If not, the ** "swallows" a segment, and try again.
  22115. // This is recursively awful.
  22116. //
  22117. // a/**/b/**/c matching a/b/x/y/z/c
  22118. // - a matches a
  22119. // - doublestar
  22120. // - matchOne(b/x/y/z/c, b/**/c)
  22121. // - b matches b
  22122. // - doublestar
  22123. // - matchOne(x/y/z/c, c) -> no
  22124. // - matchOne(y/z/c, c) -> no
  22125. // - matchOne(z/c, c) -> no
  22126. // - matchOne(c, c) yes, hit
  22127. var fr = fi;
  22128. var pr = pi + 1;
  22129. if (pr === pl) {
  22130. this.debug('** at the end');
  22131. // a ** at the end will just swallow the rest.
  22132. // We have found a match.
  22133. // however, it will not swallow /.x, unless
  22134. // options.dot is set.
  22135. // . and .. are *never* matched by **, for explosively
  22136. // exponential reasons.
  22137. for (; fi < fl; fi++) {
  22138. if (file[fi] === '.' || file[fi] === '..' ||
  22139. (!options.dot && file[fi].charAt(0) === '.')) return false
  22140. }
  22141. return true
  22142. }
  22143. // ok, let's see if we can swallow whatever we can.
  22144. while (fr < fl) {
  22145. var swallowee = file[fr];
  22146. this.debug('\nglobstar while', file, fr, pattern, pr, swallowee);
  22147. // XXX remove this slice. Just pass the start index.
  22148. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  22149. this.debug('globstar found match!', fr, fl, swallowee);
  22150. // found a match.
  22151. return true
  22152. } else {
  22153. // can't swallow "." or ".." ever.
  22154. // can only swallow ".foo" when explicitly asked.
  22155. if (swallowee === '.' || swallowee === '..' ||
  22156. (!options.dot && swallowee.charAt(0) === '.')) {
  22157. this.debug('dot detected!', file, fr, pattern, pr);
  22158. break
  22159. }
  22160. // ** swallows a segment, and continue.
  22161. this.debug('globstar swallow a segment, and continue');
  22162. fr++;
  22163. }
  22164. }
  22165. // no match was found.
  22166. // However, in partial mode, we can't say this is necessarily over.
  22167. // If there's more *pattern* left, then
  22168. if (partial) {
  22169. // ran out of file
  22170. this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
  22171. if (fr === fl) return true
  22172. }
  22173. return false
  22174. }
  22175. // something other than **
  22176. // non-magic patterns just have to match exactly
  22177. // patterns with magic have been turned into regexps.
  22178. var hit;
  22179. if (typeof p === 'string') {
  22180. if (options.nocase) {
  22181. hit = f.toLowerCase() === p.toLowerCase();
  22182. } else {
  22183. hit = f === p;
  22184. }
  22185. this.debug('string match', p, f, hit);
  22186. } else {
  22187. hit = f.match(p);
  22188. this.debug('pattern match', p, f, hit);
  22189. }
  22190. if (!hit) return false
  22191. }
  22192. // Note: ending in / means that we'll get a final ""
  22193. // at the end of the pattern. This can only match a
  22194. // corresponding "" at the end of the file.
  22195. // If the file ends in /, then it can only match a
  22196. // a pattern that ends in /, unless the pattern just
  22197. // doesn't have any more for it. But, a/b/ should *not*
  22198. // match "a/b/*", even though "" matches against the
  22199. // [^/]*? pattern, except in partial mode, where it might
  22200. // simply not be reached yet.
  22201. // However, a/b/ should still satisfy a/*
  22202. // now either we fell off the end of the pattern, or we're done.
  22203. if (fi === fl && pi === pl) {
  22204. // ran out of pattern and filename at the same time.
  22205. // an exact hit!
  22206. return true
  22207. } else if (fi === fl) {
  22208. // ran out of file, but still had pattern left.
  22209. // this is ok if we're doing the match as part of
  22210. // a glob fs traversal.
  22211. return partial
  22212. } else if (pi === pl) {
  22213. // ran out of pattern, still have file left.
  22214. // this is only acceptable if we're on the very last
  22215. // empty segment of a file with a trailing slash.
  22216. // a/* should match a/b/
  22217. var emptyFileEnd = (fi === fl - 1) && (file[fi] === '');
  22218. return emptyFileEnd
  22219. }
  22220. // should be unreachable.
  22221. throw new Error('wtf?')
  22222. };
  22223. // replace stuff like \* with *
  22224. function globUnescape (s) {
  22225. return s.replace(/\\(.)/g, '$1')
  22226. }
  22227. function regExpEscape (s) {
  22228. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
  22229. }
  22230. var mimicFn = (to, from) => {
  22231. // TODO: use `Reflect.ownKeys()` when targeting Node.js 6
  22232. for (const prop of Object.getOwnPropertyNames(from).concat(Object.getOwnPropertySymbols(from))) {
  22233. Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
  22234. }
  22235. };
  22236. var mem = createCommonjsModule(function (module) {
  22237. 'use strict';
  22238. const cacheStore = new WeakMap();
  22239. const defaultCacheKey = function (x) {
  22240. if (arguments.length === 1 && (x === null || x === undefined || (typeof x !== 'function' && typeof x !== 'object'))) {
  22241. return x;
  22242. }
  22243. return JSON.stringify(arguments);
  22244. };
  22245. module.exports = (fn, opts) => {
  22246. opts = Object.assign({
  22247. cacheKey: defaultCacheKey,
  22248. cache: new Map()
  22249. }, opts);
  22250. const memoized = function () {
  22251. const cache = cacheStore.get(memoized);
  22252. const key = opts.cacheKey.apply(null, arguments);
  22253. if (cache.has(key)) {
  22254. const c = cache.get(key);
  22255. if (typeof opts.maxAge !== 'number' || Date.now() < c.maxAge) {
  22256. return c.data;
  22257. }
  22258. }
  22259. const ret = fn.apply(null, arguments);
  22260. cache.set(key, {
  22261. data: ret,
  22262. maxAge: Date.now() + (opts.maxAge || 0)
  22263. });
  22264. return ret;
  22265. };
  22266. mimicFn(memoized, fn);
  22267. cacheStore.set(memoized, opts.cache);
  22268. return memoized;
  22269. };
  22270. module.exports.clear = fn => {
  22271. const cache = cacheStore.get(fn);
  22272. if (cache && typeof cache.clear === 'function') {
  22273. cache.clear();
  22274. }
  22275. };
  22276. });
  22277. var semver$3 = createCommonjsModule(function (module, exports) {
  22278. exports = module.exports = SemVer;
  22279. // The debug function is excluded entirely from the minified version.
  22280. /* nomin */ var debug;
  22281. /* nomin */ if (typeof process === 'object' &&
  22282. /* nomin */ process.env &&
  22283. /* nomin */ process.env.NODE_DEBUG &&
  22284. /* nomin */ /\bsemver\b/i.test(process.env.NODE_DEBUG))
  22285. /* nomin */ debug = function() {
  22286. /* nomin */ var args = Array.prototype.slice.call(arguments, 0);
  22287. /* nomin */ args.unshift('SEMVER');
  22288. /* nomin */ console.log.apply(console, args);
  22289. /* nomin */ };
  22290. /* nomin */ else
  22291. /* nomin */ debug = function() {};
  22292. // Note: this is the semver.org version of the spec that it implements
  22293. // Not necessarily the package version of this code.
  22294. exports.SEMVER_SPEC_VERSION = '2.0.0';
  22295. var MAX_LENGTH = 256;
  22296. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
  22297. // Max safe segment length for coercion.
  22298. var MAX_SAFE_COMPONENT_LENGTH = 16;
  22299. // The actual regexps go on exports.re
  22300. var re = exports.re = [];
  22301. var src = exports.src = [];
  22302. var R = 0;
  22303. // The following Regular Expressions can be used for tokenizing,
  22304. // validating, and parsing SemVer version strings.
  22305. // ## Numeric Identifier
  22306. // A single `0`, or a non-zero digit followed by zero or more digits.
  22307. var NUMERICIDENTIFIER = R++;
  22308. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  22309. var NUMERICIDENTIFIERLOOSE = R++;
  22310. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+';
  22311. // ## Non-numeric Identifier
  22312. // Zero or more digits, followed by a letter or hyphen, and then zero or
  22313. // more letters, digits, or hyphens.
  22314. var NONNUMERICIDENTIFIER = R++;
  22315. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*';
  22316. // ## Main Version
  22317. // Three dot-separated numeric identifiers.
  22318. var MAINVERSION = R++;
  22319. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' +
  22320. '(' + src[NUMERICIDENTIFIER] + ')\\.' +
  22321. '(' + src[NUMERICIDENTIFIER] + ')';
  22322. var MAINVERSIONLOOSE = R++;
  22323. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
  22324. '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
  22325. '(' + src[NUMERICIDENTIFIERLOOSE] + ')';
  22326. // ## Pre-release Version Identifier
  22327. // A numeric identifier, or a non-numeric identifier.
  22328. var PRERELEASEIDENTIFIER = R++;
  22329. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] +
  22330. '|' + src[NONNUMERICIDENTIFIER] + ')';
  22331. var PRERELEASEIDENTIFIERLOOSE = R++;
  22332. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] +
  22333. '|' + src[NONNUMERICIDENTIFIER] + ')';
  22334. // ## Pre-release Version
  22335. // Hyphen, followed by one or more dot-separated pre-release version
  22336. // identifiers.
  22337. var PRERELEASE = R++;
  22338. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] +
  22339. '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  22340. var PRERELEASELOOSE = R++;
  22341. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] +
  22342. '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))';
  22343. // ## Build Metadata Identifier
  22344. // Any combination of digits, letters, or hyphens.
  22345. var BUILDIDENTIFIER = R++;
  22346. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+';
  22347. // ## Build Metadata
  22348. // Plus sign, followed by one or more period-separated build metadata
  22349. // identifiers.
  22350. var BUILD = R++;
  22351. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] +
  22352. '(?:\\.' + src[BUILDIDENTIFIER] + ')*))';
  22353. // ## Full Version String
  22354. // A main version, followed optionally by a pre-release version and
  22355. // build metadata.
  22356. // Note that the only major, minor, patch, and pre-release sections of
  22357. // the version string are capturing groups. The build metadata is not a
  22358. // capturing group, because it should not ever be used in version
  22359. // comparison.
  22360. var FULL = R++;
  22361. var FULLPLAIN = 'v?' + src[MAINVERSION] +
  22362. src[PRERELEASE] + '?' +
  22363. src[BUILD] + '?';
  22364. src[FULL] = '^' + FULLPLAIN + '$';
  22365. // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  22366. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  22367. // common in the npm registry.
  22368. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] +
  22369. src[PRERELEASELOOSE] + '?' +
  22370. src[BUILD] + '?';
  22371. var LOOSE = R++;
  22372. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  22373. var GTLT = R++;
  22374. src[GTLT] = '((?:<|>)?=?)';
  22375. // Something like "2.*" or "1.2.x".
  22376. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  22377. // Only the first item is strictly required.
  22378. var XRANGEIDENTIFIERLOOSE = R++;
  22379. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  22380. var XRANGEIDENTIFIER = R++;
  22381. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  22382. var XRANGEPLAIN = R++;
  22383. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' +
  22384. '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
  22385. '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
  22386. '(?:' + src[PRERELEASE] + ')?' +
  22387. src[BUILD] + '?' +
  22388. ')?)?';
  22389. var XRANGEPLAINLOOSE = R++;
  22390. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
  22391. '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
  22392. '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
  22393. '(?:' + src[PRERELEASELOOSE] + ')?' +
  22394. src[BUILD] + '?' +
  22395. ')?)?';
  22396. var XRANGE = R++;
  22397. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  22398. var XRANGELOOSE = R++;
  22399. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$';
  22400. // Coercion.
  22401. // Extract anything that could conceivably be a part of a valid semver
  22402. var COERCE = R++;
  22403. src[COERCE] = '(?:^|[^\\d])' +
  22404. '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' +
  22405. '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
  22406. '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
  22407. '(?:$|[^\\d])';
  22408. // Tilde ranges.
  22409. // Meaning is "reasonably at or greater than"
  22410. var LONETILDE = R++;
  22411. src[LONETILDE] = '(?:~>?)';
  22412. var TILDETRIM = R++;
  22413. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  22414. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  22415. var tildeTrimReplace = '$1~';
  22416. var TILDE = R++;
  22417. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  22418. var TILDELOOSE = R++;
  22419. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$';
  22420. // Caret ranges.
  22421. // Meaning is "at least and backwards compatible with"
  22422. var LONECARET = R++;
  22423. src[LONECARET] = '(?:\\^)';
  22424. var CARETTRIM = R++;
  22425. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  22426. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  22427. var caretTrimReplace = '$1^';
  22428. var CARET = R++;
  22429. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  22430. var CARETLOOSE = R++;
  22431. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$';
  22432. // A simple gt/lt/eq thing, or just "" to indicate "any version"
  22433. var COMPARATORLOOSE = R++;
  22434. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  22435. var COMPARATOR = R++;
  22436. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$';
  22437. // An expression to strip any whitespace between the gtlt and the thing
  22438. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  22439. var COMPARATORTRIM = R++;
  22440. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] +
  22441. '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')';
  22442. // this one has to use the /g flag
  22443. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  22444. var comparatorTrimReplace = '$1$2$3';
  22445. // Something like `1.2.3 - 1.2.4`
  22446. // Note that these all use the loose form, because they'll be
  22447. // checked against either the strict or loose comparator form
  22448. // later.
  22449. var HYPHENRANGE = R++;
  22450. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' +
  22451. '\\s+-\\s+' +
  22452. '(' + src[XRANGEPLAIN] + ')' +
  22453. '\\s*$';
  22454. var HYPHENRANGELOOSE = R++;
  22455. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' +
  22456. '\\s+-\\s+' +
  22457. '(' + src[XRANGEPLAINLOOSE] + ')' +
  22458. '\\s*$';
  22459. // Star ranges basically just allow anything at all.
  22460. var STAR = R++;
  22461. src[STAR] = '(<|>)?=?\\s*\\*';
  22462. // Compile to actual regexp objects.
  22463. // All are flag-free, unless they were created above with a flag.
  22464. for (var i = 0; i < R; i++) {
  22465. debug(i, src[i]);
  22466. if (!re[i])
  22467. re[i] = new RegExp(src[i]);
  22468. }
  22469. exports.parse = parse;
  22470. function parse(version, loose) {
  22471. if (version instanceof SemVer)
  22472. return version;
  22473. if (typeof version !== 'string')
  22474. return null;
  22475. if (version.length > MAX_LENGTH)
  22476. return null;
  22477. var r = loose ? re[LOOSE] : re[FULL];
  22478. if (!r.test(version))
  22479. return null;
  22480. try {
  22481. return new SemVer(version, loose);
  22482. } catch (er) {
  22483. return null;
  22484. }
  22485. }
  22486. exports.valid = valid;
  22487. function valid(version, loose) {
  22488. var v = parse(version, loose);
  22489. return v ? v.version : null;
  22490. }
  22491. exports.clean = clean;
  22492. function clean(version, loose) {
  22493. var s = parse(version.trim().replace(/^[=v]+/, ''), loose);
  22494. return s ? s.version : null;
  22495. }
  22496. exports.SemVer = SemVer;
  22497. function SemVer(version, loose) {
  22498. if (version instanceof SemVer) {
  22499. if (version.loose === loose)
  22500. return version;
  22501. else
  22502. version = version.version;
  22503. } else if (typeof version !== 'string') {
  22504. throw new TypeError('Invalid Version: ' + version);
  22505. }
  22506. if (version.length > MAX_LENGTH)
  22507. throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters')
  22508. if (!(this instanceof SemVer))
  22509. return new SemVer(version, loose);
  22510. debug('SemVer', version, loose);
  22511. this.loose = loose;
  22512. var m = version.trim().match(loose ? re[LOOSE] : re[FULL]);
  22513. if (!m)
  22514. throw new TypeError('Invalid Version: ' + version);
  22515. this.raw = version;
  22516. // these are actually numbers
  22517. this.major = +m[1];
  22518. this.minor = +m[2];
  22519. this.patch = +m[3];
  22520. if (this.major > MAX_SAFE_INTEGER || this.major < 0)
  22521. throw new TypeError('Invalid major version')
  22522. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0)
  22523. throw new TypeError('Invalid minor version')
  22524. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0)
  22525. throw new TypeError('Invalid patch version')
  22526. // numberify any prerelease numeric ids
  22527. if (!m[4])
  22528. this.prerelease = [];
  22529. else
  22530. this.prerelease = m[4].split('.').map(function(id) {
  22531. if (/^[0-9]+$/.test(id)) {
  22532. var num = +id;
  22533. if (num >= 0 && num < MAX_SAFE_INTEGER)
  22534. return num;
  22535. }
  22536. return id;
  22537. });
  22538. this.build = m[5] ? m[5].split('.') : [];
  22539. this.format();
  22540. }
  22541. SemVer.prototype.format = function() {
  22542. this.version = this.major + '.' + this.minor + '.' + this.patch;
  22543. if (this.prerelease.length)
  22544. this.version += '-' + this.prerelease.join('.');
  22545. return this.version;
  22546. };
  22547. SemVer.prototype.toString = function() {
  22548. return this.version;
  22549. };
  22550. SemVer.prototype.compare = function(other) {
  22551. debug('SemVer.compare', this.version, this.loose, other);
  22552. if (!(other instanceof SemVer))
  22553. other = new SemVer(other, this.loose);
  22554. return this.compareMain(other) || this.comparePre(other);
  22555. };
  22556. SemVer.prototype.compareMain = function(other) {
  22557. if (!(other instanceof SemVer))
  22558. other = new SemVer(other, this.loose);
  22559. return compareIdentifiers(this.major, other.major) ||
  22560. compareIdentifiers(this.minor, other.minor) ||
  22561. compareIdentifiers(this.patch, other.patch);
  22562. };
  22563. SemVer.prototype.comparePre = function(other) {
  22564. if (!(other instanceof SemVer))
  22565. other = new SemVer(other, this.loose);
  22566. // NOT having a prerelease is > having one
  22567. if (this.prerelease.length && !other.prerelease.length)
  22568. return -1;
  22569. else if (!this.prerelease.length && other.prerelease.length)
  22570. return 1;
  22571. else if (!this.prerelease.length && !other.prerelease.length)
  22572. return 0;
  22573. var i = 0;
  22574. do {
  22575. var a = this.prerelease[i];
  22576. var b = other.prerelease[i];
  22577. debug('prerelease compare', i, a, b);
  22578. if (a === undefined && b === undefined)
  22579. return 0;
  22580. else if (b === undefined)
  22581. return 1;
  22582. else if (a === undefined)
  22583. return -1;
  22584. else if (a === b)
  22585. continue;
  22586. else
  22587. return compareIdentifiers(a, b);
  22588. } while (++i);
  22589. };
  22590. // preminor will bump the version up to the next minor release, and immediately
  22591. // down to pre-release. premajor and prepatch work the same way.
  22592. SemVer.prototype.inc = function(release, identifier) {
  22593. switch (release) {
  22594. case 'premajor':
  22595. this.prerelease.length = 0;
  22596. this.patch = 0;
  22597. this.minor = 0;
  22598. this.major++;
  22599. this.inc('pre', identifier);
  22600. break;
  22601. case 'preminor':
  22602. this.prerelease.length = 0;
  22603. this.patch = 0;
  22604. this.minor++;
  22605. this.inc('pre', identifier);
  22606. break;
  22607. case 'prepatch':
  22608. // If this is already a prerelease, it will bump to the next version
  22609. // drop any prereleases that might already exist, since they are not
  22610. // relevant at this point.
  22611. this.prerelease.length = 0;
  22612. this.inc('patch', identifier);
  22613. this.inc('pre', identifier);
  22614. break;
  22615. // If the input is a non-prerelease version, this acts the same as
  22616. // prepatch.
  22617. case 'prerelease':
  22618. if (this.prerelease.length === 0)
  22619. this.inc('patch', identifier);
  22620. this.inc('pre', identifier);
  22621. break;
  22622. case 'major':
  22623. // If this is a pre-major version, bump up to the same major version.
  22624. // Otherwise increment major.
  22625. // 1.0.0-5 bumps to 1.0.0
  22626. // 1.1.0 bumps to 2.0.0
  22627. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0)
  22628. this.major++;
  22629. this.minor = 0;
  22630. this.patch = 0;
  22631. this.prerelease = [];
  22632. break;
  22633. case 'minor':
  22634. // If this is a pre-minor version, bump up to the same minor version.
  22635. // Otherwise increment minor.
  22636. // 1.2.0-5 bumps to 1.2.0
  22637. // 1.2.1 bumps to 1.3.0
  22638. if (this.patch !== 0 || this.prerelease.length === 0)
  22639. this.minor++;
  22640. this.patch = 0;
  22641. this.prerelease = [];
  22642. break;
  22643. case 'patch':
  22644. // If this is not a pre-release version, it will increment the patch.
  22645. // If it is a pre-release it will bump up to the same patch version.
  22646. // 1.2.0-5 patches to 1.2.0
  22647. // 1.2.0 patches to 1.2.1
  22648. if (this.prerelease.length === 0)
  22649. this.patch++;
  22650. this.prerelease = [];
  22651. break;
  22652. // This probably shouldn't be used publicly.
  22653. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  22654. case 'pre':
  22655. if (this.prerelease.length === 0)
  22656. this.prerelease = [0];
  22657. else {
  22658. var i = this.prerelease.length;
  22659. while (--i >= 0) {
  22660. if (typeof this.prerelease[i] === 'number') {
  22661. this.prerelease[i]++;
  22662. i = -2;
  22663. }
  22664. }
  22665. if (i === -1) // didn't increment anything
  22666. this.prerelease.push(0);
  22667. }
  22668. if (identifier) {
  22669. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  22670. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  22671. if (this.prerelease[0] === identifier) {
  22672. if (isNaN(this.prerelease[1]))
  22673. this.prerelease = [identifier, 0];
  22674. } else
  22675. this.prerelease = [identifier, 0];
  22676. }
  22677. break;
  22678. default:
  22679. throw new Error('invalid increment argument: ' + release);
  22680. }
  22681. this.format();
  22682. this.raw = this.version;
  22683. return this;
  22684. };
  22685. exports.inc = inc;
  22686. function inc(version, release, loose, identifier) {
  22687. if (typeof(loose) === 'string') {
  22688. identifier = loose;
  22689. loose = undefined;
  22690. }
  22691. try {
  22692. return new SemVer(version, loose).inc(release, identifier).version;
  22693. } catch (er) {
  22694. return null;
  22695. }
  22696. }
  22697. exports.diff = diff;
  22698. function diff(version1, version2) {
  22699. if (eq(version1, version2)) {
  22700. return null;
  22701. } else {
  22702. var v1 = parse(version1);
  22703. var v2 = parse(version2);
  22704. if (v1.prerelease.length || v2.prerelease.length) {
  22705. for (var key in v1) {
  22706. if (key === 'major' || key === 'minor' || key === 'patch') {
  22707. if (v1[key] !== v2[key]) {
  22708. return 'pre'+key;
  22709. }
  22710. }
  22711. }
  22712. return 'prerelease';
  22713. }
  22714. for (var key in v1) {
  22715. if (key === 'major' || key === 'minor' || key === 'patch') {
  22716. if (v1[key] !== v2[key]) {
  22717. return key;
  22718. }
  22719. }
  22720. }
  22721. }
  22722. }
  22723. exports.compareIdentifiers = compareIdentifiers;
  22724. var numeric = /^[0-9]+$/;
  22725. function compareIdentifiers(a, b) {
  22726. var anum = numeric.test(a);
  22727. var bnum = numeric.test(b);
  22728. if (anum && bnum) {
  22729. a = +a;
  22730. b = +b;
  22731. }
  22732. return (anum && !bnum) ? -1 :
  22733. (bnum && !anum) ? 1 :
  22734. a < b ? -1 :
  22735. a > b ? 1 :
  22736. 0;
  22737. }
  22738. exports.rcompareIdentifiers = rcompareIdentifiers;
  22739. function rcompareIdentifiers(a, b) {
  22740. return compareIdentifiers(b, a);
  22741. }
  22742. exports.major = major;
  22743. function major(a, loose) {
  22744. return new SemVer(a, loose).major;
  22745. }
  22746. exports.minor = minor;
  22747. function minor(a, loose) {
  22748. return new SemVer(a, loose).minor;
  22749. }
  22750. exports.patch = patch;
  22751. function patch(a, loose) {
  22752. return new SemVer(a, loose).patch;
  22753. }
  22754. exports.compare = compare;
  22755. function compare(a, b, loose) {
  22756. return new SemVer(a, loose).compare(new SemVer(b, loose));
  22757. }
  22758. exports.compareLoose = compareLoose;
  22759. function compareLoose(a, b) {
  22760. return compare(a, b, true);
  22761. }
  22762. exports.rcompare = rcompare;
  22763. function rcompare(a, b, loose) {
  22764. return compare(b, a, loose);
  22765. }
  22766. exports.sort = sort;
  22767. function sort(list, loose) {
  22768. return list.sort(function(a, b) {
  22769. return exports.compare(a, b, loose);
  22770. });
  22771. }
  22772. exports.rsort = rsort;
  22773. function rsort(list, loose) {
  22774. return list.sort(function(a, b) {
  22775. return exports.rcompare(a, b, loose);
  22776. });
  22777. }
  22778. exports.gt = gt;
  22779. function gt(a, b, loose) {
  22780. return compare(a, b, loose) > 0;
  22781. }
  22782. exports.lt = lt;
  22783. function lt(a, b, loose) {
  22784. return compare(a, b, loose) < 0;
  22785. }
  22786. exports.eq = eq;
  22787. function eq(a, b, loose) {
  22788. return compare(a, b, loose) === 0;
  22789. }
  22790. exports.neq = neq;
  22791. function neq(a, b, loose) {
  22792. return compare(a, b, loose) !== 0;
  22793. }
  22794. exports.gte = gte;
  22795. function gte(a, b, loose) {
  22796. return compare(a, b, loose) >= 0;
  22797. }
  22798. exports.lte = lte;
  22799. function lte(a, b, loose) {
  22800. return compare(a, b, loose) <= 0;
  22801. }
  22802. exports.cmp = cmp;
  22803. function cmp(a, op, b, loose) {
  22804. var ret;
  22805. switch (op) {
  22806. case '===':
  22807. if (typeof a === 'object') a = a.version;
  22808. if (typeof b === 'object') b = b.version;
  22809. ret = a === b;
  22810. break;
  22811. case '!==':
  22812. if (typeof a === 'object') a = a.version;
  22813. if (typeof b === 'object') b = b.version;
  22814. ret = a !== b;
  22815. break;
  22816. case '': case '=': case '==': ret = eq(a, b, loose); break;
  22817. case '!=': ret = neq(a, b, loose); break;
  22818. case '>': ret = gt(a, b, loose); break;
  22819. case '>=': ret = gte(a, b, loose); break;
  22820. case '<': ret = lt(a, b, loose); break;
  22821. case '<=': ret = lte(a, b, loose); break;
  22822. default: throw new TypeError('Invalid operator: ' + op);
  22823. }
  22824. return ret;
  22825. }
  22826. exports.Comparator = Comparator;
  22827. function Comparator(comp, loose) {
  22828. if (comp instanceof Comparator) {
  22829. if (comp.loose === loose)
  22830. return comp;
  22831. else
  22832. comp = comp.value;
  22833. }
  22834. if (!(this instanceof Comparator))
  22835. return new Comparator(comp, loose);
  22836. debug('comparator', comp, loose);
  22837. this.loose = loose;
  22838. this.parse(comp);
  22839. if (this.semver === ANY)
  22840. this.value = '';
  22841. else
  22842. this.value = this.operator + this.semver.version;
  22843. debug('comp', this);
  22844. }
  22845. var ANY = {};
  22846. Comparator.prototype.parse = function(comp) {
  22847. var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  22848. var m = comp.match(r);
  22849. if (!m)
  22850. throw new TypeError('Invalid comparator: ' + comp);
  22851. this.operator = m[1];
  22852. if (this.operator === '=')
  22853. this.operator = '';
  22854. // if it literally is just '>' or '' then allow anything.
  22855. if (!m[2])
  22856. this.semver = ANY;
  22857. else
  22858. this.semver = new SemVer(m[2], this.loose);
  22859. };
  22860. Comparator.prototype.toString = function() {
  22861. return this.value;
  22862. };
  22863. Comparator.prototype.test = function(version) {
  22864. debug('Comparator.test', version, this.loose);
  22865. if (this.semver === ANY)
  22866. return true;
  22867. if (typeof version === 'string')
  22868. version = new SemVer(version, this.loose);
  22869. return cmp(version, this.operator, this.semver, this.loose);
  22870. };
  22871. Comparator.prototype.intersects = function(comp, loose) {
  22872. if (!(comp instanceof Comparator)) {
  22873. throw new TypeError('a Comparator is required');
  22874. }
  22875. var rangeTmp;
  22876. if (this.operator === '') {
  22877. rangeTmp = new Range(comp.value, loose);
  22878. return satisfies(this.value, rangeTmp, loose);
  22879. } else if (comp.operator === '') {
  22880. rangeTmp = new Range(this.value, loose);
  22881. return satisfies(comp.semver, rangeTmp, loose);
  22882. }
  22883. var sameDirectionIncreasing =
  22884. (this.operator === '>=' || this.operator === '>') &&
  22885. (comp.operator === '>=' || comp.operator === '>');
  22886. var sameDirectionDecreasing =
  22887. (this.operator === '<=' || this.operator === '<') &&
  22888. (comp.operator === '<=' || comp.operator === '<');
  22889. var sameSemVer = this.semver.version === comp.semver.version;
  22890. var differentDirectionsInclusive =
  22891. (this.operator === '>=' || this.operator === '<=') &&
  22892. (comp.operator === '>=' || comp.operator === '<=');
  22893. var oppositeDirectionsLessThan =
  22894. cmp(this.semver, '<', comp.semver, loose) &&
  22895. ((this.operator === '>=' || this.operator === '>') &&
  22896. (comp.operator === '<=' || comp.operator === '<'));
  22897. var oppositeDirectionsGreaterThan =
  22898. cmp(this.semver, '>', comp.semver, loose) &&
  22899. ((this.operator === '<=' || this.operator === '<') &&
  22900. (comp.operator === '>=' || comp.operator === '>'));
  22901. return sameDirectionIncreasing || sameDirectionDecreasing ||
  22902. (sameSemVer && differentDirectionsInclusive) ||
  22903. oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  22904. };
  22905. exports.Range = Range;
  22906. function Range(range, loose) {
  22907. if (range instanceof Range) {
  22908. if (range.loose === loose) {
  22909. return range;
  22910. } else {
  22911. return new Range(range.raw, loose);
  22912. }
  22913. }
  22914. if (range instanceof Comparator) {
  22915. return new Range(range.value, loose);
  22916. }
  22917. if (!(this instanceof Range))
  22918. return new Range(range, loose);
  22919. this.loose = loose;
  22920. // First, split based on boolean or ||
  22921. this.raw = range;
  22922. this.set = range.split(/\s*\|\|\s*/).map(function(range) {
  22923. return this.parseRange(range.trim());
  22924. }, this).filter(function(c) {
  22925. // throw out any that are not relevant for whatever reason
  22926. return c.length;
  22927. });
  22928. if (!this.set.length) {
  22929. throw new TypeError('Invalid SemVer Range: ' + range);
  22930. }
  22931. this.format();
  22932. }
  22933. Range.prototype.format = function() {
  22934. this.range = this.set.map(function(comps) {
  22935. return comps.join(' ').trim();
  22936. }).join('||').trim();
  22937. return this.range;
  22938. };
  22939. Range.prototype.toString = function() {
  22940. return this.range;
  22941. };
  22942. Range.prototype.parseRange = function(range) {
  22943. var loose = this.loose;
  22944. range = range.trim();
  22945. debug('range', range, loose);
  22946. // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  22947. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  22948. range = range.replace(hr, hyphenReplace);
  22949. debug('hyphen replace', range);
  22950. // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  22951. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  22952. debug('comparator trim', range, re[COMPARATORTRIM]);
  22953. // `~ 1.2.3` => `~1.2.3`
  22954. range = range.replace(re[TILDETRIM], tildeTrimReplace);
  22955. // `^ 1.2.3` => `^1.2.3`
  22956. range = range.replace(re[CARETTRIM], caretTrimReplace);
  22957. // normalize spaces
  22958. range = range.split(/\s+/).join(' ');
  22959. // At this point, the range is completely trimmed and
  22960. // ready to be split into comparators.
  22961. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  22962. var set = range.split(' ').map(function(comp) {
  22963. return parseComparator(comp, loose);
  22964. }).join(' ').split(/\s+/);
  22965. if (this.loose) {
  22966. // in loose mode, throw out any that are not valid comparators
  22967. set = set.filter(function(comp) {
  22968. return !!comp.match(compRe);
  22969. });
  22970. }
  22971. set = set.map(function(comp) {
  22972. return new Comparator(comp, loose);
  22973. });
  22974. return set;
  22975. };
  22976. Range.prototype.intersects = function(range, loose) {
  22977. if (!(range instanceof Range)) {
  22978. throw new TypeError('a Range is required');
  22979. }
  22980. return this.set.some(function(thisComparators) {
  22981. return thisComparators.every(function(thisComparator) {
  22982. return range.set.some(function(rangeComparators) {
  22983. return rangeComparators.every(function(rangeComparator) {
  22984. return thisComparator.intersects(rangeComparator, loose);
  22985. });
  22986. });
  22987. });
  22988. });
  22989. };
  22990. // Mostly just for testing and legacy API reasons
  22991. exports.toComparators = toComparators;
  22992. function toComparators(range, loose) {
  22993. return new Range(range, loose).set.map(function(comp) {
  22994. return comp.map(function(c) {
  22995. return c.value;
  22996. }).join(' ').trim().split(' ');
  22997. });
  22998. }
  22999. // comprised of xranges, tildes, stars, and gtlt's at this point.
  23000. // already replaced the hyphen ranges
  23001. // turn into a set of JUST comparators.
  23002. function parseComparator(comp, loose) {
  23003. debug('comp', comp);
  23004. comp = replaceCarets(comp, loose);
  23005. debug('caret', comp);
  23006. comp = replaceTildes(comp, loose);
  23007. debug('tildes', comp);
  23008. comp = replaceXRanges(comp, loose);
  23009. debug('xrange', comp);
  23010. comp = replaceStars(comp, loose);
  23011. debug('stars', comp);
  23012. return comp;
  23013. }
  23014. function isX(id) {
  23015. return !id || id.toLowerCase() === 'x' || id === '*';
  23016. }
  23017. // ~, ~> --> * (any, kinda silly)
  23018. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  23019. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  23020. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  23021. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  23022. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  23023. function replaceTildes(comp, loose) {
  23024. return comp.trim().split(/\s+/).map(function(comp) {
  23025. return replaceTilde(comp, loose);
  23026. }).join(' ');
  23027. }
  23028. function replaceTilde(comp, loose) {
  23029. var r = loose ? re[TILDELOOSE] : re[TILDE];
  23030. return comp.replace(r, function(_, M, m, p, pr) {
  23031. debug('tilde', comp, _, M, m, p, pr);
  23032. var ret;
  23033. if (isX(M))
  23034. ret = '';
  23035. else if (isX(m))
  23036. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  23037. else if (isX(p))
  23038. // ~1.2 == >=1.2.0 <1.3.0
  23039. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  23040. else if (pr) {
  23041. debug('replaceTilde pr', pr);
  23042. if (pr.charAt(0) !== '-')
  23043. pr = '-' + pr;
  23044. ret = '>=' + M + '.' + m + '.' + p + pr +
  23045. ' <' + M + '.' + (+m + 1) + '.0';
  23046. } else
  23047. // ~1.2.3 == >=1.2.3 <1.3.0
  23048. ret = '>=' + M + '.' + m + '.' + p +
  23049. ' <' + M + '.' + (+m + 1) + '.0';
  23050. debug('tilde return', ret);
  23051. return ret;
  23052. });
  23053. }
  23054. // ^ --> * (any, kinda silly)
  23055. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  23056. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  23057. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  23058. // ^1.2.3 --> >=1.2.3 <2.0.0
  23059. // ^1.2.0 --> >=1.2.0 <2.0.0
  23060. function replaceCarets(comp, loose) {
  23061. return comp.trim().split(/\s+/).map(function(comp) {
  23062. return replaceCaret(comp, loose);
  23063. }).join(' ');
  23064. }
  23065. function replaceCaret(comp, loose) {
  23066. debug('caret', comp, loose);
  23067. var r = loose ? re[CARETLOOSE] : re[CARET];
  23068. return comp.replace(r, function(_, M, m, p, pr) {
  23069. debug('caret', comp, _, M, m, p, pr);
  23070. var ret;
  23071. if (isX(M))
  23072. ret = '';
  23073. else if (isX(m))
  23074. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  23075. else if (isX(p)) {
  23076. if (M === '0')
  23077. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  23078. else
  23079. ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  23080. } else if (pr) {
  23081. debug('replaceCaret pr', pr);
  23082. if (pr.charAt(0) !== '-')
  23083. pr = '-' + pr;
  23084. if (M === '0') {
  23085. if (m === '0')
  23086. ret = '>=' + M + '.' + m + '.' + p + pr +
  23087. ' <' + M + '.' + m + '.' + (+p + 1);
  23088. else
  23089. ret = '>=' + M + '.' + m + '.' + p + pr +
  23090. ' <' + M + '.' + (+m + 1) + '.0';
  23091. } else
  23092. ret = '>=' + M + '.' + m + '.' + p + pr +
  23093. ' <' + (+M + 1) + '.0.0';
  23094. } else {
  23095. debug('no pr');
  23096. if (M === '0') {
  23097. if (m === '0')
  23098. ret = '>=' + M + '.' + m + '.' + p +
  23099. ' <' + M + '.' + m + '.' + (+p + 1);
  23100. else
  23101. ret = '>=' + M + '.' + m + '.' + p +
  23102. ' <' + M + '.' + (+m + 1) + '.0';
  23103. } else
  23104. ret = '>=' + M + '.' + m + '.' + p +
  23105. ' <' + (+M + 1) + '.0.0';
  23106. }
  23107. debug('caret return', ret);
  23108. return ret;
  23109. });
  23110. }
  23111. function replaceXRanges(comp, loose) {
  23112. debug('replaceXRanges', comp, loose);
  23113. return comp.split(/\s+/).map(function(comp) {
  23114. return replaceXRange(comp, loose);
  23115. }).join(' ');
  23116. }
  23117. function replaceXRange(comp, loose) {
  23118. comp = comp.trim();
  23119. var r = loose ? re[XRANGELOOSE] : re[XRANGE];
  23120. return comp.replace(r, function(ret, gtlt, M, m, p, pr) {
  23121. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  23122. var xM = isX(M);
  23123. var xm = xM || isX(m);
  23124. var xp = xm || isX(p);
  23125. var anyX = xp;
  23126. if (gtlt === '=' && anyX)
  23127. gtlt = '';
  23128. if (xM) {
  23129. if (gtlt === '>' || gtlt === '<') {
  23130. // nothing is allowed
  23131. ret = '<0.0.0';
  23132. } else {
  23133. // nothing is forbidden
  23134. ret = '*';
  23135. }
  23136. } else if (gtlt && anyX) {
  23137. // replace X with 0
  23138. if (xm)
  23139. m = 0;
  23140. if (xp)
  23141. p = 0;
  23142. if (gtlt === '>') {
  23143. // >1 => >=2.0.0
  23144. // >1.2 => >=1.3.0
  23145. // >1.2.3 => >= 1.2.4
  23146. gtlt = '>=';
  23147. if (xm) {
  23148. M = +M + 1;
  23149. m = 0;
  23150. p = 0;
  23151. } else if (xp) {
  23152. m = +m + 1;
  23153. p = 0;
  23154. }
  23155. } else if (gtlt === '<=') {
  23156. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  23157. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  23158. gtlt = '<';
  23159. if (xm)
  23160. M = +M + 1;
  23161. else
  23162. m = +m + 1;
  23163. }
  23164. ret = gtlt + M + '.' + m + '.' + p;
  23165. } else if (xm) {
  23166. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  23167. } else if (xp) {
  23168. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  23169. }
  23170. debug('xRange return', ret);
  23171. return ret;
  23172. });
  23173. }
  23174. // Because * is AND-ed with everything else in the comparator,
  23175. // and '' means "any version", just remove the *s entirely.
  23176. function replaceStars(comp, loose) {
  23177. debug('replaceStars', comp, loose);
  23178. // Looseness is ignored here. star is always as loose as it gets!
  23179. return comp.trim().replace(re[STAR], '');
  23180. }
  23181. // This function is passed to string.replace(re[HYPHENRANGE])
  23182. // M, m, patch, prerelease, build
  23183. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  23184. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  23185. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  23186. function hyphenReplace($0,
  23187. from, fM, fm, fp, fpr, fb,
  23188. to, tM, tm, tp, tpr, tb) {
  23189. if (isX(fM))
  23190. from = '';
  23191. else if (isX(fm))
  23192. from = '>=' + fM + '.0.0';
  23193. else if (isX(fp))
  23194. from = '>=' + fM + '.' + fm + '.0';
  23195. else
  23196. from = '>=' + from;
  23197. if (isX(tM))
  23198. to = '';
  23199. else if (isX(tm))
  23200. to = '<' + (+tM + 1) + '.0.0';
  23201. else if (isX(tp))
  23202. to = '<' + tM + '.' + (+tm + 1) + '.0';
  23203. else if (tpr)
  23204. to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
  23205. else
  23206. to = '<=' + to;
  23207. return (from + ' ' + to).trim();
  23208. }
  23209. // if ANY of the sets match ALL of its comparators, then pass
  23210. Range.prototype.test = function(version) {
  23211. if (!version)
  23212. return false;
  23213. if (typeof version === 'string')
  23214. version = new SemVer(version, this.loose);
  23215. for (var i = 0; i < this.set.length; i++) {
  23216. if (testSet(this.set[i], version))
  23217. return true;
  23218. }
  23219. return false;
  23220. };
  23221. function testSet(set, version) {
  23222. for (var i = 0; i < set.length; i++) {
  23223. if (!set[i].test(version))
  23224. return false;
  23225. }
  23226. if (version.prerelease.length) {
  23227. // Find the set of versions that are allowed to have prereleases
  23228. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  23229. // That should allow `1.2.3-pr.2` to pass.
  23230. // However, `1.2.4-alpha.notready` should NOT be allowed,
  23231. // even though it's within the range set by the comparators.
  23232. for (var i = 0; i < set.length; i++) {
  23233. debug(set[i].semver);
  23234. if (set[i].semver === ANY)
  23235. continue;
  23236. if (set[i].semver.prerelease.length > 0) {
  23237. var allowed = set[i].semver;
  23238. if (allowed.major === version.major &&
  23239. allowed.minor === version.minor &&
  23240. allowed.patch === version.patch)
  23241. return true;
  23242. }
  23243. }
  23244. // Version has a -pre, but it's not one of the ones we like.
  23245. return false;
  23246. }
  23247. return true;
  23248. }
  23249. exports.satisfies = satisfies;
  23250. function satisfies(version, range, loose) {
  23251. try {
  23252. range = new Range(range, loose);
  23253. } catch (er) {
  23254. return false;
  23255. }
  23256. return range.test(version);
  23257. }
  23258. exports.maxSatisfying = maxSatisfying;
  23259. function maxSatisfying(versions, range, loose) {
  23260. var max = null;
  23261. var maxSV = null;
  23262. try {
  23263. var rangeObj = new Range(range, loose);
  23264. } catch (er) {
  23265. return null;
  23266. }
  23267. versions.forEach(function (v) {
  23268. if (rangeObj.test(v)) { // satisfies(v, range, loose)
  23269. if (!max || maxSV.compare(v) === -1) { // compare(max, v, true)
  23270. max = v;
  23271. maxSV = new SemVer(max, loose);
  23272. }
  23273. }
  23274. });
  23275. return max;
  23276. }
  23277. exports.minSatisfying = minSatisfying;
  23278. function minSatisfying(versions, range, loose) {
  23279. var min = null;
  23280. var minSV = null;
  23281. try {
  23282. var rangeObj = new Range(range, loose);
  23283. } catch (er) {
  23284. return null;
  23285. }
  23286. versions.forEach(function (v) {
  23287. if (rangeObj.test(v)) { // satisfies(v, range, loose)
  23288. if (!min || minSV.compare(v) === 1) { // compare(min, v, true)
  23289. min = v;
  23290. minSV = new SemVer(min, loose);
  23291. }
  23292. }
  23293. });
  23294. return min;
  23295. }
  23296. exports.validRange = validRange;
  23297. function validRange(range, loose) {
  23298. try {
  23299. // Return '*' instead of '' so that truthiness works.
  23300. // This will throw if it's invalid anyway
  23301. return new Range(range, loose).range || '*';
  23302. } catch (er) {
  23303. return null;
  23304. }
  23305. }
  23306. // Determine if version is less than all the versions possible in the range
  23307. exports.ltr = ltr;
  23308. function ltr(version, range, loose) {
  23309. return outside(version, range, '<', loose);
  23310. }
  23311. // Determine if version is greater than all the versions possible in the range.
  23312. exports.gtr = gtr;
  23313. function gtr(version, range, loose) {
  23314. return outside(version, range, '>', loose);
  23315. }
  23316. exports.outside = outside;
  23317. function outside(version, range, hilo, loose) {
  23318. version = new SemVer(version, loose);
  23319. range = new Range(range, loose);
  23320. var gtfn, ltefn, ltfn, comp, ecomp;
  23321. switch (hilo) {
  23322. case '>':
  23323. gtfn = gt;
  23324. ltefn = lte;
  23325. ltfn = lt;
  23326. comp = '>';
  23327. ecomp = '>=';
  23328. break;
  23329. case '<':
  23330. gtfn = lt;
  23331. ltefn = gte;
  23332. ltfn = gt;
  23333. comp = '<';
  23334. ecomp = '<=';
  23335. break;
  23336. default:
  23337. throw new TypeError('Must provide a hilo val of "<" or ">"');
  23338. }
  23339. // If it satisifes the range it is not outside
  23340. if (satisfies(version, range, loose)) {
  23341. return false;
  23342. }
  23343. // From now on, variable terms are as if we're in "gtr" mode.
  23344. // but note that everything is flipped for the "ltr" function.
  23345. for (var i = 0; i < range.set.length; ++i) {
  23346. var comparators = range.set[i];
  23347. var high = null;
  23348. var low = null;
  23349. comparators.forEach(function(comparator) {
  23350. if (comparator.semver === ANY) {
  23351. comparator = new Comparator('>=0.0.0');
  23352. }
  23353. high = high || comparator;
  23354. low = low || comparator;
  23355. if (gtfn(comparator.semver, high.semver, loose)) {
  23356. high = comparator;
  23357. } else if (ltfn(comparator.semver, low.semver, loose)) {
  23358. low = comparator;
  23359. }
  23360. });
  23361. // If the edge version comparator has a operator then our version
  23362. // isn't outside it
  23363. if (high.operator === comp || high.operator === ecomp) {
  23364. return false;
  23365. }
  23366. // If the lowest version comparator has an operator and our version
  23367. // is less than it then it isn't higher than the range
  23368. if ((!low.operator || low.operator === comp) &&
  23369. ltefn(version, low.semver)) {
  23370. return false;
  23371. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  23372. return false;
  23373. }
  23374. }
  23375. return true;
  23376. }
  23377. exports.prerelease = prerelease;
  23378. function prerelease(version, loose) {
  23379. var parsed = parse(version, loose);
  23380. return (parsed && parsed.prerelease.length) ? parsed.prerelease : null;
  23381. }
  23382. exports.intersects = intersects;
  23383. function intersects(r1, r2, loose) {
  23384. r1 = new Range(r1, loose);
  23385. r2 = new Range(r2, loose);
  23386. return r1.intersects(r2)
  23387. }
  23388. exports.coerce = coerce;
  23389. function coerce(version) {
  23390. if (version instanceof SemVer)
  23391. return version;
  23392. if (typeof version !== 'string')
  23393. return null;
  23394. var match = version.match(re[COERCE]);
  23395. if (match == null)
  23396. return null;
  23397. return parse((match[1] || '0') + '.' + (match[2] || '0') + '.' + (match[3] || '0'));
  23398. }
  23399. });
  23400. var hasOwnProperty = Object.prototype.hasOwnProperty;
  23401. var pseudomap = PseudoMap;
  23402. function PseudoMap (set) {
  23403. if (!(this instanceof PseudoMap)) // whyyyyyyy
  23404. throw new TypeError("Constructor PseudoMap requires 'new'")
  23405. this.clear();
  23406. if (set) {
  23407. if ((set instanceof PseudoMap) ||
  23408. (typeof Map === 'function' && set instanceof Map))
  23409. set.forEach(function (value, key) {
  23410. this.set(key, value);
  23411. }, this);
  23412. else if (Array.isArray(set))
  23413. set.forEach(function (kv) {
  23414. this.set(kv[0], kv[1]);
  23415. }, this);
  23416. else
  23417. throw new TypeError('invalid argument')
  23418. }
  23419. }
  23420. PseudoMap.prototype.forEach = function (fn, thisp) {
  23421. thisp = thisp || this;
  23422. Object.keys(this._data).forEach(function (k) {
  23423. if (k !== 'size')
  23424. fn.call(thisp, this._data[k].value, this._data[k].key);
  23425. }, this);
  23426. };
  23427. PseudoMap.prototype.has = function (k) {
  23428. return !!find(this._data, k)
  23429. };
  23430. PseudoMap.prototype.get = function (k) {
  23431. var res = find(this._data, k);
  23432. return res && res.value
  23433. };
  23434. PseudoMap.prototype.set = function (k, v) {
  23435. set(this._data, k, v);
  23436. };
  23437. PseudoMap.prototype.delete = function (k) {
  23438. var res = find(this._data, k);
  23439. if (res) {
  23440. delete this._data[res._index];
  23441. this._data.size--;
  23442. }
  23443. };
  23444. PseudoMap.prototype.clear = function () {
  23445. var data = Object.create(null);
  23446. data.size = 0;
  23447. Object.defineProperty(this, '_data', {
  23448. value: data,
  23449. enumerable: false,
  23450. configurable: true,
  23451. writable: false
  23452. });
  23453. };
  23454. Object.defineProperty(PseudoMap.prototype, 'size', {
  23455. get: function () {
  23456. return this._data.size
  23457. },
  23458. set: function (n) {},
  23459. enumerable: true,
  23460. configurable: true
  23461. });
  23462. PseudoMap.prototype.values =
  23463. PseudoMap.prototype.keys =
  23464. PseudoMap.prototype.entries = function () {
  23465. throw new Error('iterators are not implemented in this version')
  23466. };
  23467. // Either identical, or both NaN
  23468. function same (a, b) {
  23469. return a === b || a !== a && b !== b
  23470. }
  23471. function Entry$1 (k, v, i) {
  23472. this.key = k;
  23473. this.value = v;
  23474. this._index = i;
  23475. }
  23476. function find (data, k) {
  23477. for (var i = 0, s = '_' + k, key = s;
  23478. hasOwnProperty.call(data, key);
  23479. key = s + i++) {
  23480. if (same(data[key].key, k))
  23481. return data[key]
  23482. }
  23483. }
  23484. function set (data, k, v) {
  23485. for (var i = 0, s = '_' + k, key = s;
  23486. hasOwnProperty.call(data, key);
  23487. key = s + i++) {
  23488. if (same(data[key].key, k)) {
  23489. data[key].value = v;
  23490. return
  23491. }
  23492. }
  23493. data.size++;
  23494. data[key] = new Entry$1(k, v, key);
  23495. }
  23496. var map = createCommonjsModule(function (module) {
  23497. if (process.env.npm_package_name === 'pseudomap' &&
  23498. process.env.npm_lifecycle_script === 'test')
  23499. process.env.TEST_PSEUDOMAP = 'true';
  23500. if (typeof Map === 'function' && !process.env.TEST_PSEUDOMAP) {
  23501. module.exports = Map;
  23502. } else {
  23503. module.exports = pseudomap;
  23504. }
  23505. });
  23506. var yallist = Yallist;
  23507. Yallist.Node = Node;
  23508. Yallist.create = Yallist;
  23509. function Yallist (list) {
  23510. var self = this;
  23511. if (!(self instanceof Yallist)) {
  23512. self = new Yallist();
  23513. }
  23514. self.tail = null;
  23515. self.head = null;
  23516. self.length = 0;
  23517. if (list && typeof list.forEach === 'function') {
  23518. list.forEach(function (item) {
  23519. self.push(item);
  23520. });
  23521. } else if (arguments.length > 0) {
  23522. for (var i = 0, l = arguments.length; i < l; i++) {
  23523. self.push(arguments[i]);
  23524. }
  23525. }
  23526. return self
  23527. }
  23528. Yallist.prototype.removeNode = function (node) {
  23529. if (node.list !== this) {
  23530. throw new Error('removing node which does not belong to this list')
  23531. }
  23532. var next = node.next;
  23533. var prev = node.prev;
  23534. if (next) {
  23535. next.prev = prev;
  23536. }
  23537. if (prev) {
  23538. prev.next = next;
  23539. }
  23540. if (node === this.head) {
  23541. this.head = next;
  23542. }
  23543. if (node === this.tail) {
  23544. this.tail = prev;
  23545. }
  23546. node.list.length--;
  23547. node.next = null;
  23548. node.prev = null;
  23549. node.list = null;
  23550. };
  23551. Yallist.prototype.unshiftNode = function (node) {
  23552. if (node === this.head) {
  23553. return
  23554. }
  23555. if (node.list) {
  23556. node.list.removeNode(node);
  23557. }
  23558. var head = this.head;
  23559. node.list = this;
  23560. node.next = head;
  23561. if (head) {
  23562. head.prev = node;
  23563. }
  23564. this.head = node;
  23565. if (!this.tail) {
  23566. this.tail = node;
  23567. }
  23568. this.length++;
  23569. };
  23570. Yallist.prototype.pushNode = function (node) {
  23571. if (node === this.tail) {
  23572. return
  23573. }
  23574. if (node.list) {
  23575. node.list.removeNode(node);
  23576. }
  23577. var tail = this.tail;
  23578. node.list = this;
  23579. node.prev = tail;
  23580. if (tail) {
  23581. tail.next = node;
  23582. }
  23583. this.tail = node;
  23584. if (!this.head) {
  23585. this.head = node;
  23586. }
  23587. this.length++;
  23588. };
  23589. Yallist.prototype.push = function () {
  23590. for (var i = 0, l = arguments.length; i < l; i++) {
  23591. push(this, arguments[i]);
  23592. }
  23593. return this.length
  23594. };
  23595. Yallist.prototype.unshift = function () {
  23596. for (var i = 0, l = arguments.length; i < l; i++) {
  23597. unshift(this, arguments[i]);
  23598. }
  23599. return this.length
  23600. };
  23601. Yallist.prototype.pop = function () {
  23602. if (!this.tail) {
  23603. return undefined
  23604. }
  23605. var res = this.tail.value;
  23606. this.tail = this.tail.prev;
  23607. if (this.tail) {
  23608. this.tail.next = null;
  23609. } else {
  23610. this.head = null;
  23611. }
  23612. this.length--;
  23613. return res
  23614. };
  23615. Yallist.prototype.shift = function () {
  23616. if (!this.head) {
  23617. return undefined
  23618. }
  23619. var res = this.head.value;
  23620. this.head = this.head.next;
  23621. if (this.head) {
  23622. this.head.prev = null;
  23623. } else {
  23624. this.tail = null;
  23625. }
  23626. this.length--;
  23627. return res
  23628. };
  23629. Yallist.prototype.forEach = function (fn, thisp) {
  23630. thisp = thisp || this;
  23631. for (var walker = this.head, i = 0; walker !== null; i++) {
  23632. fn.call(thisp, walker.value, i, this);
  23633. walker = walker.next;
  23634. }
  23635. };
  23636. Yallist.prototype.forEachReverse = function (fn, thisp) {
  23637. thisp = thisp || this;
  23638. for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
  23639. fn.call(thisp, walker.value, i, this);
  23640. walker = walker.prev;
  23641. }
  23642. };
  23643. Yallist.prototype.get = function (n) {
  23644. for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
  23645. // abort out of the list early if we hit a cycle
  23646. walker = walker.next;
  23647. }
  23648. if (i === n && walker !== null) {
  23649. return walker.value
  23650. }
  23651. };
  23652. Yallist.prototype.getReverse = function (n) {
  23653. for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
  23654. // abort out of the list early if we hit a cycle
  23655. walker = walker.prev;
  23656. }
  23657. if (i === n && walker !== null) {
  23658. return walker.value
  23659. }
  23660. };
  23661. Yallist.prototype.map = function (fn, thisp) {
  23662. thisp = thisp || this;
  23663. var res = new Yallist();
  23664. for (var walker = this.head; walker !== null;) {
  23665. res.push(fn.call(thisp, walker.value, this));
  23666. walker = walker.next;
  23667. }
  23668. return res
  23669. };
  23670. Yallist.prototype.mapReverse = function (fn, thisp) {
  23671. thisp = thisp || this;
  23672. var res = new Yallist();
  23673. for (var walker = this.tail; walker !== null;) {
  23674. res.push(fn.call(thisp, walker.value, this));
  23675. walker = walker.prev;
  23676. }
  23677. return res
  23678. };
  23679. Yallist.prototype.reduce = function (fn, initial) {
  23680. var acc;
  23681. var walker = this.head;
  23682. if (arguments.length > 1) {
  23683. acc = initial;
  23684. } else if (this.head) {
  23685. walker = this.head.next;
  23686. acc = this.head.value;
  23687. } else {
  23688. throw new TypeError('Reduce of empty list with no initial value')
  23689. }
  23690. for (var i = 0; walker !== null; i++) {
  23691. acc = fn(acc, walker.value, i);
  23692. walker = walker.next;
  23693. }
  23694. return acc
  23695. };
  23696. Yallist.prototype.reduceReverse = function (fn, initial) {
  23697. var acc;
  23698. var walker = this.tail;
  23699. if (arguments.length > 1) {
  23700. acc = initial;
  23701. } else if (this.tail) {
  23702. walker = this.tail.prev;
  23703. acc = this.tail.value;
  23704. } else {
  23705. throw new TypeError('Reduce of empty list with no initial value')
  23706. }
  23707. for (var i = this.length - 1; walker !== null; i--) {
  23708. acc = fn(acc, walker.value, i);
  23709. walker = walker.prev;
  23710. }
  23711. return acc
  23712. };
  23713. Yallist.prototype.toArray = function () {
  23714. var arr = new Array(this.length);
  23715. for (var i = 0, walker = this.head; walker !== null; i++) {
  23716. arr[i] = walker.value;
  23717. walker = walker.next;
  23718. }
  23719. return arr
  23720. };
  23721. Yallist.prototype.toArrayReverse = function () {
  23722. var arr = new Array(this.length);
  23723. for (var i = 0, walker = this.tail; walker !== null; i++) {
  23724. arr[i] = walker.value;
  23725. walker = walker.prev;
  23726. }
  23727. return arr
  23728. };
  23729. Yallist.prototype.slice = function (from, to) {
  23730. to = to || this.length;
  23731. if (to < 0) {
  23732. to += this.length;
  23733. }
  23734. from = from || 0;
  23735. if (from < 0) {
  23736. from += this.length;
  23737. }
  23738. var ret = new Yallist();
  23739. if (to < from || to < 0) {
  23740. return ret
  23741. }
  23742. if (from < 0) {
  23743. from = 0;
  23744. }
  23745. if (to > this.length) {
  23746. to = this.length;
  23747. }
  23748. for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
  23749. walker = walker.next;
  23750. }
  23751. for (; walker !== null && i < to; i++, walker = walker.next) {
  23752. ret.push(walker.value);
  23753. }
  23754. return ret
  23755. };
  23756. Yallist.prototype.sliceReverse = function (from, to) {
  23757. to = to || this.length;
  23758. if (to < 0) {
  23759. to += this.length;
  23760. }
  23761. from = from || 0;
  23762. if (from < 0) {
  23763. from += this.length;
  23764. }
  23765. var ret = new Yallist();
  23766. if (to < from || to < 0) {
  23767. return ret
  23768. }
  23769. if (from < 0) {
  23770. from = 0;
  23771. }
  23772. if (to > this.length) {
  23773. to = this.length;
  23774. }
  23775. for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
  23776. walker = walker.prev;
  23777. }
  23778. for (; walker !== null && i > from; i--, walker = walker.prev) {
  23779. ret.push(walker.value);
  23780. }
  23781. return ret
  23782. };
  23783. Yallist.prototype.reverse = function () {
  23784. var head = this.head;
  23785. var tail = this.tail;
  23786. for (var walker = head; walker !== null; walker = walker.prev) {
  23787. var p = walker.prev;
  23788. walker.prev = walker.next;
  23789. walker.next = p;
  23790. }
  23791. this.head = tail;
  23792. this.tail = head;
  23793. return this
  23794. };
  23795. function push (self, item) {
  23796. self.tail = new Node(item, self.tail, null, self);
  23797. if (!self.head) {
  23798. self.head = self.tail;
  23799. }
  23800. self.length++;
  23801. }
  23802. function unshift (self, item) {
  23803. self.head = new Node(item, null, self.head, self);
  23804. if (!self.tail) {
  23805. self.tail = self.head;
  23806. }
  23807. self.length++;
  23808. }
  23809. function Node (value, prev, next, list) {
  23810. if (!(this instanceof Node)) {
  23811. return new Node(value, prev, next, list)
  23812. }
  23813. this.list = list;
  23814. this.value = value;
  23815. if (prev) {
  23816. prev.next = this;
  23817. this.prev = prev;
  23818. } else {
  23819. this.prev = null;
  23820. }
  23821. if (next) {
  23822. next.prev = this;
  23823. this.next = next;
  23824. } else {
  23825. this.next = null;
  23826. }
  23827. }
  23828. var lruCache = LRUCache;
  23829. // This will be a proper iterable 'Map' in engines that support it,
  23830. // or a fakey-fake PseudoMap in older versions.
  23831. // A linked list to keep track of recently-used-ness
  23832. // use symbols if possible, otherwise just _props
  23833. var hasSymbol = typeof Symbol === 'function';
  23834. var makeSymbol;
  23835. if (hasSymbol) {
  23836. makeSymbol = function (key) {
  23837. return Symbol.for(key)
  23838. };
  23839. } else {
  23840. makeSymbol = function (key) {
  23841. return '_' + key
  23842. };
  23843. }
  23844. var MAX = makeSymbol('max');
  23845. var LENGTH = makeSymbol('length');
  23846. var LENGTH_CALCULATOR = makeSymbol('lengthCalculator');
  23847. var ALLOW_STALE = makeSymbol('allowStale');
  23848. var MAX_AGE = makeSymbol('maxAge');
  23849. var DISPOSE = makeSymbol('dispose');
  23850. var NO_DISPOSE_ON_SET = makeSymbol('noDisposeOnSet');
  23851. var LRU_LIST = makeSymbol('lruList');
  23852. var CACHE = makeSymbol('cache');
  23853. function naiveLength () { return 1 }
  23854. // lruList is a yallist where the head is the youngest
  23855. // item, and the tail is the oldest. the list contains the Hit
  23856. // objects as the entries.
  23857. // Each Hit object has a reference to its Yallist.Node. This
  23858. // never changes.
  23859. //
  23860. // cache is a Map (or PseudoMap) that matches the keys to
  23861. // the Yallist.Node object.
  23862. function LRUCache (options) {
  23863. if (!(this instanceof LRUCache)) {
  23864. return new LRUCache(options)
  23865. }
  23866. if (typeof options === 'number') {
  23867. options = { max: options };
  23868. }
  23869. if (!options) {
  23870. options = {};
  23871. }
  23872. var max = this[MAX] = options.max;
  23873. // Kind of weird to have a default max of Infinity, but oh well.
  23874. if (!max ||
  23875. !(typeof max === 'number') ||
  23876. max <= 0) {
  23877. this[MAX] = Infinity;
  23878. }
  23879. var lc = options.length || naiveLength;
  23880. if (typeof lc !== 'function') {
  23881. lc = naiveLength;
  23882. }
  23883. this[LENGTH_CALCULATOR] = lc;
  23884. this[ALLOW_STALE] = options.stale || false;
  23885. this[MAX_AGE] = options.maxAge || 0;
  23886. this[DISPOSE] = options.dispose;
  23887. this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
  23888. this.reset();
  23889. }
  23890. // resize the cache when the max changes.
  23891. Object.defineProperty(LRUCache.prototype, 'max', {
  23892. set: function (mL) {
  23893. if (!mL || !(typeof mL === 'number') || mL <= 0) {
  23894. mL = Infinity;
  23895. }
  23896. this[MAX] = mL;
  23897. trim(this);
  23898. },
  23899. get: function () {
  23900. return this[MAX]
  23901. },
  23902. enumerable: true
  23903. });
  23904. Object.defineProperty(LRUCache.prototype, 'allowStale', {
  23905. set: function (allowStale) {
  23906. this[ALLOW_STALE] = !!allowStale;
  23907. },
  23908. get: function () {
  23909. return this[ALLOW_STALE]
  23910. },
  23911. enumerable: true
  23912. });
  23913. Object.defineProperty(LRUCache.prototype, 'maxAge', {
  23914. set: function (mA) {
  23915. if (!mA || !(typeof mA === 'number') || mA < 0) {
  23916. mA = 0;
  23917. }
  23918. this[MAX_AGE] = mA;
  23919. trim(this);
  23920. },
  23921. get: function () {
  23922. return this[MAX_AGE]
  23923. },
  23924. enumerable: true
  23925. });
  23926. // resize the cache when the lengthCalculator changes.
  23927. Object.defineProperty(LRUCache.prototype, 'lengthCalculator', {
  23928. set: function (lC) {
  23929. if (typeof lC !== 'function') {
  23930. lC = naiveLength;
  23931. }
  23932. if (lC !== this[LENGTH_CALCULATOR]) {
  23933. this[LENGTH_CALCULATOR] = lC;
  23934. this[LENGTH] = 0;
  23935. this[LRU_LIST].forEach(function (hit) {
  23936. hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
  23937. this[LENGTH] += hit.length;
  23938. }, this);
  23939. }
  23940. trim(this);
  23941. },
  23942. get: function () { return this[LENGTH_CALCULATOR] },
  23943. enumerable: true
  23944. });
  23945. Object.defineProperty(LRUCache.prototype, 'length', {
  23946. get: function () { return this[LENGTH] },
  23947. enumerable: true
  23948. });
  23949. Object.defineProperty(LRUCache.prototype, 'itemCount', {
  23950. get: function () { return this[LRU_LIST].length },
  23951. enumerable: true
  23952. });
  23953. LRUCache.prototype.rforEach = function (fn, thisp) {
  23954. thisp = thisp || this;
  23955. for (var walker = this[LRU_LIST].tail; walker !== null;) {
  23956. var prev = walker.prev;
  23957. forEachStep(this, fn, walker, thisp);
  23958. walker = prev;
  23959. }
  23960. };
  23961. function forEachStep (self, fn, node, thisp) {
  23962. var hit = node.value;
  23963. if (isStale(self, hit)) {
  23964. del(self, node);
  23965. if (!self[ALLOW_STALE]) {
  23966. hit = undefined;
  23967. }
  23968. }
  23969. if (hit) {
  23970. fn.call(thisp, hit.value, hit.key, self);
  23971. }
  23972. }
  23973. LRUCache.prototype.forEach = function (fn, thisp) {
  23974. thisp = thisp || this;
  23975. for (var walker = this[LRU_LIST].head; walker !== null;) {
  23976. var next = walker.next;
  23977. forEachStep(this, fn, walker, thisp);
  23978. walker = next;
  23979. }
  23980. };
  23981. LRUCache.prototype.keys = function () {
  23982. return this[LRU_LIST].toArray().map(function (k) {
  23983. return k.key
  23984. }, this)
  23985. };
  23986. LRUCache.prototype.values = function () {
  23987. return this[LRU_LIST].toArray().map(function (k) {
  23988. return k.value
  23989. }, this)
  23990. };
  23991. LRUCache.prototype.reset = function () {
  23992. if (this[DISPOSE] &&
  23993. this[LRU_LIST] &&
  23994. this[LRU_LIST].length) {
  23995. this[LRU_LIST].forEach(function (hit) {
  23996. this[DISPOSE](hit.key, hit.value);
  23997. }, this);
  23998. }
  23999. this[CACHE] = new map(); // hash of items by key
  24000. this[LRU_LIST] = new yallist(); // list of items in order of use recency
  24001. this[LENGTH] = 0; // length of items in the list
  24002. };
  24003. LRUCache.prototype.dump = function () {
  24004. return this[LRU_LIST].map(function (hit) {
  24005. if (!isStale(this, hit)) {
  24006. return {
  24007. k: hit.key,
  24008. v: hit.value,
  24009. e: hit.now + (hit.maxAge || 0)
  24010. }
  24011. }
  24012. }, this).toArray().filter(function (h) {
  24013. return h
  24014. })
  24015. };
  24016. LRUCache.prototype.dumpLru = function () {
  24017. return this[LRU_LIST]
  24018. };
  24019. LRUCache.prototype.inspect = function (n, opts) {
  24020. var str = 'LRUCache {';
  24021. var extras = false;
  24022. var as = this[ALLOW_STALE];
  24023. if (as) {
  24024. str += '\n allowStale: true';
  24025. extras = true;
  24026. }
  24027. var max = this[MAX];
  24028. if (max && max !== Infinity) {
  24029. if (extras) {
  24030. str += ',';
  24031. }
  24032. str += '\n max: ' + util.inspect(max, opts);
  24033. extras = true;
  24034. }
  24035. var maxAge = this[MAX_AGE];
  24036. if (maxAge) {
  24037. if (extras) {
  24038. str += ',';
  24039. }
  24040. str += '\n maxAge: ' + util.inspect(maxAge, opts);
  24041. extras = true;
  24042. }
  24043. var lc = this[LENGTH_CALCULATOR];
  24044. if (lc && lc !== naiveLength) {
  24045. if (extras) {
  24046. str += ',';
  24047. }
  24048. str += '\n length: ' + util.inspect(this[LENGTH], opts);
  24049. extras = true;
  24050. }
  24051. var didFirst = false;
  24052. this[LRU_LIST].forEach(function (item) {
  24053. if (didFirst) {
  24054. str += ',\n ';
  24055. } else {
  24056. if (extras) {
  24057. str += ',\n';
  24058. }
  24059. didFirst = true;
  24060. str += '\n ';
  24061. }
  24062. var key = util.inspect(item.key).split('\n').join('\n ');
  24063. var val = { value: item.value };
  24064. if (item.maxAge !== maxAge) {
  24065. val.maxAge = item.maxAge;
  24066. }
  24067. if (lc !== naiveLength) {
  24068. val.length = item.length;
  24069. }
  24070. if (isStale(this, item)) {
  24071. val.stale = true;
  24072. }
  24073. val = util.inspect(val, opts).split('\n').join('\n ');
  24074. str += key + ' => ' + val;
  24075. });
  24076. if (didFirst || extras) {
  24077. str += '\n';
  24078. }
  24079. str += '}';
  24080. return str
  24081. };
  24082. LRUCache.prototype.set = function (key, value, maxAge) {
  24083. maxAge = maxAge || this[MAX_AGE];
  24084. var now = maxAge ? Date.now() : 0;
  24085. var len = this[LENGTH_CALCULATOR](value, key);
  24086. if (this[CACHE].has(key)) {
  24087. if (len > this[MAX]) {
  24088. del(this, this[CACHE].get(key));
  24089. return false
  24090. }
  24091. var node = this[CACHE].get(key);
  24092. var item = node.value;
  24093. // dispose of the old one before overwriting
  24094. // split out into 2 ifs for better coverage tracking
  24095. if (this[DISPOSE]) {
  24096. if (!this[NO_DISPOSE_ON_SET]) {
  24097. this[DISPOSE](key, item.value);
  24098. }
  24099. }
  24100. item.now = now;
  24101. item.maxAge = maxAge;
  24102. item.value = value;
  24103. this[LENGTH] += len - item.length;
  24104. item.length = len;
  24105. this.get(key);
  24106. trim(this);
  24107. return true
  24108. }
  24109. var hit = new Entry(key, value, len, now, maxAge);
  24110. // oversized objects fall out of cache automatically.
  24111. if (hit.length > this[MAX]) {
  24112. if (this[DISPOSE]) {
  24113. this[DISPOSE](key, value);
  24114. }
  24115. return false
  24116. }
  24117. this[LENGTH] += hit.length;
  24118. this[LRU_LIST].unshift(hit);
  24119. this[CACHE].set(key, this[LRU_LIST].head);
  24120. trim(this);
  24121. return true
  24122. };
  24123. LRUCache.prototype.has = function (key) {
  24124. if (!this[CACHE].has(key)) return false
  24125. var hit = this[CACHE].get(key).value;
  24126. if (isStale(this, hit)) {
  24127. return false
  24128. }
  24129. return true
  24130. };
  24131. LRUCache.prototype.get = function (key) {
  24132. return get(this, key, true)
  24133. };
  24134. LRUCache.prototype.peek = function (key) {
  24135. return get(this, key, false)
  24136. };
  24137. LRUCache.prototype.pop = function () {
  24138. var node = this[LRU_LIST].tail;
  24139. if (!node) return null
  24140. del(this, node);
  24141. return node.value
  24142. };
  24143. LRUCache.prototype.del = function (key) {
  24144. del(this, this[CACHE].get(key));
  24145. };
  24146. LRUCache.prototype.load = function (arr) {
  24147. // reset the cache
  24148. this.reset();
  24149. var now = Date.now();
  24150. // A previous serialized cache has the most recent items first
  24151. for (var l = arr.length - 1; l >= 0; l--) {
  24152. var hit = arr[l];
  24153. var expiresAt = hit.e || 0;
  24154. if (expiresAt === 0) {
  24155. // the item was created without expiration in a non aged cache
  24156. this.set(hit.k, hit.v);
  24157. } else {
  24158. var maxAge = expiresAt - now;
  24159. // dont add already expired items
  24160. if (maxAge > 0) {
  24161. this.set(hit.k, hit.v, maxAge);
  24162. }
  24163. }
  24164. }
  24165. };
  24166. LRUCache.prototype.prune = function () {
  24167. var self = this;
  24168. this[CACHE].forEach(function (value, key) {
  24169. get(self, key, false);
  24170. });
  24171. };
  24172. function get (self, key, doUse) {
  24173. var node = self[CACHE].get(key);
  24174. if (node) {
  24175. var hit = node.value;
  24176. if (isStale(self, hit)) {
  24177. del(self, node);
  24178. if (!self[ALLOW_STALE]) hit = undefined;
  24179. } else {
  24180. if (doUse) {
  24181. self[LRU_LIST].unshiftNode(node);
  24182. }
  24183. }
  24184. if (hit) hit = hit.value;
  24185. }
  24186. return hit
  24187. }
  24188. function isStale (self, hit) {
  24189. if (!hit || (!hit.maxAge && !self[MAX_AGE])) {
  24190. return false
  24191. }
  24192. var stale = false;
  24193. var diff = Date.now() - hit.now;
  24194. if (hit.maxAge) {
  24195. stale = diff > hit.maxAge;
  24196. } else {
  24197. stale = self[MAX_AGE] && (diff > self[MAX_AGE]);
  24198. }
  24199. return stale
  24200. }
  24201. function trim (self) {
  24202. if (self[LENGTH] > self[MAX]) {
  24203. for (var walker = self[LRU_LIST].tail;
  24204. self[LENGTH] > self[MAX] && walker !== null;) {
  24205. // We know that we're about to delete this one, and also
  24206. // what the next least recently used key will be, so just
  24207. // go ahead and set it now.
  24208. var prev = walker.prev;
  24209. del(self, walker);
  24210. walker = prev;
  24211. }
  24212. }
  24213. }
  24214. function del (self, node) {
  24215. if (node) {
  24216. var hit = node.value;
  24217. if (self[DISPOSE]) {
  24218. self[DISPOSE](hit.key, hit.value);
  24219. }
  24220. self[LENGTH] -= hit.length;
  24221. self[CACHE].delete(hit.key);
  24222. self[LRU_LIST].removeNode(node);
  24223. }
  24224. }
  24225. // classy, since V8 prefers predictable objects.
  24226. function Entry (key, value, length, now, maxAge) {
  24227. this.key = key;
  24228. this.value = value;
  24229. this.length = length;
  24230. this.now = now;
  24231. this.maxAge = maxAge || 0;
  24232. }
  24233. var sigmund_1 = sigmund;
  24234. function sigmund (subject, maxSessions) {
  24235. maxSessions = maxSessions || 10;
  24236. var notes = [];
  24237. var analysis = '';
  24238. var RE = RegExp;
  24239. function psychoAnalyze (subject, session) {
  24240. if (session > maxSessions) return;
  24241. if (typeof subject === 'function' ||
  24242. typeof subject === 'undefined') {
  24243. return;
  24244. }
  24245. if (typeof subject !== 'object' || !subject ||
  24246. (subject instanceof RE)) {
  24247. analysis += subject;
  24248. return;
  24249. }
  24250. if (notes.indexOf(subject) !== -1 || session === maxSessions) return;
  24251. notes.push(subject);
  24252. analysis += '{';
  24253. Object.keys(subject).forEach(function (issue, _, __) {
  24254. // pseudo-private values. skip those.
  24255. if (issue.charAt(0) === '_') return;
  24256. var to = typeof subject[issue];
  24257. if (to === 'function' || to === 'undefined') return;
  24258. analysis += issue;
  24259. psychoAnalyze(subject[issue], session + 1);
  24260. });
  24261. }
  24262. psychoAnalyze(subject, 0);
  24263. return analysis;
  24264. }
  24265. // vim: set softtabstop=4 shiftwidth=4:
  24266. var fnmatch = createCommonjsModule(function (module, exports) {
  24267. // Based on minimatch.js by isaacs <https://npmjs.org/package/minimatch>
  24268. var platform = typeof process === "object" ? process.platform : "win32";
  24269. if (module) module.exports = minimatch;
  24270. else exports.minimatch = minimatch;
  24271. minimatch.Minimatch = Minimatch;
  24272. var cache = minimatch.cache = new lruCache({max: 100})
  24273. , GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
  24274. var qmark = "[^/]"
  24275. // * => any number of characters
  24276. , star = qmark + "*?"
  24277. // ** when dots are allowed. Anything goes, except .. and .
  24278. // not (^ or / followed by one or two dots followed by $ or /),
  24279. // followed by anything, any number of times.
  24280. , twoStarDot = "(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?"
  24281. // not a ^ or / followed by a dot,
  24282. // followed by anything, any number of times.
  24283. , twoStarNoDot = "(?:(?!(?:\\\/|^)\\.).)*?"
  24284. // characters that need to be escaped in RegExp.
  24285. , reSpecials = charSet("().*{}+?[]^$\\!");
  24286. // "abc" -> { a:true, b:true, c:true }
  24287. function charSet (s) {
  24288. return s.split("").reduce(function (set, c) {
  24289. set[c] = true;
  24290. return set
  24291. }, {})
  24292. }
  24293. // normalizes slashes.
  24294. var slashSplit = /\/+/;
  24295. minimatch.monkeyPatch = monkeyPatch;
  24296. function monkeyPatch () {
  24297. var desc = Object.getOwnPropertyDescriptor(String.prototype, "match");
  24298. var orig = desc.value;
  24299. desc.value = function (p) {
  24300. if (p instanceof Minimatch) return p.match(this)
  24301. return orig.call(this, p)
  24302. };
  24303. Object.defineProperty(String.prototype, desc);
  24304. }
  24305. minimatch.filter = filter;
  24306. function filter (pattern, options) {
  24307. options = options || {};
  24308. return function (p, i, list) {
  24309. return minimatch(p, pattern, options)
  24310. }
  24311. }
  24312. function ext (a, b) {
  24313. a = a || {};
  24314. b = b || {};
  24315. var t = {};
  24316. Object.keys(b).forEach(function (k) {
  24317. t[k] = b[k];
  24318. });
  24319. Object.keys(a).forEach(function (k) {
  24320. t[k] = a[k];
  24321. });
  24322. return t
  24323. }
  24324. minimatch.defaults = function (def) {
  24325. if (!def || !Object.keys(def).length) return minimatch
  24326. var orig = minimatch;
  24327. var m = function minimatch (p, pattern, options) {
  24328. return orig.minimatch(p, pattern, ext(def, options))
  24329. };
  24330. m.Minimatch = function Minimatch (pattern, options) {
  24331. return new orig.Minimatch(pattern, ext(def, options))
  24332. };
  24333. return m
  24334. };
  24335. Minimatch.defaults = function (def) {
  24336. if (!def || !Object.keys(def).length) return Minimatch
  24337. return minimatch.defaults(def).Minimatch
  24338. };
  24339. function minimatch (p, pattern, options) {
  24340. if (typeof pattern !== "string") {
  24341. throw new TypeError("glob pattern string required")
  24342. }
  24343. if (!options) options = {};
  24344. // shortcut: comments match nothing.
  24345. if (!options.nocomment && pattern.charAt(0) === "#") {
  24346. return false
  24347. }
  24348. // "" only matches ""
  24349. if (pattern.trim() === "") return p === ""
  24350. return new Minimatch(pattern, options).match(p)
  24351. }
  24352. function Minimatch (pattern, options) {
  24353. if (!(this instanceof Minimatch)) {
  24354. return new Minimatch(pattern, options, cache)
  24355. }
  24356. if (typeof pattern !== "string") {
  24357. throw new TypeError("glob pattern string required")
  24358. }
  24359. if (!options) options = {};
  24360. // windows: need to use /, not \
  24361. // On other platforms, \ is a valid (albeit bad) filename char.
  24362. if (platform === "win32") {
  24363. pattern = pattern.split("\\").join("/");
  24364. }
  24365. // lru storage.
  24366. // these things aren't particularly big, but walking down the string
  24367. // and turning it into a regexp can get pretty costly.
  24368. var cacheKey = pattern + "\n" + sigmund_1(options);
  24369. var cached = minimatch.cache.get(cacheKey);
  24370. if (cached) return cached
  24371. minimatch.cache.set(cacheKey, this);
  24372. this.options = options;
  24373. this.set = [];
  24374. this.pattern = pattern;
  24375. this.regexp = null;
  24376. this.negate = false;
  24377. this.comment = false;
  24378. this.empty = false;
  24379. // make the set of regexps etc.
  24380. this.make();
  24381. }
  24382. Minimatch.prototype.make = make;
  24383. function make () {
  24384. // don't do it more than once.
  24385. if (this._made) return
  24386. var pattern = this.pattern;
  24387. var options = this.options;
  24388. // empty patterns and comments match nothing.
  24389. if (!options.nocomment && pattern.charAt(0) === "#") {
  24390. this.comment = true;
  24391. return
  24392. }
  24393. if (!pattern) {
  24394. this.empty = true;
  24395. return
  24396. }
  24397. // step 1: figure out negation, etc.
  24398. this.parseNegate();
  24399. // step 2: expand braces
  24400. var set = this.globSet = this.braceExpand();
  24401. if (options.debug) console.error(this.pattern, set);
  24402. // step 3: now we have a set, so turn each one into a series of path-portion
  24403. // matching patterns.
  24404. // These will be regexps, except in the case of "**", which is
  24405. // set to the GLOBSTAR object for globstar behavior,
  24406. // and will not contain any / characters
  24407. set = this.globParts = set.map(function (s) {
  24408. return s.split(slashSplit)
  24409. });
  24410. if (options.debug) console.error(this.pattern, set);
  24411. // glob --> regexps
  24412. set = set.map(function (s, si, set) {
  24413. return s.map(this.parse, this)
  24414. }, this);
  24415. if (options.debug) console.error(this.pattern, set);
  24416. // filter out everything that didn't compile properly.
  24417. set = set.filter(function (s) {
  24418. return -1 === s.indexOf(false)
  24419. });
  24420. if (options.debug) console.error(this.pattern, set);
  24421. this.set = set;
  24422. }
  24423. Minimatch.prototype.parseNegate = parseNegate;
  24424. function parseNegate () {
  24425. var pattern = this.pattern
  24426. , negate = false
  24427. , options = this.options
  24428. , negateOffset = 0;
  24429. if (options.nonegate) return
  24430. for ( var i = 0, l = pattern.length
  24431. ; i < l && pattern.charAt(i) === "!"
  24432. ; i ++) {
  24433. negate = !negate;
  24434. negateOffset ++;
  24435. }
  24436. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  24437. this.negate = negate;
  24438. }
  24439. // Brace expansion:
  24440. // a{b,c}d -> abd acd
  24441. // a{b,}c -> abc ac
  24442. // a{0..3}d -> a0d a1d a2d a3d
  24443. // a{b,c{d,e}f}g -> abg acdfg acefg
  24444. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  24445. //
  24446. // Invalid sets are not expanded.
  24447. // a{2..}b -> a{2..}b
  24448. // a{b}c -> a{b}c
  24449. minimatch.braceExpand = function (pattern, options) {
  24450. return new Minimatch(pattern, options).braceExpand()
  24451. };
  24452. Minimatch.prototype.braceExpand = braceExpand;
  24453. function braceExpand (pattern, options) {
  24454. options = options || this.options;
  24455. pattern = typeof pattern === "undefined"
  24456. ? this.pattern : pattern;
  24457. if (typeof pattern === "undefined") {
  24458. throw new Error("undefined pattern")
  24459. }
  24460. if (options.nobrace ||
  24461. !pattern.match(/\{.*\}/)) {
  24462. // shortcut. no need to expand.
  24463. return [pattern]
  24464. }
  24465. var escaping = false;
  24466. // examples and comments refer to this crazy pattern:
  24467. // a{b,c{d,e},{f,g}h}x{y,z}
  24468. // expected:
  24469. // abxy
  24470. // abxz
  24471. // acdxy
  24472. // acdxz
  24473. // acexy
  24474. // acexz
  24475. // afhxy
  24476. // afhxz
  24477. // aghxy
  24478. // aghxz
  24479. // everything before the first \{ is just a prefix.
  24480. // So, we pluck that off, and work with the rest,
  24481. // and then prepend it to everything we find.
  24482. if (pattern.charAt(0) !== "{") {
  24483. // console.error(pattern)
  24484. var prefix = null;
  24485. for (var i = 0, l = pattern.length; i < l; i ++) {
  24486. var c = pattern.charAt(i);
  24487. // console.error(i, c)
  24488. if (c === "\\") {
  24489. escaping = !escaping;
  24490. } else if (c === "{" && !escaping) {
  24491. prefix = pattern.substr(0, i);
  24492. break
  24493. }
  24494. }
  24495. // actually no sets, all { were escaped.
  24496. if (prefix === null) {
  24497. // console.error("no sets")
  24498. return [pattern]
  24499. }
  24500. var tail = braceExpand(pattern.substr(i), options);
  24501. return tail.map(function (t) {
  24502. return prefix + t
  24503. })
  24504. }
  24505. // now we have something like:
  24506. // {b,c{d,e},{f,g}h}x{y,z}
  24507. // walk through the set, expanding each part, until
  24508. // the set ends. then, we'll expand the suffix.
  24509. // If the set only has a single member, then'll put the {} back
  24510. // first, handle numeric sets, since they're easier
  24511. var numset = pattern.match(/^\{(-?[0-9]+)\.\.(-?[0-9]+)\}/);
  24512. if (numset) {
  24513. // console.error("numset", numset[1], numset[2])
  24514. var suf = braceExpand(pattern.substr(numset[0].length), options)
  24515. , start = +numset[1]
  24516. , end = +numset[2]
  24517. , inc = start > end ? -1 : 1
  24518. , set = [];
  24519. for (var i = start; i != (end + inc); i += inc) {
  24520. // append all the suffixes
  24521. for (var ii = 0, ll = suf.length; ii < ll; ii ++) {
  24522. set.push(i + suf[ii]);
  24523. }
  24524. }
  24525. return set
  24526. }
  24527. // ok, walk through the set
  24528. // We hope, somewhat optimistically, that there
  24529. // will be a } at the end.
  24530. // If the closing brace isn't found, then the pattern is
  24531. // interpreted as braceExpand("\\" + pattern) so that
  24532. // the leading \{ will be interpreted literally.
  24533. var i = 1 // skip the \{
  24534. , depth = 1
  24535. , set = []
  24536. , member = ""
  24537. , sawEnd = false
  24538. , escaping = false;
  24539. function addMember () {
  24540. set.push(member);
  24541. member = "";
  24542. }
  24543. // console.error("Entering for")
  24544. FOR: for (i = 1, l = pattern.length; i < l; i ++) {
  24545. var c = pattern.charAt(i);
  24546. // console.error("", i, c)
  24547. if (escaping) {
  24548. escaping = false;
  24549. member += "\\" + c;
  24550. } else {
  24551. switch (c) {
  24552. case "\\":
  24553. escaping = true;
  24554. continue
  24555. case "{":
  24556. depth ++;
  24557. member += "{";
  24558. continue
  24559. case "}":
  24560. depth --;
  24561. // if this closes the actual set, then we're done
  24562. if (depth === 0) {
  24563. addMember();
  24564. // pluck off the close-brace
  24565. i ++;
  24566. break FOR
  24567. } else {
  24568. member += c;
  24569. continue
  24570. }
  24571. case ",":
  24572. if (depth === 1) {
  24573. addMember();
  24574. } else {
  24575. member += c;
  24576. }
  24577. continue
  24578. default:
  24579. member += c;
  24580. continue
  24581. } // switch
  24582. } // else
  24583. } // for
  24584. // now we've either finished the set, and the suffix is
  24585. // pattern.substr(i), or we have *not* closed the set,
  24586. // and need to escape the leading brace
  24587. if (depth !== 0) {
  24588. // console.error("didn't close", pattern)
  24589. return braceExpand("\\" + pattern, options)
  24590. }
  24591. // x{y,z} -> ["xy", "xz"]
  24592. // console.error("set", set)
  24593. // console.error("suffix", pattern.substr(i))
  24594. var suf = braceExpand(pattern.substr(i), options);
  24595. // ["b", "c{d,e}","{f,g}h"] ->
  24596. // [["b"], ["cd", "ce"], ["fh", "gh"]]
  24597. var addBraces = set.length === 1;
  24598. // console.error("set pre-expanded", set)
  24599. set = set.map(function (p) {
  24600. return braceExpand(p, options)
  24601. });
  24602. // console.error("set expanded", set)
  24603. // [["b"], ["cd", "ce"], ["fh", "gh"]] ->
  24604. // ["b", "cd", "ce", "fh", "gh"]
  24605. set = set.reduce(function (l, r) {
  24606. return l.concat(r)
  24607. });
  24608. if (addBraces) {
  24609. set = set.map(function (s) {
  24610. return "{" + s + "}"
  24611. });
  24612. }
  24613. // now attach the suffixes.
  24614. var ret = [];
  24615. for (var i = 0, l = set.length; i < l; i ++) {
  24616. for (var ii = 0, ll = suf.length; ii < ll; ii ++) {
  24617. ret.push(set[i] + suf[ii]);
  24618. }
  24619. }
  24620. return ret
  24621. }
  24622. // parse a component of the expanded set.
  24623. // At this point, no pattern may contain "/" in it
  24624. // so we're going to return a 2d array, where each entry is the full
  24625. // pattern, split on '/', and then turned into a regular expression.
  24626. // A regexp is made at the end which joins each array with an
  24627. // escaped /, and another full one which joins each regexp with |.
  24628. //
  24629. // Following the lead of Bash 4.1, note that "**" only has special meaning
  24630. // when it is the *only* thing in a path portion. Otherwise, any series
  24631. // of * is equivalent to a single *. Globstar behavior is enabled by
  24632. // default, and can be disabled by setting options.noglobstar.
  24633. Minimatch.prototype.parse = parse;
  24634. var SUBPARSE = {};
  24635. function parse (pattern, isSub) {
  24636. var options = this.options;
  24637. // shortcuts
  24638. if (!options.noglobstar && pattern === "**") return GLOBSTAR
  24639. if (pattern === "") return ""
  24640. var re = ""
  24641. , hasMagic = !!options.nocase
  24642. , escaping = false
  24643. // ? => one single character
  24644. , patternListStack = []
  24645. , plType
  24646. , stateChar
  24647. , inClass = false
  24648. , reClassStart = -1
  24649. , classStart = -1
  24650. // . and .. never match anything that doesn't start with .,
  24651. // even when options.dot is set.
  24652. , patternStart = pattern.charAt(0) === "." ? "" // anything
  24653. // not (start or / followed by . or .. followed by / or end)
  24654. : options.dot ? "(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))"
  24655. : "(?!\\.)";
  24656. function clearStateChar () {
  24657. if (stateChar) {
  24658. // we had some state-tracking character
  24659. // that wasn't consumed by this pass.
  24660. switch (stateChar) {
  24661. case "*":
  24662. re += star;
  24663. hasMagic = true;
  24664. break
  24665. case "?":
  24666. re += qmark;
  24667. hasMagic = true;
  24668. break
  24669. default:
  24670. re += "\\"+stateChar;
  24671. break
  24672. }
  24673. stateChar = false;
  24674. }
  24675. }
  24676. for ( var i = 0, len = pattern.length, c
  24677. ; (i < len) && (c = pattern.charAt(i))
  24678. ; i ++ ) {
  24679. if (options.debug) {
  24680. console.error("%s\t%s %s %j", pattern, i, re, c);
  24681. }
  24682. // skip over any that are escaped.
  24683. if (escaping && reSpecials[c]) {
  24684. re += "\\" + c;
  24685. escaping = false;
  24686. continue
  24687. }
  24688. SWITCH: switch (c) {
  24689. case "/":
  24690. // completely not allowed, even escaped.
  24691. // Should already be path-split by now.
  24692. return false
  24693. case "\\":
  24694. clearStateChar();
  24695. escaping = true;
  24696. continue
  24697. // the various stateChar values
  24698. // for the "extglob" stuff.
  24699. case "?":
  24700. case "*":
  24701. case "+":
  24702. case "@":
  24703. case "!":
  24704. if (options.debug) {
  24705. console.error("%s\t%s %s %j <-- stateChar", pattern, i, re, c);
  24706. }
  24707. // all of those are literals inside a class, except that
  24708. // the glob [!a] means [^a] in regexp
  24709. if (inClass) {
  24710. if (c === "!" && i === classStart + 1) c = "^";
  24711. re += c;
  24712. continue
  24713. }
  24714. // if we already have a stateChar, then it means
  24715. // that there was something like ** or +? in there.
  24716. // Handle the stateChar, then proceed with this one.
  24717. clearStateChar();
  24718. stateChar = c;
  24719. // if extglob is disabled, then +(asdf|foo) isn't a thing.
  24720. // just clear the statechar *now*, rather than even diving into
  24721. // the patternList stuff.
  24722. if (options.noext) clearStateChar();
  24723. continue
  24724. case "(":
  24725. if (inClass) {
  24726. re += "(";
  24727. continue
  24728. }
  24729. if (!stateChar) {
  24730. re += "\\(";
  24731. continue
  24732. }
  24733. plType = stateChar;
  24734. patternListStack.push({ type: plType
  24735. , start: i - 1
  24736. , reStart: re.length });
  24737. // negation is (?:(?!js)[^/]*)
  24738. re += stateChar === "!" ? "(?:(?!" : "(?:";
  24739. stateChar = false;
  24740. continue
  24741. case ")":
  24742. if (inClass || !patternListStack.length) {
  24743. re += "\\)";
  24744. continue
  24745. }
  24746. hasMagic = true;
  24747. re += ")";
  24748. plType = patternListStack.pop().type;
  24749. // negation is (?:(?!js)[^/]*)
  24750. // The others are (?:<pattern>)<type>
  24751. switch (plType) {
  24752. case "!":
  24753. re += "[^/]*?)";
  24754. break
  24755. case "?":
  24756. case "+":
  24757. case "*": re += plType;
  24758. case "@": break // the default anyway
  24759. }
  24760. continue
  24761. case "|":
  24762. if (inClass || !patternListStack.length || escaping) {
  24763. re += "\\|";
  24764. escaping = false;
  24765. continue
  24766. }
  24767. re += "|";
  24768. continue
  24769. // these are mostly the same in regexp and glob
  24770. case "[":
  24771. // swallow any state-tracking char before the [
  24772. clearStateChar();
  24773. if (inClass) {
  24774. re += "\\" + c;
  24775. continue
  24776. }
  24777. inClass = true;
  24778. classStart = i;
  24779. reClassStart = re.length;
  24780. re += c;
  24781. continue
  24782. case "]":
  24783. // a right bracket shall lose its special
  24784. // meaning and represent itself in
  24785. // a bracket expression if it occurs
  24786. // first in the list. -- POSIX.2 2.8.3.2
  24787. if (i === classStart + 1 || !inClass) {
  24788. re += "\\" + c;
  24789. escaping = false;
  24790. continue
  24791. }
  24792. // finish up the class.
  24793. hasMagic = true;
  24794. inClass = false;
  24795. re += c;
  24796. continue
  24797. default:
  24798. // swallow any state char that wasn't consumed
  24799. clearStateChar();
  24800. if (escaping) {
  24801. // no need
  24802. escaping = false;
  24803. } else if (reSpecials[c]
  24804. && !(c === "^" && inClass)) {
  24805. re += "\\";
  24806. }
  24807. re += c;
  24808. } // switch
  24809. } // for
  24810. // handle the case where we left a class open.
  24811. // "[abc" is valid, equivalent to "\[abc"
  24812. if (inClass) {
  24813. // split where the last [ was, and escape it
  24814. // this is a huge pita. We now have to re-walk
  24815. // the contents of the would-be class to re-translate
  24816. // any characters that were passed through as-is
  24817. var cs = pattern.substr(classStart + 1)
  24818. , sp = this.parse(cs, SUBPARSE);
  24819. re = re.substr(0, reClassStart) + "\\[" + sp[0];
  24820. hasMagic = hasMagic || sp[1];
  24821. }
  24822. // handle the case where we had a +( thing at the *end*
  24823. // of the pattern.
  24824. // each pattern list stack adds 3 chars, and we need to go through
  24825. // and escape any | chars that were passed through as-is for the regexp.
  24826. // Go through and escape them, taking care not to double-escape any
  24827. // | chars that were already escaped.
  24828. var pl;
  24829. while (pl = patternListStack.pop()) {
  24830. var tail = re.slice(pl.reStart + 3);
  24831. // maybe some even number of \, then maybe 1 \, followed by a |
  24832. tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
  24833. if (!$2) {
  24834. // the | isn't already escaped, so escape it.
  24835. $2 = "\\";
  24836. }
  24837. // need to escape all those slashes *again*, without escaping the
  24838. // one that we need for escaping the | character. As it works out,
  24839. // escaping an even number of slashes can be done by simply repeating
  24840. // it exactly after itself. That's why this trick works.
  24841. //
  24842. // I am sorry that you have to see this.
  24843. return $1 + $1 + $2 + "|"
  24844. });
  24845. // console.error("tail=%j\n %s", tail, tail)
  24846. var t = pl.type === "*" ? star
  24847. : pl.type === "?" ? qmark
  24848. : "\\" + pl.type;
  24849. hasMagic = true;
  24850. re = re.slice(0, pl.reStart)
  24851. + t + "\\("
  24852. + tail;
  24853. }
  24854. // handle trailing things that only matter at the very end.
  24855. clearStateChar();
  24856. if (escaping) {
  24857. // trailing \\
  24858. re += "\\\\";
  24859. }
  24860. // only need to apply the nodot start if the re starts with
  24861. // something that could conceivably capture a dot
  24862. var addPatternStart = false;
  24863. switch (re.charAt(0)) {
  24864. case ".":
  24865. case "[":
  24866. case "(": addPatternStart = true;
  24867. }
  24868. // if the re is not "" at this point, then we need to make sure
  24869. // it doesn't match against an empty path part.
  24870. // Otherwise a/* will match a/, which it should not.
  24871. if (re !== "" && hasMagic) re = "(?=.)" + re;
  24872. if (addPatternStart) re = patternStart + re;
  24873. // parsing just a piece of a larger pattern.
  24874. if (isSub === SUBPARSE) {
  24875. return [ re, hasMagic ]
  24876. }
  24877. // skip the regexp for non-magical patterns
  24878. // unescape anything in it, though, so that it'll be
  24879. // an exact match against a file etc.
  24880. if (!hasMagic) {
  24881. return globUnescape(pattern)
  24882. }
  24883. var flags = options.nocase ? "i" : ""
  24884. , regExp = new RegExp("^" + re + "$", flags);
  24885. regExp._glob = pattern;
  24886. regExp._src = re;
  24887. return regExp
  24888. }
  24889. minimatch.makeRe = function (pattern, options) {
  24890. return new Minimatch(pattern, options || {}).makeRe()
  24891. };
  24892. Minimatch.prototype.makeRe = makeRe;
  24893. function makeRe () {
  24894. if (this.regexp || this.regexp === false) return this.regexp
  24895. // at this point, this.set is a 2d array of partial
  24896. // pattern strings, or "**".
  24897. //
  24898. // It's better to use .match(). This function shouldn't
  24899. // be used, really, but it's pretty convenient sometimes,
  24900. // when you just want to work with a regex.
  24901. var set = this.set;
  24902. if (!set.length) return this.regexp = false
  24903. var options = this.options;
  24904. var twoStar = options.noglobstar ? star
  24905. : options.dot ? twoStarDot
  24906. : twoStarNoDot
  24907. , flags = options.nocase ? "i" : "";
  24908. var re = set.map(function (pattern) {
  24909. return pattern.map(function (p) {
  24910. return (p === GLOBSTAR) ? twoStar
  24911. : (typeof p === "string") ? regExpEscape(p)
  24912. : p._src
  24913. }).join("\\\/")
  24914. }).join("|");
  24915. // must match entire pattern
  24916. // ending in a * or ** will make it less strict.
  24917. re = "^(?:" + re + ")$";
  24918. // can match anything, as long as it's not this.
  24919. if (this.negate) re = "^(?!" + re + ").*$";
  24920. try {
  24921. return this.regexp = new RegExp(re, flags)
  24922. } catch (ex) {
  24923. return this.regexp = false
  24924. }
  24925. }
  24926. minimatch.match = function (list, pattern, options) {
  24927. var mm = new Minimatch(pattern, options);
  24928. list = list.filter(function (f) {
  24929. return mm.match(f)
  24930. });
  24931. if (options.nonull && !list.length) {
  24932. list.push(pattern);
  24933. }
  24934. return list
  24935. };
  24936. Minimatch.prototype.match = match;
  24937. function match (f, partial) {
  24938. // console.error("match", f, this.pattern)
  24939. // short-circuit in the case of busted things.
  24940. // comments, etc.
  24941. if (this.comment) return false
  24942. if (this.empty) return f === ""
  24943. if (f === "/" && partial) return true
  24944. var options = this.options;
  24945. // windows: need to use /, not \
  24946. // On other platforms, \ is a valid (albeit bad) filename char.
  24947. if (platform === "win32") {
  24948. f = f.split("\\").join("/");
  24949. }
  24950. // treat the test path as a set of pathparts.
  24951. f = f.split(slashSplit);
  24952. if (options.debug) {
  24953. console.error(this.pattern, "split", f);
  24954. }
  24955. // just ONE of the pattern sets in this.set needs to match
  24956. // in order for it to be valid. If negating, then just one
  24957. // match means that we have failed.
  24958. // Either way, return on the first hit.
  24959. var set = this.set;
  24960. // console.error(this.pattern, "set", set)
  24961. for (var i = 0, l = set.length; i < l; i ++) {
  24962. var pattern = set[i];
  24963. var hit = this.matchOne(f, pattern, partial);
  24964. if (hit) {
  24965. if (options.flipNegate) return true
  24966. return !this.negate
  24967. }
  24968. }
  24969. // didn't get any hits. this is success if it's a negative
  24970. // pattern, failure otherwise.
  24971. if (options.flipNegate) return false
  24972. return this.negate
  24973. }
  24974. // set partial to true to test if, for example,
  24975. // "/a/b" matches the start of "/*/b/*/d"
  24976. // Partial means, if you run out of file before you run
  24977. // out of pattern, then that's fine, as long as all
  24978. // the parts match.
  24979. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  24980. var options = this.options;
  24981. if (options.debug) {
  24982. console.error("matchOne",
  24983. { "this": this
  24984. , file: file
  24985. , pattern: pattern });
  24986. }
  24987. if (options.matchBase && pattern.length === 1) {
  24988. file = path.basename(file.join("/")).split("/");
  24989. }
  24990. if (options.debug) {
  24991. console.error("matchOne", file.length, pattern.length);
  24992. }
  24993. for ( var fi = 0
  24994. , pi = 0
  24995. , fl = file.length
  24996. , pl = pattern.length
  24997. ; (fi < fl) && (pi < pl)
  24998. ; fi ++, pi ++ ) {
  24999. if (options.debug) {
  25000. console.error("matchOne loop");
  25001. }
  25002. var p = pattern[pi]
  25003. , f = file[fi];
  25004. if (options.debug) {
  25005. console.error(pattern, p, f);
  25006. }
  25007. // should be impossible.
  25008. // some invalid regexp stuff in the set.
  25009. if (p === false) return false
  25010. if (p === GLOBSTAR) {
  25011. if (options.debug)
  25012. console.error('GLOBSTAR', [pattern, p, f]);
  25013. // "**"
  25014. // a/**/b/**/c would match the following:
  25015. // a/b/x/y/z/c
  25016. // a/x/y/z/b/c
  25017. // a/b/x/b/x/c
  25018. // a/b/c
  25019. // To do this, take the rest of the pattern after
  25020. // the **, and see if it would match the file remainder.
  25021. // If so, return success.
  25022. // If not, the ** "swallows" a segment, and try again.
  25023. // This is recursively awful.
  25024. //
  25025. // a/**/b/**/c matching a/b/x/y/z/c
  25026. // - a matches a
  25027. // - doublestar
  25028. // - matchOne(b/x/y/z/c, b/**/c)
  25029. // - b matches b
  25030. // - doublestar
  25031. // - matchOne(x/y/z/c, c) -> no
  25032. // - matchOne(y/z/c, c) -> no
  25033. // - matchOne(z/c, c) -> no
  25034. // - matchOne(c, c) yes, hit
  25035. var fr = fi
  25036. , pr = pi + 1;
  25037. if (pr === pl) {
  25038. if (options.debug)
  25039. console.error('** at the end');
  25040. // a ** at the end will just swallow the rest.
  25041. // We have found a match.
  25042. // however, it will not swallow /.x, unless
  25043. // options.dot is set.
  25044. // . and .. are *never* matched by **, for explosively
  25045. // exponential reasons.
  25046. for ( ; fi < fl; fi ++) {
  25047. if (file[fi] === "." || file[fi] === ".." ||
  25048. (!options.dot && file[fi].charAt(0) === ".")) return false
  25049. }
  25050. return true
  25051. }
  25052. // ok, let's see if we can swallow whatever we can.
  25053. WHILE: while (fr < fl) {
  25054. var swallowee = file[fr];
  25055. if (options.debug) {
  25056. console.error('\nglobstar while',
  25057. file, fr, pattern, pr, swallowee);
  25058. }
  25059. // XXX remove this slice. Just pass the start index.
  25060. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  25061. if (options.debug)
  25062. console.error('globstar found match!', fr, fl, swallowee);
  25063. // found a match.
  25064. return true
  25065. } else {
  25066. // can't swallow "." or ".." ever.
  25067. // can only swallow ".foo" when explicitly asked.
  25068. if (swallowee === "." || swallowee === ".." ||
  25069. (!options.dot && swallowee.charAt(0) === ".")) {
  25070. if (options.debug)
  25071. console.error("dot detected!", file, fr, pattern, pr);
  25072. break WHILE
  25073. }
  25074. // ** swallows a segment, and continue.
  25075. if (options.debug)
  25076. console.error('globstar swallow a segment, and continue');
  25077. fr ++;
  25078. }
  25079. }
  25080. // no match was found.
  25081. // However, in partial mode, we can't say this is necessarily over.
  25082. // If there's more *pattern* left, then
  25083. if (partial) {
  25084. // ran out of file
  25085. // console.error("\n>>> no match, partial?", file, fr, pattern, pr)
  25086. if (fr === fl) return true
  25087. }
  25088. return false
  25089. }
  25090. // something other than **
  25091. // non-magic patterns just have to match exactly
  25092. // patterns with magic have been turned into regexps.
  25093. var hit;
  25094. if (typeof p === "string") {
  25095. if (options.nocase) {
  25096. hit = f.toLowerCase() === p.toLowerCase();
  25097. } else {
  25098. hit = f === p;
  25099. }
  25100. if (options.debug) {
  25101. console.error("string match", p, f, hit);
  25102. }
  25103. } else {
  25104. hit = f.match(p);
  25105. if (options.debug) {
  25106. console.error("pattern match", p, f, hit);
  25107. }
  25108. }
  25109. if (!hit) return false
  25110. }
  25111. // Note: ending in / means that we'll get a final ""
  25112. // at the end of the pattern. This can only match a
  25113. // corresponding "" at the end of the file.
  25114. // If the file ends in /, then it can only match a
  25115. // a pattern that ends in /, unless the pattern just
  25116. // doesn't have any more for it. But, a/b/ should *not*
  25117. // match "a/b/*", even though "" matches against the
  25118. // [^/]*? pattern, except in partial mode, where it might
  25119. // simply not be reached yet.
  25120. // However, a/b/ should still satisfy a/*
  25121. // now either we fell off the end of the pattern, or we're done.
  25122. if (fi === fl && pi === pl) {
  25123. // ran out of pattern and filename at the same time.
  25124. // an exact hit!
  25125. return true
  25126. } else if (fi === fl) {
  25127. // ran out of file, but still had pattern left.
  25128. // this is ok if we're doing the match as part of
  25129. // a glob fs traversal.
  25130. return partial
  25131. } else if (pi === pl) {
  25132. // ran out of pattern, still have file left.
  25133. // this is only acceptable if we're on the very last
  25134. // empty segment of a file with a trailing slash.
  25135. // a/* should match a/b/
  25136. var emptyFileEnd = (fi === fl - 1) && (file[fi] === "");
  25137. return emptyFileEnd
  25138. }
  25139. // should be unreachable.
  25140. throw new Error("wtf?")
  25141. };
  25142. // replace stuff like \* with *
  25143. function globUnescape (s) {
  25144. return s.replace(/\\(.)/g, "$1")
  25145. }
  25146. function regExpEscape (s) {
  25147. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
  25148. }
  25149. });
  25150. var ini = createCommonjsModule(function (module, exports) {
  25151. "use strict";
  25152. // Based on iniparser by shockie <https://npmjs.org/package/iniparser>
  25153. var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
  25154. return new (P || (P = Promise))(function (resolve, reject) {
  25155. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  25156. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  25157. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  25158. step((generator = generator.apply(thisArg, _arguments || [])).next());
  25159. });
  25160. };
  25161. var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
  25162. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  25163. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  25164. function verb(n) { return function (v) { return step([n, v]); }; }
  25165. function step(op) {
  25166. if (f) throw new TypeError("Generator is already executing.");
  25167. while (_) try {
  25168. if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
  25169. if (y = 0, t) op = [0, t.value];
  25170. switch (op[0]) {
  25171. case 0: case 1: t = op; break;
  25172. case 4: _.label++; return { value: op[1], done: false };
  25173. case 5: _.label++; y = op[1]; op = [0]; continue;
  25174. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  25175. default:
  25176. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  25177. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  25178. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  25179. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  25180. if (t[2]) _.ops.pop();
  25181. _.trys.pop(); continue;
  25182. }
  25183. op = body.call(thisArg, _);
  25184. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  25185. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  25186. }
  25187. };
  25188. Object.defineProperty(exports, "__esModule", { value: true });
  25189. /**
  25190. * define the possible values:
  25191. * section: [section]
  25192. * param: key=value
  25193. * comment: ;this is a comment
  25194. */
  25195. var regex = {
  25196. section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
  25197. param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
  25198. comment: /^\s*[#;].*$/,
  25199. };
  25200. /**
  25201. * Parses an .ini file
  25202. * @param file The location of the .ini file
  25203. */
  25204. function parse(file) {
  25205. return __awaiter(this, void 0, void 0, function () {
  25206. return __generator(this, function (_a) {
  25207. return [2 /*return*/, new Promise(function (resolve, reject) {
  25208. fs.readFile(file, 'utf8', function (err, data) {
  25209. if (err) {
  25210. reject(err);
  25211. return;
  25212. }
  25213. resolve(parseString(data));
  25214. });
  25215. })];
  25216. });
  25217. });
  25218. }
  25219. exports.parse = parse;
  25220. function parseSync(file) {
  25221. return parseString(fs.readFileSync(file, 'utf8'));
  25222. }
  25223. exports.parseSync = parseSync;
  25224. function parseString(data) {
  25225. var sectionBody = {};
  25226. var sectionName = null;
  25227. var value = [[sectionName, sectionBody]];
  25228. var lines = data.split(/\r\n|\r|\n/);
  25229. lines.forEach(function (line) {
  25230. var match;
  25231. if (regex.comment.test(line)) {
  25232. return;
  25233. }
  25234. if (regex.param.test(line)) {
  25235. match = line.match(regex.param);
  25236. sectionBody[match[1]] =
  25237. match[2];
  25238. }
  25239. else if (regex.section.test(line)) {
  25240. match = line.match(regex.section);
  25241. sectionName = match[1];
  25242. sectionBody = {};
  25243. value.push([sectionName, sectionBody]);
  25244. }
  25245. });
  25246. return value;
  25247. }
  25248. exports.parseString = parseString;
  25249. });
  25250. unwrapExports(ini);
  25251. var name$1 = "editorconfig";
  25252. var version$2 = "0.15.0";
  25253. var description$1 = "EditorConfig File Locator and Interpreter for Node.js";
  25254. var keywords = ["editorconfig","core"];
  25255. var main$1 = "index.js";
  25256. var bin$1 = {"editorconfig":"bin/editorconfig"};
  25257. var contributors = ["Hong Xu (topbug.net)","Jed Mao (https://github.com/jedmao/)","Trey Hunner (http://treyhunner.com)"];
  25258. var directories = {"bin":"./bin","lib":"./lib"};
  25259. 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"};
  25260. var repository$1 = {"type":"git","url":"git://github.com/editorconfig/editorconfig-core-js.git"};
  25261. var bugs$1 = "https://github.com/editorconfig/editorconfig-core-js/issues";
  25262. var author$1 = "EditorConfig Team";
  25263. var license$1 = "MIT";
  25264. 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"};
  25265. 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"};
  25266. var _package$2 = {
  25267. name: name$1,
  25268. version: version$2,
  25269. description: description$1,
  25270. keywords: keywords,
  25271. main: main$1,
  25272. bin: bin$1,
  25273. contributors: contributors,
  25274. directories: directories,
  25275. scripts: scripts$1,
  25276. repository: repository$1,
  25277. bugs: bugs$1,
  25278. author: author$1,
  25279. license: license$1,
  25280. dependencies: dependencies$1,
  25281. devDependencies: devDependencies$1
  25282. };
  25283. var _package$3 = Object.freeze({
  25284. name: name$1,
  25285. version: version$2,
  25286. description: description$1,
  25287. keywords: keywords,
  25288. main: main$1,
  25289. bin: bin$1,
  25290. contributors: contributors,
  25291. directories: directories,
  25292. scripts: scripts$1,
  25293. repository: repository$1,
  25294. bugs: bugs$1,
  25295. author: author$1,
  25296. license: license$1,
  25297. dependencies: dependencies$1,
  25298. devDependencies: devDependencies$1,
  25299. default: _package$2
  25300. });
  25301. var pkg = ( _package$3 && _package$2 ) || _package$3;
  25302. var editorconfig = createCommonjsModule(function (module, exports) {
  25303. "use strict";
  25304. var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
  25305. return new (P || (P = Promise))(function (resolve, reject) {
  25306. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  25307. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  25308. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  25309. step((generator = generator.apply(thisArg, _arguments || [])).next());
  25310. });
  25311. };
  25312. var __generator = (commonjsGlobal && commonjsGlobal.__generator) || function (thisArg, body) {
  25313. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  25314. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  25315. function verb(n) { return function (v) { return step([n, v]); }; }
  25316. function step(op) {
  25317. if (f) throw new TypeError("Generator is already executing.");
  25318. while (_) try {
  25319. if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
  25320. if (y = 0, t) op = [0, t.value];
  25321. switch (op[0]) {
  25322. case 0: case 1: t = op; break;
  25323. case 4: _.label++; return { value: op[1], done: false };
  25324. case 5: _.label++; y = op[1]; op = [0]; continue;
  25325. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  25326. default:
  25327. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  25328. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  25329. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  25330. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  25331. if (t[2]) _.ops.pop();
  25332. _.trys.pop(); continue;
  25333. }
  25334. op = body.call(thisArg, _);
  25335. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  25336. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  25337. }
  25338. };
  25339. Object.defineProperty(exports, "__esModule", { value: true });
  25340. exports.parseString = ini.parseString;
  25341. // tslint:disable-next-line:no-var-requires
  25342. var knownProps = {
  25343. end_of_line: true,
  25344. indent_style: true,
  25345. indent_size: true,
  25346. insert_final_newline: true,
  25347. trim_trailing_whitespace: true,
  25348. charset: true,
  25349. };
  25350. function fnmatch$$1(filepath, glob) {
  25351. var matchOptions = { matchBase: true, dot: true, noext: true };
  25352. glob = glob.replace(/\*\*/g, '{*,**/**/**}');
  25353. return fnmatch(filepath, glob, matchOptions);
  25354. }
  25355. function getConfigFileNames(filepath, options) {
  25356. var paths = [];
  25357. do {
  25358. filepath = path.dirname(filepath);
  25359. paths.push(path.join(filepath, options.config));
  25360. } while (filepath !== options.root);
  25361. return paths;
  25362. }
  25363. function processMatches(matches, version) {
  25364. // Set indent_size to 'tab' if indent_size is unspecified and
  25365. // indent_style is set to 'tab'.
  25366. if ('indent_style' in matches
  25367. && matches.indent_style === 'tab'
  25368. && !('indent_size' in matches)
  25369. && semver$3.gte(version, '0.10.0')) {
  25370. matches.indent_size = 'tab';
  25371. }
  25372. // Set tab_width to indent_size if indent_size is specified and
  25373. // tab_width is unspecified
  25374. if ('indent_size' in matches
  25375. && !('tab_width' in matches)
  25376. && matches.indent_size !== 'tab') {
  25377. matches.tab_width = matches.indent_size;
  25378. }
  25379. // Set indent_size to tab_width if indent_size is 'tab'
  25380. if ('indent_size' in matches
  25381. && 'tab_width' in matches
  25382. && matches.indent_size === 'tab') {
  25383. matches.indent_size = matches.tab_width;
  25384. }
  25385. return matches;
  25386. }
  25387. function processOptions(options, filepath) {
  25388. if (options === void 0) { options = {}; }
  25389. return {
  25390. config: options.config || '.editorconfig',
  25391. version: options.version || pkg.version,
  25392. root: path.resolve(options.root || path.parse(filepath).root),
  25393. };
  25394. }
  25395. function buildFullGlob(pathPrefix, glob) {
  25396. switch (glob.indexOf('/')) {
  25397. case -1:
  25398. glob = '**/' + glob;
  25399. break;
  25400. case 0:
  25401. glob = glob.substring(1);
  25402. break;
  25403. default:
  25404. break;
  25405. }
  25406. return path.join(pathPrefix, glob);
  25407. }
  25408. function extendProps(props, options) {
  25409. if (props === void 0) { props = {}; }
  25410. if (options === void 0) { options = {}; }
  25411. for (var key in options) {
  25412. if (options.hasOwnProperty(key)) {
  25413. var value = options[key];
  25414. var key2 = key.toLowerCase();
  25415. var value2 = value;
  25416. if (knownProps[key2]) {
  25417. value2 = value.toLowerCase();
  25418. }
  25419. try {
  25420. value2 = JSON.parse(value);
  25421. }
  25422. catch (e) { }
  25423. if (typeof value === 'undefined' || value === null) {
  25424. // null and undefined are values specific to JSON (no special meaning
  25425. // in editorconfig) & should just be returned as regular strings.
  25426. value2 = String(value);
  25427. }
  25428. props[key2] = value2;
  25429. }
  25430. }
  25431. return props;
  25432. }
  25433. function parseFromConfigs(configs, filepath, options) {
  25434. return processMatches(configs
  25435. .reverse()
  25436. .reduce(function (matches, file) {
  25437. var pathPrefix = path.dirname(file.name);
  25438. file.contents.forEach(function (section) {
  25439. var glob = section[0];
  25440. var options2 = section[1];
  25441. if (!glob) {
  25442. return;
  25443. }
  25444. var fullGlob = buildFullGlob(pathPrefix, glob);
  25445. if (!fnmatch$$1(filepath, fullGlob)) {
  25446. return;
  25447. }
  25448. matches = extendProps(matches, options2);
  25449. });
  25450. return matches;
  25451. }, {}), options.version);
  25452. }
  25453. function getConfigsForFiles(files) {
  25454. var configs = [];
  25455. for (var i in files) {
  25456. if (files.hasOwnProperty(i)) {
  25457. var file = files[i];
  25458. var contents = ini.parseString(file.contents);
  25459. configs.push({
  25460. name: file.name,
  25461. contents: contents,
  25462. });
  25463. if ((contents[0][1].root || '').toLowerCase() === 'true') {
  25464. break;
  25465. }
  25466. }
  25467. }
  25468. return configs;
  25469. }
  25470. function readConfigFiles(filepaths) {
  25471. return __awaiter(this, void 0, void 0, function () {
  25472. return __generator(this, function (_a) {
  25473. return [2 /*return*/, Promise.all(filepaths.map(function (name) { return new Promise(function (resolve) {
  25474. fs.readFile(name, 'utf8', function (err, data) {
  25475. resolve({
  25476. name: name,
  25477. contents: err ? '' : data,
  25478. });
  25479. });
  25480. }); }))];
  25481. });
  25482. });
  25483. }
  25484. function readConfigFilesSync(filepaths) {
  25485. var files = [];
  25486. var file;
  25487. filepaths.forEach(function (filepath) {
  25488. try {
  25489. file = fs.readFileSync(filepath, 'utf8');
  25490. }
  25491. catch (e) {
  25492. file = '';
  25493. }
  25494. files.push({
  25495. name: filepath,
  25496. contents: file,
  25497. });
  25498. });
  25499. return files;
  25500. }
  25501. function opts(filepath, options) {
  25502. if (options === void 0) { options = {}; }
  25503. var resolvedFilePath = path.resolve(filepath);
  25504. return [
  25505. resolvedFilePath,
  25506. processOptions(options, resolvedFilePath),
  25507. ];
  25508. }
  25509. function parseFromFiles(filepath, files, options) {
  25510. if (options === void 0) { options = {}; }
  25511. return __awaiter(this, void 0, void 0, function () {
  25512. var _a, resolvedFilePath, processedOptions;
  25513. return __generator(this, function (_b) {
  25514. _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
  25515. return [2 /*return*/, files.then(getConfigsForFiles)
  25516. .then(function (configs) { return parseFromConfigs(configs, resolvedFilePath, processedOptions); })];
  25517. });
  25518. });
  25519. }
  25520. exports.parseFromFiles = parseFromFiles;
  25521. function parseFromFilesSync(filepath, files, options) {
  25522. if (options === void 0) { options = {}; }
  25523. var _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
  25524. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  25525. }
  25526. exports.parseFromFilesSync = parseFromFilesSync;
  25527. function parse(_filepath, _options) {
  25528. if (_options === void 0) { _options = {}; }
  25529. return __awaiter(this, void 0, void 0, function () {
  25530. var _a, resolvedFilePath, processedOptions, filepaths;
  25531. return __generator(this, function (_b) {
  25532. _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
  25533. filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  25534. return [2 /*return*/, readConfigFiles(filepaths)
  25535. .then(getConfigsForFiles)
  25536. .then(function (configs) { return parseFromConfigs(configs, resolvedFilePath, processedOptions); })];
  25537. });
  25538. });
  25539. }
  25540. exports.parse = parse;
  25541. function parseSync(_filepath, _options) {
  25542. if (_options === void 0) { _options = {}; }
  25543. var _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
  25544. var filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  25545. var files = readConfigFilesSync(filepaths);
  25546. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  25547. }
  25548. exports.parseSync = parseSync;
  25549. });
  25550. unwrapExports(editorconfig);
  25551. var editorconfigToPrettier = editorConfigToPrettier;
  25552. function editorConfigToPrettier(editorConfig) {
  25553. if (!editorConfig || Object.keys(editorConfig).length === 0) {
  25554. return null;
  25555. }
  25556. const result = {};
  25557. if (editorConfig.indent_style) {
  25558. result.useTabs = editorConfig.indent_style === "tab";
  25559. }
  25560. if (editorConfig.indent_size === "tab") {
  25561. result.useTabs = true;
  25562. }
  25563. if (result.useTabs && editorConfig.tab_width) {
  25564. result.tabWidth = editorConfig.tab_width;
  25565. } else if (
  25566. editorConfig.indent_style === "space" &&
  25567. editorConfig.indent_size &&
  25568. editorConfig.indent_size !== "tab"
  25569. ) {
  25570. result.tabWidth = editorConfig.indent_size;
  25571. } else if (editorConfig.tab_width !== undefined) {
  25572. result.tabWidth = editorConfig.tab_width;
  25573. }
  25574. if (editorConfig.max_line_length && editorConfig.max_line_length !== "off") {
  25575. result.printWidth = editorConfig.max_line_length;
  25576. }
  25577. if (editorConfig.quote_type === "single") {
  25578. result.singleQuote = true;
  25579. } else if (editorConfig.quote_type === "double") {
  25580. result.singleQuote = false;
  25581. }
  25582. return result;
  25583. }
  25584. function markerExists (files, markers) {
  25585. return markers.some(function(marker) {
  25586. return files.some(function(file) {
  25587. return file === marker;
  25588. });
  25589. });
  25590. }
  25591. function traverseFolder (directory, levels, markers) {
  25592. var files = fs.readdirSync(directory);
  25593. if (levels === 0) {
  25594. return null;
  25595. } else if (markerExists(files, markers)) {
  25596. return directory;
  25597. } else {
  25598. return traverseFolder(path.resolve(directory, '..'), levels - 1, markers);
  25599. }
  25600. }
  25601. var findProjectRoot = function findRoot(dir, opts) {
  25602. if (!dir) throw new Error("Directory not defined");
  25603. opts = opts || {};
  25604. var levels = opts.maxDepth || findRoot.MAX_DEPTH;
  25605. var markers = opts.markers || findRoot.MARKERS;
  25606. return traverseFolder(dir, levels, markers);
  25607. };
  25608. var MAX_DEPTH = 9;
  25609. var MARKERS = [ '.git', '.hg' ];
  25610. findProjectRoot.MAX_DEPTH = MAX_DEPTH;
  25611. findProjectRoot.MARKERS = MARKERS;
  25612. var resolveConfigEditorconfig = createCommonjsModule(function (module) {
  25613. "use strict";
  25614. const maybeParse = (filePath, config, parse) => {
  25615. const root = findProjectRoot(path.dirname(path.resolve(filePath)));
  25616. return filePath && parse(filePath, { root });
  25617. };
  25618. const editorconfigAsyncNoCache = (filePath, config) => {
  25619. return Promise.resolve(maybeParse(filePath, config, editorconfig.parse)).then(
  25620. editorconfigToPrettier
  25621. );
  25622. };
  25623. const editorconfigAsyncWithCache = mem(editorconfigAsyncNoCache);
  25624. const editorconfigSyncNoCache = (filePath, config) => {
  25625. return editorconfigToPrettier(
  25626. maybeParse(filePath, config, editorconfig.parseSync)
  25627. );
  25628. };
  25629. const editorconfigSyncWithCache = mem(editorconfigSyncNoCache);
  25630. function getLoadFunction(opts) {
  25631. if (!opts.editorconfig) {
  25632. return () => null;
  25633. }
  25634. if (opts.sync) {
  25635. return opts.cache ? editorconfigSyncWithCache : editorconfigSyncNoCache;
  25636. }
  25637. return opts.cache ? editorconfigAsyncWithCache : editorconfigAsyncNoCache;
  25638. }
  25639. function clearCache() {
  25640. mem.clear(editorconfigSyncWithCache);
  25641. mem.clear(editorconfigAsyncWithCache);
  25642. }
  25643. module.exports = {
  25644. getLoadFunction,
  25645. clearCache
  25646. };
  25647. });
  25648. var thirdParty$1 = ( thirdParty && thirdParty__default ) || thirdParty;
  25649. var resolveConfig_1 = createCommonjsModule(function (module) {
  25650. "use strict";
  25651. const getExplorerMemoized = mem(opts =>
  25652. thirdParty$1.cosmiconfig("prettier", {
  25653. sync: opts.sync,
  25654. cache: opts.cache,
  25655. rcExtensions: true,
  25656. transform: result => {
  25657. if (result && result.config) {
  25658. delete result.config.$schema;
  25659. }
  25660. return result;
  25661. }
  25662. })
  25663. );
  25664. /** @param {{ cache: boolean, sync: boolean }} opts */
  25665. function getLoadFunction(opts) {
  25666. // Normalize opts before passing to a memoized function
  25667. opts = Object.assign({ sync: false, cache: false }, opts);
  25668. return getExplorerMemoized(opts).load;
  25669. }
  25670. function _resolveConfig(filePath, opts, sync) {
  25671. opts = Object.assign({ useCache: true }, opts);
  25672. const loadOpts = {
  25673. cache: !!opts.useCache,
  25674. sync: !!sync,
  25675. editorconfig: !!opts.editorconfig
  25676. };
  25677. const load = getLoadFunction(loadOpts);
  25678. const loadEditorConfig = resolveConfigEditorconfig.getLoadFunction(loadOpts);
  25679. const arr = [load, loadEditorConfig].map(l => l(filePath, opts.config));
  25680. const unwrapAndMerge = arr => {
  25681. const result = arr[0];
  25682. const editorConfigured = arr[1];
  25683. const merged = Object.assign(
  25684. {},
  25685. editorConfigured,
  25686. mergeOverrides(Object.assign({}, result), filePath)
  25687. );
  25688. if (!result && !editorConfigured) {
  25689. return null;
  25690. }
  25691. return merged;
  25692. };
  25693. if (loadOpts.sync) {
  25694. return unwrapAndMerge(arr);
  25695. }
  25696. return Promise.all(arr).then(unwrapAndMerge);
  25697. }
  25698. const resolveConfig = (filePath, opts) => _resolveConfig(filePath, opts, false);
  25699. resolveConfig.sync = (filePath, opts) => _resolveConfig(filePath, opts, true);
  25700. function clearCache() {
  25701. mem.clear(getExplorerMemoized);
  25702. resolveConfigEditorconfig.clearCache();
  25703. }
  25704. function resolveConfigFile(filePath) {
  25705. const load = getLoadFunction({ sync: false });
  25706. return load(filePath).then(result => {
  25707. return result ? result.filepath : null;
  25708. });
  25709. }
  25710. resolveConfigFile.sync = filePath => {
  25711. const load = getLoadFunction({ sync: true });
  25712. const result = load(filePath);
  25713. return result ? result.filepath : null;
  25714. };
  25715. function mergeOverrides(configResult, filePath) {
  25716. const options = Object.assign({}, configResult.config);
  25717. if (filePath && options.overrides) {
  25718. const relativeFilePath = path.relative(
  25719. path.dirname(configResult.filepath),
  25720. filePath
  25721. );
  25722. for (const override of options.overrides) {
  25723. if (
  25724. pathMatchesGlobs(
  25725. relativeFilePath,
  25726. override.files,
  25727. override.excludeFiles
  25728. )
  25729. ) {
  25730. Object.assign(options, override.options);
  25731. }
  25732. }
  25733. }
  25734. delete options.overrides;
  25735. return options;
  25736. }
  25737. // Based on eslint: https://github.com/eslint/eslint/blob/master/lib/config/config-ops.js
  25738. function pathMatchesGlobs(filePath, patterns, excludedPatterns) {
  25739. const patternList = [].concat(patterns);
  25740. const excludedPatternList = [].concat(excludedPatterns || []);
  25741. const opts = { matchBase: true };
  25742. return (
  25743. patternList.some(pattern => minimatch_1(filePath, pattern, opts)) &&
  25744. !excludedPatternList.some(excludedPattern =>
  25745. minimatch_1(filePath, excludedPattern, opts)
  25746. )
  25747. );
  25748. }
  25749. module.exports = {
  25750. resolveConfig,
  25751. resolveConfigFile,
  25752. clearCache
  25753. };
  25754. });
  25755. const version = require$$0$11.version;
  25756. const getSupportInfo = support.getSupportInfo;
  25757. const normalizeOptions = options$12.normalize;
  25758. const printDocToString = doc.printer.printDocToString;
  25759. const printDocToDebug = doc.debug.printDocToDebug;
  25760. function guessLineEnding(text) {
  25761. const index = text.indexOf("\n");
  25762. if (index >= 0 && text.charAt(index - 1) === "\r") {
  25763. return "\r\n";
  25764. }
  25765. return "\n";
  25766. }
  25767. function attachComments(text, ast, opts) {
  25768. const astComments = ast.comments;
  25769. if (astComments) {
  25770. delete ast.comments;
  25771. comments.attach(astComments, ast, text, opts);
  25772. }
  25773. ast.tokens = [];
  25774. opts.originalText = text.trimRight();
  25775. return astComments;
  25776. }
  25777. function ensureAllCommentsPrinted(astComments) {
  25778. if (!astComments) {
  25779. return;
  25780. }
  25781. for (let i = 0; i < astComments.length; ++i) {
  25782. if (astComments[i].value.trim() === "prettier-ignore") {
  25783. // If there's a prettier-ignore, we're not printing that sub-tree so we
  25784. // don't know if the comments was printed or not.
  25785. return;
  25786. }
  25787. }
  25788. astComments.forEach(comment => {
  25789. if (!comment.printed) {
  25790. throw new Error(
  25791. 'Comment "' +
  25792. comment.value.trim() +
  25793. '" was not printed. Please report this error!'
  25794. );
  25795. }
  25796. delete comment.printed;
  25797. });
  25798. }
  25799. function formatWithCursor(text, opts, addAlignmentSize) {
  25800. const selectedParser = parser$3.resolveParser(opts);
  25801. const hasPragma = !selectedParser.hasPragma || selectedParser.hasPragma(text);
  25802. if (opts.requirePragma && !hasPragma) {
  25803. return { formatted: text };
  25804. }
  25805. const UTF8BOM = 0xfeff;
  25806. const hasUnicodeBOM = text.charCodeAt(0) === UTF8BOM;
  25807. if (hasUnicodeBOM) {
  25808. text = text.substring(1);
  25809. }
  25810. if (
  25811. opts.insertPragma &&
  25812. opts.printer.insertPragma &&
  25813. !hasPragma &&
  25814. opts.rangeStart === 0 &&
  25815. opts.rangeEnd === Infinity
  25816. ) {
  25817. text = opts.printer.insertPragma(text);
  25818. }
  25819. addAlignmentSize = addAlignmentSize || 0;
  25820. const result = parser$3.parse(text, opts);
  25821. const ast = result.ast;
  25822. text = result.text;
  25823. const formattedRangeOnly = formatRange(text, opts, ast);
  25824. if (formattedRangeOnly) {
  25825. return { formatted: formattedRangeOnly };
  25826. }
  25827. let cursorOffset;
  25828. if (opts.cursorOffset >= 0) {
  25829. const cursorNodeAndParents = findNodeAtOffset(ast, opts.cursorOffset, opts);
  25830. const cursorNode = cursorNodeAndParents.node;
  25831. if (cursorNode) {
  25832. cursorOffset = opts.cursorOffset - opts.locStart(cursorNode);
  25833. opts.cursorNode = cursorNode;
  25834. }
  25835. }
  25836. const astComments = attachComments(text, ast, opts);
  25837. const doc$$1 = astToDoc(ast, opts, addAlignmentSize);
  25838. opts.newLine = guessLineEnding(text);
  25839. const toStringResult = printDocToString(doc$$1, opts);
  25840. let str = toStringResult.formatted;
  25841. if (hasUnicodeBOM) {
  25842. str = String.fromCharCode(UTF8BOM) + str;
  25843. }
  25844. const cursorOffsetResult = toStringResult.cursor;
  25845. ensureAllCommentsPrinted(astComments);
  25846. // Remove extra leading indentation as well as the added indentation after last newline
  25847. if (addAlignmentSize > 0) {
  25848. return { formatted: str.trim() + opts.newLine };
  25849. }
  25850. if (cursorOffset !== undefined) {
  25851. return {
  25852. formatted: str,
  25853. cursorOffset: cursorOffsetResult + cursorOffset
  25854. };
  25855. }
  25856. return { formatted: str };
  25857. }
  25858. function format(text, opts, addAlignmentSize) {
  25859. return formatWithCursor(text, opts, addAlignmentSize).formatted;
  25860. }
  25861. function findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts) {
  25862. let resultStartNode = startNodeAndParents.node;
  25863. let resultEndNode = endNodeAndParents.node;
  25864. if (resultStartNode === resultEndNode) {
  25865. return {
  25866. startNode: resultStartNode,
  25867. endNode: resultEndNode
  25868. };
  25869. }
  25870. for (const endParent of endNodeAndParents.parentNodes) {
  25871. if (
  25872. endParent.type !== "Program" &&
  25873. endParent.type !== "File" &&
  25874. opts.locStart(endParent) >= opts.locStart(startNodeAndParents.node)
  25875. ) {
  25876. resultEndNode = endParent;
  25877. } else {
  25878. break;
  25879. }
  25880. }
  25881. for (const startParent of startNodeAndParents.parentNodes) {
  25882. if (
  25883. startParent.type !== "Program" &&
  25884. startParent.type !== "File" &&
  25885. opts.locEnd(startParent) <= opts.locEnd(endNodeAndParents.node)
  25886. ) {
  25887. resultStartNode = startParent;
  25888. } else {
  25889. break;
  25890. }
  25891. }
  25892. return {
  25893. startNode: resultStartNode,
  25894. endNode: resultEndNode
  25895. };
  25896. }
  25897. function findNodeAtOffset(node, offset, options, predicate, parentNodes) {
  25898. predicate = predicate || (() => true);
  25899. parentNodes = parentNodes || [];
  25900. const start = options.locStart(node, options.locStart);
  25901. const end = options.locEnd(node, options.locEnd);
  25902. if (start <= offset && offset <= end) {
  25903. for (const childNode of comments.getSortedChildNodes(
  25904. node,
  25905. undefined /* text */,
  25906. options
  25907. )) {
  25908. const childResult = findNodeAtOffset(
  25909. childNode,
  25910. offset,
  25911. options,
  25912. predicate,
  25913. [node].concat(parentNodes)
  25914. );
  25915. if (childResult) {
  25916. return childResult;
  25917. }
  25918. }
  25919. if (predicate(node)) {
  25920. return {
  25921. node: node,
  25922. parentNodes: parentNodes
  25923. };
  25924. }
  25925. }
  25926. }
  25927. // See https://www.ecma-international.org/ecma-262/5.1/#sec-A.5
  25928. function isSourceElement(opts, node) {
  25929. if (node == null) {
  25930. return false;
  25931. }
  25932. // JS and JS like to avoid repetitions
  25933. const jsSourceElements = [
  25934. "FunctionDeclaration",
  25935. "BlockStatement",
  25936. "BreakStatement",
  25937. "ContinueStatement",
  25938. "DebuggerStatement",
  25939. "DoWhileStatement",
  25940. "EmptyStatement",
  25941. "ExpressionStatement",
  25942. "ForInStatement",
  25943. "ForStatement",
  25944. "IfStatement",
  25945. "LabeledStatement",
  25946. "ReturnStatement",
  25947. "SwitchStatement",
  25948. "ThrowStatement",
  25949. "TryStatement",
  25950. "VariableDeclaration",
  25951. "WhileStatement",
  25952. "WithStatement",
  25953. "ClassDeclaration", // ES 2015
  25954. "ImportDeclaration", // Module
  25955. "ExportDefaultDeclaration", // Module
  25956. "ExportNamedDeclaration", // Module
  25957. "ExportAllDeclaration", // Module
  25958. "TypeAlias", // Flow
  25959. "InterfaceDeclaration", // Flow, TypeScript
  25960. "TypeAliasDeclaration", // TypeScript
  25961. "ExportAssignment", // TypeScript
  25962. "ExportDeclaration" // TypeScript
  25963. ];
  25964. const jsonSourceElements = [
  25965. "ObjectExpression",
  25966. "ArrayExpression",
  25967. "StringLiteral",
  25968. "NumericLiteral",
  25969. "BooleanLiteral",
  25970. "NullLiteral"
  25971. ];
  25972. const graphqlSourceElements = [
  25973. "OperationDefinition",
  25974. "FragmentDefinition",
  25975. "VariableDefinition",
  25976. "TypeExtensionDefinition",
  25977. "ObjectTypeDefinition",
  25978. "FieldDefinition",
  25979. "DirectiveDefinition",
  25980. "EnumTypeDefinition",
  25981. "EnumValueDefinition",
  25982. "InputValueDefinition",
  25983. "InputObjectTypeDefinition",
  25984. "SchemaDefinition",
  25985. "OperationTypeDefinition",
  25986. "InterfaceTypeDefinition",
  25987. "UnionTypeDefinition",
  25988. "ScalarTypeDefinition"
  25989. ];
  25990. switch (opts.parser) {
  25991. case "flow":
  25992. case "babylon":
  25993. case "typescript":
  25994. return jsSourceElements.indexOf(node.type) > -1;
  25995. case "json":
  25996. return jsonSourceElements.indexOf(node.type) > -1;
  25997. case "graphql":
  25998. return graphqlSourceElements.indexOf(node.kind) > -1;
  25999. }
  26000. return false;
  26001. }
  26002. function calculateRange(text, opts, ast) {
  26003. // Contract the range so that it has non-whitespace characters at its endpoints.
  26004. // This ensures we can format a range that doesn't end on a node.
  26005. const rangeStringOrig = text.slice(opts.rangeStart, opts.rangeEnd);
  26006. const startNonWhitespace = Math.max(
  26007. opts.rangeStart + rangeStringOrig.search(/\S/),
  26008. opts.rangeStart
  26009. );
  26010. let endNonWhitespace;
  26011. for (
  26012. endNonWhitespace = opts.rangeEnd;
  26013. endNonWhitespace > opts.rangeStart;
  26014. --endNonWhitespace
  26015. ) {
  26016. if (text[endNonWhitespace - 1].match(/\S/)) {
  26017. break;
  26018. }
  26019. }
  26020. const startNodeAndParents = findNodeAtOffset(
  26021. ast,
  26022. startNonWhitespace,
  26023. opts,
  26024. node => isSourceElement(opts, node)
  26025. );
  26026. const endNodeAndParents = findNodeAtOffset(
  26027. ast,
  26028. endNonWhitespace,
  26029. opts,
  26030. node => isSourceElement(opts, node)
  26031. );
  26032. if (!startNodeAndParents || !endNodeAndParents) {
  26033. return {
  26034. rangeStart: 0,
  26035. rangeEnd: 0
  26036. };
  26037. }
  26038. const siblingAncestors = findSiblingAncestors(
  26039. startNodeAndParents,
  26040. endNodeAndParents,
  26041. opts
  26042. );
  26043. const startNode = siblingAncestors.startNode;
  26044. const endNode = siblingAncestors.endNode;
  26045. const rangeStart = Math.min(
  26046. opts.locStart(startNode, opts.locStart),
  26047. opts.locStart(endNode, opts.locStart)
  26048. );
  26049. const rangeEnd = Math.max(
  26050. opts.locEnd(startNode, opts.locEnd),
  26051. opts.locEnd(endNode, opts.locEnd)
  26052. );
  26053. return {
  26054. rangeStart: rangeStart,
  26055. rangeEnd: rangeEnd
  26056. };
  26057. }
  26058. function formatRange(text, opts, ast) {
  26059. if (opts.rangeStart <= 0 && text.length <= opts.rangeEnd) {
  26060. return;
  26061. }
  26062. const range = calculateRange(text, opts, ast);
  26063. const rangeStart = range.rangeStart;
  26064. const rangeEnd = range.rangeEnd;
  26065. const rangeString = text.slice(rangeStart, rangeEnd);
  26066. // Try to extend the range backwards to the beginning of the line.
  26067. // This is so we can detect indentation correctly and restore it.
  26068. // Use `Math.min` since `lastIndexOf` returns 0 when `rangeStart` is 0
  26069. const rangeStart2 = Math.min(
  26070. rangeStart,
  26071. text.lastIndexOf("\n", rangeStart) + 1
  26072. );
  26073. const indentString = text.slice(rangeStart2, rangeStart);
  26074. const alignmentSize = util$1.getAlignmentSize(
  26075. indentString,
  26076. opts.tabWidth
  26077. );
  26078. const rangeFormatted = format(
  26079. rangeString,
  26080. Object.assign({}, opts, {
  26081. rangeStart: 0,
  26082. rangeEnd: Infinity,
  26083. printWidth: opts.printWidth - alignmentSize
  26084. }),
  26085. alignmentSize
  26086. );
  26087. // Since the range contracts to avoid trailing whitespace,
  26088. // we need to remove the newline that was inserted by the `format` call.
  26089. const rangeTrimmed = rangeFormatted.trimRight();
  26090. return text.slice(0, rangeStart) + rangeTrimmed + text.slice(rangeEnd);
  26091. }
  26092. var prettier$2 = {
  26093. formatWithCursor: function(text, opts) {
  26094. return formatWithCursor(text, normalizeOptions(opts));
  26095. },
  26096. format: function(text, opts) {
  26097. return format(text, normalizeOptions(opts));
  26098. },
  26099. check: function(text, opts) {
  26100. try {
  26101. const formatted = format(text, normalizeOptions(opts));
  26102. return formatted === text;
  26103. } catch (e) {
  26104. return false;
  26105. }
  26106. },
  26107. doc,
  26108. resolveConfig: resolveConfig_1.resolveConfig,
  26109. clearConfigCache: resolveConfig_1.clearCache,
  26110. getSupportInfo,
  26111. version,
  26112. util: utilShared,
  26113. /* istanbul ignore next */
  26114. __debug: {
  26115. parse: function(text, opts) {
  26116. opts = normalizeOptions(opts);
  26117. return parser$3.parse(text, opts);
  26118. },
  26119. formatAST: function(ast, opts) {
  26120. opts = normalizeOptions(opts);
  26121. const doc$$1 = astToDoc(ast, opts);
  26122. const str = printDocToString(doc$$1, opts);
  26123. return str;
  26124. },
  26125. // Doesn't handle shebang for now
  26126. formatDoc: function(doc$$1, opts) {
  26127. opts = normalizeOptions(opts);
  26128. const debug = printDocToDebug(doc$$1);
  26129. const str = format(debug, opts);
  26130. return str;
  26131. },
  26132. printToDoc: function(text, opts) {
  26133. opts = normalizeOptions(opts);
  26134. const result = parser$3.parse(text, opts);
  26135. const ast = result.ast;
  26136. text = result.text;
  26137. attachComments(text, ast, opts);
  26138. const doc$$1 = astToDoc(ast, opts);
  26139. return doc$$1;
  26140. },
  26141. printDocToString: function(doc$$1, opts) {
  26142. opts = normalizeOptions(opts);
  26143. const str = printDocToString(doc$$1, opts);
  26144. return str;
  26145. }
  26146. }
  26147. };
  26148. var at;
  26149. var ch;
  26150. var escapee = {
  26151. '"': '"',
  26152. '\\': '\\',
  26153. '/': '/',
  26154. b: '\b',
  26155. f: '\f',
  26156. n: '\n',
  26157. r: '\r',
  26158. t: '\t'
  26159. };
  26160. var text;
  26161. var error = function (m) {
  26162. // Call error when something is wrong.
  26163. throw {
  26164. name: 'SyntaxError',
  26165. message: m,
  26166. at: at,
  26167. text: text
  26168. };
  26169. };
  26170. var next = function (c) {
  26171. // If a c parameter is provided, verify that it matches the current character.
  26172. if (c && c !== ch) {
  26173. error("Expected '" + c + "' instead of '" + ch + "'");
  26174. }
  26175. // Get the next character. When there are no more characters,
  26176. // return the empty string.
  26177. ch = text.charAt(at);
  26178. at += 1;
  26179. return ch;
  26180. };
  26181. var number = function () {
  26182. // Parse a number value.
  26183. var number,
  26184. string = '';
  26185. if (ch === '-') {
  26186. string = '-';
  26187. next('-');
  26188. }
  26189. while (ch >= '0' && ch <= '9') {
  26190. string += ch;
  26191. next();
  26192. }
  26193. if (ch === '.') {
  26194. string += '.';
  26195. while (next() && ch >= '0' && ch <= '9') {
  26196. string += ch;
  26197. }
  26198. }
  26199. if (ch === 'e' || ch === 'E') {
  26200. string += ch;
  26201. next();
  26202. if (ch === '-' || ch === '+') {
  26203. string += ch;
  26204. next();
  26205. }
  26206. while (ch >= '0' && ch <= '9') {
  26207. string += ch;
  26208. next();
  26209. }
  26210. }
  26211. number = +string;
  26212. if (!isFinite(number)) {
  26213. error("Bad number");
  26214. } else {
  26215. return number;
  26216. }
  26217. };
  26218. var string = function () {
  26219. // Parse a string value.
  26220. var hex,
  26221. i,
  26222. string = '',
  26223. uffff;
  26224. // When parsing for string values, we must look for " and \ characters.
  26225. if (ch === '"') {
  26226. while (next()) {
  26227. if (ch === '"') {
  26228. next();
  26229. return string;
  26230. } else if (ch === '\\') {
  26231. next();
  26232. if (ch === 'u') {
  26233. uffff = 0;
  26234. for (i = 0; i < 4; i += 1) {
  26235. hex = parseInt(next(), 16);
  26236. if (!isFinite(hex)) {
  26237. break;
  26238. }
  26239. uffff = uffff * 16 + hex;
  26240. }
  26241. string += String.fromCharCode(uffff);
  26242. } else if (typeof escapee[ch] === 'string') {
  26243. string += escapee[ch];
  26244. } else {
  26245. break;
  26246. }
  26247. } else {
  26248. string += ch;
  26249. }
  26250. }
  26251. }
  26252. error("Bad string");
  26253. };
  26254. var white = function () {
  26255. // Skip whitespace.
  26256. while (ch && ch <= ' ') {
  26257. next();
  26258. }
  26259. };
  26260. var word = function () {
  26261. // true, false, or null.
  26262. switch (ch) {
  26263. case 't':
  26264. next('t');
  26265. next('r');
  26266. next('u');
  26267. next('e');
  26268. return true;
  26269. case 'f':
  26270. next('f');
  26271. next('a');
  26272. next('l');
  26273. next('s');
  26274. next('e');
  26275. return false;
  26276. case 'n':
  26277. next('n');
  26278. next('u');
  26279. next('l');
  26280. next('l');
  26281. return null;
  26282. }
  26283. error("Unexpected '" + ch + "'");
  26284. };
  26285. var value;
  26286. var array = function () {
  26287. // Parse an array value.
  26288. var array = [];
  26289. if (ch === '[') {
  26290. next('[');
  26291. white();
  26292. if (ch === ']') {
  26293. next(']');
  26294. return array; // empty array
  26295. }
  26296. while (ch) {
  26297. array.push(value());
  26298. white();
  26299. if (ch === ']') {
  26300. next(']');
  26301. return array;
  26302. }
  26303. next(',');
  26304. white();
  26305. }
  26306. }
  26307. error("Bad array");
  26308. };
  26309. var object = function () {
  26310. // Parse an object value.
  26311. var key,
  26312. object = {};
  26313. if (ch === '{') {
  26314. next('{');
  26315. white();
  26316. if (ch === '}') {
  26317. next('}');
  26318. return object; // empty object
  26319. }
  26320. while (ch) {
  26321. key = string();
  26322. white();
  26323. next(':');
  26324. if (Object.hasOwnProperty.call(object, key)) {
  26325. error('Duplicate key "' + key + '"');
  26326. }
  26327. object[key] = value();
  26328. white();
  26329. if (ch === '}') {
  26330. next('}');
  26331. return object;
  26332. }
  26333. next(',');
  26334. white();
  26335. }
  26336. }
  26337. error("Bad object");
  26338. };
  26339. value = function () {
  26340. // Parse a JSON value. It could be an object, an array, a string, a number,
  26341. // or a word.
  26342. white();
  26343. switch (ch) {
  26344. case '{':
  26345. return object();
  26346. case '[':
  26347. return array();
  26348. case '"':
  26349. return string();
  26350. case '-':
  26351. return number();
  26352. default:
  26353. return ch >= '0' && ch <= '9' ? number() : word();
  26354. }
  26355. };
  26356. // Return the json_parse function. It will have access to all of the above
  26357. // functions and variables.
  26358. var parse$6 = function (source, reviver) {
  26359. var result;
  26360. text = source;
  26361. at = 0;
  26362. ch = ' ';
  26363. result = value();
  26364. white();
  26365. if (ch) {
  26366. error("Syntax error");
  26367. }
  26368. // If there is a reviver function, we recursively walk the new structure,
  26369. // passing each name/value pair to the reviver function for possible
  26370. // transformation, starting with a temporary root object that holds the result
  26371. // in an empty key. If there is not a reviver function, we simply return the
  26372. // result.
  26373. return typeof reviver === 'function' ? (function walk(holder, key) {
  26374. var k, v, value = holder[key];
  26375. if (value && typeof value === 'object') {
  26376. for (k in value) {
  26377. if (Object.prototype.hasOwnProperty.call(value, k)) {
  26378. v = walk(value, k);
  26379. if (v !== undefined) {
  26380. value[k] = v;
  26381. } else {
  26382. delete value[k];
  26383. }
  26384. }
  26385. }
  26386. }
  26387. return reviver.call(holder, key, value);
  26388. }({'': result}, '')) : result;
  26389. };
  26390. var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  26391. var gap;
  26392. var indent$8;
  26393. var meta = { // table of character substitutions
  26394. '\b': '\\b',
  26395. '\t': '\\t',
  26396. '\n': '\\n',
  26397. '\f': '\\f',
  26398. '\r': '\\r',
  26399. '"' : '\\"',
  26400. '\\': '\\\\'
  26401. };
  26402. var rep;
  26403. function quote(string) {
  26404. // If the string contains no control characters, no quote characters, and no
  26405. // backslash characters, then we can safely slap some quotes around it.
  26406. // Otherwise we must also replace the offending characters with safe escape
  26407. // sequences.
  26408. escapable.lastIndex = 0;
  26409. return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
  26410. var c = meta[a];
  26411. return typeof c === 'string' ? c :
  26412. '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  26413. }) + '"' : '"' + string + '"';
  26414. }
  26415. function str(key, holder) {
  26416. // Produce a string from holder[key].
  26417. var i, // The loop counter.
  26418. k, // The member key.
  26419. v, // The member value.
  26420. length,
  26421. mind = gap,
  26422. partial,
  26423. value = holder[key];
  26424. // If the value has a toJSON method, call it to obtain a replacement value.
  26425. if (value && typeof value === 'object' &&
  26426. typeof value.toJSON === 'function') {
  26427. value = value.toJSON(key);
  26428. }
  26429. // If we were called with a replacer function, then call the replacer to
  26430. // obtain a replacement value.
  26431. if (typeof rep === 'function') {
  26432. value = rep.call(holder, key, value);
  26433. }
  26434. // What happens next depends on the value's type.
  26435. switch (typeof value) {
  26436. case 'string':
  26437. return quote(value);
  26438. case 'number':
  26439. // JSON numbers must be finite. Encode non-finite numbers as null.
  26440. return isFinite(value) ? String(value) : 'null';
  26441. case 'boolean':
  26442. case 'null':
  26443. // If the value is a boolean or null, convert it to a string. Note:
  26444. // typeof null does not produce 'null'. The case is included here in
  26445. // the remote chance that this gets fixed someday.
  26446. return String(value);
  26447. case 'object':
  26448. if (!value) return 'null';
  26449. gap += indent$8;
  26450. partial = [];
  26451. // Array.isArray
  26452. if (Object.prototype.toString.apply(value) === '[object Array]') {
  26453. length = value.length;
  26454. for (i = 0; i < length; i += 1) {
  26455. partial[i] = str(i, value) || 'null';
  26456. }
  26457. // Join all of the elements together, separated with commas, and
  26458. // wrap them in brackets.
  26459. v = partial.length === 0 ? '[]' : gap ?
  26460. '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
  26461. '[' + partial.join(',') + ']';
  26462. gap = mind;
  26463. return v;
  26464. }
  26465. // If the replacer is an array, use it to select the members to be
  26466. // stringified.
  26467. if (rep && typeof rep === 'object') {
  26468. length = rep.length;
  26469. for (i = 0; i < length; i += 1) {
  26470. k = rep[i];
  26471. if (typeof k === 'string') {
  26472. v = str(k, value);
  26473. if (v) {
  26474. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  26475. }
  26476. }
  26477. }
  26478. }
  26479. else {
  26480. // Otherwise, iterate through all of the keys in the object.
  26481. for (k in value) {
  26482. if (Object.prototype.hasOwnProperty.call(value, k)) {
  26483. v = str(k, value);
  26484. if (v) {
  26485. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  26486. }
  26487. }
  26488. }
  26489. }
  26490. // Join all of the member texts together, separated with commas,
  26491. // and wrap them in braces.
  26492. v = partial.length === 0 ? '{}' : gap ?
  26493. '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
  26494. '{' + partial.join(',') + '}';
  26495. gap = mind;
  26496. return v;
  26497. }
  26498. }
  26499. var stringify$1 = function (value, replacer, space) {
  26500. var i;
  26501. gap = '';
  26502. indent$8 = '';
  26503. // If the space parameter is a number, make an indent string containing that
  26504. // many spaces.
  26505. if (typeof space === 'number') {
  26506. for (i = 0; i < space; i += 1) {
  26507. indent$8 += ' ';
  26508. }
  26509. }
  26510. // If the space parameter is a string, it will be used as the indent string.
  26511. else if (typeof space === 'string') {
  26512. indent$8 = space;
  26513. }
  26514. // If there is a replacer, it must be a function or an array.
  26515. // Otherwise, throw an error.
  26516. rep = replacer;
  26517. if (replacer && typeof replacer !== 'function'
  26518. && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
  26519. throw new Error('JSON.stringify');
  26520. }
  26521. // Make a fake root object containing our value under the key of ''.
  26522. // Return the result of stringifying the value.
  26523. return str('', {'': value});
  26524. };
  26525. var parse$5 = parse$6;
  26526. var stringify = stringify$1;
  26527. var jsonify = {
  26528. parse: parse$5,
  26529. stringify: stringify
  26530. };
  26531. var json = typeof JSON !== 'undefined' ? JSON : jsonify;
  26532. var jsonStableStringify = function (obj, opts) {
  26533. if (!opts) opts = {};
  26534. if (typeof opts === 'function') opts = { cmp: opts };
  26535. var space = opts.space || '';
  26536. if (typeof space === 'number') space = Array(space+1).join(' ');
  26537. var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;
  26538. var replacer = opts.replacer || function(key, value) { return value; };
  26539. var cmp = opts.cmp && (function (f) {
  26540. return function (node) {
  26541. return function (a, b) {
  26542. var aobj = { key: a, value: node[a] };
  26543. var bobj = { key: b, value: node[b] };
  26544. return f(aobj, bobj);
  26545. };
  26546. };
  26547. })(opts.cmp);
  26548. var seen = [];
  26549. return (function stringify (parent, key, node, level) {
  26550. var indent = space ? ('\n' + new Array(level + 1).join(space)) : '';
  26551. var colonSeparator = space ? ': ' : ':';
  26552. if (node && node.toJSON && typeof node.toJSON === 'function') {
  26553. node = node.toJSON();
  26554. }
  26555. node = replacer.call(parent, key, node);
  26556. if (node === undefined) {
  26557. return;
  26558. }
  26559. if (typeof node !== 'object' || node === null) {
  26560. return json.stringify(node);
  26561. }
  26562. if (isArray$1(node)) {
  26563. var out = [];
  26564. for (var i = 0; i < node.length; i++) {
  26565. var item = stringify(node, i, node[i], level+1) || json.stringify(null);
  26566. out.push(indent + space + item);
  26567. }
  26568. return '[' + out.join(',') + indent + ']';
  26569. }
  26570. else {
  26571. if (seen.indexOf(node) !== -1) {
  26572. if (cycles) return json.stringify('__cycle__');
  26573. throw new TypeError('Converting circular structure to JSON');
  26574. }
  26575. else seen.push(node);
  26576. var keys = objectKeys(node).sort(cmp && cmp(node));
  26577. var out = [];
  26578. for (var i = 0; i < keys.length; i++) {
  26579. var key = keys[i];
  26580. var value = stringify(node, key, node[key], level+1);
  26581. if(!value) continue;
  26582. var keyValue = json.stringify(key)
  26583. + colonSeparator
  26584. + value;
  26585. out.push(indent + space + keyValue);
  26586. }
  26587. seen.splice(seen.indexOf(node), 1);
  26588. return '{' + out.join(',') + indent + '}';
  26589. }
  26590. })({ '': obj }, '', obj, 0);
  26591. };
  26592. var isArray$1 = Array.isArray || function (x) {
  26593. return {}.toString.call(x) === '[object Array]';
  26594. };
  26595. var objectKeys = Object.keys || function (obj) {
  26596. var has = Object.prototype.hasOwnProperty || function () { return true };
  26597. var keys = [];
  26598. for (var key in obj) {
  26599. if (has.call(obj, key)) keys.push(key);
  26600. }
  26601. return keys;
  26602. };
  26603. function preserveCamelCase(str) {
  26604. let isLastCharLower = false;
  26605. let isLastCharUpper = false;
  26606. let isLastLastCharUpper = false;
  26607. for (let i = 0; i < str.length; i++) {
  26608. const c = str[i];
  26609. if (isLastCharLower && /[a-zA-Z]/.test(c) && c.toUpperCase() === c) {
  26610. str = str.substr(0, i) + '-' + str.substr(i);
  26611. isLastCharLower = false;
  26612. isLastLastCharUpper = isLastCharUpper;
  26613. isLastCharUpper = true;
  26614. i++;
  26615. } else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(c) && c.toLowerCase() === c) {
  26616. str = str.substr(0, i - 1) + '-' + str.substr(i - 1);
  26617. isLastLastCharUpper = isLastCharUpper;
  26618. isLastCharUpper = false;
  26619. isLastCharLower = true;
  26620. } else {
  26621. isLastCharLower = c.toLowerCase() === c;
  26622. isLastLastCharUpper = isLastCharUpper;
  26623. isLastCharUpper = c.toUpperCase() === c;
  26624. }
  26625. }
  26626. return str;
  26627. }
  26628. var camelcase = function (str) {
  26629. if (arguments.length > 1) {
  26630. str = Array.from(arguments)
  26631. .map(x => x.trim())
  26632. .filter(x => x.length)
  26633. .join('-');
  26634. } else {
  26635. str = str.trim();
  26636. }
  26637. if (str.length === 0) {
  26638. return '';
  26639. }
  26640. if (str.length === 1) {
  26641. return str.toLowerCase();
  26642. }
  26643. if (/^[a-z0-9]+$/.test(str)) {
  26644. return str;
  26645. }
  26646. const hasUpperCase = str !== str.toLowerCase();
  26647. if (hasUpperCase) {
  26648. str = preserveCamelCase(str);
  26649. }
  26650. return str
  26651. .replace(/^[_.\- ]+/, '')
  26652. .toLowerCase()
  26653. .replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase());
  26654. };
  26655. /*!
  26656. * dashify <https://github.com/jonschlinkert/dashify>
  26657. *
  26658. * Copyright (c) 2015 Jon Schlinkert.
  26659. * Licensed under the MIT license.
  26660. */
  26661. var dashify = function dashify(str) {
  26662. if (typeof str !== 'string') {
  26663. throw new TypeError('expected a string');
  26664. }
  26665. str = str.replace(/([a-z])([A-Z])/g, '$1-$2');
  26666. str = str.replace(/[ \t\W]/g, '-');
  26667. str = str.replace(/^-+|-+$/g, '');
  26668. return str.toLowerCase();
  26669. };
  26670. var PENDING = 'pending';
  26671. var SETTLED = 'settled';
  26672. var FULFILLED = 'fulfilled';
  26673. var REJECTED = 'rejected';
  26674. var NOOP = function () {};
  26675. var isNode = typeof commonjsGlobal !== 'undefined' && typeof commonjsGlobal.process !== 'undefined' && typeof commonjsGlobal.process.emit === 'function';
  26676. var asyncSetTimer = typeof setImmediate === 'undefined' ? setTimeout : setImmediate;
  26677. var asyncQueue = [];
  26678. var asyncTimer;
  26679. function asyncFlush() {
  26680. // run promise callbacks
  26681. for (var i = 0; i < asyncQueue.length; i++) {
  26682. asyncQueue[i][0](asyncQueue[i][1]);
  26683. }
  26684. // reset async asyncQueue
  26685. asyncQueue = [];
  26686. asyncTimer = false;
  26687. }
  26688. function asyncCall(callback, arg) {
  26689. asyncQueue.push([callback, arg]);
  26690. if (!asyncTimer) {
  26691. asyncTimer = true;
  26692. asyncSetTimer(asyncFlush, 0);
  26693. }
  26694. }
  26695. function invokeResolver(resolver, promise) {
  26696. function resolvePromise(value) {
  26697. resolve$3(promise, value);
  26698. }
  26699. function rejectPromise(reason) {
  26700. reject(promise, reason);
  26701. }
  26702. try {
  26703. resolver(resolvePromise, rejectPromise);
  26704. } catch (e) {
  26705. rejectPromise(e);
  26706. }
  26707. }
  26708. function invokeCallback(subscriber) {
  26709. var owner = subscriber.owner;
  26710. var settled = owner._state;
  26711. var value = owner._data;
  26712. var callback = subscriber[settled];
  26713. var promise = subscriber.then;
  26714. if (typeof callback === 'function') {
  26715. settled = FULFILLED;
  26716. try {
  26717. value = callback(value);
  26718. } catch (e) {
  26719. reject(promise, e);
  26720. }
  26721. }
  26722. if (!handleThenable(promise, value)) {
  26723. if (settled === FULFILLED) {
  26724. resolve$3(promise, value);
  26725. }
  26726. if (settled === REJECTED) {
  26727. reject(promise, value);
  26728. }
  26729. }
  26730. }
  26731. function handleThenable(promise, value) {
  26732. var resolved;
  26733. try {
  26734. if (promise === value) {
  26735. throw new TypeError('A promises callback cannot return that same promise.');
  26736. }
  26737. if (value && (typeof value === 'function' || typeof value === 'object')) {
  26738. // then should be retrieved only once
  26739. var then = value.then;
  26740. if (typeof then === 'function') {
  26741. then.call(value, function (val) {
  26742. if (!resolved) {
  26743. resolved = true;
  26744. if (value === val) {
  26745. fulfill(promise, val);
  26746. } else {
  26747. resolve$3(promise, val);
  26748. }
  26749. }
  26750. }, function (reason) {
  26751. if (!resolved) {
  26752. resolved = true;
  26753. reject(promise, reason);
  26754. }
  26755. });
  26756. return true;
  26757. }
  26758. }
  26759. } catch (e) {
  26760. if (!resolved) {
  26761. reject(promise, e);
  26762. }
  26763. return true;
  26764. }
  26765. return false;
  26766. }
  26767. function resolve$3(promise, value) {
  26768. if (promise === value || !handleThenable(promise, value)) {
  26769. fulfill(promise, value);
  26770. }
  26771. }
  26772. function fulfill(promise, value) {
  26773. if (promise._state === PENDING) {
  26774. promise._state = SETTLED;
  26775. promise._data = value;
  26776. asyncCall(publishFulfillment, promise);
  26777. }
  26778. }
  26779. function reject(promise, reason) {
  26780. if (promise._state === PENDING) {
  26781. promise._state = SETTLED;
  26782. promise._data = reason;
  26783. asyncCall(publishRejection, promise);
  26784. }
  26785. }
  26786. function publish(promise) {
  26787. promise._then = promise._then.forEach(invokeCallback);
  26788. }
  26789. function publishFulfillment(promise) {
  26790. promise._state = FULFILLED;
  26791. publish(promise);
  26792. }
  26793. function publishRejection(promise) {
  26794. promise._state = REJECTED;
  26795. publish(promise);
  26796. if (!promise._handled && isNode) {
  26797. commonjsGlobal.process.emit('unhandledRejection', promise._data, promise);
  26798. }
  26799. }
  26800. function notifyRejectionHandled(promise) {
  26801. commonjsGlobal.process.emit('rejectionHandled', promise);
  26802. }
  26803. /**
  26804. * @class
  26805. */
  26806. function Promise$1(resolver) {
  26807. if (typeof resolver !== 'function') {
  26808. throw new TypeError('Promise resolver ' + resolver + ' is not a function');
  26809. }
  26810. if (this instanceof Promise$1 === false) {
  26811. throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object constructor cannot be called as a function.');
  26812. }
  26813. this._then = [];
  26814. invokeResolver(resolver, this);
  26815. }
  26816. Promise$1.prototype = {
  26817. constructor: Promise$1,
  26818. _state: PENDING,
  26819. _then: null,
  26820. _data: undefined,
  26821. _handled: false,
  26822. then: function (onFulfillment, onRejection) {
  26823. var subscriber = {
  26824. owner: this,
  26825. then: new this.constructor(NOOP),
  26826. fulfilled: onFulfillment,
  26827. rejected: onRejection
  26828. };
  26829. if ((onRejection || onFulfillment) && !this._handled) {
  26830. this._handled = true;
  26831. if (this._state === REJECTED && isNode) {
  26832. asyncCall(notifyRejectionHandled, this);
  26833. }
  26834. }
  26835. if (this._state === FULFILLED || this._state === REJECTED) {
  26836. // already resolved, call callback async
  26837. asyncCall(invokeCallback, subscriber);
  26838. } else {
  26839. // subscribe
  26840. this._then.push(subscriber);
  26841. }
  26842. return subscriber.then;
  26843. },
  26844. catch: function (onRejection) {
  26845. return this.then(null, onRejection);
  26846. }
  26847. };
  26848. Promise$1.all = function (promises) {
  26849. if (!Array.isArray(promises)) {
  26850. throw new TypeError('You must pass an array to Promise.all().');
  26851. }
  26852. return new Promise$1(function (resolve, reject) {
  26853. var results = [];
  26854. var remaining = 0;
  26855. function resolver(index) {
  26856. remaining++;
  26857. return function (value) {
  26858. results[index] = value;
  26859. if (!--remaining) {
  26860. resolve(results);
  26861. }
  26862. };
  26863. }
  26864. for (var i = 0, promise; i < promises.length; i++) {
  26865. promise = promises[i];
  26866. if (promise && typeof promise.then === 'function') {
  26867. promise.then(resolver(i), reject);
  26868. } else {
  26869. results[i] = promise;
  26870. }
  26871. }
  26872. if (!remaining) {
  26873. resolve(results);
  26874. }
  26875. });
  26876. };
  26877. Promise$1.race = function (promises) {
  26878. if (!Array.isArray(promises)) {
  26879. throw new TypeError('You must pass an array to Promise.race().');
  26880. }
  26881. return new Promise$1(function (resolve, reject) {
  26882. for (var i = 0, promise; i < promises.length; i++) {
  26883. promise = promises[i];
  26884. if (promise && typeof promise.then === 'function') {
  26885. promise.then(resolve, reject);
  26886. } else {
  26887. resolve(promise);
  26888. }
  26889. }
  26890. });
  26891. };
  26892. Promise$1.resolve = function (value) {
  26893. if (value && typeof value === 'object' && value.constructor === Promise$1) {
  26894. return value;
  26895. }
  26896. return new Promise$1(function (resolve) {
  26897. resolve(value);
  26898. });
  26899. };
  26900. Promise$1.reject = function (reason) {
  26901. return new Promise$1(function (resolve, reject) {
  26902. reject(reason);
  26903. });
  26904. };
  26905. var pinkie = Promise$1;
  26906. var pinkiePromise = typeof Promise === 'function' ? Promise : pinkie;
  26907. var arrayUniq = createCommonjsModule(function (module) {
  26908. 'use strict';
  26909. // there's 3 implementations written in increasing order of efficiency
  26910. // 1 - no Set type is defined
  26911. function uniqNoSet(arr) {
  26912. var ret = [];
  26913. for (var i = 0; i < arr.length; i++) {
  26914. if (ret.indexOf(arr[i]) === -1) {
  26915. ret.push(arr[i]);
  26916. }
  26917. }
  26918. return ret;
  26919. }
  26920. // 2 - a simple Set type is defined
  26921. function uniqSet(arr) {
  26922. var seen = new Set();
  26923. return arr.filter(function (el) {
  26924. if (!seen.has(el)) {
  26925. seen.add(el);
  26926. return true;
  26927. }
  26928. return false;
  26929. });
  26930. }
  26931. // 3 - a standard Set type is defined and it has a forEach method
  26932. function uniqSetWithForEach(arr) {
  26933. var ret = [];
  26934. (new Set(arr)).forEach(function (el) {
  26935. ret.push(el);
  26936. });
  26937. return ret;
  26938. }
  26939. // V8 currently has a broken implementation
  26940. // https://github.com/joyent/node/issues/8449
  26941. function doesForEachActuallyWork() {
  26942. var ret = false;
  26943. (new Set([true])).forEach(function (el) {
  26944. ret = el;
  26945. });
  26946. return ret === true;
  26947. }
  26948. if ('Set' in commonjsGlobal) {
  26949. if (typeof Set.prototype.forEach === 'function' && doesForEachActuallyWork()) {
  26950. module.exports = uniqSetWithForEach;
  26951. } else {
  26952. module.exports = uniqSet;
  26953. }
  26954. } else {
  26955. module.exports = uniqNoSet;
  26956. }
  26957. });
  26958. var arrayUnion = function () {
  26959. return arrayUniq([].concat.apply([], arguments));
  26960. };
  26961. /*
  26962. object-assign
  26963. (c) Sindre Sorhus
  26964. @license MIT
  26965. */
  26966. /* eslint-disable no-unused-vars */
  26967. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  26968. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  26969. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  26970. function toObject(val) {
  26971. if (val === null || val === undefined) {
  26972. throw new TypeError('Object.assign cannot be called with null or undefined');
  26973. }
  26974. return Object(val);
  26975. }
  26976. function shouldUseNative() {
  26977. try {
  26978. if (!Object.assign) {
  26979. return false;
  26980. }
  26981. // Detect buggy property enumeration order in older V8 versions.
  26982. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  26983. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  26984. test1[5] = 'de';
  26985. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  26986. return false;
  26987. }
  26988. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  26989. var test2 = {};
  26990. for (var i = 0; i < 10; i++) {
  26991. test2['_' + String.fromCharCode(i)] = i;
  26992. }
  26993. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  26994. return test2[n];
  26995. });
  26996. if (order2.join('') !== '0123456789') {
  26997. return false;
  26998. }
  26999. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  27000. var test3 = {};
  27001. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  27002. test3[letter] = letter;
  27003. });
  27004. if (Object.keys(Object.assign({}, test3)).join('') !==
  27005. 'abcdefghijklmnopqrst') {
  27006. return false;
  27007. }
  27008. return true;
  27009. } catch (err) {
  27010. // We don't expect any of the above to throw, but better to be safe.
  27011. return false;
  27012. }
  27013. }
  27014. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  27015. var from;
  27016. var to = toObject(target);
  27017. var symbols;
  27018. for (var s = 1; s < arguments.length; s++) {
  27019. from = Object(arguments[s]);
  27020. for (var key in from) {
  27021. if (hasOwnProperty$1.call(from, key)) {
  27022. to[key] = from[key];
  27023. }
  27024. }
  27025. if (getOwnPropertySymbols) {
  27026. symbols = getOwnPropertySymbols(from);
  27027. for (var i = 0; i < symbols.length; i++) {
  27028. if (propIsEnumerable.call(from, symbols[i])) {
  27029. to[symbols[i]] = from[symbols[i]];
  27030. }
  27031. }
  27032. }
  27033. }
  27034. return to;
  27035. };
  27036. // Copyright Joyent, Inc. and other Node contributors.
  27037. //
  27038. // Permission is hereby granted, free of charge, to any person obtaining a
  27039. // copy of this software and associated documentation files (the
  27040. // "Software"), to deal in the Software without restriction, including
  27041. // without limitation the rights to use, copy, modify, merge, publish,
  27042. // distribute, sublicense, and/or sell copies of the Software, and to permit
  27043. // persons to whom the Software is furnished to do so, subject to the
  27044. // following conditions:
  27045. //
  27046. // The above copyright notice and this permission notice shall be included
  27047. // in all copies or substantial portions of the Software.
  27048. //
  27049. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  27050. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27051. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  27052. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  27053. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  27054. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  27055. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  27056. var isWindows = process.platform === 'win32';
  27057. // JavaScript implementation of realpath, ported from node pre-v6
  27058. var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
  27059. function rethrow() {
  27060. // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
  27061. // is fairly slow to generate.
  27062. var callback;
  27063. if (DEBUG) {
  27064. var backtrace = new Error;
  27065. callback = debugCallback;
  27066. } else
  27067. callback = missingCallback;
  27068. return callback;
  27069. function debugCallback(err) {
  27070. if (err) {
  27071. backtrace.message = err.message;
  27072. err = backtrace;
  27073. missingCallback(err);
  27074. }
  27075. }
  27076. function missingCallback(err) {
  27077. if (err) {
  27078. if (process.throwDeprecation)
  27079. throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
  27080. else if (!process.noDeprecation) {
  27081. var msg = 'fs: missing callback ' + (err.stack || err.message);
  27082. if (process.traceDeprecation)
  27083. console.trace(msg);
  27084. else
  27085. console.error(msg);
  27086. }
  27087. }
  27088. }
  27089. }
  27090. function maybeCallback(cb) {
  27091. return typeof cb === 'function' ? cb : rethrow();
  27092. }
  27093. // Regexp that finds the next partion of a (partial) path
  27094. // result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
  27095. if (isWindows) {
  27096. var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
  27097. } else {
  27098. var nextPartRe = /(.*?)(?:[\/]+|$)/g;
  27099. }
  27100. // Regex to find the device root, including trailing slash. E.g. 'c:\\'.
  27101. if (isWindows) {
  27102. var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
  27103. } else {
  27104. var splitRootRe = /^[\/]*/;
  27105. }
  27106. var realpathSync$1 = function realpathSync(p, cache) {
  27107. // make p is absolute
  27108. p = path.resolve(p);
  27109. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  27110. return cache[p];
  27111. }
  27112. var original = p,
  27113. seenLinks = {},
  27114. knownHard = {};
  27115. // current character position in p
  27116. var pos;
  27117. // the partial path so far, including a trailing slash if any
  27118. var current;
  27119. // the partial path without a trailing slash (except when pointing at a root)
  27120. var base;
  27121. // the partial path scanned in the previous round, with slash
  27122. var previous;
  27123. start();
  27124. function start() {
  27125. // Skip over roots
  27126. var m = splitRootRe.exec(p);
  27127. pos = m[0].length;
  27128. current = m[0];
  27129. base = m[0];
  27130. previous = '';
  27131. // On windows, check that the root exists. On unix there is no need.
  27132. if (isWindows && !knownHard[base]) {
  27133. fs.lstatSync(base);
  27134. knownHard[base] = true;
  27135. }
  27136. }
  27137. // walk down the path, swapping out linked pathparts for their real
  27138. // values
  27139. // NB: p.length changes.
  27140. while (pos < p.length) {
  27141. // find the next part
  27142. nextPartRe.lastIndex = pos;
  27143. var result = nextPartRe.exec(p);
  27144. previous = current;
  27145. current += result[0];
  27146. base = previous + result[1];
  27147. pos = nextPartRe.lastIndex;
  27148. // continue if not a symlink
  27149. if (knownHard[base] || (cache && cache[base] === base)) {
  27150. continue;
  27151. }
  27152. var resolvedLink;
  27153. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  27154. // some known symbolic link. no need to stat again.
  27155. resolvedLink = cache[base];
  27156. } else {
  27157. var stat = fs.lstatSync(base);
  27158. if (!stat.isSymbolicLink()) {
  27159. knownHard[base] = true;
  27160. if (cache) cache[base] = base;
  27161. continue;
  27162. }
  27163. // read the link if it wasn't read before
  27164. // dev/ino always return 0 on windows, so skip the check.
  27165. var linkTarget = null;
  27166. if (!isWindows) {
  27167. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  27168. if (seenLinks.hasOwnProperty(id)) {
  27169. linkTarget = seenLinks[id];
  27170. }
  27171. }
  27172. if (linkTarget === null) {
  27173. fs.statSync(base);
  27174. linkTarget = fs.readlinkSync(base);
  27175. }
  27176. resolvedLink = path.resolve(previous, linkTarget);
  27177. // track this, if given a cache.
  27178. if (cache) cache[base] = resolvedLink;
  27179. if (!isWindows) seenLinks[id] = linkTarget;
  27180. }
  27181. // resolve the link, then start over
  27182. p = path.resolve(resolvedLink, p.slice(pos));
  27183. start();
  27184. }
  27185. if (cache) cache[original] = p;
  27186. return p;
  27187. };
  27188. var realpath$1 = function realpath(p, cache, cb) {
  27189. if (typeof cb !== 'function') {
  27190. cb = maybeCallback(cache);
  27191. cache = null;
  27192. }
  27193. // make p is absolute
  27194. p = path.resolve(p);
  27195. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  27196. return process.nextTick(cb.bind(null, null, cache[p]));
  27197. }
  27198. var original = p,
  27199. seenLinks = {},
  27200. knownHard = {};
  27201. // current character position in p
  27202. var pos;
  27203. // the partial path so far, including a trailing slash if any
  27204. var current;
  27205. // the partial path without a trailing slash (except when pointing at a root)
  27206. var base;
  27207. // the partial path scanned in the previous round, with slash
  27208. var previous;
  27209. start();
  27210. function start() {
  27211. // Skip over roots
  27212. var m = splitRootRe.exec(p);
  27213. pos = m[0].length;
  27214. current = m[0];
  27215. base = m[0];
  27216. previous = '';
  27217. // On windows, check that the root exists. On unix there is no need.
  27218. if (isWindows && !knownHard[base]) {
  27219. fs.lstat(base, function(err) {
  27220. if (err) return cb(err);
  27221. knownHard[base] = true;
  27222. LOOP();
  27223. });
  27224. } else {
  27225. process.nextTick(LOOP);
  27226. }
  27227. }
  27228. // walk down the path, swapping out linked pathparts for their real
  27229. // values
  27230. function LOOP() {
  27231. // stop if scanned past end of path
  27232. if (pos >= p.length) {
  27233. if (cache) cache[original] = p;
  27234. return cb(null, p);
  27235. }
  27236. // find the next part
  27237. nextPartRe.lastIndex = pos;
  27238. var result = nextPartRe.exec(p);
  27239. previous = current;
  27240. current += result[0];
  27241. base = previous + result[1];
  27242. pos = nextPartRe.lastIndex;
  27243. // continue if not a symlink
  27244. if (knownHard[base] || (cache && cache[base] === base)) {
  27245. return process.nextTick(LOOP);
  27246. }
  27247. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  27248. // known symbolic link. no need to stat again.
  27249. return gotResolvedLink(cache[base]);
  27250. }
  27251. return fs.lstat(base, gotStat);
  27252. }
  27253. function gotStat(err, stat) {
  27254. if (err) return cb(err);
  27255. // if not a symlink, skip to the next path part
  27256. if (!stat.isSymbolicLink()) {
  27257. knownHard[base] = true;
  27258. if (cache) cache[base] = base;
  27259. return process.nextTick(LOOP);
  27260. }
  27261. // stat & read the link if not read before
  27262. // call gotTarget as soon as the link target is known
  27263. // dev/ino always return 0 on windows, so skip the check.
  27264. if (!isWindows) {
  27265. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  27266. if (seenLinks.hasOwnProperty(id)) {
  27267. return gotTarget(null, seenLinks[id], base);
  27268. }
  27269. }
  27270. fs.stat(base, function(err) {
  27271. if (err) return cb(err);
  27272. fs.readlink(base, function(err, target) {
  27273. if (!isWindows) seenLinks[id] = target;
  27274. gotTarget(err, target);
  27275. });
  27276. });
  27277. }
  27278. function gotTarget(err, target, base) {
  27279. if (err) return cb(err);
  27280. var resolvedLink = path.resolve(previous, target);
  27281. if (cache) cache[base] = resolvedLink;
  27282. gotResolvedLink(resolvedLink);
  27283. }
  27284. function gotResolvedLink(resolvedLink) {
  27285. // resolve the link, then start over
  27286. p = path.resolve(resolvedLink, p.slice(pos));
  27287. start();
  27288. }
  27289. };
  27290. var old = {
  27291. realpathSync: realpathSync$1,
  27292. realpath: realpath$1
  27293. };
  27294. var fs_realpath = realpath;
  27295. realpath.realpath = realpath;
  27296. realpath.sync = realpathSync;
  27297. realpath.realpathSync = realpathSync;
  27298. realpath.monkeypatch = monkeypatch;
  27299. realpath.unmonkeypatch = unmonkeypatch;
  27300. var origRealpath = fs.realpath;
  27301. var origRealpathSync = fs.realpathSync;
  27302. var version$3 = process.version;
  27303. var ok = /^v[0-5]\./.test(version$3);
  27304. function newError (er) {
  27305. return er && er.syscall === 'realpath' && (
  27306. er.code === 'ELOOP' ||
  27307. er.code === 'ENOMEM' ||
  27308. er.code === 'ENAMETOOLONG'
  27309. )
  27310. }
  27311. function realpath (p, cache, cb) {
  27312. if (ok) {
  27313. return origRealpath(p, cache, cb)
  27314. }
  27315. if (typeof cache === 'function') {
  27316. cb = cache;
  27317. cache = null;
  27318. }
  27319. origRealpath(p, cache, function (er, result) {
  27320. if (newError(er)) {
  27321. old.realpath(p, cache, cb);
  27322. } else {
  27323. cb(er, result);
  27324. }
  27325. });
  27326. }
  27327. function realpathSync (p, cache) {
  27328. if (ok) {
  27329. return origRealpathSync(p, cache)
  27330. }
  27331. try {
  27332. return origRealpathSync(p, cache)
  27333. } catch (er) {
  27334. if (newError(er)) {
  27335. return old.realpathSync(p, cache)
  27336. } else {
  27337. throw er
  27338. }
  27339. }
  27340. }
  27341. function monkeypatch () {
  27342. fs.realpath = realpath;
  27343. fs.realpathSync = realpathSync;
  27344. }
  27345. function unmonkeypatch () {
  27346. fs.realpath = origRealpath;
  27347. fs.realpathSync = origRealpathSync;
  27348. }
  27349. var inherits_browser = createCommonjsModule(function (module) {
  27350. if (typeof Object.create === 'function') {
  27351. // implementation from standard node.js 'util' module
  27352. module.exports = function inherits(ctor, superCtor) {
  27353. ctor.super_ = superCtor;
  27354. ctor.prototype = Object.create(superCtor.prototype, {
  27355. constructor: {
  27356. value: ctor,
  27357. enumerable: false,
  27358. writable: true,
  27359. configurable: true
  27360. }
  27361. });
  27362. };
  27363. } else {
  27364. // old school shim for old browsers
  27365. module.exports = function inherits(ctor, superCtor) {
  27366. ctor.super_ = superCtor;
  27367. var TempCtor = function () {};
  27368. TempCtor.prototype = superCtor.prototype;
  27369. ctor.prototype = new TempCtor();
  27370. ctor.prototype.constructor = ctor;
  27371. };
  27372. }
  27373. });
  27374. var inherits = createCommonjsModule(function (module) {
  27375. try {
  27376. var util$$2 = util;
  27377. if (typeof util$$2.inherits !== 'function') throw '';
  27378. module.exports = util$$2.inherits;
  27379. } catch (e) {
  27380. module.exports = inherits_browser;
  27381. }
  27382. });
  27383. function posix(path$$1) {
  27384. return path$$1.charAt(0) === '/';
  27385. }
  27386. function win32(path$$1) {
  27387. // https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
  27388. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
  27389. var result = splitDeviceRe.exec(path$$1);
  27390. var device = result[1] || '';
  27391. var isUnc = Boolean(device && device.charAt(1) !== ':');
  27392. // UNC paths are always absolute
  27393. return Boolean(result[2] || isUnc);
  27394. }
  27395. var pathIsAbsolute = process.platform === 'win32' ? win32 : posix;
  27396. var posix_1 = posix;
  27397. var win32_1 = win32;
  27398. pathIsAbsolute.posix = posix_1;
  27399. pathIsAbsolute.win32 = win32_1;
  27400. var alphasort_1 = alphasort$2;
  27401. var alphasorti_1 = alphasorti$2;
  27402. var setopts_1 = setopts$2;
  27403. var ownProp_1 = ownProp$2;
  27404. var makeAbs_1 = makeAbs;
  27405. var finish_1 = finish;
  27406. var mark_1 = mark;
  27407. var isIgnored_1 = isIgnored$2;
  27408. var childrenIgnored_1 = childrenIgnored$2;
  27409. function ownProp$2 (obj, field) {
  27410. return Object.prototype.hasOwnProperty.call(obj, field)
  27411. }
  27412. var Minimatch$3 = minimatch_1.Minimatch;
  27413. function alphasorti$2 (a, b) {
  27414. return a.toLowerCase().localeCompare(b.toLowerCase())
  27415. }
  27416. function alphasort$2 (a, b) {
  27417. return a.localeCompare(b)
  27418. }
  27419. function setupIgnores (self, options) {
  27420. self.ignore = options.ignore || [];
  27421. if (!Array.isArray(self.ignore))
  27422. self.ignore = [self.ignore];
  27423. if (self.ignore.length) {
  27424. self.ignore = self.ignore.map(ignoreMap);
  27425. }
  27426. }
  27427. // ignore patterns are always in dot:true mode.
  27428. function ignoreMap (pattern) {
  27429. var gmatcher = null;
  27430. if (pattern.slice(-3) === '/**') {
  27431. var gpattern = pattern.replace(/(\/\*\*)+$/, '');
  27432. gmatcher = new Minimatch$3(gpattern, { dot: true });
  27433. }
  27434. return {
  27435. matcher: new Minimatch$3(pattern, { dot: true }),
  27436. gmatcher: gmatcher
  27437. }
  27438. }
  27439. function setopts$2 (self, pattern, options) {
  27440. if (!options)
  27441. options = {};
  27442. // base-matching: just use globstar for that.
  27443. if (options.matchBase && -1 === pattern.indexOf("/")) {
  27444. if (options.noglobstar) {
  27445. throw new Error("base matching requires globstar")
  27446. }
  27447. pattern = "**/" + pattern;
  27448. }
  27449. self.silent = !!options.silent;
  27450. self.pattern = pattern;
  27451. self.strict = options.strict !== false;
  27452. self.realpath = !!options.realpath;
  27453. self.realpathCache = options.realpathCache || Object.create(null);
  27454. self.follow = !!options.follow;
  27455. self.dot = !!options.dot;
  27456. self.mark = !!options.mark;
  27457. self.nodir = !!options.nodir;
  27458. if (self.nodir)
  27459. self.mark = true;
  27460. self.sync = !!options.sync;
  27461. self.nounique = !!options.nounique;
  27462. self.nonull = !!options.nonull;
  27463. self.nosort = !!options.nosort;
  27464. self.nocase = !!options.nocase;
  27465. self.stat = !!options.stat;
  27466. self.noprocess = !!options.noprocess;
  27467. self.absolute = !!options.absolute;
  27468. self.maxLength = options.maxLength || Infinity;
  27469. self.cache = options.cache || Object.create(null);
  27470. self.statCache = options.statCache || Object.create(null);
  27471. self.symlinks = options.symlinks || Object.create(null);
  27472. setupIgnores(self, options);
  27473. self.changedCwd = false;
  27474. var cwd = process.cwd();
  27475. if (!ownProp$2(options, "cwd"))
  27476. self.cwd = cwd;
  27477. else {
  27478. self.cwd = path.resolve(options.cwd);
  27479. self.changedCwd = self.cwd !== cwd;
  27480. }
  27481. self.root = options.root || path.resolve(self.cwd, "/");
  27482. self.root = path.resolve(self.root);
  27483. if (process.platform === "win32")
  27484. self.root = self.root.replace(/\\/g, "/");
  27485. // TODO: is an absolute `cwd` supposed to be resolved against `root`?
  27486. // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
  27487. self.cwdAbs = pathIsAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
  27488. if (process.platform === "win32")
  27489. self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
  27490. self.nomount = !!options.nomount;
  27491. // disable comments and negation in Minimatch.
  27492. // Note that they are not supported in Glob itself anyway.
  27493. options.nonegate = true;
  27494. options.nocomment = true;
  27495. self.minimatch = new Minimatch$3(pattern, options);
  27496. self.options = self.minimatch.options;
  27497. }
  27498. function finish (self) {
  27499. var nou = self.nounique;
  27500. var all = nou ? [] : Object.create(null);
  27501. for (var i = 0, l = self.matches.length; i < l; i ++) {
  27502. var matches = self.matches[i];
  27503. if (!matches || Object.keys(matches).length === 0) {
  27504. if (self.nonull) {
  27505. // do like the shell, and spit out the literal glob
  27506. var literal = self.minimatch.globSet[i];
  27507. if (nou)
  27508. all.push(literal);
  27509. else
  27510. all[literal] = true;
  27511. }
  27512. } else {
  27513. // had matches
  27514. var m = Object.keys(matches);
  27515. if (nou)
  27516. all.push.apply(all, m);
  27517. else
  27518. m.forEach(function (m) {
  27519. all[m] = true;
  27520. });
  27521. }
  27522. }
  27523. if (!nou)
  27524. all = Object.keys(all);
  27525. if (!self.nosort)
  27526. all = all.sort(self.nocase ? alphasorti$2 : alphasort$2);
  27527. // at *some* point we statted all of these
  27528. if (self.mark) {
  27529. for (var i = 0; i < all.length; i++) {
  27530. all[i] = self._mark(all[i]);
  27531. }
  27532. if (self.nodir) {
  27533. all = all.filter(function (e) {
  27534. var notDir = !(/\/$/.test(e));
  27535. var c = self.cache[e] || self.cache[makeAbs(self, e)];
  27536. if (notDir && c)
  27537. notDir = c !== 'DIR' && !Array.isArray(c);
  27538. return notDir
  27539. });
  27540. }
  27541. }
  27542. if (self.ignore.length)
  27543. all = all.filter(function(m) {
  27544. return !isIgnored$2(self, m)
  27545. });
  27546. self.found = all;
  27547. }
  27548. function mark (self, p) {
  27549. var abs = makeAbs(self, p);
  27550. var c = self.cache[abs];
  27551. var m = p;
  27552. if (c) {
  27553. var isDir = c === 'DIR' || Array.isArray(c);
  27554. var slash = p.slice(-1) === '/';
  27555. if (isDir && !slash)
  27556. m += '/';
  27557. else if (!isDir && slash)
  27558. m = m.slice(0, -1);
  27559. if (m !== p) {
  27560. var mabs = makeAbs(self, m);
  27561. self.statCache[mabs] = self.statCache[abs];
  27562. self.cache[mabs] = self.cache[abs];
  27563. }
  27564. }
  27565. return m
  27566. }
  27567. // lotta situps...
  27568. function makeAbs (self, f) {
  27569. var abs = f;
  27570. if (f.charAt(0) === '/') {
  27571. abs = path.join(self.root, f);
  27572. } else if (pathIsAbsolute(f) || f === '') {
  27573. abs = f;
  27574. } else if (self.changedCwd) {
  27575. abs = path.resolve(self.cwd, f);
  27576. } else {
  27577. abs = path.resolve(f);
  27578. }
  27579. if (process.platform === 'win32')
  27580. abs = abs.replace(/\\/g, '/');
  27581. return abs
  27582. }
  27583. // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
  27584. // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
  27585. function isIgnored$2 (self, path$$2) {
  27586. if (!self.ignore.length)
  27587. return false
  27588. return self.ignore.some(function(item) {
  27589. return item.matcher.match(path$$2) || !!(item.gmatcher && item.gmatcher.match(path$$2))
  27590. })
  27591. }
  27592. function childrenIgnored$2 (self, path$$2) {
  27593. if (!self.ignore.length)
  27594. return false
  27595. return self.ignore.some(function(item) {
  27596. return !!(item.gmatcher && item.gmatcher.match(path$$2))
  27597. })
  27598. }
  27599. var common = {
  27600. alphasort: alphasort_1,
  27601. alphasorti: alphasorti_1,
  27602. setopts: setopts_1,
  27603. ownProp: ownProp_1,
  27604. makeAbs: makeAbs_1,
  27605. finish: finish_1,
  27606. mark: mark_1,
  27607. isIgnored: isIgnored_1,
  27608. childrenIgnored: childrenIgnored_1
  27609. };
  27610. var sync$4 = globSync;
  27611. globSync.GlobSync = GlobSync$1;
  27612. var setopts$1 = common.setopts;
  27613. var ownProp$1 = common.ownProp;
  27614. var childrenIgnored$1 = common.childrenIgnored;
  27615. var isIgnored$1 = common.isIgnored;
  27616. function globSync (pattern, options) {
  27617. if (typeof options === 'function' || arguments.length === 3)
  27618. throw new TypeError('callback provided to sync glob\n'+
  27619. 'See: https://github.com/isaacs/node-glob/issues/167')
  27620. return new GlobSync$1(pattern, options).found
  27621. }
  27622. function GlobSync$1 (pattern, options) {
  27623. if (!pattern)
  27624. throw new Error('must provide pattern')
  27625. if (typeof options === 'function' || arguments.length === 3)
  27626. throw new TypeError('callback provided to sync glob\n'+
  27627. 'See: https://github.com/isaacs/node-glob/issues/167')
  27628. if (!(this instanceof GlobSync$1))
  27629. return new GlobSync$1(pattern, options)
  27630. setopts$1(this, pattern, options);
  27631. if (this.noprocess)
  27632. return this
  27633. var n = this.minimatch.set.length;
  27634. this.matches = new Array(n);
  27635. for (var i = 0; i < n; i ++) {
  27636. this._process(this.minimatch.set[i], i, false);
  27637. }
  27638. this._finish();
  27639. }
  27640. GlobSync$1.prototype._finish = function () {
  27641. assert(this instanceof GlobSync$1);
  27642. if (this.realpath) {
  27643. var self = this;
  27644. this.matches.forEach(function (matchset, index) {
  27645. var set = self.matches[index] = Object.create(null);
  27646. for (var p in matchset) {
  27647. try {
  27648. p = self._makeAbs(p);
  27649. var real = fs_realpath.realpathSync(p, self.realpathCache);
  27650. set[real] = true;
  27651. } catch (er) {
  27652. if (er.syscall === 'stat')
  27653. set[self._makeAbs(p)] = true;
  27654. else
  27655. throw er
  27656. }
  27657. }
  27658. });
  27659. }
  27660. common.finish(this);
  27661. };
  27662. GlobSync$1.prototype._process = function (pattern, index, inGlobStar) {
  27663. assert(this instanceof GlobSync$1);
  27664. // Get the first [n] parts of pattern that are all strings.
  27665. var n = 0;
  27666. while (typeof pattern[n] === 'string') {
  27667. n ++;
  27668. }
  27669. // now n is the index of the first one that is *not* a string.
  27670. // See if there's anything else
  27671. var prefix;
  27672. switch (n) {
  27673. // if not, then this is rather simple
  27674. case pattern.length:
  27675. this._processSimple(pattern.join('/'), index);
  27676. return
  27677. case 0:
  27678. // pattern *starts* with some non-trivial item.
  27679. // going to readdir(cwd), but not include the prefix in matches.
  27680. prefix = null;
  27681. break
  27682. default:
  27683. // pattern has some string bits in the front.
  27684. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  27685. // or 'relative' like '../baz'
  27686. prefix = pattern.slice(0, n).join('/');
  27687. break
  27688. }
  27689. var remain = pattern.slice(n);
  27690. // get the list of entries.
  27691. var read;
  27692. if (prefix === null)
  27693. read = '.';
  27694. else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  27695. if (!prefix || !pathIsAbsolute(prefix))
  27696. prefix = '/' + prefix;
  27697. read = prefix;
  27698. } else
  27699. read = prefix;
  27700. var abs = this._makeAbs(read);
  27701. //if ignored, skip processing
  27702. if (childrenIgnored$1(this, read))
  27703. return
  27704. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  27705. if (isGlobStar)
  27706. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar);
  27707. else
  27708. this._processReaddir(prefix, read, abs, remain, index, inGlobStar);
  27709. };
  27710. GlobSync$1.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
  27711. var entries = this._readdir(abs, inGlobStar);
  27712. // if the abs isn't a dir, then nothing can match!
  27713. if (!entries)
  27714. return
  27715. // It will only match dot entries if it starts with a dot, or if
  27716. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  27717. var pn = remain[0];
  27718. var negate = !!this.minimatch.negate;
  27719. var rawGlob = pn._glob;
  27720. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  27721. var matchedEntries = [];
  27722. for (var i = 0; i < entries.length; i++) {
  27723. var e = entries[i];
  27724. if (e.charAt(0) !== '.' || dotOk) {
  27725. var m;
  27726. if (negate && !prefix) {
  27727. m = !e.match(pn);
  27728. } else {
  27729. m = e.match(pn);
  27730. }
  27731. if (m)
  27732. matchedEntries.push(e);
  27733. }
  27734. }
  27735. var len = matchedEntries.length;
  27736. // If there are no matched entries, then nothing matches.
  27737. if (len === 0)
  27738. return
  27739. // if this is the last remaining pattern bit, then no need for
  27740. // an additional stat *unless* the user has specified mark or
  27741. // stat explicitly. We know they exist, since readdir returned
  27742. // them.
  27743. if (remain.length === 1 && !this.mark && !this.stat) {
  27744. if (!this.matches[index])
  27745. this.matches[index] = Object.create(null);
  27746. for (var i = 0; i < len; i ++) {
  27747. var e = matchedEntries[i];
  27748. if (prefix) {
  27749. if (prefix.slice(-1) !== '/')
  27750. e = prefix + '/' + e;
  27751. else
  27752. e = prefix + e;
  27753. }
  27754. if (e.charAt(0) === '/' && !this.nomount) {
  27755. e = path.join(this.root, e);
  27756. }
  27757. this._emitMatch(index, e);
  27758. }
  27759. // This was the last one, and no stats were needed
  27760. return
  27761. }
  27762. // now test all matched entries as stand-ins for that part
  27763. // of the pattern.
  27764. remain.shift();
  27765. for (var i = 0; i < len; i ++) {
  27766. var e = matchedEntries[i];
  27767. var newPattern;
  27768. if (prefix)
  27769. newPattern = [prefix, e];
  27770. else
  27771. newPattern = [e];
  27772. this._process(newPattern.concat(remain), index, inGlobStar);
  27773. }
  27774. };
  27775. GlobSync$1.prototype._emitMatch = function (index, e) {
  27776. if (isIgnored$1(this, e))
  27777. return
  27778. var abs = this._makeAbs(e);
  27779. if (this.mark)
  27780. e = this._mark(e);
  27781. if (this.absolute) {
  27782. e = abs;
  27783. }
  27784. if (this.matches[index][e])
  27785. return
  27786. if (this.nodir) {
  27787. var c = this.cache[abs];
  27788. if (c === 'DIR' || Array.isArray(c))
  27789. return
  27790. }
  27791. this.matches[index][e] = true;
  27792. if (this.stat)
  27793. this._stat(e);
  27794. };
  27795. GlobSync$1.prototype._readdirInGlobStar = function (abs) {
  27796. // follow all symlinked directories forever
  27797. // just proceed as if this is a non-globstar situation
  27798. if (this.follow)
  27799. return this._readdir(abs, false)
  27800. var entries;
  27801. var lstat;
  27802. var stat;
  27803. try {
  27804. lstat = fs.lstatSync(abs);
  27805. } catch (er) {
  27806. if (er.code === 'ENOENT') {
  27807. // lstat failed, doesn't exist
  27808. return null
  27809. }
  27810. }
  27811. var isSym = lstat && lstat.isSymbolicLink();
  27812. this.symlinks[abs] = isSym;
  27813. // If it's not a symlink or a dir, then it's definitely a regular file.
  27814. // don't bother doing a readdir in that case.
  27815. if (!isSym && lstat && !lstat.isDirectory())
  27816. this.cache[abs] = 'FILE';
  27817. else
  27818. entries = this._readdir(abs, false);
  27819. return entries
  27820. };
  27821. GlobSync$1.prototype._readdir = function (abs, inGlobStar) {
  27822. var entries;
  27823. if (inGlobStar && !ownProp$1(this.symlinks, abs))
  27824. return this._readdirInGlobStar(abs)
  27825. if (ownProp$1(this.cache, abs)) {
  27826. var c = this.cache[abs];
  27827. if (!c || c === 'FILE')
  27828. return null
  27829. if (Array.isArray(c))
  27830. return c
  27831. }
  27832. try {
  27833. return this._readdirEntries(abs, fs.readdirSync(abs))
  27834. } catch (er) {
  27835. this._readdirError(abs, er);
  27836. return null
  27837. }
  27838. };
  27839. GlobSync$1.prototype._readdirEntries = function (abs, entries) {
  27840. // if we haven't asked to stat everything, then just
  27841. // assume that everything in there exists, so we can avoid
  27842. // having to stat it a second time.
  27843. if (!this.mark && !this.stat) {
  27844. for (var i = 0; i < entries.length; i ++) {
  27845. var e = entries[i];
  27846. if (abs === '/')
  27847. e = abs + e;
  27848. else
  27849. e = abs + '/' + e;
  27850. this.cache[e] = true;
  27851. }
  27852. }
  27853. this.cache[abs] = entries;
  27854. // mark and cache dir-ness
  27855. return entries
  27856. };
  27857. GlobSync$1.prototype._readdirError = function (f, er) {
  27858. // handle errors, and cache the information
  27859. switch (er.code) {
  27860. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  27861. case 'ENOTDIR': // totally normal. means it *does* exist.
  27862. var abs = this._makeAbs(f);
  27863. this.cache[abs] = 'FILE';
  27864. if (abs === this.cwdAbs) {
  27865. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  27866. error.path = this.cwd;
  27867. error.code = er.code;
  27868. throw error
  27869. }
  27870. break
  27871. case 'ENOENT': // not terribly unusual
  27872. case 'ELOOP':
  27873. case 'ENAMETOOLONG':
  27874. case 'UNKNOWN':
  27875. this.cache[this._makeAbs(f)] = false;
  27876. break
  27877. default: // some unusual error. Treat as failure.
  27878. this.cache[this._makeAbs(f)] = false;
  27879. if (this.strict)
  27880. throw er
  27881. if (!this.silent)
  27882. console.error('glob error', er);
  27883. break
  27884. }
  27885. };
  27886. GlobSync$1.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
  27887. var entries = this._readdir(abs, inGlobStar);
  27888. // no entries means not a dir, so it can never have matches
  27889. // foo.txt/** doesn't match foo.txt
  27890. if (!entries)
  27891. return
  27892. // test without the globstar, and with every child both below
  27893. // and replacing the globstar.
  27894. var remainWithoutGlobStar = remain.slice(1);
  27895. var gspref = prefix ? [ prefix ] : [];
  27896. var noGlobStar = gspref.concat(remainWithoutGlobStar);
  27897. // the noGlobStar pattern exits the inGlobStar state
  27898. this._process(noGlobStar, index, false);
  27899. var len = entries.length;
  27900. var isSym = this.symlinks[abs];
  27901. // If it's a symlink, and we're in a globstar, then stop
  27902. if (isSym && inGlobStar)
  27903. return
  27904. for (var i = 0; i < len; i++) {
  27905. var e = entries[i];
  27906. if (e.charAt(0) === '.' && !this.dot)
  27907. continue
  27908. // these two cases enter the inGlobStar state
  27909. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  27910. this._process(instead, index, true);
  27911. var below = gspref.concat(entries[i], remain);
  27912. this._process(below, index, true);
  27913. }
  27914. };
  27915. GlobSync$1.prototype._processSimple = function (prefix, index) {
  27916. // XXX review this. Shouldn't it be doing the mounting etc
  27917. // before doing stat? kinda weird?
  27918. var exists = this._stat(prefix);
  27919. if (!this.matches[index])
  27920. this.matches[index] = Object.create(null);
  27921. // If it doesn't exist, then just mark the lack of results
  27922. if (!exists)
  27923. return
  27924. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  27925. var trail = /[\/\\]$/.test(prefix);
  27926. if (prefix.charAt(0) === '/') {
  27927. prefix = path.join(this.root, prefix);
  27928. } else {
  27929. prefix = path.resolve(this.root, prefix);
  27930. if (trail)
  27931. prefix += '/';
  27932. }
  27933. }
  27934. if (process.platform === 'win32')
  27935. prefix = prefix.replace(/\\/g, '/');
  27936. // Mark this as a match
  27937. this._emitMatch(index, prefix);
  27938. };
  27939. // Returns either 'DIR', 'FILE', or false
  27940. GlobSync$1.prototype._stat = function (f) {
  27941. var abs = this._makeAbs(f);
  27942. var needDir = f.slice(-1) === '/';
  27943. if (f.length > this.maxLength)
  27944. return false
  27945. if (!this.stat && ownProp$1(this.cache, abs)) {
  27946. var c = this.cache[abs];
  27947. if (Array.isArray(c))
  27948. c = 'DIR';
  27949. // It exists, but maybe not how we need it
  27950. if (!needDir || c === 'DIR')
  27951. return c
  27952. if (needDir && c === 'FILE')
  27953. return false
  27954. // otherwise we have to stat, because maybe c=true
  27955. // if we know it exists, but not what it is.
  27956. }
  27957. var exists;
  27958. var stat = this.statCache[abs];
  27959. if (!stat) {
  27960. var lstat;
  27961. try {
  27962. lstat = fs.lstatSync(abs);
  27963. } catch (er) {
  27964. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  27965. this.statCache[abs] = false;
  27966. return false
  27967. }
  27968. }
  27969. if (lstat && lstat.isSymbolicLink()) {
  27970. try {
  27971. stat = fs.statSync(abs);
  27972. } catch (er) {
  27973. stat = lstat;
  27974. }
  27975. } else {
  27976. stat = lstat;
  27977. }
  27978. }
  27979. this.statCache[abs] = stat;
  27980. var c = true;
  27981. if (stat)
  27982. c = stat.isDirectory() ? 'DIR' : 'FILE';
  27983. this.cache[abs] = this.cache[abs] || c;
  27984. if (needDir && c === 'FILE')
  27985. return false
  27986. return c
  27987. };
  27988. GlobSync$1.prototype._mark = function (p) {
  27989. return common.mark(this, p)
  27990. };
  27991. GlobSync$1.prototype._makeAbs = function (f) {
  27992. return common.makeAbs(this, f)
  27993. };
  27994. // Returns a wrapper function that returns a wrapped callback
  27995. // The wrapper function should do some stuff, and return a
  27996. // presumably different callback function.
  27997. // This makes sure that own properties are retained, so that
  27998. // decorations and such are not lost along the way.
  27999. var wrappy_1 = wrappy;
  28000. function wrappy (fn, cb) {
  28001. if (fn && cb) return wrappy(fn)(cb)
  28002. if (typeof fn !== 'function')
  28003. throw new TypeError('need wrapper function')
  28004. Object.keys(fn).forEach(function (k) {
  28005. wrapper[k] = fn[k];
  28006. });
  28007. return wrapper
  28008. function wrapper() {
  28009. var args = new Array(arguments.length);
  28010. for (var i = 0; i < args.length; i++) {
  28011. args[i] = arguments[i];
  28012. }
  28013. var ret = fn.apply(this, args);
  28014. var cb = args[args.length-1];
  28015. if (typeof ret === 'function' && ret !== cb) {
  28016. Object.keys(cb).forEach(function (k) {
  28017. ret[k] = cb[k];
  28018. });
  28019. }
  28020. return ret
  28021. }
  28022. }
  28023. var once_1 = wrappy_1(once);
  28024. var strict = wrappy_1(onceStrict);
  28025. once.proto = once(function () {
  28026. Object.defineProperty(Function.prototype, 'once', {
  28027. value: function () {
  28028. return once(this)
  28029. },
  28030. configurable: true
  28031. });
  28032. Object.defineProperty(Function.prototype, 'onceStrict', {
  28033. value: function () {
  28034. return onceStrict(this)
  28035. },
  28036. configurable: true
  28037. });
  28038. });
  28039. function once (fn) {
  28040. var f = function () {
  28041. if (f.called) return f.value
  28042. f.called = true;
  28043. return f.value = fn.apply(this, arguments)
  28044. };
  28045. f.called = false;
  28046. return f
  28047. }
  28048. function onceStrict (fn) {
  28049. var f = function () {
  28050. if (f.called)
  28051. throw new Error(f.onceError)
  28052. f.called = true;
  28053. return f.value = fn.apply(this, arguments)
  28054. };
  28055. var name = fn.name || 'Function wrapped with `once`';
  28056. f.onceError = name + " shouldn't be called more than once";
  28057. f.called = false;
  28058. return f
  28059. }
  28060. once_1.strict = strict;
  28061. var reqs = Object.create(null);
  28062. var inflight_1 = wrappy_1(inflight);
  28063. function inflight (key, cb) {
  28064. if (reqs[key]) {
  28065. reqs[key].push(cb);
  28066. return null
  28067. } else {
  28068. reqs[key] = [cb];
  28069. return makeres(key)
  28070. }
  28071. }
  28072. function makeres (key) {
  28073. return once_1(function RES () {
  28074. var cbs = reqs[key];
  28075. var len = cbs.length;
  28076. var args = slice(arguments);
  28077. // XXX It's somewhat ambiguous whether a new callback added in this
  28078. // pass should be queued for later execution if something in the
  28079. // list of callbacks throws, or if it should just be discarded.
  28080. // However, it's such an edge case that it hardly matters, and either
  28081. // choice is likely as surprising as the other.
  28082. // As it happens, we do go ahead and schedule it for later execution.
  28083. try {
  28084. for (var i = 0; i < len; i++) {
  28085. cbs[i].apply(null, args);
  28086. }
  28087. } finally {
  28088. if (cbs.length > len) {
  28089. // added more in the interim.
  28090. // de-zalgo, just in case, but don't call again.
  28091. cbs.splice(0, len);
  28092. process.nextTick(function () {
  28093. RES.apply(null, args);
  28094. });
  28095. } else {
  28096. delete reqs[key];
  28097. }
  28098. }
  28099. })
  28100. }
  28101. function slice (args) {
  28102. var length = args.length;
  28103. var array = [];
  28104. for (var i = 0; i < length; i++) array[i] = args[i];
  28105. return array
  28106. }
  28107. // Approach:
  28108. //
  28109. // 1. Get the minimatch set
  28110. // 2. For each pattern in the set, PROCESS(pattern, false)
  28111. // 3. Store matches per-set, then uniq them
  28112. //
  28113. // PROCESS(pattern, inGlobStar)
  28114. // Get the first [n] items from pattern that are all strings
  28115. // Join these together. This is PREFIX.
  28116. // If there is no more remaining, then stat(PREFIX) and
  28117. // add to matches if it succeeds. END.
  28118. //
  28119. // If inGlobStar and PREFIX is symlink and points to dir
  28120. // set ENTRIES = []
  28121. // else readdir(PREFIX) as ENTRIES
  28122. // If fail, END
  28123. //
  28124. // with ENTRIES
  28125. // If pattern[n] is GLOBSTAR
  28126. // // handle the case where the globstar match is empty
  28127. // // by pruning it out, and testing the resulting pattern
  28128. // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
  28129. // // handle other cases.
  28130. // for ENTRY in ENTRIES (not dotfiles)
  28131. // // attach globstar + tail onto the entry
  28132. // // Mark that this entry is a globstar match
  28133. // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
  28134. //
  28135. // else // not globstar
  28136. // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
  28137. // Test ENTRY against pattern[n]
  28138. // If fails, continue
  28139. // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
  28140. //
  28141. // Caveat:
  28142. // Cache all stats and readdirs results to minimize syscall. Since all
  28143. // we ever care about is existence and directory-ness, we can just keep
  28144. // `true` for files, and [children,...] for directories, or `false` for
  28145. // things that don't exist.
  28146. var glob_1 = glob;
  28147. var EE = events.EventEmitter;
  28148. var setopts = common.setopts;
  28149. var ownProp = common.ownProp;
  28150. var childrenIgnored = common.childrenIgnored;
  28151. var isIgnored = common.isIgnored;
  28152. function glob (pattern, options, cb) {
  28153. if (typeof options === 'function') cb = options, options = {};
  28154. if (!options) options = {};
  28155. if (options.sync) {
  28156. if (cb)
  28157. throw new TypeError('callback provided to sync glob')
  28158. return sync$4(pattern, options)
  28159. }
  28160. return new Glob(pattern, options, cb)
  28161. }
  28162. glob.sync = sync$4;
  28163. var GlobSync = glob.GlobSync = sync$4.GlobSync;
  28164. // old api surface
  28165. glob.glob = glob;
  28166. function extend (origin, add) {
  28167. if (add === null || typeof add !== 'object') {
  28168. return origin
  28169. }
  28170. var keys = Object.keys(add);
  28171. var i = keys.length;
  28172. while (i--) {
  28173. origin[keys[i]] = add[keys[i]];
  28174. }
  28175. return origin
  28176. }
  28177. glob.hasMagic = function (pattern, options_) {
  28178. var options = extend({}, options_);
  28179. options.noprocess = true;
  28180. var g = new Glob(pattern, options);
  28181. var set = g.minimatch.set;
  28182. if (!pattern)
  28183. return false
  28184. if (set.length > 1)
  28185. return true
  28186. for (var j = 0; j < set[0].length; j++) {
  28187. if (typeof set[0][j] !== 'string')
  28188. return true
  28189. }
  28190. return false
  28191. };
  28192. glob.Glob = Glob;
  28193. inherits(Glob, EE);
  28194. function Glob (pattern, options, cb) {
  28195. if (typeof options === 'function') {
  28196. cb = options;
  28197. options = null;
  28198. }
  28199. if (options && options.sync) {
  28200. if (cb)
  28201. throw new TypeError('callback provided to sync glob')
  28202. return new GlobSync(pattern, options)
  28203. }
  28204. if (!(this instanceof Glob))
  28205. return new Glob(pattern, options, cb)
  28206. setopts(this, pattern, options);
  28207. this._didRealPath = false;
  28208. // process each pattern in the minimatch set
  28209. var n = this.minimatch.set.length;
  28210. // The matches are stored as {<filename>: true,...} so that
  28211. // duplicates are automagically pruned.
  28212. // Later, we do an Object.keys() on these.
  28213. // Keep them as a list so we can fill in when nonull is set.
  28214. this.matches = new Array(n);
  28215. if (typeof cb === 'function') {
  28216. cb = once_1(cb);
  28217. this.on('error', cb);
  28218. this.on('end', function (matches) {
  28219. cb(null, matches);
  28220. });
  28221. }
  28222. var self = this;
  28223. this._processing = 0;
  28224. this._emitQueue = [];
  28225. this._processQueue = [];
  28226. this.paused = false;
  28227. if (this.noprocess)
  28228. return this
  28229. if (n === 0)
  28230. return done()
  28231. var sync = true;
  28232. for (var i = 0; i < n; i ++) {
  28233. this._process(this.minimatch.set[i], i, false, done);
  28234. }
  28235. sync = false;
  28236. function done () {
  28237. --self._processing;
  28238. if (self._processing <= 0) {
  28239. if (sync) {
  28240. process.nextTick(function () {
  28241. self._finish();
  28242. });
  28243. } else {
  28244. self._finish();
  28245. }
  28246. }
  28247. }
  28248. }
  28249. Glob.prototype._finish = function () {
  28250. assert(this instanceof Glob);
  28251. if (this.aborted)
  28252. return
  28253. if (this.realpath && !this._didRealpath)
  28254. return this._realpath()
  28255. common.finish(this);
  28256. this.emit('end', this.found);
  28257. };
  28258. Glob.prototype._realpath = function () {
  28259. if (this._didRealpath)
  28260. return
  28261. this._didRealpath = true;
  28262. var n = this.matches.length;
  28263. if (n === 0)
  28264. return this._finish()
  28265. var self = this;
  28266. for (var i = 0; i < this.matches.length; i++)
  28267. this._realpathSet(i, next);
  28268. function next () {
  28269. if (--n === 0)
  28270. self._finish();
  28271. }
  28272. };
  28273. Glob.prototype._realpathSet = function (index, cb) {
  28274. var matchset = this.matches[index];
  28275. if (!matchset)
  28276. return cb()
  28277. var found = Object.keys(matchset);
  28278. var self = this;
  28279. var n = found.length;
  28280. if (n === 0)
  28281. return cb()
  28282. var set = this.matches[index] = Object.create(null);
  28283. found.forEach(function (p, i) {
  28284. // If there's a problem with the stat, then it means that
  28285. // one or more of the links in the realpath couldn't be
  28286. // resolved. just return the abs value in that case.
  28287. p = self._makeAbs(p);
  28288. fs_realpath.realpath(p, self.realpathCache, function (er, real) {
  28289. if (!er)
  28290. set[real] = true;
  28291. else if (er.syscall === 'stat')
  28292. set[p] = true;
  28293. else
  28294. self.emit('error', er); // srsly wtf right here
  28295. if (--n === 0) {
  28296. self.matches[index] = set;
  28297. cb();
  28298. }
  28299. });
  28300. });
  28301. };
  28302. Glob.prototype._mark = function (p) {
  28303. return common.mark(this, p)
  28304. };
  28305. Glob.prototype._makeAbs = function (f) {
  28306. return common.makeAbs(this, f)
  28307. };
  28308. Glob.prototype.abort = function () {
  28309. this.aborted = true;
  28310. this.emit('abort');
  28311. };
  28312. Glob.prototype.pause = function () {
  28313. if (!this.paused) {
  28314. this.paused = true;
  28315. this.emit('pause');
  28316. }
  28317. };
  28318. Glob.prototype.resume = function () {
  28319. if (this.paused) {
  28320. this.emit('resume');
  28321. this.paused = false;
  28322. if (this._emitQueue.length) {
  28323. var eq = this._emitQueue.slice(0);
  28324. this._emitQueue.length = 0;
  28325. for (var i = 0; i < eq.length; i ++) {
  28326. var e = eq[i];
  28327. this._emitMatch(e[0], e[1]);
  28328. }
  28329. }
  28330. if (this._processQueue.length) {
  28331. var pq = this._processQueue.slice(0);
  28332. this._processQueue.length = 0;
  28333. for (var i = 0; i < pq.length; i ++) {
  28334. var p = pq[i];
  28335. this._processing--;
  28336. this._process(p[0], p[1], p[2], p[3]);
  28337. }
  28338. }
  28339. }
  28340. };
  28341. Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
  28342. assert(this instanceof Glob);
  28343. assert(typeof cb === 'function');
  28344. if (this.aborted)
  28345. return
  28346. this._processing++;
  28347. if (this.paused) {
  28348. this._processQueue.push([pattern, index, inGlobStar, cb]);
  28349. return
  28350. }
  28351. //console.error('PROCESS %d', this._processing, pattern)
  28352. // Get the first [n] parts of pattern that are all strings.
  28353. var n = 0;
  28354. while (typeof pattern[n] === 'string') {
  28355. n ++;
  28356. }
  28357. // now n is the index of the first one that is *not* a string.
  28358. // see if there's anything else
  28359. var prefix;
  28360. switch (n) {
  28361. // if not, then this is rather simple
  28362. case pattern.length:
  28363. this._processSimple(pattern.join('/'), index, cb);
  28364. return
  28365. case 0:
  28366. // pattern *starts* with some non-trivial item.
  28367. // going to readdir(cwd), but not include the prefix in matches.
  28368. prefix = null;
  28369. break
  28370. default:
  28371. // pattern has some string bits in the front.
  28372. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  28373. // or 'relative' like '../baz'
  28374. prefix = pattern.slice(0, n).join('/');
  28375. break
  28376. }
  28377. var remain = pattern.slice(n);
  28378. // get the list of entries.
  28379. var read;
  28380. if (prefix === null)
  28381. read = '.';
  28382. else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  28383. if (!prefix || !pathIsAbsolute(prefix))
  28384. prefix = '/' + prefix;
  28385. read = prefix;
  28386. } else
  28387. read = prefix;
  28388. var abs = this._makeAbs(read);
  28389. //if ignored, skip _processing
  28390. if (childrenIgnored(this, read))
  28391. return cb()
  28392. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  28393. if (isGlobStar)
  28394. this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb);
  28395. else
  28396. this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb);
  28397. };
  28398. Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  28399. var self = this;
  28400. this._readdir(abs, inGlobStar, function (er, entries) {
  28401. return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb)
  28402. });
  28403. };
  28404. Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  28405. // if the abs isn't a dir, then nothing can match!
  28406. if (!entries)
  28407. return cb()
  28408. // It will only match dot entries if it starts with a dot, or if
  28409. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  28410. var pn = remain[0];
  28411. var negate = !!this.minimatch.negate;
  28412. var rawGlob = pn._glob;
  28413. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  28414. var matchedEntries = [];
  28415. for (var i = 0; i < entries.length; i++) {
  28416. var e = entries[i];
  28417. if (e.charAt(0) !== '.' || dotOk) {
  28418. var m;
  28419. if (negate && !prefix) {
  28420. m = !e.match(pn);
  28421. } else {
  28422. m = e.match(pn);
  28423. }
  28424. if (m)
  28425. matchedEntries.push(e);
  28426. }
  28427. }
  28428. //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
  28429. var len = matchedEntries.length;
  28430. // If there are no matched entries, then nothing matches.
  28431. if (len === 0)
  28432. return cb()
  28433. // if this is the last remaining pattern bit, then no need for
  28434. // an additional stat *unless* the user has specified mark or
  28435. // stat explicitly. We know they exist, since readdir returned
  28436. // them.
  28437. if (remain.length === 1 && !this.mark && !this.stat) {
  28438. if (!this.matches[index])
  28439. this.matches[index] = Object.create(null);
  28440. for (var i = 0; i < len; i ++) {
  28441. var e = matchedEntries[i];
  28442. if (prefix) {
  28443. if (prefix !== '/')
  28444. e = prefix + '/' + e;
  28445. else
  28446. e = prefix + e;
  28447. }
  28448. if (e.charAt(0) === '/' && !this.nomount) {
  28449. e = path.join(this.root, e);
  28450. }
  28451. this._emitMatch(index, e);
  28452. }
  28453. // This was the last one, and no stats were needed
  28454. return cb()
  28455. }
  28456. // now test all matched entries as stand-ins for that part
  28457. // of the pattern.
  28458. remain.shift();
  28459. for (var i = 0; i < len; i ++) {
  28460. var e = matchedEntries[i];
  28461. var newPattern;
  28462. if (prefix) {
  28463. if (prefix !== '/')
  28464. e = prefix + '/' + e;
  28465. else
  28466. e = prefix + e;
  28467. }
  28468. this._process([e].concat(remain), index, inGlobStar, cb);
  28469. }
  28470. cb();
  28471. };
  28472. Glob.prototype._emitMatch = function (index, e) {
  28473. if (this.aborted)
  28474. return
  28475. if (isIgnored(this, e))
  28476. return
  28477. if (this.paused) {
  28478. this._emitQueue.push([index, e]);
  28479. return
  28480. }
  28481. var abs = pathIsAbsolute(e) ? e : this._makeAbs(e);
  28482. if (this.mark)
  28483. e = this._mark(e);
  28484. if (this.absolute)
  28485. e = abs;
  28486. if (this.matches[index][e])
  28487. return
  28488. if (this.nodir) {
  28489. var c = this.cache[abs];
  28490. if (c === 'DIR' || Array.isArray(c))
  28491. return
  28492. }
  28493. this.matches[index][e] = true;
  28494. var st = this.statCache[abs];
  28495. if (st)
  28496. this.emit('stat', e, st);
  28497. this.emit('match', e);
  28498. };
  28499. Glob.prototype._readdirInGlobStar = function (abs, cb) {
  28500. if (this.aborted)
  28501. return
  28502. // follow all symlinked directories forever
  28503. // just proceed as if this is a non-globstar situation
  28504. if (this.follow)
  28505. return this._readdir(abs, false, cb)
  28506. var lstatkey = 'lstat\0' + abs;
  28507. var self = this;
  28508. var lstatcb = inflight_1(lstatkey, lstatcb_);
  28509. if (lstatcb)
  28510. fs.lstat(abs, lstatcb);
  28511. function lstatcb_ (er, lstat) {
  28512. if (er && er.code === 'ENOENT')
  28513. return cb()
  28514. var isSym = lstat && lstat.isSymbolicLink();
  28515. self.symlinks[abs] = isSym;
  28516. // If it's not a symlink or a dir, then it's definitely a regular file.
  28517. // don't bother doing a readdir in that case.
  28518. if (!isSym && lstat && !lstat.isDirectory()) {
  28519. self.cache[abs] = 'FILE';
  28520. cb();
  28521. } else
  28522. self._readdir(abs, false, cb);
  28523. }
  28524. };
  28525. Glob.prototype._readdir = function (abs, inGlobStar, cb) {
  28526. if (this.aborted)
  28527. return
  28528. cb = inflight_1('readdir\0'+abs+'\0'+inGlobStar, cb);
  28529. if (!cb)
  28530. return
  28531. //console.error('RD %j %j', +inGlobStar, abs)
  28532. if (inGlobStar && !ownProp(this.symlinks, abs))
  28533. return this._readdirInGlobStar(abs, cb)
  28534. if (ownProp(this.cache, abs)) {
  28535. var c = this.cache[abs];
  28536. if (!c || c === 'FILE')
  28537. return cb()
  28538. if (Array.isArray(c))
  28539. return cb(null, c)
  28540. }
  28541. var self = this;
  28542. fs.readdir(abs, readdirCb(this, abs, cb));
  28543. };
  28544. function readdirCb (self, abs, cb) {
  28545. return function (er, entries) {
  28546. if (er)
  28547. self._readdirError(abs, er, cb);
  28548. else
  28549. self._readdirEntries(abs, entries, cb);
  28550. }
  28551. }
  28552. Glob.prototype._readdirEntries = function (abs, entries, cb) {
  28553. if (this.aborted)
  28554. return
  28555. // if we haven't asked to stat everything, then just
  28556. // assume that everything in there exists, so we can avoid
  28557. // having to stat it a second time.
  28558. if (!this.mark && !this.stat) {
  28559. for (var i = 0; i < entries.length; i ++) {
  28560. var e = entries[i];
  28561. if (abs === '/')
  28562. e = abs + e;
  28563. else
  28564. e = abs + '/' + e;
  28565. this.cache[e] = true;
  28566. }
  28567. }
  28568. this.cache[abs] = entries;
  28569. return cb(null, entries)
  28570. };
  28571. Glob.prototype._readdirError = function (f, er, cb) {
  28572. if (this.aborted)
  28573. return
  28574. // handle errors, and cache the information
  28575. switch (er.code) {
  28576. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  28577. case 'ENOTDIR': // totally normal. means it *does* exist.
  28578. var abs = this._makeAbs(f);
  28579. this.cache[abs] = 'FILE';
  28580. if (abs === this.cwdAbs) {
  28581. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  28582. error.path = this.cwd;
  28583. error.code = er.code;
  28584. this.emit('error', error);
  28585. this.abort();
  28586. }
  28587. break
  28588. case 'ENOENT': // not terribly unusual
  28589. case 'ELOOP':
  28590. case 'ENAMETOOLONG':
  28591. case 'UNKNOWN':
  28592. this.cache[this._makeAbs(f)] = false;
  28593. break
  28594. default: // some unusual error. Treat as failure.
  28595. this.cache[this._makeAbs(f)] = false;
  28596. if (this.strict) {
  28597. this.emit('error', er);
  28598. // If the error is handled, then we abort
  28599. // if not, we threw out of here
  28600. this.abort();
  28601. }
  28602. if (!this.silent)
  28603. console.error('glob error', er);
  28604. break
  28605. }
  28606. return cb()
  28607. };
  28608. Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  28609. var self = this;
  28610. this._readdir(abs, inGlobStar, function (er, entries) {
  28611. self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
  28612. });
  28613. };
  28614. Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  28615. //console.error('pgs2', prefix, remain[0], entries)
  28616. // no entries means not a dir, so it can never have matches
  28617. // foo.txt/** doesn't match foo.txt
  28618. if (!entries)
  28619. return cb()
  28620. // test without the globstar, and with every child both below
  28621. // and replacing the globstar.
  28622. var remainWithoutGlobStar = remain.slice(1);
  28623. var gspref = prefix ? [ prefix ] : [];
  28624. var noGlobStar = gspref.concat(remainWithoutGlobStar);
  28625. // the noGlobStar pattern exits the inGlobStar state
  28626. this._process(noGlobStar, index, false, cb);
  28627. var isSym = this.symlinks[abs];
  28628. var len = entries.length;
  28629. // If it's a symlink, and we're in a globstar, then stop
  28630. if (isSym && inGlobStar)
  28631. return cb()
  28632. for (var i = 0; i < len; i++) {
  28633. var e = entries[i];
  28634. if (e.charAt(0) === '.' && !this.dot)
  28635. continue
  28636. // these two cases enter the inGlobStar state
  28637. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  28638. this._process(instead, index, true, cb);
  28639. var below = gspref.concat(entries[i], remain);
  28640. this._process(below, index, true, cb);
  28641. }
  28642. cb();
  28643. };
  28644. Glob.prototype._processSimple = function (prefix, index, cb) {
  28645. // XXX review this. Shouldn't it be doing the mounting etc
  28646. // before doing stat? kinda weird?
  28647. var self = this;
  28648. this._stat(prefix, function (er, exists) {
  28649. self._processSimple2(prefix, index, er, exists, cb);
  28650. });
  28651. };
  28652. Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
  28653. //console.error('ps2', prefix, exists)
  28654. if (!this.matches[index])
  28655. this.matches[index] = Object.create(null);
  28656. // If it doesn't exist, then just mark the lack of results
  28657. if (!exists)
  28658. return cb()
  28659. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  28660. var trail = /[\/\\]$/.test(prefix);
  28661. if (prefix.charAt(0) === '/') {
  28662. prefix = path.join(this.root, prefix);
  28663. } else {
  28664. prefix = path.resolve(this.root, prefix);
  28665. if (trail)
  28666. prefix += '/';
  28667. }
  28668. }
  28669. if (process.platform === 'win32')
  28670. prefix = prefix.replace(/\\/g, '/');
  28671. // Mark this as a match
  28672. this._emitMatch(index, prefix);
  28673. cb();
  28674. };
  28675. // Returns either 'DIR', 'FILE', or false
  28676. Glob.prototype._stat = function (f, cb) {
  28677. var abs = this._makeAbs(f);
  28678. var needDir = f.slice(-1) === '/';
  28679. if (f.length > this.maxLength)
  28680. return cb()
  28681. if (!this.stat && ownProp(this.cache, abs)) {
  28682. var c = this.cache[abs];
  28683. if (Array.isArray(c))
  28684. c = 'DIR';
  28685. // It exists, but maybe not how we need it
  28686. if (!needDir || c === 'DIR')
  28687. return cb(null, c)
  28688. if (needDir && c === 'FILE')
  28689. return cb()
  28690. // otherwise we have to stat, because maybe c=true
  28691. // if we know it exists, but not what it is.
  28692. }
  28693. var exists;
  28694. var stat = this.statCache[abs];
  28695. if (stat !== undefined) {
  28696. if (stat === false)
  28697. return cb(null, stat)
  28698. else {
  28699. var type = stat.isDirectory() ? 'DIR' : 'FILE';
  28700. if (needDir && type === 'FILE')
  28701. return cb()
  28702. else
  28703. return cb(null, type, stat)
  28704. }
  28705. }
  28706. var self = this;
  28707. var statcb = inflight_1('stat\0' + abs, lstatcb_);
  28708. if (statcb)
  28709. fs.lstat(abs, statcb);
  28710. function lstatcb_ (er, lstat) {
  28711. if (lstat && lstat.isSymbolicLink()) {
  28712. // If it's a symlink, then treat it as the target, unless
  28713. // the target does not exist, then treat it as a file.
  28714. return fs.stat(abs, function (er, stat) {
  28715. if (er)
  28716. self._stat2(f, abs, null, lstat, cb);
  28717. else
  28718. self._stat2(f, abs, er, stat, cb);
  28719. })
  28720. } else {
  28721. self._stat2(f, abs, er, lstat, cb);
  28722. }
  28723. }
  28724. };
  28725. Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
  28726. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  28727. this.statCache[abs] = false;
  28728. return cb()
  28729. }
  28730. var needDir = f.slice(-1) === '/';
  28731. this.statCache[abs] = stat;
  28732. if (abs.slice(-1) === '/' && stat && !stat.isDirectory())
  28733. return cb(null, false, stat)
  28734. var c = true;
  28735. if (stat)
  28736. c = stat.isDirectory() ? 'DIR' : 'FILE';
  28737. this.cache[abs] = this.cache[abs] || c;
  28738. if (needDir && c === 'FILE')
  28739. return cb()
  28740. return cb(null, c, stat)
  28741. };
  28742. var pify_1 = createCommonjsModule(function (module) {
  28743. 'use strict';
  28744. var processFn = function (fn, P, opts) {
  28745. return function () {
  28746. var that = this;
  28747. var args = new Array(arguments.length);
  28748. for (var i = 0; i < arguments.length; i++) {
  28749. args[i] = arguments[i];
  28750. }
  28751. return new P(function (resolve, reject) {
  28752. args.push(function (err, result) {
  28753. if (err) {
  28754. reject(err);
  28755. } else if (opts.multiArgs) {
  28756. var results = new Array(arguments.length - 1);
  28757. for (var i = 1; i < arguments.length; i++) {
  28758. results[i - 1] = arguments[i];
  28759. }
  28760. resolve(results);
  28761. } else {
  28762. resolve(result);
  28763. }
  28764. });
  28765. fn.apply(that, args);
  28766. });
  28767. };
  28768. };
  28769. var pify = module.exports = function (obj, P, opts) {
  28770. if (typeof P !== 'function') {
  28771. opts = P;
  28772. P = Promise;
  28773. }
  28774. opts = opts || {};
  28775. opts.exclude = opts.exclude || [/.+Sync$/];
  28776. var filter = function (key) {
  28777. var match = function (pattern) {
  28778. return typeof pattern === 'string' ? key === pattern : pattern.test(key);
  28779. };
  28780. return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
  28781. };
  28782. var ret = typeof obj === 'function' ? function () {
  28783. if (opts.excludeMain) {
  28784. return obj.apply(this, arguments);
  28785. }
  28786. return processFn(obj, P, opts).apply(this, arguments);
  28787. } : {};
  28788. return Object.keys(obj).reduce(function (ret, key) {
  28789. var x = obj[key];
  28790. ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x;
  28791. return ret;
  28792. }, ret);
  28793. };
  28794. pify.all = pify;
  28795. });
  28796. var globP = pify_1(glob_1, pinkiePromise).bind(glob_1);
  28797. function isNegative(pattern) {
  28798. return pattern[0] === '!';
  28799. }
  28800. function isString(value) {
  28801. return typeof value === 'string';
  28802. }
  28803. function assertPatternsInput(patterns) {
  28804. if (!patterns.every(isString)) {
  28805. throw new TypeError('patterns must be a string or an array of strings');
  28806. }
  28807. }
  28808. function generateGlobTasks(patterns, opts) {
  28809. patterns = [].concat(patterns);
  28810. assertPatternsInput(patterns);
  28811. var globTasks = [];
  28812. opts = objectAssign({
  28813. cache: Object.create(null),
  28814. statCache: Object.create(null),
  28815. realpathCache: Object.create(null),
  28816. symlinks: Object.create(null),
  28817. ignore: []
  28818. }, opts);
  28819. patterns.forEach(function (pattern, i) {
  28820. if (isNegative(pattern)) {
  28821. return;
  28822. }
  28823. var ignore = patterns.slice(i).filter(isNegative).map(function (pattern) {
  28824. return pattern.slice(1);
  28825. });
  28826. globTasks.push({
  28827. pattern: pattern,
  28828. opts: objectAssign({}, opts, {
  28829. ignore: opts.ignore.concat(ignore)
  28830. })
  28831. });
  28832. });
  28833. return globTasks;
  28834. }
  28835. var globby = function (patterns, opts) {
  28836. var globTasks;
  28837. try {
  28838. globTasks = generateGlobTasks(patterns, opts);
  28839. } catch (err) {
  28840. return pinkiePromise.reject(err);
  28841. }
  28842. return pinkiePromise.all(globTasks.map(function (task) {
  28843. return globP(task.pattern, task.opts);
  28844. })).then(function (paths) {
  28845. return arrayUnion.apply(null, paths);
  28846. });
  28847. };
  28848. var sync$3 = function (patterns, opts) {
  28849. var globTasks = generateGlobTasks(patterns, opts);
  28850. return globTasks.reduce(function (matches, task) {
  28851. return arrayUnion(matches, glob_1.sync(task.pattern, task.opts));
  28852. }, []);
  28853. };
  28854. var generateGlobTasks_1 = generateGlobTasks;
  28855. var hasMagic = function (patterns, opts) {
  28856. return [].concat(patterns).some(function (pattern) {
  28857. return glob_1.hasMagic(pattern, opts);
  28858. });
  28859. };
  28860. globby.sync = sync$3;
  28861. globby.generateGlobTasks = generateGlobTasks_1;
  28862. globby.hasMagic = hasMagic;
  28863. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  28864. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  28865. var ignore = function () {
  28866. return new IgnoreBase();
  28867. };
  28868. // A simple implementation of make-array
  28869. function make_array(subject) {
  28870. return Array.isArray(subject) ? subject : [subject];
  28871. }
  28872. var REGEX_BLANK_LINE = /^\s+$/;
  28873. var REGEX_LEADING_EXCAPED_EXCLAMATION = /^\\\!/;
  28874. var REGEX_LEADING_EXCAPED_HASH = /^\\#/;
  28875. var SLASH = '/';
  28876. var KEY_IGNORE = typeof Symbol !== 'undefined' ? Symbol.for('node-ignore')
  28877. /* istanbul ignore next */
  28878. : 'node-ignore';
  28879. var IgnoreBase = function () {
  28880. function IgnoreBase() {
  28881. _classCallCheck(this, IgnoreBase);
  28882. this._rules = [];
  28883. this[KEY_IGNORE] = true;
  28884. this._initCache();
  28885. }
  28886. _createClass(IgnoreBase, [{
  28887. key: '_initCache',
  28888. value: function _initCache() {
  28889. this._cache = {};
  28890. }
  28891. // @param {Array.<string>|string|Ignore} pattern
  28892. }, {
  28893. key: 'add',
  28894. value: function add(pattern) {
  28895. this._added = false;
  28896. if (typeof pattern === 'string') {
  28897. pattern = pattern.split(/\r?\n/g);
  28898. }
  28899. make_array(pattern).forEach(this._addPattern, this);
  28900. // Some rules have just added to the ignore,
  28901. // making the behavior changed.
  28902. if (this._added) {
  28903. this._initCache();
  28904. }
  28905. return this;
  28906. }
  28907. // legacy
  28908. }, {
  28909. key: 'addPattern',
  28910. value: function addPattern(pattern) {
  28911. return this.add(pattern);
  28912. }
  28913. }, {
  28914. key: '_addPattern',
  28915. value: function _addPattern(pattern) {
  28916. // #32
  28917. if (pattern && pattern[KEY_IGNORE]) {
  28918. this._rules = this._rules.concat(pattern._rules);
  28919. this._added = true;
  28920. return;
  28921. }
  28922. if (this._checkPattern(pattern)) {
  28923. var rule = this._createRule(pattern);
  28924. this._added = true;
  28925. this._rules.push(rule);
  28926. }
  28927. }
  28928. }, {
  28929. key: '_checkPattern',
  28930. value: function _checkPattern(pattern) {
  28931. // > A blank line matches no files, so it can serve as a separator for readability.
  28932. return pattern && typeof pattern === 'string' && !REGEX_BLANK_LINE.test(pattern)
  28933. // > A line starting with # serves as a comment.
  28934. && pattern.indexOf('#') !== 0;
  28935. }
  28936. }, {
  28937. key: 'filter',
  28938. value: function filter(paths) {
  28939. var _this = this;
  28940. return make_array(paths).filter(function (path$$1) {
  28941. return _this._filter(path$$1);
  28942. });
  28943. }
  28944. }, {
  28945. key: 'createFilter',
  28946. value: function createFilter() {
  28947. var _this2 = this;
  28948. return function (path$$1) {
  28949. return _this2._filter(path$$1);
  28950. };
  28951. }
  28952. }, {
  28953. key: 'ignores',
  28954. value: function ignores(path$$1) {
  28955. return !this._filter(path$$1);
  28956. }
  28957. }, {
  28958. key: '_createRule',
  28959. value: function _createRule(pattern) {
  28960. var origin = pattern;
  28961. var negative = false;
  28962. // > An optional prefix "!" which negates the pattern;
  28963. if (pattern.indexOf('!') === 0) {
  28964. negative = true;
  28965. pattern = pattern.substr(1);
  28966. }
  28967. pattern = pattern
  28968. // > Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, `"\!important!.txt"`.
  28969. .replace(REGEX_LEADING_EXCAPED_EXCLAMATION, '!')
  28970. // > Put a backslash ("\") in front of the first hash for patterns that begin with a hash.
  28971. .replace(REGEX_LEADING_EXCAPED_HASH, '#');
  28972. var regex = make_regex(pattern, negative);
  28973. return {
  28974. origin: origin,
  28975. pattern: pattern,
  28976. negative: negative,
  28977. regex: regex
  28978. };
  28979. }
  28980. // @returns `Boolean` true if the `path` is NOT ignored
  28981. }, {
  28982. key: '_filter',
  28983. value: function _filter(path$$1, slices) {
  28984. if (!path$$1) {
  28985. return false;
  28986. }
  28987. if (path$$1 in this._cache) {
  28988. return this._cache[path$$1];
  28989. }
  28990. if (!slices) {
  28991. // path/to/a.js
  28992. // ['path', 'to', 'a.js']
  28993. slices = path$$1.split(SLASH);
  28994. }
  28995. slices.pop();
  28996. return this._cache[path$$1] = slices.length
  28997. // > It is not possible to re-include a file if a parent directory of that file is excluded.
  28998. // If the path contains a parent directory, check the parent first
  28999. ? this._filter(slices.join(SLASH) + SLASH, slices) && this._test(path$$1)
  29000. // Or only test the path
  29001. : this._test(path$$1);
  29002. }
  29003. // @returns {Boolean} true if a file is NOT ignored
  29004. }, {
  29005. key: '_test',
  29006. value: function _test(path$$1) {
  29007. // Explicitly define variable type by setting matched to `0`
  29008. var matched = 0;
  29009. this._rules.forEach(function (rule) {
  29010. // if matched = true, then we only test negative rules
  29011. // if matched = false, then we test non-negative rules
  29012. if (!(matched ^ rule.negative)) {
  29013. matched = rule.negative ^ rule.regex.test(path$$1);
  29014. }
  29015. });
  29016. return !matched;
  29017. }
  29018. }]);
  29019. return IgnoreBase;
  29020. }();
  29021. // > If the pattern ends with a slash,
  29022. // > it is removed for the purpose of the following description,
  29023. // > but it would only find a match with a directory.
  29024. // > In other words, foo/ will match a directory foo and paths underneath it,
  29025. // > but will not match a regular file or a symbolic link foo
  29026. // > (this is consistent with the way how pathspec works in general in Git).
  29027. // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
  29028. // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
  29029. // you could use option `mark: true` with `glob`
  29030. // '`foo/`' should not continue with the '`..`'
  29031. var DEFAULT_REPLACER_PREFIX = [
  29032. // > Trailing spaces are ignored unless they are quoted with backslash ("\")
  29033. [
  29034. // (a\ ) -> (a )
  29035. // (a ) -> (a)
  29036. // (a \ ) -> (a )
  29037. /\\?\s+$/, function (match) {
  29038. return match.indexOf('\\') === 0 ? ' ' : '';
  29039. }],
  29040. // replace (\ ) with ' '
  29041. [/\\\s/g, function () {
  29042. return ' ';
  29043. }],
  29044. // Escape metacharacters
  29045. // which is written down by users but means special for regular expressions.
  29046. // > There are 12 characters with special meanings:
  29047. // > - the backslash \,
  29048. // > - the caret ^,
  29049. // > - the dollar sign $,
  29050. // > - the period or dot .,
  29051. // > - the vertical bar or pipe symbol |,
  29052. // > - the question mark ?,
  29053. // > - the asterisk or star *,
  29054. // > - the plus sign +,
  29055. // > - the opening parenthesis (,
  29056. // > - the closing parenthesis ),
  29057. // > - and the opening square bracket [,
  29058. // > - the opening curly brace {,
  29059. // > These special characters are often called "metacharacters".
  29060. [/[\\\^$.|?*+()\[{]/g, function (match) {
  29061. return '\\' + match;
  29062. }],
  29063. // leading slash
  29064. [
  29065. // > A leading slash matches the beginning of the pathname.
  29066. // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
  29067. // A leading slash matches the beginning of the pathname
  29068. /^\//, function () {
  29069. return '^';
  29070. }],
  29071. // replace special metacharacter slash after the leading slash
  29072. [/\//g, function () {
  29073. return '\\/';
  29074. }], [
  29075. // > A leading "**" followed by a slash means match in all directories.
  29076. // > For example, "**/foo" matches file or directory "foo" anywhere,
  29077. // > the same as pattern "foo".
  29078. // > "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".
  29079. // Notice that the '*'s have been replaced as '\\*'
  29080. /^\^*\\\*\\\*\\\//,
  29081. // '**/foo' <-> 'foo'
  29082. function () {
  29083. return '^(?:.*\\/)?';
  29084. }]];
  29085. var DEFAULT_REPLACER_SUFFIX = [
  29086. // starting
  29087. [
  29088. // there will be no leading '/' (which has been replaced by section "leading slash")
  29089. // If starts with '**', adding a '^' to the regular expression also works
  29090. /^(?=[^\^])/, function () {
  29091. return !/\/(?!$)/.test(this)
  29092. // > If the pattern does not contain a slash /, Git treats it as a shell glob pattern
  29093. // Actually, if there is only a trailing slash, git also treats it as a shell glob pattern
  29094. ? '(?:^|\\/)'
  29095. // > Otherwise, Git treats the pattern as a shell glob suitable for consumption by fnmatch(3)
  29096. : '^';
  29097. }],
  29098. // two globstars
  29099. [
  29100. // Use lookahead assertions so that we could match more than one `'/**'`
  29101. /\\\/\\\*\\\*(?=\\\/|$)/g,
  29102. // Zero, one or several directories
  29103. // should not use '*', or it will be replaced by the next replacer
  29104. // Check if it is not the last `'/**'`
  29105. function (match, index, str) {
  29106. return index + 6 < str.length
  29107. // case: /**/
  29108. // > A slash followed by two consecutive asterisks then a slash matches zero or more directories.
  29109. // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
  29110. // '/**/'
  29111. ? '(?:\\/[^\\/]+)*'
  29112. // case: /**
  29113. // > A trailing `"/**"` matches everything inside.
  29114. // #21: everything inside but it should not include the current folder
  29115. : '\\/.+';
  29116. }],
  29117. // intermediate wildcards
  29118. [
  29119. // Never replace escaped '*'
  29120. // ignore rule '\*' will match the path '*'
  29121. // 'abc.*/' -> go
  29122. // 'abc.*' -> skip this rule
  29123. /(^|[^\\]+)\\\*(?=.+)/g,
  29124. // '*.js' matches '.js'
  29125. // '*.js' doesn't match 'abc'
  29126. function (match, p1) {
  29127. return p1 + '[^\\/]*';
  29128. }],
  29129. // trailing wildcard
  29130. [/(\^|\\\/)?\\\*$/, function (match, p1) {
  29131. return (p1
  29132. // '\^':
  29133. // '/*' does not match ''
  29134. // '/*' does not match everything
  29135. // '\\\/':
  29136. // 'abc/*' does not match 'abc/'
  29137. ? p1 + '[^/]+'
  29138. // 'a*' matches 'a'
  29139. // 'a*' matches 'aa'
  29140. : '[^/]*') + '(?=$|\\/$)';
  29141. }], [
  29142. // unescape
  29143. /\\\\\\/g, function () {
  29144. return '\\';
  29145. }]];
  29146. var POSITIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [
  29147. // 'f'
  29148. // matches
  29149. // - /f(end)
  29150. // - /f/
  29151. // - (start)f(end)
  29152. // - (start)f/
  29153. // doesn't match
  29154. // - oof
  29155. // - foo
  29156. // pseudo:
  29157. // -> (^|/)f(/|$)
  29158. // ending
  29159. [
  29160. // 'js' will not match 'js.'
  29161. // 'ab' will not match 'abc'
  29162. /(?:[^*\/])$/,
  29163. // 'js*' will not match 'a.js'
  29164. // 'js/' will not match 'a.js'
  29165. // 'js' will match 'a.js' and 'a.js/'
  29166. function (match) {
  29167. return match + '(?=$|\\/)';
  29168. }]], DEFAULT_REPLACER_SUFFIX);
  29169. var NEGATIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [
  29170. // #24
  29171. // The MISSING rule of [gitignore docs](https://git-scm.com/docs/gitignore)
  29172. // A negative pattern without a trailing wildcard should not
  29173. // re-include the things inside that directory.
  29174. // eg:
  29175. // ['node_modules/*', '!node_modules']
  29176. // should ignore `node_modules/a.js`
  29177. [/(?:[^*\/])$/, function (match) {
  29178. return match + '(?=$|\\/$)';
  29179. }]], DEFAULT_REPLACER_SUFFIX);
  29180. // A simple cache, because an ignore rule only has only one certain meaning
  29181. var cache = {};
  29182. // @param {pattern}
  29183. function make_regex(pattern, negative) {
  29184. var r = cache[pattern];
  29185. if (r) {
  29186. return r;
  29187. }
  29188. var replacers = negative ? NEGATIVE_REPLACERS : POSITIVE_REPLACERS;
  29189. var source = replacers.reduce(function (prev, current) {
  29190. return prev.replace(current[0], current[1].bind(pattern));
  29191. }, pattern);
  29192. return cache[pattern] = new RegExp(source, 'i');
  29193. }
  29194. // Windows
  29195. // --------------------------------------------------------------
  29196. /* istanbul ignore if */
  29197. if (
  29198. // Detect `process` so that it can run in browsers.
  29199. typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) {
  29200. var filter$1 = IgnoreBase.prototype._filter;
  29201. var make_posix = function make_posix(str) {
  29202. return (/^\\\\\?\\/.test(str) || /[^\x00-\x80]+/.test(str) ? str : str.replace(/\\/g, '/')
  29203. );
  29204. };
  29205. IgnoreBase.prototype._filter = function (path$$1, slices) {
  29206. path$$1 = make_posix(path$$1);
  29207. return filter$1.call(this, path$$1, slices);
  29208. };
  29209. }
  29210. var ansiStyles$3 = createCommonjsModule(function (module) {
  29211. 'use strict';
  29212. const wrapAnsi16 = (fn, offset) => function () {
  29213. const code = fn.apply(colorConvert, arguments);
  29214. return `\u001B[${code + offset}m`;
  29215. };
  29216. const wrapAnsi256 = (fn, offset) => function () {
  29217. const code = fn.apply(colorConvert, arguments);
  29218. return `\u001B[${38 + offset};5;${code}m`;
  29219. };
  29220. const wrapAnsi16m = (fn, offset) => function () {
  29221. const rgb = fn.apply(colorConvert, arguments);
  29222. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  29223. };
  29224. function assembleStyles() {
  29225. const styles = {
  29226. modifier: {
  29227. reset: [0, 0],
  29228. // 21 isn't widely supported and 22 does the same thing
  29229. bold: [1, 22],
  29230. dim: [2, 22],
  29231. italic: [3, 23],
  29232. underline: [4, 24],
  29233. inverse: [7, 27],
  29234. hidden: [8, 28],
  29235. strikethrough: [9, 29]
  29236. },
  29237. color: {
  29238. black: [30, 39],
  29239. red: [31, 39],
  29240. green: [32, 39],
  29241. yellow: [33, 39],
  29242. blue: [34, 39],
  29243. magenta: [35, 39],
  29244. cyan: [36, 39],
  29245. white: [37, 39],
  29246. gray: [90, 39],
  29247. // Bright color
  29248. redBright: [91, 39],
  29249. greenBright: [92, 39],
  29250. yellowBright: [93, 39],
  29251. blueBright: [94, 39],
  29252. magentaBright: [95, 39],
  29253. cyanBright: [96, 39],
  29254. whiteBright: [97, 39]
  29255. },
  29256. bgColor: {
  29257. bgBlack: [40, 49],
  29258. bgRed: [41, 49],
  29259. bgGreen: [42, 49],
  29260. bgYellow: [43, 49],
  29261. bgBlue: [44, 49],
  29262. bgMagenta: [45, 49],
  29263. bgCyan: [46, 49],
  29264. bgWhite: [47, 49],
  29265. // Bright color
  29266. bgBlackBright: [100, 49],
  29267. bgRedBright: [101, 49],
  29268. bgGreenBright: [102, 49],
  29269. bgYellowBright: [103, 49],
  29270. bgBlueBright: [104, 49],
  29271. bgMagentaBright: [105, 49],
  29272. bgCyanBright: [106, 49],
  29273. bgWhiteBright: [107, 49]
  29274. }
  29275. };
  29276. // Fix humans
  29277. styles.color.grey = styles.color.gray;
  29278. Object.keys(styles).forEach(groupName => {
  29279. const group = styles[groupName];
  29280. Object.keys(group).forEach(styleName => {
  29281. const style = group[styleName];
  29282. styles[styleName] = {
  29283. open: `\u001B[${style[0]}m`,
  29284. close: `\u001B[${style[1]}m`
  29285. };
  29286. group[styleName] = styles[styleName];
  29287. });
  29288. Object.defineProperty(styles, groupName, {
  29289. value: group,
  29290. enumerable: false
  29291. });
  29292. });
  29293. const rgb2rgb = (r, g, b) => [r, g, b];
  29294. styles.color.close = '\u001B[39m';
  29295. styles.bgColor.close = '\u001B[49m';
  29296. styles.color.ansi = {};
  29297. styles.color.ansi256 = {};
  29298. styles.color.ansi16m = {
  29299. rgb: wrapAnsi16m(rgb2rgb, 0)
  29300. };
  29301. styles.bgColor.ansi = {};
  29302. styles.bgColor.ansi256 = {};
  29303. styles.bgColor.ansi16m = {
  29304. rgb: wrapAnsi16m(rgb2rgb, 10)
  29305. };
  29306. for (const key of Object.keys(colorConvert)) {
  29307. if (typeof colorConvert[key] !== 'object') {
  29308. continue;
  29309. }
  29310. const suite = colorConvert[key];
  29311. if ('ansi16' in suite) {
  29312. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  29313. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  29314. }
  29315. if ('ansi256' in suite) {
  29316. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  29317. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  29318. }
  29319. if ('rgb' in suite) {
  29320. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  29321. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  29322. }
  29323. }
  29324. return styles;
  29325. }
  29326. Object.defineProperty(module, 'exports', {
  29327. enumerable: true,
  29328. get: assembleStyles
  29329. });
  29330. });
  29331. var hasFlag$3 = function (flag, argv) {
  29332. argv = argv || process.argv;
  29333. var terminatorPos = argv.indexOf('--');
  29334. var prefix = /^-{1,2}/.test(flag) ? '' : '--';
  29335. var pos = argv.indexOf(prefix + flag);
  29336. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  29337. };
  29338. var supportsColor$3 = createCommonjsModule(function (module) {
  29339. 'use strict';
  29340. const env = process.env;
  29341. const support = level => {
  29342. if (level === 0) {
  29343. return false;
  29344. }
  29345. return {
  29346. level,
  29347. hasBasic: true,
  29348. has256: level >= 2,
  29349. has16m: level >= 3
  29350. };
  29351. };
  29352. let supportLevel = (() => {
  29353. if (hasFlag$3('no-color') ||
  29354. hasFlag$3('no-colors') ||
  29355. hasFlag$3('color=false')) {
  29356. return 0;
  29357. }
  29358. if (hasFlag$3('color=16m') ||
  29359. hasFlag$3('color=full') ||
  29360. hasFlag$3('color=truecolor')) {
  29361. return 3;
  29362. }
  29363. if (hasFlag$3('color=256')) {
  29364. return 2;
  29365. }
  29366. if (hasFlag$3('color') ||
  29367. hasFlag$3('colors') ||
  29368. hasFlag$3('color=true') ||
  29369. hasFlag$3('color=always')) {
  29370. return 1;
  29371. }
  29372. if (process.stdout && !process.stdout.isTTY) {
  29373. return 0;
  29374. }
  29375. if (process.platform === 'win32') {
  29376. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  29377. // libuv that enables 256 color output on Windows. Anything earlier and it
  29378. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  29379. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  29380. // release that supports 256 colors.
  29381. const osRelease = os.release().split('.');
  29382. if (
  29383. Number(process.version.split('.')[0]) >= 8 &&
  29384. Number(osRelease[0]) >= 10 &&
  29385. Number(osRelease[2]) >= 10586
  29386. ) {
  29387. return 2;
  29388. }
  29389. return 1;
  29390. }
  29391. if ('CI' in env) {
  29392. if ('TRAVIS' in env || env.CI === 'Travis' || 'CIRCLECI' in env) {
  29393. return 1;
  29394. }
  29395. return 0;
  29396. }
  29397. if ('TEAMCITY_VERSION' in env) {
  29398. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  29399. }
  29400. if ('TERM_PROGRAM' in env) {
  29401. const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  29402. switch (env.TERM_PROGRAM) {
  29403. case 'iTerm.app':
  29404. return version >= 3 ? 3 : 2;
  29405. case 'Hyper':
  29406. return 3;
  29407. case 'Apple_Terminal':
  29408. return 2;
  29409. // No default
  29410. }
  29411. }
  29412. if (/^(screen|xterm)-256(?:color)?/.test(env.TERM)) {
  29413. return 2;
  29414. }
  29415. if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) {
  29416. return 1;
  29417. }
  29418. if ('COLORTERM' in env) {
  29419. return 1;
  29420. }
  29421. if (env.TERM === 'dumb') {
  29422. return 0;
  29423. }
  29424. return 0;
  29425. })();
  29426. if ('FORCE_COLOR' in env) {
  29427. supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : (supportLevel || 1);
  29428. }
  29429. module.exports = process && support(supportLevel);
  29430. });
  29431. var templates$2 = createCommonjsModule(function (module) {
  29432. 'use strict';
  29433. const TEMPLATE_REGEX = /(?:\\(u[a-f0-9]{4}|x[a-f0-9]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  29434. const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  29435. const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  29436. const ESCAPE_REGEX = /\\(u[0-9a-f]{4}|x[0-9a-f]{2}|.)|([^\\])/gi;
  29437. const ESCAPES = {
  29438. n: '\n',
  29439. r: '\r',
  29440. t: '\t',
  29441. b: '\b',
  29442. f: '\f',
  29443. v: '\v',
  29444. 0: '\0',
  29445. '\\': '\\',
  29446. e: '\u001b',
  29447. a: '\u0007'
  29448. };
  29449. function unescape(c) {
  29450. if ((c[0] === 'u' && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
  29451. return String.fromCharCode(parseInt(c.slice(1), 16));
  29452. }
  29453. return ESCAPES[c] || c;
  29454. }
  29455. function parseArguments(name, args) {
  29456. const results = [];
  29457. const chunks = args.trim().split(/\s*,\s*/g);
  29458. let matches;
  29459. for (const chunk of chunks) {
  29460. if (!isNaN(chunk)) {
  29461. results.push(Number(chunk));
  29462. } else if ((matches = chunk.match(STRING_REGEX))) {
  29463. results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr));
  29464. } else {
  29465. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  29466. }
  29467. }
  29468. return results;
  29469. }
  29470. function parseStyle(style) {
  29471. STYLE_REGEX.lastIndex = 0;
  29472. const results = [];
  29473. let matches;
  29474. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  29475. const name = matches[1];
  29476. if (matches[2]) {
  29477. const args = parseArguments(name, matches[2]);
  29478. results.push([name].concat(args));
  29479. } else {
  29480. results.push([name]);
  29481. }
  29482. }
  29483. return results;
  29484. }
  29485. function buildStyle(chalk, styles) {
  29486. const enabled = {};
  29487. for (const layer of styles) {
  29488. for (const style of layer.styles) {
  29489. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  29490. }
  29491. }
  29492. let current = chalk;
  29493. for (const styleName of Object.keys(enabled)) {
  29494. if (Array.isArray(enabled[styleName])) {
  29495. if (!(styleName in current)) {
  29496. throw new Error(`Unknown Chalk style: ${styleName}`);
  29497. }
  29498. if (enabled[styleName].length > 0) {
  29499. current = current[styleName].apply(current, enabled[styleName]);
  29500. } else {
  29501. current = current[styleName];
  29502. }
  29503. }
  29504. }
  29505. return current;
  29506. }
  29507. module.exports = (chalk, tmp) => {
  29508. const styles = [];
  29509. const chunks = [];
  29510. let chunk = [];
  29511. // eslint-disable-next-line max-params
  29512. tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => {
  29513. if (escapeChar) {
  29514. chunk.push(unescape(escapeChar));
  29515. } else if (style) {
  29516. const str = chunk.join('');
  29517. chunk = [];
  29518. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  29519. styles.push({inverse, styles: parseStyle(style)});
  29520. } else if (close) {
  29521. if (styles.length === 0) {
  29522. throw new Error('Found extraneous } in Chalk template literal');
  29523. }
  29524. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  29525. chunk = [];
  29526. styles.pop();
  29527. } else {
  29528. chunk.push(chr);
  29529. }
  29530. });
  29531. chunks.push(chunk.join(''));
  29532. if (styles.length > 0) {
  29533. const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  29534. throw new Error(errMsg);
  29535. }
  29536. return chunks.join('');
  29537. };
  29538. });
  29539. const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
  29540. // `supportsColor.level` → `ansiStyles.color[name]` mapping
  29541. const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
  29542. // `color-convert` models to exclude from the Chalk API due to conflicts and such
  29543. const skipModels = new Set(['gray']);
  29544. const styles = Object.create(null);
  29545. function applyOptions(obj, options) {
  29546. options = options || {};
  29547. // Detect level if not set manually
  29548. const scLevel = supportsColor$3 ? supportsColor$3.level : 0;
  29549. obj.level = options.level === undefined ? scLevel : options.level;
  29550. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  29551. }
  29552. function Chalk(options) {
  29553. // We check for this.template here since calling `chalk.constructor()`
  29554. // by itself will have a `this` of a previously constructed chalk object
  29555. if (!this || !(this instanceof Chalk) || this.template) {
  29556. const chalk = {};
  29557. applyOptions(chalk, options);
  29558. chalk.template = function () {
  29559. const args = [].slice.call(arguments);
  29560. return chalkTag.apply(null, [chalk.template].concat(args));
  29561. };
  29562. Object.setPrototypeOf(chalk, Chalk.prototype);
  29563. Object.setPrototypeOf(chalk.template, chalk);
  29564. chalk.template.constructor = Chalk;
  29565. return chalk.template;
  29566. }
  29567. applyOptions(this, options);
  29568. }
  29569. // Use bright blue on Windows as the normal blue color is illegible
  29570. if (isSimpleWindowsTerm) {
  29571. ansiStyles$3.blue.open = '\u001B[94m';
  29572. }
  29573. for (const key of Object.keys(ansiStyles$3)) {
  29574. ansiStyles$3[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles$3[key].close), 'g');
  29575. styles[key] = {
  29576. get() {
  29577. const codes = ansiStyles$3[key];
  29578. return build$1.call(this, this._styles ? this._styles.concat(codes) : [codes], key);
  29579. }
  29580. };
  29581. }
  29582. ansiStyles$3.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles$3.color.close), 'g');
  29583. for (const model of Object.keys(ansiStyles$3.color.ansi)) {
  29584. if (skipModels.has(model)) {
  29585. continue;
  29586. }
  29587. styles[model] = {
  29588. get() {
  29589. const level = this.level;
  29590. return function () {
  29591. const open = ansiStyles$3.color[levelMapping[level]][model].apply(null, arguments);
  29592. const codes = {
  29593. open,
  29594. close: ansiStyles$3.color.close,
  29595. closeRe: ansiStyles$3.color.closeRe
  29596. };
  29597. return build$1.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
  29598. };
  29599. }
  29600. };
  29601. }
  29602. ansiStyles$3.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles$3.bgColor.close), 'g');
  29603. for (const model of Object.keys(ansiStyles$3.bgColor.ansi)) {
  29604. if (skipModels.has(model)) {
  29605. continue;
  29606. }
  29607. const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  29608. styles[bgModel] = {
  29609. get() {
  29610. const level = this.level;
  29611. return function () {
  29612. const open = ansiStyles$3.bgColor[levelMapping[level]][model].apply(null, arguments);
  29613. const codes = {
  29614. open,
  29615. close: ansiStyles$3.bgColor.close,
  29616. closeRe: ansiStyles$3.bgColor.closeRe
  29617. };
  29618. return build$1.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
  29619. };
  29620. }
  29621. };
  29622. }
  29623. const proto = Object.defineProperties(() => {}, styles);
  29624. function build$1(_styles, key) {
  29625. const builder = function () {
  29626. return applyStyle.apply(builder, arguments);
  29627. };
  29628. builder._styles = _styles;
  29629. const self = this;
  29630. Object.defineProperty(builder, 'level', {
  29631. enumerable: true,
  29632. get() {
  29633. return self.level;
  29634. },
  29635. set(level) {
  29636. self.level = level;
  29637. }
  29638. });
  29639. Object.defineProperty(builder, 'enabled', {
  29640. enumerable: true,
  29641. get() {
  29642. return self.enabled;
  29643. },
  29644. set(enabled) {
  29645. self.enabled = enabled;
  29646. }
  29647. });
  29648. // See below for fix regarding invisible grey/dim combination on Windows
  29649. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey';
  29650. // `__proto__` is used because we must return a function, but there is
  29651. // no way to create a function with a different prototype
  29652. builder.__proto__ = proto; // eslint-disable-line no-proto
  29653. return builder;
  29654. }
  29655. function applyStyle() {
  29656. // Support varags, but simply cast to string in case there's only one arg
  29657. const args = arguments;
  29658. const argsLen = args.length;
  29659. let str = String(arguments[0]);
  29660. if (argsLen === 0) {
  29661. return '';
  29662. }
  29663. if (argsLen > 1) {
  29664. // Don't slice `arguments`, it prevents V8 optimizations
  29665. for (let a = 1; a < argsLen; a++) {
  29666. str += ' ' + args[a];
  29667. }
  29668. }
  29669. if (!this.enabled || this.level <= 0 || !str) {
  29670. return str;
  29671. }
  29672. // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  29673. // see https://github.com/chalk/chalk/issues/58
  29674. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  29675. const originalDim = ansiStyles$3.dim.open;
  29676. if (isSimpleWindowsTerm && this.hasGrey) {
  29677. ansiStyles$3.dim.open = '';
  29678. }
  29679. for (const code of this._styles.slice().reverse()) {
  29680. // Replace any instances already present with a re-opening code
  29681. // otherwise only the part of the string until said closing code
  29682. // will be colored, and the rest will simply be 'plain'.
  29683. str = code.open + str.replace(code.closeRe, code.open) + code.close;
  29684. // Close the styling before a linebreak and reopen
  29685. // after next line to fix a bleed issue on macOS
  29686. // https://github.com/chalk/chalk/pull/92
  29687. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  29688. }
  29689. // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  29690. ansiStyles$3.dim.open = originalDim;
  29691. return str;
  29692. }
  29693. function chalkTag(chalk, strings) {
  29694. if (!Array.isArray(strings)) {
  29695. // If chalk() was called by itself or with a string,
  29696. // return the string itself as a string.
  29697. return [].slice.call(arguments, 1).join(' ');
  29698. }
  29699. const args = [].slice.call(arguments, 2);
  29700. const parts = [strings.raw[0]];
  29701. for (let i = 1; i < strings.length; i++) {
  29702. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  29703. parts.push(String(strings.raw[i]));
  29704. }
  29705. return templates$2(chalk, parts.join(''));
  29706. }
  29707. Object.defineProperties(Chalk.prototype, styles);
  29708. var chalk$2 = Chalk(); // eslint-disable-line new-cap
  29709. var supportsColor_1 = supportsColor$3;
  29710. chalk$2.supportsColor = supportsColor_1;
  29711. var minimist = function (args, opts) {
  29712. if (!opts) opts = {};
  29713. var flags = { bools : {}, strings : {}, unknownFn: null };
  29714. if (typeof opts['unknown'] === 'function') {
  29715. flags.unknownFn = opts['unknown'];
  29716. }
  29717. if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {
  29718. flags.allBools = true;
  29719. } else {
  29720. [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {
  29721. flags.bools[key] = true;
  29722. });
  29723. }
  29724. var aliases = {};
  29725. Object.keys(opts.alias || {}).forEach(function (key) {
  29726. aliases[key] = [].concat(opts.alias[key]);
  29727. aliases[key].forEach(function (x) {
  29728. aliases[x] = [key].concat(aliases[key].filter(function (y) {
  29729. return x !== y;
  29730. }));
  29731. });
  29732. });
  29733. [].concat(opts.string).filter(Boolean).forEach(function (key) {
  29734. flags.strings[key] = true;
  29735. if (aliases[key]) {
  29736. flags.strings[aliases[key]] = true;
  29737. }
  29738. });
  29739. var defaults = opts['default'] || {};
  29740. var argv = { _ : [] };
  29741. Object.keys(flags.bools).forEach(function (key) {
  29742. setArg(key, defaults[key] === undefined ? false : defaults[key]);
  29743. });
  29744. var notFlags = [];
  29745. if (args.indexOf('--') !== -1) {
  29746. notFlags = args.slice(args.indexOf('--')+1);
  29747. args = args.slice(0, args.indexOf('--'));
  29748. }
  29749. function argDefined(key, arg) {
  29750. return (flags.allBools && /^--[^=]+$/.test(arg)) ||
  29751. flags.strings[key] || flags.bools[key] || aliases[key];
  29752. }
  29753. function setArg (key, val, arg) {
  29754. if (arg && flags.unknownFn && !argDefined(key, arg)) {
  29755. if (flags.unknownFn(arg) === false) return;
  29756. }
  29757. var value = !flags.strings[key] && isNumber(val)
  29758. ? Number(val) : val;
  29759. setKey(argv, key.split('.'), value);
  29760. (aliases[key] || []).forEach(function (x) {
  29761. setKey(argv, x.split('.'), value);
  29762. });
  29763. }
  29764. function setKey (obj, keys, value) {
  29765. var o = obj;
  29766. keys.slice(0,-1).forEach(function (key) {
  29767. if (o[key] === undefined) o[key] = {};
  29768. o = o[key];
  29769. });
  29770. var key = keys[keys.length - 1];
  29771. if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {
  29772. o[key] = value;
  29773. }
  29774. else if (Array.isArray(o[key])) {
  29775. o[key].push(value);
  29776. }
  29777. else {
  29778. o[key] = [ o[key], value ];
  29779. }
  29780. }
  29781. function aliasIsBoolean(key) {
  29782. return aliases[key].some(function (x) {
  29783. return flags.bools[x];
  29784. });
  29785. }
  29786. for (var i = 0; i < args.length; i++) {
  29787. var arg = args[i];
  29788. if (/^--.+=/.test(arg)) {
  29789. // Using [\s\S] instead of . because js doesn't support the
  29790. // 'dotall' regex modifier. See:
  29791. // http://stackoverflow.com/a/1068308/13216
  29792. var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
  29793. var key = m[1];
  29794. var value = m[2];
  29795. if (flags.bools[key]) {
  29796. value = value !== 'false';
  29797. }
  29798. setArg(key, value, arg);
  29799. }
  29800. else if (/^--no-.+/.test(arg)) {
  29801. var key = arg.match(/^--no-(.+)/)[1];
  29802. setArg(key, false, arg);
  29803. }
  29804. else if (/^--.+/.test(arg)) {
  29805. var key = arg.match(/^--(.+)/)[1];
  29806. var next = args[i + 1];
  29807. if (next !== undefined && !/^-/.test(next)
  29808. && !flags.bools[key]
  29809. && !flags.allBools
  29810. && (aliases[key] ? !aliasIsBoolean(key) : true)) {
  29811. setArg(key, next, arg);
  29812. i++;
  29813. }
  29814. else if (/^(true|false)$/.test(next)) {
  29815. setArg(key, next === 'true', arg);
  29816. i++;
  29817. }
  29818. else {
  29819. setArg(key, flags.strings[key] ? '' : true, arg);
  29820. }
  29821. }
  29822. else if (/^-[^-]+/.test(arg)) {
  29823. var letters = arg.slice(1,-1).split('');
  29824. var broken = false;
  29825. for (var j = 0; j < letters.length; j++) {
  29826. var next = arg.slice(j+2);
  29827. if (next === '-') {
  29828. setArg(letters[j], next, arg);
  29829. continue;
  29830. }
  29831. if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
  29832. setArg(letters[j], next.split('=')[1], arg);
  29833. broken = true;
  29834. break;
  29835. }
  29836. if (/[A-Za-z]/.test(letters[j])
  29837. && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
  29838. setArg(letters[j], next, arg);
  29839. broken = true;
  29840. break;
  29841. }
  29842. if (letters[j+1] && letters[j+1].match(/\W/)) {
  29843. setArg(letters[j], arg.slice(j+2), arg);
  29844. broken = true;
  29845. break;
  29846. }
  29847. else {
  29848. setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
  29849. }
  29850. }
  29851. var key = arg.slice(-1)[0];
  29852. if (!broken && key !== '-') {
  29853. if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])
  29854. && !flags.bools[key]
  29855. && (aliases[key] ? !aliasIsBoolean(key) : true)) {
  29856. setArg(key, args[i+1], arg);
  29857. i++;
  29858. }
  29859. else if (args[i+1] && /true|false/.test(args[i+1])) {
  29860. setArg(key, args[i+1] === 'true', arg);
  29861. i++;
  29862. }
  29863. else {
  29864. setArg(key, flags.strings[key] ? '' : true, arg);
  29865. }
  29866. }
  29867. }
  29868. else {
  29869. if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
  29870. argv._.push(
  29871. flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)
  29872. );
  29873. }
  29874. if (opts.stopEarly) {
  29875. argv._.push.apply(argv._, args.slice(i + 1));
  29876. break;
  29877. }
  29878. }
  29879. }
  29880. Object.keys(defaults).forEach(function (key) {
  29881. if (!hasKey(argv, key.split('.'))) {
  29882. setKey(argv, key.split('.'), defaults[key]);
  29883. (aliases[key] || []).forEach(function (x) {
  29884. setKey(argv, x.split('.'), defaults[key]);
  29885. });
  29886. }
  29887. });
  29888. if (opts['--']) {
  29889. argv['--'] = new Array();
  29890. notFlags.forEach(function(key) {
  29891. argv['--'].push(key);
  29892. });
  29893. }
  29894. else {
  29895. notFlags.forEach(function(key) {
  29896. argv._.push(key);
  29897. });
  29898. }
  29899. return argv;
  29900. };
  29901. function hasKey (obj, keys) {
  29902. var o = obj;
  29903. keys.slice(0,-1).forEach(function (key) {
  29904. o = (o[key] || {});
  29905. });
  29906. var key = keys[keys.length - 1];
  29907. return key in o;
  29908. }
  29909. function isNumber (x) {
  29910. if (typeof x === 'number') return true;
  29911. if (/^0x[0-9a-f]+$/i.test(x)) return true;
  29912. return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
  29913. }
  29914. const PLACEHOLDER = null;
  29915. /**
  29916. * unspecified boolean flag without default value is parsed as `undefined` instead of `false`
  29917. */
  29918. var minimist_1 = function(args, options) {
  29919. const boolean = options.boolean || [];
  29920. const defaults = options.default || {};
  29921. const booleanWithoutDefault = boolean.filter(key => !(key in defaults));
  29922. const newDefaults = Object.assign(
  29923. {},
  29924. defaults,
  29925. booleanWithoutDefault.reduce(
  29926. (reduced, key) => Object.assign(reduced, { [key]: PLACEHOLDER }),
  29927. {}
  29928. )
  29929. );
  29930. const parsed = minimist(
  29931. args,
  29932. Object.assign({}, options, { default: newDefaults })
  29933. );
  29934. return Object.keys(parsed).reduce((reduced, key) => {
  29935. if (parsed[key] !== PLACEHOLDER) {
  29936. reduced[key] = parsed[key];
  29937. }
  29938. return reduced;
  29939. }, {});
  29940. };
  29941. function cleanAST$1(ast, options) {
  29942. return JSON.stringify(massageAST(ast, options), null, 2);
  29943. }
  29944. function massageAST(ast, options, parent) {
  29945. if (Array.isArray(ast)) {
  29946. return ast.map(e => massageAST(e, options, parent)).filter(e => e);
  29947. }
  29948. if (!ast || typeof ast !== "object") {
  29949. return ast;
  29950. }
  29951. const newObj = {};
  29952. for (const key in ast) {
  29953. if (typeof ast[key] !== "function") {
  29954. newObj[key] = massageAST(ast[key], options, ast);
  29955. }
  29956. }
  29957. [
  29958. "loc",
  29959. "range",
  29960. "raw",
  29961. "comments",
  29962. "leadingComments",
  29963. "trailingComments",
  29964. "extra",
  29965. "start",
  29966. "end",
  29967. "tokens",
  29968. "flags",
  29969. "raws",
  29970. "sourceIndex",
  29971. "id",
  29972. "source",
  29973. "before",
  29974. "after",
  29975. "trailingComma",
  29976. "parent",
  29977. "prev",
  29978. "position"
  29979. ].forEach(name => {
  29980. delete newObj[name];
  29981. });
  29982. if (options.printer.massageAstNode) {
  29983. const result = options.printer.massageAstNode(ast, newObj, parent);
  29984. if (result === null) {
  29985. return undefined;
  29986. }
  29987. if (result) {
  29988. return result;
  29989. }
  29990. }
  29991. return newObj;
  29992. }
  29993. var cleanAst = { cleanAST: cleanAST$1, massageAST };
  29994. var base = createCommonjsModule(function (module, exports) {
  29995. /*istanbul ignore start*/'use strict';
  29996. exports.__esModule = true;
  29997. exports['default'] = /*istanbul ignore end*/Diff;
  29998. function Diff() {}
  29999. Diff.prototype = { /*istanbul ignore start*/
  30000. /*istanbul ignore end*/diff: function diff(oldString, newString) {
  30001. /*istanbul ignore start*/var /*istanbul ignore end*/options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  30002. var callback = options.callback;
  30003. if (typeof options === 'function') {
  30004. callback = options;
  30005. options = {};
  30006. }
  30007. this.options = options;
  30008. var self = this;
  30009. function done(value) {
  30010. if (callback) {
  30011. setTimeout(function () {
  30012. callback(undefined, value);
  30013. }, 0);
  30014. return true;
  30015. } else {
  30016. return value;
  30017. }
  30018. }
  30019. // Allow subclasses to massage the input prior to running
  30020. oldString = this.castInput(oldString);
  30021. newString = this.castInput(newString);
  30022. oldString = this.removeEmpty(this.tokenize(oldString));
  30023. newString = this.removeEmpty(this.tokenize(newString));
  30024. var newLen = newString.length,
  30025. oldLen = oldString.length;
  30026. var editLength = 1;
  30027. var maxEditLength = newLen + oldLen;
  30028. var bestPath = [{ newPos: -1, components: [] }];
  30029. // Seed editLength = 0, i.e. the content starts with the same values
  30030. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  30031. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  30032. // Identity per the equality and tokenizer
  30033. return done([{ value: this.join(newString), count: newString.length }]);
  30034. }
  30035. // Main worker method. checks all permutations of a given edit length for acceptance.
  30036. function execEditLength() {
  30037. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  30038. var basePath = /*istanbul ignore start*/void 0;
  30039. var addPath = bestPath[diagonalPath - 1],
  30040. removePath = bestPath[diagonalPath + 1],
  30041. _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  30042. if (addPath) {
  30043. // No one else is going to attempt to use this value, clear it
  30044. bestPath[diagonalPath - 1] = undefined;
  30045. }
  30046. var canAdd = addPath && addPath.newPos + 1 < newLen,
  30047. canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
  30048. if (!canAdd && !canRemove) {
  30049. // If this path is a terminal then prune
  30050. bestPath[diagonalPath] = undefined;
  30051. continue;
  30052. }
  30053. // Select the diagonal that we want to branch from. We select the prior
  30054. // path whose position in the new string is the farthest from the origin
  30055. // and does not pass the bounds of the diff graph
  30056. if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
  30057. basePath = clonePath(removePath);
  30058. self.pushComponent(basePath.components, undefined, true);
  30059. } else {
  30060. basePath = addPath; // No need to clone, we've pulled it from the list
  30061. basePath.newPos++;
  30062. self.pushComponent(basePath.components, true, undefined);
  30063. }
  30064. _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
  30065. // If we have hit the end of both strings, then we are done
  30066. if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
  30067. return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
  30068. } else {
  30069. // Otherwise track this path as a potential candidate and continue.
  30070. bestPath[diagonalPath] = basePath;
  30071. }
  30072. }
  30073. editLength++;
  30074. }
  30075. // Performs the length of edit iteration. Is a bit fugly as this has to support the
  30076. // sync and async mode which is never fun. Loops over execEditLength until a value
  30077. // is produced.
  30078. if (callback) {
  30079. (function exec() {
  30080. setTimeout(function () {
  30081. // This should not happen, but we want to be safe.
  30082. /* istanbul ignore next */
  30083. if (editLength > maxEditLength) {
  30084. return callback();
  30085. }
  30086. if (!execEditLength()) {
  30087. exec();
  30088. }
  30089. }, 0);
  30090. })();
  30091. } else {
  30092. while (editLength <= maxEditLength) {
  30093. var ret = execEditLength();
  30094. if (ret) {
  30095. return ret;
  30096. }
  30097. }
  30098. }
  30099. },
  30100. /*istanbul ignore start*/ /*istanbul ignore end*/pushComponent: function pushComponent(components, added, removed) {
  30101. var last = components[components.length - 1];
  30102. if (last && last.added === added && last.removed === removed) {
  30103. // We need to clone here as the component clone operation is just
  30104. // as shallow array clone
  30105. components[components.length - 1] = { count: last.count + 1, added: added, removed: removed };
  30106. } else {
  30107. components.push({ count: 1, added: added, removed: removed });
  30108. }
  30109. },
  30110. /*istanbul ignore start*/ /*istanbul ignore end*/extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
  30111. var newLen = newString.length,
  30112. oldLen = oldString.length,
  30113. newPos = basePath.newPos,
  30114. oldPos = newPos - diagonalPath,
  30115. commonCount = 0;
  30116. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  30117. newPos++;
  30118. oldPos++;
  30119. commonCount++;
  30120. }
  30121. if (commonCount) {
  30122. basePath.components.push({ count: commonCount });
  30123. }
  30124. basePath.newPos = newPos;
  30125. return oldPos;
  30126. },
  30127. /*istanbul ignore start*/ /*istanbul ignore end*/equals: function equals(left, right) {
  30128. return left === right;
  30129. },
  30130. /*istanbul ignore start*/ /*istanbul ignore end*/removeEmpty: function removeEmpty(array) {
  30131. var ret = [];
  30132. for (var i = 0; i < array.length; i++) {
  30133. if (array[i]) {
  30134. ret.push(array[i]);
  30135. }
  30136. }
  30137. return ret;
  30138. },
  30139. /*istanbul ignore start*/ /*istanbul ignore end*/castInput: function castInput(value) {
  30140. return value;
  30141. },
  30142. /*istanbul ignore start*/ /*istanbul ignore end*/tokenize: function tokenize(value) {
  30143. return value.split('');
  30144. },
  30145. /*istanbul ignore start*/ /*istanbul ignore end*/join: function join(chars) {
  30146. return chars.join('');
  30147. }
  30148. };
  30149. function buildValues(diff, components, newString, oldString, useLongestToken) {
  30150. var componentPos = 0,
  30151. componentLen = components.length,
  30152. newPos = 0,
  30153. oldPos = 0;
  30154. for (; componentPos < componentLen; componentPos++) {
  30155. var component = components[componentPos];
  30156. if (!component.removed) {
  30157. if (!component.added && useLongestToken) {
  30158. var value = newString.slice(newPos, newPos + component.count);
  30159. value = value.map(function (value, i) {
  30160. var oldValue = oldString[oldPos + i];
  30161. return oldValue.length > value.length ? oldValue : value;
  30162. });
  30163. component.value = diff.join(value);
  30164. } else {
  30165. component.value = diff.join(newString.slice(newPos, newPos + component.count));
  30166. }
  30167. newPos += component.count;
  30168. // Common case
  30169. if (!component.added) {
  30170. oldPos += component.count;
  30171. }
  30172. } else {
  30173. component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
  30174. oldPos += component.count;
  30175. // Reverse add and remove so removes are output first to match common convention
  30176. // The diffing algorithm is tied to add then remove output and this is the simplest
  30177. // route to get the desired output with minimal overhead.
  30178. if (componentPos && components[componentPos - 1].added) {
  30179. var tmp = components[componentPos - 1];
  30180. components[componentPos - 1] = components[componentPos];
  30181. components[componentPos] = tmp;
  30182. }
  30183. }
  30184. }
  30185. // Special case handle for when one terminal is ignored. For this case we merge the
  30186. // terminal into the prior string and drop the change.
  30187. var lastComponent = components[componentLen - 1];
  30188. if (componentLen > 1 && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
  30189. components[componentLen - 2].value += lastComponent.value;
  30190. components.pop();
  30191. }
  30192. return components;
  30193. }
  30194. function clonePath(path$$1) {
  30195. return { newPos: path$$1.newPos, components: path$$1.components.slice(0) };
  30196. }
  30197. });
  30198. unwrapExports(base);
  30199. var character = createCommonjsModule(function (module, exports) {
  30200. /*istanbul ignore start*/'use strict';
  30201. exports.__esModule = true;
  30202. exports.characterDiff = undefined;
  30203. exports. /*istanbul ignore end*/diffChars = diffChars;
  30204. /*istanbul ignore start*/
  30205. var _base2 = _interopRequireDefault(base);
  30206. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  30207. /*istanbul ignore end*/var characterDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/characterDiff = new /*istanbul ignore start*/_base2['default']();
  30208. function diffChars(oldStr, newStr, callback) {
  30209. return characterDiff.diff(oldStr, newStr, callback);
  30210. }
  30211. });
  30212. unwrapExports(character);
  30213. var params = createCommonjsModule(function (module, exports) {
  30214. /*istanbul ignore start*/'use strict';
  30215. exports.__esModule = true;
  30216. exports. /*istanbul ignore end*/generateOptions = generateOptions;
  30217. function generateOptions(options, defaults) {
  30218. if (typeof options === 'function') {
  30219. defaults.callback = options;
  30220. } else if (options) {
  30221. for (var name in options) {
  30222. /* istanbul ignore else */
  30223. if (options.hasOwnProperty(name)) {
  30224. defaults[name] = options[name];
  30225. }
  30226. }
  30227. }
  30228. return defaults;
  30229. }
  30230. });
  30231. unwrapExports(params);
  30232. var word$1 = createCommonjsModule(function (module, exports) {
  30233. /*istanbul ignore start*/'use strict';
  30234. exports.__esModule = true;
  30235. exports.wordDiff = undefined;
  30236. exports. /*istanbul ignore end*/diffWords = diffWords;
  30237. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffWordsWithSpace = diffWordsWithSpace;
  30238. /*istanbul ignore start*/
  30239. var _base2 = _interopRequireDefault(base);
  30240. /*istanbul ignore end*/
  30241. /*istanbul ignore start*/
  30242. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  30243. /*istanbul ignore end*/
  30244. // Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
  30245. //
  30246. // Ranges and exceptions:
  30247. // Latin-1 Supplement, 0080–00FF
  30248. // - U+00D7 × Multiplication sign
  30249. // - U+00F7 ÷ Division sign
  30250. // Latin Extended-A, 0100–017F
  30251. // Latin Extended-B, 0180–024F
  30252. // IPA Extensions, 0250–02AF
  30253. // Spacing Modifier Letters, 02B0–02FF
  30254. // - U+02C7 ˇ &#711; Caron
  30255. // - U+02D8 ˘ &#728; Breve
  30256. // - U+02D9 ˙ &#729; Dot Above
  30257. // - U+02DA ˚ &#730; Ring Above
  30258. // - U+02DB ˛ &#731; Ogonek
  30259. // - U+02DC ˜ &#732; Small Tilde
  30260. // - U+02DD ˝ &#733; Double Acute Accent
  30261. // Latin Extended Additional, 1E00–1EFF
  30262. var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
  30263. var reWhitespace = /\S/;
  30264. var wordDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/wordDiff = new /*istanbul ignore start*/_base2['default']();
  30265. wordDiff.equals = function (left, right) {
  30266. return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
  30267. };
  30268. wordDiff.tokenize = function (value) {
  30269. var tokens = value.split(/(\s+|\b)/);
  30270. // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
  30271. for (var i = 0; i < tokens.length - 1; i++) {
  30272. // If we have an empty string in the next field and we have only word chars before and after, merge
  30273. if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
  30274. tokens[i] += tokens[i + 2];
  30275. tokens.splice(i + 1, 2);
  30276. i--;
  30277. }
  30278. }
  30279. return tokens;
  30280. };
  30281. function diffWords(oldStr, newStr, callback) {
  30282. var options = /*istanbul ignore start*/(0, params.generateOptions) /*istanbul ignore end*/(callback, { ignoreWhitespace: true });
  30283. return wordDiff.diff(oldStr, newStr, options);
  30284. }
  30285. function diffWordsWithSpace(oldStr, newStr, callback) {
  30286. return wordDiff.diff(oldStr, newStr, callback);
  30287. }
  30288. });
  30289. unwrapExports(word$1);
  30290. var line$7 = createCommonjsModule(function (module, exports) {
  30291. /*istanbul ignore start*/'use strict';
  30292. exports.__esModule = true;
  30293. exports.lineDiff = undefined;
  30294. exports. /*istanbul ignore end*/diffLines = diffLines;
  30295. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffTrimmedLines = diffTrimmedLines;
  30296. /*istanbul ignore start*/
  30297. var _base2 = _interopRequireDefault(base);
  30298. /*istanbul ignore end*/
  30299. /*istanbul ignore start*/
  30300. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  30301. /*istanbul ignore end*/var lineDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/lineDiff = new /*istanbul ignore start*/_base2['default']();
  30302. lineDiff.tokenize = function (value) {
  30303. var retLines = [],
  30304. linesAndNewlines = value.split(/(\n|\r\n)/);
  30305. // Ignore the final empty token that occurs if the string ends with a new line
  30306. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  30307. linesAndNewlines.pop();
  30308. }
  30309. // Merge the content and line separators into single tokens
  30310. for (var i = 0; i < linesAndNewlines.length; i++) {
  30311. var line = linesAndNewlines[i];
  30312. if (i % 2 && !this.options.newlineIsToken) {
  30313. retLines[retLines.length - 1] += line;
  30314. } else {
  30315. if (this.options.ignoreWhitespace) {
  30316. line = line.trim();
  30317. }
  30318. retLines.push(line);
  30319. }
  30320. }
  30321. return retLines;
  30322. };
  30323. function diffLines(oldStr, newStr, callback) {
  30324. return lineDiff.diff(oldStr, newStr, callback);
  30325. }
  30326. function diffTrimmedLines(oldStr, newStr, callback) {
  30327. var options = /*istanbul ignore start*/(0, params.generateOptions) /*istanbul ignore end*/(callback, { ignoreWhitespace: true });
  30328. return lineDiff.diff(oldStr, newStr, options);
  30329. }
  30330. });
  30331. unwrapExports(line$7);
  30332. var sentence = createCommonjsModule(function (module, exports) {
  30333. /*istanbul ignore start*/'use strict';
  30334. exports.__esModule = true;
  30335. exports.sentenceDiff = undefined;
  30336. exports. /*istanbul ignore end*/diffSentences = diffSentences;
  30337. /*istanbul ignore start*/
  30338. var _base2 = _interopRequireDefault(base);
  30339. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  30340. /*istanbul ignore end*/var sentenceDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/sentenceDiff = new /*istanbul ignore start*/_base2['default']();
  30341. sentenceDiff.tokenize = function (value) {
  30342. return value.split(/(\S.+?[.!?])(?=\s+|$)/);
  30343. };
  30344. function diffSentences(oldStr, newStr, callback) {
  30345. return sentenceDiff.diff(oldStr, newStr, callback);
  30346. }
  30347. });
  30348. unwrapExports(sentence);
  30349. var css = createCommonjsModule(function (module, exports) {
  30350. /*istanbul ignore start*/'use strict';
  30351. exports.__esModule = true;
  30352. exports.cssDiff = undefined;
  30353. exports. /*istanbul ignore end*/diffCss = diffCss;
  30354. /*istanbul ignore start*/
  30355. var _base2 = _interopRequireDefault(base);
  30356. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  30357. /*istanbul ignore end*/var cssDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/cssDiff = new /*istanbul ignore start*/_base2['default']();
  30358. cssDiff.tokenize = function (value) {
  30359. return value.split(/([{}:;,]|\s+)/);
  30360. };
  30361. function diffCss(oldStr, newStr, callback) {
  30362. return cssDiff.diff(oldStr, newStr, callback);
  30363. }
  30364. });
  30365. unwrapExports(css);
  30366. var json$1 = createCommonjsModule(function (module, exports) {
  30367. /*istanbul ignore start*/'use strict';
  30368. exports.__esModule = true;
  30369. exports.jsonDiff = undefined;
  30370. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
  30371. exports. /*istanbul ignore end*/diffJson = diffJson;
  30372. /*istanbul ignore start*/exports. /*istanbul ignore end*/canonicalize = canonicalize;
  30373. /*istanbul ignore start*/
  30374. var _base2 = _interopRequireDefault(base);
  30375. /*istanbul ignore end*/
  30376. /*istanbul ignore start*/
  30377. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  30378. /*istanbul ignore end*/
  30379. var objectPrototypeToString = Object.prototype.toString;
  30380. var jsonDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/jsonDiff = new /*istanbul ignore start*/_base2['default']();
  30381. // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  30382. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  30383. jsonDiff.useLongestToken = true;
  30384. jsonDiff.tokenize = /*istanbul ignore start*/line$7.lineDiff. /*istanbul ignore end*/tokenize;
  30385. jsonDiff.castInput = function (value) {
  30386. /*istanbul ignore start*/var /*istanbul ignore end*/undefinedReplacement = this.options.undefinedReplacement;
  30387. return typeof value === 'string' ? value : JSON.stringify(canonicalize(value), function (k, v) {
  30388. if (typeof v === 'undefined') {
  30389. return undefinedReplacement;
  30390. }
  30391. return v;
  30392. }, ' ');
  30393. };
  30394. jsonDiff.equals = function (left, right) {
  30395. return (/*istanbul ignore start*/_base2['default']. /*istanbul ignore end*/prototype.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'))
  30396. );
  30397. };
  30398. function diffJson(oldObj, newObj, options) {
  30399. return jsonDiff.diff(oldObj, newObj, options);
  30400. }
  30401. // This function handles the presence of circular references by bailing out when encountering an
  30402. // object that is already on the "stack" of items being processed.
  30403. function canonicalize(obj, stack, replacementStack) {
  30404. stack = stack || [];
  30405. replacementStack = replacementStack || [];
  30406. var i = /*istanbul ignore start*/void 0;
  30407. for (i = 0; i < stack.length; i += 1) {
  30408. if (stack[i] === obj) {
  30409. return replacementStack[i];
  30410. }
  30411. }
  30412. var canonicalizedObj = /*istanbul ignore start*/void 0;
  30413. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  30414. stack.push(obj);
  30415. canonicalizedObj = new Array(obj.length);
  30416. replacementStack.push(canonicalizedObj);
  30417. for (i = 0; i < obj.length; i += 1) {
  30418. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack);
  30419. }
  30420. stack.pop();
  30421. replacementStack.pop();
  30422. return canonicalizedObj;
  30423. }
  30424. if (obj && obj.toJSON) {
  30425. obj = obj.toJSON();
  30426. }
  30427. if ( /*istanbul ignore start*/(typeof /*istanbul ignore end*/obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && obj !== null) {
  30428. stack.push(obj);
  30429. canonicalizedObj = {};
  30430. replacementStack.push(canonicalizedObj);
  30431. var sortedKeys = [],
  30432. key = /*istanbul ignore start*/void 0;
  30433. for (key in obj) {
  30434. /* istanbul ignore else */
  30435. if (obj.hasOwnProperty(key)) {
  30436. sortedKeys.push(key);
  30437. }
  30438. }
  30439. sortedKeys.sort();
  30440. for (i = 0; i < sortedKeys.length; i += 1) {
  30441. key = sortedKeys[i];
  30442. canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack);
  30443. }
  30444. stack.pop();
  30445. replacementStack.pop();
  30446. } else {
  30447. canonicalizedObj = obj;
  30448. }
  30449. return canonicalizedObj;
  30450. }
  30451. });
  30452. unwrapExports(json$1);
  30453. var array$1 = createCommonjsModule(function (module, exports) {
  30454. /*istanbul ignore start*/'use strict';
  30455. exports.__esModule = true;
  30456. exports.arrayDiff = undefined;
  30457. exports. /*istanbul ignore end*/diffArrays = diffArrays;
  30458. /*istanbul ignore start*/
  30459. var _base2 = _interopRequireDefault(base);
  30460. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  30461. /*istanbul ignore end*/var arrayDiff = /*istanbul ignore start*/exports. /*istanbul ignore end*/arrayDiff = new /*istanbul ignore start*/_base2['default']();
  30462. arrayDiff.tokenize = arrayDiff.join = function (value) {
  30463. return value.slice();
  30464. };
  30465. function diffArrays(oldArr, newArr, callback) {
  30466. return arrayDiff.diff(oldArr, newArr, callback);
  30467. }
  30468. });
  30469. unwrapExports(array$1);
  30470. var parse$8 = createCommonjsModule(function (module, exports) {
  30471. /*istanbul ignore start*/'use strict';
  30472. exports.__esModule = true;
  30473. exports. /*istanbul ignore end*/parsePatch = parsePatch;
  30474. function parsePatch(uniDiff) {
  30475. /*istanbul ignore start*/var /*istanbul ignore end*/options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  30476. var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
  30477. delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  30478. list = [],
  30479. i = 0;
  30480. function parseIndex() {
  30481. var index = {};
  30482. list.push(index);
  30483. // Parse diff metadata
  30484. while (i < diffstr.length) {
  30485. var line = diffstr[i];
  30486. // File header found, end parsing diff metadata
  30487. if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
  30488. break;
  30489. }
  30490. // Diff index
  30491. var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
  30492. if (header) {
  30493. index.index = header[1];
  30494. }
  30495. i++;
  30496. }
  30497. // Parse file headers if they are defined. Unified diff requires them, but
  30498. // there's no technical issues to have an isolated hunk without file header
  30499. parseFileHeader(index);
  30500. parseFileHeader(index);
  30501. // Parse hunks
  30502. index.hunks = [];
  30503. while (i < diffstr.length) {
  30504. var _line = diffstr[i];
  30505. if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
  30506. break;
  30507. } else if (/^@@/.test(_line)) {
  30508. index.hunks.push(parseHunk());
  30509. } else if (_line && options.strict) {
  30510. // Ignore unexpected content unless in strict mode
  30511. throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
  30512. } else {
  30513. i++;
  30514. }
  30515. }
  30516. }
  30517. // Parses the --- and +++ headers, if none are found, no lines
  30518. // are consumed.
  30519. function parseFileHeader(index) {
  30520. var headerPattern = /^(---|\+\+\+)\s+([\S ]*)(?:\t(.*?)\s*)?$/;
  30521. var fileHeader = headerPattern.exec(diffstr[i]);
  30522. if (fileHeader) {
  30523. var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
  30524. index[keyPrefix + 'FileName'] = fileHeader[2];
  30525. index[keyPrefix + 'Header'] = fileHeader[3];
  30526. i++;
  30527. }
  30528. }
  30529. // Parses a hunk
  30530. // This assumes that we are at the start of a hunk.
  30531. function parseHunk() {
  30532. var chunkHeaderIndex = i,
  30533. chunkHeaderLine = diffstr[i++],
  30534. chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
  30535. var hunk = {
  30536. oldStart: +chunkHeader[1],
  30537. oldLines: +chunkHeader[2] || 1,
  30538. newStart: +chunkHeader[3],
  30539. newLines: +chunkHeader[4] || 1,
  30540. lines: [],
  30541. linedelimiters: []
  30542. };
  30543. var addCount = 0,
  30544. removeCount = 0;
  30545. for (; i < diffstr.length; i++) {
  30546. // Lines starting with '---' could be mistaken for the "remove line" operation
  30547. // But they could be the header for the next file. Therefore prune such cases out.
  30548. if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
  30549. break;
  30550. }
  30551. var operation = diffstr[i][0];
  30552. if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
  30553. hunk.lines.push(diffstr[i]);
  30554. hunk.linedelimiters.push(delimiters[i] || '\n');
  30555. if (operation === '+') {
  30556. addCount++;
  30557. } else if (operation === '-') {
  30558. removeCount++;
  30559. } else if (operation === ' ') {
  30560. addCount++;
  30561. removeCount++;
  30562. }
  30563. } else {
  30564. break;
  30565. }
  30566. }
  30567. // Handle the empty block count case
  30568. if (!addCount && hunk.newLines === 1) {
  30569. hunk.newLines = 0;
  30570. }
  30571. if (!removeCount && hunk.oldLines === 1) {
  30572. hunk.oldLines = 0;
  30573. }
  30574. // Perform optional sanity checking
  30575. if (options.strict) {
  30576. if (addCount !== hunk.newLines) {
  30577. throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  30578. }
  30579. if (removeCount !== hunk.oldLines) {
  30580. throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  30581. }
  30582. }
  30583. return hunk;
  30584. }
  30585. while (i < diffstr.length) {
  30586. parseIndex();
  30587. }
  30588. return list;
  30589. }
  30590. });
  30591. unwrapExports(parse$8);
  30592. var distanceIterator = createCommonjsModule(function (module, exports) {
  30593. /*istanbul ignore start*/"use strict";
  30594. exports.__esModule = true;
  30595. exports["default"] = /*istanbul ignore end*/function (start, minLine, maxLine) {
  30596. var wantForward = true,
  30597. backwardExhausted = false,
  30598. forwardExhausted = false,
  30599. localOffset = 1;
  30600. return function iterator() {
  30601. if (wantForward && !forwardExhausted) {
  30602. if (backwardExhausted) {
  30603. localOffset++;
  30604. } else {
  30605. wantForward = false;
  30606. }
  30607. // Check if trying to fit beyond text length, and if not, check it fits
  30608. // after offset location (or desired location on first iteration)
  30609. if (start + localOffset <= maxLine) {
  30610. return localOffset;
  30611. }
  30612. forwardExhausted = true;
  30613. }
  30614. if (!backwardExhausted) {
  30615. if (!forwardExhausted) {
  30616. wantForward = true;
  30617. }
  30618. // Check if trying to fit before text beginning, and if not, check it fits
  30619. // before offset location
  30620. if (minLine <= start - localOffset) {
  30621. return -localOffset++;
  30622. }
  30623. backwardExhausted = true;
  30624. return iterator();
  30625. }
  30626. // We tried to fit hunk before text beginning and beyond text lenght, then
  30627. // hunk can't fit on the text. Return undefined
  30628. };
  30629. };
  30630. });
  30631. unwrapExports(distanceIterator);
  30632. var apply = createCommonjsModule(function (module, exports) {
  30633. /*istanbul ignore start*/'use strict';
  30634. exports.__esModule = true;
  30635. exports. /*istanbul ignore end*/applyPatch = applyPatch;
  30636. /*istanbul ignore start*/exports. /*istanbul ignore end*/applyPatches = applyPatches;
  30637. /*istanbul ignore start*/
  30638. var _distanceIterator2 = _interopRequireDefault(distanceIterator);
  30639. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  30640. /*istanbul ignore end*/function applyPatch(source, uniDiff) {
  30641. /*istanbul ignore start*/var /*istanbul ignore end*/options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  30642. if (typeof uniDiff === 'string') {
  30643. uniDiff = /*istanbul ignore start*/(0, parse$8.parsePatch) /*istanbul ignore end*/(uniDiff);
  30644. }
  30645. if (Array.isArray(uniDiff)) {
  30646. if (uniDiff.length > 1) {
  30647. throw new Error('applyPatch only works with a single input.');
  30648. }
  30649. uniDiff = uniDiff[0];
  30650. }
  30651. // Apply the diff to the input
  30652. var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
  30653. delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  30654. hunks = uniDiff.hunks,
  30655. compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) /*istanbul ignore start*/{
  30656. return (/*istanbul ignore end*/line === patchContent
  30657. );
  30658. },
  30659. errorCount = 0,
  30660. fuzzFactor = options.fuzzFactor || 0,
  30661. minLine = 0,
  30662. offset = 0,
  30663. removeEOFNL = /*istanbul ignore start*/void 0 /*istanbul ignore end*/,
  30664. addEOFNL = /*istanbul ignore start*/void 0;
  30665. /**
  30666. * Checks if the hunk exactly fits on the provided location
  30667. */
  30668. function hunkFits(hunk, toPos) {
  30669. for (var j = 0; j < hunk.lines.length; j++) {
  30670. var line = hunk.lines[j],
  30671. operation = line[0],
  30672. content = line.substr(1);
  30673. if (operation === ' ' || operation === '-') {
  30674. // Context sanity check
  30675. if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
  30676. errorCount++;
  30677. if (errorCount > fuzzFactor) {
  30678. return false;
  30679. }
  30680. }
  30681. toPos++;
  30682. }
  30683. }
  30684. return true;
  30685. }
  30686. // Search best fit offsets for each hunk based on the previous ones
  30687. for (var i = 0; i < hunks.length; i++) {
  30688. var hunk = hunks[i],
  30689. maxLine = lines.length - hunk.oldLines,
  30690. localOffset = 0,
  30691. toPos = offset + hunk.oldStart - 1;
  30692. var iterator = /*istanbul ignore start*/(0, _distanceIterator2['default']) /*istanbul ignore end*/(toPos, minLine, maxLine);
  30693. for (; localOffset !== undefined; localOffset = iterator()) {
  30694. if (hunkFits(hunk, toPos + localOffset)) {
  30695. hunk.offset = offset += localOffset;
  30696. break;
  30697. }
  30698. }
  30699. if (localOffset === undefined) {
  30700. return false;
  30701. }
  30702. // Set lower text limit to end of the current hunk, so next ones don't try
  30703. // to fit over already patched text
  30704. minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
  30705. }
  30706. // Apply patch hunks
  30707. for (var _i = 0; _i < hunks.length; _i++) {
  30708. var _hunk = hunks[_i],
  30709. _toPos = _hunk.offset + _hunk.newStart - 1;
  30710. if (_hunk.newLines == 0) {
  30711. _toPos++;
  30712. }
  30713. for (var j = 0; j < _hunk.lines.length; j++) {
  30714. var line = _hunk.lines[j],
  30715. operation = line[0],
  30716. content = line.substr(1),
  30717. delimiter = _hunk.linedelimiters[j];
  30718. if (operation === ' ') {
  30719. _toPos++;
  30720. } else if (operation === '-') {
  30721. lines.splice(_toPos, 1);
  30722. delimiters.splice(_toPos, 1);
  30723. /* istanbul ignore else */
  30724. } else if (operation === '+') {
  30725. lines.splice(_toPos, 0, content);
  30726. delimiters.splice(_toPos, 0, delimiter);
  30727. _toPos++;
  30728. } else if (operation === '\\') {
  30729. var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
  30730. if (previousOperation === '+') {
  30731. removeEOFNL = true;
  30732. } else if (previousOperation === '-') {
  30733. addEOFNL = true;
  30734. }
  30735. }
  30736. }
  30737. }
  30738. // Handle EOFNL insertion/removal
  30739. if (removeEOFNL) {
  30740. while (!lines[lines.length - 1]) {
  30741. lines.pop();
  30742. delimiters.pop();
  30743. }
  30744. } else if (addEOFNL) {
  30745. lines.push('');
  30746. delimiters.push('\n');
  30747. }
  30748. for (var _k = 0; _k < lines.length - 1; _k++) {
  30749. lines[_k] = lines[_k] + delimiters[_k];
  30750. }
  30751. return lines.join('');
  30752. }
  30753. // Wrapper that supports multiple file patches via callbacks.
  30754. function applyPatches(uniDiff, options) {
  30755. if (typeof uniDiff === 'string') {
  30756. uniDiff = /*istanbul ignore start*/(0, parse$8.parsePatch) /*istanbul ignore end*/(uniDiff);
  30757. }
  30758. var currentIndex = 0;
  30759. function processIndex() {
  30760. var index = uniDiff[currentIndex++];
  30761. if (!index) {
  30762. return options.complete();
  30763. }
  30764. options.loadFile(index, function (err, data) {
  30765. if (err) {
  30766. return options.complete(err);
  30767. }
  30768. var updatedContent = applyPatch(data, index, options);
  30769. options.patched(index, updatedContent, function (err) {
  30770. if (err) {
  30771. return options.complete(err);
  30772. }
  30773. processIndex();
  30774. });
  30775. });
  30776. }
  30777. processIndex();
  30778. }
  30779. });
  30780. unwrapExports(apply);
  30781. var create = createCommonjsModule(function (module, exports) {
  30782. /*istanbul ignore start*/'use strict';
  30783. exports.__esModule = true;
  30784. exports. /*istanbul ignore end*/structuredPatch = structuredPatch;
  30785. /*istanbul ignore start*/exports. /*istanbul ignore end*/createTwoFilesPatch = createTwoFilesPatch;
  30786. /*istanbul ignore start*/exports. /*istanbul ignore end*/createPatch = createPatch;
  30787. /*istanbul ignore start*/
  30788. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  30789. /*istanbul ignore end*/function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  30790. if (!options) {
  30791. options = {};
  30792. }
  30793. if (typeof options.context === 'undefined') {
  30794. options.context = 4;
  30795. }
  30796. var diff = /*istanbul ignore start*/(0, line$7.diffLines) /*istanbul ignore end*/(oldStr, newStr, options);
  30797. diff.push({ value: '', lines: [] }); // Append an empty value to make cleanup easier
  30798. function contextLines(lines) {
  30799. return lines.map(function (entry) {
  30800. return ' ' + entry;
  30801. });
  30802. }
  30803. var hunks = [];
  30804. var oldRangeStart = 0,
  30805. newRangeStart = 0,
  30806. curRange = [],
  30807. oldLine = 1,
  30808. newLine = 1;
  30809. /*istanbul ignore start*/
  30810. var _loop = function _loop( /*istanbul ignore end*/i) {
  30811. var current = diff[i],
  30812. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  30813. current.lines = lines;
  30814. if (current.added || current.removed) {
  30815. /*istanbul ignore start*/
  30816. var _curRange;
  30817. /*istanbul ignore end*/
  30818. // If we have previous context, start with that
  30819. if (!oldRangeStart) {
  30820. var prev = diff[i - 1];
  30821. oldRangeStart = oldLine;
  30822. newRangeStart = newLine;
  30823. if (prev) {
  30824. curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
  30825. oldRangeStart -= curRange.length;
  30826. newRangeStart -= curRange.length;
  30827. }
  30828. }
  30829. // Output our changes
  30830. /*istanbul ignore start*/(_curRange = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/lines.map(function (entry) {
  30831. return (current.added ? '+' : '-') + entry;
  30832. })));
  30833. // Track the updated file position
  30834. if (current.added) {
  30835. newLine += lines.length;
  30836. } else {
  30837. oldLine += lines.length;
  30838. }
  30839. } else {
  30840. // Identical context lines. Track line changes
  30841. if (oldRangeStart) {
  30842. // Close out any changes that have been output (or join overlapping)
  30843. if (lines.length <= options.context * 2 && i < diff.length - 2) {
  30844. /*istanbul ignore start*/
  30845. var _curRange2;
  30846. /*istanbul ignore end*/
  30847. // Overlapping
  30848. /*istanbul ignore start*/(_curRange2 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange2 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines)));
  30849. } else {
  30850. /*istanbul ignore start*/
  30851. var _curRange3;
  30852. /*istanbul ignore end*/
  30853. // end the range and output
  30854. var contextSize = Math.min(lines.length, options.context);
  30855. /*istanbul ignore start*/(_curRange3 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange3 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines.slice(0, contextSize))));
  30856. var hunk = {
  30857. oldStart: oldRangeStart,
  30858. oldLines: oldLine - oldRangeStart + contextSize,
  30859. newStart: newRangeStart,
  30860. newLines: newLine - newRangeStart + contextSize,
  30861. lines: curRange
  30862. };
  30863. if (i >= diff.length - 2 && lines.length <= options.context) {
  30864. // EOF is inside this hunk
  30865. var oldEOFNewline = /\n$/.test(oldStr);
  30866. var newEOFNewline = /\n$/.test(newStr);
  30867. if (lines.length == 0 && !oldEOFNewline) {
  30868. // special case: old has no eol and no trailing context; no-nl can end up before adds
  30869. curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
  30870. } else if (!oldEOFNewline || !newEOFNewline) {
  30871. curRange.push('\\ No newline at end of file');
  30872. }
  30873. }
  30874. hunks.push(hunk);
  30875. oldRangeStart = 0;
  30876. newRangeStart = 0;
  30877. curRange = [];
  30878. }
  30879. }
  30880. oldLine += lines.length;
  30881. newLine += lines.length;
  30882. }
  30883. };
  30884. for (var i = 0; i < diff.length; i++) {
  30885. /*istanbul ignore start*/
  30886. _loop( /*istanbul ignore end*/i);
  30887. }
  30888. return {
  30889. oldFileName: oldFileName, newFileName: newFileName,
  30890. oldHeader: oldHeader, newHeader: newHeader,
  30891. hunks: hunks
  30892. };
  30893. }
  30894. function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  30895. var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
  30896. var ret = [];
  30897. if (oldFileName == newFileName) {
  30898. ret.push('Index: ' + oldFileName);
  30899. }
  30900. ret.push('===================================================================');
  30901. ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
  30902. ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
  30903. for (var i = 0; i < diff.hunks.length; i++) {
  30904. var hunk = diff.hunks[i];
  30905. ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
  30906. ret.push.apply(ret, hunk.lines);
  30907. }
  30908. return ret.join('\n') + '\n';
  30909. }
  30910. function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
  30911. return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
  30912. }
  30913. });
  30914. unwrapExports(create);
  30915. var dmp = createCommonjsModule(function (module, exports) {
  30916. /*istanbul ignore start*/"use strict";
  30917. exports.__esModule = true;
  30918. exports. /*istanbul ignore end*/convertChangesToDMP = convertChangesToDMP;
  30919. // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  30920. function convertChangesToDMP(changes) {
  30921. var ret = [],
  30922. change = /*istanbul ignore start*/void 0 /*istanbul ignore end*/,
  30923. operation = /*istanbul ignore start*/void 0;
  30924. for (var i = 0; i < changes.length; i++) {
  30925. change = changes[i];
  30926. if (change.added) {
  30927. operation = 1;
  30928. } else if (change.removed) {
  30929. operation = -1;
  30930. } else {
  30931. operation = 0;
  30932. }
  30933. ret.push([operation, change.value]);
  30934. }
  30935. return ret;
  30936. }
  30937. });
  30938. unwrapExports(dmp);
  30939. var xml = createCommonjsModule(function (module, exports) {
  30940. /*istanbul ignore start*/'use strict';
  30941. exports.__esModule = true;
  30942. exports. /*istanbul ignore end*/convertChangesToXML = convertChangesToXML;
  30943. function convertChangesToXML(changes) {
  30944. var ret = [];
  30945. for (var i = 0; i < changes.length; i++) {
  30946. var change = changes[i];
  30947. if (change.added) {
  30948. ret.push('<ins>');
  30949. } else if (change.removed) {
  30950. ret.push('<del>');
  30951. }
  30952. ret.push(escapeHTML(change.value));
  30953. if (change.added) {
  30954. ret.push('</ins>');
  30955. } else if (change.removed) {
  30956. ret.push('</del>');
  30957. }
  30958. }
  30959. return ret.join('');
  30960. }
  30961. function escapeHTML(s) {
  30962. var n = s;
  30963. n = n.replace(/&/g, '&amp;');
  30964. n = n.replace(/</g, '&lt;');
  30965. n = n.replace(/>/g, '&gt;');
  30966. n = n.replace(/"/g, '&quot;');
  30967. return n;
  30968. }
  30969. });
  30970. unwrapExports(xml);
  30971. var lib$6 = createCommonjsModule(function (module, exports) {
  30972. /*istanbul ignore start*/'use strict';
  30973. exports.__esModule = true;
  30974. exports.canonicalize = exports.convertChangesToXML = exports.convertChangesToDMP = exports.parsePatch = exports.applyPatches = exports.applyPatch = exports.createPatch = exports.createTwoFilesPatch = exports.structuredPatch = exports.diffArrays = exports.diffJson = exports.diffCss = exports.diffSentences = exports.diffTrimmedLines = exports.diffLines = exports.diffWordsWithSpace = exports.diffWords = exports.diffChars = exports.Diff = undefined;
  30975. /*istanbul ignore end*/
  30976. /*istanbul ignore start*/
  30977. var _base2 = _interopRequireDefault(base);
  30978. /*istanbul ignore end*/
  30979. /*istanbul ignore start*/
  30980. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  30981. exports. /*istanbul ignore end*/Diff = _base2['default'];
  30982. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffChars = character.diffChars;
  30983. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffWords = word$1.diffWords;
  30984. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffWordsWithSpace = word$1.diffWordsWithSpace;
  30985. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffLines = line$7.diffLines;
  30986. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffTrimmedLines = line$7.diffTrimmedLines;
  30987. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffSentences = sentence.diffSentences;
  30988. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffCss = css.diffCss;
  30989. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffJson = json$1.diffJson;
  30990. /*istanbul ignore start*/exports. /*istanbul ignore end*/diffArrays = array$1.diffArrays;
  30991. /*istanbul ignore start*/exports. /*istanbul ignore end*/structuredPatch = create.structuredPatch;
  30992. /*istanbul ignore start*/exports. /*istanbul ignore end*/createTwoFilesPatch = create.createTwoFilesPatch;
  30993. /*istanbul ignore start*/exports. /*istanbul ignore end*/createPatch = create.createPatch;
  30994. /*istanbul ignore start*/exports. /*istanbul ignore end*/applyPatch = apply.applyPatch;
  30995. /*istanbul ignore start*/exports. /*istanbul ignore end*/applyPatches = apply.applyPatches;
  30996. /*istanbul ignore start*/exports. /*istanbul ignore end*/parsePatch = parse$8.parsePatch;
  30997. /*istanbul ignore start*/exports. /*istanbul ignore end*/convertChangesToDMP = dmp.convertChangesToDMP;
  30998. /*istanbul ignore start*/exports. /*istanbul ignore end*/convertChangesToXML = xml.convertChangesToXML;
  30999. /*istanbul ignore start*/exports. /*istanbul ignore end*/canonicalize = json$1.canonicalize; /* See LICENSE file for terms of use */
  31000. /*
  31001. * Text diff implementation.
  31002. *
  31003. * This library supports the following APIS:
  31004. * JsDiff.diffChars: Character by character diff
  31005. * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
  31006. * JsDiff.diffLines: Line based diff
  31007. *
  31008. * JsDiff.diffCss: Diff targeted at CSS content
  31009. *
  31010. * These methods are based on the implementation proposed in
  31011. * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
  31012. * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
  31013. */
  31014. });
  31015. unwrapExports(lib$6);
  31016. const cleanAST = cleanAst.cleanAST;
  31017. const getSupportInfo$3 = support.getSupportInfo;
  31018. const OPTION_USAGE_THRESHOLD = 25;
  31019. const CHOICE_USAGE_MARGIN = 3;
  31020. const CHOICE_USAGE_INDENTATION = 2;
  31021. function getOptions(argv, detailedOptions) {
  31022. return detailedOptions.filter(option => option.forwardToApi).reduce(
  31023. (current, option) =>
  31024. Object.assign(current, {
  31025. [option.forwardToApi]: argv[option.name]
  31026. }),
  31027. {}
  31028. );
  31029. }
  31030. function cliifyOptions(object, apiDetailedOptionMap) {
  31031. return Object.keys(object || {}).reduce((output, key) => {
  31032. const apiOption = apiDetailedOptionMap[key];
  31033. const cliKey = apiOption ? apiOption.name : key;
  31034. output[dashify(cliKey)] = object[key];
  31035. return output;
  31036. }, {});
  31037. }
  31038. function diff(a, b) {
  31039. return lib$6.createTwoFilesPatch("", "", a, b, "", "", {
  31040. context: 2
  31041. });
  31042. }
  31043. function handleError(context, filename, error) {
  31044. const isParseError = Boolean(error && error.loc);
  31045. const isValidationError = /Validation Error/.test(error && error.message);
  31046. // For parse errors and validation errors, we only want to show the error
  31047. // message formatted in a nice way. `String(error)` takes care of that. Other
  31048. // (unexpected) errors are passed as-is as a separate argument to
  31049. // `console.error`. That includes the stack trace (if any), and shows a nice
  31050. // `util.inspect` of throws things that aren't `Error` objects. (The Flow
  31051. // parser has mistakenly thrown arrays sometimes.)
  31052. if (isParseError) {
  31053. context.logger.error(`${filename}: ${String(error)}`);
  31054. } else if (isValidationError || error instanceof errors.ConfigError) {
  31055. context.logger.error(String(error));
  31056. // If validation fails for one file, it will fail for all of them.
  31057. process.exit(1);
  31058. } else if (error instanceof errors.DebugError) {
  31059. context.logger.error(`${filename}: ${error.message}`);
  31060. } else {
  31061. context.logger.error(filename + ": " + (error.stack || error));
  31062. }
  31063. // Don't exit the process if one file failed
  31064. process.exitCode = 2;
  31065. }
  31066. function logResolvedConfigPathOrDie(context, filePath) {
  31067. const configFile = resolveConfig_1.resolveConfigFile.sync(filePath);
  31068. if (configFile) {
  31069. context.logger.log(path.relative(process.cwd(), configFile));
  31070. } else {
  31071. process.exit(1);
  31072. }
  31073. }
  31074. function writeOutput(result, options) {
  31075. // Don't use `console.log` here since it adds an extra newline at the end.
  31076. process.stdout.write(result.formatted);
  31077. if (options.cursorOffset >= 0) {
  31078. process.stderr.write(result.cursorOffset + "\n");
  31079. }
  31080. }
  31081. function listDifferent(context, input, options, filename) {
  31082. if (!context.argv["list-different"]) {
  31083. return;
  31084. }
  31085. options = Object.assign({}, options, { filepath: filename });
  31086. if (!prettier$2.check(input, options)) {
  31087. if (!context.argv["write"]) {
  31088. context.logger.log(filename);
  31089. }
  31090. process.exitCode = 1;
  31091. }
  31092. return true;
  31093. }
  31094. function format$1(context, input, opt) {
  31095. if (context.argv["debug-print-doc"]) {
  31096. const doc = prettier$2.__debug.printToDoc(input, opt);
  31097. return { formatted: prettier$2.__debug.formatDoc(doc) };
  31098. }
  31099. if (context.argv["debug-check"]) {
  31100. const pp = prettier$2.format(input, opt);
  31101. const pppp = prettier$2.format(pp, opt);
  31102. if (pp !== pppp) {
  31103. throw new errors.DebugError(
  31104. "prettier(input) !== prettier(prettier(input))\n" + diff(pp, pppp)
  31105. );
  31106. } else {
  31107. const normalizedOpts = options$12.normalize(opt);
  31108. const ast = cleanAST(
  31109. prettier$2.__debug.parse(input, opt).ast,
  31110. normalizedOpts
  31111. );
  31112. const past = cleanAST(
  31113. prettier$2.__debug.parse(pp, opt).ast,
  31114. normalizedOpts
  31115. );
  31116. if (ast !== past) {
  31117. const MAX_AST_SIZE = 2097152; // 2MB
  31118. const astDiff =
  31119. ast.length > MAX_AST_SIZE || past.length > MAX_AST_SIZE
  31120. ? "AST diff too large to render"
  31121. : diff(ast, past);
  31122. throw new errors.DebugError(
  31123. "ast(input) !== ast(prettier(input))\n" +
  31124. astDiff +
  31125. "\n" +
  31126. diff(input, pp)
  31127. );
  31128. }
  31129. }
  31130. return { formatted: opt.filepath || "(stdin)\n" };
  31131. }
  31132. return prettier$2.formatWithCursor(input, opt);
  31133. }
  31134. function getOptionsOrDie(context, filePath) {
  31135. try {
  31136. if (context.argv["config"] === false) {
  31137. context.logger.debug(
  31138. "'--no-config' option found, skip loading config file."
  31139. );
  31140. return null;
  31141. }
  31142. context.logger.debug(
  31143. context.argv["config"]
  31144. ? `load config file from '${context.argv["config"]}'`
  31145. : `resolve config from '${filePath}'`
  31146. );
  31147. const options = resolveConfig_1.resolveConfig.sync(filePath, {
  31148. editorconfig: context.argv["editorconfig"],
  31149. config: context.argv["config"]
  31150. });
  31151. context.logger.debug("loaded options `" + JSON.stringify(options) + "`");
  31152. return options;
  31153. } catch (error) {
  31154. context.logger.error("Invalid configuration file: " + error.message);
  31155. process.exit(2);
  31156. }
  31157. }
  31158. function getOptionsForFile(context, filepath) {
  31159. const options = getOptionsOrDie(context, filepath);
  31160. const hasPlugins = options && options.plugins;
  31161. if (hasPlugins) {
  31162. pushContextPlugins(context, options.plugins);
  31163. }
  31164. const appliedOptions = Object.assign(
  31165. { filepath },
  31166. applyConfigPrecedence(
  31167. context,
  31168. options &&
  31169. optionsNormalizer.normalizeApiOptions(options, context.supportOptions, {
  31170. logger: context.logger
  31171. })
  31172. )
  31173. );
  31174. context.logger.debug(
  31175. `applied config-precedence (${context.argv["config-precedence"]}): ` +
  31176. `${JSON.stringify(appliedOptions)}`
  31177. );
  31178. if (hasPlugins) {
  31179. popContextPlugins(context);
  31180. }
  31181. return appliedOptions;
  31182. }
  31183. function parseArgsToOptions(context, overrideDefaults) {
  31184. const minimistOptions = createMinimistOptions(context.detailedOptions);
  31185. const apiDetailedOptionMap = createApiDetailedOptionMap(
  31186. context.detailedOptions
  31187. );
  31188. return getOptions(
  31189. optionsNormalizer.normalizeCliOptions(
  31190. minimist_1(
  31191. context.args,
  31192. Object.assign({
  31193. string: minimistOptions.string,
  31194. boolean: minimistOptions.boolean,
  31195. default: cliifyOptions(overrideDefaults, apiDetailedOptionMap)
  31196. })
  31197. ),
  31198. context.detailedOptions,
  31199. { logger: false }
  31200. ),
  31201. context.detailedOptions
  31202. );
  31203. }
  31204. function applyConfigPrecedence(context, options) {
  31205. try {
  31206. switch (context.argv["config-precedence"]) {
  31207. case "cli-override":
  31208. return parseArgsToOptions(context, options);
  31209. case "file-override":
  31210. return Object.assign({}, parseArgsToOptions(context), options);
  31211. case "prefer-file":
  31212. return options || parseArgsToOptions(context);
  31213. }
  31214. } catch (error) {
  31215. context.logger.error(error.toString());
  31216. process.exit(2);
  31217. }
  31218. }
  31219. function formatStdin(context) {
  31220. const filepath = context.argv["stdin-filepath"]
  31221. ? path.resolve(process.cwd(), context.argv["stdin-filepath"])
  31222. : process.cwd();
  31223. const ignorer = createIgnorer(context);
  31224. const relativeFilepath = path.relative(process.cwd(), filepath);
  31225. thirdParty$1.getStream(process.stdin).then(input => {
  31226. if (relativeFilepath && ignorer.filter([relativeFilepath]).length === 0) {
  31227. writeOutput({ formatted: input }, {});
  31228. return;
  31229. }
  31230. const options = getOptionsForFile(context, filepath);
  31231. if (listDifferent(context, input, options, "(stdin)")) {
  31232. return;
  31233. }
  31234. try {
  31235. writeOutput(format$1(context, input, options), options);
  31236. } catch (error) {
  31237. handleError(context, "stdin", error);
  31238. }
  31239. });
  31240. }
  31241. function createIgnorer(context) {
  31242. const ignoreFilePath = path.resolve(context.argv["ignore-path"]);
  31243. let ignoreText = "";
  31244. try {
  31245. ignoreText = fs.readFileSync(ignoreFilePath, "utf8");
  31246. } catch (readError) {
  31247. if (readError.code !== "ENOENT") {
  31248. context.logger.error(
  31249. `Unable to read ${ignoreFilePath}: ` + readError.message
  31250. );
  31251. process.exit(2);
  31252. }
  31253. }
  31254. return ignore().add(ignoreText);
  31255. }
  31256. function eachFilename(context, patterns, callback) {
  31257. const ignoreNodeModules = context.argv["with-node-modules"] !== true;
  31258. if (ignoreNodeModules) {
  31259. patterns = patterns.concat(["!**/node_modules/**", "!./node_modules/**"]);
  31260. }
  31261. try {
  31262. const filePaths = globby
  31263. .sync(patterns, { dot: true, nodir: true })
  31264. .map(filePath => path.relative(process.cwd(), filePath));
  31265. if (filePaths.length === 0) {
  31266. context.logger.error(
  31267. `No matching files. Patterns tried: ${patterns.join(" ")}`
  31268. );
  31269. process.exitCode = 2;
  31270. return;
  31271. }
  31272. filePaths.forEach(filePath =>
  31273. callback(filePath, getOptionsForFile(context, filePath))
  31274. );
  31275. } catch (error) {
  31276. context.logger.error(
  31277. `Unable to expand glob patterns: ${patterns.join(" ")}\n${error.message}`
  31278. );
  31279. // Don't exit the process if one pattern failed
  31280. process.exitCode = 2;
  31281. }
  31282. }
  31283. function formatFiles(context) {
  31284. // The ignorer will be used to filter file paths after the glob is checked,
  31285. // before any files are actually written
  31286. const ignorer = createIgnorer(context);
  31287. eachFilename(context, context.filePatterns, (filename, options) => {
  31288. const fileIgnored = ignorer.filter([filename]).length === 0;
  31289. if (
  31290. fileIgnored &&
  31291. (context.argv["debug-check"] ||
  31292. context.argv["write"] ||
  31293. context.argv["list-different"])
  31294. ) {
  31295. return;
  31296. }
  31297. if (context.argv["write"] && process.stdout.isTTY) {
  31298. // Don't use `console.log` here since we need to replace this line.
  31299. context.logger.log(filename, { newline: false });
  31300. }
  31301. let input;
  31302. try {
  31303. input = fs.readFileSync(filename, "utf8");
  31304. } catch (error) {
  31305. // Add newline to split errors from filename line.
  31306. context.logger.log("");
  31307. context.logger.error(
  31308. `Unable to read file: ${filename}\n${error.message}`
  31309. );
  31310. // Don't exit the process if one file failed
  31311. process.exitCode = 2;
  31312. return;
  31313. }
  31314. if (fileIgnored) {
  31315. writeOutput({ formatted: input }, options);
  31316. return;
  31317. }
  31318. listDifferent(context, input, options, filename);
  31319. const start = Date.now();
  31320. let result;
  31321. let output;
  31322. try {
  31323. result = format$1(
  31324. context,
  31325. input,
  31326. Object.assign({}, options, { filepath: filename })
  31327. );
  31328. output = result.formatted;
  31329. } catch (error) {
  31330. // Add newline to split errors from filename line.
  31331. process.stdout.write("\n");
  31332. handleError(context, filename, error);
  31333. return;
  31334. }
  31335. if (context.argv["write"]) {
  31336. if (process.stdout.isTTY) {
  31337. // Remove previously printed filename to log it with duration.
  31338. readline.clearLine(process.stdout, 0);
  31339. readline.cursorTo(process.stdout, 0, null);
  31340. }
  31341. // Don't write the file if it won't change in order not to invalidate
  31342. // mtime based caches.
  31343. if (output === input) {
  31344. if (!context.argv["list-different"]) {
  31345. context.logger.log(`${chalk$2.grey(filename)} ${Date.now() - start}ms`);
  31346. }
  31347. } else {
  31348. if (context.argv["list-different"]) {
  31349. context.logger.log(filename);
  31350. } else {
  31351. context.logger.log(`${filename} ${Date.now() - start}ms`);
  31352. }
  31353. try {
  31354. fs.writeFileSync(filename, output, "utf8");
  31355. } catch (error) {
  31356. context.logger.error(
  31357. `Unable to write file: ${filename}\n${error.message}`
  31358. );
  31359. // Don't exit the process if one file failed
  31360. process.exitCode = 2;
  31361. }
  31362. }
  31363. } else if (context.argv["debug-check"]) {
  31364. if (output) {
  31365. context.logger.log(output);
  31366. } else {
  31367. process.exitCode = 2;
  31368. }
  31369. } else if (!context.argv["list-different"]) {
  31370. writeOutput(result, options);
  31371. }
  31372. });
  31373. }
  31374. function getOptionsWithOpposites(options) {
  31375. // Add --no-foo after --foo.
  31376. const optionsWithOpposites = options.map(option => [
  31377. option.description ? option : null,
  31378. option.oppositeDescription
  31379. ? Object.assign({}, option, {
  31380. name: `no-${option.name}`,
  31381. type: "boolean",
  31382. description: option.oppositeDescription
  31383. })
  31384. : null
  31385. ]);
  31386. return flattenArray(optionsWithOpposites).filter(Boolean);
  31387. }
  31388. function createUsage(context) {
  31389. const options = getOptionsWithOpposites(context.detailedOptions).filter(
  31390. // remove unnecessary option (e.g. `semi`, `color`, etc.), which is only used for --help <flag>
  31391. option =>
  31392. !(
  31393. option.type === "boolean" &&
  31394. option.oppositeDescription &&
  31395. !option.name.startsWith("no-")
  31396. )
  31397. );
  31398. const groupedOptions = groupBy(options, option => option.category);
  31399. const firstCategories = constant.categoryOrder.slice(0, -1);
  31400. const lastCategories = constant.categoryOrder.slice(-1);
  31401. const restCategories = Object.keys(groupedOptions).filter(
  31402. category =>
  31403. firstCategories.indexOf(category) === -1 &&
  31404. lastCategories.indexOf(category) === -1
  31405. );
  31406. const allCategories = firstCategories.concat(restCategories, lastCategories);
  31407. const optionsUsage = allCategories.map(category => {
  31408. const categoryOptions = groupedOptions[category]
  31409. .map(option => createOptionUsage(context, option, OPTION_USAGE_THRESHOLD))
  31410. .join("\n");
  31411. return `${category} options:\n\n${indent$9(categoryOptions, 2)}`;
  31412. });
  31413. return [constant.usageSummary].concat(optionsUsage, [""]).join("\n\n");
  31414. }
  31415. function createOptionUsage(context, option, threshold) {
  31416. const header = createOptionUsageHeader(option);
  31417. const optionDefaultValue = getOptionDefaultValue(context, option.name);
  31418. return createOptionUsageRow(
  31419. header,
  31420. `${option.description}${
  31421. optionDefaultValue === undefined
  31422. ? ""
  31423. : `\nDefaults to ${createDefaultValueDisplay(optionDefaultValue)}.`
  31424. }`,
  31425. threshold
  31426. );
  31427. }
  31428. function createDefaultValueDisplay(value) {
  31429. return Array.isArray(value)
  31430. ? `[${value.map(createDefaultValueDisplay).join(", ")}]`
  31431. : value;
  31432. }
  31433. function createOptionUsageHeader(option) {
  31434. const name = `--${option.name}`;
  31435. const alias = option.alias ? `-${option.alias},` : null;
  31436. const type = createOptionUsageType(option);
  31437. return [alias, name, type].filter(Boolean).join(" ");
  31438. }
  31439. function createOptionUsageRow(header, content, threshold) {
  31440. const separator =
  31441. header.length >= threshold
  31442. ? `\n${" ".repeat(threshold)}`
  31443. : " ".repeat(threshold - header.length);
  31444. const description = content.replace(/\n/g, `\n${" ".repeat(threshold)}`);
  31445. return `${header}${separator}${description}`;
  31446. }
  31447. function createOptionUsageType(option) {
  31448. switch (option.type) {
  31449. case "boolean":
  31450. return null;
  31451. case "choice":
  31452. return `<${option.choices
  31453. .filter(choice => !choice.deprecated)
  31454. .map(choice => choice.value)
  31455. .join("|")}>`;
  31456. default:
  31457. return `<${option.type}>`;
  31458. }
  31459. }
  31460. function flattenArray(array) {
  31461. return [].concat.apply([], array);
  31462. }
  31463. function getOptionWithLevenSuggestion(context, options, optionName) {
  31464. // support aliases
  31465. const optionNameContainers = flattenArray(
  31466. options.map((option, index) => [
  31467. { value: option.name, index },
  31468. option.alias ? { value: option.alias, index } : null
  31469. ])
  31470. ).filter(Boolean);
  31471. const optionNameContainer = optionNameContainers.find(
  31472. optionNameContainer => optionNameContainer.value === optionName
  31473. );
  31474. if (optionNameContainer !== undefined) {
  31475. return options[optionNameContainer.index];
  31476. }
  31477. const suggestedOptionNameContainer = optionNameContainers.find(
  31478. optionNameContainer => leven(optionNameContainer.value, optionName) < 3
  31479. );
  31480. if (suggestedOptionNameContainer !== undefined) {
  31481. const suggestedOptionName = suggestedOptionNameContainer.value;
  31482. context.logger.warn(
  31483. `Unknown option name "${optionName}", did you mean "${suggestedOptionName}"?`
  31484. );
  31485. return options[suggestedOptionNameContainer.index];
  31486. }
  31487. context.logger.warn(`Unknown option name "${optionName}"`);
  31488. return options.find(option => option.name === "help");
  31489. }
  31490. function createChoiceUsages(choices, margin, indentation) {
  31491. const activeChoices = choices.filter(choice => !choice.deprecated);
  31492. const threshold =
  31493. activeChoices
  31494. .map(choice => choice.value.length)
  31495. .reduce((current, length) => Math.max(current, length), 0) + margin;
  31496. return activeChoices.map(choice =>
  31497. indent$9(
  31498. createOptionUsageRow(choice.value, choice.description, threshold),
  31499. indentation
  31500. )
  31501. );
  31502. }
  31503. function createDetailedUsage(context, optionName) {
  31504. const option = getOptionWithLevenSuggestion(
  31505. context,
  31506. getOptionsWithOpposites(context.detailedOptions),
  31507. optionName
  31508. );
  31509. const header = createOptionUsageHeader(option);
  31510. const description = `\n\n${indent$9(option.description, 2)}`;
  31511. const choices =
  31512. option.type !== "choice"
  31513. ? ""
  31514. : `\n\nValid options:\n\n${createChoiceUsages(
  31515. option.choices,
  31516. CHOICE_USAGE_MARGIN,
  31517. CHOICE_USAGE_INDENTATION
  31518. ).join("\n")}`;
  31519. const optionDefaultValue = getOptionDefaultValue(context, option.name);
  31520. const defaults =
  31521. optionDefaultValue !== undefined
  31522. ? `\n\nDefault: ${createDefaultValueDisplay(optionDefaultValue)}`
  31523. : "";
  31524. const pluginDefaults =
  31525. option.pluginDefaults && Object.keys(option.pluginDefaults).length
  31526. ? `\nPlugin defaults:${Object.keys(option.pluginDefaults).map(
  31527. key =>
  31528. `\n* ${key}: ${createDefaultValueDisplay(
  31529. option.pluginDefaults[key]
  31530. )}`
  31531. )}`
  31532. : "";
  31533. return `${header}${description}${choices}${defaults}${pluginDefaults}`;
  31534. }
  31535. function getOptionDefaultValue(context, optionName) {
  31536. // --no-option
  31537. if (!(optionName in context.detailedOptionMap)) {
  31538. return undefined;
  31539. }
  31540. const option = context.detailedOptionMap[optionName];
  31541. if (option.default !== undefined) {
  31542. return option.default;
  31543. }
  31544. const optionCamelName = camelcase(optionName);
  31545. if (optionCamelName in context.apiDefaultOptions) {
  31546. return context.apiDefaultOptions[optionCamelName];
  31547. }
  31548. return undefined;
  31549. }
  31550. function indent$9(str, spaces) {
  31551. return str.replace(/^/gm, " ".repeat(spaces));
  31552. }
  31553. function groupBy(array, getKey) {
  31554. return array.reduce((obj, item) => {
  31555. const key = getKey(item);
  31556. const previousItems = key in obj ? obj[key] : [];
  31557. return Object.assign({}, obj, { [key]: previousItems.concat(item) });
  31558. }, Object.create(null));
  31559. }
  31560. function pick(object, keys) {
  31561. return !keys
  31562. ? object
  31563. : keys.reduce(
  31564. (reduced, key) => Object.assign(reduced, { [key]: object[key] }),
  31565. {}
  31566. );
  31567. }
  31568. function createLogger(logLevel) {
  31569. return {
  31570. warn: createLogFunc("warn", "yellow"),
  31571. error: createLogFunc("error", "red"),
  31572. debug: createLogFunc("debug", "blue"),
  31573. log: createLogFunc("log")
  31574. };
  31575. function createLogFunc(loggerName, color) {
  31576. if (!shouldLog(loggerName)) {
  31577. return () => {};
  31578. }
  31579. const prefix = color ? `[${chalk$2[color](loggerName)}] ` : "";
  31580. return function(message, opts) {
  31581. opts = Object.assign({ newline: true }, opts);
  31582. const stream = process[loggerName === "log" ? "stdout" : "stderr"];
  31583. stream.write(message.replace(/^/gm, prefix) + (opts.newline ? "\n" : ""));
  31584. };
  31585. }
  31586. function shouldLog(loggerName) {
  31587. switch (logLevel) {
  31588. case "silent":
  31589. return false;
  31590. default:
  31591. return true;
  31592. case "debug":
  31593. if (loggerName === "debug") {
  31594. return true;
  31595. }
  31596. // fall through
  31597. case "log":
  31598. if (loggerName === "log") {
  31599. return true;
  31600. }
  31601. // fall through
  31602. case "warn":
  31603. if (loggerName === "warn") {
  31604. return true;
  31605. }
  31606. // fall through
  31607. case "error":
  31608. return loggerName === "error";
  31609. }
  31610. }
  31611. }
  31612. function normalizeDetailedOption(name, option) {
  31613. return Object.assign({ category: constant.CATEGORY_OTHER }, option, {
  31614. choices:
  31615. option.choices &&
  31616. option.choices.map(choice => {
  31617. const newChoice = Object.assign(
  31618. { description: "", deprecated: false },
  31619. typeof choice === "object" ? choice : { value: choice }
  31620. );
  31621. if (newChoice.value === true) {
  31622. newChoice.value = ""; // backward compability for original boolean option
  31623. }
  31624. return newChoice;
  31625. })
  31626. });
  31627. }
  31628. function normalizeDetailedOptionMap(detailedOptionMap) {
  31629. return Object.keys(detailedOptionMap)
  31630. .sort()
  31631. .reduce((normalized, name) => {
  31632. const option = detailedOptionMap[name];
  31633. return Object.assign(normalized, {
  31634. [name]: normalizeDetailedOption(name, option)
  31635. });
  31636. }, {});
  31637. }
  31638. function createMinimistOptions(detailedOptions) {
  31639. return {
  31640. boolean: detailedOptions
  31641. .filter(option => option.type === "boolean")
  31642. .map(option => option.name),
  31643. string: detailedOptions
  31644. .filter(option => option.type !== "boolean")
  31645. .map(option => option.name),
  31646. default: detailedOptions
  31647. .filter(option => !option.deprecated)
  31648. .filter(option => !option.forwardToApi || option.name === "plugin")
  31649. .filter(option => option.default !== undefined)
  31650. .reduce(
  31651. (current, option) =>
  31652. Object.assign({ [option.name]: option.default }, current),
  31653. {}
  31654. ),
  31655. alias: detailedOptions
  31656. .filter(option => option.alias !== undefined)
  31657. .reduce(
  31658. (current, option) =>
  31659. Object.assign({ [option.name]: option.alias }, current),
  31660. {}
  31661. )
  31662. };
  31663. }
  31664. function createApiDetailedOptionMap(detailedOptions) {
  31665. return detailedOptions.reduce(
  31666. (current, option) =>
  31667. option.forwardToApi && option.forwardToApi !== option.name
  31668. ? Object.assign(current, { [option.forwardToApi]: option })
  31669. : current,
  31670. {}
  31671. );
  31672. }
  31673. function createDetailedOptionMap(supportOptions) {
  31674. return supportOptions.reduce((reduced, option) => {
  31675. const newOption = Object.assign({}, option, {
  31676. name: option.cliName || dashify(option.name),
  31677. description: option.cliDescription || option.description,
  31678. category: option.cliCategory || constant.CATEGORY_FORMAT,
  31679. forwardToApi: option.name
  31680. });
  31681. if (option.deprecated) {
  31682. delete newOption.forwardToApi;
  31683. delete newOption.description;
  31684. delete newOption.oppositeDescription;
  31685. newOption.deprecated = true;
  31686. }
  31687. return Object.assign(reduced, { [newOption.name]: newOption });
  31688. }, {});
  31689. }
  31690. //-----------------------------context-util-start-------------------------------
  31691. /**
  31692. * @typedef {Object} Context
  31693. * @property logger
  31694. * @property args
  31695. * @property argv
  31696. * @property filePatterns
  31697. * @property supportOptions
  31698. * @property detailedOptions
  31699. * @property detailedOptionMap
  31700. * @property apiDefaultOptions
  31701. */
  31702. function createContext(args) {
  31703. const context = { args };
  31704. updateContextArgv(context);
  31705. normalizeContextArgv(context, ["loglevel", "plugin"]);
  31706. context.logger = createLogger(context.argv["loglevel"]);
  31707. updateContextArgv(context, context.argv["plugin"]);
  31708. return context;
  31709. }
  31710. function initContext(context) {
  31711. // split into 2 step so that we could wrap this in a `try..catch` in cli/index.js
  31712. normalizeContextArgv(context);
  31713. }
  31714. function updateContextOptions(context, plugins) {
  31715. const supportOptions = getSupportInfo$3(null, {
  31716. showDeprecated: true,
  31717. showUnreleased: true,
  31718. showInternal: true,
  31719. plugins
  31720. }).options;
  31721. const detailedOptionMap = normalizeDetailedOptionMap(
  31722. Object.assign({}, createDetailedOptionMap(supportOptions), constant.options)
  31723. );
  31724. const detailedOptions = util$1.arrayify(detailedOptionMap, "name");
  31725. const apiDefaultOptions = supportOptions
  31726. .filter(optionInfo => !optionInfo.deprecated)
  31727. .reduce(
  31728. (reduced, optionInfo) =>
  31729. Object.assign(reduced, { [optionInfo.name]: optionInfo.default }),
  31730. Object.assign({}, options$12.hiddenDefaults)
  31731. );
  31732. context.supportOptions = supportOptions;
  31733. context.detailedOptions = detailedOptions;
  31734. context.detailedOptionMap = detailedOptionMap;
  31735. context.apiDefaultOptions = apiDefaultOptions;
  31736. }
  31737. function pushContextPlugins(context, plugins) {
  31738. context._supportOptions = context.supportOptions;
  31739. context._detailedOptions = context.detailedOptions;
  31740. context._detailedOptionMap = context.detailedOptionMap;
  31741. context._apiDefaultOptions = context.apiDefaultOptions;
  31742. updateContextOptions(context, plugins);
  31743. }
  31744. function popContextPlugins(context) {
  31745. context.supportOptions = context._supportOptions;
  31746. context.detailedOptions = context._detailedOptions;
  31747. context.detailedOptionMap = context._detailedOptionMap;
  31748. context.apiDefaultOptions = context._apiDefaultOptions;
  31749. }
  31750. function updateContextArgv(context, plugins) {
  31751. pushContextPlugins(context, plugins);
  31752. const minimistOptions = createMinimistOptions(context.detailedOptions);
  31753. const argv = minimist_1(context.args, minimistOptions);
  31754. context.argv = argv;
  31755. context.filePatterns = argv["_"];
  31756. }
  31757. function normalizeContextArgv(context, keys) {
  31758. const detailedOptions = !keys
  31759. ? context.detailedOptions
  31760. : context.detailedOptions.filter(
  31761. option => keys.indexOf(option.name) !== -1
  31762. );
  31763. const argv = !keys ? context.argv : pick(context.argv, keys);
  31764. context.argv = optionsNormalizer.normalizeCliOptions(argv, detailedOptions, {
  31765. logger: context.logger
  31766. });
  31767. }
  31768. //------------------------------context-util-end--------------------------------
  31769. var util_1 = {
  31770. createContext,
  31771. createDetailedOptionMap,
  31772. createDetailedUsage,
  31773. createUsage,
  31774. format: format$1,
  31775. formatFiles,
  31776. formatStdin,
  31777. initContext,
  31778. logResolvedConfigPathOrDie,
  31779. normalizeDetailedOptionMap
  31780. };
  31781. function run(args) {
  31782. const context = util_1.createContext(args);
  31783. try {
  31784. util_1.initContext(context);
  31785. context.logger.debug(`normalized argv: ${JSON.stringify(context.argv)}`);
  31786. if (context.argv["write"] && context.argv["debug-check"]) {
  31787. context.logger.error("Cannot use --write and --debug-check together.");
  31788. process.exit(1);
  31789. }
  31790. if (context.argv["find-config-path"] && context.filePatterns.length) {
  31791. context.logger.error("Cannot use --find-config-path with multiple files");
  31792. process.exit(1);
  31793. }
  31794. if (context.argv["version"]) {
  31795. context.logger.log(prettier$2.version);
  31796. process.exit(0);
  31797. }
  31798. if (context.argv["help"] !== undefined) {
  31799. context.logger.log(
  31800. typeof context.argv["help"] === "string" && context.argv["help"] !== ""
  31801. ? util_1.createDetailedUsage(context, context.argv["help"])
  31802. : util_1.createUsage(context)
  31803. );
  31804. process.exit(0);
  31805. }
  31806. if (context.argv["support-info"]) {
  31807. context.logger.log(
  31808. prettier$2.format(jsonStableStringify(prettier$2.getSupportInfo()), {
  31809. parser: "json"
  31810. })
  31811. );
  31812. process.exit(0);
  31813. }
  31814. const hasFilePatterns = context.filePatterns.length !== 0;
  31815. const useStdin =
  31816. context.argv["stdin"] || (!hasFilePatterns && !process.stdin.isTTY);
  31817. if (context.argv["find-config-path"]) {
  31818. util_1.logResolvedConfigPathOrDie(
  31819. context,
  31820. context.argv["find-config-path"]
  31821. );
  31822. } else if (useStdin) {
  31823. util_1.formatStdin(context);
  31824. } else if (hasFilePatterns) {
  31825. util_1.formatFiles(context);
  31826. } else {
  31827. context.logger.log(util_1.createUsage(context));
  31828. process.exit(1);
  31829. }
  31830. } catch (error) {
  31831. context.logger.error(error.message);
  31832. process.exit(1);
  31833. }
  31834. }
  31835. var cli = {
  31836. run
  31837. };
  31838. cli.run(process.argv.slice(2));
  31839. var prettier = {
  31840. };
  31841. module.exports = prettier;