bin-prettier.js 1.0 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967
  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 path = _interopDefault(require('path'));
  5. var os = _interopDefault(require('os'));
  6. var assert = _interopDefault(require('assert'));
  7. var fs = _interopDefault(require('fs'));
  8. var util = _interopDefault(require('util'));
  9. var events = _interopDefault(require('events'));
  10. var thirdParty = require('./third-party');
  11. var thirdParty__default = thirdParty['default'];
  12. var readline = _interopDefault(require('readline'));
  13. var name = "prettier";
  14. var version$1 = "1.13.7";
  15. var description = "Prettier is an opinionated code formatter";
  16. var bin = {
  17. "prettier": "./bin/prettier.js"
  18. };
  19. var repository = "prettier/prettier";
  20. var homepage = "https://prettier.io";
  21. var author = "James Long";
  22. var license = "MIT";
  23. var main = "./index.js";
  24. var engines = {
  25. "node": ">=6"
  26. };
  27. var dependencies = {
  28. "@babel/code-frame": "7.0.0-beta.49",
  29. "@babel/parser": "7.0.0-beta.49",
  30. "@glimmer/syntax": "0.30.3",
  31. "camelcase": "4.1.0",
  32. "chalk": "2.1.0",
  33. "cjk-regex": "1.0.2",
  34. "cosmiconfig": "3.1.0",
  35. "dashify": "0.2.2",
  36. "dedent": "0.7.0",
  37. "diff": "3.2.0",
  38. "editorconfig": "0.15.0",
  39. "editorconfig-to-prettier": "0.0.6",
  40. "emoji-regex": "6.5.1",
  41. "escape-string-regexp": "1.0.5",
  42. "esutils": "2.0.2",
  43. "find-parent-dir": "0.3.0",
  44. "find-project-root": "1.1.1",
  45. "flow-parser": "0.75.0",
  46. "get-stream": "3.0.0",
  47. "globby": "6.1.0",
  48. "graphql": "0.13.2",
  49. "html-tag-names": "1.1.2",
  50. "ignore": "3.3.7",
  51. "jest-docblock": "22.2.2",
  52. "json-stable-stringify": "1.0.1",
  53. "leven": "2.1.0",
  54. "lodash.uniqby": "4.7.0",
  55. "mem": "1.1.0",
  56. "minimatch": "3.0.4",
  57. "minimist": "1.2.0",
  58. "parse5": "3.0.3",
  59. "postcss-less": "1.1.5",
  60. "postcss-media-query-parser": "0.2.3",
  61. "postcss-scss": "1.0.5",
  62. "postcss-selector-parser": "2.2.3",
  63. "postcss-values-parser": "1.5.0",
  64. "remark-parse": "5.0.0",
  65. "resolve": "1.5.0",
  66. "semver": "5.4.1",
  67. "string-width": "2.1.1",
  68. "typescript": "2.9.0-dev.20180421",
  69. "typescript-eslint-parser": "16.0.0",
  70. "unicode-regex": "1.0.1",
  71. "unified": "6.1.6"
  72. };
  73. var devDependencies = {
  74. "@babel/cli": "7.0.0-beta.49",
  75. "@babel/core": "7.0.0-beta.49",
  76. "@babel/preset-env": "7.0.0-beta.49",
  77. "builtin-modules": "2.0.0",
  78. "codecov": "2.2.0",
  79. "cross-env": "5.0.5",
  80. "eslint": "4.18.2",
  81. "eslint-config-prettier": "2.9.0",
  82. "eslint-friendly-formatter": "3.0.0",
  83. "eslint-plugin-import": "2.9.0",
  84. "eslint-plugin-prettier": "2.6.0",
  85. "eslint-plugin-react": "7.7.0",
  86. "jest": "21.1.0",
  87. "mkdirp": "0.5.1",
  88. "prettier": "1.13.4",
  89. "prettylint": "1.0.0",
  90. "rimraf": "2.6.2",
  91. "rollup": "0.47.6",
  92. "rollup-plugin-babel": "4.0.0-beta.4",
  93. "rollup-plugin-commonjs": "8.2.6",
  94. "rollup-plugin-json": "2.1.1",
  95. "rollup-plugin-node-builtins": "2.0.0",
  96. "rollup-plugin-node-globals": "1.1.0",
  97. "rollup-plugin-node-resolve": "2.0.0",
  98. "rollup-plugin-replace": "1.2.1",
  99. "rollup-plugin-uglify": "3.0.0",
  100. "shelljs": "0.8.1",
  101. "snapshot-diff": "0.2.2",
  102. "strip-ansi": "4.0.0",
  103. "tempy": "0.2.1",
  104. "webpack": "2.6.1"
  105. };
  106. var scripts = {
  107. "prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1",
  108. "prepare-release": "yarn && yarn build && yarn test:dist",
  109. "test": "jest",
  110. "test:dist": "node ./scripts/test-dist.js",
  111. "test-integration": "jest tests_integration",
  112. "lint": "cross-env EFF_NO_LINK_RULES=true eslint . --format node_modules/eslint-friendly-formatter",
  113. "lint-docs": "prettylint {.,docs,website,website/blog}/*.md",
  114. "build": "node ./scripts/build/build.js",
  115. "build-docs": "node ./scripts/build-docs.js",
  116. "check-deps": "node ./scripts/check-deps.js"
  117. };
  118. var _package = {
  119. name: name,
  120. version: version$1,
  121. description: description,
  122. bin: bin,
  123. repository: repository,
  124. homepage: homepage,
  125. author: author,
  126. license: license,
  127. main: main,
  128. engines: engines,
  129. dependencies: dependencies,
  130. devDependencies: devDependencies,
  131. scripts: scripts
  132. };
  133. var _package$1 = Object.freeze({
  134. name: name,
  135. version: version$1,
  136. description: description,
  137. bin: bin,
  138. repository: repository,
  139. homepage: homepage,
  140. author: author,
  141. license: license,
  142. main: main,
  143. engines: engines,
  144. dependencies: dependencies,
  145. devDependencies: devDependencies,
  146. scripts: scripts,
  147. default: _package
  148. });
  149. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  150. function unwrapExports (x) {
  151. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  152. }
  153. function createCommonjsModule(fn, module) {
  154. return module = { exports: {} }, fn(module, module.exports), module.exports;
  155. }
  156. var base = createCommonjsModule(function (module, exports) {
  157. /*istanbul ignore start*/
  158. 'use strict';
  159. exports.__esModule = true;
  160. exports['default'] =
  161. /*istanbul ignore end*/
  162. Diff;
  163. function Diff() {}
  164. Diff.prototype = {
  165. /*istanbul ignore start*/
  166. /*istanbul ignore end*/
  167. diff: function diff(oldString, newString) {
  168. /*istanbul ignore start*/
  169. var
  170. /*istanbul ignore end*/
  171. options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  172. var callback = options.callback;
  173. if (typeof options === 'function') {
  174. callback = options;
  175. options = {};
  176. }
  177. this.options = options;
  178. var self = this;
  179. function done(value) {
  180. if (callback) {
  181. setTimeout(function () {
  182. callback(undefined, value);
  183. }, 0);
  184. return true;
  185. } else {
  186. return value;
  187. }
  188. } // Allow subclasses to massage the input prior to running
  189. oldString = this.castInput(oldString);
  190. newString = this.castInput(newString);
  191. oldString = this.removeEmpty(this.tokenize(oldString));
  192. newString = this.removeEmpty(this.tokenize(newString));
  193. var newLen = newString.length,
  194. oldLen = oldString.length;
  195. var editLength = 1;
  196. var maxEditLength = newLen + oldLen;
  197. var bestPath = [{
  198. newPos: -1,
  199. components: []
  200. }]; // Seed editLength = 0, i.e. the content starts with the same values
  201. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  202. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  203. // Identity per the equality and tokenizer
  204. return done([{
  205. value: this.join(newString),
  206. count: newString.length
  207. }]);
  208. } // Main worker method. checks all permutations of a given edit length for acceptance.
  209. function execEditLength() {
  210. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  211. var basePath =
  212. /*istanbul ignore start*/
  213. void 0;
  214. var addPath = bestPath[diagonalPath - 1],
  215. removePath = bestPath[diagonalPath + 1],
  216. _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  217. if (addPath) {
  218. // No one else is going to attempt to use this value, clear it
  219. bestPath[diagonalPath - 1] = undefined;
  220. }
  221. var canAdd = addPath && addPath.newPos + 1 < newLen,
  222. canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
  223. if (!canAdd && !canRemove) {
  224. // If this path is a terminal then prune
  225. bestPath[diagonalPath] = undefined;
  226. continue;
  227. } // Select the diagonal that we want to branch from. We select the prior
  228. // path whose position in the new string is the farthest from the origin
  229. // and does not pass the bounds of the diff graph
  230. if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
  231. basePath = clonePath(removePath);
  232. self.pushComponent(basePath.components, undefined, true);
  233. } else {
  234. basePath = addPath; // No need to clone, we've pulled it from the list
  235. basePath.newPos++;
  236. self.pushComponent(basePath.components, true, undefined);
  237. }
  238. _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
  239. if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
  240. return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
  241. } else {
  242. // Otherwise track this path as a potential candidate and continue.
  243. bestPath[diagonalPath] = basePath;
  244. }
  245. }
  246. editLength++;
  247. } // Performs the length of edit iteration. Is a bit fugly as this has to support the
  248. // sync and async mode which is never fun. Loops over execEditLength until a value
  249. // is produced.
  250. if (callback) {
  251. (function exec() {
  252. setTimeout(function () {
  253. // This should not happen, but we want to be safe.
  254. /* istanbul ignore next */
  255. if (editLength > maxEditLength) {
  256. return callback();
  257. }
  258. if (!execEditLength()) {
  259. exec();
  260. }
  261. }, 0);
  262. })();
  263. } else {
  264. while (editLength <= maxEditLength) {
  265. var ret = execEditLength();
  266. if (ret) {
  267. return ret;
  268. }
  269. }
  270. }
  271. },
  272. /*istanbul ignore start*/
  273. /*istanbul ignore end*/
  274. pushComponent: function pushComponent(components, added, removed) {
  275. var last = components[components.length - 1];
  276. if (last && last.added === added && last.removed === removed) {
  277. // We need to clone here as the component clone operation is just
  278. // as shallow array clone
  279. components[components.length - 1] = {
  280. count: last.count + 1,
  281. added: added,
  282. removed: removed
  283. };
  284. } else {
  285. components.push({
  286. count: 1,
  287. added: added,
  288. removed: removed
  289. });
  290. }
  291. },
  292. /*istanbul ignore start*/
  293. /*istanbul ignore end*/
  294. extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
  295. var newLen = newString.length,
  296. oldLen = oldString.length,
  297. newPos = basePath.newPos,
  298. oldPos = newPos - diagonalPath,
  299. commonCount = 0;
  300. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  301. newPos++;
  302. oldPos++;
  303. commonCount++;
  304. }
  305. if (commonCount) {
  306. basePath.components.push({
  307. count: commonCount
  308. });
  309. }
  310. basePath.newPos = newPos;
  311. return oldPos;
  312. },
  313. /*istanbul ignore start*/
  314. /*istanbul ignore end*/
  315. equals: function equals(left, right) {
  316. return left === right;
  317. },
  318. /*istanbul ignore start*/
  319. /*istanbul ignore end*/
  320. removeEmpty: function removeEmpty(array) {
  321. var ret = [];
  322. for (var i = 0; i < array.length; i++) {
  323. if (array[i]) {
  324. ret.push(array[i]);
  325. }
  326. }
  327. return ret;
  328. },
  329. /*istanbul ignore start*/
  330. /*istanbul ignore end*/
  331. castInput: function castInput(value) {
  332. return value;
  333. },
  334. /*istanbul ignore start*/
  335. /*istanbul ignore end*/
  336. tokenize: function tokenize(value) {
  337. return value.split('');
  338. },
  339. /*istanbul ignore start*/
  340. /*istanbul ignore end*/
  341. join: function join(chars) {
  342. return chars.join('');
  343. }
  344. };
  345. function buildValues(diff, components, newString, oldString, useLongestToken) {
  346. var componentPos = 0,
  347. componentLen = components.length,
  348. newPos = 0,
  349. oldPos = 0;
  350. for (; componentPos < componentLen; componentPos++) {
  351. var component = components[componentPos];
  352. if (!component.removed) {
  353. if (!component.added && useLongestToken) {
  354. var value = newString.slice(newPos, newPos + component.count);
  355. value = value.map(function (value, i) {
  356. var oldValue = oldString[oldPos + i];
  357. return oldValue.length > value.length ? oldValue : value;
  358. });
  359. component.value = diff.join(value);
  360. } else {
  361. component.value = diff.join(newString.slice(newPos, newPos + component.count));
  362. }
  363. newPos += component.count; // Common case
  364. if (!component.added) {
  365. oldPos += component.count;
  366. }
  367. } else {
  368. component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
  369. oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
  370. // The diffing algorithm is tied to add then remove output and this is the simplest
  371. // route to get the desired output with minimal overhead.
  372. if (componentPos && components[componentPos - 1].added) {
  373. var tmp = components[componentPos - 1];
  374. components[componentPos - 1] = components[componentPos];
  375. components[componentPos] = tmp;
  376. }
  377. }
  378. } // Special case handle for when one terminal is ignored. For this case we merge the
  379. // terminal into the prior string and drop the change.
  380. var lastComponent = components[componentLen - 1];
  381. if (componentLen > 1 && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
  382. components[componentLen - 2].value += lastComponent.value;
  383. components.pop();
  384. }
  385. return components;
  386. }
  387. function clonePath(path$$1) {
  388. return {
  389. newPos: path$$1.newPos,
  390. components: path$$1.components.slice(0)
  391. };
  392. }
  393. });
  394. unwrapExports(base);
  395. var character = createCommonjsModule(function (module, exports) {
  396. /*istanbul ignore start*/
  397. 'use strict';
  398. exports.__esModule = true;
  399. exports.characterDiff = undefined;
  400. exports.
  401. /*istanbul ignore end*/
  402. diffChars = diffChars;
  403. /*istanbul ignore start*/
  404. var _base2 = _interopRequireDefault(base);
  405. function _interopRequireDefault(obj) {
  406. return obj && obj.__esModule ? obj : {
  407. 'default': obj
  408. };
  409. }
  410. /*istanbul ignore end*/
  411. var characterDiff =
  412. /*istanbul ignore start*/
  413. exports.
  414. /*istanbul ignore end*/
  415. characterDiff = new
  416. /*istanbul ignore start*/
  417. _base2['default']();
  418. function diffChars(oldStr, newStr, callback) {
  419. return characterDiff.diff(oldStr, newStr, callback);
  420. }
  421. });
  422. unwrapExports(character);
  423. var params = createCommonjsModule(function (module, exports) {
  424. /*istanbul ignore start*/
  425. 'use strict';
  426. exports.__esModule = true;
  427. exports.
  428. /*istanbul ignore end*/
  429. generateOptions = generateOptions;
  430. function generateOptions(options, defaults) {
  431. if (typeof options === 'function') {
  432. defaults.callback = options;
  433. } else if (options) {
  434. for (var name in options) {
  435. /* istanbul ignore else */
  436. if (options.hasOwnProperty(name)) {
  437. defaults[name] = options[name];
  438. }
  439. }
  440. }
  441. return defaults;
  442. }
  443. });
  444. unwrapExports(params);
  445. var word = createCommonjsModule(function (module, exports) {
  446. /*istanbul ignore start*/
  447. 'use strict';
  448. exports.__esModule = true;
  449. exports.wordDiff = undefined;
  450. exports.
  451. /*istanbul ignore end*/
  452. diffWords = diffWords;
  453. /*istanbul ignore start*/
  454. exports.
  455. /*istanbul ignore end*/
  456. diffWordsWithSpace = diffWordsWithSpace;
  457. /*istanbul ignore start*/
  458. var _base2 = _interopRequireDefault(base);
  459. /*istanbul ignore end*/
  460. /*istanbul ignore start*/
  461. function _interopRequireDefault(obj) {
  462. return obj && obj.__esModule ? obj : {
  463. 'default': obj
  464. };
  465. }
  466. /*istanbul ignore end*/
  467. // Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
  468. //
  469. // Ranges and exceptions:
  470. // Latin-1 Supplement, 0080–00FF
  471. // - U+00D7 × Multiplication sign
  472. // - U+00F7 ÷ Division sign
  473. // Latin Extended-A, 0100–017F
  474. // Latin Extended-B, 0180–024F
  475. // IPA Extensions, 0250–02AF
  476. // Spacing Modifier Letters, 02B0–02FF
  477. // - U+02C7 ˇ &#711; Caron
  478. // - U+02D8 ˘ &#728; Breve
  479. // - U+02D9 ˙ &#729; Dot Above
  480. // - U+02DA ˚ &#730; Ring Above
  481. // - U+02DB ˛ &#731; Ogonek
  482. // - U+02DC ˜ &#732; Small Tilde
  483. // - U+02DD ˝ &#733; Double Acute Accent
  484. // Latin Extended Additional, 1E00–1EFF
  485. var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
  486. var reWhitespace = /\S/;
  487. var wordDiff =
  488. /*istanbul ignore start*/
  489. exports.
  490. /*istanbul ignore end*/
  491. wordDiff = new
  492. /*istanbul ignore start*/
  493. _base2['default']();
  494. wordDiff.equals = function (left, right) {
  495. return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
  496. };
  497. wordDiff.tokenize = function (value) {
  498. var tokens = value.split(/(\s+|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
  499. for (var i = 0; i < tokens.length - 1; i++) {
  500. // If we have an empty string in the next field and we have only word chars before and after, merge
  501. if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
  502. tokens[i] += tokens[i + 2];
  503. tokens.splice(i + 1, 2);
  504. i--;
  505. }
  506. }
  507. return tokens;
  508. };
  509. function diffWords(oldStr, newStr, callback) {
  510. var options =
  511. /*istanbul ignore start*/
  512. (0, params.generateOptions
  513. /*istanbul ignore end*/
  514. )(callback, {
  515. ignoreWhitespace: true
  516. });
  517. return wordDiff.diff(oldStr, newStr, options);
  518. }
  519. function diffWordsWithSpace(oldStr, newStr, callback) {
  520. return wordDiff.diff(oldStr, newStr, callback);
  521. }
  522. });
  523. unwrapExports(word);
  524. var line = createCommonjsModule(function (module, exports) {
  525. /*istanbul ignore start*/
  526. 'use strict';
  527. exports.__esModule = true;
  528. exports.lineDiff = undefined;
  529. exports.
  530. /*istanbul ignore end*/
  531. diffLines = diffLines;
  532. /*istanbul ignore start*/
  533. exports.
  534. /*istanbul ignore end*/
  535. diffTrimmedLines = diffTrimmedLines;
  536. /*istanbul ignore start*/
  537. var _base2 = _interopRequireDefault(base);
  538. /*istanbul ignore end*/
  539. /*istanbul ignore start*/
  540. function _interopRequireDefault(obj) {
  541. return obj && obj.__esModule ? obj : {
  542. 'default': obj
  543. };
  544. }
  545. /*istanbul ignore end*/
  546. var lineDiff =
  547. /*istanbul ignore start*/
  548. exports.
  549. /*istanbul ignore end*/
  550. lineDiff = new
  551. /*istanbul ignore start*/
  552. _base2['default']();
  553. lineDiff.tokenize = function (value) {
  554. var retLines = [],
  555. linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
  556. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  557. linesAndNewlines.pop();
  558. } // Merge the content and line separators into single tokens
  559. for (var i = 0; i < linesAndNewlines.length; i++) {
  560. var line = linesAndNewlines[i];
  561. if (i % 2 && !this.options.newlineIsToken) {
  562. retLines[retLines.length - 1] += line;
  563. } else {
  564. if (this.options.ignoreWhitespace) {
  565. line = line.trim();
  566. }
  567. retLines.push(line);
  568. }
  569. }
  570. return retLines;
  571. };
  572. function diffLines(oldStr, newStr, callback) {
  573. return lineDiff.diff(oldStr, newStr, callback);
  574. }
  575. function diffTrimmedLines(oldStr, newStr, callback) {
  576. var options =
  577. /*istanbul ignore start*/
  578. (0, params.generateOptions
  579. /*istanbul ignore end*/
  580. )(callback, {
  581. ignoreWhitespace: true
  582. });
  583. return lineDiff.diff(oldStr, newStr, options);
  584. }
  585. });
  586. unwrapExports(line);
  587. var sentence = createCommonjsModule(function (module, exports) {
  588. /*istanbul ignore start*/
  589. 'use strict';
  590. exports.__esModule = true;
  591. exports.sentenceDiff = undefined;
  592. exports.
  593. /*istanbul ignore end*/
  594. diffSentences = diffSentences;
  595. /*istanbul ignore start*/
  596. var _base2 = _interopRequireDefault(base);
  597. function _interopRequireDefault(obj) {
  598. return obj && obj.__esModule ? obj : {
  599. 'default': obj
  600. };
  601. }
  602. /*istanbul ignore end*/
  603. var sentenceDiff =
  604. /*istanbul ignore start*/
  605. exports.
  606. /*istanbul ignore end*/
  607. sentenceDiff = new
  608. /*istanbul ignore start*/
  609. _base2['default']();
  610. sentenceDiff.tokenize = function (value) {
  611. return value.split(/(\S.+?[.!?])(?=\s+|$)/);
  612. };
  613. function diffSentences(oldStr, newStr, callback) {
  614. return sentenceDiff.diff(oldStr, newStr, callback);
  615. }
  616. });
  617. unwrapExports(sentence);
  618. var css = createCommonjsModule(function (module, exports) {
  619. /*istanbul ignore start*/
  620. 'use strict';
  621. exports.__esModule = true;
  622. exports.cssDiff = undefined;
  623. exports.
  624. /*istanbul ignore end*/
  625. diffCss = diffCss;
  626. /*istanbul ignore start*/
  627. var _base2 = _interopRequireDefault(base);
  628. function _interopRequireDefault(obj) {
  629. return obj && obj.__esModule ? obj : {
  630. 'default': obj
  631. };
  632. }
  633. /*istanbul ignore end*/
  634. var cssDiff =
  635. /*istanbul ignore start*/
  636. exports.
  637. /*istanbul ignore end*/
  638. cssDiff = new
  639. /*istanbul ignore start*/
  640. _base2['default']();
  641. cssDiff.tokenize = function (value) {
  642. return value.split(/([{}:;,]|\s+)/);
  643. };
  644. function diffCss(oldStr, newStr, callback) {
  645. return cssDiff.diff(oldStr, newStr, callback);
  646. }
  647. });
  648. unwrapExports(css);
  649. var json = createCommonjsModule(function (module, exports) {
  650. /*istanbul ignore start*/
  651. 'use strict';
  652. exports.__esModule = true;
  653. exports.jsonDiff = undefined;
  654. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  655. return typeof obj;
  656. } : function (obj) {
  657. return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
  658. };
  659. exports.
  660. /*istanbul ignore end*/
  661. diffJson = diffJson;
  662. /*istanbul ignore start*/
  663. exports.
  664. /*istanbul ignore end*/
  665. canonicalize = canonicalize;
  666. /*istanbul ignore start*/
  667. var _base2 = _interopRequireDefault(base);
  668. /*istanbul ignore end*/
  669. /*istanbul ignore start*/
  670. function _interopRequireDefault(obj) {
  671. return obj && obj.__esModule ? obj : {
  672. 'default': obj
  673. };
  674. }
  675. /*istanbul ignore end*/
  676. var objectPrototypeToString = Object.prototype.toString;
  677. var jsonDiff =
  678. /*istanbul ignore start*/
  679. exports.
  680. /*istanbul ignore end*/
  681. jsonDiff = new
  682. /*istanbul ignore start*/
  683. _base2['default'](); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  684. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  685. jsonDiff.useLongestToken = true;
  686. jsonDiff.tokenize =
  687. /*istanbul ignore start*/
  688. line.lineDiff.
  689. /*istanbul ignore end*/
  690. tokenize;
  691. jsonDiff.castInput = function (value) {
  692. /*istanbul ignore start*/
  693. var
  694. /*istanbul ignore end*/
  695. undefinedReplacement = this.options.undefinedReplacement;
  696. return typeof value === 'string' ? value : JSON.stringify(canonicalize(value), function (k, v) {
  697. if (typeof v === 'undefined') {
  698. return undefinedReplacement;
  699. }
  700. return v;
  701. }, ' ');
  702. };
  703. jsonDiff.equals = function (left, right) {
  704. return (
  705. /*istanbul ignore start*/
  706. _base2['default'].
  707. /*istanbul ignore end*/
  708. prototype.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'))
  709. );
  710. };
  711. function diffJson(oldObj, newObj, options) {
  712. return jsonDiff.diff(oldObj, newObj, options);
  713. } // This function handles the presence of circular references by bailing out when encountering an
  714. // object that is already on the "stack" of items being processed.
  715. function canonicalize(obj, stack, replacementStack) {
  716. stack = stack || [];
  717. replacementStack = replacementStack || [];
  718. var i =
  719. /*istanbul ignore start*/
  720. void 0;
  721. for (i = 0; i < stack.length; i += 1) {
  722. if (stack[i] === obj) {
  723. return replacementStack[i];
  724. }
  725. }
  726. var canonicalizedObj =
  727. /*istanbul ignore start*/
  728. void 0;
  729. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  730. stack.push(obj);
  731. canonicalizedObj = new Array(obj.length);
  732. replacementStack.push(canonicalizedObj);
  733. for (i = 0; i < obj.length; i += 1) {
  734. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack);
  735. }
  736. stack.pop();
  737. replacementStack.pop();
  738. return canonicalizedObj;
  739. }
  740. if (obj && obj.toJSON) {
  741. obj = obj.toJSON();
  742. }
  743. if (
  744. /*istanbul ignore start*/
  745. (typeof
  746. /*istanbul ignore end*/
  747. obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && obj !== null) {
  748. stack.push(obj);
  749. canonicalizedObj = {};
  750. replacementStack.push(canonicalizedObj);
  751. var sortedKeys = [],
  752. key =
  753. /*istanbul ignore start*/
  754. void 0;
  755. for (key in obj) {
  756. /* istanbul ignore else */
  757. if (obj.hasOwnProperty(key)) {
  758. sortedKeys.push(key);
  759. }
  760. }
  761. sortedKeys.sort();
  762. for (i = 0; i < sortedKeys.length; i += 1) {
  763. key = sortedKeys[i];
  764. canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack);
  765. }
  766. stack.pop();
  767. replacementStack.pop();
  768. } else {
  769. canonicalizedObj = obj;
  770. }
  771. return canonicalizedObj;
  772. }
  773. });
  774. unwrapExports(json);
  775. var array = createCommonjsModule(function (module, exports) {
  776. /*istanbul ignore start*/
  777. 'use strict';
  778. exports.__esModule = true;
  779. exports.arrayDiff = undefined;
  780. exports.
  781. /*istanbul ignore end*/
  782. diffArrays = diffArrays;
  783. /*istanbul ignore start*/
  784. var _base2 = _interopRequireDefault(base);
  785. function _interopRequireDefault(obj) {
  786. return obj && obj.__esModule ? obj : {
  787. 'default': obj
  788. };
  789. }
  790. /*istanbul ignore end*/
  791. var arrayDiff =
  792. /*istanbul ignore start*/
  793. exports.
  794. /*istanbul ignore end*/
  795. arrayDiff = new
  796. /*istanbul ignore start*/
  797. _base2['default']();
  798. arrayDiff.tokenize = arrayDiff.join = function (value) {
  799. return value.slice();
  800. };
  801. function diffArrays(oldArr, newArr, callback) {
  802. return arrayDiff.diff(oldArr, newArr, callback);
  803. }
  804. });
  805. unwrapExports(array);
  806. var parse = createCommonjsModule(function (module, exports) {
  807. /*istanbul ignore start*/
  808. 'use strict';
  809. exports.__esModule = true;
  810. exports.
  811. /*istanbul ignore end*/
  812. parsePatch = parsePatch;
  813. function parsePatch(uniDiff) {
  814. /*istanbul ignore start*/
  815. var
  816. /*istanbul ignore end*/
  817. options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  818. var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
  819. delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  820. list = [],
  821. i = 0;
  822. function parseIndex() {
  823. var index = {};
  824. list.push(index); // Parse diff metadata
  825. while (i < diffstr.length) {
  826. var line = diffstr[i]; // File header found, end parsing diff metadata
  827. if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
  828. break;
  829. } // Diff index
  830. var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
  831. if (header) {
  832. index.index = header[1];
  833. }
  834. i++;
  835. } // Parse file headers if they are defined. Unified diff requires them, but
  836. // there's no technical issues to have an isolated hunk without file header
  837. parseFileHeader(index);
  838. parseFileHeader(index); // Parse hunks
  839. index.hunks = [];
  840. while (i < diffstr.length) {
  841. var _line = diffstr[i];
  842. if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
  843. break;
  844. } else if (/^@@/.test(_line)) {
  845. index.hunks.push(parseHunk());
  846. } else if (_line && options.strict) {
  847. // Ignore unexpected content unless in strict mode
  848. throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
  849. } else {
  850. i++;
  851. }
  852. }
  853. } // Parses the --- and +++ headers, if none are found, no lines
  854. // are consumed.
  855. function parseFileHeader(index) {
  856. var headerPattern = /^(---|\+\+\+)\s+([\S ]*)(?:\t(.*?)\s*)?$/;
  857. var fileHeader = headerPattern.exec(diffstr[i]);
  858. if (fileHeader) {
  859. var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
  860. index[keyPrefix + 'FileName'] = fileHeader[2];
  861. index[keyPrefix + 'Header'] = fileHeader[3];
  862. i++;
  863. }
  864. } // Parses a hunk
  865. // This assumes that we are at the start of a hunk.
  866. function parseHunk() {
  867. var chunkHeaderIndex = i,
  868. chunkHeaderLine = diffstr[i++],
  869. chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
  870. var hunk = {
  871. oldStart: +chunkHeader[1],
  872. oldLines: +chunkHeader[2] || 1,
  873. newStart: +chunkHeader[3],
  874. newLines: +chunkHeader[4] || 1,
  875. lines: [],
  876. linedelimiters: []
  877. };
  878. var addCount = 0,
  879. removeCount = 0;
  880. for (; i < diffstr.length; i++) {
  881. // Lines starting with '---' could be mistaken for the "remove line" operation
  882. // But they could be the header for the next file. Therefore prune such cases out.
  883. if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
  884. break;
  885. }
  886. var operation = diffstr[i][0];
  887. if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
  888. hunk.lines.push(diffstr[i]);
  889. hunk.linedelimiters.push(delimiters[i] || '\n');
  890. if (operation === '+') {
  891. addCount++;
  892. } else if (operation === '-') {
  893. removeCount++;
  894. } else if (operation === ' ') {
  895. addCount++;
  896. removeCount++;
  897. }
  898. } else {
  899. break;
  900. }
  901. } // Handle the empty block count case
  902. if (!addCount && hunk.newLines === 1) {
  903. hunk.newLines = 0;
  904. }
  905. if (!removeCount && hunk.oldLines === 1) {
  906. hunk.oldLines = 0;
  907. } // Perform optional sanity checking
  908. if (options.strict) {
  909. if (addCount !== hunk.newLines) {
  910. throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  911. }
  912. if (removeCount !== hunk.oldLines) {
  913. throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  914. }
  915. }
  916. return hunk;
  917. }
  918. while (i < diffstr.length) {
  919. parseIndex();
  920. }
  921. return list;
  922. }
  923. });
  924. unwrapExports(parse);
  925. var distanceIterator = createCommonjsModule(function (module, exports) {
  926. /*istanbul ignore start*/
  927. "use strict";
  928. exports.__esModule = true;
  929. exports["default"] =
  930. /*istanbul ignore end*/
  931. function (start, minLine, maxLine) {
  932. var wantForward = true,
  933. backwardExhausted = false,
  934. forwardExhausted = false,
  935. localOffset = 1;
  936. return function iterator() {
  937. if (wantForward && !forwardExhausted) {
  938. if (backwardExhausted) {
  939. localOffset++;
  940. } else {
  941. wantForward = false;
  942. } // Check if trying to fit beyond text length, and if not, check it fits
  943. // after offset location (or desired location on first iteration)
  944. if (start + localOffset <= maxLine) {
  945. return localOffset;
  946. }
  947. forwardExhausted = true;
  948. }
  949. if (!backwardExhausted) {
  950. if (!forwardExhausted) {
  951. wantForward = true;
  952. } // Check if trying to fit before text beginning, and if not, check it fits
  953. // before offset location
  954. if (minLine <= start - localOffset) {
  955. return -localOffset++;
  956. }
  957. backwardExhausted = true;
  958. return iterator();
  959. } // We tried to fit hunk before text beginning and beyond text lenght, then
  960. // hunk can't fit on the text. Return undefined
  961. };
  962. };
  963. });
  964. unwrapExports(distanceIterator);
  965. var apply = createCommonjsModule(function (module, exports) {
  966. /*istanbul ignore start*/
  967. 'use strict';
  968. exports.__esModule = true;
  969. exports.
  970. /*istanbul ignore end*/
  971. applyPatch = applyPatch;
  972. /*istanbul ignore start*/
  973. exports.
  974. /*istanbul ignore end*/
  975. applyPatches = applyPatches;
  976. /*istanbul ignore start*/
  977. var _distanceIterator2 = _interopRequireDefault(distanceIterator);
  978. function _interopRequireDefault(obj) {
  979. return obj && obj.__esModule ? obj : {
  980. 'default': obj
  981. };
  982. }
  983. /*istanbul ignore end*/
  984. function applyPatch(source, uniDiff) {
  985. /*istanbul ignore start*/
  986. var
  987. /*istanbul ignore end*/
  988. options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  989. if (typeof uniDiff === 'string') {
  990. uniDiff =
  991. /*istanbul ignore start*/
  992. (0, parse.parsePatch
  993. /*istanbul ignore end*/
  994. )(uniDiff);
  995. }
  996. if (Array.isArray(uniDiff)) {
  997. if (uniDiff.length > 1) {
  998. throw new Error('applyPatch only works with a single input.');
  999. }
  1000. uniDiff = uniDiff[0];
  1001. } // Apply the diff to the input
  1002. var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
  1003. delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  1004. hunks = uniDiff.hunks,
  1005. compareLine = options.compareLine || function (lineNumber, line, operation, patchContent)
  1006. /*istanbul ignore start*/
  1007. {
  1008. return (
  1009. /*istanbul ignore end*/
  1010. line === patchContent
  1011. );
  1012. },
  1013. errorCount = 0,
  1014. fuzzFactor = options.fuzzFactor || 0,
  1015. minLine = 0,
  1016. offset = 0,
  1017. removeEOFNL =
  1018. /*istanbul ignore start*/
  1019. void 0
  1020. /*istanbul ignore end*/
  1021. ,
  1022. addEOFNL =
  1023. /*istanbul ignore start*/
  1024. void 0;
  1025. /**
  1026. * Checks if the hunk exactly fits on the provided location
  1027. */
  1028. function hunkFits(hunk, toPos) {
  1029. for (var j = 0; j < hunk.lines.length; j++) {
  1030. var line = hunk.lines[j],
  1031. operation = line[0],
  1032. content = line.substr(1);
  1033. if (operation === ' ' || operation === '-') {
  1034. // Context sanity check
  1035. if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
  1036. errorCount++;
  1037. if (errorCount > fuzzFactor) {
  1038. return false;
  1039. }
  1040. }
  1041. toPos++;
  1042. }
  1043. }
  1044. return true;
  1045. } // Search best fit offsets for each hunk based on the previous ones
  1046. for (var i = 0; i < hunks.length; i++) {
  1047. var hunk = hunks[i],
  1048. maxLine = lines.length - hunk.oldLines,
  1049. localOffset = 0,
  1050. toPos = offset + hunk.oldStart - 1;
  1051. var iterator =
  1052. /*istanbul ignore start*/
  1053. (0, _distanceIterator2['default']
  1054. /*istanbul ignore end*/
  1055. )(toPos, minLine, maxLine);
  1056. for (; localOffset !== undefined; localOffset = iterator()) {
  1057. if (hunkFits(hunk, toPos + localOffset)) {
  1058. hunk.offset = offset += localOffset;
  1059. break;
  1060. }
  1061. }
  1062. if (localOffset === undefined) {
  1063. return false;
  1064. } // Set lower text limit to end of the current hunk, so next ones don't try
  1065. // to fit over already patched text
  1066. minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
  1067. } // Apply patch hunks
  1068. for (var _i = 0; _i < hunks.length; _i++) {
  1069. var _hunk = hunks[_i],
  1070. _toPos = _hunk.offset + _hunk.newStart - 1;
  1071. if (_hunk.newLines == 0) {
  1072. _toPos++;
  1073. }
  1074. for (var j = 0; j < _hunk.lines.length; j++) {
  1075. var line = _hunk.lines[j],
  1076. operation = line[0],
  1077. content = line.substr(1),
  1078. delimiter = _hunk.linedelimiters[j];
  1079. if (operation === ' ') {
  1080. _toPos++;
  1081. } else if (operation === '-') {
  1082. lines.splice(_toPos, 1);
  1083. delimiters.splice(_toPos, 1);
  1084. /* istanbul ignore else */
  1085. } else if (operation === '+') {
  1086. lines.splice(_toPos, 0, content);
  1087. delimiters.splice(_toPos, 0, delimiter);
  1088. _toPos++;
  1089. } else if (operation === '\\') {
  1090. var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
  1091. if (previousOperation === '+') {
  1092. removeEOFNL = true;
  1093. } else if (previousOperation === '-') {
  1094. addEOFNL = true;
  1095. }
  1096. }
  1097. }
  1098. } // Handle EOFNL insertion/removal
  1099. if (removeEOFNL) {
  1100. while (!lines[lines.length - 1]) {
  1101. lines.pop();
  1102. delimiters.pop();
  1103. }
  1104. } else if (addEOFNL) {
  1105. lines.push('');
  1106. delimiters.push('\n');
  1107. }
  1108. for (var _k = 0; _k < lines.length - 1; _k++) {
  1109. lines[_k] = lines[_k] + delimiters[_k];
  1110. }
  1111. return lines.join('');
  1112. } // Wrapper that supports multiple file patches via callbacks.
  1113. function applyPatches(uniDiff, options) {
  1114. if (typeof uniDiff === 'string') {
  1115. uniDiff =
  1116. /*istanbul ignore start*/
  1117. (0, parse.parsePatch
  1118. /*istanbul ignore end*/
  1119. )(uniDiff);
  1120. }
  1121. var currentIndex = 0;
  1122. function processIndex() {
  1123. var index = uniDiff[currentIndex++];
  1124. if (!index) {
  1125. return options.complete();
  1126. }
  1127. options.loadFile(index, function (err, data) {
  1128. if (err) {
  1129. return options.complete(err);
  1130. }
  1131. var updatedContent = applyPatch(data, index, options);
  1132. options.patched(index, updatedContent, function (err) {
  1133. if (err) {
  1134. return options.complete(err);
  1135. }
  1136. processIndex();
  1137. });
  1138. });
  1139. }
  1140. processIndex();
  1141. }
  1142. });
  1143. unwrapExports(apply);
  1144. var create = createCommonjsModule(function (module, exports) {
  1145. /*istanbul ignore start*/
  1146. 'use strict';
  1147. exports.__esModule = true;
  1148. exports.
  1149. /*istanbul ignore end*/
  1150. structuredPatch = structuredPatch;
  1151. /*istanbul ignore start*/
  1152. exports.
  1153. /*istanbul ignore end*/
  1154. createTwoFilesPatch = createTwoFilesPatch;
  1155. /*istanbul ignore start*/
  1156. exports.
  1157. /*istanbul ignore end*/
  1158. createPatch = createPatch;
  1159. /*istanbul ignore start*/
  1160. function _toConsumableArray(arr) {
  1161. if (Array.isArray(arr)) {
  1162. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
  1163. arr2[i] = arr[i];
  1164. }
  1165. return arr2;
  1166. } else {
  1167. return Array.from(arr);
  1168. }
  1169. }
  1170. /*istanbul ignore end*/
  1171. function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  1172. if (!options) {
  1173. options = {};
  1174. }
  1175. if (typeof options.context === 'undefined') {
  1176. options.context = 4;
  1177. }
  1178. var diff =
  1179. /*istanbul ignore start*/
  1180. (0, line.diffLines
  1181. /*istanbul ignore end*/
  1182. )(oldStr, newStr, options);
  1183. diff.push({
  1184. value: '',
  1185. lines: []
  1186. }); // Append an empty value to make cleanup easier
  1187. function contextLines(lines) {
  1188. return lines.map(function (entry) {
  1189. return ' ' + entry;
  1190. });
  1191. }
  1192. var hunks = [];
  1193. var oldRangeStart = 0,
  1194. newRangeStart = 0,
  1195. curRange = [],
  1196. oldLine = 1,
  1197. newLine = 1;
  1198. /*istanbul ignore start*/
  1199. var _loop = function _loop(
  1200. /*istanbul ignore end*/
  1201. i) {
  1202. var current = diff[i],
  1203. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  1204. current.lines = lines;
  1205. if (current.added || current.removed) {
  1206. /*istanbul ignore start*/
  1207. var _curRange;
  1208. /*istanbul ignore end*/
  1209. // If we have previous context, start with that
  1210. if (!oldRangeStart) {
  1211. var prev = diff[i - 1];
  1212. oldRangeStart = oldLine;
  1213. newRangeStart = newLine;
  1214. if (prev) {
  1215. curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
  1216. oldRangeStart -= curRange.length;
  1217. newRangeStart -= curRange.length;
  1218. }
  1219. } // Output our changes
  1220. /*istanbul ignore start*/
  1221. (_curRange =
  1222. /*istanbul ignore end*/
  1223. curRange).push.
  1224. /*istanbul ignore start*/
  1225. apply
  1226. /*istanbul ignore end*/
  1227. (
  1228. /*istanbul ignore start*/
  1229. _curRange
  1230. /*istanbul ignore end*/
  1231. ,
  1232. /*istanbul ignore start*/
  1233. _toConsumableArray(
  1234. /*istanbul ignore end*/
  1235. lines.map(function (entry) {
  1236. return (current.added ? '+' : '-') + entry;
  1237. }))); // Track the updated file position
  1238. if (current.added) {
  1239. newLine += lines.length;
  1240. } else {
  1241. oldLine += lines.length;
  1242. }
  1243. } else {
  1244. // Identical context lines. Track line changes
  1245. if (oldRangeStart) {
  1246. // Close out any changes that have been output (or join overlapping)
  1247. if (lines.length <= options.context * 2 && i < diff.length - 2) {
  1248. /*istanbul ignore start*/
  1249. var _curRange2;
  1250. /*istanbul ignore end*/
  1251. // Overlapping
  1252. /*istanbul ignore start*/
  1253. (_curRange2 =
  1254. /*istanbul ignore end*/
  1255. curRange).push.
  1256. /*istanbul ignore start*/
  1257. apply
  1258. /*istanbul ignore end*/
  1259. (
  1260. /*istanbul ignore start*/
  1261. _curRange2
  1262. /*istanbul ignore end*/
  1263. ,
  1264. /*istanbul ignore start*/
  1265. _toConsumableArray(
  1266. /*istanbul ignore end*/
  1267. contextLines(lines)));
  1268. } else {
  1269. /*istanbul ignore start*/
  1270. var _curRange3;
  1271. /*istanbul ignore end*/
  1272. // end the range and output
  1273. var contextSize = Math.min(lines.length, options.context);
  1274. /*istanbul ignore start*/
  1275. (_curRange3 =
  1276. /*istanbul ignore end*/
  1277. curRange).push.
  1278. /*istanbul ignore start*/
  1279. apply
  1280. /*istanbul ignore end*/
  1281. (
  1282. /*istanbul ignore start*/
  1283. _curRange3
  1284. /*istanbul ignore end*/
  1285. ,
  1286. /*istanbul ignore start*/
  1287. _toConsumableArray(
  1288. /*istanbul ignore end*/
  1289. contextLines(lines.slice(0, contextSize))));
  1290. var hunk = {
  1291. oldStart: oldRangeStart,
  1292. oldLines: oldLine - oldRangeStart + contextSize,
  1293. newStart: newRangeStart,
  1294. newLines: newLine - newRangeStart + contextSize,
  1295. lines: curRange
  1296. };
  1297. if (i >= diff.length - 2 && lines.length <= options.context) {
  1298. // EOF is inside this hunk
  1299. var oldEOFNewline = /\n$/.test(oldStr);
  1300. var newEOFNewline = /\n$/.test(newStr);
  1301. if (lines.length == 0 && !oldEOFNewline) {
  1302. // special case: old has no eol and no trailing context; no-nl can end up before adds
  1303. curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
  1304. } else if (!oldEOFNewline || !newEOFNewline) {
  1305. curRange.push('\\ No newline at end of file');
  1306. }
  1307. }
  1308. hunks.push(hunk);
  1309. oldRangeStart = 0;
  1310. newRangeStart = 0;
  1311. curRange = [];
  1312. }
  1313. }
  1314. oldLine += lines.length;
  1315. newLine += lines.length;
  1316. }
  1317. };
  1318. for (var i = 0; i < diff.length; i++) {
  1319. /*istanbul ignore start*/
  1320. _loop(
  1321. /*istanbul ignore end*/
  1322. i);
  1323. }
  1324. return {
  1325. oldFileName: oldFileName,
  1326. newFileName: newFileName,
  1327. oldHeader: oldHeader,
  1328. newHeader: newHeader,
  1329. hunks: hunks
  1330. };
  1331. }
  1332. function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  1333. var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
  1334. var ret = [];
  1335. if (oldFileName == newFileName) {
  1336. ret.push('Index: ' + oldFileName);
  1337. }
  1338. ret.push('===================================================================');
  1339. ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
  1340. ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
  1341. for (var i = 0; i < diff.hunks.length; i++) {
  1342. var hunk = diff.hunks[i];
  1343. ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
  1344. ret.push.apply(ret, hunk.lines);
  1345. }
  1346. return ret.join('\n') + '\n';
  1347. }
  1348. function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
  1349. return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
  1350. }
  1351. });
  1352. unwrapExports(create);
  1353. var dmp = createCommonjsModule(function (module, exports) {
  1354. /*istanbul ignore start*/
  1355. "use strict";
  1356. exports.__esModule = true;
  1357. exports.
  1358. /*istanbul ignore end*/
  1359. convertChangesToDMP = convertChangesToDMP; // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  1360. function convertChangesToDMP(changes) {
  1361. var ret = [],
  1362. change =
  1363. /*istanbul ignore start*/
  1364. void 0
  1365. /*istanbul ignore end*/
  1366. ,
  1367. operation =
  1368. /*istanbul ignore start*/
  1369. void 0;
  1370. for (var i = 0; i < changes.length; i++) {
  1371. change = changes[i];
  1372. if (change.added) {
  1373. operation = 1;
  1374. } else if (change.removed) {
  1375. operation = -1;
  1376. } else {
  1377. operation = 0;
  1378. }
  1379. ret.push([operation, change.value]);
  1380. }
  1381. return ret;
  1382. }
  1383. });
  1384. unwrapExports(dmp);
  1385. var xml = createCommonjsModule(function (module, exports) {
  1386. /*istanbul ignore start*/
  1387. 'use strict';
  1388. exports.__esModule = true;
  1389. exports.
  1390. /*istanbul ignore end*/
  1391. convertChangesToXML = convertChangesToXML;
  1392. function convertChangesToXML(changes) {
  1393. var ret = [];
  1394. for (var i = 0; i < changes.length; i++) {
  1395. var change = changes[i];
  1396. if (change.added) {
  1397. ret.push('<ins>');
  1398. } else if (change.removed) {
  1399. ret.push('<del>');
  1400. }
  1401. ret.push(escapeHTML(change.value));
  1402. if (change.added) {
  1403. ret.push('</ins>');
  1404. } else if (change.removed) {
  1405. ret.push('</del>');
  1406. }
  1407. }
  1408. return ret.join('');
  1409. }
  1410. function escapeHTML(s) {
  1411. var n = s;
  1412. n = n.replace(/&/g, '&amp;');
  1413. n = n.replace(/</g, '&lt;');
  1414. n = n.replace(/>/g, '&gt;');
  1415. n = n.replace(/"/g, '&quot;');
  1416. return n;
  1417. }
  1418. });
  1419. unwrapExports(xml);
  1420. var lib = createCommonjsModule(function (module, exports) {
  1421. /*istanbul ignore start*/
  1422. 'use strict';
  1423. exports.__esModule = true;
  1424. 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;
  1425. /*istanbul ignore end*/
  1426. /*istanbul ignore start*/
  1427. var _base2 = _interopRequireDefault(base);
  1428. /*istanbul ignore end*/
  1429. /*istanbul ignore start*/
  1430. function _interopRequireDefault(obj) {
  1431. return obj && obj.__esModule ? obj : {
  1432. 'default': obj
  1433. };
  1434. }
  1435. exports.
  1436. /*istanbul ignore end*/
  1437. Diff = _base2['default'];
  1438. /*istanbul ignore start*/
  1439. exports.
  1440. /*istanbul ignore end*/
  1441. diffChars = character.diffChars;
  1442. /*istanbul ignore start*/
  1443. exports.
  1444. /*istanbul ignore end*/
  1445. diffWords = word.diffWords;
  1446. /*istanbul ignore start*/
  1447. exports.
  1448. /*istanbul ignore end*/
  1449. diffWordsWithSpace = word.diffWordsWithSpace;
  1450. /*istanbul ignore start*/
  1451. exports.
  1452. /*istanbul ignore end*/
  1453. diffLines = line.diffLines;
  1454. /*istanbul ignore start*/
  1455. exports.
  1456. /*istanbul ignore end*/
  1457. diffTrimmedLines = line.diffTrimmedLines;
  1458. /*istanbul ignore start*/
  1459. exports.
  1460. /*istanbul ignore end*/
  1461. diffSentences = sentence.diffSentences;
  1462. /*istanbul ignore start*/
  1463. exports.
  1464. /*istanbul ignore end*/
  1465. diffCss = css.diffCss;
  1466. /*istanbul ignore start*/
  1467. exports.
  1468. /*istanbul ignore end*/
  1469. diffJson = json.diffJson;
  1470. /*istanbul ignore start*/
  1471. exports.
  1472. /*istanbul ignore end*/
  1473. diffArrays = array.diffArrays;
  1474. /*istanbul ignore start*/
  1475. exports.
  1476. /*istanbul ignore end*/
  1477. structuredPatch = create.structuredPatch;
  1478. /*istanbul ignore start*/
  1479. exports.
  1480. /*istanbul ignore end*/
  1481. createTwoFilesPatch = create.createTwoFilesPatch;
  1482. /*istanbul ignore start*/
  1483. exports.
  1484. /*istanbul ignore end*/
  1485. createPatch = create.createPatch;
  1486. /*istanbul ignore start*/
  1487. exports.
  1488. /*istanbul ignore end*/
  1489. applyPatch = apply.applyPatch;
  1490. /*istanbul ignore start*/
  1491. exports.
  1492. /*istanbul ignore end*/
  1493. applyPatches = apply.applyPatches;
  1494. /*istanbul ignore start*/
  1495. exports.
  1496. /*istanbul ignore end*/
  1497. parsePatch = parse.parsePatch;
  1498. /*istanbul ignore start*/
  1499. exports.
  1500. /*istanbul ignore end*/
  1501. convertChangesToDMP = dmp.convertChangesToDMP;
  1502. /*istanbul ignore start*/
  1503. exports.
  1504. /*istanbul ignore end*/
  1505. convertChangesToXML = xml.convertChangesToXML;
  1506. /*istanbul ignore start*/
  1507. exports.
  1508. /*istanbul ignore end*/
  1509. canonicalize = json.canonicalize;
  1510. /* See LICENSE file for terms of use */
  1511. /*
  1512. * Text diff implementation.
  1513. *
  1514. * This library supports the following APIS:
  1515. * JsDiff.diffChars: Character by character diff
  1516. * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace
  1517. * JsDiff.diffLines: Line based diff
  1518. *
  1519. * JsDiff.diffCss: Diff targeted at CSS content
  1520. *
  1521. * These methods are based on the implementation proposed in
  1522. * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).
  1523. * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927
  1524. */
  1525. });
  1526. unwrapExports(lib);
  1527. function _classCallCheck(instance, Constructor) {
  1528. if (!(instance instanceof Constructor)) {
  1529. throw new TypeError("Cannot call a class as a function");
  1530. }
  1531. }
  1532. function _inherits(subClass, superClass) {
  1533. if (typeof superClass !== "function" && superClass !== null) {
  1534. throw new TypeError("Super expression must either be null or a function");
  1535. }
  1536. subClass.prototype = Object.create(superClass && superClass.prototype, {
  1537. constructor: {
  1538. value: subClass,
  1539. writable: true,
  1540. configurable: true
  1541. }
  1542. });
  1543. if (superClass) _setPrototypeOf(subClass, superClass);
  1544. }
  1545. function _getPrototypeOf(o) {
  1546. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  1547. return o.__proto__ || Object.getPrototypeOf(o);
  1548. };
  1549. return _getPrototypeOf(o);
  1550. }
  1551. function _setPrototypeOf(o, p) {
  1552. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1553. o.__proto__ = p;
  1554. return o;
  1555. };
  1556. return _setPrototypeOf(o, p);
  1557. }
  1558. function isNativeReflectConstruct() {
  1559. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  1560. if (Reflect.construct.sham) return false;
  1561. if (typeof Proxy === "function") return true;
  1562. try {
  1563. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  1564. return true;
  1565. } catch (e) {
  1566. return false;
  1567. }
  1568. }
  1569. function _construct(Parent, args, Class) {
  1570. if (isNativeReflectConstruct()) {
  1571. _construct = Reflect.construct;
  1572. } else {
  1573. _construct = function _construct(Parent, args, Class) {
  1574. var a = [null];
  1575. a.push.apply(a, args);
  1576. var Constructor = Function.bind.apply(Parent, a);
  1577. var instance = new Constructor();
  1578. if (Class) _setPrototypeOf(instance, Class.prototype);
  1579. return instance;
  1580. };
  1581. }
  1582. return _construct.apply(null, arguments);
  1583. }
  1584. function _wrapNativeSuper(Class) {
  1585. var _cache = typeof Map === "function" ? new Map() : undefined;
  1586. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  1587. if (Class === null) return null;
  1588. if (typeof Class !== "function") {
  1589. throw new TypeError("Super expression must either be null or a function");
  1590. }
  1591. if (typeof _cache !== "undefined") {
  1592. if (_cache.has(Class)) return _cache.get(Class);
  1593. _cache.set(Class, Wrapper);
  1594. }
  1595. function Wrapper() {
  1596. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  1597. }
  1598. Wrapper.prototype = Object.create(Class.prototype, {
  1599. constructor: {
  1600. value: Wrapper,
  1601. enumerable: false,
  1602. writable: true,
  1603. configurable: true
  1604. }
  1605. });
  1606. return _setPrototypeOf(Wrapper, Class);
  1607. };
  1608. return _wrapNativeSuper(Class);
  1609. }
  1610. function _assertThisInitialized(self) {
  1611. if (self === void 0) {
  1612. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1613. }
  1614. return self;
  1615. }
  1616. function _possibleConstructorReturn(self, call) {
  1617. if (call && (typeof call === "object" || typeof call === "function")) {
  1618. return call;
  1619. }
  1620. return _assertThisInitialized(self);
  1621. }
  1622. function _slicedToArray(arr, i) {
  1623. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
  1624. }
  1625. function _arrayWithHoles(arr) {
  1626. if (Array.isArray(arr)) return arr;
  1627. }
  1628. function _iterableToArrayLimit(arr, i) {
  1629. var _arr = [];
  1630. var _n = true;
  1631. var _d = false;
  1632. var _e = undefined;
  1633. try {
  1634. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  1635. _arr.push(_s.value);
  1636. if (i && _arr.length === i) break;
  1637. }
  1638. } catch (err) {
  1639. _d = true;
  1640. _e = err;
  1641. } finally {
  1642. try {
  1643. if (!_n && _i["return"] != null) _i["return"]();
  1644. } finally {
  1645. if (_d) throw _e;
  1646. }
  1647. }
  1648. return _arr;
  1649. }
  1650. function _nonIterableRest() {
  1651. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  1652. }
  1653. var ConfigError =
  1654. /*#__PURE__*/
  1655. function (_Error) {
  1656. _inherits(ConfigError, _Error);
  1657. function ConfigError() {
  1658. _classCallCheck(this, ConfigError);
  1659. return _possibleConstructorReturn(this, _getPrototypeOf(ConfigError).apply(this, arguments));
  1660. }
  1661. return ConfigError;
  1662. }(_wrapNativeSuper(Error));
  1663. var DebugError =
  1664. /*#__PURE__*/
  1665. function (_Error2) {
  1666. _inherits(DebugError, _Error2);
  1667. function DebugError() {
  1668. _classCallCheck(this, DebugError);
  1669. return _possibleConstructorReturn(this, _getPrototypeOf(DebugError).apply(this, arguments));
  1670. }
  1671. return DebugError;
  1672. }(_wrapNativeSuper(Error));
  1673. var UndefinedParserError$1 =
  1674. /*#__PURE__*/
  1675. function (_Error3) {
  1676. _inherits(UndefinedParserError, _Error3);
  1677. function UndefinedParserError() {
  1678. _classCallCheck(this, UndefinedParserError);
  1679. return _possibleConstructorReturn(this, _getPrototypeOf(UndefinedParserError).apply(this, arguments));
  1680. }
  1681. return UndefinedParserError;
  1682. }(_wrapNativeSuper(Error));
  1683. var errors = {
  1684. ConfigError,
  1685. DebugError,
  1686. UndefinedParserError: UndefinedParserError$1
  1687. };
  1688. var semver = createCommonjsModule(function (module, exports) {
  1689. exports = module.exports = SemVer; // The debug function is excluded entirely from the minified version.
  1690. /* nomin */
  1691. var debug;
  1692. /* nomin */
  1693. if (typeof process === 'object' &&
  1694. /* nomin */
  1695. process.env &&
  1696. /* nomin */
  1697. process.env.NODE_DEBUG &&
  1698. /* nomin */
  1699. /\bsemver\b/i.test(process.env.NODE_DEBUG))
  1700. /* nomin */
  1701. debug = function debug() {
  1702. /* nomin */
  1703. var args = Array.prototype.slice.call(arguments, 0);
  1704. /* nomin */
  1705. args.unshift('SEMVER');
  1706. /* nomin */
  1707. console.log.apply(console, args);
  1708. /* nomin */
  1709. };
  1710. /* nomin */
  1711. else
  1712. /* nomin */
  1713. debug = function debug() {}; // Note: this is the semver.org version of the spec that it implements
  1714. // Not necessarily the package version of this code.
  1715. exports.SEMVER_SPEC_VERSION = '2.0.0';
  1716. var MAX_LENGTH = 256;
  1717. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // The actual regexps go on exports.re
  1718. var re = exports.re = [];
  1719. var src = exports.src = [];
  1720. var R = 0; // The following Regular Expressions can be used for tokenizing,
  1721. // validating, and parsing SemVer version strings.
  1722. // ## Numeric Identifier
  1723. // A single `0`, or a non-zero digit followed by zero or more digits.
  1724. var NUMERICIDENTIFIER = R++;
  1725. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  1726. var NUMERICIDENTIFIERLOOSE = R++;
  1727. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
  1728. // Zero or more digits, followed by a letter or hyphen, and then zero or
  1729. // more letters, digits, or hyphens.
  1730. var NONNUMERICIDENTIFIER = R++;
  1731. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
  1732. // Three dot-separated numeric identifiers.
  1733. var MAINVERSION = R++;
  1734. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')';
  1735. var MAINVERSIONLOOSE = R++;
  1736. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
  1737. // A numeric identifier, or a non-numeric identifier.
  1738. var PRERELEASEIDENTIFIER = R++;
  1739. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + '|' + src[NONNUMERICIDENTIFIER] + ')';
  1740. var PRERELEASEIDENTIFIERLOOSE = R++;
  1741. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + '|' + src[NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
  1742. // Hyphen, followed by one or more dot-separated pre-release version
  1743. // identifiers.
  1744. var PRERELEASE = R++;
  1745. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  1746. var PRERELEASELOOSE = R++;
  1747. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
  1748. // Any combination of digits, letters, or hyphens.
  1749. var BUILDIDENTIFIER = R++;
  1750. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
  1751. // Plus sign, followed by one or more period-separated build metadata
  1752. // identifiers.
  1753. var BUILD = R++;
  1754. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'; // ## Full Version String
  1755. // A main version, followed optionally by a pre-release version and
  1756. // build metadata.
  1757. // Note that the only major, minor, patch, and pre-release sections of
  1758. // the version string are capturing groups. The build metadata is not a
  1759. // capturing group, because it should not ever be used in version
  1760. // comparison.
  1761. var FULL = R++;
  1762. var FULLPLAIN = 'v?' + src[MAINVERSION] + src[PRERELEASE] + '?' + src[BUILD] + '?';
  1763. src[FULL] = '^' + FULLPLAIN + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  1764. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  1765. // common in the npm registry.
  1766. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + src[PRERELEASELOOSE] + '?' + src[BUILD] + '?';
  1767. var LOOSE = R++;
  1768. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  1769. var GTLT = R++;
  1770. src[GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
  1771. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  1772. // Only the first item is strictly required.
  1773. var XRANGEIDENTIFIERLOOSE = R++;
  1774. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  1775. var XRANGEIDENTIFIER = R++;
  1776. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  1777. var XRANGEPLAIN = R++;
  1778. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:' + src[PRERELEASE] + ')?' + src[BUILD] + '?' + ')?)?';
  1779. var XRANGEPLAINLOOSE = R++;
  1780. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[PRERELEASELOOSE] + ')?' + src[BUILD] + '?' + ')?)?';
  1781. var XRANGE = R++;
  1782. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  1783. var XRANGELOOSE = R++;
  1784. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'; // Tilde ranges.
  1785. // Meaning is "reasonably at or greater than"
  1786. var LONETILDE = R++;
  1787. src[LONETILDE] = '(?:~>?)';
  1788. var TILDETRIM = R++;
  1789. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  1790. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  1791. var tildeTrimReplace = '$1~';
  1792. var TILDE = R++;
  1793. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  1794. var TILDELOOSE = R++;
  1795. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'; // Caret ranges.
  1796. // Meaning is "at least and backwards compatible with"
  1797. var LONECARET = R++;
  1798. src[LONECARET] = '(?:\\^)';
  1799. var CARETTRIM = R++;
  1800. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  1801. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  1802. var caretTrimReplace = '$1^';
  1803. var CARET = R++;
  1804. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  1805. var CARETLOOSE = R++;
  1806. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
  1807. var COMPARATORLOOSE = R++;
  1808. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  1809. var COMPARATOR = R++;
  1810. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
  1811. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  1812. var COMPARATORTRIM = R++;
  1813. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'; // this one has to use the /g flag
  1814. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  1815. var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  1816. // Note that these all use the loose form, because they'll be
  1817. // checked against either the strict or loose comparator form
  1818. // later.
  1819. var HYPHENRANGE = R++;
  1820. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAIN] + ')' + '\\s*$';
  1821. var HYPHENRANGELOOSE = R++;
  1822. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
  1823. var STAR = R++;
  1824. src[STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
  1825. // All are flag-free, unless they were created above with a flag.
  1826. for (var i = 0; i < R; i++) {
  1827. debug(i, src[i]);
  1828. if (!re[i]) re[i] = new RegExp(src[i]);
  1829. }
  1830. exports.parse = parse;
  1831. function parse(version, loose) {
  1832. if (version instanceof SemVer) return version;
  1833. if (typeof version !== 'string') return null;
  1834. if (version.length > MAX_LENGTH) return null;
  1835. var r = loose ? re[LOOSE] : re[FULL];
  1836. if (!r.test(version)) return null;
  1837. try {
  1838. return new SemVer(version, loose);
  1839. } catch (er) {
  1840. return null;
  1841. }
  1842. }
  1843. exports.valid = valid;
  1844. function valid(version, loose) {
  1845. var v = parse(version, loose);
  1846. return v ? v.version : null;
  1847. }
  1848. exports.clean = clean;
  1849. function clean(version, loose) {
  1850. var s = parse(version.trim().replace(/^[=v]+/, ''), loose);
  1851. return s ? s.version : null;
  1852. }
  1853. exports.SemVer = SemVer;
  1854. function SemVer(version, loose) {
  1855. if (version instanceof SemVer) {
  1856. if (version.loose === loose) return version;else version = version.version;
  1857. } else if (typeof version !== 'string') {
  1858. throw new TypeError('Invalid Version: ' + version);
  1859. }
  1860. if (version.length > MAX_LENGTH) throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
  1861. if (!(this instanceof SemVer)) return new SemVer(version, loose);
  1862. debug('SemVer', version, loose);
  1863. this.loose = loose;
  1864. var m = version.trim().match(loose ? re[LOOSE] : re[FULL]);
  1865. if (!m) throw new TypeError('Invalid Version: ' + version);
  1866. this.raw = version; // these are actually numbers
  1867. this.major = +m[1];
  1868. this.minor = +m[2];
  1869. this.patch = +m[3];
  1870. if (this.major > MAX_SAFE_INTEGER || this.major < 0) throw new TypeError('Invalid major version');
  1871. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) throw new TypeError('Invalid minor version');
  1872. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) throw new TypeError('Invalid patch version'); // numberify any prerelease numeric ids
  1873. if (!m[4]) this.prerelease = [];else this.prerelease = m[4].split('.').map(function (id) {
  1874. if (/^[0-9]+$/.test(id)) {
  1875. var num = +id;
  1876. if (num >= 0 && num < MAX_SAFE_INTEGER) return num;
  1877. }
  1878. return id;
  1879. });
  1880. this.build = m[5] ? m[5].split('.') : [];
  1881. this.format();
  1882. }
  1883. SemVer.prototype.format = function () {
  1884. this.version = this.major + '.' + this.minor + '.' + this.patch;
  1885. if (this.prerelease.length) this.version += '-' + this.prerelease.join('.');
  1886. return this.version;
  1887. };
  1888. SemVer.prototype.toString = function () {
  1889. return this.version;
  1890. };
  1891. SemVer.prototype.compare = function (other) {
  1892. debug('SemVer.compare', this.version, this.loose, other);
  1893. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose);
  1894. return this.compareMain(other) || this.comparePre(other);
  1895. };
  1896. SemVer.prototype.compareMain = function (other) {
  1897. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose);
  1898. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  1899. };
  1900. SemVer.prototype.comparePre = function (other) {
  1901. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose); // NOT having a prerelease is > having one
  1902. if (this.prerelease.length && !other.prerelease.length) return -1;else if (!this.prerelease.length && other.prerelease.length) return 1;else if (!this.prerelease.length && !other.prerelease.length) return 0;
  1903. var i = 0;
  1904. do {
  1905. var a = this.prerelease[i];
  1906. var b = other.prerelease[i];
  1907. debug('prerelease compare', i, a, b);
  1908. if (a === undefined && b === undefined) return 0;else if (b === undefined) return 1;else if (a === undefined) return -1;else if (a === b) continue;else return compareIdentifiers(a, b);
  1909. } while (++i);
  1910. }; // preminor will bump the version up to the next minor release, and immediately
  1911. // down to pre-release. premajor and prepatch work the same way.
  1912. SemVer.prototype.inc = function (release, identifier) {
  1913. switch (release) {
  1914. case 'premajor':
  1915. this.prerelease.length = 0;
  1916. this.patch = 0;
  1917. this.minor = 0;
  1918. this.major++;
  1919. this.inc('pre', identifier);
  1920. break;
  1921. case 'preminor':
  1922. this.prerelease.length = 0;
  1923. this.patch = 0;
  1924. this.minor++;
  1925. this.inc('pre', identifier);
  1926. break;
  1927. case 'prepatch':
  1928. // If this is already a prerelease, it will bump to the next version
  1929. // drop any prereleases that might already exist, since they are not
  1930. // relevant at this point.
  1931. this.prerelease.length = 0;
  1932. this.inc('patch', identifier);
  1933. this.inc('pre', identifier);
  1934. break;
  1935. // If the input is a non-prerelease version, this acts the same as
  1936. // prepatch.
  1937. case 'prerelease':
  1938. if (this.prerelease.length === 0) this.inc('patch', identifier);
  1939. this.inc('pre', identifier);
  1940. break;
  1941. case 'major':
  1942. // If this is a pre-major version, bump up to the same major version.
  1943. // Otherwise increment major.
  1944. // 1.0.0-5 bumps to 1.0.0
  1945. // 1.1.0 bumps to 2.0.0
  1946. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) this.major++;
  1947. this.minor = 0;
  1948. this.patch = 0;
  1949. this.prerelease = [];
  1950. break;
  1951. case 'minor':
  1952. // If this is a pre-minor version, bump up to the same minor version.
  1953. // Otherwise increment minor.
  1954. // 1.2.0-5 bumps to 1.2.0
  1955. // 1.2.1 bumps to 1.3.0
  1956. if (this.patch !== 0 || this.prerelease.length === 0) this.minor++;
  1957. this.patch = 0;
  1958. this.prerelease = [];
  1959. break;
  1960. case 'patch':
  1961. // If this is not a pre-release version, it will increment the patch.
  1962. // If it is a pre-release it will bump up to the same patch version.
  1963. // 1.2.0-5 patches to 1.2.0
  1964. // 1.2.0 patches to 1.2.1
  1965. if (this.prerelease.length === 0) this.patch++;
  1966. this.prerelease = [];
  1967. break;
  1968. // This probably shouldn't be used publicly.
  1969. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  1970. case 'pre':
  1971. if (this.prerelease.length === 0) this.prerelease = [0];else {
  1972. var i = this.prerelease.length;
  1973. while (--i >= 0) {
  1974. if (typeof this.prerelease[i] === 'number') {
  1975. this.prerelease[i]++;
  1976. i = -2;
  1977. }
  1978. }
  1979. if (i === -1) // didn't increment anything
  1980. this.prerelease.push(0);
  1981. }
  1982. if (identifier) {
  1983. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  1984. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  1985. if (this.prerelease[0] === identifier) {
  1986. if (isNaN(this.prerelease[1])) this.prerelease = [identifier, 0];
  1987. } else this.prerelease = [identifier, 0];
  1988. }
  1989. break;
  1990. default:
  1991. throw new Error('invalid increment argument: ' + release);
  1992. }
  1993. this.format();
  1994. this.raw = this.version;
  1995. return this;
  1996. };
  1997. exports.inc = inc;
  1998. function inc(version, release, loose, identifier) {
  1999. if (typeof loose === 'string') {
  2000. identifier = loose;
  2001. loose = undefined;
  2002. }
  2003. try {
  2004. return new SemVer(version, loose).inc(release, identifier).version;
  2005. } catch (er) {
  2006. return null;
  2007. }
  2008. }
  2009. exports.diff = diff;
  2010. function diff(version1, version2) {
  2011. if (eq(version1, version2)) {
  2012. return null;
  2013. } else {
  2014. var v1 = parse(version1);
  2015. var v2 = parse(version2);
  2016. if (v1.prerelease.length || v2.prerelease.length) {
  2017. for (var key in v1) {
  2018. if (key === 'major' || key === 'minor' || key === 'patch') {
  2019. if (v1[key] !== v2[key]) {
  2020. return 'pre' + key;
  2021. }
  2022. }
  2023. }
  2024. return 'prerelease';
  2025. }
  2026. for (var key in v1) {
  2027. if (key === 'major' || key === 'minor' || key === 'patch') {
  2028. if (v1[key] !== v2[key]) {
  2029. return key;
  2030. }
  2031. }
  2032. }
  2033. }
  2034. }
  2035. exports.compareIdentifiers = compareIdentifiers;
  2036. var numeric = /^[0-9]+$/;
  2037. function compareIdentifiers(a, b) {
  2038. var anum = numeric.test(a);
  2039. var bnum = numeric.test(b);
  2040. if (anum && bnum) {
  2041. a = +a;
  2042. b = +b;
  2043. }
  2044. return anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : a > b ? 1 : 0;
  2045. }
  2046. exports.rcompareIdentifiers = rcompareIdentifiers;
  2047. function rcompareIdentifiers(a, b) {
  2048. return compareIdentifiers(b, a);
  2049. }
  2050. exports.major = major;
  2051. function major(a, loose) {
  2052. return new SemVer(a, loose).major;
  2053. }
  2054. exports.minor = minor;
  2055. function minor(a, loose) {
  2056. return new SemVer(a, loose).minor;
  2057. }
  2058. exports.patch = patch;
  2059. function patch(a, loose) {
  2060. return new SemVer(a, loose).patch;
  2061. }
  2062. exports.compare = compare;
  2063. function compare(a, b, loose) {
  2064. return new SemVer(a, loose).compare(new SemVer(b, loose));
  2065. }
  2066. exports.compareLoose = compareLoose;
  2067. function compareLoose(a, b) {
  2068. return compare(a, b, true);
  2069. }
  2070. exports.rcompare = rcompare;
  2071. function rcompare(a, b, loose) {
  2072. return compare(b, a, loose);
  2073. }
  2074. exports.sort = sort;
  2075. function sort(list, loose) {
  2076. return list.sort(function (a, b) {
  2077. return exports.compare(a, b, loose);
  2078. });
  2079. }
  2080. exports.rsort = rsort;
  2081. function rsort(list, loose) {
  2082. return list.sort(function (a, b) {
  2083. return exports.rcompare(a, b, loose);
  2084. });
  2085. }
  2086. exports.gt = gt;
  2087. function gt(a, b, loose) {
  2088. return compare(a, b, loose) > 0;
  2089. }
  2090. exports.lt = lt;
  2091. function lt(a, b, loose) {
  2092. return compare(a, b, loose) < 0;
  2093. }
  2094. exports.eq = eq;
  2095. function eq(a, b, loose) {
  2096. return compare(a, b, loose) === 0;
  2097. }
  2098. exports.neq = neq;
  2099. function neq(a, b, loose) {
  2100. return compare(a, b, loose) !== 0;
  2101. }
  2102. exports.gte = gte;
  2103. function gte(a, b, loose) {
  2104. return compare(a, b, loose) >= 0;
  2105. }
  2106. exports.lte = lte;
  2107. function lte(a, b, loose) {
  2108. return compare(a, b, loose) <= 0;
  2109. }
  2110. exports.cmp = cmp;
  2111. function cmp(a, op, b, loose) {
  2112. var ret;
  2113. switch (op) {
  2114. case '===':
  2115. if (typeof a === 'object') a = a.version;
  2116. if (typeof b === 'object') b = b.version;
  2117. ret = a === b;
  2118. break;
  2119. case '!==':
  2120. if (typeof a === 'object') a = a.version;
  2121. if (typeof b === 'object') b = b.version;
  2122. ret = a !== b;
  2123. break;
  2124. case '':
  2125. case '=':
  2126. case '==':
  2127. ret = eq(a, b, loose);
  2128. break;
  2129. case '!=':
  2130. ret = neq(a, b, loose);
  2131. break;
  2132. case '>':
  2133. ret = gt(a, b, loose);
  2134. break;
  2135. case '>=':
  2136. ret = gte(a, b, loose);
  2137. break;
  2138. case '<':
  2139. ret = lt(a, b, loose);
  2140. break;
  2141. case '<=':
  2142. ret = lte(a, b, loose);
  2143. break;
  2144. default:
  2145. throw new TypeError('Invalid operator: ' + op);
  2146. }
  2147. return ret;
  2148. }
  2149. exports.Comparator = Comparator;
  2150. function Comparator(comp, loose) {
  2151. if (comp instanceof Comparator) {
  2152. if (comp.loose === loose) return comp;else comp = comp.value;
  2153. }
  2154. if (!(this instanceof Comparator)) return new Comparator(comp, loose);
  2155. debug('comparator', comp, loose);
  2156. this.loose = loose;
  2157. this.parse(comp);
  2158. if (this.semver === ANY) this.value = '';else this.value = this.operator + this.semver.version;
  2159. debug('comp', this);
  2160. }
  2161. var ANY = {};
  2162. Comparator.prototype.parse = function (comp) {
  2163. var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  2164. var m = comp.match(r);
  2165. if (!m) throw new TypeError('Invalid comparator: ' + comp);
  2166. this.operator = m[1];
  2167. if (this.operator === '=') this.operator = ''; // if it literally is just '>' or '' then allow anything.
  2168. if (!m[2]) this.semver = ANY;else this.semver = new SemVer(m[2], this.loose);
  2169. };
  2170. Comparator.prototype.toString = function () {
  2171. return this.value;
  2172. };
  2173. Comparator.prototype.test = function (version) {
  2174. debug('Comparator.test', version, this.loose);
  2175. if (this.semver === ANY) return true;
  2176. if (typeof version === 'string') version = new SemVer(version, this.loose);
  2177. return cmp(version, this.operator, this.semver, this.loose);
  2178. };
  2179. Comparator.prototype.intersects = function (comp, loose) {
  2180. if (!(comp instanceof Comparator)) {
  2181. throw new TypeError('a Comparator is required');
  2182. }
  2183. var rangeTmp;
  2184. if (this.operator === '') {
  2185. rangeTmp = new Range(comp.value, loose);
  2186. return satisfies(this.value, rangeTmp, loose);
  2187. } else if (comp.operator === '') {
  2188. rangeTmp = new Range(this.value, loose);
  2189. return satisfies(comp.semver, rangeTmp, loose);
  2190. }
  2191. var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
  2192. var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
  2193. var sameSemVer = this.semver.version === comp.semver.version;
  2194. var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
  2195. var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, loose) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
  2196. var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, loose) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
  2197. return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  2198. };
  2199. exports.Range = Range;
  2200. function Range(range, loose) {
  2201. if (range instanceof Range) {
  2202. if (range.loose === loose) {
  2203. return range;
  2204. } else {
  2205. return new Range(range.raw, loose);
  2206. }
  2207. }
  2208. if (range instanceof Comparator) {
  2209. return new Range(range.value, loose);
  2210. }
  2211. if (!(this instanceof Range)) return new Range(range, loose);
  2212. this.loose = loose; // First, split based on boolean or ||
  2213. this.raw = range;
  2214. this.set = range.split(/\s*\|\|\s*/).map(function (range) {
  2215. return this.parseRange(range.trim());
  2216. }, this).filter(function (c) {
  2217. // throw out any that are not relevant for whatever reason
  2218. return c.length;
  2219. });
  2220. if (!this.set.length) {
  2221. throw new TypeError('Invalid SemVer Range: ' + range);
  2222. }
  2223. this.format();
  2224. }
  2225. Range.prototype.format = function () {
  2226. this.range = this.set.map(function (comps) {
  2227. return comps.join(' ').trim();
  2228. }).join('||').trim();
  2229. return this.range;
  2230. };
  2231. Range.prototype.toString = function () {
  2232. return this.range;
  2233. };
  2234. Range.prototype.parseRange = function (range) {
  2235. var loose = this.loose;
  2236. range = range.trim();
  2237. debug('range', range, loose); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  2238. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  2239. range = range.replace(hr, hyphenReplace);
  2240. debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  2241. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  2242. debug('comparator trim', range, re[COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
  2243. range = range.replace(re[TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
  2244. range = range.replace(re[CARETTRIM], caretTrimReplace); // normalize spaces
  2245. range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
  2246. // ready to be split into comparators.
  2247. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  2248. var set = range.split(' ').map(function (comp) {
  2249. return parseComparator(comp, loose);
  2250. }).join(' ').split(/\s+/);
  2251. if (this.loose) {
  2252. // in loose mode, throw out any that are not valid comparators
  2253. set = set.filter(function (comp) {
  2254. return !!comp.match(compRe);
  2255. });
  2256. }
  2257. set = set.map(function (comp) {
  2258. return new Comparator(comp, loose);
  2259. });
  2260. return set;
  2261. };
  2262. Range.prototype.intersects = function (range, loose) {
  2263. if (!(range instanceof Range)) {
  2264. throw new TypeError('a Range is required');
  2265. }
  2266. return this.set.some(function (thisComparators) {
  2267. return thisComparators.every(function (thisComparator) {
  2268. return range.set.some(function (rangeComparators) {
  2269. return rangeComparators.every(function (rangeComparator) {
  2270. return thisComparator.intersects(rangeComparator, loose);
  2271. });
  2272. });
  2273. });
  2274. });
  2275. }; // Mostly just for testing and legacy API reasons
  2276. exports.toComparators = toComparators;
  2277. function toComparators(range, loose) {
  2278. return new Range(range, loose).set.map(function (comp) {
  2279. return comp.map(function (c) {
  2280. return c.value;
  2281. }).join(' ').trim().split(' ');
  2282. });
  2283. } // comprised of xranges, tildes, stars, and gtlt's at this point.
  2284. // already replaced the hyphen ranges
  2285. // turn into a set of JUST comparators.
  2286. function parseComparator(comp, loose) {
  2287. debug('comp', comp);
  2288. comp = replaceCarets(comp, loose);
  2289. debug('caret', comp);
  2290. comp = replaceTildes(comp, loose);
  2291. debug('tildes', comp);
  2292. comp = replaceXRanges(comp, loose);
  2293. debug('xrange', comp);
  2294. comp = replaceStars(comp, loose);
  2295. debug('stars', comp);
  2296. return comp;
  2297. }
  2298. function isX(id) {
  2299. return !id || id.toLowerCase() === 'x' || id === '*';
  2300. } // ~, ~> --> * (any, kinda silly)
  2301. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  2302. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  2303. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  2304. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  2305. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  2306. function replaceTildes(comp, loose) {
  2307. return comp.trim().split(/\s+/).map(function (comp) {
  2308. return replaceTilde(comp, loose);
  2309. }).join(' ');
  2310. }
  2311. function replaceTilde(comp, loose) {
  2312. var r = loose ? re[TILDELOOSE] : re[TILDE];
  2313. return comp.replace(r, function (_, M, m, p, pr) {
  2314. debug('tilde', comp, _, M, m, p, pr);
  2315. var ret;
  2316. if (isX(M)) ret = '';else if (isX(m)) ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';else if (isX(p)) // ~1.2 == >=1.2.0 <1.3.0
  2317. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else if (pr) {
  2318. debug('replaceTilde pr', pr);
  2319. if (pr.charAt(0) !== '-') pr = '-' + pr;
  2320. ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  2321. } else // ~1.2.3 == >=1.2.3 <1.3.0
  2322. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  2323. debug('tilde return', ret);
  2324. return ret;
  2325. });
  2326. } // ^ --> * (any, kinda silly)
  2327. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  2328. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  2329. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  2330. // ^1.2.3 --> >=1.2.3 <2.0.0
  2331. // ^1.2.0 --> >=1.2.0 <2.0.0
  2332. function replaceCarets(comp, loose) {
  2333. return comp.trim().split(/\s+/).map(function (comp) {
  2334. return replaceCaret(comp, loose);
  2335. }).join(' ');
  2336. }
  2337. function replaceCaret(comp, loose) {
  2338. debug('caret', comp, loose);
  2339. var r = loose ? re[CARETLOOSE] : re[CARET];
  2340. return comp.replace(r, function (_, M, m, p, pr) {
  2341. debug('caret', comp, _, M, m, p, pr);
  2342. var ret;
  2343. if (isX(M)) ret = '';else if (isX(m)) ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';else if (isX(p)) {
  2344. if (M === '0') ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  2345. } else if (pr) {
  2346. debug('replaceCaret pr', pr);
  2347. if (pr.charAt(0) !== '-') pr = '-' + pr;
  2348. if (M === '0') {
  2349. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  2350. } else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + (+M + 1) + '.0.0';
  2351. } else {
  2352. debug('no pr');
  2353. if (M === '0') {
  2354. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  2355. } else ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
  2356. }
  2357. debug('caret return', ret);
  2358. return ret;
  2359. });
  2360. }
  2361. function replaceXRanges(comp, loose) {
  2362. debug('replaceXRanges', comp, loose);
  2363. return comp.split(/\s+/).map(function (comp) {
  2364. return replaceXRange(comp, loose);
  2365. }).join(' ');
  2366. }
  2367. function replaceXRange(comp, loose) {
  2368. comp = comp.trim();
  2369. var r = loose ? re[XRANGELOOSE] : re[XRANGE];
  2370. return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
  2371. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  2372. var xM = isX(M);
  2373. var xm = xM || isX(m);
  2374. var xp = xm || isX(p);
  2375. var anyX = xp;
  2376. if (gtlt === '=' && anyX) gtlt = '';
  2377. if (xM) {
  2378. if (gtlt === '>' || gtlt === '<') {
  2379. // nothing is allowed
  2380. ret = '<0.0.0';
  2381. } else {
  2382. // nothing is forbidden
  2383. ret = '*';
  2384. }
  2385. } else if (gtlt && anyX) {
  2386. // replace X with 0
  2387. if (xm) m = 0;
  2388. if (xp) p = 0;
  2389. if (gtlt === '>') {
  2390. // >1 => >=2.0.0
  2391. // >1.2 => >=1.3.0
  2392. // >1.2.3 => >= 1.2.4
  2393. gtlt = '>=';
  2394. if (xm) {
  2395. M = +M + 1;
  2396. m = 0;
  2397. p = 0;
  2398. } else if (xp) {
  2399. m = +m + 1;
  2400. p = 0;
  2401. }
  2402. } else if (gtlt === '<=') {
  2403. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  2404. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  2405. gtlt = '<';
  2406. if (xm) M = +M + 1;else m = +m + 1;
  2407. }
  2408. ret = gtlt + M + '.' + m + '.' + p;
  2409. } else if (xm) {
  2410. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  2411. } else if (xp) {
  2412. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  2413. }
  2414. debug('xRange return', ret);
  2415. return ret;
  2416. });
  2417. } // Because * is AND-ed with everything else in the comparator,
  2418. // and '' means "any version", just remove the *s entirely.
  2419. function replaceStars(comp, loose) {
  2420. debug('replaceStars', comp, loose); // Looseness is ignored here. star is always as loose as it gets!
  2421. return comp.trim().replace(re[STAR], '');
  2422. } // This function is passed to string.replace(re[HYPHENRANGE])
  2423. // M, m, patch, prerelease, build
  2424. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  2425. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  2426. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  2427. function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
  2428. if (isX(fM)) from = '';else if (isX(fm)) from = '>=' + fM + '.0.0';else if (isX(fp)) from = '>=' + fM + '.' + fm + '.0';else from = '>=' + from;
  2429. if (isX(tM)) to = '';else if (isX(tm)) to = '<' + (+tM + 1) + '.0.0';else if (isX(tp)) to = '<' + tM + '.' + (+tm + 1) + '.0';else if (tpr) to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;else to = '<=' + to;
  2430. return (from + ' ' + to).trim();
  2431. } // if ANY of the sets match ALL of its comparators, then pass
  2432. Range.prototype.test = function (version) {
  2433. if (!version) return false;
  2434. if (typeof version === 'string') version = new SemVer(version, this.loose);
  2435. for (var i = 0; i < this.set.length; i++) {
  2436. if (testSet(this.set[i], version)) return true;
  2437. }
  2438. return false;
  2439. };
  2440. function testSet(set, version) {
  2441. for (var i = 0; i < set.length; i++) {
  2442. if (!set[i].test(version)) return false;
  2443. }
  2444. if (version.prerelease.length) {
  2445. // Find the set of versions that are allowed to have prereleases
  2446. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  2447. // That should allow `1.2.3-pr.2` to pass.
  2448. // However, `1.2.4-alpha.notready` should NOT be allowed,
  2449. // even though it's within the range set by the comparators.
  2450. for (var i = 0; i < set.length; i++) {
  2451. debug(set[i].semver);
  2452. if (set[i].semver === ANY) continue;
  2453. if (set[i].semver.prerelease.length > 0) {
  2454. var allowed = set[i].semver;
  2455. if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) return true;
  2456. }
  2457. } // Version has a -pre, but it's not one of the ones we like.
  2458. return false;
  2459. }
  2460. return true;
  2461. }
  2462. exports.satisfies = satisfies;
  2463. function satisfies(version, range, loose) {
  2464. try {
  2465. range = new Range(range, loose);
  2466. } catch (er) {
  2467. return false;
  2468. }
  2469. return range.test(version);
  2470. }
  2471. exports.maxSatisfying = maxSatisfying;
  2472. function maxSatisfying(versions, range, loose) {
  2473. var max = null;
  2474. var maxSV = null;
  2475. try {
  2476. var rangeObj = new Range(range, loose);
  2477. } catch (er) {
  2478. return null;
  2479. }
  2480. versions.forEach(function (v) {
  2481. if (rangeObj.test(v)) {
  2482. // satisfies(v, range, loose)
  2483. if (!max || maxSV.compare(v) === -1) {
  2484. // compare(max, v, true)
  2485. max = v;
  2486. maxSV = new SemVer(max, loose);
  2487. }
  2488. }
  2489. });
  2490. return max;
  2491. }
  2492. exports.minSatisfying = minSatisfying;
  2493. function minSatisfying(versions, range, loose) {
  2494. var min = null;
  2495. var minSV = null;
  2496. try {
  2497. var rangeObj = new Range(range, loose);
  2498. } catch (er) {
  2499. return null;
  2500. }
  2501. versions.forEach(function (v) {
  2502. if (rangeObj.test(v)) {
  2503. // satisfies(v, range, loose)
  2504. if (!min || minSV.compare(v) === 1) {
  2505. // compare(min, v, true)
  2506. min = v;
  2507. minSV = new SemVer(min, loose);
  2508. }
  2509. }
  2510. });
  2511. return min;
  2512. }
  2513. exports.validRange = validRange;
  2514. function validRange(range, loose) {
  2515. try {
  2516. // Return '*' instead of '' so that truthiness works.
  2517. // This will throw if it's invalid anyway
  2518. return new Range(range, loose).range || '*';
  2519. } catch (er) {
  2520. return null;
  2521. }
  2522. } // Determine if version is less than all the versions possible in the range
  2523. exports.ltr = ltr;
  2524. function ltr(version, range, loose) {
  2525. return outside(version, range, '<', loose);
  2526. } // Determine if version is greater than all the versions possible in the range.
  2527. exports.gtr = gtr;
  2528. function gtr(version, range, loose) {
  2529. return outside(version, range, '>', loose);
  2530. }
  2531. exports.outside = outside;
  2532. function outside(version, range, hilo, loose) {
  2533. version = new SemVer(version, loose);
  2534. range = new Range(range, loose);
  2535. var gtfn, ltefn, ltfn, comp, ecomp;
  2536. switch (hilo) {
  2537. case '>':
  2538. gtfn = gt;
  2539. ltefn = lte;
  2540. ltfn = lt;
  2541. comp = '>';
  2542. ecomp = '>=';
  2543. break;
  2544. case '<':
  2545. gtfn = lt;
  2546. ltefn = gte;
  2547. ltfn = gt;
  2548. comp = '<';
  2549. ecomp = '<=';
  2550. break;
  2551. default:
  2552. throw new TypeError('Must provide a hilo val of "<" or ">"');
  2553. } // If it satisifes the range it is not outside
  2554. if (satisfies(version, range, loose)) {
  2555. return false;
  2556. } // From now on, variable terms are as if we're in "gtr" mode.
  2557. // but note that everything is flipped for the "ltr" function.
  2558. for (var i = 0; i < range.set.length; ++i) {
  2559. var comparators = range.set[i];
  2560. var high = null;
  2561. var low = null;
  2562. comparators.forEach(function (comparator) {
  2563. if (comparator.semver === ANY) {
  2564. comparator = new Comparator('>=0.0.0');
  2565. }
  2566. high = high || comparator;
  2567. low = low || comparator;
  2568. if (gtfn(comparator.semver, high.semver, loose)) {
  2569. high = comparator;
  2570. } else if (ltfn(comparator.semver, low.semver, loose)) {
  2571. low = comparator;
  2572. }
  2573. }); // If the edge version comparator has a operator then our version
  2574. // isn't outside it
  2575. if (high.operator === comp || high.operator === ecomp) {
  2576. return false;
  2577. } // If the lowest version comparator has an operator and our version
  2578. // is less than it then it isn't higher than the range
  2579. if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
  2580. return false;
  2581. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  2582. return false;
  2583. }
  2584. }
  2585. return true;
  2586. }
  2587. exports.prerelease = prerelease;
  2588. function prerelease(version, loose) {
  2589. var parsed = parse(version, loose);
  2590. return parsed && parsed.prerelease.length ? parsed.prerelease : null;
  2591. }
  2592. exports.intersects = intersects;
  2593. function intersects(r1, r2, loose) {
  2594. r1 = new Range(r1, loose);
  2595. r2 = new Range(r2, loose);
  2596. return r1.intersects(r2);
  2597. }
  2598. });
  2599. var arrayify = function arrayify(object, keyName) {
  2600. return Object.keys(object).reduce(function (array, key) {
  2601. return array.concat(Object.assign({
  2602. [keyName]: key
  2603. }, object[key]));
  2604. }, []);
  2605. };
  2606. var dedent_1 = createCommonjsModule(function (module) {
  2607. "use strict";
  2608. function dedent(strings) {
  2609. var raw = void 0;
  2610. if (typeof strings === "string") {
  2611. // dedent can be used as a plain function
  2612. raw = [strings];
  2613. } else {
  2614. raw = strings.raw;
  2615. } // first, perform interpolation
  2616. var result = "";
  2617. for (var i = 0; i < raw.length; i++) {
  2618. result += raw[i]. // join lines when there is a suppressed newline
  2619. replace(/\\\n[ \t]*/g, ""). // handle escaped backticks
  2620. replace(/\\`/g, "`");
  2621. if (i < (arguments.length <= 1 ? 0 : arguments.length - 1)) {
  2622. result += arguments.length <= i + 1 ? undefined : arguments[i + 1];
  2623. }
  2624. } // now strip indentation
  2625. var lines = result.split("\n");
  2626. var mindent = null;
  2627. lines.forEach(function (l) {
  2628. var m = l.match(/^(\s+)\S+/);
  2629. if (m) {
  2630. var indent = m[1].length;
  2631. if (!mindent) {
  2632. // this is the first indented line
  2633. mindent = indent;
  2634. } else {
  2635. mindent = Math.min(mindent, indent);
  2636. }
  2637. }
  2638. });
  2639. if (mindent !== null) {
  2640. result = lines.map(function (l) {
  2641. return l[0] === " " ? l.slice(mindent) : l;
  2642. }).join("\n");
  2643. } // dedent eats leading and trailing whitespace too
  2644. result = result.trim(); // handle escaped newlines at the end to ensure they don't get stripped too
  2645. return result.replace(/\\n/g, "\n");
  2646. }
  2647. {
  2648. module.exports = dedent;
  2649. }
  2650. });
  2651. var CATEGORY_CONFIG = "Config";
  2652. var CATEGORY_EDITOR = "Editor";
  2653. var CATEGORY_FORMAT = "Format";
  2654. var CATEGORY_OTHER = "Other";
  2655. var CATEGORY_OUTPUT = "Output";
  2656. var CATEGORY_GLOBAL = "Global";
  2657. var CATEGORY_SPECIAL = "Special";
  2658. /**
  2659. * @typedef {Object} OptionInfo
  2660. * @property {string} since - available since version
  2661. * @property {string} category
  2662. * @property {'int' | 'boolean' | 'choice' | 'path'} type
  2663. * @property {boolean} array - indicate it's an array of the specified type
  2664. * @property {boolean?} deprecated - deprecated since version
  2665. * @property {OptionRedirectInfo?} redirect - redirect deprecated option
  2666. * @property {string} description
  2667. * @property {string?} oppositeDescription - for `false` option
  2668. * @property {OptionValueInfo} default
  2669. * @property {OptionRangeInfo?} range - for type int
  2670. * @property {OptionChoiceInfo?} choices - for type choice
  2671. * @property {(value: any) => boolean} exception
  2672. *
  2673. * @typedef {number | boolean | string} OptionValue
  2674. * @typedef {OptionValue | [{ value: OptionValue[] }] | Array<{ since: string, value: OptionValue}>} OptionValueInfo
  2675. *
  2676. * @typedef {Object} OptionRedirectInfo
  2677. * @property {string} option
  2678. * @property {OptionValue} value
  2679. *
  2680. * @typedef {Object} OptionRangeInfo
  2681. * @property {number} start - recommended range start
  2682. * @property {number} end - recommended range end
  2683. * @property {number} step - recommended range step
  2684. *
  2685. * @typedef {Object} OptionChoiceInfo
  2686. * @property {boolean | string} value - boolean for the option that is originally boolean type
  2687. * @property {string?} description - undefined if redirect
  2688. * @property {string?} since - undefined if available since the first version of the option
  2689. * @property {string?} deprecated - deprecated since version
  2690. * @property {OptionValueInfo?} redirect - redirect deprecated value
  2691. *
  2692. * @property {string?} cliName
  2693. * @property {string?} cliCategory
  2694. * @property {string?} cliDescription
  2695. */
  2696. /** @type {{ [name: string]: OptionInfo } */
  2697. var options$2 = {
  2698. cursorOffset: {
  2699. since: "1.4.0",
  2700. category: CATEGORY_SPECIAL,
  2701. type: "int",
  2702. default: -1,
  2703. range: {
  2704. start: -1,
  2705. end: Infinity,
  2706. step: 1
  2707. },
  2708. description: dedent_1`
  2709. Print (to stderr) where a cursor at the given position would move to after formatting.
  2710. This option cannot be used with --range-start and --range-end.
  2711. `,
  2712. cliCategory: CATEGORY_EDITOR
  2713. },
  2714. filepath: {
  2715. since: "1.4.0",
  2716. category: CATEGORY_SPECIAL,
  2717. type: "path",
  2718. default: undefined,
  2719. description: "Specify the input filepath. This will be used to do parser inference.",
  2720. cliName: "stdin-filepath",
  2721. cliCategory: CATEGORY_OTHER,
  2722. cliDescription: "Path to the file to pretend that stdin comes from."
  2723. },
  2724. insertPragma: {
  2725. since: "1.8.0",
  2726. category: CATEGORY_SPECIAL,
  2727. type: "boolean",
  2728. default: false,
  2729. description: "Insert @format pragma into file's first docblock comment.",
  2730. cliCategory: CATEGORY_OTHER
  2731. },
  2732. parser: {
  2733. since: "0.0.10",
  2734. category: CATEGORY_GLOBAL,
  2735. type: "choice",
  2736. default: [{
  2737. since: "0.0.10",
  2738. value: "babylon"
  2739. }, {
  2740. since: "1.13.0",
  2741. value: undefined
  2742. }],
  2743. description: "Which parser to use.",
  2744. exception: function exception(value) {
  2745. return typeof value === "string" || typeof value === "function";
  2746. },
  2747. choices: [{
  2748. value: "flow",
  2749. description: "Flow"
  2750. }, {
  2751. value: "babylon",
  2752. description: "JavaScript"
  2753. }, {
  2754. value: "typescript",
  2755. since: "1.4.0",
  2756. description: "TypeScript"
  2757. }, {
  2758. value: "css",
  2759. since: "1.7.1",
  2760. description: "CSS"
  2761. }, {
  2762. value: "postcss",
  2763. since: "1.4.0",
  2764. description: "CSS/Less/SCSS",
  2765. deprecated: "1.7.1",
  2766. redirect: "css"
  2767. }, {
  2768. value: "less",
  2769. since: "1.7.1",
  2770. description: "Less"
  2771. }, {
  2772. value: "scss",
  2773. since: "1.7.1",
  2774. description: "SCSS"
  2775. }, {
  2776. value: "json",
  2777. since: "1.5.0",
  2778. description: "JSON"
  2779. }, {
  2780. value: "json5",
  2781. since: "1.13.0",
  2782. description: "JSON5"
  2783. }, {
  2784. value: "json-stringify",
  2785. since: "1.13.0",
  2786. description: "JSON.stringify"
  2787. }, {
  2788. value: "graphql",
  2789. since: "1.5.0",
  2790. description: "GraphQL"
  2791. }, {
  2792. value: "markdown",
  2793. since: "1.8.0",
  2794. description: "Markdown"
  2795. }, {
  2796. value: "vue",
  2797. since: "1.10.0",
  2798. description: "Vue"
  2799. }]
  2800. },
  2801. plugins: {
  2802. since: "1.10.0",
  2803. type: "path",
  2804. array: true,
  2805. default: [{
  2806. value: []
  2807. }],
  2808. category: CATEGORY_GLOBAL,
  2809. description: "Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
  2810. exception: function exception(value) {
  2811. return typeof value === "string" || typeof value === "object";
  2812. },
  2813. cliName: "plugin",
  2814. cliCategory: CATEGORY_CONFIG
  2815. },
  2816. pluginSearchDirs: {
  2817. since: "1.13.0",
  2818. type: "path",
  2819. array: true,
  2820. default: [{
  2821. value: []
  2822. }],
  2823. category: CATEGORY_GLOBAL,
  2824. description: dedent_1`
  2825. Custom directory that contains prettier plugins in node_modules subdirectory.
  2826. Overrides default behavior when plugins are searched relatively to the location of Prettier.
  2827. Multiple values are accepted.
  2828. `,
  2829. exception: function exception(value) {
  2830. return typeof value === "string" || typeof value === "object";
  2831. },
  2832. cliName: "plugin-search-dir",
  2833. cliCategory: CATEGORY_CONFIG
  2834. },
  2835. printWidth: {
  2836. since: "0.0.0",
  2837. category: CATEGORY_GLOBAL,
  2838. type: "int",
  2839. default: 80,
  2840. description: "The line length where Prettier will try wrap.",
  2841. range: {
  2842. start: 0,
  2843. end: Infinity,
  2844. step: 1
  2845. }
  2846. },
  2847. rangeEnd: {
  2848. since: "1.4.0",
  2849. category: CATEGORY_SPECIAL,
  2850. type: "int",
  2851. default: Infinity,
  2852. range: {
  2853. start: 0,
  2854. end: Infinity,
  2855. step: 1
  2856. },
  2857. description: dedent_1`
  2858. Format code ending at a given character offset (exclusive).
  2859. The range will extend forwards to the end of the selected statement.
  2860. This option cannot be used with --cursor-offset.
  2861. `,
  2862. cliCategory: CATEGORY_EDITOR
  2863. },
  2864. rangeStart: {
  2865. since: "1.4.0",
  2866. category: CATEGORY_SPECIAL,
  2867. type: "int",
  2868. default: 0,
  2869. range: {
  2870. start: 0,
  2871. end: Infinity,
  2872. step: 1
  2873. },
  2874. description: dedent_1`
  2875. Format code starting at a given character offset.
  2876. The range will extend backwards to the start of the first line containing the selected statement.
  2877. This option cannot be used with --cursor-offset.
  2878. `,
  2879. cliCategory: CATEGORY_EDITOR
  2880. },
  2881. requirePragma: {
  2882. since: "1.7.0",
  2883. category: CATEGORY_SPECIAL,
  2884. type: "boolean",
  2885. default: false,
  2886. description: dedent_1`
  2887. Require either '@prettier' or '@format' to be present in the file's first docblock comment
  2888. in order for it to be formatted.
  2889. `,
  2890. cliCategory: CATEGORY_OTHER
  2891. },
  2892. tabWidth: {
  2893. type: "int",
  2894. category: CATEGORY_GLOBAL,
  2895. default: 2,
  2896. description: "Number of spaces per indentation level.",
  2897. range: {
  2898. start: 0,
  2899. end: Infinity,
  2900. step: 1
  2901. }
  2902. },
  2903. useFlowParser: {
  2904. since: "0.0.0",
  2905. category: CATEGORY_GLOBAL,
  2906. type: "boolean",
  2907. default: false,
  2908. deprecated: "0.0.10",
  2909. description: "Use flow parser.",
  2910. redirect: {
  2911. option: "parser",
  2912. value: "flow"
  2913. },
  2914. cliName: "flow-parser"
  2915. },
  2916. useTabs: {
  2917. since: "1.0.0",
  2918. category: CATEGORY_GLOBAL,
  2919. type: "boolean",
  2920. default: false,
  2921. description: "Indent with tabs instead of spaces."
  2922. }
  2923. };
  2924. var coreOptions$1 = {
  2925. CATEGORY_CONFIG,
  2926. CATEGORY_EDITOR,
  2927. CATEGORY_FORMAT,
  2928. CATEGORY_OTHER,
  2929. CATEGORY_OUTPUT,
  2930. CATEGORY_GLOBAL,
  2931. CATEGORY_SPECIAL,
  2932. options: options$2
  2933. };
  2934. var require$$0 = ( _package$1 && _package ) || _package$1;
  2935. var currentVersion = require$$0.version;
  2936. var coreOptions = coreOptions$1.options;
  2937. function getSupportInfo$2(version, opts) {
  2938. opts = Object.assign({
  2939. plugins: [],
  2940. showUnreleased: false,
  2941. showDeprecated: false,
  2942. showInternal: false
  2943. }, opts);
  2944. if (!version) {
  2945. version = currentVersion;
  2946. }
  2947. var plugins = opts.plugins;
  2948. var options = arrayify(Object.assign(plugins.reduce(function (currentOptions, plugin) {
  2949. return Object.assign(currentOptions, plugin.options);
  2950. }, {}), coreOptions), "name").sort(function (a, b) {
  2951. return a.name === b.name ? 0 : a.name < b.name ? -1 : 1;
  2952. }).filter(filterSince).filter(filterDeprecated).map(mapDeprecated).map(mapInternal).map(function (option) {
  2953. var newOption = Object.assign({}, option);
  2954. if (Array.isArray(newOption.default)) {
  2955. newOption.default = newOption.default.length === 1 ? newOption.default[0].value : newOption.default.filter(filterSince).sort(function (info1, info2) {
  2956. return semver.compare(info2.since, info1.since);
  2957. })[0].value;
  2958. }
  2959. if (Array.isArray(newOption.choices)) {
  2960. newOption.choices = newOption.choices.filter(filterSince).filter(filterDeprecated).map(mapDeprecated);
  2961. }
  2962. return newOption;
  2963. }).map(function (option) {
  2964. var filteredPlugins = plugins.filter(function (plugin) {
  2965. return plugin.defaultOptions && plugin.defaultOptions[option.name];
  2966. });
  2967. var pluginDefaults = filteredPlugins.reduce(function (reduced, plugin) {
  2968. reduced[plugin.name] = plugin.defaultOptions[option.name];
  2969. return reduced;
  2970. }, {});
  2971. return Object.assign(option, {
  2972. pluginDefaults
  2973. });
  2974. });
  2975. var usePostCssParser = semver.lt(version, "1.7.1");
  2976. var languages = plugins.reduce(function (all, plugin) {
  2977. return all.concat(plugin.languages || []);
  2978. }, []).filter(function (language) {
  2979. return language.since ? semver.gte(version, language.since) : language.since !== null;
  2980. }).map(function (language) {
  2981. // Prevent breaking changes
  2982. if (language.name === "Markdown") {
  2983. return Object.assign({}, language, {
  2984. parsers: ["markdown"]
  2985. });
  2986. }
  2987. if (language.name === "TypeScript") {
  2988. return Object.assign({}, language, {
  2989. parsers: ["typescript"]
  2990. });
  2991. }
  2992. if (usePostCssParser && language.group === "CSS") {
  2993. return Object.assign({}, language, {
  2994. parsers: ["postcss"]
  2995. });
  2996. }
  2997. return language;
  2998. });
  2999. return {
  3000. languages,
  3001. options
  3002. };
  3003. function filterSince(object) {
  3004. return opts.showUnreleased || !("since" in object) || object.since && semver.gte(version, object.since);
  3005. }
  3006. function filterDeprecated(object) {
  3007. return opts.showDeprecated || !("deprecated" in object) || object.deprecated && semver.lt(version, object.deprecated);
  3008. }
  3009. function mapDeprecated(object) {
  3010. if (!object.deprecated || opts.showDeprecated) {
  3011. return object;
  3012. }
  3013. var newObject = Object.assign({}, object);
  3014. delete newObject.deprecated;
  3015. delete newObject.redirect;
  3016. return newObject;
  3017. }
  3018. function mapInternal(object) {
  3019. if (opts.showInternal) {
  3020. return object;
  3021. }
  3022. var newObject = Object.assign({}, object);
  3023. delete newObject.cliName;
  3024. delete newObject.cliCategory;
  3025. delete newObject.cliDescription;
  3026. return newObject;
  3027. }
  3028. }
  3029. var support = {
  3030. getSupportInfo: getSupportInfo$2
  3031. };
  3032. /* eslint-disable no-nested-ternary */
  3033. var arr = [];
  3034. var charCodeCache = [];
  3035. var leven = function leven(a, b) {
  3036. if (a === b) {
  3037. return 0;
  3038. }
  3039. var swap = a; // Swapping the strings if `a` is longer than `b` so we know which one is the
  3040. // shortest & which one is the longest
  3041. if (a.length > b.length) {
  3042. a = b;
  3043. b = swap;
  3044. }
  3045. var aLen = a.length;
  3046. var bLen = b.length;
  3047. if (aLen === 0) {
  3048. return bLen;
  3049. }
  3050. if (bLen === 0) {
  3051. return aLen;
  3052. } // Performing suffix trimming:
  3053. // We can linearly drop suffix common to both strings since they
  3054. // don't increase distance at all
  3055. // Note: `~-` is the bitwise way to perform a `- 1` operation
  3056. while (aLen > 0 && a.charCodeAt(~-aLen) === b.charCodeAt(~-bLen)) {
  3057. aLen--;
  3058. bLen--;
  3059. }
  3060. if (aLen === 0) {
  3061. return bLen;
  3062. } // Performing prefix trimming
  3063. // We can linearly drop prefix common to both strings since they
  3064. // don't increase distance at all
  3065. var start = 0;
  3066. while (start < aLen && a.charCodeAt(start) === b.charCodeAt(start)) {
  3067. start++;
  3068. }
  3069. aLen -= start;
  3070. bLen -= start;
  3071. if (aLen === 0) {
  3072. return bLen;
  3073. }
  3074. var bCharCode;
  3075. var ret;
  3076. var tmp;
  3077. var tmp2;
  3078. var i = 0;
  3079. var j = 0;
  3080. while (i < aLen) {
  3081. charCodeCache[start + i] = a.charCodeAt(start + i);
  3082. arr[i] = ++i;
  3083. }
  3084. while (j < bLen) {
  3085. bCharCode = b.charCodeAt(start + j);
  3086. tmp = j++;
  3087. ret = j;
  3088. for (i = 0; i < aLen; i++) {
  3089. tmp2 = bCharCode === charCodeCache[start + i] ? tmp : tmp + 1;
  3090. tmp = arr[i];
  3091. ret = arr[i] = tmp > ret ? tmp2 > ret ? ret + 1 : tmp2 : tmp2 > tmp ? tmp + 1 : tmp2;
  3092. }
  3093. }
  3094. return ret;
  3095. };
  3096. function apiDescriptor(name, value) {
  3097. return arguments.length === 1 ? JSON.stringify(name) : `\`{ ${apiDescriptor(name)}: ${JSON.stringify(value)} }\``;
  3098. }
  3099. function cliDescriptor(name, value) {
  3100. return value === false ? `\`--no-${name}\`` : value === true || arguments.length === 1 ? `\`--${name}\`` : value === "" ? `\`--${name}\` without an argument` : `\`--${name}=${value}\``;
  3101. }
  3102. var optionsDescriptor = {
  3103. apiDescriptor,
  3104. cliDescriptor
  3105. };
  3106. function validateOption(value, optionInfo, opts) {
  3107. opts = opts || {};
  3108. var descriptor = opts.descriptor || optionsDescriptor.apiDescriptor;
  3109. if (typeof optionInfo.exception === "function" && optionInfo.exception(value)) {
  3110. return;
  3111. }
  3112. try {
  3113. validateOptionType(value, optionInfo);
  3114. } catch (error) {
  3115. throw new Error(`Invalid \`${descriptor(optionInfo.name)}\` value. ${error.message}, but received \`${JSON.stringify(value)}\`.`);
  3116. }
  3117. }
  3118. function validateOptionType(value, optionInfo) {
  3119. if (optionInfo.array) {
  3120. if (!Array.isArray(value)) {
  3121. throw new Error(`Expected an array`);
  3122. }
  3123. value.forEach(function (v) {
  3124. return validateOptionType(v, Object.assign({}, optionInfo, {
  3125. array: false
  3126. }));
  3127. });
  3128. } else {
  3129. switch (optionInfo.type) {
  3130. case "int":
  3131. validateIntOption(value);
  3132. break;
  3133. case "boolean":
  3134. validateBooleanOption(value);
  3135. break;
  3136. case "choice":
  3137. validateChoiceOption(value, optionInfo.choices);
  3138. break;
  3139. }
  3140. }
  3141. }
  3142. function validateBooleanOption(value) {
  3143. if (typeof value !== "boolean") {
  3144. throw new Error(`Expected a boolean`);
  3145. }
  3146. }
  3147. function validateIntOption(value) {
  3148. if (!(typeof value === "number" && Math.floor(value) === value && value >= 0 && value !== Infinity)) {
  3149. throw new Error(`Expected an integer`);
  3150. }
  3151. }
  3152. function validateChoiceOption(value, choiceInfos) {
  3153. if (!choiceInfos.some(function (choiceInfo) {
  3154. return choiceInfo.value === value;
  3155. })) {
  3156. var choices = choiceInfos.filter(function (choiceInfo) {
  3157. return !choiceInfo.deprecated;
  3158. }).map(function (choiceInfo) {
  3159. return JSON.stringify(choiceInfo.value);
  3160. }).sort();
  3161. var head = choices.slice(0, -2);
  3162. var tail = choices.slice(-2);
  3163. throw new Error(`Expected ${head.concat(tail.join(" or ")).join(", ")}`);
  3164. }
  3165. }
  3166. var optionsValidator = {
  3167. validateOption
  3168. };
  3169. function normalizeOptions$1(options, optionInfos, opts) {
  3170. opts = opts || {};
  3171. var logger = opts.logger === false ? {
  3172. warn() {}
  3173. } : opts.logger !== undefined ? opts.logger : console;
  3174. var descriptor = opts.descriptor || optionsDescriptor.apiDescriptor;
  3175. var passThrough = opts.passThrough || [];
  3176. var optionInfoMap = optionInfos.reduce(function (reduced, optionInfo) {
  3177. return Object.assign(reduced, {
  3178. [optionInfo.name]: optionInfo
  3179. });
  3180. }, {});
  3181. var normalizedOptions = Object.keys(options).reduce(function (newOptions, key) {
  3182. var optionInfo = optionInfoMap[key];
  3183. var optionName = key;
  3184. var optionValue = options[key];
  3185. if (!optionInfo) {
  3186. if (passThrough === true || passThrough.indexOf(optionName) !== -1) {
  3187. newOptions[optionName] = optionValue;
  3188. } else {
  3189. logger.warn(createUnknownOptionMessage(optionName, optionValue, optionInfos, descriptor));
  3190. }
  3191. return newOptions;
  3192. }
  3193. if (!optionInfo.deprecated) {
  3194. optionValue = normalizeOption(optionValue, optionInfo);
  3195. } else if (typeof optionInfo.redirect === "string") {
  3196. logger.warn(createRedirectOptionMessage(optionInfo, descriptor));
  3197. optionName = optionInfo.redirect;
  3198. } else if (optionValue) {
  3199. logger.warn(createRedirectOptionMessage(optionInfo, descriptor));
  3200. optionValue = optionInfo.redirect.value;
  3201. optionName = optionInfo.redirect.option;
  3202. }
  3203. if (optionInfo.choices) {
  3204. var choiceInfo = optionInfo.choices.find(function (choice) {
  3205. return choice.value === optionValue;
  3206. });
  3207. if (choiceInfo && choiceInfo.deprecated) {
  3208. logger.warn(createRedirectChoiceMessage(optionInfo, choiceInfo, descriptor));
  3209. optionValue = choiceInfo.redirect;
  3210. }
  3211. }
  3212. if (optionInfo.array && !Array.isArray(optionValue)) {
  3213. optionValue = [optionValue];
  3214. }
  3215. if (optionValue !== optionInfo.default) {
  3216. optionsValidator.validateOption(optionValue, optionInfoMap[optionName], {
  3217. descriptor
  3218. });
  3219. }
  3220. newOptions[optionName] = optionValue;
  3221. return newOptions;
  3222. }, {});
  3223. return normalizedOptions;
  3224. }
  3225. function normalizeOption(option, optionInfo) {
  3226. return optionInfo.type === "int" ? Number(option) : option;
  3227. }
  3228. function createUnknownOptionMessage(key, value, optionInfos, descriptor) {
  3229. var messages = [`Ignored unknown option ${descriptor(key, value)}.`];
  3230. var suggestedOptionInfo = optionInfos.find(function (optionInfo) {
  3231. return leven(optionInfo.name, key) < 3;
  3232. });
  3233. if (suggestedOptionInfo) {
  3234. messages.push(`Did you mean ${JSON.stringify(suggestedOptionInfo.name)}?`);
  3235. }
  3236. return messages.join(" ");
  3237. }
  3238. function createRedirectOptionMessage(optionInfo, descriptor) {
  3239. return `${descriptor(optionInfo.name)} is deprecated. Prettier now treats it as ${typeof optionInfo.redirect === "string" ? descriptor(optionInfo.redirect) : descriptor(optionInfo.redirect.option, optionInfo.redirect.value)}.`;
  3240. }
  3241. function createRedirectChoiceMessage(optionInfo, choiceInfo, descriptor) {
  3242. return `${descriptor(optionInfo.name, choiceInfo.value)} is deprecated. Prettier now treats it as ${descriptor(optionInfo.name, choiceInfo.redirect)}.`;
  3243. }
  3244. function normalizeApiOptions(options, optionInfos, opts) {
  3245. return normalizeOptions$1(options, optionInfos, Object.assign({
  3246. descriptor: optionsDescriptor.apiDescriptor
  3247. }, opts));
  3248. }
  3249. function normalizeCliOptions(options, optionInfos, opts) {
  3250. var args = options["_"] || [];
  3251. var newOptions = normalizeOptions$1(Object.keys(options).reduce(function (reduced, key) {
  3252. return Object.assign(reduced, key.length === 1 // omit alias
  3253. ? null : {
  3254. [key]: options[key]
  3255. });
  3256. }, {}), optionInfos, Object.assign({
  3257. descriptor: optionsDescriptor.cliDescriptor
  3258. }, opts));
  3259. newOptions["_"] = args;
  3260. return newOptions;
  3261. }
  3262. var optionsNormalizer = {
  3263. normalizeApiOptions,
  3264. normalizeCliOptions
  3265. };
  3266. var getLast = function getLast(arr) {
  3267. return arr.length > 0 ? arr[arr.length - 1] : null;
  3268. };
  3269. function locStart$1(node) {
  3270. // Handle nodes with decorators. They should start at the first decorator
  3271. if (node.declaration && node.declaration.decorators && node.declaration.decorators.length > 0) {
  3272. return locStart$1(node.declaration.decorators[0]);
  3273. }
  3274. if (node.decorators && node.decorators.length > 0) {
  3275. return locStart$1(node.decorators[0]);
  3276. }
  3277. if (node.__location) {
  3278. return node.__location.startOffset;
  3279. }
  3280. if (node.range) {
  3281. return node.range[0];
  3282. }
  3283. if (typeof node.start === "number") {
  3284. return node.start;
  3285. }
  3286. if (node.loc) {
  3287. return node.loc.start;
  3288. }
  3289. return null;
  3290. }
  3291. function locEnd$1(node) {
  3292. var endNode = node.nodes && getLast(node.nodes);
  3293. if (endNode && node.source && !node.source.end) {
  3294. node = endNode;
  3295. }
  3296. if (node.__location) {
  3297. return node.__location.endOffset;
  3298. }
  3299. var loc = node.range ? node.range[1] : typeof node.end === "number" ? node.end : null;
  3300. if (node.typeAnnotation) {
  3301. return Math.max(loc, locEnd$1(node.typeAnnotation));
  3302. }
  3303. if (node.loc && !loc) {
  3304. return node.loc.end;
  3305. }
  3306. return loc;
  3307. }
  3308. var loc = {
  3309. locStart: locStart$1,
  3310. locEnd: locEnd$1
  3311. };
  3312. var jsTokens = createCommonjsModule(function (module, exports) {
  3313. // Copyright 2014, 2015, 2016, 2017 Simon Lydell
  3314. // License: MIT. (See LICENSE.)
  3315. Object.defineProperty(exports, "__esModule", {
  3316. value: true
  3317. }); // This regex comes from regex.coffee, and is inserted here by generate-index.js
  3318. // (run `npm run build`).
  3319. 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;
  3320. exports.matchToToken = function (match) {
  3321. var token = {
  3322. type: "invalid",
  3323. value: match[0]
  3324. };
  3325. if (match[1]) token.type = "string", token.closed = !!(match[3] || match[4]);else if (match[5]) token.type = "comment";else if (match[6]) token.type = "comment", token.closed = !!match[7];else if (match[8]) token.type = "regex";else if (match[9]) token.type = "number";else if (match[10]) token.type = "name";else if (match[11]) token.type = "punctuator";else if (match[12]) token.type = "whitespace";
  3326. return token;
  3327. };
  3328. });
  3329. unwrapExports(jsTokens);
  3330. var ast = createCommonjsModule(function (module) {
  3331. /*
  3332. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  3333. Redistribution and use in source and binary forms, with or without
  3334. modification, are permitted provided that the following conditions are met:
  3335. * Redistributions of source code must retain the above copyright
  3336. notice, this list of conditions and the following disclaimer.
  3337. * Redistributions in binary form must reproduce the above copyright
  3338. notice, this list of conditions and the following disclaimer in the
  3339. documentation and/or other materials provided with the distribution.
  3340. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
  3341. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  3342. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  3343. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  3344. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  3345. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  3346. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  3347. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  3348. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  3349. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3350. */
  3351. (function () {
  3352. 'use strict';
  3353. function isExpression(node) {
  3354. if (node == null) {
  3355. return false;
  3356. }
  3357. switch (node.type) {
  3358. case 'ArrayExpression':
  3359. case 'AssignmentExpression':
  3360. case 'BinaryExpression':
  3361. case 'CallExpression':
  3362. case 'ConditionalExpression':
  3363. case 'FunctionExpression':
  3364. case 'Identifier':
  3365. case 'Literal':
  3366. case 'LogicalExpression':
  3367. case 'MemberExpression':
  3368. case 'NewExpression':
  3369. case 'ObjectExpression':
  3370. case 'SequenceExpression':
  3371. case 'ThisExpression':
  3372. case 'UnaryExpression':
  3373. case 'UpdateExpression':
  3374. return true;
  3375. }
  3376. return false;
  3377. }
  3378. function isIterationStatement(node) {
  3379. if (node == null) {
  3380. return false;
  3381. }
  3382. switch (node.type) {
  3383. case 'DoWhileStatement':
  3384. case 'ForInStatement':
  3385. case 'ForStatement':
  3386. case 'WhileStatement':
  3387. return true;
  3388. }
  3389. return false;
  3390. }
  3391. function isStatement(node) {
  3392. if (node == null) {
  3393. return false;
  3394. }
  3395. switch (node.type) {
  3396. case 'BlockStatement':
  3397. case 'BreakStatement':
  3398. case 'ContinueStatement':
  3399. case 'DebuggerStatement':
  3400. case 'DoWhileStatement':
  3401. case 'EmptyStatement':
  3402. case 'ExpressionStatement':
  3403. case 'ForInStatement':
  3404. case 'ForStatement':
  3405. case 'IfStatement':
  3406. case 'LabeledStatement':
  3407. case 'ReturnStatement':
  3408. case 'SwitchStatement':
  3409. case 'ThrowStatement':
  3410. case 'TryStatement':
  3411. case 'VariableDeclaration':
  3412. case 'WhileStatement':
  3413. case 'WithStatement':
  3414. return true;
  3415. }
  3416. return false;
  3417. }
  3418. function isSourceElement(node) {
  3419. return isStatement(node) || node != null && node.type === 'FunctionDeclaration';
  3420. }
  3421. function trailingStatement(node) {
  3422. switch (node.type) {
  3423. case 'IfStatement':
  3424. if (node.alternate != null) {
  3425. return node.alternate;
  3426. }
  3427. return node.consequent;
  3428. case 'LabeledStatement':
  3429. case 'ForStatement':
  3430. case 'ForInStatement':
  3431. case 'WhileStatement':
  3432. case 'WithStatement':
  3433. return node.body;
  3434. }
  3435. return null;
  3436. }
  3437. function isProblematicIfStatement(node) {
  3438. var current;
  3439. if (node.type !== 'IfStatement') {
  3440. return false;
  3441. }
  3442. if (node.alternate == null) {
  3443. return false;
  3444. }
  3445. current = node.consequent;
  3446. do {
  3447. if (current.type === 'IfStatement') {
  3448. if (current.alternate == null) {
  3449. return true;
  3450. }
  3451. }
  3452. current = trailingStatement(current);
  3453. } while (current);
  3454. return false;
  3455. }
  3456. module.exports = {
  3457. isExpression: isExpression,
  3458. isStatement: isStatement,
  3459. isIterationStatement: isIterationStatement,
  3460. isSourceElement: isSourceElement,
  3461. isProblematicIfStatement: isProblematicIfStatement,
  3462. trailingStatement: trailingStatement
  3463. };
  3464. })();
  3465. /* vim: set sw=4 ts=4 et tw=80 : */
  3466. });
  3467. var code = createCommonjsModule(function (module) {
  3468. /*
  3469. Copyright (C) 2013-2014 Yusuke Suzuki <utatane.tea@gmail.com>
  3470. Copyright (C) 2014 Ivan Nikulin <ifaaan@gmail.com>
  3471. Redistribution and use in source and binary forms, with or without
  3472. modification, are permitted provided that the following conditions are met:
  3473. * Redistributions of source code must retain the above copyright
  3474. notice, this list of conditions and the following disclaimer.
  3475. * Redistributions in binary form must reproduce the above copyright
  3476. notice, this list of conditions and the following disclaimer in the
  3477. documentation and/or other materials provided with the distribution.
  3478. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  3479. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  3480. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  3481. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  3482. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  3483. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  3484. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  3485. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  3486. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  3487. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3488. */
  3489. (function () {
  3490. 'use strict';
  3491. var ES6Regex, ES5Regex, NON_ASCII_WHITESPACES, IDENTIFIER_START, IDENTIFIER_PART, ch; // See `tools/generate-identifier-regex.js`.
  3492. ES5Regex = {
  3493. // ECMAScript 5.1/Unicode v7.0.0 NonAsciiIdentifierStart:
  3494. 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]/,
  3495. // ECMAScript 5.1/Unicode v7.0.0 NonAsciiIdentifierPart:
  3496. 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]/
  3497. };
  3498. ES6Regex = {
  3499. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierStart:
  3500. 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]/,
  3501. // ECMAScript 6/Unicode v7.0.0 NonAsciiIdentifierPart:
  3502. 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]/
  3503. };
  3504. function isDecimalDigit(ch) {
  3505. return 0x30 <= ch && ch <= 0x39; // 0..9
  3506. }
  3507. function isHexDigit(ch) {
  3508. return 0x30 <= ch && ch <= 0x39 || // 0..9
  3509. 0x61 <= ch && ch <= 0x66 || // a..f
  3510. 0x41 <= ch && ch <= 0x46; // A..F
  3511. }
  3512. function isOctalDigit(ch) {
  3513. return ch >= 0x30 && ch <= 0x37; // 0..7
  3514. } // 7.2 White Space
  3515. NON_ASCII_WHITESPACES = [0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF];
  3516. function isWhiteSpace(ch) {
  3517. return ch === 0x20 || ch === 0x09 || ch === 0x0B || ch === 0x0C || ch === 0xA0 || ch >= 0x1680 && NON_ASCII_WHITESPACES.indexOf(ch) >= 0;
  3518. } // 7.3 Line Terminators
  3519. function isLineTerminator(ch) {
  3520. return ch === 0x0A || ch === 0x0D || ch === 0x2028 || ch === 0x2029;
  3521. } // 7.6 Identifier Names and Identifiers
  3522. function fromCodePoint(cp) {
  3523. if (cp <= 0xFFFF) {
  3524. return String.fromCharCode(cp);
  3525. }
  3526. var cu1 = String.fromCharCode(Math.floor((cp - 0x10000) / 0x400) + 0xD800);
  3527. var cu2 = String.fromCharCode((cp - 0x10000) % 0x400 + 0xDC00);
  3528. return cu1 + cu2;
  3529. }
  3530. IDENTIFIER_START = new Array(0x80);
  3531. for (ch = 0; ch < 0x80; ++ch) {
  3532. IDENTIFIER_START[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  3533. ch >= 0x41 && ch <= 0x5A || // A..Z
  3534. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  3535. }
  3536. IDENTIFIER_PART = new Array(0x80);
  3537. for (ch = 0; ch < 0x80; ++ch) {
  3538. IDENTIFIER_PART[ch] = ch >= 0x61 && ch <= 0x7A || // a..z
  3539. ch >= 0x41 && ch <= 0x5A || // A..Z
  3540. ch >= 0x30 && ch <= 0x39 || // 0..9
  3541. ch === 0x24 || ch === 0x5F; // $ (dollar) and _ (underscore)
  3542. }
  3543. function isIdentifierStartES5(ch) {
  3544. return ch < 0x80 ? IDENTIFIER_START[ch] : ES5Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  3545. }
  3546. function isIdentifierPartES5(ch) {
  3547. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES5Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  3548. }
  3549. function isIdentifierStartES6(ch) {
  3550. return ch < 0x80 ? IDENTIFIER_START[ch] : ES6Regex.NonAsciiIdentifierStart.test(fromCodePoint(ch));
  3551. }
  3552. function isIdentifierPartES6(ch) {
  3553. return ch < 0x80 ? IDENTIFIER_PART[ch] : ES6Regex.NonAsciiIdentifierPart.test(fromCodePoint(ch));
  3554. }
  3555. module.exports = {
  3556. isDecimalDigit: isDecimalDigit,
  3557. isHexDigit: isHexDigit,
  3558. isOctalDigit: isOctalDigit,
  3559. isWhiteSpace: isWhiteSpace,
  3560. isLineTerminator: isLineTerminator,
  3561. isIdentifierStartES5: isIdentifierStartES5,
  3562. isIdentifierPartES5: isIdentifierPartES5,
  3563. isIdentifierStartES6: isIdentifierStartES6,
  3564. isIdentifierPartES6: isIdentifierPartES6
  3565. };
  3566. })();
  3567. /* vim: set sw=4 ts=4 et tw=80 : */
  3568. });
  3569. var keyword = createCommonjsModule(function (module) {
  3570. /*
  3571. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  3572. Redistribution and use in source and binary forms, with or without
  3573. modification, are permitted provided that the following conditions are met:
  3574. * Redistributions of source code must retain the above copyright
  3575. notice, this list of conditions and the following disclaimer.
  3576. * Redistributions in binary form must reproduce the above copyright
  3577. notice, this list of conditions and the following disclaimer in the
  3578. documentation and/or other materials provided with the distribution.
  3579. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  3580. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  3581. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  3582. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  3583. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  3584. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  3585. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  3586. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  3587. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  3588. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3589. */
  3590. (function () {
  3591. 'use strict';
  3592. var code$$1 = code;
  3593. function isStrictModeReservedWordES6(id) {
  3594. switch (id) {
  3595. case 'implements':
  3596. case 'interface':
  3597. case 'package':
  3598. case 'private':
  3599. case 'protected':
  3600. case 'public':
  3601. case 'static':
  3602. case 'let':
  3603. return true;
  3604. default:
  3605. return false;
  3606. }
  3607. }
  3608. function isKeywordES5(id, strict) {
  3609. // yield should not be treated as keyword under non-strict mode.
  3610. if (!strict && id === 'yield') {
  3611. return false;
  3612. }
  3613. return isKeywordES6(id, strict);
  3614. }
  3615. function isKeywordES6(id, strict) {
  3616. if (strict && isStrictModeReservedWordES6(id)) {
  3617. return true;
  3618. }
  3619. switch (id.length) {
  3620. case 2:
  3621. return id === 'if' || id === 'in' || id === 'do';
  3622. case 3:
  3623. return id === 'var' || id === 'for' || id === 'new' || id === 'try';
  3624. case 4:
  3625. return id === 'this' || id === 'else' || id === 'case' || id === 'void' || id === 'with' || id === 'enum';
  3626. case 5:
  3627. return id === 'while' || id === 'break' || id === 'catch' || id === 'throw' || id === 'const' || id === 'yield' || id === 'class' || id === 'super';
  3628. case 6:
  3629. return id === 'return' || id === 'typeof' || id === 'delete' || id === 'switch' || id === 'export' || id === 'import';
  3630. case 7:
  3631. return id === 'default' || id === 'finally' || id === 'extends';
  3632. case 8:
  3633. return id === 'function' || id === 'continue' || id === 'debugger';
  3634. case 10:
  3635. return id === 'instanceof';
  3636. default:
  3637. return false;
  3638. }
  3639. }
  3640. function isReservedWordES5(id, strict) {
  3641. return id === 'null' || id === 'true' || id === 'false' || isKeywordES5(id, strict);
  3642. }
  3643. function isReservedWordES6(id, strict) {
  3644. return id === 'null' || id === 'true' || id === 'false' || isKeywordES6(id, strict);
  3645. }
  3646. function isRestrictedWord(id) {
  3647. return id === 'eval' || id === 'arguments';
  3648. }
  3649. function isIdentifierNameES5(id) {
  3650. var i, iz, ch;
  3651. if (id.length === 0) {
  3652. return false;
  3653. }
  3654. ch = id.charCodeAt(0);
  3655. if (!code$$1.isIdentifierStartES5(ch)) {
  3656. return false;
  3657. }
  3658. for (i = 1, iz = id.length; i < iz; ++i) {
  3659. ch = id.charCodeAt(i);
  3660. if (!code$$1.isIdentifierPartES5(ch)) {
  3661. return false;
  3662. }
  3663. }
  3664. return true;
  3665. }
  3666. function decodeUtf16(lead, trail) {
  3667. return (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
  3668. }
  3669. function isIdentifierNameES6(id) {
  3670. var i, iz, ch, lowCh, check;
  3671. if (id.length === 0) {
  3672. return false;
  3673. }
  3674. check = code$$1.isIdentifierStartES6;
  3675. for (i = 0, iz = id.length; i < iz; ++i) {
  3676. ch = id.charCodeAt(i);
  3677. if (0xD800 <= ch && ch <= 0xDBFF) {
  3678. ++i;
  3679. if (i >= iz) {
  3680. return false;
  3681. }
  3682. lowCh = id.charCodeAt(i);
  3683. if (!(0xDC00 <= lowCh && lowCh <= 0xDFFF)) {
  3684. return false;
  3685. }
  3686. ch = decodeUtf16(ch, lowCh);
  3687. }
  3688. if (!check(ch)) {
  3689. return false;
  3690. }
  3691. check = code$$1.isIdentifierPartES6;
  3692. }
  3693. return true;
  3694. }
  3695. function isIdentifierES5(id, strict) {
  3696. return isIdentifierNameES5(id) && !isReservedWordES5(id, strict);
  3697. }
  3698. function isIdentifierES6(id, strict) {
  3699. return isIdentifierNameES6(id) && !isReservedWordES6(id, strict);
  3700. }
  3701. module.exports = {
  3702. isKeywordES5: isKeywordES5,
  3703. isKeywordES6: isKeywordES6,
  3704. isReservedWordES5: isReservedWordES5,
  3705. isReservedWordES6: isReservedWordES6,
  3706. isRestrictedWord: isRestrictedWord,
  3707. isIdentifierNameES5: isIdentifierNameES5,
  3708. isIdentifierNameES6: isIdentifierNameES6,
  3709. isIdentifierES5: isIdentifierES5,
  3710. isIdentifierES6: isIdentifierES6
  3711. };
  3712. })();
  3713. /* vim: set sw=4 ts=4 et tw=80 : */
  3714. });
  3715. var utils = createCommonjsModule(function (module, exports) {
  3716. /*
  3717. Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
  3718. Redistribution and use in source and binary forms, with or without
  3719. modification, are permitted provided that the following conditions are met:
  3720. * Redistributions of source code must retain the above copyright
  3721. notice, this list of conditions and the following disclaimer.
  3722. * Redistributions in binary form must reproduce the above copyright
  3723. notice, this list of conditions and the following disclaimer in the
  3724. documentation and/or other materials provided with the distribution.
  3725. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  3726. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  3727. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  3728. ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  3729. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  3730. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  3731. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  3732. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  3733. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  3734. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3735. */
  3736. (function () {
  3737. 'use strict';
  3738. exports.ast = ast;
  3739. exports.code = code;
  3740. exports.keyword = keyword;
  3741. })();
  3742. /* vim: set sw=4 ts=4 et tw=80 : */
  3743. });
  3744. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  3745. var escapeStringRegexp = function escapeStringRegexp(str) {
  3746. if (typeof str !== 'string') {
  3747. throw new TypeError('Expected a string');
  3748. }
  3749. return str.replace(matchOperatorsRe, '\\$&');
  3750. };
  3751. var colorName = {
  3752. "aliceblue": [240, 248, 255],
  3753. "antiquewhite": [250, 235, 215],
  3754. "aqua": [0, 255, 255],
  3755. "aquamarine": [127, 255, 212],
  3756. "azure": [240, 255, 255],
  3757. "beige": [245, 245, 220],
  3758. "bisque": [255, 228, 196],
  3759. "black": [0, 0, 0],
  3760. "blanchedalmond": [255, 235, 205],
  3761. "blue": [0, 0, 255],
  3762. "blueviolet": [138, 43, 226],
  3763. "brown": [165, 42, 42],
  3764. "burlywood": [222, 184, 135],
  3765. "cadetblue": [95, 158, 160],
  3766. "chartreuse": [127, 255, 0],
  3767. "chocolate": [210, 105, 30],
  3768. "coral": [255, 127, 80],
  3769. "cornflowerblue": [100, 149, 237],
  3770. "cornsilk": [255, 248, 220],
  3771. "crimson": [220, 20, 60],
  3772. "cyan": [0, 255, 255],
  3773. "darkblue": [0, 0, 139],
  3774. "darkcyan": [0, 139, 139],
  3775. "darkgoldenrod": [184, 134, 11],
  3776. "darkgray": [169, 169, 169],
  3777. "darkgreen": [0, 100, 0],
  3778. "darkgrey": [169, 169, 169],
  3779. "darkkhaki": [189, 183, 107],
  3780. "darkmagenta": [139, 0, 139],
  3781. "darkolivegreen": [85, 107, 47],
  3782. "darkorange": [255, 140, 0],
  3783. "darkorchid": [153, 50, 204],
  3784. "darkred": [139, 0, 0],
  3785. "darksalmon": [233, 150, 122],
  3786. "darkseagreen": [143, 188, 143],
  3787. "darkslateblue": [72, 61, 139],
  3788. "darkslategray": [47, 79, 79],
  3789. "darkslategrey": [47, 79, 79],
  3790. "darkturquoise": [0, 206, 209],
  3791. "darkviolet": [148, 0, 211],
  3792. "deeppink": [255, 20, 147],
  3793. "deepskyblue": [0, 191, 255],
  3794. "dimgray": [105, 105, 105],
  3795. "dimgrey": [105, 105, 105],
  3796. "dodgerblue": [30, 144, 255],
  3797. "firebrick": [178, 34, 34],
  3798. "floralwhite": [255, 250, 240],
  3799. "forestgreen": [34, 139, 34],
  3800. "fuchsia": [255, 0, 255],
  3801. "gainsboro": [220, 220, 220],
  3802. "ghostwhite": [248, 248, 255],
  3803. "gold": [255, 215, 0],
  3804. "goldenrod": [218, 165, 32],
  3805. "gray": [128, 128, 128],
  3806. "green": [0, 128, 0],
  3807. "greenyellow": [173, 255, 47],
  3808. "grey": [128, 128, 128],
  3809. "honeydew": [240, 255, 240],
  3810. "hotpink": [255, 105, 180],
  3811. "indianred": [205, 92, 92],
  3812. "indigo": [75, 0, 130],
  3813. "ivory": [255, 255, 240],
  3814. "khaki": [240, 230, 140],
  3815. "lavender": [230, 230, 250],
  3816. "lavenderblush": [255, 240, 245],
  3817. "lawngreen": [124, 252, 0],
  3818. "lemonchiffon": [255, 250, 205],
  3819. "lightblue": [173, 216, 230],
  3820. "lightcoral": [240, 128, 128],
  3821. "lightcyan": [224, 255, 255],
  3822. "lightgoldenrodyellow": [250, 250, 210],
  3823. "lightgray": [211, 211, 211],
  3824. "lightgreen": [144, 238, 144],
  3825. "lightgrey": [211, 211, 211],
  3826. "lightpink": [255, 182, 193],
  3827. "lightsalmon": [255, 160, 122],
  3828. "lightseagreen": [32, 178, 170],
  3829. "lightskyblue": [135, 206, 250],
  3830. "lightslategray": [119, 136, 153],
  3831. "lightslategrey": [119, 136, 153],
  3832. "lightsteelblue": [176, 196, 222],
  3833. "lightyellow": [255, 255, 224],
  3834. "lime": [0, 255, 0],
  3835. "limegreen": [50, 205, 50],
  3836. "linen": [250, 240, 230],
  3837. "magenta": [255, 0, 255],
  3838. "maroon": [128, 0, 0],
  3839. "mediumaquamarine": [102, 205, 170],
  3840. "mediumblue": [0, 0, 205],
  3841. "mediumorchid": [186, 85, 211],
  3842. "mediumpurple": [147, 112, 219],
  3843. "mediumseagreen": [60, 179, 113],
  3844. "mediumslateblue": [123, 104, 238],
  3845. "mediumspringgreen": [0, 250, 154],
  3846. "mediumturquoise": [72, 209, 204],
  3847. "mediumvioletred": [199, 21, 133],
  3848. "midnightblue": [25, 25, 112],
  3849. "mintcream": [245, 255, 250],
  3850. "mistyrose": [255, 228, 225],
  3851. "moccasin": [255, 228, 181],
  3852. "navajowhite": [255, 222, 173],
  3853. "navy": [0, 0, 128],
  3854. "oldlace": [253, 245, 230],
  3855. "olive": [128, 128, 0],
  3856. "olivedrab": [107, 142, 35],
  3857. "orange": [255, 165, 0],
  3858. "orangered": [255, 69, 0],
  3859. "orchid": [218, 112, 214],
  3860. "palegoldenrod": [238, 232, 170],
  3861. "palegreen": [152, 251, 152],
  3862. "paleturquoise": [175, 238, 238],
  3863. "palevioletred": [219, 112, 147],
  3864. "papayawhip": [255, 239, 213],
  3865. "peachpuff": [255, 218, 185],
  3866. "peru": [205, 133, 63],
  3867. "pink": [255, 192, 203],
  3868. "plum": [221, 160, 221],
  3869. "powderblue": [176, 224, 230],
  3870. "purple": [128, 0, 128],
  3871. "rebeccapurple": [102, 51, 153],
  3872. "red": [255, 0, 0],
  3873. "rosybrown": [188, 143, 143],
  3874. "royalblue": [65, 105, 225],
  3875. "saddlebrown": [139, 69, 19],
  3876. "salmon": [250, 128, 114],
  3877. "sandybrown": [244, 164, 96],
  3878. "seagreen": [46, 139, 87],
  3879. "seashell": [255, 245, 238],
  3880. "sienna": [160, 82, 45],
  3881. "silver": [192, 192, 192],
  3882. "skyblue": [135, 206, 235],
  3883. "slateblue": [106, 90, 205],
  3884. "slategray": [112, 128, 144],
  3885. "slategrey": [112, 128, 144],
  3886. "snow": [255, 250, 250],
  3887. "springgreen": [0, 255, 127],
  3888. "steelblue": [70, 130, 180],
  3889. "tan": [210, 180, 140],
  3890. "teal": [0, 128, 128],
  3891. "thistle": [216, 191, 216],
  3892. "tomato": [255, 99, 71],
  3893. "turquoise": [64, 224, 208],
  3894. "violet": [238, 130, 238],
  3895. "wheat": [245, 222, 179],
  3896. "white": [255, 255, 255],
  3897. "whitesmoke": [245, 245, 245],
  3898. "yellow": [255, 255, 0],
  3899. "yellowgreen": [154, 205, 50]
  3900. };
  3901. var conversions = createCommonjsModule(function (module) {
  3902. /* MIT license */
  3903. // NOTE: conversions should only return primitive values (i.e. arrays, or
  3904. // values that give correct `typeof` results).
  3905. // do not use box values types (i.e. Number(), String(), etc.)
  3906. var reverseKeywords = {};
  3907. for (var key in colorName) {
  3908. if (colorName.hasOwnProperty(key)) {
  3909. reverseKeywords[colorName[key]] = key;
  3910. }
  3911. }
  3912. var convert = module.exports = {
  3913. rgb: {
  3914. channels: 3,
  3915. labels: 'rgb'
  3916. },
  3917. hsl: {
  3918. channels: 3,
  3919. labels: 'hsl'
  3920. },
  3921. hsv: {
  3922. channels: 3,
  3923. labels: 'hsv'
  3924. },
  3925. hwb: {
  3926. channels: 3,
  3927. labels: 'hwb'
  3928. },
  3929. cmyk: {
  3930. channels: 4,
  3931. labels: 'cmyk'
  3932. },
  3933. xyz: {
  3934. channels: 3,
  3935. labels: 'xyz'
  3936. },
  3937. lab: {
  3938. channels: 3,
  3939. labels: 'lab'
  3940. },
  3941. lch: {
  3942. channels: 3,
  3943. labels: 'lch'
  3944. },
  3945. hex: {
  3946. channels: 1,
  3947. labels: ['hex']
  3948. },
  3949. keyword: {
  3950. channels: 1,
  3951. labels: ['keyword']
  3952. },
  3953. ansi16: {
  3954. channels: 1,
  3955. labels: ['ansi16']
  3956. },
  3957. ansi256: {
  3958. channels: 1,
  3959. labels: ['ansi256']
  3960. },
  3961. hcg: {
  3962. channels: 3,
  3963. labels: ['h', 'c', 'g']
  3964. },
  3965. apple: {
  3966. channels: 3,
  3967. labels: ['r16', 'g16', 'b16']
  3968. },
  3969. gray: {
  3970. channels: 1,
  3971. labels: ['gray']
  3972. }
  3973. }; // hide .channels and .labels properties
  3974. for (var model in convert) {
  3975. if (convert.hasOwnProperty(model)) {
  3976. if (!('channels' in convert[model])) {
  3977. throw new Error('missing channels property: ' + model);
  3978. }
  3979. if (!('labels' in convert[model])) {
  3980. throw new Error('missing channel labels property: ' + model);
  3981. }
  3982. if (convert[model].labels.length !== convert[model].channels) {
  3983. throw new Error('channel and label counts mismatch: ' + model);
  3984. }
  3985. var channels = convert[model].channels;
  3986. var labels = convert[model].labels;
  3987. delete convert[model].channels;
  3988. delete convert[model].labels;
  3989. Object.defineProperty(convert[model], 'channels', {
  3990. value: channels
  3991. });
  3992. Object.defineProperty(convert[model], 'labels', {
  3993. value: labels
  3994. });
  3995. }
  3996. }
  3997. convert.rgb.hsl = function (rgb) {
  3998. var r = rgb[0] / 255;
  3999. var g = rgb[1] / 255;
  4000. var b = rgb[2] / 255;
  4001. var min = Math.min(r, g, b);
  4002. var max = Math.max(r, g, b);
  4003. var delta = max - min;
  4004. var h;
  4005. var s;
  4006. var l;
  4007. if (max === min) {
  4008. h = 0;
  4009. } else if (r === max) {
  4010. h = (g - b) / delta;
  4011. } else if (g === max) {
  4012. h = 2 + (b - r) / delta;
  4013. } else if (b === max) {
  4014. h = 4 + (r - g) / delta;
  4015. }
  4016. h = Math.min(h * 60, 360);
  4017. if (h < 0) {
  4018. h += 360;
  4019. }
  4020. l = (min + max) / 2;
  4021. if (max === min) {
  4022. s = 0;
  4023. } else if (l <= 0.5) {
  4024. s = delta / (max + min);
  4025. } else {
  4026. s = delta / (2 - max - min);
  4027. }
  4028. return [h, s * 100, l * 100];
  4029. };
  4030. convert.rgb.hsv = function (rgb) {
  4031. var r = rgb[0];
  4032. var g = rgb[1];
  4033. var b = rgb[2];
  4034. var min = Math.min(r, g, b);
  4035. var max = Math.max(r, g, b);
  4036. var delta = max - min;
  4037. var h;
  4038. var s;
  4039. var v;
  4040. if (max === 0) {
  4041. s = 0;
  4042. } else {
  4043. s = delta / max * 1000 / 10;
  4044. }
  4045. if (max === min) {
  4046. h = 0;
  4047. } else if (r === max) {
  4048. h = (g - b) / delta;
  4049. } else if (g === max) {
  4050. h = 2 + (b - r) / delta;
  4051. } else if (b === max) {
  4052. h = 4 + (r - g) / delta;
  4053. }
  4054. h = Math.min(h * 60, 360);
  4055. if (h < 0) {
  4056. h += 360;
  4057. }
  4058. v = max / 255 * 1000 / 10;
  4059. return [h, s, v];
  4060. };
  4061. convert.rgb.hwb = function (rgb) {
  4062. var r = rgb[0];
  4063. var g = rgb[1];
  4064. var b = rgb[2];
  4065. var h = convert.rgb.hsl(rgb)[0];
  4066. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  4067. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  4068. return [h, w * 100, b * 100];
  4069. };
  4070. convert.rgb.cmyk = function (rgb) {
  4071. var r = rgb[0] / 255;
  4072. var g = rgb[1] / 255;
  4073. var b = rgb[2] / 255;
  4074. var c;
  4075. var m;
  4076. var y;
  4077. var k;
  4078. k = Math.min(1 - r, 1 - g, 1 - b);
  4079. c = (1 - r - k) / (1 - k) || 0;
  4080. m = (1 - g - k) / (1 - k) || 0;
  4081. y = (1 - b - k) / (1 - k) || 0;
  4082. return [c * 100, m * 100, y * 100, k * 100];
  4083. };
  4084. /**
  4085. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  4086. * */
  4087. function comparativeDistance(x, y) {
  4088. return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
  4089. }
  4090. convert.rgb.keyword = function (rgb) {
  4091. var reversed = reverseKeywords[rgb];
  4092. if (reversed) {
  4093. return reversed;
  4094. }
  4095. var currentClosestDistance = Infinity;
  4096. var currentClosestKeyword;
  4097. for (var keyword in colorName) {
  4098. if (colorName.hasOwnProperty(keyword)) {
  4099. var value = colorName[keyword]; // Compute comparative distance
  4100. var distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  4101. if (distance < currentClosestDistance) {
  4102. currentClosestDistance = distance;
  4103. currentClosestKeyword = keyword;
  4104. }
  4105. }
  4106. }
  4107. return currentClosestKeyword;
  4108. };
  4109. convert.keyword.rgb = function (keyword) {
  4110. return colorName[keyword];
  4111. };
  4112. convert.rgb.xyz = function (rgb) {
  4113. var r = rgb[0] / 255;
  4114. var g = rgb[1] / 255;
  4115. var b = rgb[2] / 255; // assume sRGB
  4116. r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
  4117. g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
  4118. b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
  4119. var x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  4120. var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  4121. var z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  4122. return [x * 100, y * 100, z * 100];
  4123. };
  4124. convert.rgb.lab = function (rgb) {
  4125. var xyz = convert.rgb.xyz(rgb);
  4126. var x = xyz[0];
  4127. var y = xyz[1];
  4128. var z = xyz[2];
  4129. var l;
  4130. var a;
  4131. var b;
  4132. x /= 95.047;
  4133. y /= 100;
  4134. z /= 108.883;
  4135. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  4136. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  4137. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  4138. l = 116 * y - 16;
  4139. a = 500 * (x - y);
  4140. b = 200 * (y - z);
  4141. return [l, a, b];
  4142. };
  4143. convert.hsl.rgb = function (hsl) {
  4144. var h = hsl[0] / 360;
  4145. var s = hsl[1] / 100;
  4146. var l = hsl[2] / 100;
  4147. var t1;
  4148. var t2;
  4149. var t3;
  4150. var rgb;
  4151. var val;
  4152. if (s === 0) {
  4153. val = l * 255;
  4154. return [val, val, val];
  4155. }
  4156. if (l < 0.5) {
  4157. t2 = l * (1 + s);
  4158. } else {
  4159. t2 = l + s - l * s;
  4160. }
  4161. t1 = 2 * l - t2;
  4162. rgb = [0, 0, 0];
  4163. for (var i = 0; i < 3; i++) {
  4164. t3 = h + 1 / 3 * -(i - 1);
  4165. if (t3 < 0) {
  4166. t3++;
  4167. }
  4168. if (t3 > 1) {
  4169. t3--;
  4170. }
  4171. if (6 * t3 < 1) {
  4172. val = t1 + (t2 - t1) * 6 * t3;
  4173. } else if (2 * t3 < 1) {
  4174. val = t2;
  4175. } else if (3 * t3 < 2) {
  4176. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  4177. } else {
  4178. val = t1;
  4179. }
  4180. rgb[i] = val * 255;
  4181. }
  4182. return rgb;
  4183. };
  4184. convert.hsl.hsv = function (hsl) {
  4185. var h = hsl[0];
  4186. var s = hsl[1] / 100;
  4187. var l = hsl[2] / 100;
  4188. var smin = s;
  4189. var lmin = Math.max(l, 0.01);
  4190. var sv;
  4191. var v;
  4192. l *= 2;
  4193. s *= l <= 1 ? l : 2 - l;
  4194. smin *= lmin <= 1 ? lmin : 2 - lmin;
  4195. v = (l + s) / 2;
  4196. sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  4197. return [h, sv * 100, v * 100];
  4198. };
  4199. convert.hsv.rgb = function (hsv) {
  4200. var h = hsv[0] / 60;
  4201. var s = hsv[1] / 100;
  4202. var v = hsv[2] / 100;
  4203. var hi = Math.floor(h) % 6;
  4204. var f = h - Math.floor(h);
  4205. var p = 255 * v * (1 - s);
  4206. var q = 255 * v * (1 - s * f);
  4207. var t = 255 * v * (1 - s * (1 - f));
  4208. v *= 255;
  4209. switch (hi) {
  4210. case 0:
  4211. return [v, t, p];
  4212. case 1:
  4213. return [q, v, p];
  4214. case 2:
  4215. return [p, v, t];
  4216. case 3:
  4217. return [p, q, v];
  4218. case 4:
  4219. return [t, p, v];
  4220. case 5:
  4221. return [v, p, q];
  4222. }
  4223. };
  4224. convert.hsv.hsl = function (hsv) {
  4225. var h = hsv[0];
  4226. var s = hsv[1] / 100;
  4227. var v = hsv[2] / 100;
  4228. var vmin = Math.max(v, 0.01);
  4229. var lmin;
  4230. var sl;
  4231. var l;
  4232. l = (2 - s) * v;
  4233. lmin = (2 - s) * vmin;
  4234. sl = s * vmin;
  4235. sl /= lmin <= 1 ? lmin : 2 - lmin;
  4236. sl = sl || 0;
  4237. l /= 2;
  4238. return [h, sl * 100, l * 100];
  4239. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  4240. convert.hwb.rgb = function (hwb) {
  4241. var h = hwb[0] / 360;
  4242. var wh = hwb[1] / 100;
  4243. var bl = hwb[2] / 100;
  4244. var ratio = wh + bl;
  4245. var i;
  4246. var v;
  4247. var f;
  4248. var n; // wh + bl cant be > 1
  4249. if (ratio > 1) {
  4250. wh /= ratio;
  4251. bl /= ratio;
  4252. }
  4253. i = Math.floor(6 * h);
  4254. v = 1 - bl;
  4255. f = 6 * h - i;
  4256. if ((i & 0x01) !== 0) {
  4257. f = 1 - f;
  4258. }
  4259. n = wh + f * (v - wh); // linear interpolation
  4260. var r;
  4261. var g;
  4262. var b;
  4263. switch (i) {
  4264. default:
  4265. case 6:
  4266. case 0:
  4267. r = v;
  4268. g = n;
  4269. b = wh;
  4270. break;
  4271. case 1:
  4272. r = n;
  4273. g = v;
  4274. b = wh;
  4275. break;
  4276. case 2:
  4277. r = wh;
  4278. g = v;
  4279. b = n;
  4280. break;
  4281. case 3:
  4282. r = wh;
  4283. g = n;
  4284. b = v;
  4285. break;
  4286. case 4:
  4287. r = n;
  4288. g = wh;
  4289. b = v;
  4290. break;
  4291. case 5:
  4292. r = v;
  4293. g = wh;
  4294. b = n;
  4295. break;
  4296. }
  4297. return [r * 255, g * 255, b * 255];
  4298. };
  4299. convert.cmyk.rgb = function (cmyk) {
  4300. var c = cmyk[0] / 100;
  4301. var m = cmyk[1] / 100;
  4302. var y = cmyk[2] / 100;
  4303. var k = cmyk[3] / 100;
  4304. var r;
  4305. var g;
  4306. var b;
  4307. r = 1 - Math.min(1, c * (1 - k) + k);
  4308. g = 1 - Math.min(1, m * (1 - k) + k);
  4309. b = 1 - Math.min(1, y * (1 - k) + k);
  4310. return [r * 255, g * 255, b * 255];
  4311. };
  4312. convert.xyz.rgb = function (xyz) {
  4313. var x = xyz[0] / 100;
  4314. var y = xyz[1] / 100;
  4315. var z = xyz[2] / 100;
  4316. var r;
  4317. var g;
  4318. var b;
  4319. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  4320. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  4321. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // assume sRGB
  4322. r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
  4323. g = g > 0.0031308 ? 1.055 * Math.pow(g, 1.0 / 2.4) - 0.055 : g * 12.92;
  4324. b = b > 0.0031308 ? 1.055 * Math.pow(b, 1.0 / 2.4) - 0.055 : b * 12.92;
  4325. r = Math.min(Math.max(0, r), 1);
  4326. g = Math.min(Math.max(0, g), 1);
  4327. b = Math.min(Math.max(0, b), 1);
  4328. return [r * 255, g * 255, b * 255];
  4329. };
  4330. convert.xyz.lab = function (xyz) {
  4331. var x = xyz[0];
  4332. var y = xyz[1];
  4333. var z = xyz[2];
  4334. var l;
  4335. var a;
  4336. var b;
  4337. x /= 95.047;
  4338. y /= 100;
  4339. z /= 108.883;
  4340. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  4341. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  4342. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  4343. l = 116 * y - 16;
  4344. a = 500 * (x - y);
  4345. b = 200 * (y - z);
  4346. return [l, a, b];
  4347. };
  4348. convert.lab.xyz = function (lab) {
  4349. var l = lab[0];
  4350. var a = lab[1];
  4351. var b = lab[2];
  4352. var x;
  4353. var y;
  4354. var z;
  4355. y = (l + 16) / 116;
  4356. x = a / 500 + y;
  4357. z = y - b / 200;
  4358. var y2 = Math.pow(y, 3);
  4359. var x2 = Math.pow(x, 3);
  4360. var z2 = Math.pow(z, 3);
  4361. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  4362. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  4363. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  4364. x *= 95.047;
  4365. y *= 100;
  4366. z *= 108.883;
  4367. return [x, y, z];
  4368. };
  4369. convert.lab.lch = function (lab) {
  4370. var l = lab[0];
  4371. var a = lab[1];
  4372. var b = lab[2];
  4373. var hr;
  4374. var h;
  4375. var c;
  4376. hr = Math.atan2(b, a);
  4377. h = hr * 360 / 2 / Math.PI;
  4378. if (h < 0) {
  4379. h += 360;
  4380. }
  4381. c = Math.sqrt(a * a + b * b);
  4382. return [l, c, h];
  4383. };
  4384. convert.lch.lab = function (lch) {
  4385. var l = lch[0];
  4386. var c = lch[1];
  4387. var h = lch[2];
  4388. var a;
  4389. var b;
  4390. var hr;
  4391. hr = h / 360 * 2 * Math.PI;
  4392. a = c * Math.cos(hr);
  4393. b = c * Math.sin(hr);
  4394. return [l, a, b];
  4395. };
  4396. convert.rgb.ansi16 = function (args) {
  4397. var r = args[0];
  4398. var g = args[1];
  4399. var b = args[2];
  4400. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  4401. value = Math.round(value / 50);
  4402. if (value === 0) {
  4403. return 30;
  4404. }
  4405. var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  4406. if (value === 2) {
  4407. ansi += 60;
  4408. }
  4409. return ansi;
  4410. };
  4411. convert.hsv.ansi16 = function (args) {
  4412. // optimization here; we already know the value and don't need to get
  4413. // it converted for us.
  4414. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  4415. };
  4416. convert.rgb.ansi256 = function (args) {
  4417. var r = args[0];
  4418. var g = args[1];
  4419. var b = args[2]; // we use the extended greyscale palette here, with the exception of
  4420. // black and white. normal palette only has 4 greyscale shades.
  4421. if (r === g && g === b) {
  4422. if (r < 8) {
  4423. return 16;
  4424. }
  4425. if (r > 248) {
  4426. return 231;
  4427. }
  4428. return Math.round((r - 8) / 247 * 24) + 232;
  4429. }
  4430. var ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  4431. return ansi;
  4432. };
  4433. convert.ansi16.rgb = function (args) {
  4434. var color = args % 10; // handle greyscale
  4435. if (color === 0 || color === 7) {
  4436. if (args > 50) {
  4437. color += 3.5;
  4438. }
  4439. color = color / 10.5 * 255;
  4440. return [color, color, color];
  4441. }
  4442. var mult = (~~(args > 50) + 1) * 0.5;
  4443. var r = (color & 1) * mult * 255;
  4444. var g = (color >> 1 & 1) * mult * 255;
  4445. var b = (color >> 2 & 1) * mult * 255;
  4446. return [r, g, b];
  4447. };
  4448. convert.ansi256.rgb = function (args) {
  4449. // handle greyscale
  4450. if (args >= 232) {
  4451. var c = (args - 232) * 10 + 8;
  4452. return [c, c, c];
  4453. }
  4454. args -= 16;
  4455. var rem;
  4456. var r = Math.floor(args / 36) / 5 * 255;
  4457. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  4458. var b = rem % 6 / 5 * 255;
  4459. return [r, g, b];
  4460. };
  4461. convert.rgb.hex = function (args) {
  4462. var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  4463. var string = integer.toString(16).toUpperCase();
  4464. return '000000'.substring(string.length) + string;
  4465. };
  4466. convert.hex.rgb = function (args) {
  4467. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  4468. if (!match) {
  4469. return [0, 0, 0];
  4470. }
  4471. var colorString = match[0];
  4472. if (match[0].length === 3) {
  4473. colorString = colorString.split('').map(function (char) {
  4474. return char + char;
  4475. }).join('');
  4476. }
  4477. var integer = parseInt(colorString, 16);
  4478. var r = integer >> 16 & 0xFF;
  4479. var g = integer >> 8 & 0xFF;
  4480. var b = integer & 0xFF;
  4481. return [r, g, b];
  4482. };
  4483. convert.rgb.hcg = function (rgb) {
  4484. var r = rgb[0] / 255;
  4485. var g = rgb[1] / 255;
  4486. var b = rgb[2] / 255;
  4487. var max = Math.max(Math.max(r, g), b);
  4488. var min = Math.min(Math.min(r, g), b);
  4489. var chroma = max - min;
  4490. var grayscale;
  4491. var hue;
  4492. if (chroma < 1) {
  4493. grayscale = min / (1 - chroma);
  4494. } else {
  4495. grayscale = 0;
  4496. }
  4497. if (chroma <= 0) {
  4498. hue = 0;
  4499. } else if (max === r) {
  4500. hue = (g - b) / chroma % 6;
  4501. } else if (max === g) {
  4502. hue = 2 + (b - r) / chroma;
  4503. } else {
  4504. hue = 4 + (r - g) / chroma + 4;
  4505. }
  4506. hue /= 6;
  4507. hue %= 1;
  4508. return [hue * 360, chroma * 100, grayscale * 100];
  4509. };
  4510. convert.hsl.hcg = function (hsl) {
  4511. var s = hsl[1] / 100;
  4512. var l = hsl[2] / 100;
  4513. var c = 1;
  4514. var f = 0;
  4515. if (l < 0.5) {
  4516. c = 2.0 * s * l;
  4517. } else {
  4518. c = 2.0 * s * (1.0 - l);
  4519. }
  4520. if (c < 1.0) {
  4521. f = (l - 0.5 * c) / (1.0 - c);
  4522. }
  4523. return [hsl[0], c * 100, f * 100];
  4524. };
  4525. convert.hsv.hcg = function (hsv) {
  4526. var s = hsv[1] / 100;
  4527. var v = hsv[2] / 100;
  4528. var c = s * v;
  4529. var f = 0;
  4530. if (c < 1.0) {
  4531. f = (v - c) / (1 - c);
  4532. }
  4533. return [hsv[0], c * 100, f * 100];
  4534. };
  4535. convert.hcg.rgb = function (hcg) {
  4536. var h = hcg[0] / 360;
  4537. var c = hcg[1] / 100;
  4538. var g = hcg[2] / 100;
  4539. if (c === 0.0) {
  4540. return [g * 255, g * 255, g * 255];
  4541. }
  4542. var pure = [0, 0, 0];
  4543. var hi = h % 1 * 6;
  4544. var v = hi % 1;
  4545. var w = 1 - v;
  4546. var mg = 0;
  4547. switch (Math.floor(hi)) {
  4548. case 0:
  4549. pure[0] = 1;
  4550. pure[1] = v;
  4551. pure[2] = 0;
  4552. break;
  4553. case 1:
  4554. pure[0] = w;
  4555. pure[1] = 1;
  4556. pure[2] = 0;
  4557. break;
  4558. case 2:
  4559. pure[0] = 0;
  4560. pure[1] = 1;
  4561. pure[2] = v;
  4562. break;
  4563. case 3:
  4564. pure[0] = 0;
  4565. pure[1] = w;
  4566. pure[2] = 1;
  4567. break;
  4568. case 4:
  4569. pure[0] = v;
  4570. pure[1] = 0;
  4571. pure[2] = 1;
  4572. break;
  4573. default:
  4574. pure[0] = 1;
  4575. pure[1] = 0;
  4576. pure[2] = w;
  4577. }
  4578. mg = (1.0 - c) * g;
  4579. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  4580. };
  4581. convert.hcg.hsv = function (hcg) {
  4582. var c = hcg[1] / 100;
  4583. var g = hcg[2] / 100;
  4584. var v = c + g * (1.0 - c);
  4585. var f = 0;
  4586. if (v > 0.0) {
  4587. f = c / v;
  4588. }
  4589. return [hcg[0], f * 100, v * 100];
  4590. };
  4591. convert.hcg.hsl = function (hcg) {
  4592. var c = hcg[1] / 100;
  4593. var g = hcg[2] / 100;
  4594. var l = g * (1.0 - c) + 0.5 * c;
  4595. var s = 0;
  4596. if (l > 0.0 && l < 0.5) {
  4597. s = c / (2 * l);
  4598. } else if (l >= 0.5 && l < 1.0) {
  4599. s = c / (2 * (1 - l));
  4600. }
  4601. return [hcg[0], s * 100, l * 100];
  4602. };
  4603. convert.hcg.hwb = function (hcg) {
  4604. var c = hcg[1] / 100;
  4605. var g = hcg[2] / 100;
  4606. var v = c + g * (1.0 - c);
  4607. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  4608. };
  4609. convert.hwb.hcg = function (hwb) {
  4610. var w = hwb[1] / 100;
  4611. var b = hwb[2] / 100;
  4612. var v = 1 - b;
  4613. var c = v - w;
  4614. var g = 0;
  4615. if (c < 1) {
  4616. g = (v - c) / (1 - c);
  4617. }
  4618. return [hwb[0], c * 100, g * 100];
  4619. };
  4620. convert.apple.rgb = function (apple) {
  4621. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  4622. };
  4623. convert.rgb.apple = function (rgb) {
  4624. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  4625. };
  4626. convert.gray.rgb = function (args) {
  4627. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  4628. };
  4629. convert.gray.hsl = convert.gray.hsv = function (args) {
  4630. return [0, 0, args[0]];
  4631. };
  4632. convert.gray.hwb = function (gray) {
  4633. return [0, 100, gray[0]];
  4634. };
  4635. convert.gray.cmyk = function (gray) {
  4636. return [0, 0, 0, gray[0]];
  4637. };
  4638. convert.gray.lab = function (gray) {
  4639. return [gray[0], 0, 0];
  4640. };
  4641. convert.gray.hex = function (gray) {
  4642. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  4643. var integer = (val << 16) + (val << 8) + val;
  4644. var string = integer.toString(16).toUpperCase();
  4645. return '000000'.substring(string.length) + string;
  4646. };
  4647. convert.rgb.gray = function (rgb) {
  4648. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  4649. return [val / 255 * 100];
  4650. };
  4651. });
  4652. /*
  4653. this function routes a model to all other models.
  4654. all functions that are routed have a property `.conversion` attached
  4655. to the returned synthetic function. This property is an array
  4656. of strings, each with the steps in between the 'from' and 'to'
  4657. color models (inclusive).
  4658. conversions that are not possible simply are not included.
  4659. */
  4660. // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  4661. var models$1 = Object.keys(conversions);
  4662. function buildGraph() {
  4663. var graph = {};
  4664. for (var len = models$1.length, i = 0; i < len; i++) {
  4665. graph[models$1[i]] = {
  4666. // http://jsperf.com/1-vs-infinity
  4667. // micro-opt, but this is simple.
  4668. distance: -1,
  4669. parent: null
  4670. };
  4671. }
  4672. return graph;
  4673. } // https://en.wikipedia.org/wiki/Breadth-first_search
  4674. function deriveBFS(fromModel) {
  4675. var graph = buildGraph();
  4676. var queue = [fromModel]; // unshift -> queue -> pop
  4677. graph[fromModel].distance = 0;
  4678. while (queue.length) {
  4679. var current = queue.pop();
  4680. var adjacents = Object.keys(conversions[current]);
  4681. for (var len = adjacents.length, i = 0; i < len; i++) {
  4682. var adjacent = adjacents[i];
  4683. var node = graph[adjacent];
  4684. if (node.distance === -1) {
  4685. node.distance = graph[current].distance + 1;
  4686. node.parent = current;
  4687. queue.unshift(adjacent);
  4688. }
  4689. }
  4690. }
  4691. return graph;
  4692. }
  4693. function link(from, to) {
  4694. return function (args) {
  4695. return to(from(args));
  4696. };
  4697. }
  4698. function wrapConversion(toModel, graph) {
  4699. var path$$1 = [graph[toModel].parent, toModel];
  4700. var fn = conversions[graph[toModel].parent][toModel];
  4701. var cur = graph[toModel].parent;
  4702. while (graph[cur].parent) {
  4703. path$$1.unshift(graph[cur].parent);
  4704. fn = link(conversions[graph[cur].parent][cur], fn);
  4705. cur = graph[cur].parent;
  4706. }
  4707. fn.conversion = path$$1;
  4708. return fn;
  4709. }
  4710. var route = function route(fromModel) {
  4711. var graph = deriveBFS(fromModel);
  4712. var conversion = {};
  4713. var models = Object.keys(graph);
  4714. for (var len = models.length, i = 0; i < len; i++) {
  4715. var toModel = models[i];
  4716. var node = graph[toModel];
  4717. if (node.parent === null) {
  4718. // no possible conversion, or this node is the source model.
  4719. continue;
  4720. }
  4721. conversion[toModel] = wrapConversion(toModel, graph);
  4722. }
  4723. return conversion;
  4724. };
  4725. var convert = {};
  4726. var models = Object.keys(conversions);
  4727. function wrapRaw(fn) {
  4728. var wrappedFn = function wrappedFn(args) {
  4729. if (args === undefined || args === null) {
  4730. return args;
  4731. }
  4732. if (arguments.length > 1) {
  4733. args = Array.prototype.slice.call(arguments);
  4734. }
  4735. return fn(args);
  4736. }; // preserve .conversion property if there is one
  4737. if ('conversion' in fn) {
  4738. wrappedFn.conversion = fn.conversion;
  4739. }
  4740. return wrappedFn;
  4741. }
  4742. function wrapRounded(fn) {
  4743. var wrappedFn = function wrappedFn(args) {
  4744. if (args === undefined || args === null) {
  4745. return args;
  4746. }
  4747. if (arguments.length > 1) {
  4748. args = Array.prototype.slice.call(arguments);
  4749. }
  4750. var result = fn(args); // we're assuming the result is an array here.
  4751. // see notice in conversions.js; don't use box types
  4752. // in conversion functions.
  4753. if (typeof result === 'object') {
  4754. for (var len = result.length, i = 0; i < len; i++) {
  4755. result[i] = Math.round(result[i]);
  4756. }
  4757. }
  4758. return result;
  4759. }; // preserve .conversion property if there is one
  4760. if ('conversion' in fn) {
  4761. wrappedFn.conversion = fn.conversion;
  4762. }
  4763. return wrappedFn;
  4764. }
  4765. models.forEach(function (fromModel) {
  4766. convert[fromModel] = {};
  4767. Object.defineProperty(convert[fromModel], 'channels', {
  4768. value: conversions[fromModel].channels
  4769. });
  4770. Object.defineProperty(convert[fromModel], 'labels', {
  4771. value: conversions[fromModel].labels
  4772. });
  4773. var routes = route(fromModel);
  4774. var routeModels = Object.keys(routes);
  4775. routeModels.forEach(function (toModel) {
  4776. var fn = routes[toModel];
  4777. convert[fromModel][toModel] = wrapRounded(fn);
  4778. convert[fromModel][toModel].raw = wrapRaw(fn);
  4779. });
  4780. });
  4781. var colorConvert = convert;
  4782. var ansiStyles = createCommonjsModule(function (module) {
  4783. 'use strict';
  4784. var wrapAnsi16 = function wrapAnsi16(fn, offset) {
  4785. return function () {
  4786. var code = fn.apply(colorConvert, arguments);
  4787. return `\u001B[${code + offset}m`;
  4788. };
  4789. };
  4790. var wrapAnsi256 = function wrapAnsi256(fn, offset) {
  4791. return function () {
  4792. var code = fn.apply(colorConvert, arguments);
  4793. return `\u001B[${38 + offset};5;${code}m`;
  4794. };
  4795. };
  4796. var wrapAnsi16m = function wrapAnsi16m(fn, offset) {
  4797. return function () {
  4798. var rgb = fn.apply(colorConvert, arguments);
  4799. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  4800. };
  4801. };
  4802. function assembleStyles() {
  4803. var styles = {
  4804. modifier: {
  4805. reset: [0, 0],
  4806. // 21 isn't widely supported and 22 does the same thing
  4807. bold: [1, 22],
  4808. dim: [2, 22],
  4809. italic: [3, 23],
  4810. underline: [4, 24],
  4811. inverse: [7, 27],
  4812. hidden: [8, 28],
  4813. strikethrough: [9, 29]
  4814. },
  4815. color: {
  4816. black: [30, 39],
  4817. red: [31, 39],
  4818. green: [32, 39],
  4819. yellow: [33, 39],
  4820. blue: [34, 39],
  4821. magenta: [35, 39],
  4822. cyan: [36, 39],
  4823. white: [37, 39],
  4824. gray: [90, 39],
  4825. // Bright color
  4826. redBright: [91, 39],
  4827. greenBright: [92, 39],
  4828. yellowBright: [93, 39],
  4829. blueBright: [94, 39],
  4830. magentaBright: [95, 39],
  4831. cyanBright: [96, 39],
  4832. whiteBright: [97, 39]
  4833. },
  4834. bgColor: {
  4835. bgBlack: [40, 49],
  4836. bgRed: [41, 49],
  4837. bgGreen: [42, 49],
  4838. bgYellow: [43, 49],
  4839. bgBlue: [44, 49],
  4840. bgMagenta: [45, 49],
  4841. bgCyan: [46, 49],
  4842. bgWhite: [47, 49],
  4843. // Bright color
  4844. bgBlackBright: [100, 49],
  4845. bgRedBright: [101, 49],
  4846. bgGreenBright: [102, 49],
  4847. bgYellowBright: [103, 49],
  4848. bgBlueBright: [104, 49],
  4849. bgMagentaBright: [105, 49],
  4850. bgCyanBright: [106, 49],
  4851. bgWhiteBright: [107, 49]
  4852. }
  4853. }; // Fix humans
  4854. styles.color.grey = styles.color.gray;
  4855. Object.keys(styles).forEach(function (groupName) {
  4856. var group = styles[groupName];
  4857. Object.keys(group).forEach(function (styleName) {
  4858. var style = group[styleName];
  4859. styles[styleName] = {
  4860. open: `\u001B[${style[0]}m`,
  4861. close: `\u001B[${style[1]}m`
  4862. };
  4863. group[styleName] = styles[styleName];
  4864. });
  4865. Object.defineProperty(styles, groupName, {
  4866. value: group,
  4867. enumerable: false
  4868. });
  4869. });
  4870. var rgb2rgb = function rgb2rgb(r, g, b) {
  4871. return [r, g, b];
  4872. };
  4873. styles.color.close = '\u001B[39m';
  4874. styles.bgColor.close = '\u001B[49m';
  4875. styles.color.ansi = {};
  4876. styles.color.ansi256 = {};
  4877. styles.color.ansi16m = {
  4878. rgb: wrapAnsi16m(rgb2rgb, 0)
  4879. };
  4880. styles.bgColor.ansi = {};
  4881. styles.bgColor.ansi256 = {};
  4882. styles.bgColor.ansi16m = {
  4883. rgb: wrapAnsi16m(rgb2rgb, 10)
  4884. };
  4885. var _arr = Object.keys(colorConvert);
  4886. for (var _i = 0; _i < _arr.length; _i++) {
  4887. var key = _arr[_i];
  4888. if (typeof colorConvert[key] !== 'object') {
  4889. continue;
  4890. }
  4891. var suite = colorConvert[key];
  4892. if ('ansi16' in suite) {
  4893. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  4894. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  4895. }
  4896. if ('ansi256' in suite) {
  4897. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  4898. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  4899. }
  4900. if ('rgb' in suite) {
  4901. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  4902. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  4903. }
  4904. }
  4905. return styles;
  4906. }
  4907. Object.defineProperty(module, 'exports', {
  4908. enumerable: true,
  4909. get: assembleStyles
  4910. });
  4911. });
  4912. var hasFlag = function hasFlag(flag, argv) {
  4913. argv = argv || process.argv;
  4914. var terminatorPos = argv.indexOf('--');
  4915. var prefix = /^-{1,2}/.test(flag) ? '' : '--';
  4916. var pos = argv.indexOf(prefix + flag);
  4917. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  4918. };
  4919. var supportsColor = createCommonjsModule(function (module) {
  4920. 'use strict';
  4921. var env = process.env;
  4922. var support = function support(level) {
  4923. if (level === 0) {
  4924. return false;
  4925. }
  4926. return {
  4927. level,
  4928. hasBasic: true,
  4929. has256: level >= 2,
  4930. has16m: level >= 3
  4931. };
  4932. };
  4933. var supportLevel = function () {
  4934. if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
  4935. return 0;
  4936. }
  4937. if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
  4938. return 3;
  4939. }
  4940. if (hasFlag('color=256')) {
  4941. return 2;
  4942. }
  4943. if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
  4944. return 1;
  4945. }
  4946. if (process.stdout && !process.stdout.isTTY) {
  4947. return 0;
  4948. }
  4949. if (process.platform === 'win32') {
  4950. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  4951. // libuv that enables 256 color output on Windows. Anything earlier and it
  4952. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  4953. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  4954. // release that supports 256 colors.
  4955. var osRelease = os.release().split('.');
  4956. if (Number(process.version.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  4957. return 2;
  4958. }
  4959. return 1;
  4960. }
  4961. if ('CI' in env) {
  4962. if ('TRAVIS' in env || env.CI === 'Travis' || 'CIRCLECI' in env) {
  4963. return 1;
  4964. }
  4965. return 0;
  4966. }
  4967. if ('TEAMCITY_VERSION' in env) {
  4968. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  4969. }
  4970. if ('TERM_PROGRAM' in env) {
  4971. var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  4972. switch (env.TERM_PROGRAM) {
  4973. case 'iTerm.app':
  4974. return version >= 3 ? 3 : 2;
  4975. case 'Hyper':
  4976. return 3;
  4977. case 'Apple_Terminal':
  4978. return 2;
  4979. // No default
  4980. }
  4981. }
  4982. if (/^(screen|xterm)-256(?:color)?/.test(env.TERM)) {
  4983. return 2;
  4984. }
  4985. if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) {
  4986. return 1;
  4987. }
  4988. if ('COLORTERM' in env) {
  4989. return 1;
  4990. }
  4991. if (env.TERM === 'dumb') {
  4992. return 0;
  4993. }
  4994. return 0;
  4995. }();
  4996. if ('FORCE_COLOR' in env) {
  4997. supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : supportLevel || 1;
  4998. }
  4999. module.exports = process && support(supportLevel);
  5000. });
  5001. var templates = createCommonjsModule(function (module) {
  5002. 'use strict';
  5003. var TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  5004. var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  5005. var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  5006. var ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  5007. var ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  5008. function unescape(c) {
  5009. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  5010. return String.fromCharCode(parseInt(c.slice(1), 16));
  5011. }
  5012. return ESCAPES.get(c) || c;
  5013. }
  5014. function parseArguments(name, args) {
  5015. var results = [];
  5016. var chunks = args.trim().split(/\s*,\s*/g);
  5017. var matches;
  5018. var _iteratorNormalCompletion = true;
  5019. var _didIteratorError = false;
  5020. var _iteratorError = undefined;
  5021. try {
  5022. for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5023. var chunk = _step.value;
  5024. if (!isNaN(chunk)) {
  5025. results.push(Number(chunk));
  5026. } else if (matches = chunk.match(STRING_REGEX)) {
  5027. results.push(matches[2].replace(ESCAPE_REGEX, function (m, escape, chr) {
  5028. return escape ? unescape(escape) : chr;
  5029. }));
  5030. } else {
  5031. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  5032. }
  5033. }
  5034. } catch (err) {
  5035. _didIteratorError = true;
  5036. _iteratorError = err;
  5037. } finally {
  5038. try {
  5039. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5040. _iterator.return();
  5041. }
  5042. } finally {
  5043. if (_didIteratorError) {
  5044. throw _iteratorError;
  5045. }
  5046. }
  5047. }
  5048. return results;
  5049. }
  5050. function parseStyle(style) {
  5051. STYLE_REGEX.lastIndex = 0;
  5052. var results = [];
  5053. var matches;
  5054. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  5055. var name = matches[1];
  5056. if (matches[2]) {
  5057. var args = parseArguments(name, matches[2]);
  5058. results.push([name].concat(args));
  5059. } else {
  5060. results.push([name]);
  5061. }
  5062. }
  5063. return results;
  5064. }
  5065. function buildStyle(chalk, styles) {
  5066. var enabled = {};
  5067. var _iteratorNormalCompletion2 = true;
  5068. var _didIteratorError2 = false;
  5069. var _iteratorError2 = undefined;
  5070. try {
  5071. for (var _iterator2 = styles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  5072. var layer = _step2.value;
  5073. var _iteratorNormalCompletion3 = true;
  5074. var _didIteratorError3 = false;
  5075. var _iteratorError3 = undefined;
  5076. try {
  5077. for (var _iterator3 = layer.styles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  5078. var style = _step3.value;
  5079. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  5080. }
  5081. } catch (err) {
  5082. _didIteratorError3 = true;
  5083. _iteratorError3 = err;
  5084. } finally {
  5085. try {
  5086. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  5087. _iterator3.return();
  5088. }
  5089. } finally {
  5090. if (_didIteratorError3) {
  5091. throw _iteratorError3;
  5092. }
  5093. }
  5094. }
  5095. }
  5096. } catch (err) {
  5097. _didIteratorError2 = true;
  5098. _iteratorError2 = err;
  5099. } finally {
  5100. try {
  5101. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  5102. _iterator2.return();
  5103. }
  5104. } finally {
  5105. if (_didIteratorError2) {
  5106. throw _iteratorError2;
  5107. }
  5108. }
  5109. }
  5110. var current = chalk;
  5111. var _arr = Object.keys(enabled);
  5112. for (var _i = 0; _i < _arr.length; _i++) {
  5113. var styleName = _arr[_i];
  5114. if (Array.isArray(enabled[styleName])) {
  5115. if (!(styleName in current)) {
  5116. throw new Error(`Unknown Chalk style: ${styleName}`);
  5117. }
  5118. if (enabled[styleName].length > 0) {
  5119. current = current[styleName].apply(current, enabled[styleName]);
  5120. } else {
  5121. current = current[styleName];
  5122. }
  5123. }
  5124. }
  5125. return current;
  5126. }
  5127. module.exports = function (chalk, tmp) {
  5128. var styles = [];
  5129. var chunks = [];
  5130. var chunk = []; // eslint-disable-next-line max-params
  5131. tmp.replace(TEMPLATE_REGEX, function (m, escapeChar, inverse, style, close, chr) {
  5132. if (escapeChar) {
  5133. chunk.push(unescape(escapeChar));
  5134. } else if (style) {
  5135. var str = chunk.join('');
  5136. chunk = [];
  5137. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  5138. styles.push({
  5139. inverse,
  5140. styles: parseStyle(style)
  5141. });
  5142. } else if (close) {
  5143. if (styles.length === 0) {
  5144. throw new Error('Found extraneous } in Chalk template literal');
  5145. }
  5146. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  5147. chunk = [];
  5148. styles.pop();
  5149. } else {
  5150. chunk.push(chr);
  5151. }
  5152. });
  5153. chunks.push(chunk.join(''));
  5154. if (styles.length > 0) {
  5155. var errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  5156. throw new Error(errMsg);
  5157. }
  5158. return chunks.join('');
  5159. };
  5160. });
  5161. var chalk = createCommonjsModule(function (module) {
  5162. 'use strict';
  5163. var isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  5164. var levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  5165. var skipModels = new Set(['gray']);
  5166. var styles = Object.create(null);
  5167. function applyOptions(obj, options) {
  5168. options = options || {}; // Detect level if not set manually
  5169. var scLevel = supportsColor ? supportsColor.level : 0;
  5170. obj.level = options.level === undefined ? scLevel : options.level;
  5171. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  5172. }
  5173. function Chalk(options) {
  5174. // We check for this.template here since calling `chalk.constructor()`
  5175. // by itself will have a `this` of a previously constructed chalk object
  5176. if (!this || !(this instanceof Chalk) || this.template) {
  5177. var _chalk = {};
  5178. applyOptions(_chalk, options);
  5179. _chalk.template = function () {
  5180. var args = [].slice.call(arguments);
  5181. return chalkTag.apply(null, [_chalk.template].concat(args));
  5182. };
  5183. Object.setPrototypeOf(_chalk, Chalk.prototype);
  5184. Object.setPrototypeOf(_chalk.template, _chalk);
  5185. _chalk.template.constructor = Chalk;
  5186. return _chalk.template;
  5187. }
  5188. applyOptions(this, options);
  5189. } // Use bright blue on Windows as the normal blue color is illegible
  5190. if (isSimpleWindowsTerm) {
  5191. ansiStyles.blue.open = '\u001B[94m';
  5192. }
  5193. var _arr = Object.keys(ansiStyles);
  5194. var _loop = function _loop() {
  5195. var key = _arr[_i];
  5196. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  5197. styles[key] = {
  5198. get() {
  5199. var codes = ansiStyles[key];
  5200. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  5201. }
  5202. };
  5203. };
  5204. for (var _i = 0; _i < _arr.length; _i++) {
  5205. _loop();
  5206. }
  5207. styles.visible = {
  5208. get() {
  5209. return build.call(this, this._styles || [], true, 'visible');
  5210. }
  5211. };
  5212. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  5213. var _arr2 = Object.keys(ansiStyles.color.ansi);
  5214. var _loop2 = function _loop2() {
  5215. var model = _arr2[_i2];
  5216. if (skipModels.has(model)) {
  5217. return "continue";
  5218. }
  5219. styles[model] = {
  5220. get() {
  5221. var level = this.level;
  5222. return function () {
  5223. var open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  5224. var codes = {
  5225. open,
  5226. close: ansiStyles.color.close,
  5227. closeRe: ansiStyles.color.closeRe
  5228. };
  5229. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  5230. };
  5231. }
  5232. };
  5233. };
  5234. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  5235. var _ret = _loop2();
  5236. if (_ret === "continue") continue;
  5237. }
  5238. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  5239. var _arr3 = Object.keys(ansiStyles.bgColor.ansi);
  5240. var _loop3 = function _loop3() {
  5241. var model = _arr3[_i3];
  5242. if (skipModels.has(model)) {
  5243. return "continue";
  5244. }
  5245. var bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  5246. styles[bgModel] = {
  5247. get() {
  5248. var level = this.level;
  5249. return function () {
  5250. var open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  5251. var codes = {
  5252. open,
  5253. close: ansiStyles.bgColor.close,
  5254. closeRe: ansiStyles.bgColor.closeRe
  5255. };
  5256. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  5257. };
  5258. }
  5259. };
  5260. };
  5261. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  5262. var _ret2 = _loop3();
  5263. if (_ret2 === "continue") continue;
  5264. }
  5265. var proto = Object.defineProperties(function () {}, styles);
  5266. function build(_styles, _empty, key) {
  5267. var builder = function builder() {
  5268. return applyStyle.apply(builder, arguments);
  5269. };
  5270. builder._styles = _styles;
  5271. builder._empty = _empty;
  5272. var self = this;
  5273. Object.defineProperty(builder, 'level', {
  5274. enumerable: true,
  5275. get() {
  5276. return self.level;
  5277. },
  5278. set(level) {
  5279. self.level = level;
  5280. }
  5281. });
  5282. Object.defineProperty(builder, 'enabled', {
  5283. enumerable: true,
  5284. get() {
  5285. return self.enabled;
  5286. },
  5287. set(enabled) {
  5288. self.enabled = enabled;
  5289. }
  5290. }); // See below for fix regarding invisible grey/dim combination on Windows
  5291. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  5292. // no way to create a function with a different prototype
  5293. builder.__proto__ = proto; // eslint-disable-line no-proto
  5294. return builder;
  5295. }
  5296. function applyStyle() {
  5297. // Support varags, but simply cast to string in case there's only one arg
  5298. var args = arguments;
  5299. var argsLen = args.length;
  5300. var str = String(arguments[0]);
  5301. if (argsLen === 0) {
  5302. return '';
  5303. }
  5304. if (argsLen > 1) {
  5305. // Don't slice `arguments`, it prevents V8 optimizations
  5306. for (var a = 1; a < argsLen; a++) {
  5307. str += ' ' + args[a];
  5308. }
  5309. }
  5310. if (!this.enabled || this.level <= 0 || !str) {
  5311. return this._empty ? '' : str;
  5312. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  5313. // see https://github.com/chalk/chalk/issues/58
  5314. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  5315. var originalDim = ansiStyles.dim.open;
  5316. if (isSimpleWindowsTerm && this.hasGrey) {
  5317. ansiStyles.dim.open = '';
  5318. }
  5319. var _iteratorNormalCompletion = true;
  5320. var _didIteratorError = false;
  5321. var _iteratorError = undefined;
  5322. try {
  5323. for (var _iterator = this._styles.slice().reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5324. var code = _step.value;
  5325. // Replace any instances already present with a re-opening code
  5326. // otherwise only the part of the string until said closing code
  5327. // will be colored, and the rest will simply be 'plain'.
  5328. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  5329. // after next line to fix a bleed issue on macOS
  5330. // https://github.com/chalk/chalk/pull/92
  5331. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  5332. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  5333. } catch (err) {
  5334. _didIteratorError = true;
  5335. _iteratorError = err;
  5336. } finally {
  5337. try {
  5338. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5339. _iterator.return();
  5340. }
  5341. } finally {
  5342. if (_didIteratorError) {
  5343. throw _iteratorError;
  5344. }
  5345. }
  5346. }
  5347. ansiStyles.dim.open = originalDim;
  5348. return str;
  5349. }
  5350. function chalkTag(chalk, strings) {
  5351. if (!Array.isArray(strings)) {
  5352. // If chalk() was called by itself or with a string,
  5353. // return the string itself as a string.
  5354. return [].slice.call(arguments, 1).join(' ');
  5355. }
  5356. var args = [].slice.call(arguments, 2);
  5357. var parts = [strings.raw[0]];
  5358. for (var i = 1; i < strings.length; i++) {
  5359. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  5360. parts.push(String(strings.raw[i]));
  5361. }
  5362. return templates(chalk, parts.join(''));
  5363. }
  5364. Object.defineProperties(Chalk.prototype, styles);
  5365. module.exports = Chalk(); // eslint-disable-line new-cap
  5366. module.exports.supportsColor = supportsColor;
  5367. module.exports.default = module.exports; // For TypeScript
  5368. });
  5369. var lib$2 = createCommonjsModule(function (module, exports) {
  5370. "use strict";
  5371. Object.defineProperty(exports, "__esModule", {
  5372. value: true
  5373. });
  5374. exports.shouldHighlight = shouldHighlight;
  5375. exports.getChalk = getChalk;
  5376. exports.default = highlight;
  5377. function _jsTokens() {
  5378. var data = _interopRequireWildcard$$1(jsTokens);
  5379. _jsTokens = function _jsTokens() {
  5380. return data;
  5381. };
  5382. return data;
  5383. }
  5384. function _esutils() {
  5385. var data = _interopRequireDefault$$1(utils);
  5386. _esutils = function _esutils() {
  5387. return data;
  5388. };
  5389. return data;
  5390. }
  5391. function _chalk() {
  5392. var data = _interopRequireDefault$$1(chalk);
  5393. _chalk = function _chalk() {
  5394. return data;
  5395. };
  5396. return data;
  5397. }
  5398. function _interopRequireDefault$$1(obj) {
  5399. return obj && obj.__esModule ? obj : {
  5400. default: obj
  5401. };
  5402. }
  5403. function _interopRequireWildcard$$1(obj) {
  5404. if (obj && obj.__esModule) {
  5405. return obj;
  5406. } else {
  5407. var newObj = {};
  5408. if (obj != null) {
  5409. for (var key in obj) {
  5410. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  5411. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
  5412. if (desc.get || desc.set) {
  5413. Object.defineProperty(newObj, key, desc);
  5414. } else {
  5415. newObj[key] = obj[key];
  5416. }
  5417. }
  5418. }
  5419. }
  5420. newObj.default = obj;
  5421. return newObj;
  5422. }
  5423. }
  5424. function getDefs(chalk$$1) {
  5425. return {
  5426. keyword: chalk$$1.cyan,
  5427. capitalized: chalk$$1.yellow,
  5428. jsx_tag: chalk$$1.yellow,
  5429. punctuator: chalk$$1.yellow,
  5430. number: chalk$$1.magenta,
  5431. string: chalk$$1.green,
  5432. regex: chalk$$1.magenta,
  5433. comment: chalk$$1.grey,
  5434. invalid: chalk$$1.white.bgRed.bold
  5435. };
  5436. }
  5437. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  5438. var JSX_TAG = /^[a-z][\w-]*$/i;
  5439. var BRACKET = /^[()[\]{}]$/;
  5440. function getTokenType(match) {
  5441. var _match$slice = match.slice(-2),
  5442. _match$slice2 = _slicedToArray(_match$slice, 2),
  5443. offset = _match$slice2[0],
  5444. text = _match$slice2[1];
  5445. var token = (0, _jsTokens().matchToToken)(match);
  5446. if (token.type === "name") {
  5447. if (_esutils().default.keyword.isReservedWordES6(token.value)) {
  5448. return "keyword";
  5449. }
  5450. if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
  5451. return "jsx_tag";
  5452. }
  5453. if (token.value[0] !== token.value[0].toLowerCase()) {
  5454. return "capitalized";
  5455. }
  5456. }
  5457. if (token.type === "punctuator" && BRACKET.test(token.value)) {
  5458. return "bracket";
  5459. }
  5460. if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
  5461. return "punctuator";
  5462. }
  5463. return token.type;
  5464. }
  5465. function highlightTokens(defs, text) {
  5466. return text.replace(_jsTokens().default, function () {
  5467. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  5468. args[_key] = arguments[_key];
  5469. }
  5470. var type = getTokenType(args);
  5471. var colorize = defs[type];
  5472. if (colorize) {
  5473. return args[0].split(NEWLINE).map(function (str) {
  5474. return colorize(str);
  5475. }).join("\n");
  5476. } else {
  5477. return args[0];
  5478. }
  5479. });
  5480. }
  5481. function shouldHighlight(options) {
  5482. return _chalk().default.supportsColor || options.forceColor;
  5483. }
  5484. function getChalk(options) {
  5485. var chalk$$1 = _chalk().default;
  5486. if (options.forceColor) {
  5487. chalk$$1 = new (_chalk().default.constructor)({
  5488. enabled: true,
  5489. level: 1
  5490. });
  5491. }
  5492. return chalk$$1;
  5493. }
  5494. function highlight(code) {
  5495. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  5496. if (shouldHighlight(options)) {
  5497. var chalk$$1 = getChalk(options);
  5498. var defs = getDefs(chalk$$1);
  5499. return highlightTokens(defs, code);
  5500. } else {
  5501. return code;
  5502. }
  5503. }
  5504. });
  5505. unwrapExports(lib$2);
  5506. var lib$1 = createCommonjsModule(function (module, exports) {
  5507. "use strict";
  5508. Object.defineProperty(exports, "__esModule", {
  5509. value: true
  5510. });
  5511. exports.codeFrameColumns = codeFrameColumns;
  5512. exports.default = _default;
  5513. function _highlight() {
  5514. var data = _interopRequireWildcard(lib$2);
  5515. _highlight = function _highlight() {
  5516. return data;
  5517. };
  5518. return data;
  5519. }
  5520. function _interopRequireWildcard(obj) {
  5521. if (obj && obj.__esModule) {
  5522. return obj;
  5523. } else {
  5524. var newObj = {};
  5525. if (obj != null) {
  5526. for (var key in obj) {
  5527. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  5528. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
  5529. if (desc.get || desc.set) {
  5530. Object.defineProperty(newObj, key, desc);
  5531. } else {
  5532. newObj[key] = obj[key];
  5533. }
  5534. }
  5535. }
  5536. }
  5537. newObj.default = obj;
  5538. return newObj;
  5539. }
  5540. }
  5541. var deprecationWarningShown = false;
  5542. function getDefs(chalk) {
  5543. return {
  5544. gutter: chalk.grey,
  5545. marker: chalk.red.bold,
  5546. message: chalk.red.bold
  5547. };
  5548. }
  5549. var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  5550. function getMarkerLines(loc, source, opts) {
  5551. var startLoc = Object.assign({
  5552. column: 0,
  5553. line: -1
  5554. }, loc.start);
  5555. var endLoc = Object.assign({}, startLoc, loc.end);
  5556. var _ref = opts || {},
  5557. _ref$linesAbove = _ref.linesAbove,
  5558. linesAbove = _ref$linesAbove === void 0 ? 2 : _ref$linesAbove,
  5559. _ref$linesBelow = _ref.linesBelow,
  5560. linesBelow = _ref$linesBelow === void 0 ? 3 : _ref$linesBelow;
  5561. var startLine = startLoc.line;
  5562. var startColumn = startLoc.column;
  5563. var endLine = endLoc.line;
  5564. var endColumn = endLoc.column;
  5565. var start = Math.max(startLine - (linesAbove + 1), 0);
  5566. var end = Math.min(source.length, endLine + linesBelow);
  5567. if (startLine === -1) {
  5568. start = 0;
  5569. }
  5570. if (endLine === -1) {
  5571. end = source.length;
  5572. }
  5573. var lineDiff = endLine - startLine;
  5574. var markerLines = {};
  5575. if (lineDiff) {
  5576. for (var i = 0; i <= lineDiff; i++) {
  5577. var lineNumber = i + startLine;
  5578. if (!startColumn) {
  5579. markerLines[lineNumber] = true;
  5580. } else if (i === 0) {
  5581. var sourceLength = source[lineNumber - 1].length;
  5582. markerLines[lineNumber] = [startColumn, sourceLength - startColumn];
  5583. } else if (i === lineDiff) {
  5584. markerLines[lineNumber] = [0, endColumn];
  5585. } else {
  5586. var _sourceLength = source[lineNumber - i].length;
  5587. markerLines[lineNumber] = [0, _sourceLength];
  5588. }
  5589. }
  5590. } else {
  5591. if (startColumn === endColumn) {
  5592. if (startColumn) {
  5593. markerLines[startLine] = [startColumn, 0];
  5594. } else {
  5595. markerLines[startLine] = true;
  5596. }
  5597. } else {
  5598. markerLines[startLine] = [startColumn, endColumn - startColumn];
  5599. }
  5600. }
  5601. return {
  5602. start,
  5603. end,
  5604. markerLines
  5605. };
  5606. }
  5607. function codeFrameColumns(rawLines, loc) {
  5608. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  5609. var highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight().shouldHighlight)(opts);
  5610. var chalk = (0, _highlight().getChalk)(opts);
  5611. var defs = getDefs(chalk);
  5612. var maybeHighlight = function maybeHighlight(chalkFn, string) {
  5613. return highlighted ? chalkFn(string) : string;
  5614. };
  5615. if (highlighted) rawLines = (0, _highlight().default)(rawLines, opts);
  5616. var lines = rawLines.split(NEWLINE);
  5617. var _getMarkerLines = getMarkerLines(loc, lines, opts),
  5618. start = _getMarkerLines.start,
  5619. end = _getMarkerLines.end,
  5620. markerLines = _getMarkerLines.markerLines;
  5621. var hasColumns = loc.start && typeof loc.start.column === "number";
  5622. var numberMaxWidth = String(end).length;
  5623. var frame = lines.slice(start, end).map(function (line, index) {
  5624. var number = start + 1 + index;
  5625. var paddedNumber = ` ${number}`.slice(-numberMaxWidth);
  5626. var gutter = ` ${paddedNumber} | `;
  5627. var hasMarker = markerLines[number];
  5628. var lastMarkerLine = !markerLines[number + 1];
  5629. if (hasMarker) {
  5630. var markerLine = "";
  5631. if (Array.isArray(hasMarker)) {
  5632. var markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  5633. var numberOfMarkers = hasMarker[1] || 1;
  5634. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  5635. if (lastMarkerLine && opts.message) {
  5636. markerLine += " " + maybeHighlight(defs.message, opts.message);
  5637. }
  5638. }
  5639. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
  5640. } else {
  5641. return ` ${maybeHighlight(defs.gutter, gutter)}${line}`;
  5642. }
  5643. }).join("\n");
  5644. if (opts.message && !hasColumns) {
  5645. frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
  5646. }
  5647. if (highlighted) {
  5648. return chalk.reset(frame);
  5649. } else {
  5650. return frame;
  5651. }
  5652. }
  5653. function _default(rawLines, lineNumber, colNumber) {
  5654. var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  5655. if (!deprecationWarningShown) {
  5656. deprecationWarningShown = true;
  5657. var message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
  5658. if (process.emitWarning) {
  5659. process.emitWarning(message, "DeprecationWarning");
  5660. } else {
  5661. var deprecationError = new Error(message);
  5662. deprecationError.name = "DeprecationWarning";
  5663. console.warn(new Error(message));
  5664. }
  5665. }
  5666. colNumber = Math.max(colNumber, 0);
  5667. var location = {
  5668. start: {
  5669. column: colNumber,
  5670. line: lineNumber
  5671. }
  5672. };
  5673. return codeFrameColumns(rawLines, location, opts);
  5674. }
  5675. });
  5676. unwrapExports(lib$1);
  5677. var ConfigError$1 = errors.ConfigError;
  5678. var locStart = loc.locStart;
  5679. var locEnd = loc.locEnd; // Use defineProperties()/getOwnPropertyDescriptor() to prevent
  5680. // triggering the parsers getters.
  5681. var ownNames = Object.getOwnPropertyNames;
  5682. var ownDescriptor = Object.getOwnPropertyDescriptor;
  5683. function getParsers(options) {
  5684. var parsers = {};
  5685. var _iteratorNormalCompletion = true;
  5686. var _didIteratorError = false;
  5687. var _iteratorError = undefined;
  5688. try {
  5689. for (var _iterator = options.plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  5690. var plugin = _step.value;
  5691. if (!plugin.parsers) {
  5692. continue;
  5693. }
  5694. var _iteratorNormalCompletion2 = true;
  5695. var _didIteratorError2 = false;
  5696. var _iteratorError2 = undefined;
  5697. try {
  5698. for (var _iterator2 = ownNames(plugin.parsers)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  5699. var name = _step2.value;
  5700. Object.defineProperty(parsers, name, ownDescriptor(plugin.parsers, name));
  5701. }
  5702. } catch (err) {
  5703. _didIteratorError2 = true;
  5704. _iteratorError2 = err;
  5705. } finally {
  5706. try {
  5707. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  5708. _iterator2.return();
  5709. }
  5710. } finally {
  5711. if (_didIteratorError2) {
  5712. throw _iteratorError2;
  5713. }
  5714. }
  5715. }
  5716. }
  5717. } catch (err) {
  5718. _didIteratorError = true;
  5719. _iteratorError = err;
  5720. } finally {
  5721. try {
  5722. if (!_iteratorNormalCompletion && _iterator.return != null) {
  5723. _iterator.return();
  5724. }
  5725. } finally {
  5726. if (_didIteratorError) {
  5727. throw _iteratorError;
  5728. }
  5729. }
  5730. }
  5731. return parsers;
  5732. }
  5733. function resolveParser$1(opts, parsers) {
  5734. parsers = parsers || getParsers(opts);
  5735. if (typeof opts.parser === "function") {
  5736. // Custom parser API always works with JavaScript.
  5737. return {
  5738. parse: opts.parser,
  5739. astFormat: "estree",
  5740. locStart,
  5741. locEnd
  5742. };
  5743. }
  5744. if (typeof opts.parser === "string") {
  5745. if (parsers.hasOwnProperty(opts.parser)) {
  5746. return parsers[opts.parser];
  5747. }
  5748. try {
  5749. return {
  5750. parse: require(path.resolve(process.cwd(), opts.parser)),
  5751. astFormat: "estree",
  5752. locStart,
  5753. locEnd
  5754. };
  5755. } catch (err) {
  5756. /* istanbul ignore next */
  5757. throw new ConfigError$1(`Couldn't resolve parser "${opts.parser}"`);
  5758. }
  5759. }
  5760. }
  5761. function parse$2(text, opts) {
  5762. var parsers = getParsers(opts); // Create a new object {parserName: parseFn}. Uses defineProperty() to only call
  5763. // the parsers getters when actually calling the parser `parse` function.
  5764. var parsersForCustomParserApi = Object.keys(parsers).reduce(function (object, parserName) {
  5765. return Object.defineProperty(object, parserName, {
  5766. enumerable: true,
  5767. get() {
  5768. return parsers[parserName].parse;
  5769. }
  5770. });
  5771. }, {});
  5772. var parser = resolveParser$1(opts, parsers);
  5773. try {
  5774. if (parser.preprocess) {
  5775. text = parser.preprocess(text, opts);
  5776. }
  5777. return {
  5778. text,
  5779. ast: parser.parse(text, parsersForCustomParserApi, opts)
  5780. };
  5781. } catch (error) {
  5782. var loc$$1 = error.loc;
  5783. if (loc$$1) {
  5784. var codeFrame = lib$1;
  5785. error.codeFrame = codeFrame.codeFrameColumns(text, loc$$1, {
  5786. highlightCode: true
  5787. });
  5788. error.message += "\n" + error.codeFrame;
  5789. throw error;
  5790. }
  5791. /* istanbul ignore next */
  5792. throw error.stack;
  5793. }
  5794. }
  5795. var parser = {
  5796. parse: parse$2,
  5797. resolveParser: resolveParser$1
  5798. };
  5799. var UndefinedParserError = errors.UndefinedParserError;
  5800. var getSupportInfo$1 = support.getSupportInfo;
  5801. var resolveParser = parser.resolveParser;
  5802. var hiddenDefaults = {
  5803. astFormat: "estree",
  5804. printer: {},
  5805. locStart: null,
  5806. locEnd: null
  5807. }; // Copy options and fill in default values.
  5808. function normalize(options, opts) {
  5809. opts = opts || {};
  5810. var rawOptions = Object.assign({}, options);
  5811. var supportOptions = getSupportInfo$1(null, {
  5812. plugins: options.plugins,
  5813. showUnreleased: true,
  5814. showDeprecated: true
  5815. }).options;
  5816. var defaults = supportOptions.reduce(function (reduced, optionInfo) {
  5817. return Object.assign(reduced, {
  5818. [optionInfo.name]: optionInfo.default
  5819. });
  5820. }, Object.assign({}, hiddenDefaults));
  5821. if (!rawOptions.parser) {
  5822. if (!rawOptions.filepath) {
  5823. var logger = opts.logger || console;
  5824. logger.warn("No parser and no filepath given, using 'babylon' the parser now " + "but this will throw an error in the future. " + "Please specify a parser or a filepath so one can be inferred.");
  5825. rawOptions.parser = "babylon";
  5826. } else {
  5827. rawOptions.parser = inferParser(rawOptions.filepath, rawOptions.plugins);
  5828. if (!rawOptions.parser) {
  5829. throw new UndefinedParserError(`No parser could be inferred for file: ${rawOptions.filepath}`);
  5830. }
  5831. }
  5832. }
  5833. var parser$$1 = resolveParser(optionsNormalizer.normalizeApiOptions(rawOptions, [supportOptions.find(function (x) {
  5834. return x.name === "parser";
  5835. })], {
  5836. passThrough: true,
  5837. logger: false
  5838. }));
  5839. rawOptions.astFormat = parser$$1.astFormat;
  5840. rawOptions.locEnd = parser$$1.locEnd;
  5841. rawOptions.locStart = parser$$1.locStart;
  5842. var plugin = getPlugin(rawOptions);
  5843. rawOptions.printer = plugin.printers[rawOptions.astFormat];
  5844. var pluginDefaults = supportOptions.filter(function (optionInfo) {
  5845. return optionInfo.pluginDefaults && optionInfo.pluginDefaults[plugin.name];
  5846. }).reduce(function (reduced, optionInfo) {
  5847. return Object.assign(reduced, {
  5848. [optionInfo.name]: optionInfo.pluginDefaults[plugin.name]
  5849. });
  5850. }, {});
  5851. var mixedDefaults = Object.assign({}, defaults, pluginDefaults);
  5852. Object.keys(mixedDefaults).forEach(function (k) {
  5853. if (rawOptions[k] == null) {
  5854. rawOptions[k] = mixedDefaults[k];
  5855. }
  5856. });
  5857. if (rawOptions.parser === "json") {
  5858. rawOptions.trailingComma = "none";
  5859. }
  5860. return optionsNormalizer.normalizeApiOptions(rawOptions, supportOptions, Object.assign({
  5861. passThrough: Object.keys(hiddenDefaults)
  5862. }, opts));
  5863. }
  5864. function getPlugin(options) {
  5865. var astFormat = options.astFormat;
  5866. if (!astFormat) {
  5867. throw new Error("getPlugin() requires astFormat to be set");
  5868. }
  5869. var printerPlugin = options.plugins.find(function (plugin) {
  5870. return plugin.printers && plugin.printers[astFormat];
  5871. });
  5872. if (!printerPlugin) {
  5873. throw new Error(`Couldn't find plugin for AST format "${astFormat}"`);
  5874. }
  5875. return printerPlugin;
  5876. }
  5877. function inferParser(filepath, plugins) {
  5878. var extension = path.extname(filepath);
  5879. var filename = path.basename(filepath).toLowerCase();
  5880. var language = getSupportInfo$1(null, {
  5881. plugins
  5882. }).languages.find(function (language) {
  5883. return language.since !== null && (language.extensions && language.extensions.indexOf(extension) > -1 || language.filenames && language.filenames.find(function (name) {
  5884. return name.toLowerCase() === filename;
  5885. }));
  5886. });
  5887. return language && language.parsers[0];
  5888. }
  5889. var options = {
  5890. normalize,
  5891. hiddenDefaults,
  5892. inferParser
  5893. };
  5894. function massageAST(ast, options, parent) {
  5895. if (Array.isArray(ast)) {
  5896. return ast.map(function (e) {
  5897. return massageAST(e, options, parent);
  5898. }).filter(function (e) {
  5899. return e;
  5900. });
  5901. }
  5902. if (!ast || typeof ast !== "object") {
  5903. return ast;
  5904. }
  5905. var newObj = {};
  5906. var _arr = Object.keys(ast);
  5907. for (var _i = 0; _i < _arr.length; _i++) {
  5908. var key = _arr[_i];
  5909. if (typeof ast[key] !== "function") {
  5910. newObj[key] = massageAST(ast[key], options, ast);
  5911. }
  5912. }
  5913. if (options.printer.massageAstNode) {
  5914. var result = options.printer.massageAstNode(ast, newObj, parent);
  5915. if (result === null) {
  5916. return undefined;
  5917. }
  5918. if (result) {
  5919. return result;
  5920. }
  5921. }
  5922. return newObj;
  5923. }
  5924. var massageAst = massageAST;
  5925. function assertDoc(val) {
  5926. /* istanbul ignore if */
  5927. if (!(typeof val === "string" || val != null && typeof val.type === "string")) {
  5928. throw new Error("Value " + JSON.stringify(val) + " is not a valid document");
  5929. }
  5930. }
  5931. function concat$1(parts) {
  5932. if (process.env.NODE_ENV !== "production") {
  5933. parts.forEach(assertDoc);
  5934. } // We cannot do this until we change `printJSXElement` to not
  5935. // access the internals of a document directly.
  5936. // if(parts.length === 1) {
  5937. // // If it's a single document, no need to concat it.
  5938. // return parts[0];
  5939. // }
  5940. return {
  5941. type: "concat",
  5942. parts
  5943. };
  5944. }
  5945. function indent$1(contents) {
  5946. if (process.env.NODE_ENV !== "production") {
  5947. assertDoc(contents);
  5948. }
  5949. return {
  5950. type: "indent",
  5951. contents
  5952. };
  5953. }
  5954. function align(n, contents) {
  5955. if (process.env.NODE_ENV !== "production") {
  5956. assertDoc(contents);
  5957. }
  5958. return {
  5959. type: "align",
  5960. contents,
  5961. n
  5962. };
  5963. }
  5964. function group(contents, opts) {
  5965. opts = opts || {};
  5966. if (process.env.NODE_ENV !== "production") {
  5967. assertDoc(contents);
  5968. }
  5969. return {
  5970. type: "group",
  5971. contents: contents,
  5972. break: !!opts.shouldBreak,
  5973. expandedStates: opts.expandedStates
  5974. };
  5975. }
  5976. function dedentToRoot(contents) {
  5977. return align(-Infinity, contents);
  5978. }
  5979. function markAsRoot(contents) {
  5980. return align({
  5981. type: "root"
  5982. }, contents);
  5983. }
  5984. function dedent$1(contents) {
  5985. return align(-1, contents);
  5986. }
  5987. function conditionalGroup(states, opts) {
  5988. return group(states[0], Object.assign(opts || {}, {
  5989. expandedStates: states
  5990. }));
  5991. }
  5992. function fill(parts) {
  5993. if (process.env.NODE_ENV !== "production") {
  5994. parts.forEach(assertDoc);
  5995. }
  5996. return {
  5997. type: "fill",
  5998. parts
  5999. };
  6000. }
  6001. function ifBreak(breakContents, flatContents) {
  6002. if (process.env.NODE_ENV !== "production") {
  6003. if (breakContents) {
  6004. assertDoc(breakContents);
  6005. }
  6006. if (flatContents) {
  6007. assertDoc(flatContents);
  6008. }
  6009. }
  6010. return {
  6011. type: "if-break",
  6012. breakContents,
  6013. flatContents
  6014. };
  6015. }
  6016. function lineSuffix$1(contents) {
  6017. if (process.env.NODE_ENV !== "production") {
  6018. assertDoc(contents);
  6019. }
  6020. return {
  6021. type: "line-suffix",
  6022. contents
  6023. };
  6024. }
  6025. var lineSuffixBoundary = {
  6026. type: "line-suffix-boundary"
  6027. };
  6028. var breakParent$1 = {
  6029. type: "break-parent"
  6030. };
  6031. var line$2 = {
  6032. type: "line"
  6033. };
  6034. var softline = {
  6035. type: "line",
  6036. soft: true
  6037. };
  6038. var hardline$1 = concat$1([{
  6039. type: "line",
  6040. hard: true
  6041. }, breakParent$1]);
  6042. var literalline = concat$1([{
  6043. type: "line",
  6044. hard: true,
  6045. literal: true
  6046. }, breakParent$1]);
  6047. var cursor$1 = {
  6048. type: "cursor",
  6049. placeholder: Symbol("cursor")
  6050. };
  6051. function join$1(sep, arr) {
  6052. var res = [];
  6053. for (var i = 0; i < arr.length; i++) {
  6054. if (i !== 0) {
  6055. res.push(sep);
  6056. }
  6057. res.push(arr[i]);
  6058. }
  6059. return concat$1(res);
  6060. }
  6061. function addAlignmentToDoc(doc, size, tabWidth) {
  6062. var aligned = doc;
  6063. if (size > 0) {
  6064. // Use indent to add tabs for all the levels of tabs we need
  6065. for (var i = 0; i < Math.floor(size / tabWidth); ++i) {
  6066. aligned = indent$1(aligned);
  6067. } // Use align for all the spaces that are needed
  6068. aligned = align(size % tabWidth, aligned); // size is absolute from 0 and not relative to the current
  6069. // indentation, so we use -Infinity to reset the indentation to 0
  6070. aligned = align(-Infinity, aligned);
  6071. }
  6072. return aligned;
  6073. }
  6074. var docBuilders = {
  6075. concat: concat$1,
  6076. join: join$1,
  6077. line: line$2,
  6078. softline,
  6079. hardline: hardline$1,
  6080. literalline,
  6081. group,
  6082. conditionalGroup,
  6083. fill,
  6084. lineSuffix: lineSuffix$1,
  6085. lineSuffixBoundary,
  6086. cursor: cursor$1,
  6087. breakParent: breakParent$1,
  6088. ifBreak,
  6089. indent: indent$1,
  6090. align,
  6091. addAlignmentToDoc,
  6092. markAsRoot,
  6093. dedentToRoot,
  6094. dedent: dedent$1
  6095. };
  6096. var ansiRegex = createCommonjsModule(function (module) {
  6097. 'use strict';
  6098. module.exports = function () {
  6099. var pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))'].join('|');
  6100. return new RegExp(pattern, 'g');
  6101. };
  6102. });
  6103. var stripAnsi = function stripAnsi(input) {
  6104. return typeof input === 'string' ? input.replace(ansiRegex(), '') : input;
  6105. };
  6106. var isFullwidthCodePoint = createCommonjsModule(function (module) {
  6107. 'use strict';
  6108. /* eslint-disable yoda */
  6109. module.exports = function (x) {
  6110. if (Number.isNaN(x)) {
  6111. return false;
  6112. } // code points are derived from:
  6113. // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
  6114. if (x >= 0x1100 && (x <= 0x115f || // Hangul Jamo
  6115. x === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  6116. x === 0x232a || // RIGHT-POINTING ANGLE BRACKET
  6117. // CJK Radicals Supplement .. Enclosed CJK Letters and Months
  6118. 0x2e80 <= x && x <= 0x3247 && x !== 0x303f || // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
  6119. 0x3250 <= x && x <= 0x4dbf || // CJK Unified Ideographs .. Yi Radicals
  6120. 0x4e00 <= x && x <= 0xa4c6 || // Hangul Jamo Extended-A
  6121. 0xa960 <= x && x <= 0xa97c || // Hangul Syllables
  6122. 0xac00 <= x && x <= 0xd7a3 || // CJK Compatibility Ideographs
  6123. 0xf900 <= x && x <= 0xfaff || // Vertical Forms
  6124. 0xfe10 <= x && x <= 0xfe19 || // CJK Compatibility Forms .. Small Form Variants
  6125. 0xfe30 <= x && x <= 0xfe6b || // Halfwidth and Fullwidth Forms
  6126. 0xff01 <= x && x <= 0xff60 || 0xffe0 <= x && x <= 0xffe6 || // Kana Supplement
  6127. 0x1b000 <= x && x <= 0x1b001 || // Enclosed Ideographic Supplement
  6128. 0x1f200 <= x && x <= 0x1f251 || // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
  6129. 0x20000 <= x && x <= 0x3fffd)) {
  6130. return true;
  6131. }
  6132. return false;
  6133. };
  6134. });
  6135. var stringWidth = createCommonjsModule(function (module) {
  6136. 'use strict';
  6137. module.exports = function (str) {
  6138. if (typeof str !== 'string' || str.length === 0) {
  6139. return 0;
  6140. }
  6141. str = stripAnsi(str);
  6142. var width = 0;
  6143. for (var i = 0; i < str.length; i++) {
  6144. var code = str.codePointAt(i); // Ignore control characters
  6145. if (code <= 0x1F || code >= 0x7F && code <= 0x9F) {
  6146. continue;
  6147. } // Ignore combining characters
  6148. if (code >= 0x300 && code <= 0x36F) {
  6149. continue;
  6150. } // Surrogates
  6151. if (code > 0xFFFF) {
  6152. i++;
  6153. }
  6154. width += isFullwidthCodePoint(code) ? 2 : 1;
  6155. }
  6156. return width;
  6157. };
  6158. });
  6159. var emojiRegex$1 = function emojiRegex() {
  6160. // https://mathiasbynens.be/notes/es-unicode-property-escapes#emoji
  6161. 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;
  6162. };
  6163. var punctuation_ranges = [// http://www.unicode.org/charts/PDF/U3000.pdf CJK Symbols and Punctuation
  6164. [0x3000, 0x303f], // http://www.unicode.org/charts/PDF/UAC00.pdf Hangul Syllables
  6165. [0xac00, 0xd7af], // http://www.unicode.org/charts/PDF/UFE10.pdf Vertical Forms
  6166. [0xfe10, 0xfe1f], // http://www.unicode.org/charts/PDF/UFE30.pdf CJK Compatibility Forms
  6167. // http://www.unicode.org/charts/PDF/UFE50.pdf Small Form Variants
  6168. [0xfe30, 0xfe6f], // http://www.unicode.org/charts/PDF/UFF00.pdf Halfwidth and Fullwidth Forms
  6169. [0xff00, 0xff60], [0xffe0, 0xffef]];
  6170. var character_ranges = [// http://www.unicode.org/charts/PDF/U1100.pdf Hangul Jamo
  6171. [0x1100, 0x11ff], // http://www.unicode.org/charts/PDF/U2E80.pdf CJK Radicals Supplement
  6172. // http://www.unicode.org/charts/PDF/U2F00.pdf Kangxi Radicals
  6173. [0x2e80, 0x2fdf], // http://www.unicode.org/charts/PDF/U3040.pdf Hiragana
  6174. // http://www.unicode.org/charts/PDF/U30A0.pdf Katakana
  6175. // http://www.unicode.org/charts/PDF/U3100.pdf Bopomofo
  6176. // http://www.unicode.org/charts/PDF/U3130.pdf Hangul Compatibility Jamo
  6177. [0x3040, 0x318f], // http://www.unicode.org/charts/PDF/U3200.pdf Enclosed CJK Letters and Months
  6178. // http://www.unicode.org/charts/PDF/U3300.pdf CJK Compatibility
  6179. // http://www.unicode.org/charts/PDF/U3400.pdf CJK Unified Ideographs Extension A
  6180. [0x3200, 0x4dbf], // http://www.unicode.org/charts/PDF/U4E00.pdf CJK Unified Ideographs (Han)
  6181. [0x4e00, 0x9fff], // http://www.unicode.org/charts/PDF/UA960.pdf Hangul Jamo Extended-A
  6182. [0xa960, 0xa97f], // http://www.unicode.org/charts/PDF/UF900.pdf CJK Compatibility Ideographs
  6183. [0xf900, 0xfaff]];
  6184. function get_regex() {
  6185. return create_regex(character_ranges.concat(punctuation_ranges));
  6186. } // istanbul ignore next
  6187. // tslint:disable-next-line:no-namespace
  6188. (function (get_regex) {
  6189. function punctuations() {
  6190. return create_regex(punctuation_ranges);
  6191. }
  6192. get_regex.punctuations = punctuations;
  6193. function characters() {
  6194. return create_regex(character_ranges);
  6195. }
  6196. get_regex.characters = characters;
  6197. })(get_regex || (get_regex = {}));
  6198. function create_regex(ranges) {
  6199. return new RegExp("[" + ranges.map(get_bracket_content).reduce(function (a, b) {
  6200. return a + b;
  6201. }) + "]", 'g');
  6202. }
  6203. function get_bracket_content(range) {
  6204. return get_escaped_unicode(range[0]) + "-" + get_escaped_unicode(range[1]);
  6205. }
  6206. function get_escaped_unicode(num) {
  6207. return "\\u" + num.toString(16);
  6208. }
  6209. var lib$3 = get_regex;
  6210. var data_generated = createCommonjsModule(function (module, exports) {
  6211. "use strict";
  6212. exports.__esModule = true;
  6213. exports.get_data = function () {
  6214. return {
  6215. "Pc": [[95, 95], [8255, 8256], [8276, 8276], [65075, 65076], [65101, 65103], [65343, 65343]],
  6216. "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]],
  6217. "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]],
  6218. "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]],
  6219. "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]],
  6220. "Zp": [[8233, 8233]],
  6221. "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]],
  6222. "Me": [[1160, 1161], [6846, 6846], [8413, 8416], [8418, 8420], [42608, 42610]],
  6223. "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]],
  6224. "Cs": [[55296, 55296], [56191, 56192], [56319, 56320], [57343, 57343]],
  6225. "Nl": [[5870, 5872], [8544, 8578], [8581, 8584], [12295, 12295], [12321, 12329], [12344, 12346], [42726, 42735]],
  6226. "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]],
  6227. "Lt": [[453, 453], [456, 456], [459, 459], [498, 498], [8072, 8079], [8088, 8095], [8104, 8111], [8124, 8124], [8140, 8140], [8188, 8188]],
  6228. "Zl": [[8232, 8232]],
  6229. "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]],
  6230. "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]],
  6231. "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]],
  6232. "Co": [[57344, 57344], [63743, 63743]],
  6233. "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]],
  6234. "Pf": [[187, 187], [8217, 8217], [8221, 8221], [8250, 8250], [11779, 11779], [11781, 11781], [11786, 11786], [11789, 11789], [11805, 11805], [11809, 11809]],
  6235. "Cc": [[0, 31], [127, 159]],
  6236. "Pi": [[171, 171], [8216, 8216], [8219, 8220], [8223, 8223], [8249, 8249], [11778, 11778], [11780, 11780], [11785, 11785], [11788, 11788], [11804, 11804], [11808, 11808]],
  6237. "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]],
  6238. "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]],
  6239. "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]],
  6240. "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]],
  6241. "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]],
  6242. "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]],
  6243. "Zs": [[32, 32], [160, 160], [5760, 5760], [8192, 8202], [8239, 8239], [8287, 8287], [12288, 12288]]
  6244. };
  6245. };
  6246. });
  6247. unwrapExports(data_generated);
  6248. var utils$2 = createCommonjsModule(function (module, exports) {
  6249. "use strict";
  6250. exports.__esModule = true;
  6251. function normalize_ranges(ranges) {
  6252. return ranges.sort(function (_a, _b) {
  6253. var start1 = _a[0];
  6254. var start2 = _b[0];
  6255. return start1 - start2;
  6256. }).reduce(function (current, tuple, index) {
  6257. if (index === 0) {
  6258. return [tuple];
  6259. }
  6260. var _a = current[current.length - 1],
  6261. last_start = _a[0],
  6262. last_end = _a[1];
  6263. var start = tuple[0],
  6264. end = tuple[1];
  6265. return last_end + 1 === start ? current.slice(0, -1).concat([[last_start, end]]) : current.concat([tuple]);
  6266. }, []);
  6267. }
  6268. exports.normalize_ranges = normalize_ranges;
  6269. function build_regex(ranges, flag) {
  6270. var pattern = ranges.map(function (_a) {
  6271. var start = _a[0],
  6272. end = _a[1];
  6273. return start === end ? "\\u" + get_hex(start) : "\\u" + get_hex(start) + "-\\u" + get_hex(end);
  6274. }).join('');
  6275. return new RegExp("[" + pattern + "]", flag);
  6276. }
  6277. exports.build_regex = build_regex;
  6278. function get_hex(char_code) {
  6279. var hex = char_code.toString(16);
  6280. while (hex.length < 4) {
  6281. hex = "0" + hex;
  6282. }
  6283. return hex;
  6284. }
  6285. });
  6286. unwrapExports(utils$2);
  6287. var lib$5 = function lib(categories, flag) {
  6288. var data = data_generated.get_data();
  6289. var ranges = categories.reduce(function (current, category) {
  6290. return current.concat(data[category]);
  6291. }, []);
  6292. return utils$2.build_regex(utils$2.normalize_ranges(ranges), flag);
  6293. };
  6294. var emojiRegex = emojiRegex$1();
  6295. var cjkPattern = lib$3().source; // http://spec.commonmark.org/0.25/#ascii-punctuation-character
  6296. var asciiPunctuationCharRange = escapeStringRegexp("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"); // http://spec.commonmark.org/0.25/#punctuation-character
  6297. var punctuationCharRange = `${asciiPunctuationCharRange}${lib$5(["Pc", "Pd", "Pe", "Pf", "Pi", "Po", "Ps"]).source.slice(1, -1)}`; // remove bracket expression `[` and `]`
  6298. var punctuationRegex = new RegExp(`[${punctuationCharRange}]`);
  6299. function isExportDeclaration(node) {
  6300. if (node) {
  6301. switch (node.type) {
  6302. case "ExportDefaultDeclaration":
  6303. case "ExportDefaultSpecifier":
  6304. case "DeclareExportDeclaration":
  6305. case "ExportNamedDeclaration":
  6306. case "ExportAllDeclaration":
  6307. return true;
  6308. }
  6309. }
  6310. return false;
  6311. }
  6312. function getParentExportDeclaration(path$$1) {
  6313. var parentNode = path$$1.getParentNode();
  6314. if (path$$1.getName() === "declaration" && isExportDeclaration(parentNode)) {
  6315. return parentNode;
  6316. }
  6317. return null;
  6318. }
  6319. function getPenultimate(arr) {
  6320. if (arr.length > 1) {
  6321. return arr[arr.length - 2];
  6322. }
  6323. return null;
  6324. }
  6325. function getLast$3(arr) {
  6326. if (arr.length > 0) {
  6327. return arr[arr.length - 1];
  6328. }
  6329. return null;
  6330. }
  6331. function skip(chars) {
  6332. return function (text, index, opts) {
  6333. var backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
  6334. // to check for failures (did someone say monads?).
  6335. if (index === false) {
  6336. return false;
  6337. }
  6338. var length = text.length;
  6339. var cursor = index;
  6340. while (cursor >= 0 && cursor < length) {
  6341. var c = text.charAt(cursor);
  6342. if (chars instanceof RegExp) {
  6343. if (!chars.test(c)) {
  6344. return cursor;
  6345. }
  6346. } else if (chars.indexOf(c) === -1) {
  6347. return cursor;
  6348. }
  6349. backwards ? cursor-- : cursor++;
  6350. }
  6351. if (cursor === -1 || cursor === length) {
  6352. // If we reached the beginning or end of the file, return the
  6353. // out-of-bounds cursor. It's up to the caller to handle this
  6354. // correctly. We don't want to indicate `false` though if it
  6355. // actually skipped valid characters.
  6356. return cursor;
  6357. }
  6358. return false;
  6359. };
  6360. }
  6361. var skipWhitespace = skip(/\s/);
  6362. var skipSpaces = skip(" \t");
  6363. var skipToLineEnd = skip(",; \t");
  6364. var skipEverythingButNewLine = skip(/[^\r\n]/);
  6365. function skipInlineComment(text, index) {
  6366. if (index === false) {
  6367. return false;
  6368. }
  6369. if (text.charAt(index) === "/" && text.charAt(index + 1) === "*") {
  6370. for (var i = index + 2; i < text.length; ++i) {
  6371. if (text.charAt(i) === "*" && text.charAt(i + 1) === "/") {
  6372. return i + 2;
  6373. }
  6374. }
  6375. }
  6376. return index;
  6377. }
  6378. function skipTrailingComment(text, index) {
  6379. if (index === false) {
  6380. return false;
  6381. }
  6382. if (text.charAt(index) === "/" && text.charAt(index + 1) === "/") {
  6383. return skipEverythingButNewLine(text, index);
  6384. }
  6385. return index;
  6386. } // This one doesn't use the above helper function because it wants to
  6387. // test \r\n in order and `skip` doesn't support ordering and we only
  6388. // want to skip one newline. It's simple to implement.
  6389. function skipNewline$1(text, index, opts) {
  6390. var backwards = opts && opts.backwards;
  6391. if (index === false) {
  6392. return false;
  6393. }
  6394. var atIndex = text.charAt(index);
  6395. if (backwards) {
  6396. if (text.charAt(index - 1) === "\r" && atIndex === "\n") {
  6397. return index - 2;
  6398. }
  6399. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  6400. return index - 1;
  6401. }
  6402. } else {
  6403. if (atIndex === "\r" && text.charAt(index + 1) === "\n") {
  6404. return index + 2;
  6405. }
  6406. if (atIndex === "\n" || atIndex === "\r" || atIndex === "\u2028" || atIndex === "\u2029") {
  6407. return index + 1;
  6408. }
  6409. }
  6410. return index;
  6411. }
  6412. function hasNewline$1(text, index, opts) {
  6413. opts = opts || {};
  6414. var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  6415. var idx2 = skipNewline$1(text, idx, opts);
  6416. return idx !== idx2;
  6417. }
  6418. function hasNewlineInRange(text, start, end) {
  6419. for (var i = start; i < end; ++i) {
  6420. if (text.charAt(i) === "\n") {
  6421. return true;
  6422. }
  6423. }
  6424. return false;
  6425. } // Note: this function doesn't ignore leading comments unlike isNextLineEmpty
  6426. function isPreviousLineEmpty$1(text, node, locStart) {
  6427. var idx = locStart(node) - 1;
  6428. idx = skipSpaces(text, idx, {
  6429. backwards: true
  6430. });
  6431. idx = skipNewline$1(text, idx, {
  6432. backwards: true
  6433. });
  6434. idx = skipSpaces(text, idx, {
  6435. backwards: true
  6436. });
  6437. var idx2 = skipNewline$1(text, idx, {
  6438. backwards: true
  6439. });
  6440. return idx !== idx2;
  6441. }
  6442. function isNextLineEmptyAfterIndex(text, index) {
  6443. var oldIdx = null;
  6444. var idx = index;
  6445. while (idx !== oldIdx) {
  6446. // We need to skip all the potential trailing inline comments
  6447. oldIdx = idx;
  6448. idx = skipToLineEnd(text, idx);
  6449. idx = skipInlineComment(text, idx);
  6450. idx = skipSpaces(text, idx);
  6451. }
  6452. idx = skipTrailingComment(text, idx);
  6453. idx = skipNewline$1(text, idx);
  6454. return hasNewline$1(text, idx);
  6455. }
  6456. function isNextLineEmpty(text, node, locEnd) {
  6457. return isNextLineEmptyAfterIndex(text, locEnd(node));
  6458. }
  6459. function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
  6460. var oldIdx = null;
  6461. var idx = locEnd(node);
  6462. while (idx !== oldIdx) {
  6463. oldIdx = idx;
  6464. idx = skipSpaces(text, idx);
  6465. idx = skipInlineComment(text, idx);
  6466. idx = skipTrailingComment(text, idx);
  6467. idx = skipNewline$1(text, idx);
  6468. }
  6469. return idx;
  6470. }
  6471. function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
  6472. return text.charAt(getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd));
  6473. }
  6474. function hasSpaces(text, index, opts) {
  6475. opts = opts || {};
  6476. var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
  6477. return idx !== index;
  6478. }
  6479. function setLocStart(node, index) {
  6480. if (node.range) {
  6481. node.range[0] = index;
  6482. } else {
  6483. node.start = index;
  6484. }
  6485. }
  6486. function setLocEnd(node, index) {
  6487. if (node.range) {
  6488. node.range[1] = index;
  6489. } else {
  6490. node.end = index;
  6491. }
  6492. }
  6493. var PRECEDENCE = {};
  6494. [["|>"], ["||", "??"], ["&&"], ["|"], ["^"], ["&"], ["==", "===", "!=", "!=="], ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], ["*", "/", "%"], ["**"]].forEach(function (tier, i) {
  6495. tier.forEach(function (op) {
  6496. PRECEDENCE[op] = i;
  6497. });
  6498. });
  6499. function getPrecedence(op) {
  6500. return PRECEDENCE[op];
  6501. }
  6502. var equalityOperators = {
  6503. "==": true,
  6504. "!=": true,
  6505. "===": true,
  6506. "!==": true
  6507. };
  6508. var additiveOperators = {
  6509. "+": true,
  6510. "-": true
  6511. };
  6512. var multiplicativeOperators = {
  6513. "*": true,
  6514. "/": true,
  6515. "%": true
  6516. };
  6517. var bitshiftOperators = {
  6518. ">>": true,
  6519. ">>>": true,
  6520. "<<": true
  6521. };
  6522. function shouldFlatten(parentOp, nodeOp) {
  6523. if (getPrecedence(nodeOp) !== getPrecedence(parentOp)) {
  6524. // x + y % z --> (x + y) % z
  6525. if (nodeOp === "%" && !additiveOperators[parentOp]) {
  6526. return true;
  6527. }
  6528. return false;
  6529. } // ** is right-associative
  6530. // x ** y ** z --> x ** (y ** z)
  6531. if (parentOp === "**") {
  6532. return false;
  6533. } // x == y == z --> (x == y) == z
  6534. if (equalityOperators[parentOp] && equalityOperators[nodeOp]) {
  6535. return false;
  6536. } // x * y % z --> (x * y) % z
  6537. if (nodeOp === "%" && multiplicativeOperators[parentOp] || parentOp === "%" && multiplicativeOperators[nodeOp]) {
  6538. return false;
  6539. } // x * y / z --> (x * y) / z
  6540. // x / y * z --> (x / y) * z
  6541. if (nodeOp !== parentOp && multiplicativeOperators[nodeOp] && multiplicativeOperators[parentOp]) {
  6542. return false;
  6543. } // x << y << z --> (x << y) << z
  6544. if (bitshiftOperators[parentOp] && bitshiftOperators[nodeOp]) {
  6545. return false;
  6546. }
  6547. return true;
  6548. }
  6549. function isBitwiseOperator(operator) {
  6550. return !!bitshiftOperators[operator] || operator === "|" || operator === "^" || operator === "&";
  6551. } // Tests if an expression starts with `{`, or (if forbidFunctionClassAndDoExpr
  6552. // holds) `function`, `class`, or `do {}`. Will be overzealous if there's
  6553. // already necessary grouping parentheses.
  6554. function startsWithNoLookaheadToken(node, forbidFunctionClassAndDoExpr) {
  6555. node = getLeftMost(node);
  6556. switch (node.type) {
  6557. // Hack. Remove after https://github.com/eslint/typescript-eslint-parser/issues/331
  6558. case "ObjectPattern":
  6559. return !forbidFunctionClassAndDoExpr;
  6560. case "FunctionExpression":
  6561. case "ClassExpression":
  6562. case "DoExpression":
  6563. return forbidFunctionClassAndDoExpr;
  6564. case "ObjectExpression":
  6565. return true;
  6566. case "MemberExpression":
  6567. return startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  6568. case "TaggedTemplateExpression":
  6569. if (node.tag.type === "FunctionExpression") {
  6570. // IIFEs are always already parenthesized
  6571. return false;
  6572. }
  6573. return startsWithNoLookaheadToken(node.tag, forbidFunctionClassAndDoExpr);
  6574. case "CallExpression":
  6575. if (node.callee.type === "FunctionExpression") {
  6576. // IIFEs are always already parenthesized
  6577. return false;
  6578. }
  6579. return startsWithNoLookaheadToken(node.callee, forbidFunctionClassAndDoExpr);
  6580. case "ConditionalExpression":
  6581. return startsWithNoLookaheadToken(node.test, forbidFunctionClassAndDoExpr);
  6582. case "UpdateExpression":
  6583. return !node.prefix && startsWithNoLookaheadToken(node.argument, forbidFunctionClassAndDoExpr);
  6584. case "BindExpression":
  6585. return node.object && startsWithNoLookaheadToken(node.object, forbidFunctionClassAndDoExpr);
  6586. case "SequenceExpression":
  6587. return startsWithNoLookaheadToken(node.expressions[0], forbidFunctionClassAndDoExpr);
  6588. case "TSAsExpression":
  6589. return startsWithNoLookaheadToken(node.expression, forbidFunctionClassAndDoExpr);
  6590. default:
  6591. return false;
  6592. }
  6593. }
  6594. function getLeftMost(node) {
  6595. if (node.left) {
  6596. return getLeftMost(node.left);
  6597. }
  6598. return node;
  6599. }
  6600. function getAlignmentSize(value, tabWidth, startIndex) {
  6601. startIndex = startIndex || 0;
  6602. var size = 0;
  6603. for (var i = startIndex; i < value.length; ++i) {
  6604. if (value[i] === "\t") {
  6605. // Tabs behave in a way that they are aligned to the nearest
  6606. // multiple of tabWidth:
  6607. // 0 -> 4, 1 -> 4, 2 -> 4, 3 -> 4
  6608. // 4 -> 8, 5 -> 8, 6 -> 8, 7 -> 8 ...
  6609. size = size + tabWidth - size % tabWidth;
  6610. } else {
  6611. size++;
  6612. }
  6613. }
  6614. return size;
  6615. }
  6616. function getIndentSize(value, tabWidth) {
  6617. var lastNewlineIndex = value.lastIndexOf("\n");
  6618. if (lastNewlineIndex === -1) {
  6619. return 0;
  6620. }
  6621. return getAlignmentSize( // All the leading whitespaces
  6622. value.slice(lastNewlineIndex + 1).match(/^[ \t]*/)[0], tabWidth);
  6623. }
  6624. function printString(raw, options, isDirectiveLiteral) {
  6625. // `rawContent` is the string exactly like it appeared in the input source
  6626. // code, without its enclosing quotes.
  6627. var rawContent = raw.slice(1, -1);
  6628. var double = {
  6629. quote: '"',
  6630. regex: /"/g
  6631. };
  6632. var single = {
  6633. quote: "'",
  6634. regex: /'/g
  6635. };
  6636. var preferred = options.singleQuote ? single : double;
  6637. var alternate = preferred === single ? double : single;
  6638. var shouldUseAlternateQuote = false;
  6639. var canChangeDirectiveQuotes = false; // If `rawContent` contains at least one of the quote preferred for enclosing
  6640. // the string, we might want to enclose with the alternate quote instead, to
  6641. // minimize the number of escaped quotes.
  6642. // Also check for the alternate quote, to determine if we're allowed to swap
  6643. // the quotes on a DirectiveLiteral.
  6644. if (rawContent.includes(preferred.quote) || rawContent.includes(alternate.quote)) {
  6645. var numPreferredQuotes = (rawContent.match(preferred.regex) || []).length;
  6646. var numAlternateQuotes = (rawContent.match(alternate.regex) || []).length;
  6647. shouldUseAlternateQuote = numPreferredQuotes > numAlternateQuotes;
  6648. } else {
  6649. canChangeDirectiveQuotes = true;
  6650. }
  6651. var enclosingQuote = options.parser === "json" ? double.quote : shouldUseAlternateQuote ? alternate.quote : preferred.quote; // Directives are exact code unit sequences, which means that you can't
  6652. // change the escape sequences they use.
  6653. // See https://github.com/prettier/prettier/issues/1555
  6654. // and https://tc39.github.io/ecma262/#directive-prologue
  6655. if (isDirectiveLiteral) {
  6656. if (canChangeDirectiveQuotes) {
  6657. return enclosingQuote + rawContent + enclosingQuote;
  6658. }
  6659. return raw;
  6660. } // It might sound unnecessary to use `makeString` even if the string already
  6661. // is enclosed with `enclosingQuote`, but it isn't. The string could contain
  6662. // unnecessary escapes (such as in `"\'"`). Always using `makeString` makes
  6663. // sure that we consistently output the minimum amount of escaped quotes.
  6664. return makeString(rawContent, enclosingQuote, !(options.parser === "css" || options.parser === "less" || options.parser === "scss"));
  6665. }
  6666. function makeString(rawContent, enclosingQuote, unescapeUnnecessaryEscapes) {
  6667. var otherQuote = enclosingQuote === '"' ? "'" : '"'; // Matches _any_ escape and unescaped quotes (both single and double).
  6668. var regex = /\\([\s\S])|(['"])/g; // Escape and unescape single and double quotes as needed to be able to
  6669. // enclose `rawContent` with `enclosingQuote`.
  6670. var newContent = rawContent.replace(regex, function (match, escaped, quote) {
  6671. // If we matched an escape, and the escaped character is a quote of the
  6672. // other type than we intend to enclose the string with, there's no need for
  6673. // it to be escaped, so return it _without_ the backslash.
  6674. if (escaped === otherQuote) {
  6675. return escaped;
  6676. } // If we matched an unescaped quote and it is of the _same_ type as we
  6677. // intend to enclose the string with, it must be escaped, so return it with
  6678. // a backslash.
  6679. if (quote === enclosingQuote) {
  6680. return "\\" + quote;
  6681. }
  6682. if (quote) {
  6683. return quote;
  6684. } // Unescape any unnecessarily escaped character.
  6685. // Adapted from https://github.com/eslint/eslint/blob/de0b4ad7bd820ade41b1f606008bea68683dc11a/lib/rules/no-useless-escape.js#L27
  6686. return unescapeUnnecessaryEscapes && /^[^\\nrvtbfux\r\n\u2028\u2029"'0-7]$/.test(escaped) ? escaped : "\\" + escaped;
  6687. });
  6688. return enclosingQuote + newContent + enclosingQuote;
  6689. }
  6690. function printNumber(rawNumber) {
  6691. return rawNumber.toLowerCase() // Remove unnecessary plus and zeroes from scientific notation.
  6692. .replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3") // Remove unnecessary scientific notation (1e0).
  6693. .replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1") // Make sure numbers always start with a digit.
  6694. .replace(/^([+-])?\./, "$10.") // Remove extraneous trailing decimal zeroes.
  6695. .replace(/(\.\d+?)0+(?=e|$)/, "$1") // Remove trailing dot.
  6696. .replace(/\.(?=e|$)/, "");
  6697. }
  6698. function getMaxContinuousCount(str, target) {
  6699. var results = str.match(new RegExp(`(${escapeStringRegexp(target)})+`, "g"));
  6700. if (results === null) {
  6701. return 0;
  6702. }
  6703. return results.reduce(function (maxCount, result) {
  6704. return Math.max(maxCount, result.length / target.length);
  6705. }, 0);
  6706. }
  6707. /**
  6708. * split text into whitespaces and words
  6709. * @param {string} text
  6710. * @return {Array<{ type: "whitespace", value: " " | "\n" | "" } | { type: "word", value: string }>}
  6711. */
  6712. function splitText(text, options) {
  6713. var KIND_NON_CJK = "non-cjk";
  6714. var KIND_CJK_CHARACTER = "cjk-character";
  6715. var KIND_CJK_PUNCTUATION = "cjk-punctuation";
  6716. var nodes = [];
  6717. (options.proseWrap === "preserve" ? text : text.replace(new RegExp(`(${cjkPattern})\n(${cjkPattern})`, "g"), "$1$2")).split(/([ \t\n]+)/).forEach(function (token, index, tokens) {
  6718. // whitespace
  6719. if (index % 2 === 1) {
  6720. nodes.push({
  6721. type: "whitespace",
  6722. value: /\n/.test(token) ? "\n" : " "
  6723. });
  6724. return;
  6725. } // word separated by whitespace
  6726. if ((index === 0 || index === tokens.length - 1) && token === "") {
  6727. return;
  6728. }
  6729. token.split(new RegExp(`(${cjkPattern})`)).forEach(function (innerToken, innerIndex, innerTokens) {
  6730. if ((innerIndex === 0 || innerIndex === innerTokens.length - 1) && innerToken === "") {
  6731. return;
  6732. } // non-CJK word
  6733. if (innerIndex % 2 === 0) {
  6734. if (innerToken !== "") {
  6735. appendNode({
  6736. type: "word",
  6737. value: innerToken,
  6738. kind: KIND_NON_CJK,
  6739. hasLeadingPunctuation: punctuationRegex.test(innerToken[0]),
  6740. hasTrailingPunctuation: punctuationRegex.test(getLast$3(innerToken))
  6741. });
  6742. }
  6743. return;
  6744. } // CJK character
  6745. appendNode(punctuationRegex.test(innerToken) ? {
  6746. type: "word",
  6747. value: innerToken,
  6748. kind: KIND_CJK_PUNCTUATION,
  6749. hasLeadingPunctuation: true,
  6750. hasTrailingPunctuation: true
  6751. } : {
  6752. type: "word",
  6753. value: innerToken,
  6754. kind: KIND_CJK_CHARACTER,
  6755. hasLeadingPunctuation: false,
  6756. hasTrailingPunctuation: false
  6757. });
  6758. });
  6759. });
  6760. return nodes;
  6761. function appendNode(node) {
  6762. var lastNode = getLast$3(nodes);
  6763. if (lastNode && lastNode.type === "word") {
  6764. if (lastNode.kind === KIND_NON_CJK && node.kind === KIND_CJK_CHARACTER && !lastNode.hasTrailingPunctuation || lastNode.kind === KIND_CJK_CHARACTER && node.kind === KIND_NON_CJK && !node.hasLeadingPunctuation) {
  6765. nodes.push({
  6766. type: "whitespace",
  6767. value: " "
  6768. });
  6769. } else if (!isBetween(KIND_NON_CJK, KIND_CJK_PUNCTUATION) && // disallow leading/trailing full-width whitespace
  6770. ![lastNode.value, node.value].some(function (value) {
  6771. return /\u3000/.test(value);
  6772. })) {
  6773. nodes.push({
  6774. type: "whitespace",
  6775. value: ""
  6776. });
  6777. }
  6778. }
  6779. nodes.push(node);
  6780. function isBetween(kind1, kind2) {
  6781. return lastNode.kind === kind1 && node.kind === kind2 || lastNode.kind === kind2 && node.kind === kind1;
  6782. }
  6783. }
  6784. }
  6785. function getStringWidth(text) {
  6786. if (!text) {
  6787. return 0;
  6788. } // emojis are considered 2-char width for consistency
  6789. // see https://github.com/sindresorhus/string-width/issues/11
  6790. // for the reason why not implemented in `string-width`
  6791. return stringWidth(text.replace(emojiRegex, " "));
  6792. }
  6793. function hasIgnoreComment(path$$1) {
  6794. var node = path$$1.getValue();
  6795. return hasNodeIgnoreComment(node);
  6796. }
  6797. function hasNodeIgnoreComment(node) {
  6798. return node && node.comments && node.comments.length > 0 && node.comments.some(function (comment) {
  6799. return comment.value.trim() === "prettier-ignore";
  6800. });
  6801. }
  6802. function addCommentHelper(node, comment) {
  6803. var comments = node.comments || (node.comments = []);
  6804. comments.push(comment);
  6805. comment.printed = false; // For some reason, TypeScript parses `// x` inside of JSXText as a comment
  6806. // We already "print" it via the raw text, we don't need to re-print it as a
  6807. // comment
  6808. if (node.type === "JSXText") {
  6809. comment.printed = true;
  6810. }
  6811. }
  6812. function addLeadingComment$1(node, comment) {
  6813. comment.leading = true;
  6814. comment.trailing = false;
  6815. addCommentHelper(node, comment);
  6816. }
  6817. function addDanglingComment$1(node, comment) {
  6818. comment.leading = false;
  6819. comment.trailing = false;
  6820. addCommentHelper(node, comment);
  6821. }
  6822. function addTrailingComment$1(node, comment) {
  6823. comment.leading = false;
  6824. comment.trailing = true;
  6825. addCommentHelper(node, comment);
  6826. }
  6827. var util$1 = {
  6828. punctuationRegex,
  6829. punctuationCharRange,
  6830. getStringWidth,
  6831. splitText,
  6832. getMaxContinuousCount,
  6833. getPrecedence,
  6834. shouldFlatten,
  6835. isBitwiseOperator,
  6836. isExportDeclaration,
  6837. getParentExportDeclaration,
  6838. getPenultimate,
  6839. getLast: getLast$3,
  6840. getNextNonSpaceNonCommentCharacterIndex,
  6841. getNextNonSpaceNonCommentCharacter,
  6842. skipWhitespace,
  6843. skipSpaces,
  6844. skipNewline: skipNewline$1,
  6845. isNextLineEmptyAfterIndex,
  6846. isNextLineEmpty,
  6847. isPreviousLineEmpty: isPreviousLineEmpty$1,
  6848. hasNewline: hasNewline$1,
  6849. hasNewlineInRange,
  6850. hasSpaces,
  6851. setLocStart,
  6852. setLocEnd,
  6853. startsWithNoLookaheadToken,
  6854. getAlignmentSize,
  6855. getIndentSize,
  6856. printString,
  6857. printNumber,
  6858. hasIgnoreComment,
  6859. hasNodeIgnoreComment,
  6860. makeString,
  6861. addLeadingComment: addLeadingComment$1,
  6862. addDanglingComment: addDanglingComment$1,
  6863. addTrailingComment: addTrailingComment$1
  6864. };
  6865. var concat$2 = docBuilders.concat;
  6866. var fill$1 = docBuilders.fill;
  6867. var cursor$2 = docBuilders.cursor;
  6868. var MODE_BREAK = 1;
  6869. var MODE_FLAT = 2;
  6870. function rootIndent() {
  6871. return {
  6872. value: "",
  6873. length: 0,
  6874. queue: []
  6875. };
  6876. }
  6877. function makeIndent(ind, options) {
  6878. return generateInd(ind, {
  6879. type: "indent"
  6880. }, options);
  6881. }
  6882. function makeAlign(ind, n, options) {
  6883. return n === -Infinity ? ind.root || rootIndent() : n < 0 ? generateInd(ind, {
  6884. type: "dedent"
  6885. }, options) : !n ? ind : n.type === "root" ? Object.assign({}, ind, {
  6886. root: ind
  6887. }) : typeof n === "string" ? generateInd(ind, {
  6888. type: "stringAlign",
  6889. n
  6890. }, options) : generateInd(ind, {
  6891. type: "numberAlign",
  6892. n
  6893. }, options);
  6894. }
  6895. function generateInd(ind, newPart, options) {
  6896. var queue = newPart.type === "dedent" ? ind.queue.slice(0, -1) : ind.queue.concat(newPart);
  6897. var value = "";
  6898. var length = 0;
  6899. var lastTabs = 0;
  6900. var lastSpaces = 0;
  6901. var _iteratorNormalCompletion = true;
  6902. var _didIteratorError = false;
  6903. var _iteratorError = undefined;
  6904. try {
  6905. for (var _iterator = queue[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  6906. var part = _step.value;
  6907. switch (part.type) {
  6908. case "indent":
  6909. flush();
  6910. if (options.useTabs) {
  6911. addTabs(1);
  6912. } else {
  6913. addSpaces(options.tabWidth);
  6914. }
  6915. break;
  6916. case "stringAlign":
  6917. flush();
  6918. value += part.n;
  6919. length += part.n.length;
  6920. break;
  6921. case "numberAlign":
  6922. lastTabs += 1;
  6923. lastSpaces += part.n;
  6924. break;
  6925. /* istanbul ignore next */
  6926. default:
  6927. throw new Error(`Unexpected type '${part.type}'`);
  6928. }
  6929. }
  6930. } catch (err) {
  6931. _didIteratorError = true;
  6932. _iteratorError = err;
  6933. } finally {
  6934. try {
  6935. if (!_iteratorNormalCompletion && _iterator.return != null) {
  6936. _iterator.return();
  6937. }
  6938. } finally {
  6939. if (_didIteratorError) {
  6940. throw _iteratorError;
  6941. }
  6942. }
  6943. }
  6944. flushSpaces();
  6945. return Object.assign({}, ind, {
  6946. value,
  6947. length,
  6948. queue
  6949. });
  6950. function addTabs(count) {
  6951. value += "\t".repeat(count);
  6952. length += options.tabWidth * count;
  6953. }
  6954. function addSpaces(count) {
  6955. value += " ".repeat(count);
  6956. length += count;
  6957. }
  6958. function flush() {
  6959. if (options.useTabs) {
  6960. flushTabs();
  6961. } else {
  6962. flushSpaces();
  6963. }
  6964. }
  6965. function flushTabs() {
  6966. if (lastTabs > 0) {
  6967. addTabs(lastTabs);
  6968. }
  6969. resetLast();
  6970. }
  6971. function flushSpaces() {
  6972. if (lastSpaces > 0) {
  6973. addSpaces(lastSpaces);
  6974. }
  6975. resetLast();
  6976. }
  6977. function resetLast() {
  6978. lastTabs = 0;
  6979. lastSpaces = 0;
  6980. }
  6981. }
  6982. function fits(next, restCommands, width, options, mustBeFlat) {
  6983. var restIdx = restCommands.length;
  6984. var cmds = [next];
  6985. while (width >= 0) {
  6986. if (cmds.length === 0) {
  6987. if (restIdx === 0) {
  6988. return true;
  6989. }
  6990. cmds.push(restCommands[restIdx - 1]);
  6991. restIdx--;
  6992. continue;
  6993. }
  6994. var x = cmds.pop();
  6995. var ind = x[0];
  6996. var mode = x[1];
  6997. var doc = x[2];
  6998. if (typeof doc === "string") {
  6999. width -= util$1.getStringWidth(doc);
  7000. } else {
  7001. switch (doc.type) {
  7002. case "concat":
  7003. for (var i = doc.parts.length - 1; i >= 0; i--) {
  7004. cmds.push([ind, mode, doc.parts[i]]);
  7005. }
  7006. break;
  7007. case "indent":
  7008. cmds.push([makeIndent(ind, options), mode, doc.contents]);
  7009. break;
  7010. case "align":
  7011. cmds.push([makeAlign(ind, doc.n, options), mode, doc.contents]);
  7012. break;
  7013. case "group":
  7014. if (mustBeFlat && doc.break) {
  7015. return false;
  7016. }
  7017. cmds.push([ind, doc.break ? MODE_BREAK : mode, doc.contents]);
  7018. break;
  7019. case "fill":
  7020. for (var _i = doc.parts.length - 1; _i >= 0; _i--) {
  7021. cmds.push([ind, mode, doc.parts[_i]]);
  7022. }
  7023. break;
  7024. case "if-break":
  7025. if (mode === MODE_BREAK) {
  7026. if (doc.breakContents) {
  7027. cmds.push([ind, mode, doc.breakContents]);
  7028. }
  7029. }
  7030. if (mode === MODE_FLAT) {
  7031. if (doc.flatContents) {
  7032. cmds.push([ind, mode, doc.flatContents]);
  7033. }
  7034. }
  7035. break;
  7036. case "line":
  7037. switch (mode) {
  7038. // fallthrough
  7039. case MODE_FLAT:
  7040. if (!doc.hard) {
  7041. if (!doc.soft) {
  7042. width -= 1;
  7043. }
  7044. break;
  7045. }
  7046. return true;
  7047. case MODE_BREAK:
  7048. return true;
  7049. }
  7050. break;
  7051. }
  7052. }
  7053. }
  7054. return false;
  7055. }
  7056. function printDocToString$1(doc, options) {
  7057. var width = options.printWidth;
  7058. var newLine = options.newLine || "\n";
  7059. var pos = 0; // cmds is basically a stack. We've turned a recursive call into a
  7060. // while loop which is much faster. The while loop below adds new
  7061. // cmds to the array instead of recursively calling `print`.
  7062. var cmds = [[rootIndent(), MODE_BREAK, doc]];
  7063. var out = [];
  7064. var shouldRemeasure = false;
  7065. var lineSuffix = [];
  7066. while (cmds.length !== 0) {
  7067. var x = cmds.pop();
  7068. var ind = x[0];
  7069. var mode = x[1];
  7070. var _doc = x[2];
  7071. if (typeof _doc === "string") {
  7072. out.push(_doc);
  7073. pos += util$1.getStringWidth(_doc);
  7074. } else {
  7075. switch (_doc.type) {
  7076. case "cursor":
  7077. out.push(cursor$2.placeholder);
  7078. break;
  7079. case "concat":
  7080. for (var i = _doc.parts.length - 1; i >= 0; i--) {
  7081. cmds.push([ind, mode, _doc.parts[i]]);
  7082. }
  7083. break;
  7084. case "indent":
  7085. cmds.push([makeIndent(ind, options), mode, _doc.contents]);
  7086. break;
  7087. case "align":
  7088. cmds.push([makeAlign(ind, _doc.n, options), mode, _doc.contents]);
  7089. break;
  7090. case "group":
  7091. switch (mode) {
  7092. case MODE_FLAT:
  7093. if (!shouldRemeasure) {
  7094. cmds.push([ind, _doc.break ? MODE_BREAK : MODE_FLAT, _doc.contents]);
  7095. break;
  7096. }
  7097. // fallthrough
  7098. case MODE_BREAK:
  7099. {
  7100. shouldRemeasure = false;
  7101. var next = [ind, MODE_FLAT, _doc.contents];
  7102. var rem = width - pos;
  7103. if (!_doc.break && fits(next, cmds, rem, options)) {
  7104. cmds.push(next);
  7105. } else {
  7106. // Expanded states are a rare case where a document
  7107. // can manually provide multiple representations of
  7108. // itself. It provides an array of documents
  7109. // going from the least expanded (most flattened)
  7110. // representation first to the most expanded. If a
  7111. // group has these, we need to manually go through
  7112. // these states and find the first one that fits.
  7113. if (_doc.expandedStates) {
  7114. var mostExpanded = _doc.expandedStates[_doc.expandedStates.length - 1];
  7115. if (_doc.break) {
  7116. cmds.push([ind, MODE_BREAK, mostExpanded]);
  7117. break;
  7118. } else {
  7119. for (var _i2 = 1; _i2 < _doc.expandedStates.length + 1; _i2++) {
  7120. if (_i2 >= _doc.expandedStates.length) {
  7121. cmds.push([ind, MODE_BREAK, mostExpanded]);
  7122. break;
  7123. } else {
  7124. var state = _doc.expandedStates[_i2];
  7125. var cmd = [ind, MODE_FLAT, state];
  7126. if (fits(cmd, cmds, rem, options)) {
  7127. cmds.push(cmd);
  7128. break;
  7129. }
  7130. }
  7131. }
  7132. }
  7133. } else {
  7134. cmds.push([ind, MODE_BREAK, _doc.contents]);
  7135. }
  7136. }
  7137. break;
  7138. }
  7139. }
  7140. break;
  7141. // Fills each line with as much code as possible before moving to a new
  7142. // line with the same indentation.
  7143. //
  7144. // Expects doc.parts to be an array of alternating content and
  7145. // whitespace. The whitespace contains the linebreaks.
  7146. //
  7147. // For example:
  7148. // ["I", line, "love", line, "monkeys"]
  7149. // or
  7150. // [{ type: group, ... }, softline, { type: group, ... }]
  7151. //
  7152. // It uses this parts structure to handle three main layout cases:
  7153. // * The first two content items fit on the same line without
  7154. // breaking
  7155. // -> output the first content item and the whitespace "flat".
  7156. // * Only the first content item fits on the line without breaking
  7157. // -> output the first content item "flat" and the whitespace with
  7158. // "break".
  7159. // * Neither content item fits on the line without breaking
  7160. // -> output the first content item and the whitespace with "break".
  7161. case "fill":
  7162. {
  7163. var _rem = width - pos;
  7164. var parts = _doc.parts;
  7165. if (parts.length === 0) {
  7166. break;
  7167. }
  7168. var content = parts[0];
  7169. var contentFlatCmd = [ind, MODE_FLAT, content];
  7170. var contentBreakCmd = [ind, MODE_BREAK, content];
  7171. var contentFits = fits(contentFlatCmd, [], _rem, options, true);
  7172. if (parts.length === 1) {
  7173. if (contentFits) {
  7174. cmds.push(contentFlatCmd);
  7175. } else {
  7176. cmds.push(contentBreakCmd);
  7177. }
  7178. break;
  7179. }
  7180. var whitespace = parts[1];
  7181. var whitespaceFlatCmd = [ind, MODE_FLAT, whitespace];
  7182. var whitespaceBreakCmd = [ind, MODE_BREAK, whitespace];
  7183. if (parts.length === 2) {
  7184. if (contentFits) {
  7185. cmds.push(whitespaceFlatCmd);
  7186. cmds.push(contentFlatCmd);
  7187. } else {
  7188. cmds.push(whitespaceBreakCmd);
  7189. cmds.push(contentBreakCmd);
  7190. }
  7191. break;
  7192. } // At this point we've handled the first pair (context, separator)
  7193. // and will create a new fill doc for the rest of the content.
  7194. // Ideally we wouldn't mutate the array here but coping all the
  7195. // elements to a new array would make this algorithm quadratic,
  7196. // which is unusable for large arrays (e.g. large texts in JSX).
  7197. parts.splice(0, 2);
  7198. var remainingCmd = [ind, mode, fill$1(parts)];
  7199. var secondContent = parts[0];
  7200. var firstAndSecondContentFlatCmd = [ind, MODE_FLAT, concat$2([content, whitespace, secondContent])];
  7201. var firstAndSecondContentFits = fits(firstAndSecondContentFlatCmd, [], _rem, options, true);
  7202. if (firstAndSecondContentFits) {
  7203. cmds.push(remainingCmd);
  7204. cmds.push(whitespaceFlatCmd);
  7205. cmds.push(contentFlatCmd);
  7206. } else if (contentFits) {
  7207. cmds.push(remainingCmd);
  7208. cmds.push(whitespaceBreakCmd);
  7209. cmds.push(contentFlatCmd);
  7210. } else {
  7211. cmds.push(remainingCmd);
  7212. cmds.push(whitespaceBreakCmd);
  7213. cmds.push(contentBreakCmd);
  7214. }
  7215. break;
  7216. }
  7217. case "if-break":
  7218. if (mode === MODE_BREAK) {
  7219. if (_doc.breakContents) {
  7220. cmds.push([ind, mode, _doc.breakContents]);
  7221. }
  7222. }
  7223. if (mode === MODE_FLAT) {
  7224. if (_doc.flatContents) {
  7225. cmds.push([ind, mode, _doc.flatContents]);
  7226. }
  7227. }
  7228. break;
  7229. case "line-suffix":
  7230. lineSuffix.push([ind, mode, _doc.contents]);
  7231. break;
  7232. case "line-suffix-boundary":
  7233. if (lineSuffix.length > 0) {
  7234. cmds.push([ind, mode, {
  7235. type: "line",
  7236. hard: true
  7237. }]);
  7238. }
  7239. break;
  7240. case "line":
  7241. switch (mode) {
  7242. case MODE_FLAT:
  7243. if (!_doc.hard) {
  7244. if (!_doc.soft) {
  7245. out.push(" ");
  7246. pos += 1;
  7247. }
  7248. break;
  7249. } else {
  7250. // This line was forced into the output even if we
  7251. // were in flattened mode, so we need to tell the next
  7252. // group that no matter what, it needs to remeasure
  7253. // because the previous measurement didn't accurately
  7254. // capture the entire expression (this is necessary
  7255. // for nested groups)
  7256. shouldRemeasure = true;
  7257. }
  7258. // fallthrough
  7259. case MODE_BREAK:
  7260. if (lineSuffix.length) {
  7261. cmds.push([ind, mode, _doc]);
  7262. [].push.apply(cmds, lineSuffix.reverse());
  7263. lineSuffix = [];
  7264. break;
  7265. }
  7266. if (_doc.literal) {
  7267. if (ind.root) {
  7268. out.push(newLine, ind.root.value);
  7269. pos = ind.root.length;
  7270. } else {
  7271. out.push(newLine);
  7272. pos = 0;
  7273. }
  7274. } else {
  7275. if (out.length > 0) {
  7276. // Trim whitespace at the end of line
  7277. while (out.length > 0 && typeof out[out.length - 1] === "string" && out[out.length - 1].match(/^[^\S\n]*$/)) {
  7278. out.pop();
  7279. }
  7280. if (out.length && typeof out[out.length - 1] === "string") {
  7281. out[out.length - 1] = out[out.length - 1].replace(/[^\S\n]*$/, "");
  7282. }
  7283. }
  7284. out.push(newLine + ind.value);
  7285. pos = ind.length;
  7286. }
  7287. break;
  7288. }
  7289. break;
  7290. default:
  7291. }
  7292. }
  7293. }
  7294. var cursorPlaceholderIndex = out.indexOf(cursor$2.placeholder);
  7295. if (cursorPlaceholderIndex !== -1) {
  7296. var otherCursorPlaceholderIndex = out.indexOf(cursor$2.placeholder, cursorPlaceholderIndex + 1);
  7297. var beforeCursor = out.slice(0, cursorPlaceholderIndex).join("");
  7298. var aroundCursor = out.slice(cursorPlaceholderIndex + 1, otherCursorPlaceholderIndex).join("");
  7299. var afterCursor = out.slice(otherCursorPlaceholderIndex + 1).join("");
  7300. return {
  7301. formatted: beforeCursor + aroundCursor + afterCursor,
  7302. cursorNodeStart: beforeCursor.length,
  7303. cursorNodeText: aroundCursor
  7304. };
  7305. }
  7306. return {
  7307. formatted: out.join("")
  7308. };
  7309. }
  7310. var docPrinter = {
  7311. printDocToString: printDocToString$1
  7312. };
  7313. function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {
  7314. function traverseDocRec(doc) {
  7315. var shouldRecurse = true;
  7316. if (onEnter) {
  7317. if (onEnter(doc) === false) {
  7318. shouldRecurse = false;
  7319. }
  7320. }
  7321. if (shouldRecurse) {
  7322. if (doc.type === "concat" || doc.type === "fill") {
  7323. for (var i = 0; i < doc.parts.length; i++) {
  7324. traverseDocRec(doc.parts[i]);
  7325. }
  7326. } else if (doc.type === "if-break") {
  7327. if (doc.breakContents) {
  7328. traverseDocRec(doc.breakContents);
  7329. }
  7330. if (doc.flatContents) {
  7331. traverseDocRec(doc.flatContents);
  7332. }
  7333. } else if (doc.type === "group" && doc.expandedStates) {
  7334. if (shouldTraverseConditionalGroups) {
  7335. doc.expandedStates.forEach(traverseDocRec);
  7336. } else {
  7337. traverseDocRec(doc.contents);
  7338. }
  7339. } else if (doc.contents) {
  7340. traverseDocRec(doc.contents);
  7341. }
  7342. }
  7343. if (onExit) {
  7344. onExit(doc);
  7345. }
  7346. }
  7347. traverseDocRec(doc);
  7348. }
  7349. function mapDoc(doc, cb) {
  7350. if (doc.type === "concat" || doc.type === "fill") {
  7351. var parts = doc.parts.map(function (part) {
  7352. return mapDoc(part, cb);
  7353. });
  7354. return cb(Object.assign({}, doc, {
  7355. parts
  7356. }));
  7357. } else if (doc.type === "if-break") {
  7358. var breakContents = doc.breakContents && mapDoc(doc.breakContents, cb);
  7359. var flatContents = doc.flatContents && mapDoc(doc.flatContents, cb);
  7360. return cb(Object.assign({}, doc, {
  7361. breakContents,
  7362. flatContents
  7363. }));
  7364. } else if (doc.contents) {
  7365. var contents = mapDoc(doc.contents, cb);
  7366. return cb(Object.assign({}, doc, {
  7367. contents
  7368. }));
  7369. }
  7370. return cb(doc);
  7371. }
  7372. function findInDoc(doc, fn, defaultValue) {
  7373. var result = defaultValue;
  7374. var hasStopped = false;
  7375. traverseDoc(doc, function (doc) {
  7376. var maybeResult = fn(doc);
  7377. if (maybeResult !== undefined) {
  7378. hasStopped = true;
  7379. result = maybeResult;
  7380. }
  7381. if (hasStopped) {
  7382. return false;
  7383. }
  7384. });
  7385. return result;
  7386. }
  7387. function isEmpty(n) {
  7388. return typeof n === "string" && n.length === 0;
  7389. }
  7390. function isLineNext(doc) {
  7391. return findInDoc(doc, function (doc) {
  7392. if (typeof doc === "string") {
  7393. return false;
  7394. }
  7395. if (doc.type === "line") {
  7396. return true;
  7397. }
  7398. }, false);
  7399. }
  7400. function willBreak(doc) {
  7401. return findInDoc(doc, function (doc) {
  7402. if (doc.type === "group" && doc.break) {
  7403. return true;
  7404. }
  7405. if (doc.type === "line" && doc.hard) {
  7406. return true;
  7407. }
  7408. if (doc.type === "break-parent") {
  7409. return true;
  7410. }
  7411. }, false);
  7412. }
  7413. function breakParentGroup(groupStack) {
  7414. if (groupStack.length > 0) {
  7415. var parentGroup = groupStack[groupStack.length - 1]; // Breaks are not propagated through conditional groups because
  7416. // the user is expected to manually handle what breaks.
  7417. if (!parentGroup.expandedStates) {
  7418. parentGroup.break = true;
  7419. }
  7420. }
  7421. return null;
  7422. }
  7423. function propagateBreaks(doc) {
  7424. var alreadyVisited = new Map();
  7425. var groupStack = [];
  7426. traverseDoc(doc, function (doc) {
  7427. if (doc.type === "break-parent") {
  7428. breakParentGroup(groupStack);
  7429. }
  7430. if (doc.type === "group") {
  7431. groupStack.push(doc);
  7432. if (alreadyVisited.has(doc)) {
  7433. return false;
  7434. }
  7435. alreadyVisited.set(doc, true);
  7436. }
  7437. }, function (doc) {
  7438. if (doc.type === "group") {
  7439. var group = groupStack.pop();
  7440. if (group.break) {
  7441. breakParentGroup(groupStack);
  7442. }
  7443. }
  7444. },
  7445. /* shouldTraverseConditionalGroups */
  7446. true);
  7447. }
  7448. function removeLines(doc) {
  7449. // Force this doc into flat mode by statically converting all
  7450. // lines into spaces (or soft lines into nothing). Hard lines
  7451. // should still output because there's too great of a chance
  7452. // of breaking existing assumptions otherwise.
  7453. return mapDoc(doc, function (d) {
  7454. if (d.type === "line" && !d.hard) {
  7455. return d.soft ? "" : " ";
  7456. } else if (d.type === "if-break") {
  7457. return d.flatContents || "";
  7458. }
  7459. return d;
  7460. });
  7461. }
  7462. function stripTrailingHardline(doc) {
  7463. // HACK remove ending hardline, original PR: #1984
  7464. if (doc.type === "concat" && doc.parts.length === 2 && doc.parts[1].type === "concat" && doc.parts[1].parts.length === 2 && doc.parts[1].parts[0].hard && doc.parts[1].parts[1].type === "break-parent") {
  7465. return doc.parts[0];
  7466. }
  7467. return doc;
  7468. }
  7469. var docUtils = {
  7470. isEmpty,
  7471. willBreak,
  7472. isLineNext,
  7473. traverseDoc,
  7474. mapDoc,
  7475. propagateBreaks,
  7476. removeLines,
  7477. stripTrailingHardline
  7478. };
  7479. function flattenDoc(doc) {
  7480. if (doc.type === "concat") {
  7481. var res = [];
  7482. for (var i = 0; i < doc.parts.length; ++i) {
  7483. var doc2 = doc.parts[i];
  7484. if (typeof doc2 !== "string" && doc2.type === "concat") {
  7485. [].push.apply(res, flattenDoc(doc2).parts);
  7486. } else {
  7487. var flattened = flattenDoc(doc2);
  7488. if (flattened !== "") {
  7489. res.push(flattened);
  7490. }
  7491. }
  7492. }
  7493. return Object.assign({}, doc, {
  7494. parts: res
  7495. });
  7496. } else if (doc.type === "if-break") {
  7497. return Object.assign({}, doc, {
  7498. breakContents: doc.breakContents != null ? flattenDoc(doc.breakContents) : null,
  7499. flatContents: doc.flatContents != null ? flattenDoc(doc.flatContents) : null
  7500. });
  7501. } else if (doc.type === "group") {
  7502. return Object.assign({}, doc, {
  7503. contents: flattenDoc(doc.contents),
  7504. expandedStates: doc.expandedStates ? doc.expandedStates.map(flattenDoc) : doc.expandedStates
  7505. });
  7506. } else if (doc.contents) {
  7507. return Object.assign({}, doc, {
  7508. contents: flattenDoc(doc.contents)
  7509. });
  7510. }
  7511. return doc;
  7512. }
  7513. function printDoc(doc) {
  7514. if (typeof doc === "string") {
  7515. return JSON.stringify(doc);
  7516. }
  7517. if (doc.type === "line") {
  7518. if (doc.literalline) {
  7519. return "literalline";
  7520. }
  7521. if (doc.hard) {
  7522. return "hardline";
  7523. }
  7524. if (doc.soft) {
  7525. return "softline";
  7526. }
  7527. return "line";
  7528. }
  7529. if (doc.type === "break-parent") {
  7530. return "breakParent";
  7531. }
  7532. if (doc.type === "concat") {
  7533. return "[" + doc.parts.map(printDoc).join(", ") + "]";
  7534. }
  7535. if (doc.type === "indent") {
  7536. return "indent(" + printDoc(doc.contents) + ")";
  7537. }
  7538. if (doc.type === "align") {
  7539. return doc.n === -Infinity ? "dedentToRoot(" + printDoc(doc.contents) + ")" : doc.n < 0 ? "dedent(" + printDoc(doc.contents) + ")" : doc.n.type === "root" ? "markAsRoot(" + printDoc(doc.contents) + ")" : "align(" + JSON.stringify(doc.n) + ", " + printDoc(doc.contents) + ")";
  7540. }
  7541. if (doc.type === "if-break") {
  7542. return "ifBreak(" + printDoc(doc.breakContents) + (doc.flatContents ? ", " + printDoc(doc.flatContents) : "") + ")";
  7543. }
  7544. if (doc.type === "group") {
  7545. if (doc.expandedStates) {
  7546. return "conditionalGroup(" + "[" + doc.expandedStates.map(printDoc).join(",") + "])";
  7547. }
  7548. return (doc.break ? "wrappedGroup" : "group") + "(" + printDoc(doc.contents) + ")";
  7549. }
  7550. if (doc.type === "fill") {
  7551. return "fill" + "(" + doc.parts.map(printDoc).join(", ") + ")";
  7552. }
  7553. if (doc.type === "line-suffix") {
  7554. return "lineSuffix(" + printDoc(doc.contents) + ")";
  7555. }
  7556. if (doc.type === "line-suffix-boundary") {
  7557. return "lineSuffixBoundary";
  7558. }
  7559. throw new Error("Unknown doc type " + doc.type);
  7560. }
  7561. var docDebug = {
  7562. printDocToDebug: function printDocToDebug(doc) {
  7563. return printDoc(flattenDoc(doc));
  7564. }
  7565. };
  7566. var doc = {
  7567. builders: docBuilders,
  7568. printer: docPrinter,
  7569. utils: docUtils,
  7570. debug: docDebug
  7571. };
  7572. var mapDoc$1 = doc.utils.mapDoc;
  7573. function isNextLineEmpty$1(text, node, options) {
  7574. return util$1.isNextLineEmpty(text, node, options.locEnd);
  7575. }
  7576. function getNextNonSpaceNonCommentCharacterIndex$1(text, node, options) {
  7577. return util$1.getNextNonSpaceNonCommentCharacterIndex(text, node, options.locEnd);
  7578. }
  7579. var utilShared = {
  7580. isNextLineEmpty: isNextLineEmpty$1,
  7581. isNextLineEmptyAfterIndex: util$1.isNextLineEmptyAfterIndex,
  7582. getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex$1,
  7583. mapDoc: mapDoc$1,
  7584. // TODO: remove in 2.0, we already exposed it in docUtils
  7585. makeString: util$1.makeString,
  7586. addLeadingComment: util$1.addLeadingComment,
  7587. addDanglingComment: util$1.addDanglingComment,
  7588. addTrailingComment: util$1.addTrailingComment
  7589. };
  7590. var _require$$0$builders = doc.builders;
  7591. var concat = _require$$0$builders.concat;
  7592. var hardline = _require$$0$builders.hardline;
  7593. var breakParent = _require$$0$builders.breakParent;
  7594. var indent = _require$$0$builders.indent;
  7595. var lineSuffix = _require$$0$builders.lineSuffix;
  7596. var join = _require$$0$builders.join;
  7597. var cursor = _require$$0$builders.cursor;
  7598. var hasNewline = util$1.hasNewline;
  7599. var skipNewline = util$1.skipNewline;
  7600. var isPreviousLineEmpty = util$1.isPreviousLineEmpty;
  7601. var addLeadingComment = utilShared.addLeadingComment;
  7602. var addDanglingComment = utilShared.addDanglingComment;
  7603. var addTrailingComment = utilShared.addTrailingComment;
  7604. var childNodesCacheKey = Symbol("child-nodes");
  7605. function getSortedChildNodes(node, options, resultArray) {
  7606. if (!node) {
  7607. return;
  7608. }
  7609. var printer = options.printer;
  7610. var locStart = options.locStart;
  7611. var locEnd = options.locEnd;
  7612. if (resultArray) {
  7613. if (node && printer.canAttachComment && printer.canAttachComment(node)) {
  7614. // This reverse insertion sort almost always takes constant
  7615. // time because we almost always (maybe always?) append the
  7616. // nodes in order anyway.
  7617. var i;
  7618. for (i = resultArray.length - 1; i >= 0; --i) {
  7619. if (locStart(resultArray[i]) <= locStart(node) && locEnd(resultArray[i]) <= locEnd(node)) {
  7620. break;
  7621. }
  7622. }
  7623. resultArray.splice(i + 1, 0, node);
  7624. return;
  7625. }
  7626. } else if (node[childNodesCacheKey]) {
  7627. return node[childNodesCacheKey];
  7628. }
  7629. var childNodes;
  7630. if (printer.getCommentChildNodes) {
  7631. childNodes = printer.getCommentChildNodes(node);
  7632. } else if (node && typeof node === "object") {
  7633. childNodes = Object.keys(node).filter(function (n) {
  7634. return n !== "enclosingNode" && n !== "precedingNode" && n !== "followingNode";
  7635. }).map(function (n) {
  7636. return node[n];
  7637. });
  7638. }
  7639. if (!childNodes) {
  7640. return;
  7641. }
  7642. if (!resultArray) {
  7643. Object.defineProperty(node, childNodesCacheKey, {
  7644. value: resultArray = [],
  7645. enumerable: false
  7646. });
  7647. }
  7648. childNodes.forEach(function (childNode) {
  7649. getSortedChildNodes(childNode, options, resultArray);
  7650. });
  7651. return resultArray;
  7652. } // As efficiently as possible, decorate the comment object with
  7653. // .precedingNode, .enclosingNode, and/or .followingNode properties, at
  7654. // least one of which is guaranteed to be defined.
  7655. function decorateComment(node, comment, options) {
  7656. var locStart = options.locStart;
  7657. var locEnd = options.locEnd;
  7658. var childNodes = getSortedChildNodes(node, options);
  7659. var precedingNode;
  7660. var followingNode; // Time to dust off the old binary search robes and wizard hat.
  7661. var left = 0;
  7662. var right = childNodes.length;
  7663. while (left < right) {
  7664. var middle = left + right >> 1;
  7665. var child = childNodes[middle];
  7666. if (locStart(child) - locStart(comment) <= 0 && locEnd(comment) - locEnd(child) <= 0) {
  7667. // The comment is completely contained by this child node.
  7668. comment.enclosingNode = child;
  7669. decorateComment(child, comment, options);
  7670. return; // Abandon the binary search at this level.
  7671. }
  7672. if (locEnd(child) - locStart(comment) <= 0) {
  7673. // This child node falls completely before the comment.
  7674. // Because we will never consider this node or any nodes
  7675. // before it again, this node must be the closest preceding
  7676. // node we have encountered so far.
  7677. precedingNode = child;
  7678. left = middle + 1;
  7679. continue;
  7680. }
  7681. if (locEnd(comment) - locStart(child) <= 0) {
  7682. // This child node falls completely after the comment.
  7683. // Because we will never consider this node or any nodes after
  7684. // it again, this node must be the closest following node we
  7685. // have encountered so far.
  7686. followingNode = child;
  7687. right = middle;
  7688. continue;
  7689. }
  7690. /* istanbul ignore next */
  7691. throw new Error("Comment location overlaps with node location");
  7692. } // We don't want comments inside of different expressions inside of the same
  7693. // template literal to move to another expression.
  7694. if (comment.enclosingNode && comment.enclosingNode.type === "TemplateLiteral") {
  7695. var quasis = comment.enclosingNode.quasis;
  7696. var commentIndex = findExpressionIndexForComment(quasis, comment, options);
  7697. if (precedingNode && findExpressionIndexForComment(quasis, precedingNode, options) !== commentIndex) {
  7698. precedingNode = null;
  7699. }
  7700. if (followingNode && findExpressionIndexForComment(quasis, followingNode, options) !== commentIndex) {
  7701. followingNode = null;
  7702. }
  7703. }
  7704. if (precedingNode) {
  7705. comment.precedingNode = precedingNode;
  7706. }
  7707. if (followingNode) {
  7708. comment.followingNode = followingNode;
  7709. }
  7710. }
  7711. function attach(comments, ast, text, options) {
  7712. if (!Array.isArray(comments)) {
  7713. return;
  7714. }
  7715. var tiesToBreak = [];
  7716. var locStart = options.locStart;
  7717. var locEnd = options.locEnd;
  7718. comments.forEach(function (comment, i) {
  7719. if ((options.parser === "json" || options.parser === "json5") && locStart(comment) - locStart(ast) <= 0) {
  7720. addLeadingComment(ast, comment);
  7721. return;
  7722. }
  7723. decorateComment(ast, comment, options);
  7724. var precedingNode = comment.precedingNode;
  7725. var enclosingNode = comment.enclosingNode;
  7726. var followingNode = comment.followingNode;
  7727. var pluginHandleOwnLineComment = options.printer.handleComments && options.printer.handleComments.ownLine ? options.printer.handleComments.ownLine : function () {
  7728. return false;
  7729. };
  7730. var pluginHandleEndOfLineComment = options.printer.handleComments && options.printer.handleComments.endOfLine ? options.printer.handleComments.endOfLine : function () {
  7731. return false;
  7732. };
  7733. var pluginHandleRemainingComment = options.printer.handleComments && options.printer.handleComments.remaining ? options.printer.handleComments.remaining : function () {
  7734. return false;
  7735. };
  7736. var isLastComment = comments.length - 1 === i;
  7737. if (hasNewline(text, locStart(comment), {
  7738. backwards: true
  7739. })) {
  7740. // If a comment exists on its own line, prefer a leading comment.
  7741. // We also need to check if it's the first line of the file.
  7742. if (pluginHandleOwnLineComment(comment, text, options, ast, isLastComment)) {// We're good
  7743. } else if (followingNode) {
  7744. // Always a leading comment.
  7745. addLeadingComment(followingNode, comment);
  7746. } else if (precedingNode) {
  7747. addTrailingComment(precedingNode, comment);
  7748. } else if (enclosingNode) {
  7749. addDanglingComment(enclosingNode, comment);
  7750. } else {
  7751. // There are no nodes, let's attach it to the root of the ast
  7752. /* istanbul ignore next */
  7753. addDanglingComment(ast, comment);
  7754. }
  7755. } else if (hasNewline(text, locEnd(comment))) {
  7756. if (pluginHandleEndOfLineComment(comment, text, options, ast, isLastComment)) {// We're good
  7757. } else if (precedingNode) {
  7758. // There is content before this comment on the same line, but
  7759. // none after it, so prefer a trailing comment of the previous node.
  7760. addTrailingComment(precedingNode, comment);
  7761. } else if (followingNode) {
  7762. addLeadingComment(followingNode, comment);
  7763. } else if (enclosingNode) {
  7764. addDanglingComment(enclosingNode, comment);
  7765. } else {
  7766. // There are no nodes, let's attach it to the root of the ast
  7767. /* istanbul ignore next */
  7768. addDanglingComment(ast, comment);
  7769. }
  7770. } else {
  7771. if (pluginHandleRemainingComment(comment, text, options, ast, isLastComment)) {// We're good
  7772. } else if (precedingNode && followingNode) {
  7773. // Otherwise, text exists both before and after the comment on
  7774. // the same line. If there is both a preceding and following
  7775. // node, use a tie-breaking algorithm to determine if it should
  7776. // be attached to the next or previous node. In the last case,
  7777. // simply attach the right node;
  7778. var tieCount = tiesToBreak.length;
  7779. if (tieCount > 0) {
  7780. var lastTie = tiesToBreak[tieCount - 1];
  7781. if (lastTie.followingNode !== comment.followingNode) {
  7782. breakTies(tiesToBreak, text, options);
  7783. }
  7784. }
  7785. tiesToBreak.push(comment);
  7786. } else if (precedingNode) {
  7787. addTrailingComment(precedingNode, comment);
  7788. } else if (followingNode) {
  7789. addLeadingComment(followingNode, comment);
  7790. } else if (enclosingNode) {
  7791. addDanglingComment(enclosingNode, comment);
  7792. } else {
  7793. // There are no nodes, let's attach it to the root of the ast
  7794. /* istanbul ignore next */
  7795. addDanglingComment(ast, comment);
  7796. }
  7797. }
  7798. });
  7799. breakTies(tiesToBreak, text, options);
  7800. comments.forEach(function (comment) {
  7801. // These node references were useful for breaking ties, but we
  7802. // don't need them anymore, and they create cycles in the AST that
  7803. // may lead to infinite recursion if we don't delete them here.
  7804. delete comment.precedingNode;
  7805. delete comment.enclosingNode;
  7806. delete comment.followingNode;
  7807. });
  7808. }
  7809. function breakTies(tiesToBreak, text, options) {
  7810. var tieCount = tiesToBreak.length;
  7811. if (tieCount === 0) {
  7812. return;
  7813. }
  7814. var precedingNode = tiesToBreak[0].precedingNode;
  7815. var followingNode = tiesToBreak[0].followingNode;
  7816. var gapEndPos = options.locStart(followingNode); // Iterate backwards through tiesToBreak, examining the gaps
  7817. // between the tied comments. In order to qualify as leading, a
  7818. // comment must be separated from followingNode by an unbroken series of
  7819. // gaps (or other comments). Gaps should only contain whitespace or open
  7820. // parentheses.
  7821. var indexOfFirstLeadingComment;
  7822. for (indexOfFirstLeadingComment = tieCount; indexOfFirstLeadingComment > 0; --indexOfFirstLeadingComment) {
  7823. var comment = tiesToBreak[indexOfFirstLeadingComment - 1];
  7824. assert.strictEqual(comment.precedingNode, precedingNode);
  7825. assert.strictEqual(comment.followingNode, followingNode);
  7826. var gap = text.slice(options.locEnd(comment), gapEndPos).trim();
  7827. if (gap === "" || /^\(+$/.test(gap)) {
  7828. gapEndPos = options.locStart(comment);
  7829. } else {
  7830. // The gap string contained something other than whitespace or open
  7831. // parentheses.
  7832. break;
  7833. }
  7834. }
  7835. tiesToBreak.forEach(function (comment, i) {
  7836. if (i < indexOfFirstLeadingComment) {
  7837. addTrailingComment(precedingNode, comment);
  7838. } else {
  7839. addLeadingComment(followingNode, comment);
  7840. }
  7841. });
  7842. tiesToBreak.length = 0;
  7843. }
  7844. function printComment(commentPath, options) {
  7845. var comment = commentPath.getValue();
  7846. comment.printed = true;
  7847. return options.printer.printComment(commentPath, options);
  7848. }
  7849. function findExpressionIndexForComment(quasis, comment, options) {
  7850. var startPos = options.locStart(comment) - 1;
  7851. for (var i = 1; i < quasis.length; ++i) {
  7852. if (startPos < getQuasiRange(quasis[i]).start) {
  7853. return i - 1;
  7854. }
  7855. } // We haven't found it, it probably means that some of the locations are off.
  7856. // Let's just return the first one.
  7857. /* istanbul ignore next */
  7858. return 0;
  7859. }
  7860. function getQuasiRange(expr) {
  7861. if (expr.start !== undefined) {
  7862. // Babylon
  7863. return {
  7864. start: expr.start,
  7865. end: expr.end
  7866. };
  7867. } // Flow
  7868. return {
  7869. start: expr.range[0],
  7870. end: expr.range[1]
  7871. };
  7872. }
  7873. function printLeadingComment(commentPath, print, options) {
  7874. var comment = commentPath.getValue();
  7875. var contents = printComment(commentPath, options);
  7876. if (!contents) {
  7877. return "";
  7878. }
  7879. var isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // Leading block comments should see if they need to stay on the
  7880. // same line or not.
  7881. if (isBlock) {
  7882. return concat([contents, hasNewline(options.originalText, options.locEnd(comment)) ? hardline : " "]);
  7883. }
  7884. return concat([contents, hardline]);
  7885. }
  7886. function printTrailingComment(commentPath, print, options) {
  7887. var comment = commentPath.getValue();
  7888. var contents = printComment(commentPath, options);
  7889. if (!contents) {
  7890. return "";
  7891. }
  7892. var isBlock = options.printer.isBlockComment && options.printer.isBlockComment(comment); // We don't want the line to break
  7893. // when the parentParentNode is a ClassDeclaration/-Expression
  7894. // And the parentNode is in the superClass property
  7895. var parentNode = commentPath.getNode(1);
  7896. var parentParentNode = commentPath.getNode(2);
  7897. var isParentSuperClass = parentParentNode && (parentParentNode.type === "ClassDeclaration" || parentParentNode.type === "ClassExpression") && parentParentNode.superClass === parentNode;
  7898. if (hasNewline(options.originalText, options.locStart(comment), {
  7899. backwards: true
  7900. })) {
  7901. // This allows comments at the end of nested structures:
  7902. // {
  7903. // x: 1,
  7904. // y: 2
  7905. // // A comment
  7906. // }
  7907. // Those kinds of comments are almost always leading comments, but
  7908. // here it doesn't go "outside" the block and turns it into a
  7909. // trailing comment for `2`. We can simulate the above by checking
  7910. // if this a comment on its own line; normal trailing comments are
  7911. // always at the end of another expression.
  7912. var isLineBeforeEmpty = isPreviousLineEmpty(options.originalText, comment, options.locStart);
  7913. return lineSuffix(concat([hardline, isLineBeforeEmpty ? hardline : "", contents]));
  7914. } else if (isBlock || isParentSuperClass) {
  7915. // Trailing block comments never need a newline
  7916. return concat([" ", contents]);
  7917. }
  7918. return concat([lineSuffix(" " + contents), !isBlock ? breakParent : ""]);
  7919. }
  7920. function printDanglingComments(path$$1, options, sameIndent, filter) {
  7921. var parts = [];
  7922. var node = path$$1.getValue();
  7923. if (!node || !node.comments) {
  7924. return "";
  7925. }
  7926. path$$1.each(function (commentPath) {
  7927. var comment = commentPath.getValue();
  7928. if (comment && !comment.leading && !comment.trailing && (!filter || filter(comment))) {
  7929. parts.push(printComment(commentPath, options));
  7930. }
  7931. }, "comments");
  7932. if (parts.length === 0) {
  7933. return "";
  7934. }
  7935. if (sameIndent) {
  7936. return join(hardline, parts);
  7937. }
  7938. return indent(concat([hardline, join(hardline, parts)]));
  7939. }
  7940. function prependCursorPlaceholder(path$$1, options, printed) {
  7941. if (path$$1.getNode() === options.cursorNode && path$$1.getValue()) {
  7942. return concat([cursor, printed, cursor]);
  7943. }
  7944. return printed;
  7945. }
  7946. function printComments(path$$1, print, options, needsSemi) {
  7947. var value = path$$1.getValue();
  7948. var printed = print(path$$1);
  7949. var comments = value && value.comments;
  7950. if (!comments || comments.length === 0) {
  7951. return prependCursorPlaceholder(path$$1, options, printed);
  7952. }
  7953. var leadingParts = [];
  7954. var trailingParts = [needsSemi ? ";" : "", printed];
  7955. path$$1.each(function (commentPath) {
  7956. var comment = commentPath.getValue();
  7957. var leading = comment.leading;
  7958. var trailing = comment.trailing;
  7959. if (leading) {
  7960. var contents = printLeadingComment(commentPath, print, options);
  7961. if (!contents) {
  7962. return;
  7963. }
  7964. leadingParts.push(contents);
  7965. var text = options.originalText;
  7966. if (hasNewline(text, skipNewline(text, options.locEnd(comment)))) {
  7967. leadingParts.push(hardline);
  7968. }
  7969. } else if (trailing) {
  7970. trailingParts.push(printTrailingComment(commentPath, print, options));
  7971. }
  7972. }, "comments");
  7973. return prependCursorPlaceholder(path$$1, options, concat(leadingParts.concat(trailingParts)));
  7974. }
  7975. var comments = {
  7976. attach,
  7977. printComments,
  7978. printDanglingComments,
  7979. getSortedChildNodes
  7980. };
  7981. function FastPath(value) {
  7982. assert.ok(this instanceof FastPath);
  7983. this.stack = [value];
  7984. } // The name of the current property is always the penultimate element of
  7985. // this.stack, and always a String.
  7986. FastPath.prototype.getName = function getName() {
  7987. var s = this.stack;
  7988. var len = s.length;
  7989. if (len > 1) {
  7990. return s[len - 2];
  7991. } // Since the name is always a string, null is a safe sentinel value to
  7992. // return if we do not know the name of the (root) value.
  7993. /* istanbul ignore next */
  7994. return null;
  7995. }; // The value of the current property is always the final element of
  7996. // this.stack.
  7997. FastPath.prototype.getValue = function getValue() {
  7998. var s = this.stack;
  7999. return s[s.length - 1];
  8000. };
  8001. function getNodeHelper(path$$1, count) {
  8002. var s = path$$1.stack;
  8003. for (var i = s.length - 1; i >= 0; i -= 2) {
  8004. var value = s[i];
  8005. if (value && !Array.isArray(value) && --count < 0) {
  8006. return value;
  8007. }
  8008. }
  8009. return null;
  8010. }
  8011. FastPath.prototype.getNode = function getNode(count) {
  8012. return getNodeHelper(this, ~~count);
  8013. };
  8014. FastPath.prototype.getParentNode = function getParentNode(count) {
  8015. return getNodeHelper(this, ~~count + 1);
  8016. }; // Temporarily push properties named by string arguments given after the
  8017. // callback function onto this.stack, then call the callback with a
  8018. // reference to this (modified) FastPath object. Note that the stack will
  8019. // be restored to its original state after the callback is finished, so it
  8020. // is probably a mistake to retain a reference to the path.
  8021. FastPath.prototype.call = function call(callback
  8022. /*, name1, name2, ... */
  8023. ) {
  8024. var s = this.stack;
  8025. var origLen = s.length;
  8026. var value = s[origLen - 1];
  8027. var argc = arguments.length;
  8028. for (var i = 1; i < argc; ++i) {
  8029. var name = arguments[i];
  8030. value = value[name];
  8031. s.push(name, value);
  8032. }
  8033. var result = callback(this);
  8034. s.length = origLen;
  8035. return result;
  8036. }; // Similar to FastPath.prototype.call, except that the value obtained by
  8037. // accessing this.getValue()[name1][name2]... should be array-like. The
  8038. // callback will be called with a reference to this path object for each
  8039. // element of the array.
  8040. FastPath.prototype.each = function each(callback
  8041. /*, name1, name2, ... */
  8042. ) {
  8043. var s = this.stack;
  8044. var origLen = s.length;
  8045. var value = s[origLen - 1];
  8046. var argc = arguments.length;
  8047. for (var i = 1; i < argc; ++i) {
  8048. var name = arguments[i];
  8049. value = value[name];
  8050. s.push(name, value);
  8051. }
  8052. for (var _i = 0; _i < value.length; ++_i) {
  8053. if (_i in value) {
  8054. s.push(_i, value[_i]); // If the callback needs to know the value of i, call
  8055. // path.getName(), assuming path is the parameter name.
  8056. callback(this);
  8057. s.length -= 2;
  8058. }
  8059. }
  8060. s.length = origLen;
  8061. }; // Similar to FastPath.prototype.each, except that the results of the
  8062. // callback function invocations are stored in an array and returned at
  8063. // the end of the iteration.
  8064. FastPath.prototype.map = function map(callback
  8065. /*, name1, name2, ... */
  8066. ) {
  8067. var s = this.stack;
  8068. var origLen = s.length;
  8069. var value = s[origLen - 1];
  8070. var argc = arguments.length;
  8071. for (var i = 1; i < argc; ++i) {
  8072. var name = arguments[i];
  8073. value = value[name];
  8074. s.push(name, value);
  8075. }
  8076. var result = new Array(value.length);
  8077. for (var _i2 = 0; _i2 < value.length; ++_i2) {
  8078. if (_i2 in value) {
  8079. s.push(_i2, value[_i2]);
  8080. result[_i2] = callback(this, _i2);
  8081. s.length -= 2;
  8082. }
  8083. }
  8084. s.length = origLen;
  8085. return result;
  8086. };
  8087. var fastPath = FastPath;
  8088. var normalize$1 = options.normalize;
  8089. function printSubtree(path$$1, print, options$$1, printAstToDoc) {
  8090. if (options$$1.printer.embed) {
  8091. return options$$1.printer.embed(path$$1, print, function (text, partialNextOptions) {
  8092. return textToDoc(text, partialNextOptions, options$$1, printAstToDoc);
  8093. }, options$$1);
  8094. }
  8095. }
  8096. function textToDoc(text, partialNextOptions, parentOptions, printAstToDoc) {
  8097. var nextOptions = normalize$1(Object.assign({}, parentOptions, partialNextOptions, {
  8098. parentParser: parentOptions.parser,
  8099. originalText: text
  8100. }), {
  8101. passThrough: true
  8102. });
  8103. var result = parser.parse(text, nextOptions);
  8104. var ast = result.ast;
  8105. text = result.text;
  8106. var astComments = ast.comments;
  8107. delete ast.comments;
  8108. comments.attach(astComments, ast, text, nextOptions);
  8109. return printAstToDoc(ast, nextOptions);
  8110. }
  8111. var multiparser = {
  8112. printSubtree
  8113. };
  8114. var doc$2 = doc;
  8115. var docBuilders$2 = doc$2.builders;
  8116. var concat$3 = docBuilders$2.concat;
  8117. var hardline$2 = docBuilders$2.hardline;
  8118. var addAlignmentToDoc$1 = docBuilders$2.addAlignmentToDoc;
  8119. var docUtils$2 = doc$2.utils;
  8120. function printAstToDoc(ast, options, addAlignmentSize) {
  8121. addAlignmentSize = addAlignmentSize || 0;
  8122. var printer = options.printer;
  8123. var cache = new Map();
  8124. function printGenerically(path$$1, args) {
  8125. var node = path$$1.getValue();
  8126. var shouldCache = node && typeof node === "object" && args === undefined;
  8127. if (shouldCache && cache.has(node)) {
  8128. return cache.get(node);
  8129. } // We let JSXElement print its comments itself because it adds () around
  8130. // UnionTypeAnnotation has to align the child without the comments
  8131. var res;
  8132. if (printer.willPrintOwnComments && printer.willPrintOwnComments(path$$1)) {
  8133. res = genericPrint(path$$1, options, printGenerically, args);
  8134. } else {
  8135. res = comments.printComments(path$$1, function (p) {
  8136. return genericPrint(p, options, printGenerically, args);
  8137. }, options, args && args.needsSemi);
  8138. }
  8139. if (shouldCache) {
  8140. cache.set(node, res);
  8141. }
  8142. return res;
  8143. }
  8144. var doc$$2 = printGenerically(new fastPath(ast));
  8145. if (addAlignmentSize > 0) {
  8146. // Add a hardline to make the indents take effect
  8147. // It should be removed in index.js format()
  8148. doc$$2 = addAlignmentToDoc$1(docUtils$2.removeLines(concat$3([hardline$2, doc$$2])), addAlignmentSize, options.tabWidth);
  8149. }
  8150. docUtils$2.propagateBreaks(doc$$2);
  8151. if (options.parser === "json" || options.parser === "json5" || options.parser === "json-stringify") {
  8152. doc$$2 = concat$3([doc$$2, hardline$2]);
  8153. }
  8154. return doc$$2;
  8155. }
  8156. function genericPrint(path$$1, options, printPath, args) {
  8157. assert.ok(path$$1 instanceof fastPath);
  8158. var node = path$$1.getValue();
  8159. var printer = options.printer; // Escape hatch
  8160. if (printer.hasPrettierIgnore && printer.hasPrettierIgnore(path$$1)) {
  8161. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  8162. }
  8163. if (node) {
  8164. try {
  8165. // Potentially switch to a different parser
  8166. var sub = multiparser.printSubtree(path$$1, printPath, options, printAstToDoc);
  8167. if (sub) {
  8168. return sub;
  8169. }
  8170. } catch (error) {
  8171. /* istanbul ignore if */
  8172. if (process.env.PRETTIER_DEBUG) {
  8173. throw error;
  8174. } // Continue with current parser
  8175. }
  8176. }
  8177. return printer.print(path$$1, options, printPath, args);
  8178. }
  8179. var astToDoc = printAstToDoc;
  8180. function findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts) {
  8181. var resultStartNode = startNodeAndParents.node;
  8182. var resultEndNode = endNodeAndParents.node;
  8183. if (resultStartNode === resultEndNode) {
  8184. return {
  8185. startNode: resultStartNode,
  8186. endNode: resultEndNode
  8187. };
  8188. }
  8189. var _iteratorNormalCompletion = true;
  8190. var _didIteratorError = false;
  8191. var _iteratorError = undefined;
  8192. try {
  8193. for (var _iterator = endNodeAndParents.parentNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  8194. var endParent = _step.value;
  8195. if (endParent.type !== "Program" && endParent.type !== "File" && opts.locStart(endParent) >= opts.locStart(startNodeAndParents.node)) {
  8196. resultEndNode = endParent;
  8197. } else {
  8198. break;
  8199. }
  8200. }
  8201. } catch (err) {
  8202. _didIteratorError = true;
  8203. _iteratorError = err;
  8204. } finally {
  8205. try {
  8206. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8207. _iterator.return();
  8208. }
  8209. } finally {
  8210. if (_didIteratorError) {
  8211. throw _iteratorError;
  8212. }
  8213. }
  8214. }
  8215. var _iteratorNormalCompletion2 = true;
  8216. var _didIteratorError2 = false;
  8217. var _iteratorError2 = undefined;
  8218. try {
  8219. for (var _iterator2 = startNodeAndParents.parentNodes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  8220. var startParent = _step2.value;
  8221. if (startParent.type !== "Program" && startParent.type !== "File" && opts.locEnd(startParent) <= opts.locEnd(endNodeAndParents.node)) {
  8222. resultStartNode = startParent;
  8223. } else {
  8224. break;
  8225. }
  8226. }
  8227. } catch (err) {
  8228. _didIteratorError2 = true;
  8229. _iteratorError2 = err;
  8230. } finally {
  8231. try {
  8232. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  8233. _iterator2.return();
  8234. }
  8235. } finally {
  8236. if (_didIteratorError2) {
  8237. throw _iteratorError2;
  8238. }
  8239. }
  8240. }
  8241. return {
  8242. startNode: resultStartNode,
  8243. endNode: resultEndNode
  8244. };
  8245. }
  8246. function findNodeAtOffset(node, offset, options, predicate, parentNodes) {
  8247. predicate = predicate || function () {
  8248. return true;
  8249. };
  8250. parentNodes = parentNodes || [];
  8251. var start = options.locStart(node, options.locStart);
  8252. var end = options.locEnd(node, options.locEnd);
  8253. if (start <= offset && offset <= end) {
  8254. var _iteratorNormalCompletion3 = true;
  8255. var _didIteratorError3 = false;
  8256. var _iteratorError3 = undefined;
  8257. try {
  8258. for (var _iterator3 = comments.getSortedChildNodes(node, options)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  8259. var childNode = _step3.value;
  8260. var childResult = findNodeAtOffset(childNode, offset, options, predicate, [node].concat(parentNodes));
  8261. if (childResult) {
  8262. return childResult;
  8263. }
  8264. }
  8265. } catch (err) {
  8266. _didIteratorError3 = true;
  8267. _iteratorError3 = err;
  8268. } finally {
  8269. try {
  8270. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  8271. _iterator3.return();
  8272. }
  8273. } finally {
  8274. if (_didIteratorError3) {
  8275. throw _iteratorError3;
  8276. }
  8277. }
  8278. }
  8279. if (predicate(node)) {
  8280. return {
  8281. node: node,
  8282. parentNodes: parentNodes
  8283. };
  8284. }
  8285. }
  8286. } // See https://www.ecma-international.org/ecma-262/5.1/#sec-A.5
  8287. function isSourceElement(opts, node) {
  8288. if (node == null) {
  8289. return false;
  8290. } // JS and JS like to avoid repetitions
  8291. var jsSourceElements = ["FunctionDeclaration", "BlockStatement", "BreakStatement", "ContinueStatement", "DebuggerStatement", "DoWhileStatement", "EmptyStatement", "ExpressionStatement", "ForInStatement", "ForStatement", "IfStatement", "LabeledStatement", "ReturnStatement", "SwitchStatement", "ThrowStatement", "TryStatement", "VariableDeclaration", "WhileStatement", "WithStatement", "ClassDeclaration", // ES 2015
  8292. "ImportDeclaration", // Module
  8293. "ExportDefaultDeclaration", // Module
  8294. "ExportNamedDeclaration", // Module
  8295. "ExportAllDeclaration", // Module
  8296. "TypeAlias", // Flow
  8297. "InterfaceDeclaration", // Flow, TypeScript
  8298. "TypeAliasDeclaration", // TypeScript
  8299. "ExportAssignment", // TypeScript
  8300. "ExportDeclaration" // TypeScript
  8301. ];
  8302. var jsonSourceElements = ["ObjectExpression", "ArrayExpression", "StringLiteral", "NumericLiteral", "BooleanLiteral", "NullLiteral"];
  8303. var graphqlSourceElements = ["OperationDefinition", "FragmentDefinition", "VariableDefinition", "TypeExtensionDefinition", "ObjectTypeDefinition", "FieldDefinition", "DirectiveDefinition", "EnumTypeDefinition", "EnumValueDefinition", "InputValueDefinition", "InputObjectTypeDefinition", "SchemaDefinition", "OperationTypeDefinition", "InterfaceTypeDefinition", "UnionTypeDefinition", "ScalarTypeDefinition"];
  8304. switch (opts.parser) {
  8305. case "flow":
  8306. case "babylon":
  8307. case "typescript":
  8308. return jsSourceElements.indexOf(node.type) > -1;
  8309. case "json":
  8310. return jsonSourceElements.indexOf(node.type) > -1;
  8311. case "graphql":
  8312. return graphqlSourceElements.indexOf(node.kind) > -1;
  8313. }
  8314. return false;
  8315. }
  8316. function calculateRange(text, opts, ast) {
  8317. // Contract the range so that it has non-whitespace characters at its endpoints.
  8318. // This ensures we can format a range that doesn't end on a node.
  8319. var rangeStringOrig = text.slice(opts.rangeStart, opts.rangeEnd);
  8320. var startNonWhitespace = Math.max(opts.rangeStart + rangeStringOrig.search(/\S/), opts.rangeStart);
  8321. var endNonWhitespace;
  8322. for (endNonWhitespace = opts.rangeEnd; endNonWhitespace > opts.rangeStart; --endNonWhitespace) {
  8323. if (text[endNonWhitespace - 1].match(/\S/)) {
  8324. break;
  8325. }
  8326. }
  8327. var startNodeAndParents = findNodeAtOffset(ast, startNonWhitespace, opts, function (node) {
  8328. return isSourceElement(opts, node);
  8329. });
  8330. var endNodeAndParents = findNodeAtOffset(ast, endNonWhitespace, opts, function (node) {
  8331. return isSourceElement(opts, node);
  8332. });
  8333. if (!startNodeAndParents || !endNodeAndParents) {
  8334. return {
  8335. rangeStart: 0,
  8336. rangeEnd: 0
  8337. };
  8338. }
  8339. var siblingAncestors = findSiblingAncestors(startNodeAndParents, endNodeAndParents, opts);
  8340. var startNode = siblingAncestors.startNode;
  8341. var endNode = siblingAncestors.endNode;
  8342. var rangeStart = Math.min(opts.locStart(startNode, opts.locStart), opts.locStart(endNode, opts.locStart));
  8343. var rangeEnd = Math.max(opts.locEnd(startNode, opts.locEnd), opts.locEnd(endNode, opts.locEnd));
  8344. return {
  8345. rangeStart: rangeStart,
  8346. rangeEnd: rangeEnd
  8347. };
  8348. }
  8349. var rangeUtil = {
  8350. calculateRange,
  8351. findNodeAtOffset
  8352. };
  8353. var normalizeOptions = options.normalize;
  8354. var printDocToString = doc.printer.printDocToString;
  8355. var printDocToDebug = doc.debug.printDocToDebug;
  8356. var UTF8BOM = 0xfeff;
  8357. var CURSOR = Symbol("cursor");
  8358. function guessLineEnding(text) {
  8359. var index = text.indexOf("\n");
  8360. if (index >= 0 && text.charAt(index - 1) === "\r") {
  8361. return "\r\n";
  8362. }
  8363. return "\n";
  8364. }
  8365. function ensureAllCommentsPrinted(astComments) {
  8366. if (!astComments) {
  8367. return;
  8368. }
  8369. for (var i = 0; i < astComments.length; ++i) {
  8370. if (astComments[i].value.trim() === "prettier-ignore") {
  8371. // If there's a prettier-ignore, we're not printing that sub-tree so we
  8372. // don't know if the comments was printed or not.
  8373. return;
  8374. }
  8375. }
  8376. astComments.forEach(function (comment) {
  8377. if (!comment.printed) {
  8378. throw new Error('Comment "' + comment.value.trim() + '" was not printed. Please report this error!');
  8379. }
  8380. delete comment.printed;
  8381. });
  8382. }
  8383. function attachComments(text, ast, opts) {
  8384. var astComments = ast.comments;
  8385. if (astComments) {
  8386. delete ast.comments;
  8387. comments.attach(astComments, ast, text, opts);
  8388. }
  8389. ast.tokens = [];
  8390. opts.originalText = text.trimRight();
  8391. return astComments;
  8392. }
  8393. function coreFormat(text, opts, addAlignmentSize) {
  8394. if (!text || !text.trim().length) {
  8395. return {
  8396. formatted: "",
  8397. cursorOffset: 0
  8398. };
  8399. }
  8400. addAlignmentSize = addAlignmentSize || 0;
  8401. var parsed = parser.parse(text, opts);
  8402. var ast = parsed.ast;
  8403. text = parsed.text;
  8404. if (opts.cursorOffset >= 0) {
  8405. var nodeResult = rangeUtil.findNodeAtOffset(ast, opts.cursorOffset, opts);
  8406. if (nodeResult && nodeResult.node) {
  8407. opts.cursorNode = nodeResult.node;
  8408. }
  8409. }
  8410. var astComments = attachComments(text, ast, opts);
  8411. var doc$$1 = astToDoc(ast, opts, addAlignmentSize);
  8412. opts.newLine = guessLineEnding(text);
  8413. var result = printDocToString(doc$$1, opts);
  8414. ensureAllCommentsPrinted(astComments); // Remove extra leading indentation as well as the added indentation after last newline
  8415. if (addAlignmentSize > 0) {
  8416. var trimmed = result.formatted.trim();
  8417. if (result.cursorNodeStart !== undefined) {
  8418. result.cursorNodeStart -= result.formatted.indexOf(trimmed);
  8419. }
  8420. result.formatted = trimmed + opts.newLine;
  8421. }
  8422. if (opts.cursorOffset >= 0) {
  8423. var oldCursorNodeStart;
  8424. var oldCursorNodeText;
  8425. var cursorOffsetRelativeToOldCursorNode;
  8426. var newCursorNodeStart;
  8427. var newCursorNodeText;
  8428. if (opts.cursorNode && result.cursorNodeText) {
  8429. oldCursorNodeStart = opts.locStart(opts.cursorNode);
  8430. oldCursorNodeText = text.slice(oldCursorNodeStart, opts.locEnd(opts.cursorNode));
  8431. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset - oldCursorNodeStart;
  8432. newCursorNodeStart = result.cursorNodeStart;
  8433. newCursorNodeText = result.cursorNodeText;
  8434. } else {
  8435. oldCursorNodeStart = 0;
  8436. oldCursorNodeText = text;
  8437. cursorOffsetRelativeToOldCursorNode = opts.cursorOffset;
  8438. newCursorNodeStart = 0;
  8439. newCursorNodeText = result.formatted;
  8440. }
  8441. if (oldCursorNodeText === newCursorNodeText) {
  8442. return {
  8443. formatted: result.formatted,
  8444. cursorOffset: newCursorNodeStart + cursorOffsetRelativeToOldCursorNode
  8445. };
  8446. } // diff old and new cursor node texts, with a special cursor
  8447. // symbol inserted to find out where it moves to
  8448. var oldCursorNodeCharArray = oldCursorNodeText.split("");
  8449. oldCursorNodeCharArray.splice(cursorOffsetRelativeToOldCursorNode, 0, CURSOR);
  8450. var newCursorNodeCharArray = newCursorNodeText.split("");
  8451. var cursorNodeDiff = lib.diffArrays(oldCursorNodeCharArray, newCursorNodeCharArray);
  8452. var cursorOffset = newCursorNodeStart;
  8453. var _iteratorNormalCompletion = true;
  8454. var _didIteratorError = false;
  8455. var _iteratorError = undefined;
  8456. try {
  8457. for (var _iterator = cursorNodeDiff[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  8458. var entry = _step.value;
  8459. if (entry.removed) {
  8460. if (entry.value.indexOf(CURSOR) > -1) {
  8461. break;
  8462. }
  8463. } else {
  8464. cursorOffset += entry.count;
  8465. }
  8466. }
  8467. } catch (err) {
  8468. _didIteratorError = true;
  8469. _iteratorError = err;
  8470. } finally {
  8471. try {
  8472. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8473. _iterator.return();
  8474. }
  8475. } finally {
  8476. if (_didIteratorError) {
  8477. throw _iteratorError;
  8478. }
  8479. }
  8480. }
  8481. return {
  8482. formatted: result.formatted,
  8483. cursorOffset
  8484. };
  8485. }
  8486. return {
  8487. formatted: result.formatted
  8488. };
  8489. }
  8490. function formatRange(text, opts) {
  8491. var parsed = parser.parse(text, opts);
  8492. var ast = parsed.ast;
  8493. text = parsed.text;
  8494. var range = rangeUtil.calculateRange(text, opts, ast);
  8495. var rangeStart = range.rangeStart;
  8496. var rangeEnd = range.rangeEnd;
  8497. var rangeString = text.slice(rangeStart, rangeEnd); // Try to extend the range backwards to the beginning of the line.
  8498. // This is so we can detect indentation correctly and restore it.
  8499. // Use `Math.min` since `lastIndexOf` returns 0 when `rangeStart` is 0
  8500. var rangeStart2 = Math.min(rangeStart, text.lastIndexOf("\n", rangeStart) + 1);
  8501. var indentString = text.slice(rangeStart2, rangeStart);
  8502. var alignmentSize = util$1.getAlignmentSize(indentString, opts.tabWidth);
  8503. var rangeResult = coreFormat(rangeString, Object.assign({}, opts, {
  8504. rangeStart: 0,
  8505. rangeEnd: Infinity,
  8506. printWidth: opts.printWidth - alignmentSize,
  8507. // track the cursor offset only if it's within our range
  8508. cursorOffset: opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd ? opts.cursorOffset - rangeStart : -1
  8509. }), alignmentSize); // Since the range contracts to avoid trailing whitespace,
  8510. // we need to remove the newline that was inserted by the `format` call.
  8511. var rangeTrimmed = rangeResult.formatted.trimRight();
  8512. var formatted = text.slice(0, rangeStart) + rangeTrimmed + text.slice(rangeEnd);
  8513. var cursorOffset = opts.cursorOffset;
  8514. if (opts.cursorOffset >= rangeEnd) {
  8515. // handle the case where the cursor was past the end of the range
  8516. cursorOffset = opts.cursorOffset - rangeEnd + (rangeStart + rangeTrimmed.length);
  8517. } else if (rangeResult.cursorOffset !== undefined) {
  8518. // handle the case where the cursor was in the range
  8519. cursorOffset = rangeResult.cursorOffset + rangeStart;
  8520. } // keep the cursor as it was if it was before the start of the range
  8521. return {
  8522. formatted,
  8523. cursorOffset
  8524. };
  8525. }
  8526. function format(text, opts) {
  8527. var selectedParser = parser.resolveParser(opts);
  8528. var hasPragma = !selectedParser.hasPragma || selectedParser.hasPragma(text);
  8529. if (opts.requirePragma && !hasPragma) {
  8530. return {
  8531. formatted: text
  8532. };
  8533. }
  8534. if (opts.rangeStart > 0 || opts.rangeEnd < text.length) {
  8535. return formatRange(text, opts);
  8536. }
  8537. var hasUnicodeBOM = text.charCodeAt(0) === UTF8BOM;
  8538. if (hasUnicodeBOM) {
  8539. text = text.substring(1);
  8540. }
  8541. if (opts.insertPragma && opts.printer.insertPragma && !hasPragma) {
  8542. text = opts.printer.insertPragma(text);
  8543. }
  8544. var result = coreFormat(text, opts);
  8545. if (hasUnicodeBOM) {
  8546. result.formatted = String.fromCharCode(UTF8BOM) + result.formatted;
  8547. }
  8548. return result;
  8549. }
  8550. var core = {
  8551. formatWithCursor(text, opts) {
  8552. opts = normalizeOptions(opts);
  8553. return format(text, normalizeOptions(opts));
  8554. },
  8555. parse(text, opts, massage) {
  8556. opts = normalizeOptions(opts);
  8557. var parsed = parser.parse(text, opts);
  8558. if (massage) {
  8559. parsed.ast = massageAst(parsed.ast, opts);
  8560. }
  8561. return parsed;
  8562. },
  8563. formatAST(ast, opts) {
  8564. opts = normalizeOptions(opts);
  8565. var doc$$1 = astToDoc(ast, opts);
  8566. return printDocToString(doc$$1, opts);
  8567. },
  8568. // Doesn't handle shebang for now
  8569. formatDoc(doc$$1, opts) {
  8570. var debug = printDocToDebug(doc$$1);
  8571. opts = normalizeOptions(Object.assign({}, opts, {
  8572. parser: "babylon"
  8573. }));
  8574. return format(debug, opts).formatted;
  8575. },
  8576. printToDoc(text, opts) {
  8577. opts = normalizeOptions(opts);
  8578. var parsed = parser.parse(text, opts);
  8579. var ast = parsed.ast;
  8580. text = parsed.text;
  8581. attachComments(text, ast, opts);
  8582. return astToDoc(ast, opts);
  8583. },
  8584. printDocToString(doc$$1, opts) {
  8585. return printDocToString(doc$$1, normalizeOptions(opts));
  8586. }
  8587. };
  8588. var _createClass$1 = function () {
  8589. function defineProperties(target, props) {
  8590. for (var i = 0; i < props.length; i++) {
  8591. var descriptor = props[i];
  8592. descriptor.enumerable = descriptor.enumerable || false;
  8593. descriptor.configurable = true;
  8594. if ("value" in descriptor) descriptor.writable = true;
  8595. Object.defineProperty(target, descriptor.key, descriptor);
  8596. }
  8597. }
  8598. return function (Constructor, protoProps, staticProps) {
  8599. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  8600. if (staticProps) defineProperties(Constructor, staticProps);
  8601. return Constructor;
  8602. };
  8603. }();
  8604. function _classCallCheck$1(instance, Constructor) {
  8605. if (!(instance instanceof Constructor)) {
  8606. throw new TypeError("Cannot call a class as a function");
  8607. }
  8608. }
  8609. var ignore = function ignore() {
  8610. return new IgnoreBase();
  8611. }; // A simple implementation of make-array
  8612. function make_array(subject) {
  8613. return Array.isArray(subject) ? subject : [subject];
  8614. }
  8615. var REGEX_BLANK_LINE = /^\s+$/;
  8616. var REGEX_LEADING_EXCAPED_EXCLAMATION = /^\\\!/;
  8617. var REGEX_LEADING_EXCAPED_HASH = /^\\#/;
  8618. var SLASH = '/';
  8619. var KEY_IGNORE = typeof Symbol !== 'undefined' ? Symbol.for('node-ignore')
  8620. /* istanbul ignore next */
  8621. : 'node-ignore';
  8622. var IgnoreBase = function () {
  8623. function IgnoreBase() {
  8624. _classCallCheck$1(this, IgnoreBase);
  8625. this._rules = [];
  8626. this[KEY_IGNORE] = true;
  8627. this._initCache();
  8628. }
  8629. _createClass$1(IgnoreBase, [{
  8630. key: '_initCache',
  8631. value: function _initCache() {
  8632. this._cache = {};
  8633. } // @param {Array.<string>|string|Ignore} pattern
  8634. }, {
  8635. key: 'add',
  8636. value: function add(pattern) {
  8637. this._added = false;
  8638. if (typeof pattern === 'string') {
  8639. pattern = pattern.split(/\r?\n/g);
  8640. }
  8641. make_array(pattern).forEach(this._addPattern, this); // Some rules have just added to the ignore,
  8642. // making the behavior changed.
  8643. if (this._added) {
  8644. this._initCache();
  8645. }
  8646. return this;
  8647. } // legacy
  8648. }, {
  8649. key: 'addPattern',
  8650. value: function addPattern(pattern) {
  8651. return this.add(pattern);
  8652. }
  8653. }, {
  8654. key: '_addPattern',
  8655. value: function _addPattern(pattern) {
  8656. // #32
  8657. if (pattern && pattern[KEY_IGNORE]) {
  8658. this._rules = this._rules.concat(pattern._rules);
  8659. this._added = true;
  8660. return;
  8661. }
  8662. if (this._checkPattern(pattern)) {
  8663. var rule = this._createRule(pattern);
  8664. this._added = true;
  8665. this._rules.push(rule);
  8666. }
  8667. }
  8668. }, {
  8669. key: '_checkPattern',
  8670. value: function _checkPattern(pattern) {
  8671. // > A blank line matches no files, so it can serve as a separator for readability.
  8672. return pattern && typeof pattern === 'string' && !REGEX_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment.
  8673. && pattern.indexOf('#') !== 0;
  8674. }
  8675. }, {
  8676. key: 'filter',
  8677. value: function filter(paths) {
  8678. var _this = this;
  8679. return make_array(paths).filter(function (path$$1) {
  8680. return _this._filter(path$$1);
  8681. });
  8682. }
  8683. }, {
  8684. key: 'createFilter',
  8685. value: function createFilter() {
  8686. var _this2 = this;
  8687. return function (path$$1) {
  8688. return _this2._filter(path$$1);
  8689. };
  8690. }
  8691. }, {
  8692. key: 'ignores',
  8693. value: function ignores(path$$1) {
  8694. return !this._filter(path$$1);
  8695. }
  8696. }, {
  8697. key: '_createRule',
  8698. value: function _createRule(pattern) {
  8699. var origin = pattern;
  8700. var negative = false; // > An optional prefix "!" which negates the pattern;
  8701. if (pattern.indexOf('!') === 0) {
  8702. negative = true;
  8703. pattern = pattern.substr(1);
  8704. }
  8705. pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, `"\!important!.txt"`.
  8706. .replace(REGEX_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that begin with a hash.
  8707. .replace(REGEX_LEADING_EXCAPED_HASH, '#');
  8708. var regex = make_regex(pattern, negative);
  8709. return {
  8710. origin: origin,
  8711. pattern: pattern,
  8712. negative: negative,
  8713. regex: regex
  8714. };
  8715. } // @returns `Boolean` true if the `path` is NOT ignored
  8716. }, {
  8717. key: '_filter',
  8718. value: function _filter(path$$1, slices) {
  8719. if (!path$$1) {
  8720. return false;
  8721. }
  8722. if (path$$1 in this._cache) {
  8723. return this._cache[path$$1];
  8724. }
  8725. if (!slices) {
  8726. // path/to/a.js
  8727. // ['path', 'to', 'a.js']
  8728. slices = path$$1.split(SLASH);
  8729. }
  8730. slices.pop();
  8731. return this._cache[path$$1] = slices.length // > It is not possible to re-include a file if a parent directory of that file is excluded.
  8732. // If the path contains a parent directory, check the parent first
  8733. ? this._filter(slices.join(SLASH) + SLASH, slices) && this._test(path$$1) // Or only test the path
  8734. : this._test(path$$1);
  8735. } // @returns {Boolean} true if a file is NOT ignored
  8736. }, {
  8737. key: '_test',
  8738. value: function _test(path$$1) {
  8739. // Explicitly define variable type by setting matched to `0`
  8740. var matched = 0;
  8741. this._rules.forEach(function (rule) {
  8742. // if matched = true, then we only test negative rules
  8743. // if matched = false, then we test non-negative rules
  8744. if (!(matched ^ rule.negative)) {
  8745. matched = rule.negative ^ rule.regex.test(path$$1);
  8746. }
  8747. });
  8748. return !matched;
  8749. }
  8750. }]);
  8751. return IgnoreBase;
  8752. }(); // > If the pattern ends with a slash,
  8753. // > it is removed for the purpose of the following description,
  8754. // > but it would only find a match with a directory.
  8755. // > In other words, foo/ will match a directory foo and paths underneath it,
  8756. // > but will not match a regular file or a symbolic link foo
  8757. // > (this is consistent with the way how pathspec works in general in Git).
  8758. // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
  8759. // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
  8760. // you could use option `mark: true` with `glob`
  8761. // '`foo/`' should not continue with the '`..`'
  8762. var DEFAULT_REPLACER_PREFIX = [// > Trailing spaces are ignored unless they are quoted with backslash ("\")
  8763. [// (a\ ) -> (a )
  8764. // (a ) -> (a)
  8765. // (a \ ) -> (a )
  8766. /\\?\s+$/, function (match) {
  8767. return match.indexOf('\\') === 0 ? ' ' : '';
  8768. }], // replace (\ ) with ' '
  8769. [/\\\s/g, function () {
  8770. return ' ';
  8771. }], // Escape metacharacters
  8772. // which is written down by users but means special for regular expressions.
  8773. // > There are 12 characters with special meanings:
  8774. // > - the backslash \,
  8775. // > - the caret ^,
  8776. // > - the dollar sign $,
  8777. // > - the period or dot .,
  8778. // > - the vertical bar or pipe symbol |,
  8779. // > - the question mark ?,
  8780. // > - the asterisk or star *,
  8781. // > - the plus sign +,
  8782. // > - the opening parenthesis (,
  8783. // > - the closing parenthesis ),
  8784. // > - and the opening square bracket [,
  8785. // > - the opening curly brace {,
  8786. // > These special characters are often called "metacharacters".
  8787. [/[\\\^$.|?*+()\[{]/g, function (match) {
  8788. return '\\' + match;
  8789. }], // leading slash
  8790. [// > A leading slash matches the beginning of the pathname.
  8791. // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
  8792. // A leading slash matches the beginning of the pathname
  8793. /^\//, function () {
  8794. return '^';
  8795. }], // replace special metacharacter slash after the leading slash
  8796. [/\//g, function () {
  8797. return '\\/';
  8798. }], [// > A leading "**" followed by a slash means match in all directories.
  8799. // > For example, "**/foo" matches file or directory "foo" anywhere,
  8800. // > the same as pattern "foo".
  8801. // > "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".
  8802. // Notice that the '*'s have been replaced as '\\*'
  8803. /^\^*\\\*\\\*\\\//, // '**/foo' <-> 'foo'
  8804. function () {
  8805. return '^(?:.*\\/)?';
  8806. }]];
  8807. var DEFAULT_REPLACER_SUFFIX = [// starting
  8808. [// there will be no leading '/' (which has been replaced by section "leading slash")
  8809. // If starts with '**', adding a '^' to the regular expression also works
  8810. /^(?=[^\^])/, function () {
  8811. return !/\/(?!$)/.test(this) // > If the pattern does not contain a slash /, Git treats it as a shell glob pattern
  8812. // Actually, if there is only a trailing slash, git also treats it as a shell glob pattern
  8813. ? '(?:^|\\/)' // > Otherwise, Git treats the pattern as a shell glob suitable for consumption by fnmatch(3)
  8814. : '^';
  8815. }], // two globstars
  8816. [// Use lookahead assertions so that we could match more than one `'/**'`
  8817. /\\\/\\\*\\\*(?=\\\/|$)/g, // Zero, one or several directories
  8818. // should not use '*', or it will be replaced by the next replacer
  8819. // Check if it is not the last `'/**'`
  8820. function (match, index, str) {
  8821. return index + 6 < str.length // case: /**/
  8822. // > A slash followed by two consecutive asterisks then a slash matches zero or more directories.
  8823. // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
  8824. // '/**/'
  8825. ? '(?:\\/[^\\/]+)*' // case: /**
  8826. // > A trailing `"/**"` matches everything inside.
  8827. // #21: everything inside but it should not include the current folder
  8828. : '\\/.+';
  8829. }], // intermediate wildcards
  8830. [// Never replace escaped '*'
  8831. // ignore rule '\*' will match the path '*'
  8832. // 'abc.*/' -> go
  8833. // 'abc.*' -> skip this rule
  8834. /(^|[^\\]+)\\\*(?=.+)/g, // '*.js' matches '.js'
  8835. // '*.js' doesn't match 'abc'
  8836. function (match, p1) {
  8837. return p1 + '[^\\/]*';
  8838. }], // trailing wildcard
  8839. [/(\^|\\\/)?\\\*$/, function (match, p1) {
  8840. return (p1 // '\^':
  8841. // '/*' does not match ''
  8842. // '/*' does not match everything
  8843. // '\\\/':
  8844. // 'abc/*' does not match 'abc/'
  8845. ? p1 + '[^/]+' // 'a*' matches 'a'
  8846. // 'a*' matches 'aa'
  8847. : '[^/]*') + '(?=$|\\/$)';
  8848. }], [// unescape
  8849. /\\\\\\/g, function () {
  8850. return '\\';
  8851. }]];
  8852. var POSITIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [// 'f'
  8853. // matches
  8854. // - /f(end)
  8855. // - /f/
  8856. // - (start)f(end)
  8857. // - (start)f/
  8858. // doesn't match
  8859. // - oof
  8860. // - foo
  8861. // pseudo:
  8862. // -> (^|/)f(/|$)
  8863. // ending
  8864. [// 'js' will not match 'js.'
  8865. // 'ab' will not match 'abc'
  8866. /(?:[^*\/])$/, // 'js*' will not match 'a.js'
  8867. // 'js/' will not match 'a.js'
  8868. // 'js' will match 'a.js' and 'a.js/'
  8869. function (match) {
  8870. return match + '(?=$|\\/)';
  8871. }]], DEFAULT_REPLACER_SUFFIX);
  8872. var NEGATIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [// #24
  8873. // The MISSING rule of [gitignore docs](https://git-scm.com/docs/gitignore)
  8874. // A negative pattern without a trailing wildcard should not
  8875. // re-include the things inside that directory.
  8876. // eg:
  8877. // ['node_modules/*', '!node_modules']
  8878. // should ignore `node_modules/a.js`
  8879. [/(?:[^*\/])$/, function (match) {
  8880. return match + '(?=$|\\/$)';
  8881. }]], DEFAULT_REPLACER_SUFFIX); // A simple cache, because an ignore rule only has only one certain meaning
  8882. var cache = {}; // @param {pattern}
  8883. function make_regex(pattern, negative) {
  8884. var r = cache[pattern];
  8885. if (r) {
  8886. return r;
  8887. }
  8888. var replacers = negative ? NEGATIVE_REPLACERS : POSITIVE_REPLACERS;
  8889. var source = replacers.reduce(function (prev, current) {
  8890. return prev.replace(current[0], current[1].bind(pattern));
  8891. }, pattern);
  8892. return cache[pattern] = new RegExp(source, 'i');
  8893. } // Windows
  8894. // --------------------------------------------------------------
  8895. /* istanbul ignore if */
  8896. if ( // Detect `process` so that it can run in browsers.
  8897. typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) {
  8898. var filter = IgnoreBase.prototype._filter;
  8899. var make_posix = function make_posix(str) {
  8900. return /^\\\\\?\\/.test(str) || /[^\x00-\x80]+/.test(str) ? str : str.replace(/\\/g, '/');
  8901. };
  8902. IgnoreBase.prototype._filter = function (path$$1, slices) {
  8903. path$$1 = make_posix(path$$1);
  8904. return filter.call(this, path$$1, slices);
  8905. };
  8906. }
  8907. /**
  8908. * @param {string} filename
  8909. * @returns {Promise<null | string>}
  8910. */
  8911. function getFileContentOrNull(filename) {
  8912. return new Promise(function (resolve, reject) {
  8913. fs.readFile(filename, "utf8", function (error, data) {
  8914. if (error && error.code !== "ENOENT") {
  8915. reject(createError(filename, error));
  8916. } else {
  8917. resolve(error ? null : data);
  8918. }
  8919. });
  8920. });
  8921. }
  8922. /**
  8923. * @param {string} filename
  8924. * @returns {null | string}
  8925. */
  8926. getFileContentOrNull.sync = function (filename) {
  8927. try {
  8928. return fs.readFileSync(filename, "utf8");
  8929. } catch (error) {
  8930. if (error && error.code === "ENOENT") {
  8931. return null;
  8932. }
  8933. throw createError(filename, error);
  8934. }
  8935. };
  8936. function createError(filename, error) {
  8937. return new Error(`Unable to read ${filename}: ${error.message}`);
  8938. }
  8939. var getFileContentOrNull_1 = getFileContentOrNull;
  8940. /**
  8941. * @param {undefined | string} ignorePath
  8942. * @param {undefined | boolean} withNodeModules
  8943. */
  8944. function createIgnorer(ignorePath, withNodeModules) {
  8945. return (!ignorePath ? Promise.resolve(null) : getFileContentOrNull_1(path.resolve(ignorePath))).then(function (ignoreContent) {
  8946. return _createIgnorer(ignoreContent, withNodeModules);
  8947. });
  8948. }
  8949. /**
  8950. * @param {undefined | string} ignorePath
  8951. * @param {undefined | boolean} withNodeModules
  8952. */
  8953. createIgnorer.sync = function (ignorePath, withNodeModules) {
  8954. var ignoreContent = !ignorePath ? null : getFileContentOrNull_1.sync(path.resolve(ignorePath));
  8955. return _createIgnorer(ignoreContent, withNodeModules);
  8956. };
  8957. /**
  8958. * @param {null | string} ignoreContent
  8959. * @param {undefined | boolean} withNodeModules
  8960. */
  8961. function _createIgnorer(ignoreContent, withNodeModules) {
  8962. var ignorer = ignore().add(ignoreContent || "");
  8963. if (!withNodeModules) {
  8964. ignorer.add("node_modules");
  8965. }
  8966. return ignorer;
  8967. }
  8968. var createIgnorer_1 = createIgnorer;
  8969. /**
  8970. * @typedef {{ ignorePath?: string, withNodeModules?: boolean, plugins: object }} FileInfoOptions
  8971. * @typedef {{ ignored: boolean, inferredParser: string | null }} FileInfoResult
  8972. */
  8973. /**
  8974. * @param {string} filePath
  8975. * @param {FileInfoOptions} opts
  8976. * @returns {Promise<FileInfoResult>}
  8977. *
  8978. * Please note that prettier.getFileInfo() expects opts.plugins to be an array of paths,
  8979. * not an object. A transformation from this array to an object is automatically done
  8980. * internally by the method wrapper. See withPlugins() in index.js.
  8981. */
  8982. function getFileInfo(filePath, opts) {
  8983. return createIgnorer_1(opts.ignorePath, opts.withNodeModules).then(function (ignorer) {
  8984. return _getFileInfo(ignorer, filePath, opts.plugins);
  8985. });
  8986. }
  8987. /**
  8988. * @param {string} filePath
  8989. * @param {FileInfoOptions} opts
  8990. * @returns {FileInfoResult}
  8991. */
  8992. getFileInfo.sync = function (filePath, opts) {
  8993. var ignorer = createIgnorer_1.sync(opts.ignorePath, opts.withNodeModules);
  8994. return _getFileInfo(ignorer, filePath, opts.plugins);
  8995. };
  8996. function _getFileInfo(ignorer, filePath, plugins) {
  8997. var ignored = ignorer.ignores(filePath);
  8998. var inferredParser = options.inferParser(filePath, plugins) || null;
  8999. return {
  9000. ignored,
  9001. inferredParser
  9002. };
  9003. }
  9004. var getFileInfo_1 = getFileInfo;
  9005. var lodash_uniqby = createCommonjsModule(function (module, exports) {
  9006. /**
  9007. * lodash (Custom Build) <https://lodash.com/>
  9008. * Build: `lodash modularize exports="npm" -o ./`
  9009. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  9010. * Released under MIT license <https://lodash.com/license>
  9011. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9012. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9013. */
  9014. /** Used as the size to enable large array optimizations. */
  9015. var LARGE_ARRAY_SIZE = 200;
  9016. /** Used as the `TypeError` message for "Functions" methods. */
  9017. var FUNC_ERROR_TEXT = 'Expected a function';
  9018. /** Used to stand-in for `undefined` hash values. */
  9019. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  9020. /** Used to compose bitmasks for comparison styles. */
  9021. var UNORDERED_COMPARE_FLAG = 1,
  9022. PARTIAL_COMPARE_FLAG = 2;
  9023. /** Used as references for various `Number` constants. */
  9024. var INFINITY = 1 / 0,
  9025. MAX_SAFE_INTEGER = 9007199254740991;
  9026. /** `Object#toString` result references. */
  9027. var argsTag = '[object Arguments]',
  9028. arrayTag = '[object Array]',
  9029. boolTag = '[object Boolean]',
  9030. dateTag = '[object Date]',
  9031. errorTag = '[object Error]',
  9032. funcTag = '[object Function]',
  9033. genTag = '[object GeneratorFunction]',
  9034. mapTag = '[object Map]',
  9035. numberTag = '[object Number]',
  9036. objectTag = '[object Object]',
  9037. promiseTag = '[object Promise]',
  9038. regexpTag = '[object RegExp]',
  9039. setTag = '[object Set]',
  9040. stringTag = '[object String]',
  9041. symbolTag = '[object Symbol]',
  9042. weakMapTag = '[object WeakMap]';
  9043. var arrayBufferTag = '[object ArrayBuffer]',
  9044. dataViewTag = '[object DataView]',
  9045. float32Tag = '[object Float32Array]',
  9046. float64Tag = '[object Float64Array]',
  9047. int8Tag = '[object Int8Array]',
  9048. int16Tag = '[object Int16Array]',
  9049. int32Tag = '[object Int32Array]',
  9050. uint8Tag = '[object Uint8Array]',
  9051. uint8ClampedTag = '[object Uint8ClampedArray]',
  9052. uint16Tag = '[object Uint16Array]',
  9053. uint32Tag = '[object Uint32Array]';
  9054. /** Used to match property names within property paths. */
  9055. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  9056. reIsPlainProp = /^\w*$/,
  9057. reLeadingDot = /^\./,
  9058. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  9059. /**
  9060. * Used to match `RegExp`
  9061. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  9062. */
  9063. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  9064. /** Used to match backslashes in property paths. */
  9065. var reEscapeChar = /\\(\\)?/g;
  9066. /** Used to detect host constructors (Safari). */
  9067. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  9068. /** Used to detect unsigned integer values. */
  9069. var reIsUint = /^(?:0|[1-9]\d*)$/;
  9070. /** Used to identify `toStringTag` values of typed arrays. */
  9071. var typedArrayTags = {};
  9072. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  9073. typedArrayTags[argsTag] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag] = typedArrayTags[mapTag] = typedArrayTags[numberTag] = typedArrayTags[objectTag] = typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  9074. /** Detect free variable `global` from Node.js. */
  9075. var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
  9076. /** Detect free variable `self`. */
  9077. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  9078. /** Used as a reference to the global object. */
  9079. var root = freeGlobal || freeSelf || Function('return this')();
  9080. /** Detect free variable `exports`. */
  9081. var freeExports = 'object' == 'object' && exports && !exports.nodeType && exports;
  9082. /** Detect free variable `module`. */
  9083. var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
  9084. /** Detect the popular CommonJS extension `module.exports`. */
  9085. var moduleExports = freeModule && freeModule.exports === freeExports;
  9086. /** Detect free variable `process` from Node.js. */
  9087. var freeProcess = moduleExports && freeGlobal.process;
  9088. /** Used to access faster Node.js helpers. */
  9089. var nodeUtil = function () {
  9090. try {
  9091. return freeProcess && freeProcess.binding('util');
  9092. } catch (e) {}
  9093. }();
  9094. /* Node.js helper references. */
  9095. var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  9096. /**
  9097. * A specialized version of `_.includes` for arrays without support for
  9098. * specifying an index to search from.
  9099. *
  9100. * @private
  9101. * @param {Array} [array] The array to inspect.
  9102. * @param {*} target The value to search for.
  9103. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  9104. */
  9105. function arrayIncludes(array, value) {
  9106. var length = array ? array.length : 0;
  9107. return !!length && baseIndexOf(array, value, 0) > -1;
  9108. }
  9109. /**
  9110. * This function is like `arrayIncludes` except that it accepts a comparator.
  9111. *
  9112. * @private
  9113. * @param {Array} [array] The array to inspect.
  9114. * @param {*} target The value to search for.
  9115. * @param {Function} comparator The comparator invoked per element.
  9116. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  9117. */
  9118. function arrayIncludesWith(array, value, comparator) {
  9119. var index = -1,
  9120. length = array ? array.length : 0;
  9121. while (++index < length) {
  9122. if (comparator(value, array[index])) {
  9123. return true;
  9124. }
  9125. }
  9126. return false;
  9127. }
  9128. /**
  9129. * A specialized version of `_.some` for arrays without support for iteratee
  9130. * shorthands.
  9131. *
  9132. * @private
  9133. * @param {Array} [array] The array to iterate over.
  9134. * @param {Function} predicate The function invoked per iteration.
  9135. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9136. * else `false`.
  9137. */
  9138. function arraySome(array, predicate) {
  9139. var index = -1,
  9140. length = array ? array.length : 0;
  9141. while (++index < length) {
  9142. if (predicate(array[index], index, array)) {
  9143. return true;
  9144. }
  9145. }
  9146. return false;
  9147. }
  9148. /**
  9149. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  9150. * support for iteratee shorthands.
  9151. *
  9152. * @private
  9153. * @param {Array} array The array to inspect.
  9154. * @param {Function} predicate The function invoked per iteration.
  9155. * @param {number} fromIndex The index to search from.
  9156. * @param {boolean} [fromRight] Specify iterating from right to left.
  9157. * @returns {number} Returns the index of the matched value, else `-1`.
  9158. */
  9159. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  9160. var length = array.length,
  9161. index = fromIndex + (fromRight ? 1 : -1);
  9162. while (fromRight ? index-- : ++index < length) {
  9163. if (predicate(array[index], index, array)) {
  9164. return index;
  9165. }
  9166. }
  9167. return -1;
  9168. }
  9169. /**
  9170. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  9171. *
  9172. * @private
  9173. * @param {Array} array The array to inspect.
  9174. * @param {*} value The value to search for.
  9175. * @param {number} fromIndex The index to search from.
  9176. * @returns {number} Returns the index of the matched value, else `-1`.
  9177. */
  9178. function baseIndexOf(array, value, fromIndex) {
  9179. if (value !== value) {
  9180. return baseFindIndex(array, baseIsNaN, fromIndex);
  9181. }
  9182. var index = fromIndex - 1,
  9183. length = array.length;
  9184. while (++index < length) {
  9185. if (array[index] === value) {
  9186. return index;
  9187. }
  9188. }
  9189. return -1;
  9190. }
  9191. /**
  9192. * The base implementation of `_.isNaN` without support for number objects.
  9193. *
  9194. * @private
  9195. * @param {*} value The value to check.
  9196. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  9197. */
  9198. function baseIsNaN(value) {
  9199. return value !== value;
  9200. }
  9201. /**
  9202. * The base implementation of `_.property` without support for deep paths.
  9203. *
  9204. * @private
  9205. * @param {string} key The key of the property to get.
  9206. * @returns {Function} Returns the new accessor function.
  9207. */
  9208. function baseProperty(key) {
  9209. return function (object) {
  9210. return object == null ? undefined : object[key];
  9211. };
  9212. }
  9213. /**
  9214. * The base implementation of `_.times` without support for iteratee shorthands
  9215. * or max array length checks.
  9216. *
  9217. * @private
  9218. * @param {number} n The number of times to invoke `iteratee`.
  9219. * @param {Function} iteratee The function invoked per iteration.
  9220. * @returns {Array} Returns the array of results.
  9221. */
  9222. function baseTimes(n, iteratee) {
  9223. var index = -1,
  9224. result = Array(n);
  9225. while (++index < n) {
  9226. result[index] = iteratee(index);
  9227. }
  9228. return result;
  9229. }
  9230. /**
  9231. * The base implementation of `_.unary` without support for storing metadata.
  9232. *
  9233. * @private
  9234. * @param {Function} func The function to cap arguments for.
  9235. * @returns {Function} Returns the new capped function.
  9236. */
  9237. function baseUnary(func) {
  9238. return function (value) {
  9239. return func(value);
  9240. };
  9241. }
  9242. /**
  9243. * Checks if a cache value for `key` exists.
  9244. *
  9245. * @private
  9246. * @param {Object} cache The cache to query.
  9247. * @param {string} key The key of the entry to check.
  9248. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9249. */
  9250. function cacheHas(cache, key) {
  9251. return cache.has(key);
  9252. }
  9253. /**
  9254. * Gets the value at `key` of `object`.
  9255. *
  9256. * @private
  9257. * @param {Object} [object] The object to query.
  9258. * @param {string} key The key of the property to get.
  9259. * @returns {*} Returns the property value.
  9260. */
  9261. function getValue(object, key) {
  9262. return object == null ? undefined : object[key];
  9263. }
  9264. /**
  9265. * Checks if `value` is a host object in IE < 9.
  9266. *
  9267. * @private
  9268. * @param {*} value The value to check.
  9269. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  9270. */
  9271. function isHostObject(value) {
  9272. // Many host objects are `Object` objects that can coerce to strings
  9273. // despite having improperly defined `toString` methods.
  9274. var result = false;
  9275. if (value != null && typeof value.toString != 'function') {
  9276. try {
  9277. result = !!(value + '');
  9278. } catch (e) {}
  9279. }
  9280. return result;
  9281. }
  9282. /**
  9283. * Converts `map` to its key-value pairs.
  9284. *
  9285. * @private
  9286. * @param {Object} map The map to convert.
  9287. * @returns {Array} Returns the key-value pairs.
  9288. */
  9289. function mapToArray(map) {
  9290. var index = -1,
  9291. result = Array(map.size);
  9292. map.forEach(function (value, key) {
  9293. result[++index] = [key, value];
  9294. });
  9295. return result;
  9296. }
  9297. /**
  9298. * Creates a unary function that invokes `func` with its argument transformed.
  9299. *
  9300. * @private
  9301. * @param {Function} func The function to wrap.
  9302. * @param {Function} transform The argument transform.
  9303. * @returns {Function} Returns the new function.
  9304. */
  9305. function overArg(func, transform) {
  9306. return function (arg) {
  9307. return func(transform(arg));
  9308. };
  9309. }
  9310. /**
  9311. * Converts `set` to an array of its values.
  9312. *
  9313. * @private
  9314. * @param {Object} set The set to convert.
  9315. * @returns {Array} Returns the values.
  9316. */
  9317. function setToArray(set) {
  9318. var index = -1,
  9319. result = Array(set.size);
  9320. set.forEach(function (value) {
  9321. result[++index] = value;
  9322. });
  9323. return result;
  9324. }
  9325. /** Used for built-in method references. */
  9326. var arrayProto = Array.prototype,
  9327. funcProto = Function.prototype,
  9328. objectProto = Object.prototype;
  9329. /** Used to detect overreaching core-js shims. */
  9330. var coreJsData = root['__core-js_shared__'];
  9331. /** Used to detect methods masquerading as native. */
  9332. var maskSrcKey = function () {
  9333. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  9334. return uid ? 'Symbol(src)_1.' + uid : '';
  9335. }();
  9336. /** Used to resolve the decompiled source of functions. */
  9337. var funcToString = funcProto.toString;
  9338. /** Used to check objects for own properties. */
  9339. var hasOwnProperty = objectProto.hasOwnProperty;
  9340. /**
  9341. * Used to resolve the
  9342. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  9343. * of values.
  9344. */
  9345. var objectToString = objectProto.toString;
  9346. /** Used to detect if a method is native. */
  9347. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  9348. /** Built-in value references. */
  9349. var Symbol = root.Symbol,
  9350. Uint8Array = root.Uint8Array,
  9351. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  9352. splice = arrayProto.splice;
  9353. /* Built-in method references for those with the same name as other `lodash` methods. */
  9354. var nativeKeys = overArg(Object.keys, Object);
  9355. /* Built-in method references that are verified to be native. */
  9356. var DataView = getNative(root, 'DataView'),
  9357. Map = getNative(root, 'Map'),
  9358. Promise = getNative(root, 'Promise'),
  9359. Set = getNative(root, 'Set'),
  9360. WeakMap = getNative(root, 'WeakMap'),
  9361. nativeCreate = getNative(Object, 'create');
  9362. /** Used to detect maps, sets, and weakmaps. */
  9363. var dataViewCtorString = toSource(DataView),
  9364. mapCtorString = toSource(Map),
  9365. promiseCtorString = toSource(Promise),
  9366. setCtorString = toSource(Set),
  9367. weakMapCtorString = toSource(WeakMap);
  9368. /** Used to convert symbols to primitives and strings. */
  9369. var symbolProto = Symbol ? Symbol.prototype : undefined,
  9370. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  9371. symbolToString = symbolProto ? symbolProto.toString : undefined;
  9372. /**
  9373. * Creates a hash object.
  9374. *
  9375. * @private
  9376. * @constructor
  9377. * @param {Array} [entries] The key-value pairs to cache.
  9378. */
  9379. function Hash(entries) {
  9380. var index = -1,
  9381. length = entries ? entries.length : 0;
  9382. this.clear();
  9383. while (++index < length) {
  9384. var entry = entries[index];
  9385. this.set(entry[0], entry[1]);
  9386. }
  9387. }
  9388. /**
  9389. * Removes all key-value entries from the hash.
  9390. *
  9391. * @private
  9392. * @name clear
  9393. * @memberOf Hash
  9394. */
  9395. function hashClear() {
  9396. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  9397. }
  9398. /**
  9399. * Removes `key` and its value from the hash.
  9400. *
  9401. * @private
  9402. * @name delete
  9403. * @memberOf Hash
  9404. * @param {Object} hash The hash to modify.
  9405. * @param {string} key The key of the value to remove.
  9406. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  9407. */
  9408. function hashDelete(key) {
  9409. return this.has(key) && delete this.__data__[key];
  9410. }
  9411. /**
  9412. * Gets the hash value for `key`.
  9413. *
  9414. * @private
  9415. * @name get
  9416. * @memberOf Hash
  9417. * @param {string} key The key of the value to get.
  9418. * @returns {*} Returns the entry value.
  9419. */
  9420. function hashGet(key) {
  9421. var data = this.__data__;
  9422. if (nativeCreate) {
  9423. var result = data[key];
  9424. return result === HASH_UNDEFINED ? undefined : result;
  9425. }
  9426. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  9427. }
  9428. /**
  9429. * Checks if a hash value for `key` exists.
  9430. *
  9431. * @private
  9432. * @name has
  9433. * @memberOf Hash
  9434. * @param {string} key The key of the entry to check.
  9435. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9436. */
  9437. function hashHas(key) {
  9438. var data = this.__data__;
  9439. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  9440. }
  9441. /**
  9442. * Sets the hash `key` to `value`.
  9443. *
  9444. * @private
  9445. * @name set
  9446. * @memberOf Hash
  9447. * @param {string} key The key of the value to set.
  9448. * @param {*} value The value to set.
  9449. * @returns {Object} Returns the hash instance.
  9450. */
  9451. function hashSet(key, value) {
  9452. var data = this.__data__;
  9453. data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
  9454. return this;
  9455. } // Add methods to `Hash`.
  9456. Hash.prototype.clear = hashClear;
  9457. Hash.prototype['delete'] = hashDelete;
  9458. Hash.prototype.get = hashGet;
  9459. Hash.prototype.has = hashHas;
  9460. Hash.prototype.set = hashSet;
  9461. /**
  9462. * Creates an list cache object.
  9463. *
  9464. * @private
  9465. * @constructor
  9466. * @param {Array} [entries] The key-value pairs to cache.
  9467. */
  9468. function ListCache(entries) {
  9469. var index = -1,
  9470. length = entries ? entries.length : 0;
  9471. this.clear();
  9472. while (++index < length) {
  9473. var entry = entries[index];
  9474. this.set(entry[0], entry[1]);
  9475. }
  9476. }
  9477. /**
  9478. * Removes all key-value entries from the list cache.
  9479. *
  9480. * @private
  9481. * @name clear
  9482. * @memberOf ListCache
  9483. */
  9484. function listCacheClear() {
  9485. this.__data__ = [];
  9486. }
  9487. /**
  9488. * Removes `key` and its value from the list cache.
  9489. *
  9490. * @private
  9491. * @name delete
  9492. * @memberOf ListCache
  9493. * @param {string} key The key of the value to remove.
  9494. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  9495. */
  9496. function listCacheDelete(key) {
  9497. var data = this.__data__,
  9498. index = assocIndexOf(data, key);
  9499. if (index < 0) {
  9500. return false;
  9501. }
  9502. var lastIndex = data.length - 1;
  9503. if (index == lastIndex) {
  9504. data.pop();
  9505. } else {
  9506. splice.call(data, index, 1);
  9507. }
  9508. return true;
  9509. }
  9510. /**
  9511. * Gets the list cache value for `key`.
  9512. *
  9513. * @private
  9514. * @name get
  9515. * @memberOf ListCache
  9516. * @param {string} key The key of the value to get.
  9517. * @returns {*} Returns the entry value.
  9518. */
  9519. function listCacheGet(key) {
  9520. var data = this.__data__,
  9521. index = assocIndexOf(data, key);
  9522. return index < 0 ? undefined : data[index][1];
  9523. }
  9524. /**
  9525. * Checks if a list cache value for `key` exists.
  9526. *
  9527. * @private
  9528. * @name has
  9529. * @memberOf ListCache
  9530. * @param {string} key The key of the entry to check.
  9531. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9532. */
  9533. function listCacheHas(key) {
  9534. return assocIndexOf(this.__data__, key) > -1;
  9535. }
  9536. /**
  9537. * Sets the list cache `key` to `value`.
  9538. *
  9539. * @private
  9540. * @name set
  9541. * @memberOf ListCache
  9542. * @param {string} key The key of the value to set.
  9543. * @param {*} value The value to set.
  9544. * @returns {Object} Returns the list cache instance.
  9545. */
  9546. function listCacheSet(key, value) {
  9547. var data = this.__data__,
  9548. index = assocIndexOf(data, key);
  9549. if (index < 0) {
  9550. data.push([key, value]);
  9551. } else {
  9552. data[index][1] = value;
  9553. }
  9554. return this;
  9555. } // Add methods to `ListCache`.
  9556. ListCache.prototype.clear = listCacheClear;
  9557. ListCache.prototype['delete'] = listCacheDelete;
  9558. ListCache.prototype.get = listCacheGet;
  9559. ListCache.prototype.has = listCacheHas;
  9560. ListCache.prototype.set = listCacheSet;
  9561. /**
  9562. * Creates a map cache object to store key-value pairs.
  9563. *
  9564. * @private
  9565. * @constructor
  9566. * @param {Array} [entries] The key-value pairs to cache.
  9567. */
  9568. function MapCache(entries) {
  9569. var index = -1,
  9570. length = entries ? entries.length : 0;
  9571. this.clear();
  9572. while (++index < length) {
  9573. var entry = entries[index];
  9574. this.set(entry[0], entry[1]);
  9575. }
  9576. }
  9577. /**
  9578. * Removes all key-value entries from the map.
  9579. *
  9580. * @private
  9581. * @name clear
  9582. * @memberOf MapCache
  9583. */
  9584. function mapCacheClear() {
  9585. this.__data__ = {
  9586. 'hash': new Hash(),
  9587. 'map': new (Map || ListCache)(),
  9588. 'string': new Hash()
  9589. };
  9590. }
  9591. /**
  9592. * Removes `key` and its value from the map.
  9593. *
  9594. * @private
  9595. * @name delete
  9596. * @memberOf MapCache
  9597. * @param {string} key The key of the value to remove.
  9598. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  9599. */
  9600. function mapCacheDelete(key) {
  9601. return getMapData(this, key)['delete'](key);
  9602. }
  9603. /**
  9604. * Gets the map value for `key`.
  9605. *
  9606. * @private
  9607. * @name get
  9608. * @memberOf MapCache
  9609. * @param {string} key The key of the value to get.
  9610. * @returns {*} Returns the entry value.
  9611. */
  9612. function mapCacheGet(key) {
  9613. return getMapData(this, key).get(key);
  9614. }
  9615. /**
  9616. * Checks if a map value for `key` exists.
  9617. *
  9618. * @private
  9619. * @name has
  9620. * @memberOf MapCache
  9621. * @param {string} key The key of the entry to check.
  9622. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9623. */
  9624. function mapCacheHas(key) {
  9625. return getMapData(this, key).has(key);
  9626. }
  9627. /**
  9628. * Sets the map `key` to `value`.
  9629. *
  9630. * @private
  9631. * @name set
  9632. * @memberOf MapCache
  9633. * @param {string} key The key of the value to set.
  9634. * @param {*} value The value to set.
  9635. * @returns {Object} Returns the map cache instance.
  9636. */
  9637. function mapCacheSet(key, value) {
  9638. getMapData(this, key).set(key, value);
  9639. return this;
  9640. } // Add methods to `MapCache`.
  9641. MapCache.prototype.clear = mapCacheClear;
  9642. MapCache.prototype['delete'] = mapCacheDelete;
  9643. MapCache.prototype.get = mapCacheGet;
  9644. MapCache.prototype.has = mapCacheHas;
  9645. MapCache.prototype.set = mapCacheSet;
  9646. /**
  9647. *
  9648. * Creates an array cache object to store unique values.
  9649. *
  9650. * @private
  9651. * @constructor
  9652. * @param {Array} [values] The values to cache.
  9653. */
  9654. function SetCache(values) {
  9655. var index = -1,
  9656. length = values ? values.length : 0;
  9657. this.__data__ = new MapCache();
  9658. while (++index < length) {
  9659. this.add(values[index]);
  9660. }
  9661. }
  9662. /**
  9663. * Adds `value` to the array cache.
  9664. *
  9665. * @private
  9666. * @name add
  9667. * @memberOf SetCache
  9668. * @alias push
  9669. * @param {*} value The value to cache.
  9670. * @returns {Object} Returns the cache instance.
  9671. */
  9672. function setCacheAdd(value) {
  9673. this.__data__.set(value, HASH_UNDEFINED);
  9674. return this;
  9675. }
  9676. /**
  9677. * Checks if `value` is in the array cache.
  9678. *
  9679. * @private
  9680. * @name has
  9681. * @memberOf SetCache
  9682. * @param {*} value The value to search for.
  9683. * @returns {number} Returns `true` if `value` is found, else `false`.
  9684. */
  9685. function setCacheHas(value) {
  9686. return this.__data__.has(value);
  9687. } // Add methods to `SetCache`.
  9688. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  9689. SetCache.prototype.has = setCacheHas;
  9690. /**
  9691. * Creates a stack cache object to store key-value pairs.
  9692. *
  9693. * @private
  9694. * @constructor
  9695. * @param {Array} [entries] The key-value pairs to cache.
  9696. */
  9697. function Stack(entries) {
  9698. this.__data__ = new ListCache(entries);
  9699. }
  9700. /**
  9701. * Removes all key-value entries from the stack.
  9702. *
  9703. * @private
  9704. * @name clear
  9705. * @memberOf Stack
  9706. */
  9707. function stackClear() {
  9708. this.__data__ = new ListCache();
  9709. }
  9710. /**
  9711. * Removes `key` and its value from the stack.
  9712. *
  9713. * @private
  9714. * @name delete
  9715. * @memberOf Stack
  9716. * @param {string} key The key of the value to remove.
  9717. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  9718. */
  9719. function stackDelete(key) {
  9720. return this.__data__['delete'](key);
  9721. }
  9722. /**
  9723. * Gets the stack value for `key`.
  9724. *
  9725. * @private
  9726. * @name get
  9727. * @memberOf Stack
  9728. * @param {string} key The key of the value to get.
  9729. * @returns {*} Returns the entry value.
  9730. */
  9731. function stackGet(key) {
  9732. return this.__data__.get(key);
  9733. }
  9734. /**
  9735. * Checks if a stack value for `key` exists.
  9736. *
  9737. * @private
  9738. * @name has
  9739. * @memberOf Stack
  9740. * @param {string} key The key of the entry to check.
  9741. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9742. */
  9743. function stackHas(key) {
  9744. return this.__data__.has(key);
  9745. }
  9746. /**
  9747. * Sets the stack `key` to `value`.
  9748. *
  9749. * @private
  9750. * @name set
  9751. * @memberOf Stack
  9752. * @param {string} key The key of the value to set.
  9753. * @param {*} value The value to set.
  9754. * @returns {Object} Returns the stack cache instance.
  9755. */
  9756. function stackSet(key, value) {
  9757. var cache = this.__data__;
  9758. if (cache instanceof ListCache) {
  9759. var pairs = cache.__data__;
  9760. if (!Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  9761. pairs.push([key, value]);
  9762. return this;
  9763. }
  9764. cache = this.__data__ = new MapCache(pairs);
  9765. }
  9766. cache.set(key, value);
  9767. return this;
  9768. } // Add methods to `Stack`.
  9769. Stack.prototype.clear = stackClear;
  9770. Stack.prototype['delete'] = stackDelete;
  9771. Stack.prototype.get = stackGet;
  9772. Stack.prototype.has = stackHas;
  9773. Stack.prototype.set = stackSet;
  9774. /**
  9775. * Creates an array of the enumerable property names of the array-like `value`.
  9776. *
  9777. * @private
  9778. * @param {*} value The value to query.
  9779. * @param {boolean} inherited Specify returning inherited property names.
  9780. * @returns {Array} Returns the array of property names.
  9781. */
  9782. function arrayLikeKeys(value, inherited) {
  9783. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  9784. // Safari 9 makes `arguments.length` enumerable in strict mode.
  9785. var result = isArray(value) || isArguments(value) ? baseTimes(value.length, String) : [];
  9786. var length = result.length,
  9787. skipIndexes = !!length;
  9788. for (var key in value) {
  9789. if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  9790. result.push(key);
  9791. }
  9792. }
  9793. return result;
  9794. }
  9795. /**
  9796. * Gets the index at which the `key` is found in `array` of key-value pairs.
  9797. *
  9798. * @private
  9799. * @param {Array} array The array to inspect.
  9800. * @param {*} key The key to search for.
  9801. * @returns {number} Returns the index of the matched value, else `-1`.
  9802. */
  9803. function assocIndexOf(array, key) {
  9804. var length = array.length;
  9805. while (length--) {
  9806. if (eq(array[length][0], key)) {
  9807. return length;
  9808. }
  9809. }
  9810. return -1;
  9811. }
  9812. /**
  9813. * The base implementation of `_.get` without support for default values.
  9814. *
  9815. * @private
  9816. * @param {Object} object The object to query.
  9817. * @param {Array|string} path The path of the property to get.
  9818. * @returns {*} Returns the resolved value.
  9819. */
  9820. function baseGet(object, path$$1) {
  9821. path$$1 = isKey(path$$1, object) ? [path$$1] : castPath(path$$1);
  9822. var index = 0,
  9823. length = path$$1.length;
  9824. while (object != null && index < length) {
  9825. object = object[toKey(path$$1[index++])];
  9826. }
  9827. return index && index == length ? object : undefined;
  9828. }
  9829. /**
  9830. * The base implementation of `getTag`.
  9831. *
  9832. * @private
  9833. * @param {*} value The value to query.
  9834. * @returns {string} Returns the `toStringTag`.
  9835. */
  9836. function baseGetTag(value) {
  9837. return objectToString.call(value);
  9838. }
  9839. /**
  9840. * The base implementation of `_.hasIn` without support for deep paths.
  9841. *
  9842. * @private
  9843. * @param {Object} [object] The object to query.
  9844. * @param {Array|string} key The key to check.
  9845. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  9846. */
  9847. function baseHasIn(object, key) {
  9848. return object != null && key in Object(object);
  9849. }
  9850. /**
  9851. * The base implementation of `_.isEqual` which supports partial comparisons
  9852. * and tracks traversed objects.
  9853. *
  9854. * @private
  9855. * @param {*} value The value to compare.
  9856. * @param {*} other The other value to compare.
  9857. * @param {Function} [customizer] The function to customize comparisons.
  9858. * @param {boolean} [bitmask] The bitmask of comparison flags.
  9859. * The bitmask may be composed of the following flags:
  9860. * 1 - Unordered comparison
  9861. * 2 - Partial comparison
  9862. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  9863. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  9864. */
  9865. function baseIsEqual(value, other, customizer, bitmask, stack) {
  9866. if (value === other) {
  9867. return true;
  9868. }
  9869. if (value == null || other == null || !isObject(value) && !isObjectLike(other)) {
  9870. return value !== value && other !== other;
  9871. }
  9872. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  9873. }
  9874. /**
  9875. * A specialized version of `baseIsEqual` for arrays and objects which performs
  9876. * deep comparisons and tracks traversed objects enabling objects with circular
  9877. * references to be compared.
  9878. *
  9879. * @private
  9880. * @param {Object} object The object to compare.
  9881. * @param {Object} other The other object to compare.
  9882. * @param {Function} equalFunc The function to determine equivalents of values.
  9883. * @param {Function} [customizer] The function to customize comparisons.
  9884. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  9885. * for more details.
  9886. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  9887. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  9888. */
  9889. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  9890. var objIsArr = isArray(object),
  9891. othIsArr = isArray(other),
  9892. objTag = arrayTag,
  9893. othTag = arrayTag;
  9894. if (!objIsArr) {
  9895. objTag = getTag(object);
  9896. objTag = objTag == argsTag ? objectTag : objTag;
  9897. }
  9898. if (!othIsArr) {
  9899. othTag = getTag(other);
  9900. othTag = othTag == argsTag ? objectTag : othTag;
  9901. }
  9902. var objIsObj = objTag == objectTag && !isHostObject(object),
  9903. othIsObj = othTag == objectTag && !isHostObject(other),
  9904. isSameTag = objTag == othTag;
  9905. if (isSameTag && !objIsObj) {
  9906. stack || (stack = new Stack());
  9907. return objIsArr || isTypedArray(object) ? equalArrays(object, other, equalFunc, customizer, bitmask, stack) : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  9908. }
  9909. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  9910. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  9911. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  9912. if (objIsWrapped || othIsWrapped) {
  9913. var objUnwrapped = objIsWrapped ? object.value() : object,
  9914. othUnwrapped = othIsWrapped ? other.value() : other;
  9915. stack || (stack = new Stack());
  9916. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  9917. }
  9918. }
  9919. if (!isSameTag) {
  9920. return false;
  9921. }
  9922. stack || (stack = new Stack());
  9923. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  9924. }
  9925. /**
  9926. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  9927. *
  9928. * @private
  9929. * @param {Object} object The object to inspect.
  9930. * @param {Object} source The object of property values to match.
  9931. * @param {Array} matchData The property names, values, and compare flags to match.
  9932. * @param {Function} [customizer] The function to customize comparisons.
  9933. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  9934. */
  9935. function baseIsMatch(object, source, matchData, customizer) {
  9936. var index = matchData.length,
  9937. length = index,
  9938. noCustomizer = !customizer;
  9939. if (object == null) {
  9940. return !length;
  9941. }
  9942. object = Object(object);
  9943. while (index--) {
  9944. var data = matchData[index];
  9945. if (noCustomizer && data[2] ? data[1] !== object[data[0]] : !(data[0] in object)) {
  9946. return false;
  9947. }
  9948. }
  9949. while (++index < length) {
  9950. data = matchData[index];
  9951. var key = data[0],
  9952. objValue = object[key],
  9953. srcValue = data[1];
  9954. if (noCustomizer && data[2]) {
  9955. if (objValue === undefined && !(key in object)) {
  9956. return false;
  9957. }
  9958. } else {
  9959. var stack = new Stack();
  9960. if (customizer) {
  9961. var result = customizer(objValue, srcValue, key, object, source, stack);
  9962. }
  9963. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) : result)) {
  9964. return false;
  9965. }
  9966. }
  9967. }
  9968. return true;
  9969. }
  9970. /**
  9971. * The base implementation of `_.isNative` without bad shim checks.
  9972. *
  9973. * @private
  9974. * @param {*} value The value to check.
  9975. * @returns {boolean} Returns `true` if `value` is a native function,
  9976. * else `false`.
  9977. */
  9978. function baseIsNative(value) {
  9979. if (!isObject(value) || isMasked(value)) {
  9980. return false;
  9981. }
  9982. var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
  9983. return pattern.test(toSource(value));
  9984. }
  9985. /**
  9986. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  9987. *
  9988. * @private
  9989. * @param {*} value The value to check.
  9990. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  9991. */
  9992. function baseIsTypedArray(value) {
  9993. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  9994. }
  9995. /**
  9996. * The base implementation of `_.iteratee`.
  9997. *
  9998. * @private
  9999. * @param {*} [value=_.identity] The value to convert to an iteratee.
  10000. * @returns {Function} Returns the iteratee.
  10001. */
  10002. function baseIteratee(value) {
  10003. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  10004. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  10005. if (typeof value == 'function') {
  10006. return value;
  10007. }
  10008. if (value == null) {
  10009. return identity;
  10010. }
  10011. if (typeof value == 'object') {
  10012. return isArray(value) ? baseMatchesProperty(value[0], value[1]) : baseMatches(value);
  10013. }
  10014. return property(value);
  10015. }
  10016. /**
  10017. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  10018. *
  10019. * @private
  10020. * @param {Object} object The object to query.
  10021. * @returns {Array} Returns the array of property names.
  10022. */
  10023. function baseKeys(object) {
  10024. if (!isPrototype(object)) {
  10025. return nativeKeys(object);
  10026. }
  10027. var result = [];
  10028. for (var key in Object(object)) {
  10029. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  10030. result.push(key);
  10031. }
  10032. }
  10033. return result;
  10034. }
  10035. /**
  10036. * The base implementation of `_.matches` which doesn't clone `source`.
  10037. *
  10038. * @private
  10039. * @param {Object} source The object of property values to match.
  10040. * @returns {Function} Returns the new spec function.
  10041. */
  10042. function baseMatches(source) {
  10043. var matchData = getMatchData(source);
  10044. if (matchData.length == 1 && matchData[0][2]) {
  10045. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  10046. }
  10047. return function (object) {
  10048. return object === source || baseIsMatch(object, source, matchData);
  10049. };
  10050. }
  10051. /**
  10052. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  10053. *
  10054. * @private
  10055. * @param {string} path The path of the property to get.
  10056. * @param {*} srcValue The value to match.
  10057. * @returns {Function} Returns the new spec function.
  10058. */
  10059. function baseMatchesProperty(path$$1, srcValue) {
  10060. if (isKey(path$$1) && isStrictComparable(srcValue)) {
  10061. return matchesStrictComparable(toKey(path$$1), srcValue);
  10062. }
  10063. return function (object) {
  10064. var objValue = get(object, path$$1);
  10065. return objValue === undefined && objValue === srcValue ? hasIn(object, path$$1) : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  10066. };
  10067. }
  10068. /**
  10069. * A specialized version of `baseProperty` which supports deep paths.
  10070. *
  10071. * @private
  10072. * @param {Array|string} path The path of the property to get.
  10073. * @returns {Function} Returns the new accessor function.
  10074. */
  10075. function basePropertyDeep(path$$1) {
  10076. return function (object) {
  10077. return baseGet(object, path$$1);
  10078. };
  10079. }
  10080. /**
  10081. * The base implementation of `_.toString` which doesn't convert nullish
  10082. * values to empty strings.
  10083. *
  10084. * @private
  10085. * @param {*} value The value to process.
  10086. * @returns {string} Returns the string.
  10087. */
  10088. function baseToString(value) {
  10089. // Exit early for strings to avoid a performance hit in some environments.
  10090. if (typeof value == 'string') {
  10091. return value;
  10092. }
  10093. if (isSymbol(value)) {
  10094. return symbolToString ? symbolToString.call(value) : '';
  10095. }
  10096. var result = value + '';
  10097. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  10098. }
  10099. /**
  10100. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  10101. *
  10102. * @private
  10103. * @param {Array} array The array to inspect.
  10104. * @param {Function} [iteratee] The iteratee invoked per element.
  10105. * @param {Function} [comparator] The comparator invoked per element.
  10106. * @returns {Array} Returns the new duplicate free array.
  10107. */
  10108. function baseUniq(array, iteratee, comparator) {
  10109. var index = -1,
  10110. includes = arrayIncludes,
  10111. length = array.length,
  10112. isCommon = true,
  10113. result = [],
  10114. seen = result;
  10115. if (comparator) {
  10116. isCommon = false;
  10117. includes = arrayIncludesWith;
  10118. } else if (length >= LARGE_ARRAY_SIZE) {
  10119. var set = iteratee ? null : createSet(array);
  10120. if (set) {
  10121. return setToArray(set);
  10122. }
  10123. isCommon = false;
  10124. includes = cacheHas;
  10125. seen = new SetCache();
  10126. } else {
  10127. seen = iteratee ? [] : result;
  10128. }
  10129. outer: while (++index < length) {
  10130. var value = array[index],
  10131. computed = iteratee ? iteratee(value) : value;
  10132. value = comparator || value !== 0 ? value : 0;
  10133. if (isCommon && computed === computed) {
  10134. var seenIndex = seen.length;
  10135. while (seenIndex--) {
  10136. if (seen[seenIndex] === computed) {
  10137. continue outer;
  10138. }
  10139. }
  10140. if (iteratee) {
  10141. seen.push(computed);
  10142. }
  10143. result.push(value);
  10144. } else if (!includes(seen, computed, comparator)) {
  10145. if (seen !== result) {
  10146. seen.push(computed);
  10147. }
  10148. result.push(value);
  10149. }
  10150. }
  10151. return result;
  10152. }
  10153. /**
  10154. * Casts `value` to a path array if it's not one.
  10155. *
  10156. * @private
  10157. * @param {*} value The value to inspect.
  10158. * @returns {Array} Returns the cast property path array.
  10159. */
  10160. function castPath(value) {
  10161. return isArray(value) ? value : stringToPath(value);
  10162. }
  10163. /**
  10164. * Creates a set object of `values`.
  10165. *
  10166. * @private
  10167. * @param {Array} values The values to add to the set.
  10168. * @returns {Object} Returns the new set.
  10169. */
  10170. var createSet = !(Set && 1 / setToArray(new Set([, -0]))[1] == INFINITY) ? noop : function (values) {
  10171. return new Set(values);
  10172. };
  10173. /**
  10174. * A specialized version of `baseIsEqualDeep` for arrays with support for
  10175. * partial deep comparisons.
  10176. *
  10177. * @private
  10178. * @param {Array} array The array to compare.
  10179. * @param {Array} other The other array to compare.
  10180. * @param {Function} equalFunc The function to determine equivalents of values.
  10181. * @param {Function} customizer The function to customize comparisons.
  10182. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  10183. * for more details.
  10184. * @param {Object} stack Tracks traversed `array` and `other` objects.
  10185. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  10186. */
  10187. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  10188. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  10189. arrLength = array.length,
  10190. othLength = other.length;
  10191. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  10192. return false;
  10193. } // Assume cyclic values are equal.
  10194. var stacked = stack.get(array);
  10195. if (stacked && stack.get(other)) {
  10196. return stacked == other;
  10197. }
  10198. var index = -1,
  10199. result = true,
  10200. seen = bitmask & UNORDERED_COMPARE_FLAG ? new SetCache() : undefined;
  10201. stack.set(array, other);
  10202. stack.set(other, array); // Ignore non-index properties.
  10203. while (++index < arrLength) {
  10204. var arrValue = array[index],
  10205. othValue = other[index];
  10206. if (customizer) {
  10207. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  10208. }
  10209. if (compared !== undefined) {
  10210. if (compared) {
  10211. continue;
  10212. }
  10213. result = false;
  10214. break;
  10215. } // Recursively compare arrays (susceptible to call stack limits).
  10216. if (seen) {
  10217. if (!arraySome(other, function (othValue, othIndex) {
  10218. if (!seen.has(othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  10219. return seen.add(othIndex);
  10220. }
  10221. })) {
  10222. result = false;
  10223. break;
  10224. }
  10225. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  10226. result = false;
  10227. break;
  10228. }
  10229. }
  10230. stack['delete'](array);
  10231. stack['delete'](other);
  10232. return result;
  10233. }
  10234. /**
  10235. * A specialized version of `baseIsEqualDeep` for comparing objects of
  10236. * the same `toStringTag`.
  10237. *
  10238. * **Note:** This function only supports comparing values with tags of
  10239. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  10240. *
  10241. * @private
  10242. * @param {Object} object The object to compare.
  10243. * @param {Object} other The other object to compare.
  10244. * @param {string} tag The `toStringTag` of the objects to compare.
  10245. * @param {Function} equalFunc The function to determine equivalents of values.
  10246. * @param {Function} customizer The function to customize comparisons.
  10247. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  10248. * for more details.
  10249. * @param {Object} stack Tracks traversed `object` and `other` objects.
  10250. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  10251. */
  10252. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  10253. switch (tag) {
  10254. case dataViewTag:
  10255. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  10256. return false;
  10257. }
  10258. object = object.buffer;
  10259. other = other.buffer;
  10260. case arrayBufferTag:
  10261. if (object.byteLength != other.byteLength || !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  10262. return false;
  10263. }
  10264. return true;
  10265. case boolTag:
  10266. case dateTag:
  10267. case numberTag:
  10268. // Coerce booleans to `1` or `0` and dates to milliseconds.
  10269. // Invalid dates are coerced to `NaN`.
  10270. return eq(+object, +other);
  10271. case errorTag:
  10272. return object.name == other.name && object.message == other.message;
  10273. case regexpTag:
  10274. case stringTag:
  10275. // Coerce regexes to strings and treat strings, primitives and objects,
  10276. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  10277. // for more details.
  10278. return object == other + '';
  10279. case mapTag:
  10280. var convert = mapToArray;
  10281. case setTag:
  10282. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  10283. convert || (convert = setToArray);
  10284. if (object.size != other.size && !isPartial) {
  10285. return false;
  10286. } // Assume cyclic values are equal.
  10287. var stacked = stack.get(object);
  10288. if (stacked) {
  10289. return stacked == other;
  10290. }
  10291. bitmask |= UNORDERED_COMPARE_FLAG; // Recursively compare objects (susceptible to call stack limits).
  10292. stack.set(object, other);
  10293. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  10294. stack['delete'](object);
  10295. return result;
  10296. case symbolTag:
  10297. if (symbolValueOf) {
  10298. return symbolValueOf.call(object) == symbolValueOf.call(other);
  10299. }
  10300. }
  10301. return false;
  10302. }
  10303. /**
  10304. * A specialized version of `baseIsEqualDeep` for objects with support for
  10305. * partial deep comparisons.
  10306. *
  10307. * @private
  10308. * @param {Object} object The object to compare.
  10309. * @param {Object} other The other object to compare.
  10310. * @param {Function} equalFunc The function to determine equivalents of values.
  10311. * @param {Function} customizer The function to customize comparisons.
  10312. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  10313. * for more details.
  10314. * @param {Object} stack Tracks traversed `object` and `other` objects.
  10315. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  10316. */
  10317. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  10318. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  10319. objProps = keys(object),
  10320. objLength = objProps.length,
  10321. othProps = keys(other),
  10322. othLength = othProps.length;
  10323. if (objLength != othLength && !isPartial) {
  10324. return false;
  10325. }
  10326. var index = objLength;
  10327. while (index--) {
  10328. var key = objProps[index];
  10329. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  10330. return false;
  10331. }
  10332. } // Assume cyclic values are equal.
  10333. var stacked = stack.get(object);
  10334. if (stacked && stack.get(other)) {
  10335. return stacked == other;
  10336. }
  10337. var result = true;
  10338. stack.set(object, other);
  10339. stack.set(other, object);
  10340. var skipCtor = isPartial;
  10341. while (++index < objLength) {
  10342. key = objProps[index];
  10343. var objValue = object[key],
  10344. othValue = other[key];
  10345. if (customizer) {
  10346. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  10347. } // Recursively compare objects (susceptible to call stack limits).
  10348. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack) : compared)) {
  10349. result = false;
  10350. break;
  10351. }
  10352. skipCtor || (skipCtor = key == 'constructor');
  10353. }
  10354. if (result && !skipCtor) {
  10355. var objCtor = object.constructor,
  10356. othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal.
  10357. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  10358. result = false;
  10359. }
  10360. }
  10361. stack['delete'](object);
  10362. stack['delete'](other);
  10363. return result;
  10364. }
  10365. /**
  10366. * Gets the data for `map`.
  10367. *
  10368. * @private
  10369. * @param {Object} map The map to query.
  10370. * @param {string} key The reference key.
  10371. * @returns {*} Returns the map data.
  10372. */
  10373. function getMapData(map, key) {
  10374. var data = map.__data__;
  10375. return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  10376. }
  10377. /**
  10378. * Gets the property names, values, and compare flags of `object`.
  10379. *
  10380. * @private
  10381. * @param {Object} object The object to query.
  10382. * @returns {Array} Returns the match data of `object`.
  10383. */
  10384. function getMatchData(object) {
  10385. var result = keys(object),
  10386. length = result.length;
  10387. while (length--) {
  10388. var key = result[length],
  10389. value = object[key];
  10390. result[length] = [key, value, isStrictComparable(value)];
  10391. }
  10392. return result;
  10393. }
  10394. /**
  10395. * Gets the native function at `key` of `object`.
  10396. *
  10397. * @private
  10398. * @param {Object} object The object to query.
  10399. * @param {string} key The key of the method to get.
  10400. * @returns {*} Returns the function if it's native, else `undefined`.
  10401. */
  10402. function getNative(object, key) {
  10403. var value = getValue(object, key);
  10404. return baseIsNative(value) ? value : undefined;
  10405. }
  10406. /**
  10407. * Gets the `toStringTag` of `value`.
  10408. *
  10409. * @private
  10410. * @param {*} value The value to query.
  10411. * @returns {string} Returns the `toStringTag`.
  10412. */
  10413. var getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11,
  10414. // for data views in Edge < 14, and promises in Node.js.
  10415. if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map && getTag(new Map()) != mapTag || Promise && getTag(Promise.resolve()) != promiseTag || Set && getTag(new Set()) != setTag || WeakMap && getTag(new WeakMap()) != weakMapTag) {
  10416. getTag = function getTag(value) {
  10417. var result = objectToString.call(value),
  10418. Ctor = result == objectTag ? value.constructor : undefined,
  10419. ctorString = Ctor ? toSource(Ctor) : undefined;
  10420. if (ctorString) {
  10421. switch (ctorString) {
  10422. case dataViewCtorString:
  10423. return dataViewTag;
  10424. case mapCtorString:
  10425. return mapTag;
  10426. case promiseCtorString:
  10427. return promiseTag;
  10428. case setCtorString:
  10429. return setTag;
  10430. case weakMapCtorString:
  10431. return weakMapTag;
  10432. }
  10433. }
  10434. return result;
  10435. };
  10436. }
  10437. /**
  10438. * Checks if `path` exists on `object`.
  10439. *
  10440. * @private
  10441. * @param {Object} object The object to query.
  10442. * @param {Array|string} path The path to check.
  10443. * @param {Function} hasFunc The function to check properties.
  10444. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  10445. */
  10446. function hasPath(object, path$$1, hasFunc) {
  10447. path$$1 = isKey(path$$1, object) ? [path$$1] : castPath(path$$1);
  10448. var result,
  10449. index = -1,
  10450. length = path$$1.length;
  10451. while (++index < length) {
  10452. var key = toKey(path$$1[index]);
  10453. if (!(result = object != null && hasFunc(object, key))) {
  10454. break;
  10455. }
  10456. object = object[key];
  10457. }
  10458. if (result) {
  10459. return result;
  10460. }
  10461. var length = object ? object.length : 0;
  10462. return !!length && isLength(length) && isIndex(key, length) && (isArray(object) || isArguments(object));
  10463. }
  10464. /**
  10465. * Checks if `value` is a valid array-like index.
  10466. *
  10467. * @private
  10468. * @param {*} value The value to check.
  10469. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  10470. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  10471. */
  10472. function isIndex(value, length) {
  10473. length = length == null ? MAX_SAFE_INTEGER : length;
  10474. return !!length && (typeof value == 'number' || reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  10475. }
  10476. /**
  10477. * Checks if `value` is a property name and not a property path.
  10478. *
  10479. * @private
  10480. * @param {*} value The value to check.
  10481. * @param {Object} [object] The object to query keys on.
  10482. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  10483. */
  10484. function isKey(value, object) {
  10485. if (isArray(value)) {
  10486. return false;
  10487. }
  10488. var type = typeof value;
  10489. if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol(value)) {
  10490. return true;
  10491. }
  10492. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
  10493. }
  10494. /**
  10495. * Checks if `value` is suitable for use as unique object key.
  10496. *
  10497. * @private
  10498. * @param {*} value The value to check.
  10499. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  10500. */
  10501. function isKeyable(value) {
  10502. var type = typeof value;
  10503. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  10504. }
  10505. /**
  10506. * Checks if `func` has its source masked.
  10507. *
  10508. * @private
  10509. * @param {Function} func The function to check.
  10510. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  10511. */
  10512. function isMasked(func) {
  10513. return !!maskSrcKey && maskSrcKey in func;
  10514. }
  10515. /**
  10516. * Checks if `value` is likely a prototype object.
  10517. *
  10518. * @private
  10519. * @param {*} value The value to check.
  10520. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  10521. */
  10522. function isPrototype(value) {
  10523. var Ctor = value && value.constructor,
  10524. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto;
  10525. return value === proto;
  10526. }
  10527. /**
  10528. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  10529. *
  10530. * @private
  10531. * @param {*} value The value to check.
  10532. * @returns {boolean} Returns `true` if `value` if suitable for strict
  10533. * equality comparisons, else `false`.
  10534. */
  10535. function isStrictComparable(value) {
  10536. return value === value && !isObject(value);
  10537. }
  10538. /**
  10539. * A specialized version of `matchesProperty` for source values suitable
  10540. * for strict equality comparisons, i.e. `===`.
  10541. *
  10542. * @private
  10543. * @param {string} key The key of the property to get.
  10544. * @param {*} srcValue The value to match.
  10545. * @returns {Function} Returns the new spec function.
  10546. */
  10547. function matchesStrictComparable(key, srcValue) {
  10548. return function (object) {
  10549. if (object == null) {
  10550. return false;
  10551. }
  10552. return object[key] === srcValue && (srcValue !== undefined || key in Object(object));
  10553. };
  10554. }
  10555. /**
  10556. * Converts `string` to a property path array.
  10557. *
  10558. * @private
  10559. * @param {string} string The string to convert.
  10560. * @returns {Array} Returns the property path array.
  10561. */
  10562. var stringToPath = memoize(function (string) {
  10563. string = toString(string);
  10564. var result = [];
  10565. if (reLeadingDot.test(string)) {
  10566. result.push('');
  10567. }
  10568. string.replace(rePropName, function (match, number, quote, string) {
  10569. result.push(quote ? string.replace(reEscapeChar, '$1') : number || match);
  10570. });
  10571. return result;
  10572. });
  10573. /**
  10574. * Converts `value` to a string key if it's not a string or symbol.
  10575. *
  10576. * @private
  10577. * @param {*} value The value to inspect.
  10578. * @returns {string|symbol} Returns the key.
  10579. */
  10580. function toKey(value) {
  10581. if (typeof value == 'string' || isSymbol(value)) {
  10582. return value;
  10583. }
  10584. var result = value + '';
  10585. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  10586. }
  10587. /**
  10588. * Converts `func` to its source code.
  10589. *
  10590. * @private
  10591. * @param {Function} func The function to process.
  10592. * @returns {string} Returns the source code.
  10593. */
  10594. function toSource(func) {
  10595. if (func != null) {
  10596. try {
  10597. return funcToString.call(func);
  10598. } catch (e) {}
  10599. try {
  10600. return func + '';
  10601. } catch (e) {}
  10602. }
  10603. return '';
  10604. }
  10605. /**
  10606. * This method is like `_.uniq` except that it accepts `iteratee` which is
  10607. * invoked for each element in `array` to generate the criterion by which
  10608. * uniqueness is computed. The iteratee is invoked with one argument: (value).
  10609. *
  10610. * @static
  10611. * @memberOf _
  10612. * @since 4.0.0
  10613. * @category Array
  10614. * @param {Array} array The array to inspect.
  10615. * @param {Function} [iteratee=_.identity]
  10616. * The iteratee invoked per element.
  10617. * @returns {Array} Returns the new duplicate free array.
  10618. * @example
  10619. *
  10620. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  10621. * // => [2.1, 1.2]
  10622. *
  10623. * // The `_.property` iteratee shorthand.
  10624. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  10625. * // => [{ 'x': 1 }, { 'x': 2 }]
  10626. */
  10627. function uniqBy(array, iteratee) {
  10628. return array && array.length ? baseUniq(array, baseIteratee(iteratee, 2)) : [];
  10629. }
  10630. /**
  10631. * Creates a function that memoizes the result of `func`. If `resolver` is
  10632. * provided, it determines the cache key for storing the result based on the
  10633. * arguments provided to the memoized function. By default, the first argument
  10634. * provided to the memoized function is used as the map cache key. The `func`
  10635. * is invoked with the `this` binding of the memoized function.
  10636. *
  10637. * **Note:** The cache is exposed as the `cache` property on the memoized
  10638. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  10639. * constructor with one whose instances implement the
  10640. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  10641. * method interface of `delete`, `get`, `has`, and `set`.
  10642. *
  10643. * @static
  10644. * @memberOf _
  10645. * @since 0.1.0
  10646. * @category Function
  10647. * @param {Function} func The function to have its output memoized.
  10648. * @param {Function} [resolver] The function to resolve the cache key.
  10649. * @returns {Function} Returns the new memoized function.
  10650. * @example
  10651. *
  10652. * var object = { 'a': 1, 'b': 2 };
  10653. * var other = { 'c': 3, 'd': 4 };
  10654. *
  10655. * var values = _.memoize(_.values);
  10656. * values(object);
  10657. * // => [1, 2]
  10658. *
  10659. * values(other);
  10660. * // => [3, 4]
  10661. *
  10662. * object.a = 2;
  10663. * values(object);
  10664. * // => [1, 2]
  10665. *
  10666. * // Modify the result cache.
  10667. * values.cache.set(object, ['a', 'b']);
  10668. * values(object);
  10669. * // => ['a', 'b']
  10670. *
  10671. * // Replace `_.memoize.Cache`.
  10672. * _.memoize.Cache = WeakMap;
  10673. */
  10674. function memoize(func, resolver) {
  10675. if (typeof func != 'function' || resolver && typeof resolver != 'function') {
  10676. throw new TypeError(FUNC_ERROR_TEXT);
  10677. }
  10678. var memoized = function memoized() {
  10679. var args = arguments,
  10680. key = resolver ? resolver.apply(this, args) : args[0],
  10681. cache = memoized.cache;
  10682. if (cache.has(key)) {
  10683. return cache.get(key);
  10684. }
  10685. var result = func.apply(this, args);
  10686. memoized.cache = cache.set(key, result);
  10687. return result;
  10688. };
  10689. memoized.cache = new (memoize.Cache || MapCache)();
  10690. return memoized;
  10691. } // Assign cache to `_.memoize`.
  10692. memoize.Cache = MapCache;
  10693. /**
  10694. * Performs a
  10695. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10696. * comparison between two values to determine if they are equivalent.
  10697. *
  10698. * @static
  10699. * @memberOf _
  10700. * @since 4.0.0
  10701. * @category Lang
  10702. * @param {*} value The value to compare.
  10703. * @param {*} other The other value to compare.
  10704. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10705. * @example
  10706. *
  10707. * var object = { 'a': 1 };
  10708. * var other = { 'a': 1 };
  10709. *
  10710. * _.eq(object, object);
  10711. * // => true
  10712. *
  10713. * _.eq(object, other);
  10714. * // => false
  10715. *
  10716. * _.eq('a', 'a');
  10717. * // => true
  10718. *
  10719. * _.eq('a', Object('a'));
  10720. * // => false
  10721. *
  10722. * _.eq(NaN, NaN);
  10723. * // => true
  10724. */
  10725. function eq(value, other) {
  10726. return value === other || value !== value && other !== other;
  10727. }
  10728. /**
  10729. * Checks if `value` is likely an `arguments` object.
  10730. *
  10731. * @static
  10732. * @memberOf _
  10733. * @since 0.1.0
  10734. * @category Lang
  10735. * @param {*} value The value to check.
  10736. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10737. * else `false`.
  10738. * @example
  10739. *
  10740. * _.isArguments(function() { return arguments; }());
  10741. * // => true
  10742. *
  10743. * _.isArguments([1, 2, 3]);
  10744. * // => false
  10745. */
  10746. function isArguments(value) {
  10747. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  10748. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  10749. }
  10750. /**
  10751. * Checks if `value` is classified as an `Array` object.
  10752. *
  10753. * @static
  10754. * @memberOf _
  10755. * @since 0.1.0
  10756. * @category Lang
  10757. * @param {*} value The value to check.
  10758. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10759. * @example
  10760. *
  10761. * _.isArray([1, 2, 3]);
  10762. * // => true
  10763. *
  10764. * _.isArray(document.body.children);
  10765. * // => false
  10766. *
  10767. * _.isArray('abc');
  10768. * // => false
  10769. *
  10770. * _.isArray(_.noop);
  10771. * // => false
  10772. */
  10773. var isArray = Array.isArray;
  10774. /**
  10775. * Checks if `value` is array-like. A value is considered array-like if it's
  10776. * not a function and has a `value.length` that's an integer greater than or
  10777. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10778. *
  10779. * @static
  10780. * @memberOf _
  10781. * @since 4.0.0
  10782. * @category Lang
  10783. * @param {*} value The value to check.
  10784. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10785. * @example
  10786. *
  10787. * _.isArrayLike([1, 2, 3]);
  10788. * // => true
  10789. *
  10790. * _.isArrayLike(document.body.children);
  10791. * // => true
  10792. *
  10793. * _.isArrayLike('abc');
  10794. * // => true
  10795. *
  10796. * _.isArrayLike(_.noop);
  10797. * // => false
  10798. */
  10799. function isArrayLike(value) {
  10800. return value != null && isLength(value.length) && !isFunction(value);
  10801. }
  10802. /**
  10803. * This method is like `_.isArrayLike` except that it also checks if `value`
  10804. * is an object.
  10805. *
  10806. * @static
  10807. * @memberOf _
  10808. * @since 4.0.0
  10809. * @category Lang
  10810. * @param {*} value The value to check.
  10811. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10812. * else `false`.
  10813. * @example
  10814. *
  10815. * _.isArrayLikeObject([1, 2, 3]);
  10816. * // => true
  10817. *
  10818. * _.isArrayLikeObject(document.body.children);
  10819. * // => true
  10820. *
  10821. * _.isArrayLikeObject('abc');
  10822. * // => false
  10823. *
  10824. * _.isArrayLikeObject(_.noop);
  10825. * // => false
  10826. */
  10827. function isArrayLikeObject(value) {
  10828. return isObjectLike(value) && isArrayLike(value);
  10829. }
  10830. /**
  10831. * Checks if `value` is classified as a `Function` object.
  10832. *
  10833. * @static
  10834. * @memberOf _
  10835. * @since 0.1.0
  10836. * @category Lang
  10837. * @param {*} value The value to check.
  10838. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10839. * @example
  10840. *
  10841. * _.isFunction(_);
  10842. * // => true
  10843. *
  10844. * _.isFunction(/abc/);
  10845. * // => false
  10846. */
  10847. function isFunction(value) {
  10848. // The use of `Object#toString` avoids issues with the `typeof` operator
  10849. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  10850. var tag = isObject(value) ? objectToString.call(value) : '';
  10851. return tag == funcTag || tag == genTag;
  10852. }
  10853. /**
  10854. * Checks if `value` is a valid array-like length.
  10855. *
  10856. * **Note:** This method is loosely based on
  10857. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10858. *
  10859. * @static
  10860. * @memberOf _
  10861. * @since 4.0.0
  10862. * @category Lang
  10863. * @param {*} value The value to check.
  10864. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10865. * @example
  10866. *
  10867. * _.isLength(3);
  10868. * // => true
  10869. *
  10870. * _.isLength(Number.MIN_VALUE);
  10871. * // => false
  10872. *
  10873. * _.isLength(Infinity);
  10874. * // => false
  10875. *
  10876. * _.isLength('3');
  10877. * // => false
  10878. */
  10879. function isLength(value) {
  10880. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10881. }
  10882. /**
  10883. * Checks if `value` is the
  10884. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10885. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10886. *
  10887. * @static
  10888. * @memberOf _
  10889. * @since 0.1.0
  10890. * @category Lang
  10891. * @param {*} value The value to check.
  10892. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10893. * @example
  10894. *
  10895. * _.isObject({});
  10896. * // => true
  10897. *
  10898. * _.isObject([1, 2, 3]);
  10899. * // => true
  10900. *
  10901. * _.isObject(_.noop);
  10902. * // => true
  10903. *
  10904. * _.isObject(null);
  10905. * // => false
  10906. */
  10907. function isObject(value) {
  10908. var type = typeof value;
  10909. return !!value && (type == 'object' || type == 'function');
  10910. }
  10911. /**
  10912. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10913. * and has a `typeof` result of "object".
  10914. *
  10915. * @static
  10916. * @memberOf _
  10917. * @since 4.0.0
  10918. * @category Lang
  10919. * @param {*} value The value to check.
  10920. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10921. * @example
  10922. *
  10923. * _.isObjectLike({});
  10924. * // => true
  10925. *
  10926. * _.isObjectLike([1, 2, 3]);
  10927. * // => true
  10928. *
  10929. * _.isObjectLike(_.noop);
  10930. * // => false
  10931. *
  10932. * _.isObjectLike(null);
  10933. * // => false
  10934. */
  10935. function isObjectLike(value) {
  10936. return !!value && typeof value == 'object';
  10937. }
  10938. /**
  10939. * Checks if `value` is classified as a `Symbol` primitive or object.
  10940. *
  10941. * @static
  10942. * @memberOf _
  10943. * @since 4.0.0
  10944. * @category Lang
  10945. * @param {*} value The value to check.
  10946. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  10947. * @example
  10948. *
  10949. * _.isSymbol(Symbol.iterator);
  10950. * // => true
  10951. *
  10952. * _.isSymbol('abc');
  10953. * // => false
  10954. */
  10955. function isSymbol(value) {
  10956. return typeof value == 'symbol' || isObjectLike(value) && objectToString.call(value) == symbolTag;
  10957. }
  10958. /**
  10959. * Checks if `value` is classified as a typed array.
  10960. *
  10961. * @static
  10962. * @memberOf _
  10963. * @since 3.0.0
  10964. * @category Lang
  10965. * @param {*} value The value to check.
  10966. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  10967. * @example
  10968. *
  10969. * _.isTypedArray(new Uint8Array);
  10970. * // => true
  10971. *
  10972. * _.isTypedArray([]);
  10973. * // => false
  10974. */
  10975. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  10976. /**
  10977. * Converts `value` to a string. An empty string is returned for `null`
  10978. * and `undefined` values. The sign of `-0` is preserved.
  10979. *
  10980. * @static
  10981. * @memberOf _
  10982. * @since 4.0.0
  10983. * @category Lang
  10984. * @param {*} value The value to process.
  10985. * @returns {string} Returns the string.
  10986. * @example
  10987. *
  10988. * _.toString(null);
  10989. * // => ''
  10990. *
  10991. * _.toString(-0);
  10992. * // => '-0'
  10993. *
  10994. * _.toString([1, 2, 3]);
  10995. * // => '1,2,3'
  10996. */
  10997. function toString(value) {
  10998. return value == null ? '' : baseToString(value);
  10999. }
  11000. /**
  11001. * Gets the value at `path` of `object`. If the resolved value is
  11002. * `undefined`, the `defaultValue` is returned in its place.
  11003. *
  11004. * @static
  11005. * @memberOf _
  11006. * @since 3.7.0
  11007. * @category Object
  11008. * @param {Object} object The object to query.
  11009. * @param {Array|string} path The path of the property to get.
  11010. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  11011. * @returns {*} Returns the resolved value.
  11012. * @example
  11013. *
  11014. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  11015. *
  11016. * _.get(object, 'a[0].b.c');
  11017. * // => 3
  11018. *
  11019. * _.get(object, ['a', '0', 'b', 'c']);
  11020. * // => 3
  11021. *
  11022. * _.get(object, 'a.b.c', 'default');
  11023. * // => 'default'
  11024. */
  11025. function get(object, path$$1, defaultValue) {
  11026. var result = object == null ? undefined : baseGet(object, path$$1);
  11027. return result === undefined ? defaultValue : result;
  11028. }
  11029. /**
  11030. * Checks if `path` is a direct or inherited property of `object`.
  11031. *
  11032. * @static
  11033. * @memberOf _
  11034. * @since 4.0.0
  11035. * @category Object
  11036. * @param {Object} object The object to query.
  11037. * @param {Array|string} path The path to check.
  11038. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  11039. * @example
  11040. *
  11041. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  11042. *
  11043. * _.hasIn(object, 'a');
  11044. * // => true
  11045. *
  11046. * _.hasIn(object, 'a.b');
  11047. * // => true
  11048. *
  11049. * _.hasIn(object, ['a', 'b']);
  11050. * // => true
  11051. *
  11052. * _.hasIn(object, 'b');
  11053. * // => false
  11054. */
  11055. function hasIn(object, path$$1) {
  11056. return object != null && hasPath(object, path$$1, baseHasIn);
  11057. }
  11058. /**
  11059. * Creates an array of the own enumerable property names of `object`.
  11060. *
  11061. * **Note:** Non-object values are coerced to objects. See the
  11062. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  11063. * for more details.
  11064. *
  11065. * @static
  11066. * @since 0.1.0
  11067. * @memberOf _
  11068. * @category Object
  11069. * @param {Object} object The object to query.
  11070. * @returns {Array} Returns the array of property names.
  11071. * @example
  11072. *
  11073. * function Foo() {
  11074. * this.a = 1;
  11075. * this.b = 2;
  11076. * }
  11077. *
  11078. * Foo.prototype.c = 3;
  11079. *
  11080. * _.keys(new Foo);
  11081. * // => ['a', 'b'] (iteration order is not guaranteed)
  11082. *
  11083. * _.keys('hi');
  11084. * // => ['0', '1']
  11085. */
  11086. function keys(object) {
  11087. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  11088. }
  11089. /**
  11090. * This method returns the first argument it receives.
  11091. *
  11092. * @static
  11093. * @since 0.1.0
  11094. * @memberOf _
  11095. * @category Util
  11096. * @param {*} value Any value.
  11097. * @returns {*} Returns `value`.
  11098. * @example
  11099. *
  11100. * var object = { 'a': 1 };
  11101. *
  11102. * console.log(_.identity(object) === object);
  11103. * // => true
  11104. */
  11105. function identity(value) {
  11106. return value;
  11107. }
  11108. /**
  11109. * This method returns `undefined`.
  11110. *
  11111. * @static
  11112. * @memberOf _
  11113. * @since 2.3.0
  11114. * @category Util
  11115. * @example
  11116. *
  11117. * _.times(2, _.noop);
  11118. * // => [undefined, undefined]
  11119. */
  11120. function noop() {} // No operation performed.
  11121. /**
  11122. * Creates a function that returns the value at `path` of a given object.
  11123. *
  11124. * @static
  11125. * @memberOf _
  11126. * @since 2.4.0
  11127. * @category Util
  11128. * @param {Array|string} path The path of the property to get.
  11129. * @returns {Function} Returns the new accessor function.
  11130. * @example
  11131. *
  11132. * var objects = [
  11133. * { 'a': { 'b': 2 } },
  11134. * { 'a': { 'b': 1 } }
  11135. * ];
  11136. *
  11137. * _.map(objects, _.property('a.b'));
  11138. * // => [2, 1]
  11139. *
  11140. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  11141. * // => [1, 2]
  11142. */
  11143. function property(path$$1) {
  11144. return isKey(path$$1) ? baseProperty(toKey(path$$1)) : basePropertyDeep(path$$1);
  11145. }
  11146. module.exports = uniqBy;
  11147. });
  11148. var PENDING = 'pending';
  11149. var SETTLED = 'settled';
  11150. var FULFILLED = 'fulfilled';
  11151. var REJECTED = 'rejected';
  11152. var NOOP = function NOOP() {};
  11153. var isNode = typeof commonjsGlobal !== 'undefined' && typeof commonjsGlobal.process !== 'undefined' && typeof commonjsGlobal.process.emit === 'function';
  11154. var asyncSetTimer = typeof setImmediate === 'undefined' ? setTimeout : setImmediate;
  11155. var asyncQueue = [];
  11156. var asyncTimer;
  11157. function asyncFlush() {
  11158. // run promise callbacks
  11159. for (var i = 0; i < asyncQueue.length; i++) {
  11160. asyncQueue[i][0](asyncQueue[i][1]);
  11161. } // reset async asyncQueue
  11162. asyncQueue = [];
  11163. asyncTimer = false;
  11164. }
  11165. function asyncCall(callback, arg) {
  11166. asyncQueue.push([callback, arg]);
  11167. if (!asyncTimer) {
  11168. asyncTimer = true;
  11169. asyncSetTimer(asyncFlush, 0);
  11170. }
  11171. }
  11172. function invokeResolver(resolver, promise) {
  11173. function resolvePromise(value) {
  11174. resolve(promise, value);
  11175. }
  11176. function rejectPromise(reason) {
  11177. reject(promise, reason);
  11178. }
  11179. try {
  11180. resolver(resolvePromise, rejectPromise);
  11181. } catch (e) {
  11182. rejectPromise(e);
  11183. }
  11184. }
  11185. function invokeCallback(subscriber) {
  11186. var owner = subscriber.owner;
  11187. var settled = owner._state;
  11188. var value = owner._data;
  11189. var callback = subscriber[settled];
  11190. var promise = subscriber.then;
  11191. if (typeof callback === 'function') {
  11192. settled = FULFILLED;
  11193. try {
  11194. value = callback(value);
  11195. } catch (e) {
  11196. reject(promise, e);
  11197. }
  11198. }
  11199. if (!handleThenable(promise, value)) {
  11200. if (settled === FULFILLED) {
  11201. resolve(promise, value);
  11202. }
  11203. if (settled === REJECTED) {
  11204. reject(promise, value);
  11205. }
  11206. }
  11207. }
  11208. function handleThenable(promise, value) {
  11209. var resolved;
  11210. try {
  11211. if (promise === value) {
  11212. throw new TypeError('A promises callback cannot return that same promise.');
  11213. }
  11214. if (value && (typeof value === 'function' || typeof value === 'object')) {
  11215. // then should be retrieved only once
  11216. var then = value.then;
  11217. if (typeof then === 'function') {
  11218. then.call(value, function (val) {
  11219. if (!resolved) {
  11220. resolved = true;
  11221. if (value === val) {
  11222. fulfill(promise, val);
  11223. } else {
  11224. resolve(promise, val);
  11225. }
  11226. }
  11227. }, function (reason) {
  11228. if (!resolved) {
  11229. resolved = true;
  11230. reject(promise, reason);
  11231. }
  11232. });
  11233. return true;
  11234. }
  11235. }
  11236. } catch (e) {
  11237. if (!resolved) {
  11238. reject(promise, e);
  11239. }
  11240. return true;
  11241. }
  11242. return false;
  11243. }
  11244. function resolve(promise, value) {
  11245. if (promise === value || !handleThenable(promise, value)) {
  11246. fulfill(promise, value);
  11247. }
  11248. }
  11249. function fulfill(promise, value) {
  11250. if (promise._state === PENDING) {
  11251. promise._state = SETTLED;
  11252. promise._data = value;
  11253. asyncCall(publishFulfillment, promise);
  11254. }
  11255. }
  11256. function reject(promise, reason) {
  11257. if (promise._state === PENDING) {
  11258. promise._state = SETTLED;
  11259. promise._data = reason;
  11260. asyncCall(publishRejection, promise);
  11261. }
  11262. }
  11263. function publish(promise) {
  11264. promise._then = promise._then.forEach(invokeCallback);
  11265. }
  11266. function publishFulfillment(promise) {
  11267. promise._state = FULFILLED;
  11268. publish(promise);
  11269. }
  11270. function publishRejection(promise) {
  11271. promise._state = REJECTED;
  11272. publish(promise);
  11273. if (!promise._handled && isNode) {
  11274. commonjsGlobal.process.emit('unhandledRejection', promise._data, promise);
  11275. }
  11276. }
  11277. function notifyRejectionHandled(promise) {
  11278. commonjsGlobal.process.emit('rejectionHandled', promise);
  11279. }
  11280. /**
  11281. * @class
  11282. */
  11283. function Promise$1(resolver) {
  11284. if (typeof resolver !== 'function') {
  11285. throw new TypeError('Promise resolver ' + resolver + ' is not a function');
  11286. }
  11287. if (this instanceof Promise$1 === false) {
  11288. throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object constructor cannot be called as a function.');
  11289. }
  11290. this._then = [];
  11291. invokeResolver(resolver, this);
  11292. }
  11293. Promise$1.prototype = {
  11294. constructor: Promise$1,
  11295. _state: PENDING,
  11296. _then: null,
  11297. _data: undefined,
  11298. _handled: false,
  11299. then: function then(onFulfillment, onRejection) {
  11300. var subscriber = {
  11301. owner: this,
  11302. then: new this.constructor(NOOP),
  11303. fulfilled: onFulfillment,
  11304. rejected: onRejection
  11305. };
  11306. if ((onRejection || onFulfillment) && !this._handled) {
  11307. this._handled = true;
  11308. if (this._state === REJECTED && isNode) {
  11309. asyncCall(notifyRejectionHandled, this);
  11310. }
  11311. }
  11312. if (this._state === FULFILLED || this._state === REJECTED) {
  11313. // already resolved, call callback async
  11314. asyncCall(invokeCallback, subscriber);
  11315. } else {
  11316. // subscribe
  11317. this._then.push(subscriber);
  11318. }
  11319. return subscriber.then;
  11320. },
  11321. catch: function _catch(onRejection) {
  11322. return this.then(null, onRejection);
  11323. }
  11324. };
  11325. Promise$1.all = function (promises) {
  11326. if (!Array.isArray(promises)) {
  11327. throw new TypeError('You must pass an array to Promise.all().');
  11328. }
  11329. return new Promise$1(function (resolve, reject) {
  11330. var results = [];
  11331. var remaining = 0;
  11332. function resolver(index) {
  11333. remaining++;
  11334. return function (value) {
  11335. results[index] = value;
  11336. if (! --remaining) {
  11337. resolve(results);
  11338. }
  11339. };
  11340. }
  11341. for (var i = 0, promise; i < promises.length; i++) {
  11342. promise = promises[i];
  11343. if (promise && typeof promise.then === 'function') {
  11344. promise.then(resolver(i), reject);
  11345. } else {
  11346. results[i] = promise;
  11347. }
  11348. }
  11349. if (!remaining) {
  11350. resolve(results);
  11351. }
  11352. });
  11353. };
  11354. Promise$1.race = function (promises) {
  11355. if (!Array.isArray(promises)) {
  11356. throw new TypeError('You must pass an array to Promise.race().');
  11357. }
  11358. return new Promise$1(function (resolve, reject) {
  11359. for (var i = 0, promise; i < promises.length; i++) {
  11360. promise = promises[i];
  11361. if (promise && typeof promise.then === 'function') {
  11362. promise.then(resolve, reject);
  11363. } else {
  11364. resolve(promise);
  11365. }
  11366. }
  11367. });
  11368. };
  11369. Promise$1.resolve = function (value) {
  11370. if (value && typeof value === 'object' && value.constructor === Promise$1) {
  11371. return value;
  11372. }
  11373. return new Promise$1(function (resolve) {
  11374. resolve(value);
  11375. });
  11376. };
  11377. Promise$1.reject = function (reason) {
  11378. return new Promise$1(function (resolve, reject) {
  11379. reject(reason);
  11380. });
  11381. };
  11382. var pinkie = Promise$1;
  11383. var pinkiePromise = typeof Promise === 'function' ? Promise : pinkie;
  11384. var arrayUniq = createCommonjsModule(function (module) {
  11385. 'use strict'; // there's 3 implementations written in increasing order of efficiency
  11386. // 1 - no Set type is defined
  11387. function uniqNoSet(arr) {
  11388. var ret = [];
  11389. for (var i = 0; i < arr.length; i++) {
  11390. if (ret.indexOf(arr[i]) === -1) {
  11391. ret.push(arr[i]);
  11392. }
  11393. }
  11394. return ret;
  11395. } // 2 - a simple Set type is defined
  11396. function uniqSet(arr) {
  11397. var seen = new Set();
  11398. return arr.filter(function (el) {
  11399. if (!seen.has(el)) {
  11400. seen.add(el);
  11401. return true;
  11402. }
  11403. return false;
  11404. });
  11405. } // 3 - a standard Set type is defined and it has a forEach method
  11406. function uniqSetWithForEach(arr) {
  11407. var ret = [];
  11408. new Set(arr).forEach(function (el) {
  11409. ret.push(el);
  11410. });
  11411. return ret;
  11412. } // V8 currently has a broken implementation
  11413. // https://github.com/joyent/node/issues/8449
  11414. function doesForEachActuallyWork() {
  11415. var ret = false;
  11416. new Set([true]).forEach(function (el) {
  11417. ret = el;
  11418. });
  11419. return ret === true;
  11420. }
  11421. if ('Set' in commonjsGlobal) {
  11422. if (typeof Set.prototype.forEach === 'function' && doesForEachActuallyWork()) {
  11423. module.exports = uniqSetWithForEach;
  11424. } else {
  11425. module.exports = uniqSet;
  11426. }
  11427. } else {
  11428. module.exports = uniqNoSet;
  11429. }
  11430. });
  11431. var arrayUnion = function arrayUnion() {
  11432. return arrayUniq([].concat.apply([], arguments));
  11433. };
  11434. /*
  11435. object-assign
  11436. (c) Sindre Sorhus
  11437. @license MIT
  11438. */
  11439. /* eslint-disable no-unused-vars */
  11440. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  11441. var hasOwnProperty = Object.prototype.hasOwnProperty;
  11442. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  11443. function toObject(val) {
  11444. if (val === null || val === undefined) {
  11445. throw new TypeError('Object.assign cannot be called with null or undefined');
  11446. }
  11447. return Object(val);
  11448. }
  11449. function shouldUseNative() {
  11450. try {
  11451. if (!Object.assign) {
  11452. return false;
  11453. } // Detect buggy property enumeration order in older V8 versions.
  11454. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  11455. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  11456. test1[5] = 'de';
  11457. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  11458. return false;
  11459. } // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  11460. var test2 = {};
  11461. for (var i = 0; i < 10; i++) {
  11462. test2['_' + String.fromCharCode(i)] = i;
  11463. }
  11464. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  11465. return test2[n];
  11466. });
  11467. if (order2.join('') !== '0123456789') {
  11468. return false;
  11469. } // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  11470. var test3 = {};
  11471. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  11472. test3[letter] = letter;
  11473. });
  11474. if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') {
  11475. return false;
  11476. }
  11477. return true;
  11478. } catch (err) {
  11479. // We don't expect any of the above to throw, but better to be safe.
  11480. return false;
  11481. }
  11482. }
  11483. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  11484. var from;
  11485. var to = toObject(target);
  11486. var symbols;
  11487. for (var s = 1; s < arguments.length; s++) {
  11488. from = Object(arguments[s]);
  11489. for (var key in from) {
  11490. if (hasOwnProperty.call(from, key)) {
  11491. to[key] = from[key];
  11492. }
  11493. }
  11494. if (getOwnPropertySymbols) {
  11495. symbols = getOwnPropertySymbols(from);
  11496. for (var i = 0; i < symbols.length; i++) {
  11497. if (propIsEnumerable.call(from, symbols[i])) {
  11498. to[symbols[i]] = from[symbols[i]];
  11499. }
  11500. }
  11501. }
  11502. }
  11503. return to;
  11504. };
  11505. //
  11506. // Permission is hereby granted, free of charge, to any person obtaining a
  11507. // copy of this software and associated documentation files (the
  11508. // "Software"), to deal in the Software without restriction, including
  11509. // without limitation the rights to use, copy, modify, merge, publish,
  11510. // distribute, sublicense, and/or sell copies of the Software, and to permit
  11511. // persons to whom the Software is furnished to do so, subject to the
  11512. // following conditions:
  11513. //
  11514. // The above copyright notice and this permission notice shall be included
  11515. // in all copies or substantial portions of the Software.
  11516. //
  11517. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11518. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11519. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  11520. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  11521. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  11522. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  11523. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  11524. var isWindows = process.platform === 'win32'; // JavaScript implementation of realpath, ported from node pre-v6
  11525. var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
  11526. function rethrow() {
  11527. // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
  11528. // is fairly slow to generate.
  11529. var callback;
  11530. if (DEBUG) {
  11531. var backtrace = new Error();
  11532. callback = debugCallback;
  11533. } else callback = missingCallback;
  11534. return callback;
  11535. function debugCallback(err) {
  11536. if (err) {
  11537. backtrace.message = err.message;
  11538. err = backtrace;
  11539. missingCallback(err);
  11540. }
  11541. }
  11542. function missingCallback(err) {
  11543. if (err) {
  11544. if (process.throwDeprecation) throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
  11545. else if (!process.noDeprecation) {
  11546. var msg = 'fs: missing callback ' + (err.stack || err.message);
  11547. if (process.traceDeprecation) console.trace(msg);else console.error(msg);
  11548. }
  11549. }
  11550. }
  11551. }
  11552. function maybeCallback(cb) {
  11553. return typeof cb === 'function' ? cb : rethrow();
  11554. }
  11555. // result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
  11556. if (isWindows) {
  11557. var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
  11558. } else {
  11559. var nextPartRe = /(.*?)(?:[\/]+|$)/g;
  11560. } // Regex to find the device root, including trailing slash. E.g. 'c:\\'.
  11561. if (isWindows) {
  11562. var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
  11563. } else {
  11564. var splitRootRe = /^[\/]*/;
  11565. }
  11566. var realpathSync$1 = function realpathSync(p, cache) {
  11567. // make p is absolute
  11568. p = path.resolve(p);
  11569. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  11570. return cache[p];
  11571. }
  11572. var original = p,
  11573. seenLinks = {},
  11574. knownHard = {}; // current character position in p
  11575. var pos; // the partial path so far, including a trailing slash if any
  11576. var current; // the partial path without a trailing slash (except when pointing at a root)
  11577. var base; // the partial path scanned in the previous round, with slash
  11578. var previous;
  11579. start();
  11580. function start() {
  11581. // Skip over roots
  11582. var m = splitRootRe.exec(p);
  11583. pos = m[0].length;
  11584. current = m[0];
  11585. base = m[0];
  11586. previous = ''; // On windows, check that the root exists. On unix there is no need.
  11587. if (isWindows && !knownHard[base]) {
  11588. fs.lstatSync(base);
  11589. knownHard[base] = true;
  11590. }
  11591. } // walk down the path, swapping out linked pathparts for their real
  11592. // values
  11593. // NB: p.length changes.
  11594. while (pos < p.length) {
  11595. // find the next part
  11596. nextPartRe.lastIndex = pos;
  11597. var result = nextPartRe.exec(p);
  11598. previous = current;
  11599. current += result[0];
  11600. base = previous + result[1];
  11601. pos = nextPartRe.lastIndex; // continue if not a symlink
  11602. if (knownHard[base] || cache && cache[base] === base) {
  11603. continue;
  11604. }
  11605. var resolvedLink;
  11606. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  11607. // some known symbolic link. no need to stat again.
  11608. resolvedLink = cache[base];
  11609. } else {
  11610. var stat = fs.lstatSync(base);
  11611. if (!stat.isSymbolicLink()) {
  11612. knownHard[base] = true;
  11613. if (cache) cache[base] = base;
  11614. continue;
  11615. } // read the link if it wasn't read before
  11616. // dev/ino always return 0 on windows, so skip the check.
  11617. var linkTarget = null;
  11618. if (!isWindows) {
  11619. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  11620. if (seenLinks.hasOwnProperty(id)) {
  11621. linkTarget = seenLinks[id];
  11622. }
  11623. }
  11624. if (linkTarget === null) {
  11625. fs.statSync(base);
  11626. linkTarget = fs.readlinkSync(base);
  11627. }
  11628. resolvedLink = path.resolve(previous, linkTarget); // track this, if given a cache.
  11629. if (cache) cache[base] = resolvedLink;
  11630. if (!isWindows) seenLinks[id] = linkTarget;
  11631. } // resolve the link, then start over
  11632. p = path.resolve(resolvedLink, p.slice(pos));
  11633. start();
  11634. }
  11635. if (cache) cache[original] = p;
  11636. return p;
  11637. };
  11638. var realpath$1 = function realpath(p, cache, cb) {
  11639. if (typeof cb !== 'function') {
  11640. cb = maybeCallback(cache);
  11641. cache = null;
  11642. } // make p is absolute
  11643. p = path.resolve(p);
  11644. if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
  11645. return process.nextTick(cb.bind(null, null, cache[p]));
  11646. }
  11647. var original = p,
  11648. seenLinks = {},
  11649. knownHard = {}; // current character position in p
  11650. var pos; // the partial path so far, including a trailing slash if any
  11651. var current; // the partial path without a trailing slash (except when pointing at a root)
  11652. var base; // the partial path scanned in the previous round, with slash
  11653. var previous;
  11654. start();
  11655. function start() {
  11656. // Skip over roots
  11657. var m = splitRootRe.exec(p);
  11658. pos = m[0].length;
  11659. current = m[0];
  11660. base = m[0];
  11661. previous = ''; // On windows, check that the root exists. On unix there is no need.
  11662. if (isWindows && !knownHard[base]) {
  11663. fs.lstat(base, function (err) {
  11664. if (err) return cb(err);
  11665. knownHard[base] = true;
  11666. LOOP();
  11667. });
  11668. } else {
  11669. process.nextTick(LOOP);
  11670. }
  11671. } // walk down the path, swapping out linked pathparts for their real
  11672. // values
  11673. function LOOP() {
  11674. // stop if scanned past end of path
  11675. if (pos >= p.length) {
  11676. if (cache) cache[original] = p;
  11677. return cb(null, p);
  11678. } // find the next part
  11679. nextPartRe.lastIndex = pos;
  11680. var result = nextPartRe.exec(p);
  11681. previous = current;
  11682. current += result[0];
  11683. base = previous + result[1];
  11684. pos = nextPartRe.lastIndex; // continue if not a symlink
  11685. if (knownHard[base] || cache && cache[base] === base) {
  11686. return process.nextTick(LOOP);
  11687. }
  11688. if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
  11689. // known symbolic link. no need to stat again.
  11690. return gotResolvedLink(cache[base]);
  11691. }
  11692. return fs.lstat(base, gotStat);
  11693. }
  11694. function gotStat(err, stat) {
  11695. if (err) return cb(err); // if not a symlink, skip to the next path part
  11696. if (!stat.isSymbolicLink()) {
  11697. knownHard[base] = true;
  11698. if (cache) cache[base] = base;
  11699. return process.nextTick(LOOP);
  11700. } // stat & read the link if not read before
  11701. // call gotTarget as soon as the link target is known
  11702. // dev/ino always return 0 on windows, so skip the check.
  11703. if (!isWindows) {
  11704. var id = stat.dev.toString(32) + ':' + stat.ino.toString(32);
  11705. if (seenLinks.hasOwnProperty(id)) {
  11706. return gotTarget(null, seenLinks[id], base);
  11707. }
  11708. }
  11709. fs.stat(base, function (err) {
  11710. if (err) return cb(err);
  11711. fs.readlink(base, function (err, target) {
  11712. if (!isWindows) seenLinks[id] = target;
  11713. gotTarget(err, target);
  11714. });
  11715. });
  11716. }
  11717. function gotTarget(err, target, base) {
  11718. if (err) return cb(err);
  11719. var resolvedLink = path.resolve(previous, target);
  11720. if (cache) cache[base] = resolvedLink;
  11721. gotResolvedLink(resolvedLink);
  11722. }
  11723. function gotResolvedLink(resolvedLink) {
  11724. // resolve the link, then start over
  11725. p = path.resolve(resolvedLink, p.slice(pos));
  11726. start();
  11727. }
  11728. };
  11729. var old = {
  11730. realpathSync: realpathSync$1,
  11731. realpath: realpath$1
  11732. };
  11733. var fs_realpath = realpath;
  11734. realpath.realpath = realpath;
  11735. realpath.sync = realpathSync;
  11736. realpath.realpathSync = realpathSync;
  11737. realpath.monkeypatch = monkeypatch;
  11738. realpath.unmonkeypatch = unmonkeypatch;
  11739. var origRealpath = fs.realpath;
  11740. var origRealpathSync = fs.realpathSync;
  11741. var version$2 = process.version;
  11742. var ok = /^v[0-5]\./.test(version$2);
  11743. function newError(er) {
  11744. return er && er.syscall === 'realpath' && (er.code === 'ELOOP' || er.code === 'ENOMEM' || er.code === 'ENAMETOOLONG');
  11745. }
  11746. function realpath(p, cache, cb) {
  11747. if (ok) {
  11748. return origRealpath(p, cache, cb);
  11749. }
  11750. if (typeof cache === 'function') {
  11751. cb = cache;
  11752. cache = null;
  11753. }
  11754. origRealpath(p, cache, function (er, result) {
  11755. if (newError(er)) {
  11756. old.realpath(p, cache, cb);
  11757. } else {
  11758. cb(er, result);
  11759. }
  11760. });
  11761. }
  11762. function realpathSync(p, cache) {
  11763. if (ok) {
  11764. return origRealpathSync(p, cache);
  11765. }
  11766. try {
  11767. return origRealpathSync(p, cache);
  11768. } catch (er) {
  11769. if (newError(er)) {
  11770. return old.realpathSync(p, cache);
  11771. } else {
  11772. throw er;
  11773. }
  11774. }
  11775. }
  11776. function monkeypatch() {
  11777. fs.realpath = realpath;
  11778. fs.realpathSync = realpathSync;
  11779. }
  11780. function unmonkeypatch() {
  11781. fs.realpath = origRealpath;
  11782. fs.realpathSync = origRealpathSync;
  11783. }
  11784. var concatMap = function concatMap(xs, fn) {
  11785. var res = [];
  11786. for (var i = 0; i < xs.length; i++) {
  11787. var x = fn(xs[i], i);
  11788. if (isArray(x)) res.push.apply(res, x);else res.push(x);
  11789. }
  11790. return res;
  11791. };
  11792. var isArray = Array.isArray || function (xs) {
  11793. return Object.prototype.toString.call(xs) === '[object Array]';
  11794. };
  11795. var balancedMatch = balanced;
  11796. function balanced(a, b, str) {
  11797. if (a instanceof RegExp) a = maybeMatch(a, str);
  11798. if (b instanceof RegExp) b = maybeMatch(b, str);
  11799. var r = range(a, b, str);
  11800. return r && {
  11801. start: r[0],
  11802. end: r[1],
  11803. pre: str.slice(0, r[0]),
  11804. body: str.slice(r[0] + a.length, r[1]),
  11805. post: str.slice(r[1] + b.length)
  11806. };
  11807. }
  11808. function maybeMatch(reg, str) {
  11809. var m = str.match(reg);
  11810. return m ? m[0] : null;
  11811. }
  11812. balanced.range = range;
  11813. function range(a, b, str) {
  11814. var begs, beg, left, right, result;
  11815. var ai = str.indexOf(a);
  11816. var bi = str.indexOf(b, ai + 1);
  11817. var i = ai;
  11818. if (ai >= 0 && bi > 0) {
  11819. begs = [];
  11820. left = str.length;
  11821. while (i >= 0 && !result) {
  11822. if (i == ai) {
  11823. begs.push(i);
  11824. ai = str.indexOf(a, i + 1);
  11825. } else if (begs.length == 1) {
  11826. result = [begs.pop(), bi];
  11827. } else {
  11828. beg = begs.pop();
  11829. if (beg < left) {
  11830. left = beg;
  11831. right = bi;
  11832. }
  11833. bi = str.indexOf(b, i + 1);
  11834. }
  11835. i = ai < bi && ai >= 0 ? ai : bi;
  11836. }
  11837. if (begs.length) {
  11838. result = [left, right];
  11839. }
  11840. }
  11841. return result;
  11842. }
  11843. var braceExpansion = expandTop;
  11844. var escSlash = '\0SLASH' + Math.random() + '\0';
  11845. var escOpen = '\0OPEN' + Math.random() + '\0';
  11846. var escClose = '\0CLOSE' + Math.random() + '\0';
  11847. var escComma = '\0COMMA' + Math.random() + '\0';
  11848. var escPeriod = '\0PERIOD' + Math.random() + '\0';
  11849. function numeric(str) {
  11850. return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
  11851. }
  11852. function escapeBraces(str) {
  11853. return str.split('\\\\').join(escSlash).split('\\{').join(escOpen).split('\\}').join(escClose).split('\\,').join(escComma).split('\\.').join(escPeriod);
  11854. }
  11855. function unescapeBraces(str) {
  11856. return str.split(escSlash).join('\\').split(escOpen).join('{').split(escClose).join('}').split(escComma).join(',').split(escPeriod).join('.');
  11857. } // Basically just str.split(","), but handling cases
  11858. // where we have nested braced sections, which should be
  11859. // treated as individual members, like {a,{b,c},d}
  11860. function parseCommaParts(str) {
  11861. if (!str) return [''];
  11862. var parts = [];
  11863. var m = balancedMatch('{', '}', str);
  11864. if (!m) return str.split(',');
  11865. var pre = m.pre;
  11866. var body = m.body;
  11867. var post = m.post;
  11868. var p = pre.split(',');
  11869. p[p.length - 1] += '{' + body + '}';
  11870. var postParts = parseCommaParts(post);
  11871. if (post.length) {
  11872. p[p.length - 1] += postParts.shift();
  11873. p.push.apply(p, postParts);
  11874. }
  11875. parts.push.apply(parts, p);
  11876. return parts;
  11877. }
  11878. function expandTop(str) {
  11879. if (!str) return []; // I don't know why Bash 4.3 does this, but it does.
  11880. // Anything starting with {} will have the first two bytes preserved
  11881. // but *only* at the top level, so {},a}b will not expand to anything,
  11882. // but a{},b}c will be expanded to [a}c,abc].
  11883. // One could argue that this is a bug in Bash, but since the goal of
  11884. // this module is to match Bash's rules, we escape a leading {}
  11885. if (str.substr(0, 2) === '{}') {
  11886. str = '\\{\\}' + str.substr(2);
  11887. }
  11888. return expand(escapeBraces(str), true).map(unescapeBraces);
  11889. }
  11890. function embrace(str) {
  11891. return '{' + str + '}';
  11892. }
  11893. function isPadded(el) {
  11894. return /^-?0\d/.test(el);
  11895. }
  11896. function lte(i, y) {
  11897. return i <= y;
  11898. }
  11899. function gte(i, y) {
  11900. return i >= y;
  11901. }
  11902. function expand(str, isTop) {
  11903. var expansions = [];
  11904. var m = balancedMatch('{', '}', str);
  11905. if (!m || /\$$/.test(m.pre)) return [str];
  11906. var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
  11907. var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
  11908. var isSequence = isNumericSequence || isAlphaSequence;
  11909. var isOptions = m.body.indexOf(',') >= 0;
  11910. if (!isSequence && !isOptions) {
  11911. // {a},b}
  11912. if (m.post.match(/,.*\}/)) {
  11913. str = m.pre + '{' + m.body + escClose + m.post;
  11914. return expand(str);
  11915. }
  11916. return [str];
  11917. }
  11918. var n;
  11919. if (isSequence) {
  11920. n = m.body.split(/\.\./);
  11921. } else {
  11922. n = parseCommaParts(m.body);
  11923. if (n.length === 1) {
  11924. // x{{a,b}}y ==> x{a}y x{b}y
  11925. n = expand(n[0], false).map(embrace);
  11926. if (n.length === 1) {
  11927. var post = m.post.length ? expand(m.post, false) : [''];
  11928. return post.map(function (p) {
  11929. return m.pre + n[0] + p;
  11930. });
  11931. }
  11932. }
  11933. } // at this point, n is the parts, and we know it's not a comma set
  11934. // with a single entry.
  11935. // no need to expand pre, since it is guaranteed to be free of brace-sets
  11936. var pre = m.pre;
  11937. var post = m.post.length ? expand(m.post, false) : [''];
  11938. var N;
  11939. if (isSequence) {
  11940. var x = numeric(n[0]);
  11941. var y = numeric(n[1]);
  11942. var width = Math.max(n[0].length, n[1].length);
  11943. var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
  11944. var test = lte;
  11945. var reverse = y < x;
  11946. if (reverse) {
  11947. incr *= -1;
  11948. test = gte;
  11949. }
  11950. var pad = n.some(isPadded);
  11951. N = [];
  11952. for (var i = x; test(i, y); i += incr) {
  11953. var c;
  11954. if (isAlphaSequence) {
  11955. c = String.fromCharCode(i);
  11956. if (c === '\\') c = '';
  11957. } else {
  11958. c = String(i);
  11959. if (pad) {
  11960. var need = width - c.length;
  11961. if (need > 0) {
  11962. var z = new Array(need + 1).join('0');
  11963. if (i < 0) c = '-' + z + c.slice(1);else c = z + c;
  11964. }
  11965. }
  11966. }
  11967. N.push(c);
  11968. }
  11969. } else {
  11970. N = concatMap(n, function (el) {
  11971. return expand(el, false);
  11972. });
  11973. }
  11974. for (var j = 0; j < N.length; j++) {
  11975. for (var k = 0; k < post.length; k++) {
  11976. var expansion = pre + N[j] + post[k];
  11977. if (!isTop || isSequence || expansion) expansions.push(expansion);
  11978. }
  11979. }
  11980. return expansions;
  11981. }
  11982. var minimatch_1 = minimatch;
  11983. minimatch.Minimatch = Minimatch$1;
  11984. var path$2 = {
  11985. sep: '/'
  11986. };
  11987. try {
  11988. path$2 = path;
  11989. } catch (er) {}
  11990. var GLOBSTAR = minimatch.GLOBSTAR = Minimatch$1.GLOBSTAR = {};
  11991. var plTypes = {
  11992. '!': {
  11993. open: '(?:(?!(?:',
  11994. close: '))[^/]*?)'
  11995. },
  11996. '?': {
  11997. open: '(?:',
  11998. close: ')?'
  11999. },
  12000. '+': {
  12001. open: '(?:',
  12002. close: ')+'
  12003. },
  12004. '*': {
  12005. open: '(?:',
  12006. close: ')*'
  12007. },
  12008. '@': {
  12009. open: '(?:',
  12010. close: ')'
  12011. } // any single thing other than /
  12012. // don't need to escape / when using new RegExp()
  12013. };
  12014. var qmark = '[^/]'; // * => any number of characters
  12015. var star = qmark + '*?'; // ** when dots are allowed. Anything goes, except .. and .
  12016. // not (^ or / followed by one or two dots followed by $ or /),
  12017. // followed by anything, any number of times.
  12018. var twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?'; // not a ^ or / followed by a dot,
  12019. // followed by anything, any number of times.
  12020. var twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?'; // characters that need to be escaped in RegExp.
  12021. var reSpecials = charSet('().*{}+?[]^$\\!'); // "abc" -> { a:true, b:true, c:true }
  12022. function charSet(s) {
  12023. return s.split('').reduce(function (set, c) {
  12024. set[c] = true;
  12025. return set;
  12026. }, {});
  12027. } // normalizes slashes.
  12028. var slashSplit = /\/+/;
  12029. minimatch.filter = filter$1;
  12030. function filter$1(pattern, options) {
  12031. options = options || {};
  12032. return function (p, i, list) {
  12033. return minimatch(p, pattern, options);
  12034. };
  12035. }
  12036. function ext(a, b) {
  12037. a = a || {};
  12038. b = b || {};
  12039. var t = {};
  12040. Object.keys(b).forEach(function (k) {
  12041. t[k] = b[k];
  12042. });
  12043. Object.keys(a).forEach(function (k) {
  12044. t[k] = a[k];
  12045. });
  12046. return t;
  12047. }
  12048. minimatch.defaults = function (def) {
  12049. if (!def || !Object.keys(def).length) return minimatch;
  12050. var orig = minimatch;
  12051. var m = function minimatch(p, pattern, options) {
  12052. return orig.minimatch(p, pattern, ext(def, options));
  12053. };
  12054. m.Minimatch = function Minimatch(pattern, options) {
  12055. return new orig.Minimatch(pattern, ext(def, options));
  12056. };
  12057. return m;
  12058. };
  12059. Minimatch$1.defaults = function (def) {
  12060. if (!def || !Object.keys(def).length) return Minimatch$1;
  12061. return minimatch.defaults(def).Minimatch;
  12062. };
  12063. function minimatch(p, pattern, options) {
  12064. if (typeof pattern !== 'string') {
  12065. throw new TypeError('glob pattern string required');
  12066. }
  12067. if (!options) options = {}; // shortcut: comments match nothing.
  12068. if (!options.nocomment && pattern.charAt(0) === '#') {
  12069. return false;
  12070. } // "" only matches ""
  12071. if (pattern.trim() === '') return p === '';
  12072. return new Minimatch$1(pattern, options).match(p);
  12073. }
  12074. function Minimatch$1(pattern, options) {
  12075. if (!(this instanceof Minimatch$1)) {
  12076. return new Minimatch$1(pattern, options);
  12077. }
  12078. if (typeof pattern !== 'string') {
  12079. throw new TypeError('glob pattern string required');
  12080. }
  12081. if (!options) options = {};
  12082. pattern = pattern.trim(); // windows support: need to use /, not \
  12083. if (path$2.sep !== '/') {
  12084. pattern = pattern.split(path$2.sep).join('/');
  12085. }
  12086. this.options = options;
  12087. this.set = [];
  12088. this.pattern = pattern;
  12089. this.regexp = null;
  12090. this.negate = false;
  12091. this.comment = false;
  12092. this.empty = false; // make the set of regexps etc.
  12093. this.make();
  12094. }
  12095. Minimatch$1.prototype.debug = function () {};
  12096. Minimatch$1.prototype.make = make;
  12097. function make() {
  12098. // don't do it more than once.
  12099. if (this._made) return;
  12100. var pattern = this.pattern;
  12101. var options = this.options; // empty patterns and comments match nothing.
  12102. if (!options.nocomment && pattern.charAt(0) === '#') {
  12103. this.comment = true;
  12104. return;
  12105. }
  12106. if (!pattern) {
  12107. this.empty = true;
  12108. return;
  12109. } // step 1: figure out negation, etc.
  12110. this.parseNegate(); // step 2: expand braces
  12111. var set = this.globSet = this.braceExpand();
  12112. if (options.debug) this.debug = console.error;
  12113. this.debug(this.pattern, set); // step 3: now we have a set, so turn each one into a series of path-portion
  12114. // matching patterns.
  12115. // These will be regexps, except in the case of "**", which is
  12116. // set to the GLOBSTAR object for globstar behavior,
  12117. // and will not contain any / characters
  12118. set = this.globParts = set.map(function (s) {
  12119. return s.split(slashSplit);
  12120. });
  12121. this.debug(this.pattern, set); // glob --> regexps
  12122. set = set.map(function (s, si, set) {
  12123. return s.map(this.parse, this);
  12124. }, this);
  12125. this.debug(this.pattern, set); // filter out everything that didn't compile properly.
  12126. set = set.filter(function (s) {
  12127. return s.indexOf(false) === -1;
  12128. });
  12129. this.debug(this.pattern, set);
  12130. this.set = set;
  12131. }
  12132. Minimatch$1.prototype.parseNegate = parseNegate;
  12133. function parseNegate() {
  12134. var pattern = this.pattern;
  12135. var negate = false;
  12136. var options = this.options;
  12137. var negateOffset = 0;
  12138. if (options.nonegate) return;
  12139. for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === '!'; i++) {
  12140. negate = !negate;
  12141. negateOffset++;
  12142. }
  12143. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  12144. this.negate = negate;
  12145. } // Brace expansion:
  12146. // a{b,c}d -> abd acd
  12147. // a{b,}c -> abc ac
  12148. // a{0..3}d -> a0d a1d a2d a3d
  12149. // a{b,c{d,e}f}g -> abg acdfg acefg
  12150. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  12151. //
  12152. // Invalid sets are not expanded.
  12153. // a{2..}b -> a{2..}b
  12154. // a{b}c -> a{b}c
  12155. minimatch.braceExpand = function (pattern, options) {
  12156. return braceExpand(pattern, options);
  12157. };
  12158. Minimatch$1.prototype.braceExpand = braceExpand;
  12159. function braceExpand(pattern, options) {
  12160. if (!options) {
  12161. if (this instanceof Minimatch$1) {
  12162. options = this.options;
  12163. } else {
  12164. options = {};
  12165. }
  12166. }
  12167. pattern = typeof pattern === 'undefined' ? this.pattern : pattern;
  12168. if (typeof pattern === 'undefined') {
  12169. throw new TypeError('undefined pattern');
  12170. }
  12171. if (options.nobrace || !pattern.match(/\{.*\}/)) {
  12172. // shortcut. no need to expand.
  12173. return [pattern];
  12174. }
  12175. return braceExpansion(pattern);
  12176. } // parse a component of the expanded set.
  12177. // At this point, no pattern may contain "/" in it
  12178. // so we're going to return a 2d array, where each entry is the full
  12179. // pattern, split on '/', and then turned into a regular expression.
  12180. // A regexp is made at the end which joins each array with an
  12181. // escaped /, and another full one which joins each regexp with |.
  12182. //
  12183. // Following the lead of Bash 4.1, note that "**" only has special meaning
  12184. // when it is the *only* thing in a path portion. Otherwise, any series
  12185. // of * is equivalent to a single *. Globstar behavior is enabled by
  12186. // default, and can be disabled by setting options.noglobstar.
  12187. Minimatch$1.prototype.parse = parse$3;
  12188. var SUBPARSE = {};
  12189. function parse$3(pattern, isSub) {
  12190. if (pattern.length > 1024 * 64) {
  12191. throw new TypeError('pattern is too long');
  12192. }
  12193. var options = this.options; // shortcuts
  12194. if (!options.noglobstar && pattern === '**') return GLOBSTAR;
  12195. if (pattern === '') return '';
  12196. var re = '';
  12197. var hasMagic = !!options.nocase;
  12198. var escaping = false; // ? => one single character
  12199. var patternListStack = [];
  12200. var negativeLists = [];
  12201. var stateChar;
  12202. var inClass = false;
  12203. var reClassStart = -1;
  12204. var classStart = -1; // . and .. never match anything that doesn't start with .,
  12205. // even when options.dot is set.
  12206. var patternStart = pattern.charAt(0) === '.' ? '' // anything
  12207. // not (start or / followed by . or .. followed by / or end)
  12208. : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' : '(?!\\.)';
  12209. var self = this;
  12210. function clearStateChar() {
  12211. if (stateChar) {
  12212. // we had some state-tracking character
  12213. // that wasn't consumed by this pass.
  12214. switch (stateChar) {
  12215. case '*':
  12216. re += star;
  12217. hasMagic = true;
  12218. break;
  12219. case '?':
  12220. re += qmark;
  12221. hasMagic = true;
  12222. break;
  12223. default:
  12224. re += '\\' + stateChar;
  12225. break;
  12226. }
  12227. self.debug('clearStateChar %j %j', stateChar, re);
  12228. stateChar = false;
  12229. }
  12230. }
  12231. for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
  12232. this.debug('%s\t%s %s %j', pattern, i, re, c); // skip over any that are escaped.
  12233. if (escaping && reSpecials[c]) {
  12234. re += '\\' + c;
  12235. escaping = false;
  12236. continue;
  12237. }
  12238. switch (c) {
  12239. case '/':
  12240. // completely not allowed, even escaped.
  12241. // Should already be path-split by now.
  12242. return false;
  12243. case '\\':
  12244. clearStateChar();
  12245. escaping = true;
  12246. continue;
  12247. // the various stateChar values
  12248. // for the "extglob" stuff.
  12249. case '?':
  12250. case '*':
  12251. case '+':
  12252. case '@':
  12253. case '!':
  12254. this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c); // all of those are literals inside a class, except that
  12255. // the glob [!a] means [^a] in regexp
  12256. if (inClass) {
  12257. this.debug(' in class');
  12258. if (c === '!' && i === classStart + 1) c = '^';
  12259. re += c;
  12260. continue;
  12261. } // if we already have a stateChar, then it means
  12262. // that there was something like ** or +? in there.
  12263. // Handle the stateChar, then proceed with this one.
  12264. self.debug('call clearStateChar %j', stateChar);
  12265. clearStateChar();
  12266. stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
  12267. // just clear the statechar *now*, rather than even diving into
  12268. // the patternList stuff.
  12269. if (options.noext) clearStateChar();
  12270. continue;
  12271. case '(':
  12272. if (inClass) {
  12273. re += '(';
  12274. continue;
  12275. }
  12276. if (!stateChar) {
  12277. re += '\\(';
  12278. continue;
  12279. }
  12280. patternListStack.push({
  12281. type: stateChar,
  12282. start: i - 1,
  12283. reStart: re.length,
  12284. open: plTypes[stateChar].open,
  12285. close: plTypes[stateChar].close
  12286. }); // negation is (?:(?!js)[^/]*)
  12287. re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
  12288. this.debug('plType %j %j', stateChar, re);
  12289. stateChar = false;
  12290. continue;
  12291. case ')':
  12292. if (inClass || !patternListStack.length) {
  12293. re += '\\)';
  12294. continue;
  12295. }
  12296. clearStateChar();
  12297. hasMagic = true;
  12298. var pl = patternListStack.pop(); // negation is (?:(?!js)[^/]*)
  12299. // The others are (?:<pattern>)<type>
  12300. re += pl.close;
  12301. if (pl.type === '!') {
  12302. negativeLists.push(pl);
  12303. }
  12304. pl.reEnd = re.length;
  12305. continue;
  12306. case '|':
  12307. if (inClass || !patternListStack.length || escaping) {
  12308. re += '\\|';
  12309. escaping = false;
  12310. continue;
  12311. }
  12312. clearStateChar();
  12313. re += '|';
  12314. continue;
  12315. // these are mostly the same in regexp and glob
  12316. case '[':
  12317. // swallow any state-tracking char before the [
  12318. clearStateChar();
  12319. if (inClass) {
  12320. re += '\\' + c;
  12321. continue;
  12322. }
  12323. inClass = true;
  12324. classStart = i;
  12325. reClassStart = re.length;
  12326. re += c;
  12327. continue;
  12328. case ']':
  12329. // a right bracket shall lose its special
  12330. // meaning and represent itself in
  12331. // a bracket expression if it occurs
  12332. // first in the list. -- POSIX.2 2.8.3.2
  12333. if (i === classStart + 1 || !inClass) {
  12334. re += '\\' + c;
  12335. escaping = false;
  12336. continue;
  12337. } // handle the case where we left a class open.
  12338. // "[z-a]" is valid, equivalent to "\[z-a\]"
  12339. if (inClass) {
  12340. // split where the last [ was, make sure we don't have
  12341. // an invalid re. if so, re-walk the contents of the
  12342. // would-be class to re-translate any characters that
  12343. // were passed through as-is
  12344. // TODO: It would probably be faster to determine this
  12345. // without a try/catch and a new RegExp, but it's tricky
  12346. // to do safely. For now, this is safe and works.
  12347. var cs = pattern.substring(classStart + 1, i);
  12348. try {
  12349. RegExp('[' + cs + ']');
  12350. } catch (er) {
  12351. // not a valid class!
  12352. var sp = this.parse(cs, SUBPARSE);
  12353. re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
  12354. hasMagic = hasMagic || sp[1];
  12355. inClass = false;
  12356. continue;
  12357. }
  12358. } // finish up the class.
  12359. hasMagic = true;
  12360. inClass = false;
  12361. re += c;
  12362. continue;
  12363. default:
  12364. // swallow any state char that wasn't consumed
  12365. clearStateChar();
  12366. if (escaping) {
  12367. // no need
  12368. escaping = false;
  12369. } else if (reSpecials[c] && !(c === '^' && inClass)) {
  12370. re += '\\';
  12371. }
  12372. re += c;
  12373. } // switch
  12374. } // for
  12375. // handle the case where we left a class open.
  12376. // "[abc" is valid, equivalent to "\[abc"
  12377. if (inClass) {
  12378. // split where the last [ was, and escape it
  12379. // this is a huge pita. We now have to re-walk
  12380. // the contents of the would-be class to re-translate
  12381. // any characters that were passed through as-is
  12382. cs = pattern.substr(classStart + 1);
  12383. sp = this.parse(cs, SUBPARSE);
  12384. re = re.substr(0, reClassStart) + '\\[' + sp[0];
  12385. hasMagic = hasMagic || sp[1];
  12386. } // handle the case where we had a +( thing at the *end*
  12387. // of the pattern.
  12388. // each pattern list stack adds 3 chars, and we need to go through
  12389. // and escape any | chars that were passed through as-is for the regexp.
  12390. // Go through and escape them, taking care not to double-escape any
  12391. // | chars that were already escaped.
  12392. for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
  12393. var tail = re.slice(pl.reStart + pl.open.length);
  12394. this.debug('setting tail', re, pl); // maybe some even number of \, then maybe 1 \, followed by a |
  12395. tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function (_, $1, $2) {
  12396. if (!$2) {
  12397. // the | isn't already escaped, so escape it.
  12398. $2 = '\\';
  12399. } // need to escape all those slashes *again*, without escaping the
  12400. // one that we need for escaping the | character. As it works out,
  12401. // escaping an even number of slashes can be done by simply repeating
  12402. // it exactly after itself. That's why this trick works.
  12403. //
  12404. // I am sorry that you have to see this.
  12405. return $1 + $1 + $2 + '|';
  12406. });
  12407. this.debug('tail=%j\n %s', tail, tail, pl, re);
  12408. var t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
  12409. hasMagic = true;
  12410. re = re.slice(0, pl.reStart) + t + '\\(' + tail;
  12411. } // handle trailing things that only matter at the very end.
  12412. clearStateChar();
  12413. if (escaping) {
  12414. // trailing \\
  12415. re += '\\\\';
  12416. } // only need to apply the nodot start if the re starts with
  12417. // something that could conceivably capture a dot
  12418. var addPatternStart = false;
  12419. switch (re.charAt(0)) {
  12420. case '.':
  12421. case '[':
  12422. case '(':
  12423. addPatternStart = true;
  12424. } // Hack to work around lack of negative lookbehind in JS
  12425. // A pattern like: *.!(x).!(y|z) needs to ensure that a name
  12426. // like 'a.xyz.yz' doesn't match. So, the first negative
  12427. // lookahead, has to look ALL the way ahead, to the end of
  12428. // the pattern.
  12429. for (var n = negativeLists.length - 1; n > -1; n--) {
  12430. var nl = negativeLists[n];
  12431. var nlBefore = re.slice(0, nl.reStart);
  12432. var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
  12433. var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
  12434. var nlAfter = re.slice(nl.reEnd);
  12435. nlLast += nlAfter; // Handle nested stuff like *(*.js|!(*.json)), where open parens
  12436. // mean that we should *not* include the ) in the bit that is considered
  12437. // "after" the negated section.
  12438. var openParensBefore = nlBefore.split('(').length - 1;
  12439. var cleanAfter = nlAfter;
  12440. for (i = 0; i < openParensBefore; i++) {
  12441. cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
  12442. }
  12443. nlAfter = cleanAfter;
  12444. var dollar = '';
  12445. if (nlAfter === '' && isSub !== SUBPARSE) {
  12446. dollar = '$';
  12447. }
  12448. var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
  12449. re = newRe;
  12450. } // if the re is not "" at this point, then we need to make sure
  12451. // it doesn't match against an empty path part.
  12452. // Otherwise a/* will match a/, which it should not.
  12453. if (re !== '' && hasMagic) {
  12454. re = '(?=.)' + re;
  12455. }
  12456. if (addPatternStart) {
  12457. re = patternStart + re;
  12458. } // parsing just a piece of a larger pattern.
  12459. if (isSub === SUBPARSE) {
  12460. return [re, hasMagic];
  12461. } // skip the regexp for non-magical patterns
  12462. // unescape anything in it, though, so that it'll be
  12463. // an exact match against a file etc.
  12464. if (!hasMagic) {
  12465. return globUnescape(pattern);
  12466. }
  12467. var flags = options.nocase ? 'i' : '';
  12468. try {
  12469. var regExp = new RegExp('^' + re + '$', flags);
  12470. } catch (er) {
  12471. // If it was an invalid regular expression, then it can't match
  12472. // anything. This trick looks for a character after the end of
  12473. // the string, which is of course impossible, except in multi-line
  12474. // mode, but it's not a /m regex.
  12475. return new RegExp('$.');
  12476. }
  12477. regExp._glob = pattern;
  12478. regExp._src = re;
  12479. return regExp;
  12480. }
  12481. minimatch.makeRe = function (pattern, options) {
  12482. return new Minimatch$1(pattern, options || {}).makeRe();
  12483. };
  12484. Minimatch$1.prototype.makeRe = makeRe;
  12485. function makeRe() {
  12486. if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
  12487. // pattern strings, or "**".
  12488. //
  12489. // It's better to use .match(). This function shouldn't
  12490. // be used, really, but it's pretty convenient sometimes,
  12491. // when you just want to work with a regex.
  12492. var set = this.set;
  12493. if (!set.length) {
  12494. this.regexp = false;
  12495. return this.regexp;
  12496. }
  12497. var options = this.options;
  12498. var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
  12499. var flags = options.nocase ? 'i' : '';
  12500. var re = set.map(function (pattern) {
  12501. return pattern.map(function (p) {
  12502. return p === GLOBSTAR ? twoStar : typeof p === 'string' ? regExpEscape(p) : p._src;
  12503. }).join('\\\/');
  12504. }).join('|'); // must match entire pattern
  12505. // ending in a * or ** will make it less strict.
  12506. re = '^(?:' + re + ')$'; // can match anything, as long as it's not this.
  12507. if (this.negate) re = '^(?!' + re + ').*$';
  12508. try {
  12509. this.regexp = new RegExp(re, flags);
  12510. } catch (ex) {
  12511. this.regexp = false;
  12512. }
  12513. return this.regexp;
  12514. }
  12515. minimatch.match = function (list, pattern, options) {
  12516. options = options || {};
  12517. var mm = new Minimatch$1(pattern, options);
  12518. list = list.filter(function (f) {
  12519. return mm.match(f);
  12520. });
  12521. if (mm.options.nonull && !list.length) {
  12522. list.push(pattern);
  12523. }
  12524. return list;
  12525. };
  12526. Minimatch$1.prototype.match = match;
  12527. function match(f, partial) {
  12528. this.debug('match', f, this.pattern); // short-circuit in the case of busted things.
  12529. // comments, etc.
  12530. if (this.comment) return false;
  12531. if (this.empty) return f === '';
  12532. if (f === '/' && partial) return true;
  12533. var options = this.options; // windows: need to use /, not \
  12534. if (path$2.sep !== '/') {
  12535. f = f.split(path$2.sep).join('/');
  12536. } // treat the test path as a set of pathparts.
  12537. f = f.split(slashSplit);
  12538. this.debug(this.pattern, 'split', f); // just ONE of the pattern sets in this.set needs to match
  12539. // in order for it to be valid. If negating, then just one
  12540. // match means that we have failed.
  12541. // Either way, return on the first hit.
  12542. var set = this.set;
  12543. this.debug(this.pattern, 'set', set); // Find the basename of the path by looking for the last non-empty segment
  12544. var filename;
  12545. var i;
  12546. for (i = f.length - 1; i >= 0; i--) {
  12547. filename = f[i];
  12548. if (filename) break;
  12549. }
  12550. for (i = 0; i < set.length; i++) {
  12551. var pattern = set[i];
  12552. var file = f;
  12553. if (options.matchBase && pattern.length === 1) {
  12554. file = [filename];
  12555. }
  12556. var hit = this.matchOne(file, pattern, partial);
  12557. if (hit) {
  12558. if (options.flipNegate) return true;
  12559. return !this.negate;
  12560. }
  12561. } // didn't get any hits. this is success if it's a negative
  12562. // pattern, failure otherwise.
  12563. if (options.flipNegate) return false;
  12564. return this.negate;
  12565. } // set partial to true to test if, for example,
  12566. // "/a/b" matches the start of "/*/b/*/d"
  12567. // Partial means, if you run out of file before you run
  12568. // out of pattern, then that's fine, as long as all
  12569. // the parts match.
  12570. Minimatch$1.prototype.matchOne = function (file, pattern, partial) {
  12571. var options = this.options;
  12572. this.debug('matchOne', {
  12573. 'this': this,
  12574. file: file,
  12575. pattern: pattern
  12576. });
  12577. this.debug('matchOne', file.length, pattern.length);
  12578. for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
  12579. this.debug('matchOne loop');
  12580. var p = pattern[pi];
  12581. var f = file[fi];
  12582. this.debug(pattern, p, f); // should be impossible.
  12583. // some invalid regexp stuff in the set.
  12584. if (p === false) return false;
  12585. if (p === GLOBSTAR) {
  12586. this.debug('GLOBSTAR', [pattern, p, f]); // "**"
  12587. // a/**/b/**/c would match the following:
  12588. // a/b/x/y/z/c
  12589. // a/x/y/z/b/c
  12590. // a/b/x/b/x/c
  12591. // a/b/c
  12592. // To do this, take the rest of the pattern after
  12593. // the **, and see if it would match the file remainder.
  12594. // If so, return success.
  12595. // If not, the ** "swallows" a segment, and try again.
  12596. // This is recursively awful.
  12597. //
  12598. // a/**/b/**/c matching a/b/x/y/z/c
  12599. // - a matches a
  12600. // - doublestar
  12601. // - matchOne(b/x/y/z/c, b/**/c)
  12602. // - b matches b
  12603. // - doublestar
  12604. // - matchOne(x/y/z/c, c) -> no
  12605. // - matchOne(y/z/c, c) -> no
  12606. // - matchOne(z/c, c) -> no
  12607. // - matchOne(c, c) yes, hit
  12608. var fr = fi;
  12609. var pr = pi + 1;
  12610. if (pr === pl) {
  12611. this.debug('** at the end'); // a ** at the end will just swallow the rest.
  12612. // We have found a match.
  12613. // however, it will not swallow /.x, unless
  12614. // options.dot is set.
  12615. // . and .. are *never* matched by **, for explosively
  12616. // exponential reasons.
  12617. for (; fi < fl; fi++) {
  12618. if (file[fi] === '.' || file[fi] === '..' || !options.dot && file[fi].charAt(0) === '.') return false;
  12619. }
  12620. return true;
  12621. } // ok, let's see if we can swallow whatever we can.
  12622. while (fr < fl) {
  12623. var swallowee = file[fr];
  12624. this.debug('\nglobstar while', file, fr, pattern, pr, swallowee); // XXX remove this slice. Just pass the start index.
  12625. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  12626. this.debug('globstar found match!', fr, fl, swallowee); // found a match.
  12627. return true;
  12628. } else {
  12629. // can't swallow "." or ".." ever.
  12630. // can only swallow ".foo" when explicitly asked.
  12631. if (swallowee === '.' || swallowee === '..' || !options.dot && swallowee.charAt(0) === '.') {
  12632. this.debug('dot detected!', file, fr, pattern, pr);
  12633. break;
  12634. } // ** swallows a segment, and continue.
  12635. this.debug('globstar swallow a segment, and continue');
  12636. fr++;
  12637. }
  12638. } // no match was found.
  12639. // However, in partial mode, we can't say this is necessarily over.
  12640. // If there's more *pattern* left, then
  12641. if (partial) {
  12642. // ran out of file
  12643. this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
  12644. if (fr === fl) return true;
  12645. }
  12646. return false;
  12647. } // something other than **
  12648. // non-magic patterns just have to match exactly
  12649. // patterns with magic have been turned into regexps.
  12650. var hit;
  12651. if (typeof p === 'string') {
  12652. if (options.nocase) {
  12653. hit = f.toLowerCase() === p.toLowerCase();
  12654. } else {
  12655. hit = f === p;
  12656. }
  12657. this.debug('string match', p, f, hit);
  12658. } else {
  12659. hit = f.match(p);
  12660. this.debug('pattern match', p, f, hit);
  12661. }
  12662. if (!hit) return false;
  12663. } // Note: ending in / means that we'll get a final ""
  12664. // at the end of the pattern. This can only match a
  12665. // corresponding "" at the end of the file.
  12666. // If the file ends in /, then it can only match a
  12667. // a pattern that ends in /, unless the pattern just
  12668. // doesn't have any more for it. But, a/b/ should *not*
  12669. // match "a/b/*", even though "" matches against the
  12670. // [^/]*? pattern, except in partial mode, where it might
  12671. // simply not be reached yet.
  12672. // However, a/b/ should still satisfy a/*
  12673. // now either we fell off the end of the pattern, or we're done.
  12674. if (fi === fl && pi === pl) {
  12675. // ran out of pattern and filename at the same time.
  12676. // an exact hit!
  12677. return true;
  12678. } else if (fi === fl) {
  12679. // ran out of file, but still had pattern left.
  12680. // this is ok if we're doing the match as part of
  12681. // a glob fs traversal.
  12682. return partial;
  12683. } else if (pi === pl) {
  12684. // ran out of pattern, still have file left.
  12685. // this is only acceptable if we're on the very last
  12686. // empty segment of a file with a trailing slash.
  12687. // a/* should match a/b/
  12688. var emptyFileEnd = fi === fl - 1 && file[fi] === '';
  12689. return emptyFileEnd;
  12690. } // should be unreachable.
  12691. throw new Error('wtf?');
  12692. }; // replace stuff like \* with *
  12693. function globUnescape(s) {
  12694. return s.replace(/\\(.)/g, '$1');
  12695. }
  12696. function regExpEscape(s) {
  12697. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
  12698. }
  12699. var inherits_browser = createCommonjsModule(function (module) {
  12700. if (typeof Object.create === 'function') {
  12701. // implementation from standard node.js 'util' module
  12702. module.exports = function inherits(ctor, superCtor) {
  12703. ctor.super_ = superCtor;
  12704. ctor.prototype = Object.create(superCtor.prototype, {
  12705. constructor: {
  12706. value: ctor,
  12707. enumerable: false,
  12708. writable: true,
  12709. configurable: true
  12710. }
  12711. });
  12712. };
  12713. } else {
  12714. // old school shim for old browsers
  12715. module.exports = function inherits(ctor, superCtor) {
  12716. ctor.super_ = superCtor;
  12717. var TempCtor = function TempCtor() {};
  12718. TempCtor.prototype = superCtor.prototype;
  12719. ctor.prototype = new TempCtor();
  12720. ctor.prototype.constructor = ctor;
  12721. };
  12722. }
  12723. });
  12724. var inherits = createCommonjsModule(function (module) {
  12725. try {
  12726. var util$$1 = util;
  12727. if (typeof util$$1.inherits !== 'function') throw '';
  12728. module.exports = util$$1.inherits;
  12729. } catch (e) {
  12730. module.exports = inherits_browser;
  12731. }
  12732. });
  12733. function posix(path$$1) {
  12734. return path$$1.charAt(0) === '/';
  12735. }
  12736. function win32(path$$1) {
  12737. // https://github.com/nodejs/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56
  12738. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
  12739. var result = splitDeviceRe.exec(path$$1);
  12740. var device = result[1] || '';
  12741. var isUnc = Boolean(device && device.charAt(1) !== ':'); // UNC paths are always absolute
  12742. return Boolean(result[2] || isUnc);
  12743. }
  12744. var pathIsAbsolute = process.platform === 'win32' ? win32 : posix;
  12745. var posix_1 = posix;
  12746. var win32_1 = win32;
  12747. pathIsAbsolute.posix = posix_1;
  12748. pathIsAbsolute.win32 = win32_1;
  12749. var alphasort_1 = alphasort$2;
  12750. var alphasorti_1 = alphasorti$2;
  12751. var setopts_1 = setopts$2;
  12752. var ownProp_1 = ownProp$2;
  12753. var makeAbs_1 = makeAbs;
  12754. var finish_1 = finish;
  12755. var mark_1 = mark;
  12756. var isIgnored_1 = isIgnored$2;
  12757. var childrenIgnored_1 = childrenIgnored$2;
  12758. function ownProp$2(obj, field) {
  12759. return Object.prototype.hasOwnProperty.call(obj, field);
  12760. }
  12761. var Minimatch$3 = minimatch_1.Minimatch;
  12762. function alphasorti$2(a, b) {
  12763. return a.toLowerCase().localeCompare(b.toLowerCase());
  12764. }
  12765. function alphasort$2(a, b) {
  12766. return a.localeCompare(b);
  12767. }
  12768. function setupIgnores(self, options) {
  12769. self.ignore = options.ignore || [];
  12770. if (!Array.isArray(self.ignore)) self.ignore = [self.ignore];
  12771. if (self.ignore.length) {
  12772. self.ignore = self.ignore.map(ignoreMap);
  12773. }
  12774. } // ignore patterns are always in dot:true mode.
  12775. function ignoreMap(pattern) {
  12776. var gmatcher = null;
  12777. if (pattern.slice(-3) === '/**') {
  12778. var gpattern = pattern.replace(/(\/\*\*)+$/, '');
  12779. gmatcher = new Minimatch$3(gpattern, {
  12780. dot: true
  12781. });
  12782. }
  12783. return {
  12784. matcher: new Minimatch$3(pattern, {
  12785. dot: true
  12786. }),
  12787. gmatcher: gmatcher
  12788. };
  12789. }
  12790. function setopts$2(self, pattern, options) {
  12791. if (!options) options = {}; // base-matching: just use globstar for that.
  12792. if (options.matchBase && -1 === pattern.indexOf("/")) {
  12793. if (options.noglobstar) {
  12794. throw new Error("base matching requires globstar");
  12795. }
  12796. pattern = "**/" + pattern;
  12797. }
  12798. self.silent = !!options.silent;
  12799. self.pattern = pattern;
  12800. self.strict = options.strict !== false;
  12801. self.realpath = !!options.realpath;
  12802. self.realpathCache = options.realpathCache || Object.create(null);
  12803. self.follow = !!options.follow;
  12804. self.dot = !!options.dot;
  12805. self.mark = !!options.mark;
  12806. self.nodir = !!options.nodir;
  12807. if (self.nodir) self.mark = true;
  12808. self.sync = !!options.sync;
  12809. self.nounique = !!options.nounique;
  12810. self.nonull = !!options.nonull;
  12811. self.nosort = !!options.nosort;
  12812. self.nocase = !!options.nocase;
  12813. self.stat = !!options.stat;
  12814. self.noprocess = !!options.noprocess;
  12815. self.absolute = !!options.absolute;
  12816. self.maxLength = options.maxLength || Infinity;
  12817. self.cache = options.cache || Object.create(null);
  12818. self.statCache = options.statCache || Object.create(null);
  12819. self.symlinks = options.symlinks || Object.create(null);
  12820. setupIgnores(self, options);
  12821. self.changedCwd = false;
  12822. var cwd = process.cwd();
  12823. if (!ownProp$2(options, "cwd")) self.cwd = cwd;else {
  12824. self.cwd = path.resolve(options.cwd);
  12825. self.changedCwd = self.cwd !== cwd;
  12826. }
  12827. self.root = options.root || path.resolve(self.cwd, "/");
  12828. self.root = path.resolve(self.root);
  12829. if (process.platform === "win32") self.root = self.root.replace(/\\/g, "/"); // TODO: is an absolute `cwd` supposed to be resolved against `root`?
  12830. // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
  12831. self.cwdAbs = pathIsAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
  12832. if (process.platform === "win32") self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
  12833. self.nomount = !!options.nomount; // disable comments and negation in Minimatch.
  12834. // Note that they are not supported in Glob itself anyway.
  12835. options.nonegate = true;
  12836. options.nocomment = true;
  12837. self.minimatch = new Minimatch$3(pattern, options);
  12838. self.options = self.minimatch.options;
  12839. }
  12840. function finish(self) {
  12841. var nou = self.nounique;
  12842. var all = nou ? [] : Object.create(null);
  12843. for (var i = 0, l = self.matches.length; i < l; i++) {
  12844. var matches = self.matches[i];
  12845. if (!matches || Object.keys(matches).length === 0) {
  12846. if (self.nonull) {
  12847. // do like the shell, and spit out the literal glob
  12848. var literal = self.minimatch.globSet[i];
  12849. if (nou) all.push(literal);else all[literal] = true;
  12850. }
  12851. } else {
  12852. // had matches
  12853. var m = Object.keys(matches);
  12854. if (nou) all.push.apply(all, m);else m.forEach(function (m) {
  12855. all[m] = true;
  12856. });
  12857. }
  12858. }
  12859. if (!nou) all = Object.keys(all);
  12860. if (!self.nosort) all = all.sort(self.nocase ? alphasorti$2 : alphasort$2); // at *some* point we statted all of these
  12861. if (self.mark) {
  12862. for (var i = 0; i < all.length; i++) {
  12863. all[i] = self._mark(all[i]);
  12864. }
  12865. if (self.nodir) {
  12866. all = all.filter(function (e) {
  12867. var notDir = !/\/$/.test(e);
  12868. var c = self.cache[e] || self.cache[makeAbs(self, e)];
  12869. if (notDir && c) notDir = c !== 'DIR' && !Array.isArray(c);
  12870. return notDir;
  12871. });
  12872. }
  12873. }
  12874. if (self.ignore.length) all = all.filter(function (m) {
  12875. return !isIgnored$2(self, m);
  12876. });
  12877. self.found = all;
  12878. }
  12879. function mark(self, p) {
  12880. var abs = makeAbs(self, p);
  12881. var c = self.cache[abs];
  12882. var m = p;
  12883. if (c) {
  12884. var isDir = c === 'DIR' || Array.isArray(c);
  12885. var slash = p.slice(-1) === '/';
  12886. if (isDir && !slash) m += '/';else if (!isDir && slash) m = m.slice(0, -1);
  12887. if (m !== p) {
  12888. var mabs = makeAbs(self, m);
  12889. self.statCache[mabs] = self.statCache[abs];
  12890. self.cache[mabs] = self.cache[abs];
  12891. }
  12892. }
  12893. return m;
  12894. } // lotta situps...
  12895. function makeAbs(self, f) {
  12896. var abs = f;
  12897. if (f.charAt(0) === '/') {
  12898. abs = path.join(self.root, f);
  12899. } else if (pathIsAbsolute(f) || f === '') {
  12900. abs = f;
  12901. } else if (self.changedCwd) {
  12902. abs = path.resolve(self.cwd, f);
  12903. } else {
  12904. abs = path.resolve(f);
  12905. }
  12906. if (process.platform === 'win32') abs = abs.replace(/\\/g, '/');
  12907. return abs;
  12908. } // Return true, if pattern ends with globstar '**', for the accompanying parent directory.
  12909. // Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents
  12910. function isIgnored$2(self, path$$2) {
  12911. if (!self.ignore.length) return false;
  12912. return self.ignore.some(function (item) {
  12913. return item.matcher.match(path$$2) || !!(item.gmatcher && item.gmatcher.match(path$$2));
  12914. });
  12915. }
  12916. function childrenIgnored$2(self, path$$2) {
  12917. if (!self.ignore.length) return false;
  12918. return self.ignore.some(function (item) {
  12919. return !!(item.gmatcher && item.gmatcher.match(path$$2));
  12920. });
  12921. }
  12922. var common = {
  12923. alphasort: alphasort_1,
  12924. alphasorti: alphasorti_1,
  12925. setopts: setopts_1,
  12926. ownProp: ownProp_1,
  12927. makeAbs: makeAbs_1,
  12928. finish: finish_1,
  12929. mark: mark_1,
  12930. isIgnored: isIgnored_1,
  12931. childrenIgnored: childrenIgnored_1
  12932. };
  12933. var sync$1 = globSync;
  12934. globSync.GlobSync = GlobSync$1;
  12935. var setopts$1 = common.setopts;
  12936. var ownProp$1 = common.ownProp;
  12937. var childrenIgnored$1 = common.childrenIgnored;
  12938. var isIgnored$1 = common.isIgnored;
  12939. function globSync(pattern, options) {
  12940. if (typeof options === 'function' || arguments.length === 3) throw new TypeError('callback provided to sync glob\n' + 'See: https://github.com/isaacs/node-glob/issues/167');
  12941. return new GlobSync$1(pattern, options).found;
  12942. }
  12943. function GlobSync$1(pattern, options) {
  12944. if (!pattern) throw new Error('must provide pattern');
  12945. if (typeof options === 'function' || arguments.length === 3) throw new TypeError('callback provided to sync glob\n' + 'See: https://github.com/isaacs/node-glob/issues/167');
  12946. if (!(this instanceof GlobSync$1)) return new GlobSync$1(pattern, options);
  12947. setopts$1(this, pattern, options);
  12948. if (this.noprocess) return this;
  12949. var n = this.minimatch.set.length;
  12950. this.matches = new Array(n);
  12951. for (var i = 0; i < n; i++) {
  12952. this._process(this.minimatch.set[i], i, false);
  12953. }
  12954. this._finish();
  12955. }
  12956. GlobSync$1.prototype._finish = function () {
  12957. assert(this instanceof GlobSync$1);
  12958. if (this.realpath) {
  12959. var self = this;
  12960. this.matches.forEach(function (matchset, index) {
  12961. var set = self.matches[index] = Object.create(null);
  12962. for (var p in matchset) {
  12963. try {
  12964. p = self._makeAbs(p);
  12965. var real = fs_realpath.realpathSync(p, self.realpathCache);
  12966. set[real] = true;
  12967. } catch (er) {
  12968. if (er.syscall === 'stat') set[self._makeAbs(p)] = true;else throw er;
  12969. }
  12970. }
  12971. });
  12972. }
  12973. common.finish(this);
  12974. };
  12975. GlobSync$1.prototype._process = function (pattern, index, inGlobStar) {
  12976. assert(this instanceof GlobSync$1); // Get the first [n] parts of pattern that are all strings.
  12977. var n = 0;
  12978. while (typeof pattern[n] === 'string') {
  12979. n++;
  12980. } // now n is the index of the first one that is *not* a string.
  12981. // See if there's anything else
  12982. var prefix;
  12983. switch (n) {
  12984. // if not, then this is rather simple
  12985. case pattern.length:
  12986. this._processSimple(pattern.join('/'), index);
  12987. return;
  12988. case 0:
  12989. // pattern *starts* with some non-trivial item.
  12990. // going to readdir(cwd), but not include the prefix in matches.
  12991. prefix = null;
  12992. break;
  12993. default:
  12994. // pattern has some string bits in the front.
  12995. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  12996. // or 'relative' like '../baz'
  12997. prefix = pattern.slice(0, n).join('/');
  12998. break;
  12999. }
  13000. var remain = pattern.slice(n); // get the list of entries.
  13001. var read;
  13002. if (prefix === null) read = '.';else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  13003. if (!prefix || !pathIsAbsolute(prefix)) prefix = '/' + prefix;
  13004. read = prefix;
  13005. } else read = prefix;
  13006. var abs = this._makeAbs(read); //if ignored, skip processing
  13007. if (childrenIgnored$1(this, read)) return;
  13008. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  13009. if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar);
  13010. };
  13011. GlobSync$1.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) {
  13012. var entries = this._readdir(abs, inGlobStar); // if the abs isn't a dir, then nothing can match!
  13013. if (!entries) return; // It will only match dot entries if it starts with a dot, or if
  13014. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  13015. var pn = remain[0];
  13016. var negate = !!this.minimatch.negate;
  13017. var rawGlob = pn._glob;
  13018. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  13019. var matchedEntries = [];
  13020. for (var i = 0; i < entries.length; i++) {
  13021. var e = entries[i];
  13022. if (e.charAt(0) !== '.' || dotOk) {
  13023. var m;
  13024. if (negate && !prefix) {
  13025. m = !e.match(pn);
  13026. } else {
  13027. m = e.match(pn);
  13028. }
  13029. if (m) matchedEntries.push(e);
  13030. }
  13031. }
  13032. var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
  13033. if (len === 0) return; // if this is the last remaining pattern bit, then no need for
  13034. // an additional stat *unless* the user has specified mark or
  13035. // stat explicitly. We know they exist, since readdir returned
  13036. // them.
  13037. if (remain.length === 1 && !this.mark && !this.stat) {
  13038. if (!this.matches[index]) this.matches[index] = Object.create(null);
  13039. for (var i = 0; i < len; i++) {
  13040. var e = matchedEntries[i];
  13041. if (prefix) {
  13042. if (prefix.slice(-1) !== '/') e = prefix + '/' + e;else e = prefix + e;
  13043. }
  13044. if (e.charAt(0) === '/' && !this.nomount) {
  13045. e = path.join(this.root, e);
  13046. }
  13047. this._emitMatch(index, e);
  13048. } // This was the last one, and no stats were needed
  13049. return;
  13050. } // now test all matched entries as stand-ins for that part
  13051. // of the pattern.
  13052. remain.shift();
  13053. for (var i = 0; i < len; i++) {
  13054. var e = matchedEntries[i];
  13055. var newPattern;
  13056. if (prefix) newPattern = [prefix, e];else newPattern = [e];
  13057. this._process(newPattern.concat(remain), index, inGlobStar);
  13058. }
  13059. };
  13060. GlobSync$1.prototype._emitMatch = function (index, e) {
  13061. if (isIgnored$1(this, e)) return;
  13062. var abs = this._makeAbs(e);
  13063. if (this.mark) e = this._mark(e);
  13064. if (this.absolute) {
  13065. e = abs;
  13066. }
  13067. if (this.matches[index][e]) return;
  13068. if (this.nodir) {
  13069. var c = this.cache[abs];
  13070. if (c === 'DIR' || Array.isArray(c)) return;
  13071. }
  13072. this.matches[index][e] = true;
  13073. if (this.stat) this._stat(e);
  13074. };
  13075. GlobSync$1.prototype._readdirInGlobStar = function (abs) {
  13076. // follow all symlinked directories forever
  13077. // just proceed as if this is a non-globstar situation
  13078. if (this.follow) return this._readdir(abs, false);
  13079. var entries;
  13080. var lstat;
  13081. var stat;
  13082. try {
  13083. lstat = fs.lstatSync(abs);
  13084. } catch (er) {
  13085. if (er.code === 'ENOENT') {
  13086. // lstat failed, doesn't exist
  13087. return null;
  13088. }
  13089. }
  13090. var isSym = lstat && lstat.isSymbolicLink();
  13091. this.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
  13092. // don't bother doing a readdir in that case.
  13093. if (!isSym && lstat && !lstat.isDirectory()) this.cache[abs] = 'FILE';else entries = this._readdir(abs, false);
  13094. return entries;
  13095. };
  13096. GlobSync$1.prototype._readdir = function (abs, inGlobStar) {
  13097. var entries;
  13098. if (inGlobStar && !ownProp$1(this.symlinks, abs)) return this._readdirInGlobStar(abs);
  13099. if (ownProp$1(this.cache, abs)) {
  13100. var c = this.cache[abs];
  13101. if (!c || c === 'FILE') return null;
  13102. if (Array.isArray(c)) return c;
  13103. }
  13104. try {
  13105. return this._readdirEntries(abs, fs.readdirSync(abs));
  13106. } catch (er) {
  13107. this._readdirError(abs, er);
  13108. return null;
  13109. }
  13110. };
  13111. GlobSync$1.prototype._readdirEntries = function (abs, entries) {
  13112. // if we haven't asked to stat everything, then just
  13113. // assume that everything in there exists, so we can avoid
  13114. // having to stat it a second time.
  13115. if (!this.mark && !this.stat) {
  13116. for (var i = 0; i < entries.length; i++) {
  13117. var e = entries[i];
  13118. if (abs === '/') e = abs + e;else e = abs + '/' + e;
  13119. this.cache[e] = true;
  13120. }
  13121. }
  13122. this.cache[abs] = entries; // mark and cache dir-ness
  13123. return entries;
  13124. };
  13125. GlobSync$1.prototype._readdirError = function (f, er) {
  13126. // handle errors, and cache the information
  13127. switch (er.code) {
  13128. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  13129. case 'ENOTDIR':
  13130. // totally normal. means it *does* exist.
  13131. var abs = this._makeAbs(f);
  13132. this.cache[abs] = 'FILE';
  13133. if (abs === this.cwdAbs) {
  13134. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  13135. error.path = this.cwd;
  13136. error.code = er.code;
  13137. throw error;
  13138. }
  13139. break;
  13140. case 'ENOENT': // not terribly unusual
  13141. case 'ELOOP':
  13142. case 'ENAMETOOLONG':
  13143. case 'UNKNOWN':
  13144. this.cache[this._makeAbs(f)] = false;
  13145. break;
  13146. default:
  13147. // some unusual error. Treat as failure.
  13148. this.cache[this._makeAbs(f)] = false;
  13149. if (this.strict) throw er;
  13150. if (!this.silent) console.error('glob error', er);
  13151. break;
  13152. }
  13153. };
  13154. GlobSync$1.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar) {
  13155. var entries = this._readdir(abs, inGlobStar); // no entries means not a dir, so it can never have matches
  13156. // foo.txt/** doesn't match foo.txt
  13157. if (!entries) return; // test without the globstar, and with every child both below
  13158. // and replacing the globstar.
  13159. var remainWithoutGlobStar = remain.slice(1);
  13160. var gspref = prefix ? [prefix] : [];
  13161. var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
  13162. this._process(noGlobStar, index, false);
  13163. var len = entries.length;
  13164. var isSym = this.symlinks[abs]; // If it's a symlink, and we're in a globstar, then stop
  13165. if (isSym && inGlobStar) return;
  13166. for (var i = 0; i < len; i++) {
  13167. var e = entries[i];
  13168. if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
  13169. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  13170. this._process(instead, index, true);
  13171. var below = gspref.concat(entries[i], remain);
  13172. this._process(below, index, true);
  13173. }
  13174. };
  13175. GlobSync$1.prototype._processSimple = function (prefix, index) {
  13176. // XXX review this. Shouldn't it be doing the mounting etc
  13177. // before doing stat? kinda weird?
  13178. var exists = this._stat(prefix);
  13179. if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
  13180. if (!exists) return;
  13181. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  13182. var trail = /[\/\\]$/.test(prefix);
  13183. if (prefix.charAt(0) === '/') {
  13184. prefix = path.join(this.root, prefix);
  13185. } else {
  13186. prefix = path.resolve(this.root, prefix);
  13187. if (trail) prefix += '/';
  13188. }
  13189. }
  13190. if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
  13191. this._emitMatch(index, prefix);
  13192. }; // Returns either 'DIR', 'FILE', or false
  13193. GlobSync$1.prototype._stat = function (f) {
  13194. var abs = this._makeAbs(f);
  13195. var needDir = f.slice(-1) === '/';
  13196. if (f.length > this.maxLength) return false;
  13197. if (!this.stat && ownProp$1(this.cache, abs)) {
  13198. var c = this.cache[abs];
  13199. if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
  13200. if (!needDir || c === 'DIR') return c;
  13201. if (needDir && c === 'FILE') return false; // otherwise we have to stat, because maybe c=true
  13202. // if we know it exists, but not what it is.
  13203. }
  13204. var exists;
  13205. var stat = this.statCache[abs];
  13206. if (!stat) {
  13207. var lstat;
  13208. try {
  13209. lstat = fs.lstatSync(abs);
  13210. } catch (er) {
  13211. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  13212. this.statCache[abs] = false;
  13213. return false;
  13214. }
  13215. }
  13216. if (lstat && lstat.isSymbolicLink()) {
  13217. try {
  13218. stat = fs.statSync(abs);
  13219. } catch (er) {
  13220. stat = lstat;
  13221. }
  13222. } else {
  13223. stat = lstat;
  13224. }
  13225. }
  13226. this.statCache[abs] = stat;
  13227. var c = true;
  13228. if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
  13229. this.cache[abs] = this.cache[abs] || c;
  13230. if (needDir && c === 'FILE') return false;
  13231. return c;
  13232. };
  13233. GlobSync$1.prototype._mark = function (p) {
  13234. return common.mark(this, p);
  13235. };
  13236. GlobSync$1.prototype._makeAbs = function (f) {
  13237. return common.makeAbs(this, f);
  13238. };
  13239. // Returns a wrapper function that returns a wrapped callback
  13240. // The wrapper function should do some stuff, and return a
  13241. // presumably different callback function.
  13242. // This makes sure that own properties are retained, so that
  13243. // decorations and such are not lost along the way.
  13244. var wrappy_1 = wrappy;
  13245. function wrappy(fn, cb) {
  13246. if (fn && cb) return wrappy(fn)(cb);
  13247. if (typeof fn !== 'function') throw new TypeError('need wrapper function');
  13248. Object.keys(fn).forEach(function (k) {
  13249. wrapper[k] = fn[k];
  13250. });
  13251. return wrapper;
  13252. function wrapper() {
  13253. var args = new Array(arguments.length);
  13254. for (var i = 0; i < args.length; i++) {
  13255. args[i] = arguments[i];
  13256. }
  13257. var ret = fn.apply(this, args);
  13258. var cb = args[args.length - 1];
  13259. if (typeof ret === 'function' && ret !== cb) {
  13260. Object.keys(cb).forEach(function (k) {
  13261. ret[k] = cb[k];
  13262. });
  13263. }
  13264. return ret;
  13265. }
  13266. }
  13267. var once_1 = wrappy_1(once);
  13268. var strict = wrappy_1(onceStrict);
  13269. once.proto = once(function () {
  13270. Object.defineProperty(Function.prototype, 'once', {
  13271. value: function value() {
  13272. return once(this);
  13273. },
  13274. configurable: true
  13275. });
  13276. Object.defineProperty(Function.prototype, 'onceStrict', {
  13277. value: function value() {
  13278. return onceStrict(this);
  13279. },
  13280. configurable: true
  13281. });
  13282. });
  13283. function once(fn) {
  13284. var f = function f() {
  13285. if (f.called) return f.value;
  13286. f.called = true;
  13287. return f.value = fn.apply(this, arguments);
  13288. };
  13289. f.called = false;
  13290. return f;
  13291. }
  13292. function onceStrict(fn) {
  13293. var f = function f() {
  13294. if (f.called) throw new Error(f.onceError);
  13295. f.called = true;
  13296. return f.value = fn.apply(this, arguments);
  13297. };
  13298. var name = fn.name || 'Function wrapped with `once`';
  13299. f.onceError = name + " shouldn't be called more than once";
  13300. f.called = false;
  13301. return f;
  13302. }
  13303. once_1.strict = strict;
  13304. var reqs = Object.create(null);
  13305. var inflight_1 = wrappy_1(inflight);
  13306. function inflight(key, cb) {
  13307. if (reqs[key]) {
  13308. reqs[key].push(cb);
  13309. return null;
  13310. } else {
  13311. reqs[key] = [cb];
  13312. return makeres(key);
  13313. }
  13314. }
  13315. function makeres(key) {
  13316. return once_1(function RES() {
  13317. var cbs = reqs[key];
  13318. var len = cbs.length;
  13319. var args = slice(arguments); // XXX It's somewhat ambiguous whether a new callback added in this
  13320. // pass should be queued for later execution if something in the
  13321. // list of callbacks throws, or if it should just be discarded.
  13322. // However, it's such an edge case that it hardly matters, and either
  13323. // choice is likely as surprising as the other.
  13324. // As it happens, we do go ahead and schedule it for later execution.
  13325. try {
  13326. for (var i = 0; i < len; i++) {
  13327. cbs[i].apply(null, args);
  13328. }
  13329. } finally {
  13330. if (cbs.length > len) {
  13331. // added more in the interim.
  13332. // de-zalgo, just in case, but don't call again.
  13333. cbs.splice(0, len);
  13334. process.nextTick(function () {
  13335. RES.apply(null, args);
  13336. });
  13337. } else {
  13338. delete reqs[key];
  13339. }
  13340. }
  13341. });
  13342. }
  13343. function slice(args) {
  13344. var length = args.length;
  13345. var array = [];
  13346. for (var i = 0; i < length; i++) {
  13347. array[i] = args[i];
  13348. }
  13349. return array;
  13350. }
  13351. //
  13352. // 1. Get the minimatch set
  13353. // 2. For each pattern in the set, PROCESS(pattern, false)
  13354. // 3. Store matches per-set, then uniq them
  13355. //
  13356. // PROCESS(pattern, inGlobStar)
  13357. // Get the first [n] items from pattern that are all strings
  13358. // Join these together. This is PREFIX.
  13359. // If there is no more remaining, then stat(PREFIX) and
  13360. // add to matches if it succeeds. END.
  13361. //
  13362. // If inGlobStar and PREFIX is symlink and points to dir
  13363. // set ENTRIES = []
  13364. // else readdir(PREFIX) as ENTRIES
  13365. // If fail, END
  13366. //
  13367. // with ENTRIES
  13368. // If pattern[n] is GLOBSTAR
  13369. // // handle the case where the globstar match is empty
  13370. // // by pruning it out, and testing the resulting pattern
  13371. // PROCESS(pattern[0..n] + pattern[n+1 .. $], false)
  13372. // // handle other cases.
  13373. // for ENTRY in ENTRIES (not dotfiles)
  13374. // // attach globstar + tail onto the entry
  13375. // // Mark that this entry is a globstar match
  13376. // PROCESS(pattern[0..n] + ENTRY + pattern[n .. $], true)
  13377. //
  13378. // else // not globstar
  13379. // for ENTRY in ENTRIES (not dotfiles, unless pattern[n] is dot)
  13380. // Test ENTRY against pattern[n]
  13381. // If fails, continue
  13382. // If passes, PROCESS(pattern[0..n] + item + pattern[n+1 .. $])
  13383. //
  13384. // Caveat:
  13385. // Cache all stats and readdirs results to minimize syscall. Since all
  13386. // we ever care about is existence and directory-ness, we can just keep
  13387. // `true` for files, and [children,...] for directories, or `false` for
  13388. // things that don't exist.
  13389. var glob_1 = glob;
  13390. var EE = events.EventEmitter;
  13391. var setopts = common.setopts;
  13392. var ownProp = common.ownProp;
  13393. var childrenIgnored = common.childrenIgnored;
  13394. var isIgnored = common.isIgnored;
  13395. function glob(pattern, options, cb) {
  13396. if (typeof options === 'function') cb = options, options = {};
  13397. if (!options) options = {};
  13398. if (options.sync) {
  13399. if (cb) throw new TypeError('callback provided to sync glob');
  13400. return sync$1(pattern, options);
  13401. }
  13402. return new Glob(pattern, options, cb);
  13403. }
  13404. glob.sync = sync$1;
  13405. var GlobSync = glob.GlobSync = sync$1.GlobSync; // old api surface
  13406. glob.glob = glob;
  13407. function extend(origin, add) {
  13408. if (add === null || typeof add !== 'object') {
  13409. return origin;
  13410. }
  13411. var keys = Object.keys(add);
  13412. var i = keys.length;
  13413. while (i--) {
  13414. origin[keys[i]] = add[keys[i]];
  13415. }
  13416. return origin;
  13417. }
  13418. glob.hasMagic = function (pattern, options_) {
  13419. var options = extend({}, options_);
  13420. options.noprocess = true;
  13421. var g = new Glob(pattern, options);
  13422. var set = g.minimatch.set;
  13423. if (!pattern) return false;
  13424. if (set.length > 1) return true;
  13425. for (var j = 0; j < set[0].length; j++) {
  13426. if (typeof set[0][j] !== 'string') return true;
  13427. }
  13428. return false;
  13429. };
  13430. glob.Glob = Glob;
  13431. inherits(Glob, EE);
  13432. function Glob(pattern, options, cb) {
  13433. if (typeof options === 'function') {
  13434. cb = options;
  13435. options = null;
  13436. }
  13437. if (options && options.sync) {
  13438. if (cb) throw new TypeError('callback provided to sync glob');
  13439. return new GlobSync(pattern, options);
  13440. }
  13441. if (!(this instanceof Glob)) return new Glob(pattern, options, cb);
  13442. setopts(this, pattern, options);
  13443. this._didRealPath = false; // process each pattern in the minimatch set
  13444. var n = this.minimatch.set.length; // The matches are stored as {<filename>: true,...} so that
  13445. // duplicates are automagically pruned.
  13446. // Later, we do an Object.keys() on these.
  13447. // Keep them as a list so we can fill in when nonull is set.
  13448. this.matches = new Array(n);
  13449. if (typeof cb === 'function') {
  13450. cb = once_1(cb);
  13451. this.on('error', cb);
  13452. this.on('end', function (matches) {
  13453. cb(null, matches);
  13454. });
  13455. }
  13456. var self = this;
  13457. this._processing = 0;
  13458. this._emitQueue = [];
  13459. this._processQueue = [];
  13460. this.paused = false;
  13461. if (this.noprocess) return this;
  13462. if (n === 0) return done();
  13463. var sync = true;
  13464. for (var i = 0; i < n; i++) {
  13465. this._process(this.minimatch.set[i], i, false, done);
  13466. }
  13467. sync = false;
  13468. function done() {
  13469. --self._processing;
  13470. if (self._processing <= 0) {
  13471. if (sync) {
  13472. process.nextTick(function () {
  13473. self._finish();
  13474. });
  13475. } else {
  13476. self._finish();
  13477. }
  13478. }
  13479. }
  13480. }
  13481. Glob.prototype._finish = function () {
  13482. assert(this instanceof Glob);
  13483. if (this.aborted) return;
  13484. if (this.realpath && !this._didRealpath) return this._realpath();
  13485. common.finish(this);
  13486. this.emit('end', this.found);
  13487. };
  13488. Glob.prototype._realpath = function () {
  13489. if (this._didRealpath) return;
  13490. this._didRealpath = true;
  13491. var n = this.matches.length;
  13492. if (n === 0) return this._finish();
  13493. var self = this;
  13494. for (var i = 0; i < this.matches.length; i++) {
  13495. this._realpathSet(i, next);
  13496. }
  13497. function next() {
  13498. if (--n === 0) self._finish();
  13499. }
  13500. };
  13501. Glob.prototype._realpathSet = function (index, cb) {
  13502. var matchset = this.matches[index];
  13503. if (!matchset) return cb();
  13504. var found = Object.keys(matchset);
  13505. var self = this;
  13506. var n = found.length;
  13507. if (n === 0) return cb();
  13508. var set = this.matches[index] = Object.create(null);
  13509. found.forEach(function (p, i) {
  13510. // If there's a problem with the stat, then it means that
  13511. // one or more of the links in the realpath couldn't be
  13512. // resolved. just return the abs value in that case.
  13513. p = self._makeAbs(p);
  13514. fs_realpath.realpath(p, self.realpathCache, function (er, real) {
  13515. if (!er) set[real] = true;else if (er.syscall === 'stat') set[p] = true;else self.emit('error', er); // srsly wtf right here
  13516. if (--n === 0) {
  13517. self.matches[index] = set;
  13518. cb();
  13519. }
  13520. });
  13521. });
  13522. };
  13523. Glob.prototype._mark = function (p) {
  13524. return common.mark(this, p);
  13525. };
  13526. Glob.prototype._makeAbs = function (f) {
  13527. return common.makeAbs(this, f);
  13528. };
  13529. Glob.prototype.abort = function () {
  13530. this.aborted = true;
  13531. this.emit('abort');
  13532. };
  13533. Glob.prototype.pause = function () {
  13534. if (!this.paused) {
  13535. this.paused = true;
  13536. this.emit('pause');
  13537. }
  13538. };
  13539. Glob.prototype.resume = function () {
  13540. if (this.paused) {
  13541. this.emit('resume');
  13542. this.paused = false;
  13543. if (this._emitQueue.length) {
  13544. var eq = this._emitQueue.slice(0);
  13545. this._emitQueue.length = 0;
  13546. for (var i = 0; i < eq.length; i++) {
  13547. var e = eq[i];
  13548. this._emitMatch(e[0], e[1]);
  13549. }
  13550. }
  13551. if (this._processQueue.length) {
  13552. var pq = this._processQueue.slice(0);
  13553. this._processQueue.length = 0;
  13554. for (var i = 0; i < pq.length; i++) {
  13555. var p = pq[i];
  13556. this._processing--;
  13557. this._process(p[0], p[1], p[2], p[3]);
  13558. }
  13559. }
  13560. }
  13561. };
  13562. Glob.prototype._process = function (pattern, index, inGlobStar, cb) {
  13563. assert(this instanceof Glob);
  13564. assert(typeof cb === 'function');
  13565. if (this.aborted) return;
  13566. this._processing++;
  13567. if (this.paused) {
  13568. this._processQueue.push([pattern, index, inGlobStar, cb]);
  13569. return;
  13570. } //console.error('PROCESS %d', this._processing, pattern)
  13571. // Get the first [n] parts of pattern that are all strings.
  13572. var n = 0;
  13573. while (typeof pattern[n] === 'string') {
  13574. n++;
  13575. } // now n is the index of the first one that is *not* a string.
  13576. // see if there's anything else
  13577. var prefix;
  13578. switch (n) {
  13579. // if not, then this is rather simple
  13580. case pattern.length:
  13581. this._processSimple(pattern.join('/'), index, cb);
  13582. return;
  13583. case 0:
  13584. // pattern *starts* with some non-trivial item.
  13585. // going to readdir(cwd), but not include the prefix in matches.
  13586. prefix = null;
  13587. break;
  13588. default:
  13589. // pattern has some string bits in the front.
  13590. // whatever it starts with, whether that's 'absolute' like /foo/bar,
  13591. // or 'relative' like '../baz'
  13592. prefix = pattern.slice(0, n).join('/');
  13593. break;
  13594. }
  13595. var remain = pattern.slice(n); // get the list of entries.
  13596. var read;
  13597. if (prefix === null) read = '.';else if (pathIsAbsolute(prefix) || pathIsAbsolute(pattern.join('/'))) {
  13598. if (!prefix || !pathIsAbsolute(prefix)) prefix = '/' + prefix;
  13599. read = prefix;
  13600. } else read = prefix;
  13601. var abs = this._makeAbs(read); //if ignored, skip _processing
  13602. if (childrenIgnored(this, read)) return cb();
  13603. var isGlobStar = remain[0] === minimatch_1.GLOBSTAR;
  13604. if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb);else this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb);
  13605. };
  13606. Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  13607. var self = this;
  13608. this._readdir(abs, inGlobStar, function (er, entries) {
  13609. return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
  13610. });
  13611. };
  13612. Glob.prototype._processReaddir2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  13613. // if the abs isn't a dir, then nothing can match!
  13614. if (!entries) return cb(); // It will only match dot entries if it starts with a dot, or if
  13615. // dot is set. Stuff like @(.foo|.bar) isn't allowed.
  13616. var pn = remain[0];
  13617. var negate = !!this.minimatch.negate;
  13618. var rawGlob = pn._glob;
  13619. var dotOk = this.dot || rawGlob.charAt(0) === '.';
  13620. var matchedEntries = [];
  13621. for (var i = 0; i < entries.length; i++) {
  13622. var e = entries[i];
  13623. if (e.charAt(0) !== '.' || dotOk) {
  13624. var m;
  13625. if (negate && !prefix) {
  13626. m = !e.match(pn);
  13627. } else {
  13628. m = e.match(pn);
  13629. }
  13630. if (m) matchedEntries.push(e);
  13631. }
  13632. } //console.error('prd2', prefix, entries, remain[0]._glob, matchedEntries)
  13633. var len = matchedEntries.length; // If there are no matched entries, then nothing matches.
  13634. if (len === 0) return cb(); // if this is the last remaining pattern bit, then no need for
  13635. // an additional stat *unless* the user has specified mark or
  13636. // stat explicitly. We know they exist, since readdir returned
  13637. // them.
  13638. if (remain.length === 1 && !this.mark && !this.stat) {
  13639. if (!this.matches[index]) this.matches[index] = Object.create(null);
  13640. for (var i = 0; i < len; i++) {
  13641. var e = matchedEntries[i];
  13642. if (prefix) {
  13643. if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
  13644. }
  13645. if (e.charAt(0) === '/' && !this.nomount) {
  13646. e = path.join(this.root, e);
  13647. }
  13648. this._emitMatch(index, e);
  13649. } // This was the last one, and no stats were needed
  13650. return cb();
  13651. } // now test all matched entries as stand-ins for that part
  13652. // of the pattern.
  13653. remain.shift();
  13654. for (var i = 0; i < len; i++) {
  13655. var e = matchedEntries[i];
  13656. var newPattern;
  13657. if (prefix) {
  13658. if (prefix !== '/') e = prefix + '/' + e;else e = prefix + e;
  13659. }
  13660. this._process([e].concat(remain), index, inGlobStar, cb);
  13661. }
  13662. cb();
  13663. };
  13664. Glob.prototype._emitMatch = function (index, e) {
  13665. if (this.aborted) return;
  13666. if (isIgnored(this, e)) return;
  13667. if (this.paused) {
  13668. this._emitQueue.push([index, e]);
  13669. return;
  13670. }
  13671. var abs = pathIsAbsolute(e) ? e : this._makeAbs(e);
  13672. if (this.mark) e = this._mark(e);
  13673. if (this.absolute) e = abs;
  13674. if (this.matches[index][e]) return;
  13675. if (this.nodir) {
  13676. var c = this.cache[abs];
  13677. if (c === 'DIR' || Array.isArray(c)) return;
  13678. }
  13679. this.matches[index][e] = true;
  13680. var st = this.statCache[abs];
  13681. if (st) this.emit('stat', e, st);
  13682. this.emit('match', e);
  13683. };
  13684. Glob.prototype._readdirInGlobStar = function (abs, cb) {
  13685. if (this.aborted) return; // follow all symlinked directories forever
  13686. // just proceed as if this is a non-globstar situation
  13687. if (this.follow) return this._readdir(abs, false, cb);
  13688. var lstatkey = 'lstat\0' + abs;
  13689. var self = this;
  13690. var lstatcb = inflight_1(lstatkey, lstatcb_);
  13691. if (lstatcb) fs.lstat(abs, lstatcb);
  13692. function lstatcb_(er, lstat) {
  13693. if (er && er.code === 'ENOENT') return cb();
  13694. var isSym = lstat && lstat.isSymbolicLink();
  13695. self.symlinks[abs] = isSym; // If it's not a symlink or a dir, then it's definitely a regular file.
  13696. // don't bother doing a readdir in that case.
  13697. if (!isSym && lstat && !lstat.isDirectory()) {
  13698. self.cache[abs] = 'FILE';
  13699. cb();
  13700. } else self._readdir(abs, false, cb);
  13701. }
  13702. };
  13703. Glob.prototype._readdir = function (abs, inGlobStar, cb) {
  13704. if (this.aborted) return;
  13705. cb = inflight_1('readdir\0' + abs + '\0' + inGlobStar, cb);
  13706. if (!cb) return; //console.error('RD %j %j', +inGlobStar, abs)
  13707. if (inGlobStar && !ownProp(this.symlinks, abs)) return this._readdirInGlobStar(abs, cb);
  13708. if (ownProp(this.cache, abs)) {
  13709. var c = this.cache[abs];
  13710. if (!c || c === 'FILE') return cb();
  13711. if (Array.isArray(c)) return cb(null, c);
  13712. }
  13713. var self = this;
  13714. fs.readdir(abs, readdirCb(this, abs, cb));
  13715. };
  13716. function readdirCb(self, abs, cb) {
  13717. return function (er, entries) {
  13718. if (er) self._readdirError(abs, er, cb);else self._readdirEntries(abs, entries, cb);
  13719. };
  13720. }
  13721. Glob.prototype._readdirEntries = function (abs, entries, cb) {
  13722. if (this.aborted) return; // if we haven't asked to stat everything, then just
  13723. // assume that everything in there exists, so we can avoid
  13724. // having to stat it a second time.
  13725. if (!this.mark && !this.stat) {
  13726. for (var i = 0; i < entries.length; i++) {
  13727. var e = entries[i];
  13728. if (abs === '/') e = abs + e;else e = abs + '/' + e;
  13729. this.cache[e] = true;
  13730. }
  13731. }
  13732. this.cache[abs] = entries;
  13733. return cb(null, entries);
  13734. };
  13735. Glob.prototype._readdirError = function (f, er, cb) {
  13736. if (this.aborted) return; // handle errors, and cache the information
  13737. switch (er.code) {
  13738. case 'ENOTSUP': // https://github.com/isaacs/node-glob/issues/205
  13739. case 'ENOTDIR':
  13740. // totally normal. means it *does* exist.
  13741. var abs = this._makeAbs(f);
  13742. this.cache[abs] = 'FILE';
  13743. if (abs === this.cwdAbs) {
  13744. var error = new Error(er.code + ' invalid cwd ' + this.cwd);
  13745. error.path = this.cwd;
  13746. error.code = er.code;
  13747. this.emit('error', error);
  13748. this.abort();
  13749. }
  13750. break;
  13751. case 'ENOENT': // not terribly unusual
  13752. case 'ELOOP':
  13753. case 'ENAMETOOLONG':
  13754. case 'UNKNOWN':
  13755. this.cache[this._makeAbs(f)] = false;
  13756. break;
  13757. default:
  13758. // some unusual error. Treat as failure.
  13759. this.cache[this._makeAbs(f)] = false;
  13760. if (this.strict) {
  13761. this.emit('error', er); // If the error is handled, then we abort
  13762. // if not, we threw out of here
  13763. this.abort();
  13764. }
  13765. if (!this.silent) console.error('glob error', er);
  13766. break;
  13767. }
  13768. return cb();
  13769. };
  13770. Glob.prototype._processGlobStar = function (prefix, read, abs, remain, index, inGlobStar, cb) {
  13771. var self = this;
  13772. this._readdir(abs, inGlobStar, function (er, entries) {
  13773. self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
  13774. });
  13775. };
  13776. Glob.prototype._processGlobStar2 = function (prefix, read, abs, remain, index, inGlobStar, entries, cb) {
  13777. //console.error('pgs2', prefix, remain[0], entries)
  13778. // no entries means not a dir, so it can never have matches
  13779. // foo.txt/** doesn't match foo.txt
  13780. if (!entries) return cb(); // test without the globstar, and with every child both below
  13781. // and replacing the globstar.
  13782. var remainWithoutGlobStar = remain.slice(1);
  13783. var gspref = prefix ? [prefix] : [];
  13784. var noGlobStar = gspref.concat(remainWithoutGlobStar); // the noGlobStar pattern exits the inGlobStar state
  13785. this._process(noGlobStar, index, false, cb);
  13786. var isSym = this.symlinks[abs];
  13787. var len = entries.length; // If it's a symlink, and we're in a globstar, then stop
  13788. if (isSym && inGlobStar) return cb();
  13789. for (var i = 0; i < len; i++) {
  13790. var e = entries[i];
  13791. if (e.charAt(0) === '.' && !this.dot) continue; // these two cases enter the inGlobStar state
  13792. var instead = gspref.concat(entries[i], remainWithoutGlobStar);
  13793. this._process(instead, index, true, cb);
  13794. var below = gspref.concat(entries[i], remain);
  13795. this._process(below, index, true, cb);
  13796. }
  13797. cb();
  13798. };
  13799. Glob.prototype._processSimple = function (prefix, index, cb) {
  13800. // XXX review this. Shouldn't it be doing the mounting etc
  13801. // before doing stat? kinda weird?
  13802. var self = this;
  13803. this._stat(prefix, function (er, exists) {
  13804. self._processSimple2(prefix, index, er, exists, cb);
  13805. });
  13806. };
  13807. Glob.prototype._processSimple2 = function (prefix, index, er, exists, cb) {
  13808. //console.error('ps2', prefix, exists)
  13809. if (!this.matches[index]) this.matches[index] = Object.create(null); // If it doesn't exist, then just mark the lack of results
  13810. if (!exists) return cb();
  13811. if (prefix && pathIsAbsolute(prefix) && !this.nomount) {
  13812. var trail = /[\/\\]$/.test(prefix);
  13813. if (prefix.charAt(0) === '/') {
  13814. prefix = path.join(this.root, prefix);
  13815. } else {
  13816. prefix = path.resolve(this.root, prefix);
  13817. if (trail) prefix += '/';
  13818. }
  13819. }
  13820. if (process.platform === 'win32') prefix = prefix.replace(/\\/g, '/'); // Mark this as a match
  13821. this._emitMatch(index, prefix);
  13822. cb();
  13823. }; // Returns either 'DIR', 'FILE', or false
  13824. Glob.prototype._stat = function (f, cb) {
  13825. var abs = this._makeAbs(f);
  13826. var needDir = f.slice(-1) === '/';
  13827. if (f.length > this.maxLength) return cb();
  13828. if (!this.stat && ownProp(this.cache, abs)) {
  13829. var c = this.cache[abs];
  13830. if (Array.isArray(c)) c = 'DIR'; // It exists, but maybe not how we need it
  13831. if (!needDir || c === 'DIR') return cb(null, c);
  13832. if (needDir && c === 'FILE') return cb(); // otherwise we have to stat, because maybe c=true
  13833. // if we know it exists, but not what it is.
  13834. }
  13835. var exists;
  13836. var stat = this.statCache[abs];
  13837. if (stat !== undefined) {
  13838. if (stat === false) return cb(null, stat);else {
  13839. var type = stat.isDirectory() ? 'DIR' : 'FILE';
  13840. if (needDir && type === 'FILE') return cb();else return cb(null, type, stat);
  13841. }
  13842. }
  13843. var self = this;
  13844. var statcb = inflight_1('stat\0' + abs, lstatcb_);
  13845. if (statcb) fs.lstat(abs, statcb);
  13846. function lstatcb_(er, lstat) {
  13847. if (lstat && lstat.isSymbolicLink()) {
  13848. // If it's a symlink, then treat it as the target, unless
  13849. // the target does not exist, then treat it as a file.
  13850. return fs.stat(abs, function (er, stat) {
  13851. if (er) self._stat2(f, abs, null, lstat, cb);else self._stat2(f, abs, er, stat, cb);
  13852. });
  13853. } else {
  13854. self._stat2(f, abs, er, lstat, cb);
  13855. }
  13856. }
  13857. };
  13858. Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
  13859. if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
  13860. this.statCache[abs] = false;
  13861. return cb();
  13862. }
  13863. var needDir = f.slice(-1) === '/';
  13864. this.statCache[abs] = stat;
  13865. if (abs.slice(-1) === '/' && stat && !stat.isDirectory()) return cb(null, false, stat);
  13866. var c = true;
  13867. if (stat) c = stat.isDirectory() ? 'DIR' : 'FILE';
  13868. this.cache[abs] = this.cache[abs] || c;
  13869. if (needDir && c === 'FILE') return cb();
  13870. return cb(null, c, stat);
  13871. };
  13872. var pify_1 = createCommonjsModule(function (module) {
  13873. 'use strict';
  13874. var processFn = function processFn(fn, P, opts) {
  13875. return function () {
  13876. var that = this;
  13877. var args = new Array(arguments.length);
  13878. for (var i = 0; i < arguments.length; i++) {
  13879. args[i] = arguments[i];
  13880. }
  13881. return new P(function (resolve, reject) {
  13882. args.push(function (err, result) {
  13883. if (err) {
  13884. reject(err);
  13885. } else if (opts.multiArgs) {
  13886. var results = new Array(arguments.length - 1);
  13887. for (var i = 1; i < arguments.length; i++) {
  13888. results[i - 1] = arguments[i];
  13889. }
  13890. resolve(results);
  13891. } else {
  13892. resolve(result);
  13893. }
  13894. });
  13895. fn.apply(that, args);
  13896. });
  13897. };
  13898. };
  13899. var pify = module.exports = function (obj, P, opts) {
  13900. if (typeof P !== 'function') {
  13901. opts = P;
  13902. P = Promise;
  13903. }
  13904. opts = opts || {};
  13905. opts.exclude = opts.exclude || [/.+Sync$/];
  13906. var filter = function filter(key) {
  13907. var match = function match(pattern) {
  13908. return typeof pattern === 'string' ? key === pattern : pattern.test(key);
  13909. };
  13910. return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
  13911. };
  13912. var ret = typeof obj === 'function' ? function () {
  13913. if (opts.excludeMain) {
  13914. return obj.apply(this, arguments);
  13915. }
  13916. return processFn(obj, P, opts).apply(this, arguments);
  13917. } : {};
  13918. return Object.keys(obj).reduce(function (ret, key) {
  13919. var x = obj[key];
  13920. ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x;
  13921. return ret;
  13922. }, ret);
  13923. };
  13924. pify.all = pify;
  13925. });
  13926. var globP = pify_1(glob_1, pinkiePromise).bind(glob_1);
  13927. function isNegative(pattern) {
  13928. return pattern[0] === '!';
  13929. }
  13930. function isString(value) {
  13931. return typeof value === 'string';
  13932. }
  13933. function assertPatternsInput(patterns) {
  13934. if (!patterns.every(isString)) {
  13935. throw new TypeError('patterns must be a string or an array of strings');
  13936. }
  13937. }
  13938. function generateGlobTasks(patterns, opts) {
  13939. patterns = [].concat(patterns);
  13940. assertPatternsInput(patterns);
  13941. var globTasks = [];
  13942. opts = objectAssign({
  13943. cache: Object.create(null),
  13944. statCache: Object.create(null),
  13945. realpathCache: Object.create(null),
  13946. symlinks: Object.create(null),
  13947. ignore: []
  13948. }, opts);
  13949. patterns.forEach(function (pattern, i) {
  13950. if (isNegative(pattern)) {
  13951. return;
  13952. }
  13953. var ignore = patterns.slice(i).filter(isNegative).map(function (pattern) {
  13954. return pattern.slice(1);
  13955. });
  13956. globTasks.push({
  13957. pattern: pattern,
  13958. opts: objectAssign({}, opts, {
  13959. ignore: opts.ignore.concat(ignore)
  13960. })
  13961. });
  13962. });
  13963. return globTasks;
  13964. }
  13965. var globby = function globby(patterns, opts) {
  13966. var globTasks;
  13967. try {
  13968. globTasks = generateGlobTasks(patterns, opts);
  13969. } catch (err) {
  13970. return pinkiePromise.reject(err);
  13971. }
  13972. return pinkiePromise.all(globTasks.map(function (task) {
  13973. return globP(task.pattern, task.opts);
  13974. })).then(function (paths) {
  13975. return arrayUnion.apply(null, paths);
  13976. });
  13977. };
  13978. var sync = function sync(patterns, opts) {
  13979. var globTasks = generateGlobTasks(patterns, opts);
  13980. return globTasks.reduce(function (matches, task) {
  13981. return arrayUnion(matches, glob_1.sync(task.pattern, task.opts));
  13982. }, []);
  13983. };
  13984. var generateGlobTasks_1 = generateGlobTasks;
  13985. var hasMagic = function hasMagic(patterns, opts) {
  13986. return [].concat(patterns).some(function (pattern) {
  13987. return glob_1.hasMagic(pattern, opts);
  13988. });
  13989. };
  13990. globby.sync = sync;
  13991. globby.generateGlobTasks = generateGlobTasks_1;
  13992. globby.hasMagic = hasMagic;
  13993. var assert$2 = true;
  13994. var buffer_ieee754 = "< 0.9.7";
  13995. var buffer = true;
  13996. var child_process = true;
  13997. var cluster = true;
  13998. var console$1 = true;
  13999. var constants = true;
  14000. var crypto = true;
  14001. var _debugger = "< 8";
  14002. var dgram = true;
  14003. var dns = true;
  14004. var domain = true;
  14005. var events$1 = true;
  14006. var freelist = "< 6";
  14007. var fs$2 = true;
  14008. var http = true;
  14009. var http2 = ">= 8.8";
  14010. var https = true;
  14011. var _http_server = ">= 0.11";
  14012. var _linklist = "< 8";
  14013. var module$1 = true;
  14014. var net = true;
  14015. var os$2 = true;
  14016. var path$3 = true;
  14017. var perf_hooks = ">= 8.5";
  14018. var process$1 = ">= 1";
  14019. var punycode = true;
  14020. var querystring = true;
  14021. var readline$1 = true;
  14022. var repl = true;
  14023. var stream = true;
  14024. var string_decoder = true;
  14025. var sys = true;
  14026. var timers = true;
  14027. var tls = true;
  14028. var tty = true;
  14029. var url = true;
  14030. var util$4 = true;
  14031. var v8 = ">= 1";
  14032. var vm = true;
  14033. var zlib = true;
  14034. var core$3 = {
  14035. assert: assert$2,
  14036. buffer_ieee754: buffer_ieee754,
  14037. buffer: buffer,
  14038. child_process: child_process,
  14039. cluster: cluster,
  14040. console: console$1,
  14041. constants: constants,
  14042. crypto: crypto,
  14043. _debugger: _debugger,
  14044. dgram: dgram,
  14045. dns: dns,
  14046. domain: domain,
  14047. events: events$1,
  14048. freelist: freelist,
  14049. fs: fs$2,
  14050. http: http,
  14051. http2: http2,
  14052. https: https,
  14053. _http_server: _http_server,
  14054. _linklist: _linklist,
  14055. module: module$1,
  14056. net: net,
  14057. os: os$2,
  14058. path: path$3,
  14059. perf_hooks: perf_hooks,
  14060. process: process$1,
  14061. punycode: punycode,
  14062. querystring: querystring,
  14063. readline: readline$1,
  14064. repl: repl,
  14065. stream: stream,
  14066. string_decoder: string_decoder,
  14067. sys: sys,
  14068. timers: timers,
  14069. tls: tls,
  14070. tty: tty,
  14071. url: url,
  14072. util: util$4,
  14073. v8: v8,
  14074. vm: vm,
  14075. zlib: zlib
  14076. };
  14077. var core$4 = Object.freeze({
  14078. assert: assert$2,
  14079. buffer_ieee754: buffer_ieee754,
  14080. buffer: buffer,
  14081. child_process: child_process,
  14082. cluster: cluster,
  14083. console: console$1,
  14084. constants: constants,
  14085. crypto: crypto,
  14086. _debugger: _debugger,
  14087. dgram: dgram,
  14088. dns: dns,
  14089. domain: domain,
  14090. events: events$1,
  14091. freelist: freelist,
  14092. fs: fs$2,
  14093. http: http,
  14094. http2: http2,
  14095. https: https,
  14096. _http_server: _http_server,
  14097. _linklist: _linklist,
  14098. module: module$1,
  14099. net: net,
  14100. os: os$2,
  14101. path: path$3,
  14102. perf_hooks: perf_hooks,
  14103. process: process$1,
  14104. punycode: punycode,
  14105. querystring: querystring,
  14106. readline: readline$1,
  14107. repl: repl,
  14108. stream: stream,
  14109. string_decoder: string_decoder,
  14110. sys: sys,
  14111. timers: timers,
  14112. tls: tls,
  14113. tty: tty,
  14114. url: url,
  14115. util: util$4,
  14116. v8: v8,
  14117. vm: vm,
  14118. zlib: zlib,
  14119. default: core$3
  14120. });
  14121. var data = ( core$4 && core$3 ) || core$4;
  14122. var current = process.versions && process.versions.node && process.versions.node.split('.') || [];
  14123. function versionIncluded(specifier) {
  14124. if (specifier === true) {
  14125. return true;
  14126. }
  14127. var parts = specifier.split(' ');
  14128. var op = parts[0];
  14129. var versionParts = parts[1].split('.');
  14130. for (var i = 0; i < 3; ++i) {
  14131. var cur = Number(current[i] || 0);
  14132. var ver = Number(versionParts[i] || 0);
  14133. if (cur === ver) {
  14134. continue; // eslint-disable-line no-restricted-syntax, no-continue
  14135. }
  14136. if (op === '<') {
  14137. return cur < ver;
  14138. } else if (op === '>=') {
  14139. return cur >= ver;
  14140. } else {
  14141. return false;
  14142. }
  14143. }
  14144. return false;
  14145. }
  14146. var core$2 = {};
  14147. for (var mod in data) {
  14148. // eslint-disable-line no-restricted-syntax
  14149. if (Object.prototype.hasOwnProperty.call(data, mod)) {
  14150. core$2[mod] = versionIncluded(data[mod]);
  14151. }
  14152. }
  14153. var core_1 = core$2;
  14154. var caller = function caller() {
  14155. // see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
  14156. var origPrepareStackTrace = Error.prepareStackTrace;
  14157. Error.prepareStackTrace = function (_, stack) {
  14158. return stack;
  14159. };
  14160. var stack = new Error().stack;
  14161. Error.prepareStackTrace = origPrepareStackTrace;
  14162. return stack[2].getFileName();
  14163. };
  14164. var pathParse = createCommonjsModule(function (module) {
  14165. 'use strict';
  14166. var isWindows = process.platform === 'win32'; // Regex to split a windows path into three parts: [*, device, slash,
  14167. // tail] windows-only
  14168. var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/; // Regex to split the tail part of the above into [*, dir, basename, ext]
  14169. var splitTailRe = /^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/;
  14170. var win32 = {}; // Function to split a filename into [root, dir, basename, ext]
  14171. function win32SplitPath(filename) {
  14172. // Separate device+slash from tail
  14173. var result = splitDeviceRe.exec(filename),
  14174. device = (result[1] || '') + (result[2] || ''),
  14175. tail = result[3] || ''; // Split the tail into dir, basename and extension
  14176. var result2 = splitTailRe.exec(tail),
  14177. dir = result2[1],
  14178. basename = result2[2],
  14179. ext = result2[3];
  14180. return [device, dir, basename, ext];
  14181. }
  14182. win32.parse = function (pathString) {
  14183. if (typeof pathString !== 'string') {
  14184. throw new TypeError("Parameter 'pathString' must be a string, not " + typeof pathString);
  14185. }
  14186. var allParts = win32SplitPath(pathString);
  14187. if (!allParts || allParts.length !== 4) {
  14188. throw new TypeError("Invalid path '" + pathString + "'");
  14189. }
  14190. return {
  14191. root: allParts[0],
  14192. dir: allParts[0] + allParts[1].slice(0, -1),
  14193. base: allParts[2],
  14194. ext: allParts[3],
  14195. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  14196. };
  14197. }; // Split a filename into [root, dir, basename, ext], unix version
  14198. // 'root' is just a slash, or nothing.
  14199. var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
  14200. var posix = {};
  14201. function posixSplitPath(filename) {
  14202. return splitPathRe.exec(filename).slice(1);
  14203. }
  14204. posix.parse = function (pathString) {
  14205. if (typeof pathString !== 'string') {
  14206. throw new TypeError("Parameter 'pathString' must be a string, not " + typeof pathString);
  14207. }
  14208. var allParts = posixSplitPath(pathString);
  14209. if (!allParts || allParts.length !== 4) {
  14210. throw new TypeError("Invalid path '" + pathString + "'");
  14211. }
  14212. allParts[1] = allParts[1] || '';
  14213. allParts[2] = allParts[2] || '';
  14214. allParts[3] = allParts[3] || '';
  14215. return {
  14216. root: allParts[0],
  14217. dir: allParts[0] + allParts[1].slice(0, -1),
  14218. base: allParts[2],
  14219. ext: allParts[3],
  14220. name: allParts[2].slice(0, allParts[2].length - allParts[3].length)
  14221. };
  14222. };
  14223. if (isWindows) module.exports = win32.parse;else
  14224. /* posix */
  14225. module.exports = posix.parse;
  14226. module.exports.posix = posix.parse;
  14227. module.exports.win32 = win32.parse;
  14228. });
  14229. var parse$4 = path.parse || pathParse;
  14230. var nodeModulesPaths = function nodeModulesPaths(start, opts) {
  14231. var modules = opts && opts.moduleDirectory ? [].concat(opts.moduleDirectory) : ['node_modules']; // ensure that `start` is an absolute path at this point,
  14232. // resolving against the process' current working directory
  14233. var absoluteStart = path.resolve(start);
  14234. if (opts && opts.preserveSymlinks === false) {
  14235. try {
  14236. absoluteStart = fs.realpathSync(absoluteStart);
  14237. } catch (err) {
  14238. if (err.code !== 'ENOENT') {
  14239. throw err;
  14240. }
  14241. }
  14242. }
  14243. var prefix = '/';
  14244. if (/^([A-Za-z]:)/.test(absoluteStart)) {
  14245. prefix = '';
  14246. } else if (/^\\\\/.test(absoluteStart)) {
  14247. prefix = '\\\\';
  14248. }
  14249. var paths = [absoluteStart];
  14250. var parsed = parse$4(absoluteStart);
  14251. while (parsed.dir !== paths[paths.length - 1]) {
  14252. paths.push(parsed.dir);
  14253. parsed = parse$4(parsed.dir);
  14254. }
  14255. var dirs = paths.reduce(function (dirs, aPath) {
  14256. return dirs.concat(modules.map(function (moduleDir) {
  14257. return path.join(prefix, aPath, moduleDir);
  14258. }));
  14259. }, []);
  14260. return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
  14261. };
  14262. var async = function resolve(x, options, callback) {
  14263. var cb = callback;
  14264. var opts = options || {};
  14265. if (typeof opts === 'function') {
  14266. cb = opts;
  14267. opts = {};
  14268. }
  14269. if (typeof x !== 'string') {
  14270. var err = new TypeError('Path must be a string.');
  14271. return process.nextTick(function () {
  14272. cb(err);
  14273. });
  14274. }
  14275. var isFile = opts.isFile || function (file, cb) {
  14276. fs.stat(file, function (err, stat) {
  14277. if (!err) {
  14278. return cb(null, stat.isFile() || stat.isFIFO());
  14279. }
  14280. if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
  14281. return cb(err);
  14282. });
  14283. };
  14284. var readFile = opts.readFile || fs.readFile;
  14285. var extensions = opts.extensions || ['.js'];
  14286. var y = opts.basedir || path.dirname(caller());
  14287. opts.paths = opts.paths || [];
  14288. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  14289. var res = path.resolve(y, x);
  14290. if (x === '..' || x.slice(-1) === '/') res += '/';
  14291. if (/\/$/.test(x) && res === y) {
  14292. loadAsDirectory(res, opts.package, onfile);
  14293. } else loadAsFile(res, opts.package, onfile);
  14294. } else loadNodeModules(x, y, function (err, n, pkg) {
  14295. if (err) cb(err);else if (n) cb(null, n, pkg);else if (core_1[x]) return cb(null, x);else {
  14296. var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
  14297. moduleError.code = 'MODULE_NOT_FOUND';
  14298. cb(moduleError);
  14299. }
  14300. });
  14301. function onfile(err, m, pkg) {
  14302. if (err) cb(err);else if (m) cb(null, m, pkg);else loadAsDirectory(res, function (err, d, pkg) {
  14303. if (err) cb(err);else if (d) cb(null, d, pkg);else {
  14304. var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
  14305. moduleError.code = 'MODULE_NOT_FOUND';
  14306. cb(moduleError);
  14307. }
  14308. });
  14309. }
  14310. function loadAsFile(x, thePackage, callback) {
  14311. var loadAsFilePackage = thePackage;
  14312. var cb = callback;
  14313. if (typeof loadAsFilePackage === 'function') {
  14314. cb = loadAsFilePackage;
  14315. loadAsFilePackage = undefined;
  14316. }
  14317. var exts = [''].concat(extensions);
  14318. load(exts, x, loadAsFilePackage);
  14319. function load(exts, x, loadPackage) {
  14320. if (exts.length === 0) return cb(null, undefined, loadPackage);
  14321. var file = x + exts[0];
  14322. var pkg = loadPackage;
  14323. if (pkg) onpkg(null, pkg);else loadpkg(path.dirname(file), onpkg);
  14324. function onpkg(err, pkg_, dir) {
  14325. pkg = pkg_;
  14326. if (err) return cb(err);
  14327. if (dir && pkg && opts.pathFilter) {
  14328. var rfile = path.relative(dir, file);
  14329. var rel = rfile.slice(0, rfile.length - exts[0].length);
  14330. var r = opts.pathFilter(pkg, x, rel);
  14331. if (r) return load([''].concat(extensions.slice()), path.resolve(dir, r), pkg);
  14332. }
  14333. isFile(file, onex);
  14334. }
  14335. function onex(err, ex) {
  14336. if (err) return cb(err);
  14337. if (ex) return cb(null, file, pkg);
  14338. load(exts.slice(1), x, pkg);
  14339. }
  14340. }
  14341. }
  14342. function loadpkg(dir, cb) {
  14343. if (dir === '' || dir === '/') return cb(null);
  14344. if (process.platform === 'win32' && /^\w:[/\\]*$/.test(dir)) {
  14345. return cb(null);
  14346. }
  14347. if (/[/\\]node_modules[/\\]*$/.test(dir)) return cb(null);
  14348. var pkgfile = path.join(dir, 'package.json');
  14349. isFile(pkgfile, function (err, ex) {
  14350. // on err, ex is false
  14351. if (!ex) return loadpkg(path.dirname(dir), cb);
  14352. readFile(pkgfile, function (err, body) {
  14353. if (err) cb(err);
  14354. try {
  14355. var pkg = JSON.parse(body);
  14356. } catch (jsonErr) {}
  14357. if (pkg && opts.packageFilter) {
  14358. pkg = opts.packageFilter(pkg, pkgfile);
  14359. }
  14360. cb(null, pkg, dir);
  14361. });
  14362. });
  14363. }
  14364. function loadAsDirectory(x, loadAsDirectoryPackage, callback) {
  14365. var cb = callback;
  14366. var fpkg = loadAsDirectoryPackage;
  14367. if (typeof fpkg === 'function') {
  14368. cb = fpkg;
  14369. fpkg = opts.package;
  14370. }
  14371. var pkgfile = path.join(x, 'package.json');
  14372. isFile(pkgfile, function (err, ex) {
  14373. if (err) return cb(err);
  14374. if (!ex) return loadAsFile(path.join(x, 'index'), fpkg, cb);
  14375. readFile(pkgfile, function (err, body) {
  14376. if (err) return cb(err);
  14377. try {
  14378. var pkg = JSON.parse(body);
  14379. } catch (jsonErr) {}
  14380. if (opts.packageFilter) {
  14381. pkg = opts.packageFilter(pkg, pkgfile);
  14382. }
  14383. if (pkg.main) {
  14384. if (pkg.main === '.' || pkg.main === './') {
  14385. pkg.main = 'index';
  14386. }
  14387. loadAsFile(path.resolve(x, pkg.main), pkg, function (err, m, pkg) {
  14388. if (err) return cb(err);
  14389. if (m) return cb(null, m, pkg);
  14390. if (!pkg) return loadAsFile(path.join(x, 'index'), pkg, cb);
  14391. var dir = path.resolve(x, pkg.main);
  14392. loadAsDirectory(dir, pkg, function (err, n, pkg) {
  14393. if (err) return cb(err);
  14394. if (n) return cb(null, n, pkg);
  14395. loadAsFile(path.join(x, 'index'), pkg, cb);
  14396. });
  14397. });
  14398. return;
  14399. }
  14400. loadAsFile(path.join(x, '/index'), pkg, cb);
  14401. });
  14402. });
  14403. }
  14404. function processDirs(cb, dirs) {
  14405. if (dirs.length === 0) return cb(null, undefined);
  14406. var dir = dirs[0];
  14407. var file = path.join(dir, x);
  14408. loadAsFile(file, undefined, onfile);
  14409. function onfile(err, m, pkg) {
  14410. if (err) return cb(err);
  14411. if (m) return cb(null, m, pkg);
  14412. loadAsDirectory(path.join(dir, x), undefined, ondir);
  14413. }
  14414. function ondir(err, n, pkg) {
  14415. if (err) return cb(err);
  14416. if (n) return cb(null, n, pkg);
  14417. processDirs(cb, dirs.slice(1));
  14418. }
  14419. }
  14420. function loadNodeModules(x, start, cb) {
  14421. processDirs(cb, nodeModulesPaths(start, opts));
  14422. }
  14423. };
  14424. var sync$3 = function sync(x, options) {
  14425. if (typeof x !== 'string') {
  14426. throw new TypeError('Path must be a string.');
  14427. }
  14428. var opts = options || {};
  14429. var isFile = opts.isFile || function (file) {
  14430. try {
  14431. var stat = fs.statSync(file);
  14432. } catch (e) {
  14433. if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
  14434. throw e;
  14435. }
  14436. return stat.isFile() || stat.isFIFO();
  14437. };
  14438. var readFileSync = opts.readFileSync || fs.readFileSync;
  14439. var extensions = opts.extensions || ['.js'];
  14440. var y = opts.basedir || path.dirname(caller());
  14441. opts.paths = opts.paths || [];
  14442. if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
  14443. var res = path.resolve(y, x);
  14444. if (x === '..' || x.slice(-1) === '/') res += '/';
  14445. var m = loadAsFileSync(res) || loadAsDirectorySync(res);
  14446. if (m) return m;
  14447. } else {
  14448. var n = loadNodeModulesSync(x, y);
  14449. if (n) return n;
  14450. }
  14451. if (core_1[x]) return x;
  14452. var err = new Error("Cannot find module '" + x + "' from '" + y + "'");
  14453. err.code = 'MODULE_NOT_FOUND';
  14454. throw err;
  14455. function loadAsFileSync(x) {
  14456. if (isFile(x)) {
  14457. return x;
  14458. }
  14459. for (var i = 0; i < extensions.length; i++) {
  14460. var file = x + extensions[i];
  14461. if (isFile(file)) {
  14462. return file;
  14463. }
  14464. }
  14465. }
  14466. function loadAsDirectorySync(x) {
  14467. var pkgfile = path.join(x, '/package.json');
  14468. if (isFile(pkgfile)) {
  14469. try {
  14470. var body = readFileSync(pkgfile, 'UTF8');
  14471. var pkg = JSON.parse(body);
  14472. if (opts.packageFilter) {
  14473. pkg = opts.packageFilter(pkg, x);
  14474. }
  14475. if (pkg.main) {
  14476. if (pkg.main === '.' || pkg.main === './') {
  14477. pkg.main = 'index';
  14478. }
  14479. var m = loadAsFileSync(path.resolve(x, pkg.main));
  14480. if (m) return m;
  14481. var n = loadAsDirectorySync(path.resolve(x, pkg.main));
  14482. if (n) return n;
  14483. }
  14484. } catch (e) {}
  14485. }
  14486. return loadAsFileSync(path.join(x, '/index'));
  14487. }
  14488. function loadNodeModulesSync(x, start) {
  14489. var dirs = nodeModulesPaths(start, opts);
  14490. for (var i = 0; i < dirs.length; i++) {
  14491. var dir = dirs[i];
  14492. var m = loadAsFileSync(path.join(dir, '/', x));
  14493. if (m) return m;
  14494. var n = loadAsDirectorySync(path.join(dir, '/', x));
  14495. if (n) return n;
  14496. }
  14497. }
  14498. };
  14499. var resolve$1 = createCommonjsModule(function (module, exports) {
  14500. async.core = core_1;
  14501. async.isCore = function isCore(x) {
  14502. return core_1[x];
  14503. };
  14504. async.sync = sync$3;
  14505. exports = async;
  14506. module.exports = async;
  14507. });
  14508. var _require$$0$builders$1 = doc.builders;
  14509. var indent$3 = _require$$0$builders$1.indent;
  14510. var join$3 = _require$$0$builders$1.join;
  14511. var hardline$4 = _require$$0$builders$1.hardline;
  14512. var softline$2 = _require$$0$builders$1.softline;
  14513. var literalline$2 = _require$$0$builders$1.literalline;
  14514. var concat$5 = _require$$0$builders$1.concat;
  14515. var dedentToRoot$1 = _require$$0$builders$1.dedentToRoot;
  14516. var _require$$0$utils = doc.utils;
  14517. var mapDoc$2 = _require$$0$utils.mapDoc;
  14518. var stripTrailingHardline$1 = _require$$0$utils.stripTrailingHardline;
  14519. function embed(path$$1, print, textToDoc
  14520. /*, options */
  14521. ) {
  14522. var node = path$$1.getValue();
  14523. var parent = path$$1.getParentNode();
  14524. var parentParent = path$$1.getParentNode(1);
  14525. switch (node.type) {
  14526. case "TemplateLiteral":
  14527. {
  14528. var isCss = [isStyledJsx, isStyledComponents, isCssProp, isAngularComponentStyles].some(function (isIt) {
  14529. return isIt(path$$1);
  14530. });
  14531. if (isCss) {
  14532. // Get full template literal with expressions replaced by placeholders
  14533. var rawQuasis = node.quasis.map(function (q) {
  14534. return q.value.raw;
  14535. });
  14536. var placeholderID = 0;
  14537. var text = rawQuasis.reduce(function (prevVal, currVal, idx) {
  14538. return idx == 0 ? currVal : prevVal + "@prettier-placeholder-" + placeholderID++ + "-id" + currVal;
  14539. }, "");
  14540. var doc$$2 = textToDoc(text, {
  14541. parser: "css"
  14542. });
  14543. return transformCssDoc(doc$$2, path$$1, print);
  14544. }
  14545. /*
  14546. * react-relay and graphql-tag
  14547. * graphql`...`
  14548. * graphql.experimental`...`
  14549. * gql`...`
  14550. *
  14551. * This intentionally excludes Relay Classic tags, as Prettier does not
  14552. * support Relay Classic formatting.
  14553. */
  14554. if (isGraphQL(path$$1)) {
  14555. var expressionDocs = node.expressions ? path$$1.map(print, "expressions") : [];
  14556. var numQuasis = node.quasis.length;
  14557. if (numQuasis === 1 && node.quasis[0].value.raw.trim() === "") {
  14558. return "``";
  14559. }
  14560. var parts = [];
  14561. for (var i = 0; i < numQuasis; i++) {
  14562. var templateElement = node.quasis[i];
  14563. var isFirst = i === 0;
  14564. var isLast = i === numQuasis - 1;
  14565. var _text = templateElement.value.cooked; // Bail out if any of the quasis have an invalid escape sequence
  14566. // (which would make the `cooked` value be `null` or `undefined`)
  14567. if (typeof _text !== "string") {
  14568. return null;
  14569. }
  14570. var lines = _text.split("\n");
  14571. var numLines = lines.length;
  14572. var expressionDoc = expressionDocs[i];
  14573. var startsWithBlankLine = numLines > 2 && lines[0].trim() === "" && lines[1].trim() === "";
  14574. var endsWithBlankLine = numLines > 2 && lines[numLines - 1].trim() === "" && lines[numLines - 2].trim() === "";
  14575. var commentsAndWhitespaceOnly = lines.every(function (line) {
  14576. return /^\s*(?:#[^\r\n]*)?$/.test(line);
  14577. }); // Bail out if an interpolation occurs within a comment.
  14578. if (!isLast && /#[^\r\n]*$/.test(lines[numLines - 1])) {
  14579. return null;
  14580. }
  14581. var _doc = null;
  14582. if (commentsAndWhitespaceOnly) {
  14583. _doc = printGraphqlComments(lines);
  14584. } else {
  14585. _doc = stripTrailingHardline$1(textToDoc(_text, {
  14586. parser: "graphql"
  14587. }));
  14588. }
  14589. if (_doc) {
  14590. _doc = escapeBackticks(_doc);
  14591. if (!isFirst && startsWithBlankLine) {
  14592. parts.push("");
  14593. }
  14594. parts.push(_doc);
  14595. if (!isLast && endsWithBlankLine) {
  14596. parts.push("");
  14597. }
  14598. } else if (!isFirst && !isLast && startsWithBlankLine) {
  14599. parts.push("");
  14600. }
  14601. if (expressionDoc) {
  14602. parts.push(concat$5(["${", expressionDoc, "}"]));
  14603. }
  14604. }
  14605. return concat$5(["`", indent$3(concat$5([hardline$4, join$3(hardline$4, parts)])), hardline$4, "`"]);
  14606. }
  14607. break;
  14608. }
  14609. case "TemplateElement":
  14610. {
  14611. /**
  14612. * md`...`
  14613. * markdown`...`
  14614. */
  14615. if (parentParent && parentParent.type === "TaggedTemplateExpression" && parent.quasis.length === 1 && parentParent.tag.type === "Identifier" && (parentParent.tag.name === "md" || parentParent.tag.name === "markdown")) {
  14616. var _text2 = parent.quasis[0].value.raw.replace(/((?:\\\\)*)\\`/g, function (_, backslashes) {
  14617. return "\\".repeat(backslashes.length / 2) + "`";
  14618. });
  14619. var indentation = getIndentation(_text2);
  14620. var hasIndent = indentation !== "";
  14621. return concat$5([hasIndent ? indent$3(concat$5([softline$2, printMarkdown(_text2.replace(new RegExp(`^${indentation}`, "gm"), ""))])) : concat$5([literalline$2, dedentToRoot$1(printMarkdown(_text2))]), softline$2]);
  14622. }
  14623. break;
  14624. }
  14625. }
  14626. function printMarkdown(text) {
  14627. var doc$$2 = textToDoc(text, {
  14628. parser: "markdown",
  14629. __inJsTemplate: true
  14630. });
  14631. return stripTrailingHardline$1(escapeBackticks(doc$$2));
  14632. }
  14633. }
  14634. function isPropertyWithinAngularComponentDecorator(path$$1, parentIndexToCheck) {
  14635. var parent = path$$1.getParentNode(parentIndexToCheck);
  14636. return !!(parent && parent.type === "Decorator" && parent.expression && parent.expression.type === "CallExpression" && parent.expression.callee && parent.expression.callee.name === "Component");
  14637. }
  14638. function getIndentation(str) {
  14639. var firstMatchedIndent = str.match(/^([^\S\n]*)\S/m);
  14640. return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
  14641. }
  14642. function escapeBackticks(doc$$2) {
  14643. return mapDoc$2(doc$$2, function (currentDoc) {
  14644. if (!currentDoc.parts) {
  14645. return currentDoc;
  14646. }
  14647. var parts = [];
  14648. currentDoc.parts.forEach(function (part) {
  14649. if (typeof part === "string") {
  14650. parts.push(part.replace(/(\\*)`/g, "$1$1\\`"));
  14651. } else {
  14652. parts.push(part);
  14653. }
  14654. });
  14655. return Object.assign({}, currentDoc, {
  14656. parts
  14657. });
  14658. });
  14659. }
  14660. function transformCssDoc(quasisDoc, path$$1, print) {
  14661. var parentNode = path$$1.getValue();
  14662. var isEmpty = parentNode.quasis.length === 1 && !parentNode.quasis[0].value.raw.trim();
  14663. if (isEmpty) {
  14664. return "``";
  14665. }
  14666. var expressionDocs = parentNode.expressions ? path$$1.map(print, "expressions") : [];
  14667. var newDoc = replacePlaceholders(quasisDoc, expressionDocs);
  14668. /* istanbul ignore if */
  14669. if (!newDoc) {
  14670. throw new Error("Couldn't insert all the expressions");
  14671. }
  14672. return concat$5(["`", indent$3(concat$5([hardline$4, stripTrailingHardline$1(newDoc)])), softline$2, "`"]);
  14673. } // Search all the placeholders in the quasisDoc tree
  14674. // and replace them with the expression docs one by one
  14675. // returns a new doc with all the placeholders replaced,
  14676. // or null if it couldn't replace any expression
  14677. function replacePlaceholders(quasisDoc, expressionDocs) {
  14678. if (!expressionDocs || !expressionDocs.length) {
  14679. return quasisDoc;
  14680. }
  14681. var expressions = expressionDocs.slice();
  14682. var replaceCounter = 0;
  14683. var newDoc = mapDoc$2(quasisDoc, function (doc$$2) {
  14684. if (!doc$$2 || !doc$$2.parts || !doc$$2.parts.length) {
  14685. return doc$$2;
  14686. }
  14687. var parts = doc$$2.parts;
  14688. var atIndex = parts.indexOf("@");
  14689. var placeholderIndex = atIndex + 1;
  14690. if (atIndex > -1 && typeof parts[placeholderIndex] === "string" && parts[placeholderIndex].startsWith("prettier-placeholder")) {
  14691. // If placeholder is split, join it
  14692. var at = parts[atIndex];
  14693. var placeholder = parts[placeholderIndex];
  14694. var rest = parts.slice(placeholderIndex + 1);
  14695. parts = parts.slice(0, atIndex).concat([at + placeholder]).concat(rest);
  14696. }
  14697. var atPlaceholderIndex = parts.findIndex(function (part) {
  14698. return typeof part === "string" && part.startsWith("@prettier-placeholder");
  14699. });
  14700. if (atPlaceholderIndex > -1) {
  14701. var _placeholder = parts[atPlaceholderIndex];
  14702. var _rest = parts.slice(atPlaceholderIndex + 1);
  14703. var placeholderMatch = _placeholder.match(/@prettier-placeholder-(.+)-id([\s\S]*)/);
  14704. var placeholderID = placeholderMatch[1]; // When the expression has a suffix appended, like:
  14705. // animation: linear ${time}s ease-out;
  14706. var suffix = placeholderMatch[2];
  14707. var expression = expressions[placeholderID];
  14708. replaceCounter++;
  14709. parts = parts.slice(0, atPlaceholderIndex).concat(["${", expression, "}" + suffix]).concat(_rest);
  14710. }
  14711. return Object.assign({}, doc$$2, {
  14712. parts: parts
  14713. });
  14714. });
  14715. return expressions.length === replaceCounter ? newDoc : null;
  14716. }
  14717. function printGraphqlComments(lines) {
  14718. var parts = [];
  14719. var seenComment = false;
  14720. lines.map(function (textLine) {
  14721. return textLine.trim();
  14722. }).forEach(function (textLine, i, array) {
  14723. // Lines are either whitespace only, or a comment (with poential whitespace
  14724. // around it). Drop whitespace-only lines.
  14725. if (textLine === "") {
  14726. return;
  14727. }
  14728. if (array[i - 1] === "" && seenComment) {
  14729. // If a non-first comment is preceded by a blank (whitespace only) line,
  14730. // add in a blank line.
  14731. parts.push(concat$5([hardline$4, textLine]));
  14732. } else {
  14733. parts.push(textLine);
  14734. }
  14735. seenComment = true;
  14736. }); // If `lines` was whitespace only, return `null`.
  14737. return parts.length === 0 ? null : join$3(hardline$4, parts);
  14738. }
  14739. /**
  14740. * Template literal in this context:
  14741. * <style jsx>{`div{color:red}`}</style>
  14742. */
  14743. function isStyledJsx(path$$1) {
  14744. var node = path$$1.getValue();
  14745. var parent = path$$1.getParentNode();
  14746. var parentParent = path$$1.getParentNode(1);
  14747. return parentParent && node.quasis && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXElement" && parentParent.openingElement.name.name === "style" && parentParent.openingElement.attributes.some(function (attribute) {
  14748. return attribute.name.name === "jsx";
  14749. });
  14750. }
  14751. /**
  14752. * Angular Components can have:
  14753. * - Inline HTML template
  14754. * - Inline CSS styles
  14755. *
  14756. * ...which are both within template literals somewhere
  14757. * inside of the Component decorator factory.
  14758. *
  14759. * TODO: Format HTML template once prettier's HTML
  14760. * formatting is "ready"
  14761. *
  14762. * E.g.
  14763. * @Component({
  14764. * template: `<div>...</div>`,
  14765. * styles: [`h1 { color: blue; }`]
  14766. * })
  14767. */
  14768. function isAngularComponentStyles(path$$1) {
  14769. var parent = path$$1.getParentNode();
  14770. var parentParent = path$$1.getParentNode(1);
  14771. var isWithinArrayValueFromProperty = !!(parent && parent.type === "ArrayExpression" && parentParent.type === "Property");
  14772. if (isWithinArrayValueFromProperty && isPropertyWithinAngularComponentDecorator(path$$1, 4)) {
  14773. if (parentParent.key && parentParent.key.name === "styles") {
  14774. return true;
  14775. }
  14776. }
  14777. return false;
  14778. }
  14779. /**
  14780. * styled-components template literals
  14781. */
  14782. function isStyledComponents(path$$1) {
  14783. var parent = path$$1.getParentNode();
  14784. if (!parent || parent.type !== "TaggedTemplateExpression") {
  14785. return false;
  14786. }
  14787. var tag = parent.tag;
  14788. switch (tag.type) {
  14789. case "MemberExpression":
  14790. return (// styled.foo``
  14791. isStyledIdentifier(tag.object) || // Component.extend``
  14792. isStyledExtend(tag)
  14793. );
  14794. case "CallExpression":
  14795. return (// styled(Component)``
  14796. isStyledIdentifier(tag.callee) || tag.callee.type === "MemberExpression" && (tag.callee.object.type === "MemberExpression" && ( // styled.foo.attr({})``
  14797. isStyledIdentifier(tag.callee.object.object) || // Component.extend.attr({)``
  14798. isStyledExtend(tag.callee.object)) || // styled(Component).attr({})``
  14799. tag.callee.object.type === "CallExpression" && isStyledIdentifier(tag.callee.object.callee))
  14800. );
  14801. case "Identifier":
  14802. // css``
  14803. return tag.name === "css";
  14804. default:
  14805. return false;
  14806. }
  14807. }
  14808. /**
  14809. * JSX element with CSS prop
  14810. */
  14811. function isCssProp(path$$1) {
  14812. var parent = path$$1.getParentNode();
  14813. var parentParent = path$$1.getParentNode(1);
  14814. return parentParent && parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" && parentParent.name.type === "JSXIdentifier" && parentParent.name.name === "css";
  14815. }
  14816. function isStyledIdentifier(node) {
  14817. return node.type === "Identifier" && node.name === "styled";
  14818. }
  14819. function isStyledExtend(node) {
  14820. return /^[A-Z]/.test(node.object.name) && node.property.name === "extend";
  14821. }
  14822. /*
  14823. * react-relay and graphql-tag
  14824. * graphql`...`
  14825. * graphql.experimental`...`
  14826. * gql`...`
  14827. * GraphQL comment block
  14828. *
  14829. * This intentionally excludes Relay Classic tags, as Prettier does not
  14830. * support Relay Classic formatting.
  14831. */
  14832. function isGraphQL(path$$1) {
  14833. var node = path$$1.getValue();
  14834. var parent = path$$1.getParentNode(); // This checks for a leading comment that is exactly `/* GraphQL */`
  14835. // In order to be in line with other implementations of this comment tag
  14836. // we will not trim the comment value and we will expect exactly one space on
  14837. // either side of the GraphQL string
  14838. // Also see ./clean.js
  14839. var hasGraphQLComment = node.leadingComments && node.leadingComments.some(function (comment) {
  14840. return comment.type === "CommentBlock" && comment.value === " GraphQL ";
  14841. });
  14842. return hasGraphQLComment || parent && (parent.type === "TaggedTemplateExpression" && (parent.tag.type === "MemberExpression" && parent.tag.object.name === "graphql" && parent.tag.property.name === "experimental" || parent.tag.type === "Identifier" && (parent.tag.name === "gql" || parent.tag.name === "graphql")) || parent.type === "CallExpression" && parent.callee.type === "Identifier" && parent.callee.name === "graphql");
  14843. }
  14844. var embed_1 = embed;
  14845. function clean(ast, newObj, parent) {
  14846. ["range", "raw", "comments", "leadingComments", "trailingComments", "extra", "start", "end", "flags"].forEach(function (name) {
  14847. delete newObj[name];
  14848. }); // We remove extra `;` and add them when needed
  14849. if (ast.type === "EmptyStatement") {
  14850. return null;
  14851. } // We move text around, including whitespaces and add {" "}
  14852. if (ast.type === "JSXText") {
  14853. return null;
  14854. }
  14855. if (ast.type === "JSXExpressionContainer" && ast.expression.type === "Literal" && ast.expression.value === " ") {
  14856. return null;
  14857. } // (TypeScript) Ignore `static` in `constructor(static p) {}`
  14858. // and `export` in `constructor(export p) {}`
  14859. if (ast.type === "TSParameterProperty" && ast.accessibility === null && !ast.readonly) {
  14860. return {
  14861. type: "Identifier",
  14862. name: ast.parameter.name,
  14863. typeAnnotation: newObj.parameter.typeAnnotation,
  14864. decorators: newObj.decorators
  14865. };
  14866. } // (TypeScript) ignore empty `specifiers` array
  14867. if (ast.type === "TSNamespaceExportDeclaration" && ast.specifiers && ast.specifiers.length === 0) {
  14868. delete newObj.specifiers;
  14869. } // (TypeScript) bypass TSParenthesizedType
  14870. if (ast.type === "TSParenthesizedType" && ast.typeAnnotation.type === "TSTypeAnnotation") {
  14871. return newObj.typeAnnotation.typeAnnotation;
  14872. } // We convert <div></div> to <div />
  14873. if (ast.type === "JSXOpeningElement") {
  14874. delete newObj.selfClosing;
  14875. }
  14876. if (ast.type === "JSXElement") {
  14877. delete newObj.closingElement;
  14878. } // We change {'key': value} into {key: value}
  14879. if ((ast.type === "Property" || ast.type === "ObjectProperty" || ast.type === "MethodDefinition" || ast.type === "ClassProperty" || ast.type === "TSPropertySignature" || ast.type === "ObjectTypeProperty") && typeof ast.key === "object" && ast.key && (ast.key.type === "Literal" || ast.key.type === "StringLiteral" || ast.key.type === "Identifier")) {
  14880. delete newObj.key;
  14881. }
  14882. if (ast.type === "OptionalMemberExpression" && ast.optional === false) {
  14883. newObj.type = "MemberExpression";
  14884. delete newObj.optional;
  14885. } // Remove raw and cooked values from TemplateElement when it's CSS
  14886. // styled-jsx
  14887. if (ast.type === "JSXElement" && ast.openingElement.name.name === "style" && ast.openingElement.attributes.some(function (attr) {
  14888. return attr.name.name === "jsx";
  14889. })) {
  14890. var templateLiterals = newObj.children.filter(function (child) {
  14891. return child.type === "JSXExpressionContainer" && child.expression.type === "TemplateLiteral";
  14892. }).map(function (container) {
  14893. return container.expression;
  14894. });
  14895. var quasis = templateLiterals.reduce(function (quasis, templateLiteral) {
  14896. return quasis.concat(templateLiteral.quasis);
  14897. }, []);
  14898. quasis.forEach(function (q) {
  14899. return delete q.value;
  14900. });
  14901. } // CSS template literals in css prop
  14902. if (ast.type === "JSXAttribute" && ast.name.name === "css" && ast.value.type === "JSXExpressionContainer" && ast.value.expression.type === "TemplateLiteral") {
  14903. newObj.value.expression.quasis.forEach(function (q) {
  14904. return delete q.value;
  14905. });
  14906. } // CSS template literals in Angular Component decorator
  14907. var expression = ast.expression || ast.callee;
  14908. if (ast.type === "Decorator" && expression.type === "CallExpression" && expression.callee.name === "Component" && expression.arguments.length === 1 && expression.arguments[0].properties.some(function (prop) {
  14909. return prop.key.name === "styles" && prop.value.type === "ArrayExpression";
  14910. })) {
  14911. newObj.expression.arguments[0].properties.forEach(function (prop) {
  14912. if (prop.value.type === "ArrayExpression") {
  14913. prop.value.elements[0].quasis.forEach(function (q) {
  14914. return delete q.value;
  14915. });
  14916. }
  14917. });
  14918. } // styled-components, graphql, markdown
  14919. if (ast.type === "TaggedTemplateExpression" && (ast.tag.type === "MemberExpression" || ast.tag.type === "Identifier" && (ast.tag.name === "gql" || ast.tag.name === "graphql" || ast.tag.name === "css" || ast.tag.name === "md" || ast.tag.name === "markdown") || ast.tag.type === "CallExpression")) {
  14920. newObj.quasi.quasis.forEach(function (quasi) {
  14921. return delete quasi.value;
  14922. });
  14923. }
  14924. if (ast.type === "TemplateLiteral") {
  14925. // This checks for a leading comment that is exactly `/* GraphQL */`
  14926. // In order to be in line with other implementations of this comment tag
  14927. // we will not trim the comment value and we will expect exactly one space on
  14928. // either side of the GraphQL string
  14929. // Also see ./embed.js
  14930. var hasGraphQLComment = ast.leadingComments && ast.leadingComments.some(function (comment) {
  14931. return comment.type === "CommentBlock" && comment.value === " GraphQL ";
  14932. });
  14933. if (hasGraphQLComment || parent.type === "CallExpression" && parent.callee.name === "graphql") {
  14934. newObj.quasis.forEach(function (quasi) {
  14935. return delete quasi.value;
  14936. });
  14937. }
  14938. }
  14939. }
  14940. var clean_1 = clean;
  14941. var detectNewline = createCommonjsModule(function (module) {
  14942. 'use strict';
  14943. module.exports = function (str) {
  14944. if (typeof str !== 'string') {
  14945. throw new TypeError('Expected a string');
  14946. }
  14947. var newlines = str.match(/(?:\r?\n)/g) || [];
  14948. if (newlines.length === 0) {
  14949. return null;
  14950. }
  14951. var crlf = newlines.filter(function (el) {
  14952. return el === '\r\n';
  14953. }).length;
  14954. var lf = newlines.length - crlf;
  14955. return crlf > lf ? '\r\n' : '\n';
  14956. };
  14957. module.exports.graceful = function (str) {
  14958. return module.exports(str) || '\n';
  14959. };
  14960. });
  14961. var build = createCommonjsModule(function (module, exports) {
  14962. 'use strict';
  14963. Object.defineProperty(exports, "__esModule", {
  14964. value: true
  14965. });
  14966. exports.extract = extract;
  14967. exports.strip = strip;
  14968. exports.parse = parse;
  14969. exports.parseWithComments = parseWithComments;
  14970. exports.print = print;
  14971. var _detectNewline;
  14972. function _load_detectNewline() {
  14973. return _detectNewline = _interopRequireDefault(detectNewline);
  14974. }
  14975. var _os;
  14976. function _load_os() {
  14977. return _os = os;
  14978. }
  14979. function _interopRequireDefault(obj) {
  14980. return obj && obj.__esModule ? obj : {
  14981. default: obj
  14982. };
  14983. }
  14984. /**
  14985. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  14986. *
  14987. * This source code is licensed under the MIT license found in the
  14988. * LICENSE file in the root directory of this source tree.
  14989. *
  14990. *
  14991. */
  14992. var commentEndRe = /\*\/$/;
  14993. var commentStartRe = /^\/\*\*/;
  14994. var docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;
  14995. var lineCommentRe = /(^|\s+)\/\/([^\r\n]*)/g;
  14996. var ltrimRe = /^\s*/;
  14997. var rtrimRe = /\s*$/;
  14998. var ltrimNewlineRe = /^(\r?\n)+/;
  14999. var multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *(?![^@\r\n]*\/\/[^]*)([^@\r\n\s][^@\r\n]+?) *\r?\n/g;
  15000. var propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;
  15001. var stringStartRe = /(\r?\n|^) *\* ?/g;
  15002. function extract(contents) {
  15003. var match = contents.match(docblockRe);
  15004. return match ? match[0].replace(ltrimRe, '') || '' : '';
  15005. }
  15006. function strip(contents) {
  15007. var match = contents.match(docblockRe);
  15008. return match && match[0] ? contents.substring(match[0].length) : contents;
  15009. }
  15010. function parse(docblock) {
  15011. return parseWithComments(docblock).pragmas;
  15012. }
  15013. function parseWithComments(docblock) {
  15014. var line = (0, (_detectNewline || _load_detectNewline()).default)(docblock) || (_os || _load_os()).EOL;
  15015. docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replace(stringStartRe, '$1'); // Normalize multi-line directives
  15016. var prev = '';
  15017. while (prev !== docblock) {
  15018. prev = docblock;
  15019. docblock = docblock.replace(multilineRe, `${line}$1 $2${line}`);
  15020. }
  15021. docblock = docblock.replace(ltrimNewlineRe, '').replace(rtrimRe, '');
  15022. var result = Object.create(null);
  15023. var comments = docblock.replace(propertyRe, '').replace(ltrimNewlineRe, '').replace(rtrimRe, '');
  15024. var match;
  15025. while (match = propertyRe.exec(docblock)) {
  15026. // strip linecomments from pragmas
  15027. var nextPragma = match[2].replace(lineCommentRe, '');
  15028. if (typeof result[match[1]] === 'string' || Array.isArray(result[match[1]])) {
  15029. result[match[1]] = [].concat(result[match[1]], nextPragma);
  15030. } else {
  15031. result[match[1]] = nextPragma;
  15032. }
  15033. }
  15034. return {
  15035. comments,
  15036. pragmas: result
  15037. };
  15038. }
  15039. function print(_ref) {
  15040. var _ref$comments = _ref.comments;
  15041. var comments = _ref$comments === undefined ? '' : _ref$comments;
  15042. var _ref$pragmas = _ref.pragmas;
  15043. var pragmas = _ref$pragmas === undefined ? {} : _ref$pragmas;
  15044. var line = (0, (_detectNewline || _load_detectNewline()).default)(comments) || (_os || _load_os()).EOL;
  15045. var head = '/**';
  15046. var start = ' *';
  15047. var tail = ' */';
  15048. var keys = Object.keys(pragmas);
  15049. var printedObject = keys.map(function (key) {
  15050. return printKeyValues(key, pragmas[key]);
  15051. }).reduce(function (arr, next) {
  15052. return arr.concat(next);
  15053. }, []).map(function (keyValue) {
  15054. return start + ' ' + keyValue + line;
  15055. }).join('');
  15056. if (!comments) {
  15057. if (keys.length === 0) {
  15058. return '';
  15059. }
  15060. if (keys.length === 1 && !Array.isArray(pragmas[keys[0]])) {
  15061. var value = pragmas[keys[0]];
  15062. return `${head} ${printKeyValues(keys[0], value)[0]}${tail}`;
  15063. }
  15064. }
  15065. var printedComments = comments.split(line).map(function (textLine) {
  15066. return `${start} ${textLine}`;
  15067. }).join(line) + line;
  15068. return head + line + (comments ? printedComments : '') + (comments && keys.length ? start + line : '') + printedObject + tail;
  15069. }
  15070. function printKeyValues(key, valueOrArray) {
  15071. return [].concat(valueOrArray).map(function (value) {
  15072. return `@${key} ${value}`.trim();
  15073. });
  15074. }
  15075. });
  15076. unwrapExports(build);
  15077. function hasPragma(text) {
  15078. var pragmas = Object.keys(build.parse(build.extract(text)));
  15079. return pragmas.indexOf("prettier") !== -1 || pragmas.indexOf("format") !== -1;
  15080. }
  15081. function insertPragma$1(text) {
  15082. var parsedDocblock = build.parseWithComments(build.extract(text));
  15083. var pragmas = Object.assign({
  15084. format: ""
  15085. }, parsedDocblock.pragmas);
  15086. var newDocblock = build.print({
  15087. pragmas,
  15088. comments: parsedDocblock.comments.replace(/^(\s+?\r?\n)+/, "") // remove leading newlines
  15089. });
  15090. var strippedText = build.strip(text);
  15091. var separatingNewlines = strippedText.startsWith("\n") ? "\n" : "\n\n";
  15092. return newDocblock + separatingNewlines + strippedText;
  15093. }
  15094. var pragma = {
  15095. hasPragma,
  15096. insertPragma: insertPragma$1
  15097. };
  15098. var addLeadingComment$2 = utilShared.addLeadingComment;
  15099. var addTrailingComment$2 = utilShared.addTrailingComment;
  15100. var addDanglingComment$2 = utilShared.addDanglingComment;
  15101. function handleOwnLineComment(comment, text, options, ast, isLastComment) {
  15102. var precedingNode = comment.precedingNode;
  15103. var enclosingNode = comment.enclosingNode;
  15104. var followingNode = comment.followingNode;
  15105. if (handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleMemberExpressionComments(enclosingNode, followingNode, comment) || handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleTryStatementComments(enclosingNode, followingNode, comment) || handleClassComments(enclosingNode, precedingNode, followingNode, comment) || handleImportSpecifierComments(enclosingNode, comment) || handleForComments(enclosingNode, precedingNode, comment) || handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleImportDeclarationComments(text, enclosingNode, precedingNode, comment, options) || handleAssignmentPatternComments(enclosingNode, comment) || handleMethodNameComments(text, enclosingNode, precedingNode, comment, options)) {
  15106. return true;
  15107. }
  15108. return false;
  15109. }
  15110. function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
  15111. var precedingNode = comment.precedingNode;
  15112. var enclosingNode = comment.enclosingNode;
  15113. var followingNode = comment.followingNode;
  15114. if (handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleConditionalExpressionComments(enclosingNode, precedingNode, followingNode, comment, text, options) || handleImportSpecifierComments(enclosingNode, comment) || handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleClassComments(enclosingNode, precedingNode, followingNode, comment) || handleLabeledStatementComments(enclosingNode, comment) || handleCallExpressionComments(precedingNode, enclosingNode, comment) || handlePropertyComments(enclosingNode, comment) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleTypeAliasComments(enclosingNode, followingNode, comment) || handleVariableDeclaratorComments(enclosingNode, followingNode, comment)) {
  15115. return true;
  15116. }
  15117. return false;
  15118. }
  15119. function handleRemainingComment(comment, text, options, ast, isLastComment) {
  15120. var precedingNode = comment.precedingNode;
  15121. var enclosingNode = comment.enclosingNode;
  15122. var followingNode = comment.followingNode;
  15123. if (handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) || handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) || handleCommentInEmptyParens(text, enclosingNode, comment, options) || handleMethodNameComments(text, enclosingNode, precedingNode, comment, options) || handleOnlyComments(enclosingNode, ast, comment, isLastComment) || handleCommentAfterArrowParams(text, enclosingNode, comment, options) || handleFunctionNameComments(text, enclosingNode, precedingNode, comment, options) || handleTSMappedTypeComments(text, enclosingNode, precedingNode, followingNode, comment) || handleBreakAndContinueStatementComments(enclosingNode, comment)) {
  15124. return true;
  15125. }
  15126. return false;
  15127. }
  15128. function addBlockStatementFirstComment(node, comment) {
  15129. var body = node.body.filter(function (n) {
  15130. return n.type !== "EmptyStatement";
  15131. });
  15132. if (body.length === 0) {
  15133. addDanglingComment$2(node, comment);
  15134. } else {
  15135. addLeadingComment$2(body[0], comment);
  15136. }
  15137. }
  15138. function addBlockOrNotComment(node, comment) {
  15139. if (node.type === "BlockStatement") {
  15140. addBlockStatementFirstComment(node, comment);
  15141. } else {
  15142. addLeadingComment$2(node, comment);
  15143. }
  15144. } // There are often comments before the else clause of if statements like
  15145. //
  15146. // if (1) { ... }
  15147. // // comment
  15148. // else { ... }
  15149. //
  15150. // They are being attached as leading comments of the BlockExpression which
  15151. // is not well printed. What we want is to instead move the comment inside
  15152. // of the block and make it leadingComment of the first element of the block
  15153. // or dangling comment of the block if there is nothing inside
  15154. //
  15155. // if (1) { ... }
  15156. // else {
  15157. // // comment
  15158. // ...
  15159. // }
  15160. function handleIfStatementComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  15161. if (!enclosingNode || enclosingNode.type !== "IfStatement" || !followingNode) {
  15162. return false;
  15163. } // We unfortunately have no way using the AST or location of nodes to know
  15164. // if the comment is positioned before the condition parenthesis:
  15165. // if (a /* comment */) {}
  15166. // The only workaround I found is to look at the next character to see if
  15167. // it is a ).
  15168. var nextCharacter = util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd);
  15169. if (nextCharacter === ")") {
  15170. addTrailingComment$2(precedingNode, comment);
  15171. return true;
  15172. } // Comments before `else`:
  15173. // - treat as trailing comments of the consequent, if it's a BlockStatement
  15174. // - treat as a dangling comment otherwise
  15175. if (precedingNode === enclosingNode.consequent && followingNode === enclosingNode.alternate) {
  15176. if (precedingNode.type === "BlockStatement") {
  15177. addTrailingComment$2(precedingNode, comment);
  15178. } else {
  15179. addDanglingComment$2(enclosingNode, comment);
  15180. }
  15181. return true;
  15182. }
  15183. if (followingNode.type === "BlockStatement") {
  15184. addBlockStatementFirstComment(followingNode, comment);
  15185. return true;
  15186. }
  15187. if (followingNode.type === "IfStatement") {
  15188. addBlockOrNotComment(followingNode.consequent, comment);
  15189. return true;
  15190. } // For comments positioned after the condition parenthesis in an if statement
  15191. // before the consequent with or without brackets on, such as
  15192. // if (a) /* comment */ {} or if (a) /* comment */ true,
  15193. // we look at the next character to see if it is a { or if the following node
  15194. // is the consequent for the if statement
  15195. if (nextCharacter === "{" || enclosingNode.consequent === followingNode) {
  15196. addLeadingComment$2(followingNode, comment);
  15197. return true;
  15198. }
  15199. return false;
  15200. } // Same as IfStatement but for TryStatement
  15201. function handleTryStatementComments(enclosingNode, followingNode, comment) {
  15202. if (!enclosingNode || enclosingNode.type !== "TryStatement" || !followingNode) {
  15203. return false;
  15204. }
  15205. if (followingNode.type === "BlockStatement") {
  15206. addBlockStatementFirstComment(followingNode, comment);
  15207. return true;
  15208. }
  15209. if (followingNode.type === "TryStatement") {
  15210. addBlockOrNotComment(followingNode.finalizer, comment);
  15211. return true;
  15212. }
  15213. if (followingNode.type === "CatchClause") {
  15214. addBlockOrNotComment(followingNode.body, comment);
  15215. return true;
  15216. }
  15217. return false;
  15218. }
  15219. function handleMemberExpressionComments(enclosingNode, followingNode, comment) {
  15220. if (enclosingNode && enclosingNode.type === "MemberExpression" && followingNode && followingNode.type === "Identifier") {
  15221. addLeadingComment$2(enclosingNode, comment);
  15222. return true;
  15223. }
  15224. return false;
  15225. }
  15226. function handleConditionalExpressionComments(enclosingNode, precedingNode, followingNode, comment, text, options) {
  15227. var isSameLineAsPrecedingNode = precedingNode && !util$1.hasNewlineInRange(text, options.locEnd(precedingNode), options.locStart(comment));
  15228. if ((!precedingNode || !isSameLineAsPrecedingNode) && enclosingNode && enclosingNode.type === "ConditionalExpression" && followingNode) {
  15229. addLeadingComment$2(followingNode, comment);
  15230. return true;
  15231. }
  15232. return false;
  15233. }
  15234. function handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) {
  15235. if (enclosingNode && (enclosingNode.type === "ObjectProperty" || enclosingNode.type === "Property") && enclosingNode.shorthand && enclosingNode.key === precedingNode && enclosingNode.value.type === "AssignmentPattern") {
  15236. addTrailingComment$2(enclosingNode.value.left, comment);
  15237. return true;
  15238. }
  15239. return false;
  15240. }
  15241. function handleClassComments(enclosingNode, precedingNode, followingNode, comment) {
  15242. if (enclosingNode && (enclosingNode.type === "ClassDeclaration" || enclosingNode.type === "ClassExpression") && enclosingNode.decorators && enclosingNode.decorators.length > 0 && !(followingNode && followingNode.type === "Decorator")) {
  15243. if (!enclosingNode.decorators || enclosingNode.decorators.length === 0) {
  15244. addLeadingComment$2(enclosingNode, comment);
  15245. } else {
  15246. addTrailingComment$2(enclosingNode.decorators[enclosingNode.decorators.length - 1], comment);
  15247. }
  15248. return true;
  15249. }
  15250. return false;
  15251. }
  15252. function handleMethodNameComments(text, enclosingNode, precedingNode, comment, options) {
  15253. // This is only needed for estree parsers (flow, typescript) to attach
  15254. // after a method name:
  15255. // obj = { fn /*comment*/() {} };
  15256. if (enclosingNode && precedingNode && (enclosingNode.type === "Property" || enclosingNode.type === "MethodDefinition") && precedingNode.type === "Identifier" && enclosingNode.key === precedingNode && // special Property case: { key: /*comment*/(value) };
  15257. // comment should be attached to value instead of key
  15258. util$1.getNextNonSpaceNonCommentCharacter(text, precedingNode, options.locEnd) !== ":") {
  15259. addTrailingComment$2(precedingNode, comment);
  15260. return true;
  15261. } // Print comments between decorators and class methods as a trailing comment
  15262. // on the decorator node instead of the method node
  15263. if (precedingNode && enclosingNode && precedingNode.type === "Decorator" && (enclosingNode.type === "ClassMethod" || enclosingNode.type === "ClassProperty" || enclosingNode.type === "TSAbstractClassProperty" || enclosingNode.type === "TSAbstractMethodDefinition" || enclosingNode.type === "MethodDefinition")) {
  15264. addTrailingComment$2(precedingNode, comment);
  15265. return true;
  15266. }
  15267. return false;
  15268. }
  15269. function handleFunctionNameComments(text, enclosingNode, precedingNode, comment, options) {
  15270. if (util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) !== "(") {
  15271. return false;
  15272. }
  15273. if (precedingNode && enclosingNode && (enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ClassMethod" || enclosingNode.type === "MethodDefinition" || enclosingNode.type === "ObjectMethod")) {
  15274. addTrailingComment$2(precedingNode, comment);
  15275. return true;
  15276. }
  15277. return false;
  15278. }
  15279. function handleCommentAfterArrowParams(text, enclosingNode, comment, options) {
  15280. if (!(enclosingNode && enclosingNode.type === "ArrowFunctionExpression")) {
  15281. return false;
  15282. }
  15283. var index = utilShared.getNextNonSpaceNonCommentCharacterIndex(text, comment, options);
  15284. if (text.substr(index, 2) === "=>") {
  15285. addDanglingComment$2(enclosingNode, comment);
  15286. return true;
  15287. }
  15288. return false;
  15289. }
  15290. function handleCommentInEmptyParens(text, enclosingNode, comment, options) {
  15291. if (util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) !== ")") {
  15292. return false;
  15293. } // Only add dangling comments to fix the case when no params are present,
  15294. // i.e. a function without any argument.
  15295. if (enclosingNode && ((enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "ArrowFunctionExpression" && (enclosingNode.body.type !== "CallExpression" || enclosingNode.body.arguments.length === 0) || enclosingNode.type === "ClassMethod" || enclosingNode.type === "ObjectMethod") && enclosingNode.params.length === 0 || enclosingNode.type === "CallExpression" && enclosingNode.arguments.length === 0)) {
  15296. addDanglingComment$2(enclosingNode, comment);
  15297. return true;
  15298. }
  15299. if (enclosingNode && enclosingNode.type === "MethodDefinition" && enclosingNode.value.params.length === 0) {
  15300. addDanglingComment$2(enclosingNode.value, comment);
  15301. return true;
  15302. }
  15303. return false;
  15304. }
  15305. function handleLastFunctionArgComments(text, precedingNode, enclosingNode, followingNode, comment, options) {
  15306. // Type definitions functions
  15307. if (precedingNode && precedingNode.type === "FunctionTypeParam" && enclosingNode && enclosingNode.type === "FunctionTypeAnnotation" && followingNode && followingNode.type !== "FunctionTypeParam") {
  15308. addTrailingComment$2(precedingNode, comment);
  15309. return true;
  15310. } // Real functions
  15311. if (precedingNode && (precedingNode.type === "Identifier" || precedingNode.type === "AssignmentPattern") && enclosingNode && (enclosingNode.type === "ArrowFunctionExpression" || enclosingNode.type === "FunctionExpression" || enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "ObjectMethod" || enclosingNode.type === "ClassMethod") && util$1.getNextNonSpaceNonCommentCharacter(text, comment, options.locEnd) === ")") {
  15312. addTrailingComment$2(precedingNode, comment);
  15313. return true;
  15314. }
  15315. return false;
  15316. }
  15317. function handleImportSpecifierComments(enclosingNode, comment) {
  15318. if (enclosingNode && enclosingNode.type === "ImportSpecifier") {
  15319. addLeadingComment$2(enclosingNode, comment);
  15320. return true;
  15321. }
  15322. return false;
  15323. }
  15324. function handleLabeledStatementComments(enclosingNode, comment) {
  15325. if (enclosingNode && enclosingNode.type === "LabeledStatement") {
  15326. addLeadingComment$2(enclosingNode, comment);
  15327. return true;
  15328. }
  15329. return false;
  15330. }
  15331. function handleBreakAndContinueStatementComments(enclosingNode, comment) {
  15332. if (enclosingNode && (enclosingNode.type === "ContinueStatement" || enclosingNode.type === "BreakStatement") && !enclosingNode.label) {
  15333. addTrailingComment$2(enclosingNode, comment);
  15334. return true;
  15335. }
  15336. return false;
  15337. }
  15338. function handleCallExpressionComments(precedingNode, enclosingNode, comment) {
  15339. if (enclosingNode && enclosingNode.type === "CallExpression" && precedingNode && enclosingNode.callee === precedingNode && enclosingNode.arguments.length > 0) {
  15340. addLeadingComment$2(enclosingNode.arguments[0], comment);
  15341. return true;
  15342. }
  15343. return false;
  15344. }
  15345. function handleUnionTypeComments(precedingNode, enclosingNode, followingNode, comment) {
  15346. if (enclosingNode && (enclosingNode.type === "UnionTypeAnnotation" || enclosingNode.type === "TSUnionType")) {
  15347. addTrailingComment$2(precedingNode, comment);
  15348. return true;
  15349. }
  15350. return false;
  15351. }
  15352. function handlePropertyComments(enclosingNode, comment) {
  15353. if (enclosingNode && (enclosingNode.type === "Property" || enclosingNode.type === "ObjectProperty")) {
  15354. addLeadingComment$2(enclosingNode, comment);
  15355. return true;
  15356. }
  15357. return false;
  15358. }
  15359. function handleOnlyComments(enclosingNode, ast, comment, isLastComment) {
  15360. // With Flow the enclosingNode is undefined so use the AST instead.
  15361. if (ast && ast.body && ast.body.length === 0) {
  15362. if (isLastComment) {
  15363. addDanglingComment$2(ast, comment);
  15364. } else {
  15365. addLeadingComment$2(ast, comment);
  15366. }
  15367. return true;
  15368. } else if (enclosingNode && enclosingNode.type === "Program" && enclosingNode.body.length === 0 && enclosingNode.directives && enclosingNode.directives.length === 0) {
  15369. if (isLastComment) {
  15370. addDanglingComment$2(enclosingNode, comment);
  15371. } else {
  15372. addLeadingComment$2(enclosingNode, comment);
  15373. }
  15374. return true;
  15375. }
  15376. return false;
  15377. }
  15378. function handleForComments(enclosingNode, precedingNode, comment) {
  15379. if (enclosingNode && (enclosingNode.type === "ForInStatement" || enclosingNode.type === "ForOfStatement")) {
  15380. addLeadingComment$2(enclosingNode, comment);
  15381. return true;
  15382. }
  15383. return false;
  15384. }
  15385. function handleImportDeclarationComments(text, enclosingNode, precedingNode, comment, options) {
  15386. if (precedingNode && enclosingNode && enclosingNode.type === "ImportDeclaration" && util$1.hasNewline(text, options.locEnd(comment))) {
  15387. addTrailingComment$2(precedingNode, comment);
  15388. return true;
  15389. }
  15390. return false;
  15391. }
  15392. function handleAssignmentPatternComments(enclosingNode, comment) {
  15393. if (enclosingNode && enclosingNode.type === "AssignmentPattern") {
  15394. addLeadingComment$2(enclosingNode, comment);
  15395. return true;
  15396. }
  15397. return false;
  15398. }
  15399. function handleTypeAliasComments(enclosingNode, followingNode, comment) {
  15400. if (enclosingNode && enclosingNode.type === "TypeAlias") {
  15401. addLeadingComment$2(enclosingNode, comment);
  15402. return true;
  15403. }
  15404. return false;
  15405. }
  15406. function handleVariableDeclaratorComments(enclosingNode, followingNode, comment) {
  15407. if (enclosingNode && (enclosingNode.type === "VariableDeclarator" || enclosingNode.type === "AssignmentExpression") && followingNode && (followingNode.type === "ObjectExpression" || followingNode.type === "ArrayExpression" || followingNode.type === "TemplateLiteral" || followingNode.type === "TaggedTemplateExpression")) {
  15408. addLeadingComment$2(followingNode, comment);
  15409. return true;
  15410. }
  15411. return false;
  15412. }
  15413. function handleTSMappedTypeComments(text, enclosingNode, precedingNode, followingNode, comment) {
  15414. if (!enclosingNode || enclosingNode.type !== "TSMappedType") {
  15415. return false;
  15416. }
  15417. if (followingNode && followingNode.type === "TSTypeParameter" && followingNode.name) {
  15418. addLeadingComment$2(followingNode.name, comment);
  15419. return true;
  15420. }
  15421. if (precedingNode && precedingNode.type === "TSTypeParameter" && precedingNode.constraint) {
  15422. addTrailingComment$2(precedingNode.constraint, comment);
  15423. return true;
  15424. }
  15425. return false;
  15426. }
  15427. function isBlockComment(comment) {
  15428. return comment.type === "Block" || comment.type === "CommentBlock";
  15429. }
  15430. var comments$3 = {
  15431. handleOwnLineComment,
  15432. handleEndOfLineComment,
  15433. handleRemainingComment,
  15434. isBlockComment
  15435. };
  15436. function hasClosureCompilerTypeCastComment(text, path$$1, locStart, locEnd) {
  15437. // https://github.com/google/closure-compiler/wiki/Annotating-Types#type-casts
  15438. // Syntax example: var x = /** @type {string} */ (fruit);
  15439. var n = path$$1.getValue();
  15440. return util$1.getNextNonSpaceNonCommentCharacter(text, n, locEnd) === ")" && (hasTypeCastComment(n) || hasAncestorTypeCastComment(0)); // for sub-item: /** @type {array} */ (numberOrString).map(x => x);
  15441. function hasAncestorTypeCastComment(index) {
  15442. var ancestor = path$$1.getParentNode(index);
  15443. return ancestor && util$1.getNextNonSpaceNonCommentCharacter(text, ancestor, locEnd) !== ")" && /^[\s(]*$/.test(text.slice(locStart(ancestor), locStart(n))) ? hasTypeCastComment(ancestor) || hasAncestorTypeCastComment(index + 1) : false;
  15444. }
  15445. function hasTypeCastComment(node) {
  15446. return node.comments && node.comments.some(function (comment) {
  15447. return comment.leading && comments$3.isBlockComment(comment) && comment.value.match(/^\*\s*@type\s*{[^}]+}\s*$/) && util$1.getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(";
  15448. });
  15449. }
  15450. }
  15451. function needsParens(path$$1, options) {
  15452. var parent = path$$1.getParentNode();
  15453. if (!parent) {
  15454. return false;
  15455. }
  15456. var name = path$$1.getName();
  15457. var node = path$$1.getNode(); // If the value of this path is some child of a Node and not a Node
  15458. // itself, then it doesn't need parentheses. Only Node objects (in
  15459. // fact, only Expression nodes) need parentheses.
  15460. if (path$$1.getValue() !== node) {
  15461. return false;
  15462. } // Only statements don't need parentheses.
  15463. if (isStatement(node)) {
  15464. return false;
  15465. } // Closure compiler requires that type casted expressions to be surrounded by
  15466. // parentheses.
  15467. if (hasClosureCompilerTypeCastComment(options.originalText, path$$1, options.locStart, options.locEnd)) {
  15468. return true;
  15469. } // Identifiers never need parentheses.
  15470. if (node.type === "Identifier") {
  15471. return false;
  15472. }
  15473. if (parent.type === "ParenthesizedExpression") {
  15474. return false;
  15475. } // Add parens around the extends clause of a class. It is needed for almost
  15476. // all expressions.
  15477. if ((parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node && (node.type === "ArrowFunctionExpression" || node.type === "AssignmentExpression" || node.type === "AwaitExpression" || node.type === "BinaryExpression" || node.type === "ConditionalExpression" || node.type === "LogicalExpression" || node.type === "NewExpression" || node.type === "ObjectExpression" || node.type === "ParenthesizedExpression" || node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "UnaryExpression" || node.type === "UpdateExpression" || node.type === "YieldExpression")) {
  15478. return true;
  15479. }
  15480. if (parent.type === "ArrowFunctionExpression" && parent.body === node && node.type !== "SequenceExpression" && // these have parens added anyway
  15481. util$1.startsWithNoLookaheadToken(node,
  15482. /* forbidFunctionClassAndDoExpr */
  15483. false) || parent.type === "ExpressionStatement" && util$1.startsWithNoLookaheadToken(node,
  15484. /* forbidFunctionClassAndDoExpr */
  15485. true)) {
  15486. return true;
  15487. }
  15488. switch (node.type) {
  15489. case "CallExpression":
  15490. {
  15491. var firstParentNotMemberExpression = parent;
  15492. var i = 0;
  15493. while (firstParentNotMemberExpression && firstParentNotMemberExpression.type === "MemberExpression") {
  15494. firstParentNotMemberExpression = path$$1.getParentNode(++i);
  15495. }
  15496. if (firstParentNotMemberExpression.type === "NewExpression" && firstParentNotMemberExpression.callee === path$$1.getParentNode(i - 1)) {
  15497. return true;
  15498. }
  15499. return false;
  15500. }
  15501. case "SpreadElement":
  15502. case "SpreadProperty":
  15503. return parent.type === "MemberExpression" && name === "object" && parent.object === node;
  15504. case "UpdateExpression":
  15505. if (parent.type === "UnaryExpression") {
  15506. return node.prefix && (node.operator === "++" && parent.operator === "+" || node.operator === "--" && parent.operator === "-");
  15507. }
  15508. // else fallthrough
  15509. case "UnaryExpression":
  15510. switch (parent.type) {
  15511. case "UnaryExpression":
  15512. return node.operator === parent.operator && (node.operator === "+" || node.operator === "-");
  15513. case "MemberExpression":
  15514. return name === "object" && parent.object === node;
  15515. case "TaggedTemplateExpression":
  15516. return true;
  15517. case "NewExpression":
  15518. case "CallExpression":
  15519. return name === "callee" && parent.callee === node;
  15520. case "BinaryExpression":
  15521. return parent.operator === "**" && name === "left";
  15522. case "TSNonNullExpression":
  15523. return true;
  15524. default:
  15525. return false;
  15526. }
  15527. case "BinaryExpression":
  15528. {
  15529. if (parent.type === "UpdateExpression") {
  15530. return true;
  15531. }
  15532. var isLeftOfAForStatement = function isLeftOfAForStatement(node) {
  15533. var i = 0;
  15534. while (node) {
  15535. var _parent = path$$1.getParentNode(i++);
  15536. if (!_parent) {
  15537. return false;
  15538. }
  15539. if (_parent.type === "ForStatement" && _parent.init === node) {
  15540. return true;
  15541. }
  15542. node = _parent;
  15543. }
  15544. return false;
  15545. };
  15546. if (node.operator === "in" && isLeftOfAForStatement(node)) {
  15547. return true;
  15548. }
  15549. }
  15550. // fallthrough
  15551. case "TSTypeAssertionExpression":
  15552. case "TSAsExpression":
  15553. case "LogicalExpression":
  15554. switch (parent.type) {
  15555. case "ConditionalExpression":
  15556. return node.type === "TSAsExpression";
  15557. case "CallExpression":
  15558. case "NewExpression":
  15559. return name === "callee" && parent.callee === node;
  15560. case "ClassDeclaration":
  15561. case "TSAbstractClassDeclaration":
  15562. return name === "superClass" && parent.superClass === node;
  15563. case "TSTypeAssertionExpression":
  15564. case "TaggedTemplateExpression":
  15565. case "UnaryExpression":
  15566. case "SpreadElement":
  15567. case "SpreadProperty":
  15568. case "ExperimentalSpreadProperty":
  15569. case "BindExpression":
  15570. case "AwaitExpression":
  15571. case "TSAsExpression":
  15572. case "TSNonNullExpression":
  15573. case "UpdateExpression":
  15574. return true;
  15575. case "MemberExpression":
  15576. return name === "object" && parent.object === node;
  15577. case "AssignmentExpression":
  15578. return parent.left === node && (node.type === "TSTypeAssertionExpression" || node.type === "TSAsExpression");
  15579. case "Decorator":
  15580. return parent.expression === node && (node.type === "TSTypeAssertionExpression" || node.type === "TSAsExpression");
  15581. case "BinaryExpression":
  15582. case "LogicalExpression":
  15583. {
  15584. if (!node.operator && node.type !== "TSTypeAssertionExpression") {
  15585. return true;
  15586. }
  15587. var po = parent.operator;
  15588. var pp = util$1.getPrecedence(po);
  15589. var no = node.operator;
  15590. var np = util$1.getPrecedence(no);
  15591. if (pp > np) {
  15592. return true;
  15593. }
  15594. if ((po === "||" || po === "??") && no === "&&") {
  15595. return true;
  15596. }
  15597. if (pp === np && name === "right") {
  15598. assert.strictEqual(parent.right, node);
  15599. return true;
  15600. }
  15601. if (pp === np && !util$1.shouldFlatten(po, no)) {
  15602. return true;
  15603. }
  15604. if (pp < np && no === "%") {
  15605. return !util$1.shouldFlatten(po, no);
  15606. } // Add parenthesis when working with binary operators
  15607. // It's not stricly needed but helps with code understanding
  15608. if (util$1.isBitwiseOperator(po)) {
  15609. return true;
  15610. }
  15611. return false;
  15612. }
  15613. default:
  15614. return false;
  15615. }
  15616. case "TSParenthesizedType":
  15617. {
  15618. var grandParent = path$$1.getParentNode(1);
  15619. if ((parent.type === "TSTypeParameter" || parent.type === "TypeParameter" || parent.type === "VariableDeclarator" || parent.type === "TSTypeAnnotation" || parent.type === "GenericTypeAnnotation" || parent.type === "TSTypeReference") && node.typeAnnotation.type === "TSTypeAnnotation" && node.typeAnnotation.typeAnnotation.type !== "TSFunctionType" && grandParent.type !== "TSTypeOperator") {
  15620. return false;
  15621. } // Delegate to inner TSParenthesizedType
  15622. if (node.typeAnnotation.type === "TSParenthesizedType") {
  15623. return false;
  15624. }
  15625. return true;
  15626. }
  15627. case "SequenceExpression":
  15628. switch (parent.type) {
  15629. case "ReturnStatement":
  15630. return false;
  15631. case "ForStatement":
  15632. // Although parentheses wouldn't hurt around sequence
  15633. // expressions in the head of for loops, traditional style
  15634. // dictates that e.g. i++, j++ should not be wrapped with
  15635. // parentheses.
  15636. return false;
  15637. case "ExpressionStatement":
  15638. return name !== "expression";
  15639. case "ArrowFunctionExpression":
  15640. // We do need parentheses, but SequenceExpressions are handled
  15641. // specially when printing bodies of arrow functions.
  15642. return name !== "body";
  15643. default:
  15644. // Otherwise err on the side of overparenthesization, adding
  15645. // explicit exceptions above if this proves overzealous.
  15646. return true;
  15647. }
  15648. case "YieldExpression":
  15649. if (parent.type === "UnaryExpression" || parent.type === "AwaitExpression" || parent.type === "TSAsExpression" || parent.type === "TSNonNullExpression") {
  15650. return true;
  15651. }
  15652. // else fallthrough
  15653. case "AwaitExpression":
  15654. switch (parent.type) {
  15655. case "TaggedTemplateExpression":
  15656. case "UnaryExpression":
  15657. case "BinaryExpression":
  15658. case "LogicalExpression":
  15659. case "SpreadElement":
  15660. case "SpreadProperty":
  15661. case "ExperimentalSpreadProperty":
  15662. case "TSAsExpression":
  15663. case "TSNonNullExpression":
  15664. return true;
  15665. case "MemberExpression":
  15666. return parent.object === node;
  15667. case "NewExpression":
  15668. case "CallExpression":
  15669. return parent.callee === node;
  15670. case "ConditionalExpression":
  15671. return parent.test === node;
  15672. default:
  15673. return false;
  15674. }
  15675. case "ArrayTypeAnnotation":
  15676. return parent.type === "NullableTypeAnnotation";
  15677. case "IntersectionTypeAnnotation":
  15678. case "UnionTypeAnnotation":
  15679. return parent.type === "ArrayTypeAnnotation" || parent.type === "NullableTypeAnnotation" || parent.type === "IntersectionTypeAnnotation" || parent.type === "UnionTypeAnnotation";
  15680. case "NullableTypeAnnotation":
  15681. return parent.type === "ArrayTypeAnnotation";
  15682. case "FunctionTypeAnnotation":
  15683. {
  15684. var ancestor = parent.type === "NullableTypeAnnotation" ? path$$1.getParentNode(1) : parent;
  15685. return ancestor.type === "UnionTypeAnnotation" || ancestor.type === "IntersectionTypeAnnotation" || ancestor.type === "ArrayTypeAnnotation" || // We should check ancestor's parent to know whether the parentheses
  15686. // are really needed, but since ??T doesn't make sense this check
  15687. // will almost never be true.
  15688. ancestor.type === "NullableTypeAnnotation";
  15689. }
  15690. case "StringLiteral":
  15691. case "NumericLiteral":
  15692. case "Literal":
  15693. if (typeof node.value === "string" && parent.type === "ExpressionStatement" && ( // TypeScript workaround for eslint/typescript-eslint-parser#267
  15694. // See corresponding workaround in printer.js case: "Literal"
  15695. options.parser !== "typescript" && !parent.directive || options.parser === "typescript" && options.originalText.substr(options.locStart(node) - 1, 1) === "(")) {
  15696. // To avoid becoming a directive
  15697. var _grandParent = path$$1.getParentNode(1);
  15698. return _grandParent.type === "Program" || _grandParent.type === "BlockStatement";
  15699. }
  15700. return parent.type === "MemberExpression" && typeof node.value === "number" && name === "object" && parent.object === node;
  15701. case "AssignmentExpression":
  15702. {
  15703. var _grandParent2 = path$$1.getParentNode(1);
  15704. if (parent.type === "ArrowFunctionExpression" && parent.body === node) {
  15705. return true;
  15706. } else if (parent.type === "ClassProperty" && parent.key === node && parent.computed) {
  15707. return false;
  15708. } else if (parent.type === "TSPropertySignature" && parent.name === node) {
  15709. return false;
  15710. } else if (parent.type === "ForStatement" && (parent.init === node || parent.update === node)) {
  15711. return false;
  15712. } else if (parent.type === "ExpressionStatement") {
  15713. return node.left.type === "ObjectPattern";
  15714. } else if (parent.type === "TSPropertySignature" && parent.key === node) {
  15715. return false;
  15716. } else if (parent.type === "AssignmentExpression") {
  15717. return false;
  15718. } else if (parent.type === "SequenceExpression" && _grandParent2 && _grandParent2.type === "ForStatement" && (_grandParent2.init === parent || _grandParent2.update === parent)) {
  15719. return false;
  15720. }
  15721. return true;
  15722. }
  15723. case "ConditionalExpression":
  15724. switch (parent.type) {
  15725. case "TaggedTemplateExpression":
  15726. case "UnaryExpression":
  15727. case "SpreadElement":
  15728. case "SpreadProperty":
  15729. case "ExperimentalSpreadProperty":
  15730. case "BinaryExpression":
  15731. case "LogicalExpression":
  15732. case "ExportDefaultDeclaration":
  15733. case "AwaitExpression":
  15734. case "JSXSpreadAttribute":
  15735. case "TSTypeAssertionExpression":
  15736. case "TypeCastExpression":
  15737. case "TSAsExpression":
  15738. case "TSNonNullExpression":
  15739. return true;
  15740. case "NewExpression":
  15741. case "CallExpression":
  15742. return name === "callee" && parent.callee === node;
  15743. case "ConditionalExpression":
  15744. return name === "test" && parent.test === node;
  15745. case "MemberExpression":
  15746. return name === "object" && parent.object === node;
  15747. default:
  15748. return false;
  15749. }
  15750. case "FunctionExpression":
  15751. switch (parent.type) {
  15752. case "CallExpression":
  15753. return name === "callee";
  15754. // Not strictly necessary, but it's clearer to the reader if IIFEs are wrapped in parentheses.
  15755. case "TaggedTemplateExpression":
  15756. return true;
  15757. // This is basically a kind of IIFE.
  15758. case "ExportDefaultDeclaration":
  15759. return true;
  15760. default:
  15761. return false;
  15762. }
  15763. case "ArrowFunctionExpression":
  15764. switch (parent.type) {
  15765. case "CallExpression":
  15766. return name === "callee";
  15767. case "NewExpression":
  15768. return name === "callee";
  15769. case "MemberExpression":
  15770. return name === "object";
  15771. case "TSAsExpression":
  15772. case "BindExpression":
  15773. case "TaggedTemplateExpression":
  15774. case "UnaryExpression":
  15775. case "LogicalExpression":
  15776. case "BinaryExpression":
  15777. case "AwaitExpression":
  15778. case "TSTypeAssertionExpression":
  15779. return true;
  15780. case "ConditionalExpression":
  15781. return name === "test";
  15782. default:
  15783. return false;
  15784. }
  15785. case "ClassExpression":
  15786. return parent.type === "ExportDefaultDeclaration";
  15787. case "OptionalMemberExpression":
  15788. return parent.type === "MemberExpression";
  15789. }
  15790. return false;
  15791. }
  15792. function isStatement(node) {
  15793. return node.type === "BlockStatement" || node.type === "BreakStatement" || node.type === "ClassBody" || node.type === "ClassDeclaration" || node.type === "ClassMethod" || node.type === "ClassProperty" || node.type === "ClassPrivateProperty" || node.type === "ContinueStatement" || node.type === "DebuggerStatement" || node.type === "DeclareClass" || node.type === "DeclareExportAllDeclaration" || node.type === "DeclareExportDeclaration" || node.type === "DeclareFunction" || node.type === "DeclareInterface" || node.type === "DeclareModule" || node.type === "DeclareModuleExports" || node.type === "DeclareVariable" || node.type === "DoWhileStatement" || node.type === "ExportAllDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExpressionStatement" || node.type === "ForAwaitStatement" || node.type === "ForInStatement" || node.type === "ForOfStatement" || node.type === "ForStatement" || node.type === "FunctionDeclaration" || node.type === "IfStatement" || node.type === "ImportDeclaration" || node.type === "InterfaceDeclaration" || node.type === "LabeledStatement" || node.type === "MethodDefinition" || node.type === "ReturnStatement" || node.type === "SwitchStatement" || node.type === "ThrowStatement" || node.type === "TryStatement" || node.type === "TSAbstractClassDeclaration" || node.type === "TSEnumDeclaration" || node.type === "TSImportEqualsDeclaration" || node.type === "TSInterfaceDeclaration" || node.type === "TSModuleDeclaration" || node.type === "TSNamespaceExportDeclaration" || node.type === "TypeAlias" || node.type === "VariableDeclaration" || node.type === "WhileStatement" || node.type === "WithStatement";
  15794. }
  15795. var needsParens_1 = needsParens;
  15796. var getParentExportDeclaration$1 = util$1.getParentExportDeclaration;
  15797. var isExportDeclaration$1 = util$1.isExportDeclaration;
  15798. var shouldFlatten$1 = util$1.shouldFlatten;
  15799. var getNextNonSpaceNonCommentCharacter$1 = util$1.getNextNonSpaceNonCommentCharacter;
  15800. var hasNewline$2 = util$1.hasNewline;
  15801. var hasNewlineInRange$1 = util$1.hasNewlineInRange;
  15802. var getLast$4 = util$1.getLast;
  15803. var getStringWidth$1 = util$1.getStringWidth;
  15804. var printString$1 = util$1.printString;
  15805. var printNumber$1 = util$1.printNumber;
  15806. var hasIgnoreComment$1 = util$1.hasIgnoreComment;
  15807. var skipWhitespace$1 = util$1.skipWhitespace;
  15808. var hasNodeIgnoreComment$1 = util$1.hasNodeIgnoreComment;
  15809. var getPenultimate$1 = util$1.getPenultimate;
  15810. var startsWithNoLookaheadToken$1 = util$1.startsWithNoLookaheadToken;
  15811. var getIndentSize$1 = util$1.getIndentSize;
  15812. var isNextLineEmpty$2 = utilShared.isNextLineEmpty;
  15813. var isNextLineEmptyAfterIndex$1 = utilShared.isNextLineEmptyAfterIndex;
  15814. var getNextNonSpaceNonCommentCharacterIndex$2 = utilShared.getNextNonSpaceNonCommentCharacterIndex;
  15815. var isIdentifierName = utils.keyword.isIdentifierNameES6;
  15816. var insertPragma = pragma.insertPragma;
  15817. var _require$$4$builders = doc.builders;
  15818. var concat$4 = _require$$4$builders.concat;
  15819. var join$2 = _require$$4$builders.join;
  15820. var line$3 = _require$$4$builders.line;
  15821. var hardline$3 = _require$$4$builders.hardline;
  15822. var softline$1 = _require$$4$builders.softline;
  15823. var literalline$1 = _require$$4$builders.literalline;
  15824. var group$1 = _require$$4$builders.group;
  15825. var indent$2 = _require$$4$builders.indent;
  15826. var align$1 = _require$$4$builders.align;
  15827. var conditionalGroup$1 = _require$$4$builders.conditionalGroup;
  15828. var fill$2 = _require$$4$builders.fill;
  15829. var ifBreak$1 = _require$$4$builders.ifBreak;
  15830. var breakParent$2 = _require$$4$builders.breakParent;
  15831. var lineSuffixBoundary$1 = _require$$4$builders.lineSuffixBoundary;
  15832. var addAlignmentToDoc$2 = _require$$4$builders.addAlignmentToDoc;
  15833. var dedent$2 = _require$$4$builders.dedent;
  15834. var _require$$4$utils = doc.utils;
  15835. var willBreak$1 = _require$$4$utils.willBreak;
  15836. var isLineNext$1 = _require$$4$utils.isLineNext;
  15837. var isEmpty$1 = _require$$4$utils.isEmpty;
  15838. var removeLines$1 = _require$$4$utils.removeLines;
  15839. var printDocToString$2 = doc.printer.printDocToString;
  15840. function shouldPrintComma(options, level) {
  15841. level = level || "es5";
  15842. switch (options.trailingComma) {
  15843. case "all":
  15844. if (level === "all") {
  15845. return true;
  15846. }
  15847. // fallthrough
  15848. case "es5":
  15849. if (level === "es5") {
  15850. return true;
  15851. }
  15852. // fallthrough
  15853. case "none":
  15854. default:
  15855. return false;
  15856. }
  15857. }
  15858. function genericPrint$1(path$$1, options, printPath, args) {
  15859. var node = path$$1.getValue();
  15860. var needsParens = false;
  15861. var linesWithoutParens = printPathNoParens(path$$1, options, printPath, args);
  15862. if (!node || isEmpty$1(linesWithoutParens)) {
  15863. return linesWithoutParens;
  15864. }
  15865. var decorators = [];
  15866. if (node.decorators && node.decorators.length > 0 && // If the parent node is an export declaration, it will be
  15867. // responsible for printing node.decorators.
  15868. !getParentExportDeclaration$1(path$$1)) {
  15869. var separator = hardline$3;
  15870. path$$1.each(function (decoratorPath) {
  15871. var decorator = decoratorPath.getValue();
  15872. if (decorator.expression) {
  15873. decorator = decorator.expression;
  15874. } else {
  15875. decorator = decorator.callee;
  15876. }
  15877. if (node.decorators.length === 1 && node.type !== "ClassDeclaration" && node.type !== "MethodDefinition" && node.type !== "ClassMethod" && (decorator.type === "Identifier" || decorator.type === "MemberExpression" || decorator.type === "OptionalMemberExpression" || (decorator.type === "CallExpression" || decorator.type === "OptionalCallExpression") && (decorator.arguments.length === 0 || decorator.arguments.length === 1 && (isStringLiteral(decorator.arguments[0]) || decorator.arguments[0].type === "Identifier" || decorator.arguments[0].type === "MemberExpression" || decorator.arguments[0].type === "OptionalMemberExpression")))) {
  15878. separator = line$3;
  15879. }
  15880. decorators.push(printPath(decoratorPath), separator);
  15881. }, "decorators");
  15882. } else if (isExportDeclaration$1(node) && node.declaration && node.declaration.decorators) {
  15883. // Export declarations are responsible for printing any decorators
  15884. // that logically apply to node.declaration.
  15885. path$$1.each(function (decoratorPath) {
  15886. var decorator = decoratorPath.getValue();
  15887. var prefix = decorator.type === "Decorator" ? "" : "@";
  15888. decorators.push(prefix, printPath(decoratorPath), hardline$3);
  15889. }, "declaration", "decorators");
  15890. } else {
  15891. // Nodes with decorators can't have parentheses, so we can avoid
  15892. // computing pathNeedsParens() except in this case.
  15893. needsParens = needsParens_1(path$$1, options);
  15894. }
  15895. var parts = [];
  15896. if (needsParens) {
  15897. parts.unshift("(");
  15898. }
  15899. parts.push(linesWithoutParens);
  15900. if (needsParens) {
  15901. parts.push(")");
  15902. }
  15903. if (decorators.length > 0) {
  15904. return group$1(concat$4(decorators.concat(parts)));
  15905. }
  15906. return concat$4(parts);
  15907. }
  15908. function hasPrettierIgnore(path$$1) {
  15909. return hasIgnoreComment$1(path$$1) || hasJsxIgnoreComment(path$$1);
  15910. }
  15911. function hasJsxIgnoreComment(path$$1) {
  15912. var node = path$$1.getValue();
  15913. var parent = path$$1.getParentNode();
  15914. if (!parent || !node || !isJSXNode(node) || !isJSXNode(parent)) {
  15915. return false;
  15916. } // Lookup the previous sibling, ignoring any empty JSXText elements
  15917. var index = parent.children.indexOf(node);
  15918. var prevSibling = null;
  15919. for (var i = index; i > 0; i--) {
  15920. var candidate = parent.children[i - 1];
  15921. if (candidate.type === "JSXText" && !isMeaningfulJSXText(candidate)) {
  15922. continue;
  15923. }
  15924. prevSibling = candidate;
  15925. break;
  15926. }
  15927. return prevSibling && prevSibling.type === "JSXExpressionContainer" && prevSibling.expression.type === "JSXEmptyExpression" && prevSibling.expression.comments && prevSibling.expression.comments.find(function (comment) {
  15928. return comment.value.trim() === "prettier-ignore";
  15929. });
  15930. } // The following is the shared logic for
  15931. // ternary operators, namely ConditionalExpression
  15932. // and TSConditionalType
  15933. function formatTernaryOperator(path$$1, options, print, operatorOptions) {
  15934. var n = path$$1.getValue();
  15935. var parts = [];
  15936. var operatorOpts = Object.assign({
  15937. beforeParts: function beforeParts() {
  15938. return [""];
  15939. },
  15940. afterParts: function afterParts() {
  15941. return [""];
  15942. },
  15943. shouldCheckJsx: true,
  15944. operatorName: "ConditionalExpression",
  15945. consequentNode: "consequent",
  15946. alternateNode: "alternate",
  15947. testNode: "test",
  15948. breakNested: true
  15949. }, operatorOptions || {}); // We print a ConditionalExpression in either "JSX mode" or "normal mode".
  15950. // See tests/jsx/conditional-expression.js for more info.
  15951. var jsxMode = false;
  15952. var parent = path$$1.getParentNode();
  15953. var forceNoIndent = parent.type === operatorOpts.operatorName; // Find the outermost non-ConditionalExpression parent, and the outermost
  15954. // ConditionalExpression parent. We'll use these to determine if we should
  15955. // print in JSX mode.
  15956. var currentParent;
  15957. var previousParent;
  15958. var i = 0;
  15959. do {
  15960. previousParent = currentParent || n;
  15961. currentParent = path$$1.getParentNode(i);
  15962. i++;
  15963. } while (currentParent && currentParent.type === operatorOpts.operatorName);
  15964. var firstNonConditionalParent = currentParent || parent;
  15965. var lastConditionalParent = previousParent;
  15966. if (operatorOpts.shouldCheckJsx && isJSXNode(n[operatorOpts.testNode]) || isJSXNode(n[operatorOpts.consequentNode]) || isJSXNode(n[operatorOpts.alternateNode]) || conditionalExpressionChainContainsJSX(lastConditionalParent)) {
  15967. jsxMode = true;
  15968. forceNoIndent = true; // Even though they don't need parens, we wrap (almost) everything in
  15969. // parens when using ?: within JSX, because the parens are analogous to
  15970. // curly braces in an if statement.
  15971. var wrap = function wrap(doc$$2) {
  15972. return concat$4([ifBreak$1("(", ""), indent$2(concat$4([softline$1, doc$$2])), softline$1, ifBreak$1(")", "")]);
  15973. }; // The only things we don't wrap are:
  15974. // * Nested conditional expressions in alternates
  15975. // * null
  15976. var isNull = function isNull(node) {
  15977. return node.type === "NullLiteral" || node.type === "Literal" && node.value === null;
  15978. };
  15979. parts.push(" ? ", isNull(n[operatorOpts.consequentNode]) ? path$$1.call(print, operatorOpts.consequentNode) : wrap(path$$1.call(print, operatorOpts.consequentNode)), " : ", n[operatorOpts.alternateNode].type === operatorOpts.operatorName || isNull(n[operatorOpts.alternateNode]) ? path$$1.call(print, operatorOpts.alternateNode) : wrap(path$$1.call(print, operatorOpts.alternateNode)));
  15980. } else {
  15981. // normal mode
  15982. var part = concat$4([line$3, "? ", n[operatorOpts.consequentNode].type === operatorOpts.operatorName ? ifBreak$1("", "(") : "", align$1(2, path$$1.call(print, operatorOpts.consequentNode)), n[operatorOpts.consequentNode].type === operatorOpts.operatorName ? ifBreak$1("", ")") : "", line$3, ": ", align$1(2, path$$1.call(print, operatorOpts.alternateNode))]);
  15983. parts.push(parent.type === operatorOpts.operatorName ? options.useTabs ? dedent$2(indent$2(part)) : align$1(Math.max(0, options.tabWidth - 2), part) : part);
  15984. } // We want a whole chain of ConditionalExpressions to all
  15985. // break if any of them break. That means we should only group around the
  15986. // outer-most ConditionalExpression.
  15987. var maybeGroup = function maybeGroup(doc$$2) {
  15988. return operatorOpts.breakNested ? parent === firstNonConditionalParent ? group$1(doc$$2) : doc$$2 : group$1(doc$$2);
  15989. }; // Always group in normal mode.
  15990. // Break the closing paren to keep the chain right after it:
  15991. // (a
  15992. // ? b
  15993. // : c
  15994. // ).call()
  15995. var breakClosingParen = !jsxMode && (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && !parent.computed;
  15996. return maybeGroup(concat$4([].concat(operatorOpts.beforeParts(), forceNoIndent ? concat$4(parts) : indent$2(concat$4(parts)), operatorOpts.afterParts(breakClosingParen))));
  15997. }
  15998. function getTypeScriptMappedTypeModifier(tokenNode, keyword) {
  15999. if (tokenNode.type === "TSPlusToken") {
  16000. return "+" + keyword;
  16001. } else if (tokenNode.type === "TSMinusToken") {
  16002. return "-" + keyword;
  16003. }
  16004. return keyword;
  16005. }
  16006. function printPathNoParens(path$$1, options, print, args) {
  16007. var n = path$$1.getValue();
  16008. var semi = options.semi ? ";" : "";
  16009. if (!n) {
  16010. return "";
  16011. }
  16012. if (typeof n === "string") {
  16013. return n;
  16014. }
  16015. var parts = [];
  16016. switch (n.type) {
  16017. case "File":
  16018. // Print @babel/parser's InterpreterDirective here so that
  16019. // leading comments on the `Program` node get printed after the hashbang.
  16020. if (n.program && n.program.interpreter) {
  16021. parts.push(path$$1.call(function (programPath) {
  16022. return programPath.call(print, "interpreter");
  16023. }, "program"));
  16024. }
  16025. parts.push(path$$1.call(print, "program"));
  16026. return concat$4(parts);
  16027. case "Program":
  16028. // Babel 6
  16029. if (n.directives) {
  16030. path$$1.each(function (childPath) {
  16031. parts.push(print(childPath), semi, hardline$3);
  16032. if (isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  16033. parts.push(hardline$3);
  16034. }
  16035. }, "directives");
  16036. }
  16037. parts.push(path$$1.call(function (bodyPath) {
  16038. return printStatementSequence(bodyPath, options, print);
  16039. }, "body"));
  16040. parts.push(comments.printDanglingComments(path$$1, options,
  16041. /* sameIndent */
  16042. true)); // Only force a trailing newline if there were any contents.
  16043. if (n.body.length || n.comments) {
  16044. parts.push(hardline$3);
  16045. }
  16046. return concat$4(parts);
  16047. // Babel extension.
  16048. case "EmptyStatement":
  16049. return "";
  16050. case "ExpressionStatement":
  16051. // Detect Flow-parsed directives
  16052. if (n.directive) {
  16053. return concat$4([nodeStr(n.expression, options, true), semi]);
  16054. } // Do not append semicolon after the only JSX element in a program
  16055. return concat$4([path$$1.call(print, "expression"), isTheOnlyJSXElementInMarkdown(options, path$$1) ? "" : semi]);
  16056. // Babel extension.
  16057. case "ParenthesizedExpression":
  16058. return concat$4(["(", path$$1.call(print, "expression"), ")"]);
  16059. case "AssignmentExpression":
  16060. return printAssignment(n.left, path$$1.call(print, "left"), concat$4([" ", n.operator]), n.right, path$$1.call(print, "right"), options);
  16061. case "BinaryExpression":
  16062. case "LogicalExpression":
  16063. {
  16064. var parent = path$$1.getParentNode();
  16065. var parentParent = path$$1.getParentNode(1);
  16066. var isInsideParenthesis = n !== parent.body && (parent.type === "IfStatement" || parent.type === "WhileStatement" || parent.type === "DoWhileStatement");
  16067. var _parts = printBinaryishExpressions(path$$1, print, options,
  16068. /* isNested */
  16069. false, isInsideParenthesis); // if (
  16070. // this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft
  16071. // ) {
  16072. //
  16073. // looks super weird, we want to break the children if the parent breaks
  16074. //
  16075. // if (
  16076. // this.hasPlugin("dynamicImports") &&
  16077. // this.lookahead().type === tt.parenLeft
  16078. // ) {
  16079. if (isInsideParenthesis) {
  16080. return concat$4(_parts);
  16081. } // Break between the parens in unaries or in a member expression, i.e.
  16082. //
  16083. // (
  16084. // a &&
  16085. // b &&
  16086. // c
  16087. // ).call()
  16088. if (parent.type === "UnaryExpression" || (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && !parent.computed) {
  16089. return group$1(concat$4([indent$2(concat$4([softline$1, concat$4(_parts)])), softline$1]));
  16090. } // Avoid indenting sub-expressions in some cases where the first sub-expression is already
  16091. // indented accordingly. We should indent sub-expressions where the first case isn't indented.
  16092. var shouldNotIndent = parent.type === "ReturnStatement" || parent.type === "JSXExpressionContainer" && parentParent.type === "JSXAttribute" || n === parent.body && parent.type === "ArrowFunctionExpression" || n !== parent.body && parent.type === "ForStatement" || parent.type === "ConditionalExpression" && parentParent.type !== "ReturnStatement";
  16093. var shouldIndentIfInlining = parent.type === "AssignmentExpression" || parent.type === "VariableDeclarator" || parent.type === "ClassProperty" || parent.type === "TSAbstractClassProperty" || parent.type === "ClassPrivateProperty" || parent.type === "ObjectProperty" || parent.type === "Property";
  16094. var samePrecedenceSubExpression = isBinaryish(n.left) && shouldFlatten$1(n.operator, n.left.operator);
  16095. if (shouldNotIndent || shouldInlineLogicalExpression(n) && !samePrecedenceSubExpression || !shouldInlineLogicalExpression(n) && shouldIndentIfInlining) {
  16096. return group$1(concat$4(_parts));
  16097. }
  16098. var rest = concat$4(_parts.slice(1));
  16099. return group$1(concat$4([// Don't include the initial expression in the indentation
  16100. // level. The first item is guaranteed to be the first
  16101. // left-most expression.
  16102. _parts.length > 0 ? _parts[0] : "", indent$2(rest)]));
  16103. }
  16104. case "AssignmentPattern":
  16105. return concat$4([path$$1.call(print, "left"), " = ", path$$1.call(print, "right")]);
  16106. case "TSTypeAssertionExpression":
  16107. {
  16108. var shouldBreakAfterCast = !(n.expression.type === "ArrayExpression" || n.expression.type === "ObjectExpression");
  16109. var castGroup = group$1(concat$4(["<", indent$2(concat$4([softline$1, path$$1.call(print, "typeAnnotation")])), softline$1, ">"]));
  16110. var exprContents = concat$4([ifBreak$1("("), indent$2(concat$4([softline$1, path$$1.call(print, "expression")])), softline$1, ifBreak$1(")")]);
  16111. if (shouldBreakAfterCast) {
  16112. return conditionalGroup$1([concat$4([castGroup, path$$1.call(print, "expression")]), concat$4([castGroup, group$1(exprContents, {
  16113. shouldBreak: true
  16114. })]), concat$4([castGroup, path$$1.call(print, "expression")])]);
  16115. }
  16116. return group$1(concat$4([castGroup, path$$1.call(print, "expression")]));
  16117. }
  16118. case "OptionalMemberExpression":
  16119. case "MemberExpression":
  16120. {
  16121. var _parent = path$$1.getParentNode();
  16122. var firstNonMemberParent;
  16123. var i = 0;
  16124. do {
  16125. firstNonMemberParent = path$$1.getParentNode(i);
  16126. i++;
  16127. } while (firstNonMemberParent && (firstNonMemberParent.type === "MemberExpression" || firstNonMemberParent.type === "OptionalMemberExpression" || firstNonMemberParent.type === "TSNonNullExpression"));
  16128. var shouldInline = firstNonMemberParent && (firstNonMemberParent.type === "NewExpression" || firstNonMemberParent.type === "BindExpression" || firstNonMemberParent.type === "VariableDeclarator" && firstNonMemberParent.id.type !== "Identifier" || firstNonMemberParent.type === "AssignmentExpression" && firstNonMemberParent.left.type !== "Identifier") || n.computed || n.object.type === "Identifier" && n.property.type === "Identifier" && _parent.type !== "MemberExpression" && _parent.type !== "OptionalMemberExpression";
  16129. return concat$4([path$$1.call(print, "object"), shouldInline ? printMemberLookup(path$$1, options, print) : group$1(indent$2(concat$4([softline$1, printMemberLookup(path$$1, options, print)])))]);
  16130. }
  16131. case "MetaProperty":
  16132. return concat$4([path$$1.call(print, "meta"), ".", path$$1.call(print, "property")]);
  16133. case "BindExpression":
  16134. if (n.object) {
  16135. parts.push(path$$1.call(print, "object"));
  16136. }
  16137. parts.push(group$1(indent$2(concat$4([softline$1, printBindExpressionCallee(path$$1, options, print)]))));
  16138. return concat$4(parts);
  16139. case "Identifier":
  16140. {
  16141. return concat$4([n.name, printOptionalToken(path$$1), printTypeAnnotation(path$$1, options, print)]);
  16142. }
  16143. case "SpreadElement":
  16144. case "SpreadElementPattern":
  16145. case "RestProperty":
  16146. case "ExperimentalRestProperty":
  16147. case "ExperimentalSpreadProperty":
  16148. case "SpreadProperty":
  16149. case "SpreadPropertyPattern":
  16150. case "RestElement":
  16151. case "ObjectTypeSpreadProperty":
  16152. return concat$4(["...", path$$1.call(print, "argument"), printTypeAnnotation(path$$1, options, print)]);
  16153. case "FunctionDeclaration":
  16154. case "FunctionExpression":
  16155. if (isNodeStartingWithDeclare(n, options)) {
  16156. parts.push("declare ");
  16157. }
  16158. parts.push(printFunctionDeclaration(path$$1, print, options));
  16159. if (!n.body) {
  16160. parts.push(semi);
  16161. }
  16162. return concat$4(parts);
  16163. case "ArrowFunctionExpression":
  16164. {
  16165. if (n.async) {
  16166. parts.push("async ");
  16167. }
  16168. if (shouldPrintParamsWithoutParens(path$$1, options)) {
  16169. parts.push(path$$1.call(print, "params", 0));
  16170. } else {
  16171. parts.push(group$1(concat$4([printFunctionParams(path$$1, print, options,
  16172. /* expandLast */
  16173. args && (args.expandLastArg || args.expandFirstArg),
  16174. /* printTypeParams */
  16175. true), printReturnType(path$$1, print, options)])));
  16176. }
  16177. var dangling = comments.printDanglingComments(path$$1, options,
  16178. /* sameIndent */
  16179. true, function (comment) {
  16180. var nextCharacter = getNextNonSpaceNonCommentCharacterIndex$2(options.originalText, comment, options);
  16181. return options.originalText.substr(nextCharacter, 2) === "=>";
  16182. });
  16183. if (dangling) {
  16184. parts.push(" ", dangling);
  16185. }
  16186. parts.push(" =>");
  16187. var body = path$$1.call(function (bodyPath) {
  16188. return print(bodyPath, args);
  16189. }, "body"); // We want to always keep these types of nodes on the same line
  16190. // as the arrow.
  16191. if (!hasLeadingOwnLineComment(options.originalText, n.body, options) && (n.body.type === "ArrayExpression" || n.body.type === "ObjectExpression" || n.body.type === "BlockStatement" || isJSXNode(n.body) || isTemplateOnItsOwnLine(n.body, options.originalText, options) || n.body.type === "ArrowFunctionExpression" || n.body.type === "DoExpression")) {
  16192. return group$1(concat$4([concat$4(parts), " ", body]));
  16193. } // We handle sequence expressions as the body of arrows specially,
  16194. // so that the required parentheses end up on their own lines.
  16195. if (n.body.type === "SequenceExpression") {
  16196. return group$1(concat$4([concat$4(parts), group$1(concat$4([" (", indent$2(concat$4([softline$1, body])), softline$1, ")"]))]));
  16197. } // if the arrow function is expanded as last argument, we are adding a
  16198. // level of indentation and need to add a softline to align the closing )
  16199. // with the opening (, or if it's inside a JSXExpression (e.g. an attribute)
  16200. // we should align the expression's closing } with the line with the opening {.
  16201. var shouldAddSoftLine = (args && args.expandLastArg || path$$1.getParentNode().type === "JSXExpressionContainer") && !(n.comments && n.comments.length);
  16202. var printTrailingComma = args && args.expandLastArg && shouldPrintComma(options, "all"); // In order to avoid confusion between
  16203. // a => a ? a : a
  16204. // a <= a ? a : a
  16205. var shouldAddParens = n.body.type === "ConditionalExpression" && !startsWithNoLookaheadToken$1(n.body,
  16206. /* forbidFunctionAndClass */
  16207. false);
  16208. return group$1(concat$4([concat$4(parts), group$1(concat$4([indent$2(concat$4([line$3, shouldAddParens ? ifBreak$1("", "(") : "", body, shouldAddParens ? ifBreak$1("", ")") : ""])), shouldAddSoftLine ? concat$4([ifBreak$1(printTrailingComma ? "," : ""), softline$1]) : ""]))]));
  16209. }
  16210. case "MethodDefinition":
  16211. case "TSAbstractMethodDefinition":
  16212. if (n.accessibility) {
  16213. parts.push(n.accessibility + " ");
  16214. }
  16215. if (n.static) {
  16216. parts.push("static ");
  16217. }
  16218. if (n.type === "TSAbstractMethodDefinition") {
  16219. parts.push("abstract ");
  16220. }
  16221. parts.push(printMethod(path$$1, options, print));
  16222. return concat$4(parts);
  16223. case "YieldExpression":
  16224. parts.push("yield");
  16225. if (n.delegate) {
  16226. parts.push("*");
  16227. }
  16228. if (n.argument) {
  16229. parts.push(" ", path$$1.call(print, "argument"));
  16230. }
  16231. return concat$4(parts);
  16232. case "AwaitExpression":
  16233. return concat$4(["await ", path$$1.call(print, "argument")]);
  16234. case "ImportSpecifier":
  16235. if (n.importKind) {
  16236. parts.push(path$$1.call(print, "importKind"), " ");
  16237. }
  16238. parts.push(path$$1.call(print, "imported"));
  16239. if (n.local && n.local.name !== n.imported.name) {
  16240. parts.push(" as ", path$$1.call(print, "local"));
  16241. }
  16242. return concat$4(parts);
  16243. case "ExportSpecifier":
  16244. parts.push(path$$1.call(print, "local"));
  16245. if (n.exported && n.exported.name !== n.local.name) {
  16246. parts.push(" as ", path$$1.call(print, "exported"));
  16247. }
  16248. return concat$4(parts);
  16249. case "ImportNamespaceSpecifier":
  16250. parts.push("* as ");
  16251. if (n.local) {
  16252. parts.push(path$$1.call(print, "local"));
  16253. } else if (n.id) {
  16254. parts.push(path$$1.call(print, "id"));
  16255. }
  16256. return concat$4(parts);
  16257. case "ImportDefaultSpecifier":
  16258. if (n.local) {
  16259. return path$$1.call(print, "local");
  16260. }
  16261. return path$$1.call(print, "id");
  16262. case "TSExportAssignment":
  16263. return concat$4(["export = ", path$$1.call(print, "expression"), semi]);
  16264. case "ExportDefaultDeclaration":
  16265. case "ExportNamedDeclaration":
  16266. return printExportDeclaration(path$$1, options, print);
  16267. case "ExportAllDeclaration":
  16268. parts.push("export ");
  16269. if (n.exportKind === "type") {
  16270. parts.push("type ");
  16271. }
  16272. parts.push("* from ", path$$1.call(print, "source"), semi);
  16273. return concat$4(parts);
  16274. case "ExportNamespaceSpecifier":
  16275. case "ExportDefaultSpecifier":
  16276. return path$$1.call(print, "exported");
  16277. case "ImportDeclaration":
  16278. {
  16279. parts.push("import ");
  16280. if (n.importKind && n.importKind !== "value") {
  16281. parts.push(n.importKind + " ");
  16282. }
  16283. var standalones = [];
  16284. var grouped = [];
  16285. if (n.specifiers && n.specifiers.length > 0) {
  16286. path$$1.each(function (specifierPath) {
  16287. var value = specifierPath.getValue();
  16288. if (value.type === "ImportDefaultSpecifier" || value.type === "ImportNamespaceSpecifier") {
  16289. standalones.push(print(specifierPath));
  16290. } else {
  16291. grouped.push(print(specifierPath));
  16292. }
  16293. }, "specifiers");
  16294. if (standalones.length > 0) {
  16295. parts.push(join$2(", ", standalones));
  16296. }
  16297. if (standalones.length > 0 && grouped.length > 0) {
  16298. parts.push(", ");
  16299. }
  16300. if (grouped.length === 1 && standalones.length === 0 && n.specifiers && !n.specifiers.some(function (node) {
  16301. return node.comments;
  16302. })) {
  16303. parts.push(concat$4(["{", options.bracketSpacing ? " " : "", concat$4(grouped), options.bracketSpacing ? " " : "", "}"]));
  16304. } else if (grouped.length >= 1) {
  16305. parts.push(group$1(concat$4(["{", indent$2(concat$4([options.bracketSpacing ? line$3 : softline$1, join$2(concat$4([",", line$3]), grouped)])), ifBreak$1(shouldPrintComma(options) ? "," : ""), options.bracketSpacing ? line$3 : softline$1, "}"])));
  16306. }
  16307. parts.push(" from ");
  16308. } else if (n.importKind && n.importKind === "type" || // import {} from 'x'
  16309. /{\s*}/.test(options.originalText.slice(options.locStart(n), options.locStart(n.source)))) {
  16310. parts.push("{} from ");
  16311. }
  16312. parts.push(path$$1.call(print, "source"), semi);
  16313. return concat$4(parts);
  16314. }
  16315. case "Import":
  16316. return "import";
  16317. case "BlockStatement":
  16318. {
  16319. var naked = path$$1.call(function (bodyPath) {
  16320. return printStatementSequence(bodyPath, options, print);
  16321. }, "body");
  16322. var hasContent = n.body.find(function (node) {
  16323. return node.type !== "EmptyStatement";
  16324. });
  16325. var hasDirectives = n.directives && n.directives.length > 0;
  16326. var _parent2 = path$$1.getParentNode();
  16327. var _parentParent = path$$1.getParentNode(1);
  16328. if (!hasContent && !hasDirectives && !hasDanglingComments(n) && (_parent2.type === "ArrowFunctionExpression" || _parent2.type === "FunctionExpression" || _parent2.type === "FunctionDeclaration" || _parent2.type === "ObjectMethod" || _parent2.type === "ClassMethod" || _parent2.type === "ForStatement" || _parent2.type === "WhileStatement" || _parent2.type === "DoWhileStatement" || _parent2.type === "DoExpression" || _parent2.type === "CatchClause" && !_parentParent.finalizer)) {
  16329. return "{}";
  16330. }
  16331. parts.push("{"); // Babel 6
  16332. if (hasDirectives) {
  16333. path$$1.each(function (childPath) {
  16334. parts.push(indent$2(concat$4([hardline$3, print(childPath), semi])));
  16335. if (isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  16336. parts.push(hardline$3);
  16337. }
  16338. }, "directives");
  16339. }
  16340. if (hasContent) {
  16341. parts.push(indent$2(concat$4([hardline$3, naked])));
  16342. }
  16343. parts.push(comments.printDanglingComments(path$$1, options));
  16344. parts.push(hardline$3, "}");
  16345. return concat$4(parts);
  16346. }
  16347. case "ReturnStatement":
  16348. parts.push("return");
  16349. if (n.argument) {
  16350. if (returnArgumentHasLeadingComment(options, n.argument)) {
  16351. parts.push(concat$4([" (", indent$2(concat$4([hardline$3, path$$1.call(print, "argument")])), hardline$3, ")"]));
  16352. } else if (n.argument.type === "LogicalExpression" || n.argument.type === "BinaryExpression" || n.argument.type === "SequenceExpression") {
  16353. parts.push(group$1(concat$4([ifBreak$1(" (", " "), indent$2(concat$4([softline$1, path$$1.call(print, "argument")])), softline$1, ifBreak$1(")")])));
  16354. } else {
  16355. parts.push(" ", path$$1.call(print, "argument"));
  16356. }
  16357. }
  16358. if (hasDanglingComments(n)) {
  16359. parts.push(" ", comments.printDanglingComments(path$$1, options,
  16360. /* sameIndent */
  16361. true));
  16362. }
  16363. parts.push(semi);
  16364. return concat$4(parts);
  16365. case "NewExpression":
  16366. case "OptionalCallExpression":
  16367. case "CallExpression":
  16368. {
  16369. var isNew = n.type === "NewExpression";
  16370. var optional = printOptionalToken(path$$1);
  16371. if ( // We want to keep CommonJS- and AMD-style require calls, and AMD-style
  16372. // define calls, as a unit.
  16373. // e.g. `define(["some/lib", (lib) => {`
  16374. !isNew && n.callee.type === "Identifier" && (n.callee.name === "require" || n.callee.name === "define") || n.callee.type === "Import" || // Template literals as single arguments
  16375. n.arguments.length === 1 && isTemplateOnItsOwnLine(n.arguments[0], options.originalText, options) || // Keep test declarations on a single line
  16376. // e.g. `it('long name', () => {`
  16377. !isNew && isTestCall(n, path$$1.getParentNode())) {
  16378. return concat$4([isNew ? "new " : "", path$$1.call(print, "callee"), optional, printFunctionTypeParameters(path$$1, options, print), concat$4(["(", join$2(", ", path$$1.map(print, "arguments")), ")"])]);
  16379. } // We detect calls on member lookups and possibly print them in a
  16380. // special chain format. See `printMemberChain` for more info.
  16381. if (!isNew && isMemberish(n.callee)) {
  16382. return printMemberChain(path$$1, options, print);
  16383. }
  16384. return concat$4([isNew ? "new " : "", path$$1.call(print, "callee"), optional, printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)]);
  16385. }
  16386. case "TSInterfaceDeclaration":
  16387. if (isNodeStartingWithDeclare(n, options)) {
  16388. parts.push("declare ");
  16389. }
  16390. parts.push(n.abstract ? "abstract " : "", printTypeScriptModifiers(path$$1, options, print), "interface ", path$$1.call(print, "id"), n.typeParameters ? path$$1.call(print, "typeParameters") : "", " ");
  16391. if (n.heritage.length) {
  16392. parts.push(group$1(indent$2(concat$4([softline$1, "extends ", indent$2(join$2(concat$4([",", line$3]), path$$1.map(print, "heritage"))), " "]))));
  16393. }
  16394. parts.push(path$$1.call(print, "body"));
  16395. return concat$4(parts);
  16396. case "ObjectExpression":
  16397. case "ObjectPattern":
  16398. case "ObjectTypeAnnotation":
  16399. case "TSInterfaceBody":
  16400. case "TSTypeLiteral":
  16401. {
  16402. var isTypeAnnotation = n.type === "ObjectTypeAnnotation";
  16403. var _parent3 = path$$1.getParentNode(0);
  16404. var shouldBreak = n.type === "TSInterfaceBody" || n.type === "ObjectPattern" && _parent3.type !== "FunctionDeclaration" && _parent3.type !== "FunctionExpression" && _parent3.type !== "ArrowFunctionExpression" && _parent3.type !== "AssignmentPattern" && _parent3.type !== "CatchClause" && n.properties.some(function (property) {
  16405. return property.value && (property.value.type === "ObjectPattern" || property.value.type === "ArrayPattern");
  16406. }) || n.type !== "ObjectPattern" && hasNewlineInRange$1(options.originalText, options.locStart(n), options.locEnd(n));
  16407. var isFlowInterfaceLikeBody = isTypeAnnotation && _parent3 && (_parent3.type === "InterfaceDeclaration" || _parent3.type === "DeclareInterface" || _parent3.type === "DeclareClass") && path$$1.getName() === "body";
  16408. var separator = isFlowInterfaceLikeBody ? ";" : n.type === "TSInterfaceBody" || n.type === "TSTypeLiteral" ? ifBreak$1(semi, ";") : ",";
  16409. var fields = [];
  16410. var leftBrace = n.exact ? "{|" : "{";
  16411. var rightBrace = n.exact ? "|}" : "}";
  16412. var propertiesField;
  16413. if (n.type === "TSTypeLiteral") {
  16414. propertiesField = "members";
  16415. } else if (n.type === "TSInterfaceBody") {
  16416. propertiesField = "body";
  16417. } else {
  16418. propertiesField = "properties";
  16419. }
  16420. if (isTypeAnnotation) {
  16421. fields.push("indexers", "callProperties");
  16422. }
  16423. fields.push(propertiesField); // Unfortunately, things are grouped together in the ast can be
  16424. // interleaved in the source code. So we need to reorder them before
  16425. // printing them.
  16426. var propsAndLoc = [];
  16427. fields.forEach(function (field) {
  16428. path$$1.each(function (childPath) {
  16429. var node = childPath.getValue();
  16430. propsAndLoc.push({
  16431. node: node,
  16432. printed: print(childPath),
  16433. loc: options.locStart(node)
  16434. });
  16435. }, field);
  16436. });
  16437. var separatorParts = [];
  16438. var props = propsAndLoc.sort(function (a, b) {
  16439. return a.loc - b.loc;
  16440. }).map(function (prop) {
  16441. var result = concat$4(separatorParts.concat(group$1(prop.printed)));
  16442. separatorParts = [separator, line$3];
  16443. if (prop.node.type === "TSPropertySignature" && hasNodeIgnoreComment$1(prop.node)) {
  16444. separatorParts.shift();
  16445. }
  16446. if (isNextLineEmpty$2(options.originalText, prop.node, options)) {
  16447. separatorParts.push(hardline$3);
  16448. }
  16449. return result;
  16450. });
  16451. var lastElem = getLast$4(n[propertiesField]);
  16452. var canHaveTrailingSeparator = !(lastElem && (lastElem.type === "RestProperty" || lastElem.type === "RestElement" || lastElem.type === "ExperimentalRestProperty" || hasNodeIgnoreComment$1(lastElem)));
  16453. var content;
  16454. if (props.length === 0 && !n.typeAnnotation) {
  16455. if (!hasDanglingComments(n)) {
  16456. return concat$4([leftBrace, rightBrace]);
  16457. }
  16458. content = group$1(concat$4([leftBrace, comments.printDanglingComments(path$$1, options), softline$1, rightBrace, printOptionalToken(path$$1)]));
  16459. } else {
  16460. content = concat$4([leftBrace, indent$2(concat$4([options.bracketSpacing ? line$3 : softline$1, concat$4(props)])), ifBreak$1(canHaveTrailingSeparator && (separator !== "," || shouldPrintComma(options)) ? separator : ""), concat$4([options.bracketSpacing ? line$3 : softline$1, rightBrace]), printOptionalToken(path$$1), printTypeAnnotation(path$$1, options, print)]);
  16461. } // If we inline the object as first argument of the parent, we don't want
  16462. // to create another group so that the object breaks before the return
  16463. // type
  16464. var parentParentParent = path$$1.getParentNode(2);
  16465. if (n.type === "ObjectPattern" && _parent3 && shouldHugArguments(_parent3) && _parent3.params[0] === n || shouldHugType(n) && parentParentParent && shouldHugArguments(parentParentParent) && parentParentParent.params[0].typeAnnotation && parentParentParent.params[0].typeAnnotation.typeAnnotation === n) {
  16466. return content;
  16467. }
  16468. return group$1(content, {
  16469. shouldBreak
  16470. });
  16471. }
  16472. // Babel 6
  16473. case "ObjectProperty": // Non-standard AST node type.
  16474. case "Property":
  16475. if (n.method || n.kind === "get" || n.kind === "set") {
  16476. return printMethod(path$$1, options, print);
  16477. }
  16478. if (n.shorthand) {
  16479. parts.push(path$$1.call(print, "value"));
  16480. } else {
  16481. var printedLeft;
  16482. if (n.computed) {
  16483. printedLeft = concat$4(["[", path$$1.call(print, "key"), "]"]);
  16484. } else {
  16485. printedLeft = printPropertyKey(path$$1, options, print);
  16486. }
  16487. parts.push(printAssignment(n.key, printedLeft, ":", n.value, path$$1.call(print, "value"), options));
  16488. }
  16489. return concat$4(parts);
  16490. // Babel 6
  16491. case "ClassMethod":
  16492. if (n.static) {
  16493. parts.push("static ");
  16494. }
  16495. parts = parts.concat(printObjectMethod(path$$1, options, print));
  16496. return concat$4(parts);
  16497. // Babel 6
  16498. case "ObjectMethod":
  16499. return printObjectMethod(path$$1, options, print);
  16500. case "Decorator":
  16501. return concat$4(["@", path$$1.call(print, "expression"), path$$1.call(print, "callee")]);
  16502. case "ArrayExpression":
  16503. case "ArrayPattern":
  16504. if (n.elements.length === 0) {
  16505. if (!hasDanglingComments(n)) {
  16506. parts.push("[]");
  16507. } else {
  16508. parts.push(group$1(concat$4(["[", comments.printDanglingComments(path$$1, options), softline$1, "]"])));
  16509. }
  16510. } else {
  16511. var _lastElem = getLast$4(n.elements);
  16512. var canHaveTrailingComma = !(_lastElem && _lastElem.type === "RestElement"); // JavaScript allows you to have empty elements in an array which
  16513. // changes its length based on the number of commas. The algorithm
  16514. // is that if the last argument is null, we need to force insert
  16515. // a comma to ensure JavaScript recognizes it.
  16516. // [,].length === 1
  16517. // [1,].length === 1
  16518. // [1,,].length === 2
  16519. //
  16520. // Note that getLast returns null if the array is empty, but
  16521. // we already check for an empty array just above so we are safe
  16522. var needsForcedTrailingComma = canHaveTrailingComma && _lastElem === null;
  16523. parts.push(group$1(concat$4(["[", indent$2(concat$4([softline$1, printArrayItems(path$$1, options, "elements", print)])), needsForcedTrailingComma ? "," : "", ifBreak$1(canHaveTrailingComma && !needsForcedTrailingComma && shouldPrintComma(options) ? "," : ""), comments.printDanglingComments(path$$1, options,
  16524. /* sameIndent */
  16525. true), softline$1, "]"])));
  16526. }
  16527. parts.push(printOptionalToken(path$$1), printTypeAnnotation(path$$1, options, print));
  16528. return concat$4(parts);
  16529. case "SequenceExpression":
  16530. {
  16531. var _parent4 = path$$1.getParentNode(0);
  16532. if (_parent4.type === "ExpressionStatement" || _parent4.type === "ForStatement") {
  16533. // For ExpressionStatements and for-loop heads, which are among
  16534. // the few places a SequenceExpression appears unparenthesized, we want
  16535. // to indent expressions after the first.
  16536. var _parts2 = [];
  16537. path$$1.each(function (p) {
  16538. if (p.getName() === 0) {
  16539. _parts2.push(print(p));
  16540. } else {
  16541. _parts2.push(",", indent$2(concat$4([line$3, print(p)])));
  16542. }
  16543. }, "expressions");
  16544. return group$1(concat$4(_parts2));
  16545. }
  16546. return group$1(concat$4([join$2(concat$4([",", line$3]), path$$1.map(print, "expressions"))]));
  16547. }
  16548. case "ThisExpression":
  16549. return "this";
  16550. case "Super":
  16551. return "super";
  16552. case "NullLiteral":
  16553. // Babel 6 Literal split
  16554. return "null";
  16555. case "RegExpLiteral":
  16556. // Babel 6 Literal split
  16557. return printRegex(n);
  16558. case "NumericLiteral":
  16559. // Babel 6 Literal split
  16560. return printNumber$1(n.extra.raw);
  16561. case "BooleanLiteral": // Babel 6 Literal split
  16562. case "StringLiteral": // Babel 6 Literal split
  16563. case "Literal":
  16564. {
  16565. if (n.regex) {
  16566. return printRegex(n.regex);
  16567. }
  16568. if (typeof n.value === "number") {
  16569. return printNumber$1(n.raw);
  16570. }
  16571. if (typeof n.value !== "string") {
  16572. return "" + n.value;
  16573. } // TypeScript workaround for eslint/typescript-eslint-parser#267
  16574. // See corresponding workaround in needs-parens.js
  16575. var grandParent = path$$1.getParentNode(1);
  16576. var isTypeScriptDirective = options.parser === "typescript" && typeof n.value === "string" && grandParent && (grandParent.type === "Program" || grandParent.type === "BlockStatement");
  16577. return nodeStr(n, options, isTypeScriptDirective);
  16578. }
  16579. case "Directive":
  16580. return path$$1.call(print, "value");
  16581. // Babel 6
  16582. case "DirectiveLiteral":
  16583. return nodeStr(n, options);
  16584. case "UnaryExpression":
  16585. parts.push(n.operator);
  16586. if (/[a-z]$/.test(n.operator)) {
  16587. parts.push(" ");
  16588. }
  16589. parts.push(path$$1.call(print, "argument"));
  16590. return concat$4(parts);
  16591. case "UpdateExpression":
  16592. parts.push(path$$1.call(print, "argument"), n.operator);
  16593. if (n.prefix) {
  16594. parts.reverse();
  16595. }
  16596. return concat$4(parts);
  16597. case "ConditionalExpression":
  16598. return formatTernaryOperator(path$$1, options, print, {
  16599. beforeParts: function beforeParts() {
  16600. return [path$$1.call(print, "test")];
  16601. },
  16602. afterParts: function afterParts(breakClosingParen) {
  16603. return [breakClosingParen ? softline$1 : ""];
  16604. }
  16605. });
  16606. case "VariableDeclaration":
  16607. {
  16608. var printed = path$$1.map(function (childPath) {
  16609. return print(childPath);
  16610. }, "declarations"); // We generally want to terminate all variable declarations with a
  16611. // semicolon, except when they in the () part of for loops.
  16612. var parentNode = path$$1.getParentNode();
  16613. var isParentForLoop = parentNode.type === "ForStatement" || parentNode.type === "ForInStatement" || parentNode.type === "ForOfStatement" || parentNode.type === "ForAwaitStatement";
  16614. var hasValue = n.declarations.some(function (decl) {
  16615. return decl.init;
  16616. });
  16617. var firstVariable;
  16618. if (printed.length === 1) {
  16619. firstVariable = printed[0];
  16620. } else if (printed.length > 1) {
  16621. // Indent first var to comply with eslint one-var rule
  16622. firstVariable = indent$2(printed[0]);
  16623. }
  16624. parts = [isNodeStartingWithDeclare(n, options) ? "declare " : "", n.kind, firstVariable ? concat$4([" ", firstVariable]) : "", indent$2(concat$4(printed.slice(1).map(function (p) {
  16625. return concat$4([",", hasValue && !isParentForLoop ? hardline$3 : line$3, p]);
  16626. })))];
  16627. if (!(isParentForLoop && parentNode.body !== n)) {
  16628. parts.push(semi);
  16629. }
  16630. return group$1(concat$4(parts));
  16631. }
  16632. case "VariableDeclarator":
  16633. return printAssignment(n.id, concat$4([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]), " =", n.init, n.init && path$$1.call(print, "init"), options);
  16634. case "WithStatement":
  16635. return group$1(concat$4(["with (", path$$1.call(print, "object"), ")", adjustClause(n.body, path$$1.call(print, "body"))]));
  16636. case "IfStatement":
  16637. {
  16638. var con = adjustClause(n.consequent, path$$1.call(print, "consequent"));
  16639. var opening = group$1(concat$4(["if (", group$1(concat$4([indent$2(concat$4([softline$1, path$$1.call(print, "test")])), softline$1])), ")", con]));
  16640. parts.push(opening);
  16641. if (n.alternate) {
  16642. var commentOnOwnLine = hasTrailingComment(n.consequent) && n.consequent.comments.some(function (comment) {
  16643. return comment.trailing && !comments$3.isBlockComment(comment);
  16644. }) || needsHardlineAfterDanglingComment(n);
  16645. var elseOnSameLine = n.consequent.type === "BlockStatement" && !commentOnOwnLine;
  16646. parts.push(elseOnSameLine ? " " : hardline$3);
  16647. if (hasDanglingComments(n)) {
  16648. parts.push(comments.printDanglingComments(path$$1, options, true), commentOnOwnLine ? hardline$3 : " ");
  16649. }
  16650. parts.push("else", group$1(adjustClause(n.alternate, path$$1.call(print, "alternate"), n.alternate.type === "IfStatement")));
  16651. }
  16652. return concat$4(parts);
  16653. }
  16654. case "ForStatement":
  16655. {
  16656. var _body = adjustClause(n.body, path$$1.call(print, "body")); // We want to keep dangling comments above the loop to stay consistent.
  16657. // Any comment positioned between the for statement and the parentheses
  16658. // is going to be printed before the statement.
  16659. var _dangling = comments.printDanglingComments(path$$1, options,
  16660. /* sameLine */
  16661. true);
  16662. var printedComments = _dangling ? concat$4([_dangling, softline$1]) : "";
  16663. if (!n.init && !n.test && !n.update) {
  16664. return concat$4([printedComments, group$1(concat$4(["for (;;)", _body]))]);
  16665. }
  16666. return concat$4([printedComments, group$1(concat$4(["for (", group$1(concat$4([indent$2(concat$4([softline$1, path$$1.call(print, "init"), ";", line$3, path$$1.call(print, "test"), ";", line$3, path$$1.call(print, "update")])), softline$1])), ")", _body]))]);
  16667. }
  16668. case "WhileStatement":
  16669. return group$1(concat$4(["while (", group$1(concat$4([indent$2(concat$4([softline$1, path$$1.call(print, "test")])), softline$1])), ")", adjustClause(n.body, path$$1.call(print, "body"))]));
  16670. case "ForInStatement":
  16671. // Note: esprima can't actually parse "for each (".
  16672. return group$1(concat$4([n.each ? "for each (" : "for (", path$$1.call(print, "left"), " in ", path$$1.call(print, "right"), ")", adjustClause(n.body, path$$1.call(print, "body"))]));
  16673. case "ForOfStatement":
  16674. case "ForAwaitStatement":
  16675. {
  16676. // Babylon 7 removed ForAwaitStatement in favor of ForOfStatement
  16677. // with `"await": true`:
  16678. // https://github.com/estree/estree/pull/138
  16679. var isAwait = n.type === "ForAwaitStatement" || n.await;
  16680. return group$1(concat$4(["for", isAwait ? " await" : "", " (", path$$1.call(print, "left"), " of ", path$$1.call(print, "right"), ")", adjustClause(n.body, path$$1.call(print, "body"))]));
  16681. }
  16682. case "DoWhileStatement":
  16683. {
  16684. var clause = adjustClause(n.body, path$$1.call(print, "body"));
  16685. var doBody = group$1(concat$4(["do", clause]));
  16686. parts = [doBody];
  16687. if (n.body.type === "BlockStatement") {
  16688. parts.push(" ");
  16689. } else {
  16690. parts.push(hardline$3);
  16691. }
  16692. parts.push("while (");
  16693. parts.push(group$1(concat$4([indent$2(concat$4([softline$1, path$$1.call(print, "test")])), softline$1])), ")", semi);
  16694. return concat$4(parts);
  16695. }
  16696. case "DoExpression":
  16697. return concat$4(["do ", path$$1.call(print, "body")]);
  16698. case "BreakStatement":
  16699. parts.push("break");
  16700. if (n.label) {
  16701. parts.push(" ", path$$1.call(print, "label"));
  16702. }
  16703. parts.push(semi);
  16704. return concat$4(parts);
  16705. case "ContinueStatement":
  16706. parts.push("continue");
  16707. if (n.label) {
  16708. parts.push(" ", path$$1.call(print, "label"));
  16709. }
  16710. parts.push(semi);
  16711. return concat$4(parts);
  16712. case "LabeledStatement":
  16713. if (n.body.type === "EmptyStatement") {
  16714. return concat$4([path$$1.call(print, "label"), ":;"]);
  16715. }
  16716. return concat$4([path$$1.call(print, "label"), ": ", path$$1.call(print, "body")]);
  16717. case "TryStatement":
  16718. return concat$4(["try ", path$$1.call(print, "block"), n.handler ? concat$4([" ", path$$1.call(print, "handler")]) : "", n.finalizer ? concat$4([" finally ", path$$1.call(print, "finalizer")]) : ""]);
  16719. case "CatchClause":
  16720. return concat$4(["catch ", n.param ? concat$4(["(", path$$1.call(print, "param"), ") "]) : "", path$$1.call(print, "body")]);
  16721. case "ThrowStatement":
  16722. return concat$4(["throw ", path$$1.call(print, "argument"), semi]);
  16723. // Note: ignoring n.lexical because it has no printing consequences.
  16724. case "SwitchStatement":
  16725. return concat$4([group$1(concat$4(["switch (", indent$2(concat$4([softline$1, path$$1.call(print, "discriminant")])), softline$1, ")"])), " {", n.cases.length > 0 ? indent$2(concat$4([hardline$3, join$2(hardline$3, path$$1.map(function (casePath) {
  16726. var caseNode = casePath.getValue();
  16727. return concat$4([casePath.call(print), n.cases.indexOf(caseNode) !== n.cases.length - 1 && isNextLineEmpty$2(options.originalText, caseNode, options) ? hardline$3 : ""]);
  16728. }, "cases"))])) : "", hardline$3, "}"]);
  16729. case "SwitchCase":
  16730. {
  16731. if (n.test) {
  16732. parts.push("case ", path$$1.call(print, "test"), ":");
  16733. } else {
  16734. parts.push("default:");
  16735. }
  16736. var consequent = n.consequent.filter(function (node) {
  16737. return node.type !== "EmptyStatement";
  16738. });
  16739. if (consequent.length > 0) {
  16740. var cons = path$$1.call(function (consequentPath) {
  16741. return printStatementSequence(consequentPath, options, print);
  16742. }, "consequent");
  16743. parts.push(consequent.length === 1 && consequent[0].type === "BlockStatement" ? concat$4([" ", cons]) : indent$2(concat$4([hardline$3, cons])));
  16744. }
  16745. return concat$4(parts);
  16746. }
  16747. // JSX extensions below.
  16748. case "DebuggerStatement":
  16749. return concat$4(["debugger", semi]);
  16750. case "JSXAttribute":
  16751. parts.push(path$$1.call(print, "name"));
  16752. if (n.value) {
  16753. var res;
  16754. if (isStringLiteral(n.value)) {
  16755. var value = rawText(n.value);
  16756. res = '"' + value.slice(1, -1).replace(/"/g, "&quot;") + '"';
  16757. } else {
  16758. res = path$$1.call(print, "value");
  16759. }
  16760. parts.push("=", res);
  16761. }
  16762. return concat$4(parts);
  16763. case "JSXIdentifier":
  16764. // Can be removed when this is fixed:
  16765. // https://github.com/eslint/typescript-eslint-parser/issues/337
  16766. if (!n.name) {
  16767. return "this";
  16768. }
  16769. return "" + n.name;
  16770. case "JSXNamespacedName":
  16771. return join$2(":", [path$$1.call(print, "namespace"), path$$1.call(print, "name")]);
  16772. case "JSXMemberExpression":
  16773. return join$2(".", [path$$1.call(print, "object"), path$$1.call(print, "property")]);
  16774. case "TSQualifiedName":
  16775. return join$2(".", [path$$1.call(print, "left"), path$$1.call(print, "right")]);
  16776. case "JSXSpreadAttribute":
  16777. case "JSXSpreadChild":
  16778. {
  16779. return concat$4(["{", path$$1.call(function (p) {
  16780. var printed = concat$4(["...", print(p)]);
  16781. var n = p.getValue();
  16782. if (!n.comments || !n.comments.length) {
  16783. return printed;
  16784. }
  16785. return concat$4([indent$2(concat$4([softline$1, comments.printComments(p, function () {
  16786. return printed;
  16787. }, options)])), softline$1]);
  16788. }, n.type === "JSXSpreadAttribute" ? "argument" : "expression"), "}"]);
  16789. }
  16790. case "JSXExpressionContainer":
  16791. {
  16792. var _parent5 = path$$1.getParentNode(0);
  16793. var preventInline = _parent5.type === "JSXAttribute" && n.expression.comments && n.expression.comments.length > 0;
  16794. var _shouldInline = !preventInline && (n.expression.type === "ArrayExpression" || n.expression.type === "ObjectExpression" || n.expression.type === "ArrowFunctionExpression" || n.expression.type === "CallExpression" || n.expression.type === "OptionalCallExpression" || n.expression.type === "FunctionExpression" || n.expression.type === "JSXEmptyExpression" || n.expression.type === "TemplateLiteral" || n.expression.type === "TaggedTemplateExpression" || n.expression.type === "DoExpression" || isJSXNode(_parent5) && (n.expression.type === "ConditionalExpression" || isBinaryish(n.expression)));
  16795. if (_shouldInline) {
  16796. return group$1(concat$4(["{", path$$1.call(print, "expression"), lineSuffixBoundary$1, "}"]));
  16797. }
  16798. return group$1(concat$4(["{", indent$2(concat$4([softline$1, path$$1.call(print, "expression")])), softline$1, lineSuffixBoundary$1, "}"]));
  16799. }
  16800. case "JSXFragment":
  16801. case "TSJsxFragment":
  16802. case "JSXElement":
  16803. {
  16804. var elem = comments.printComments(path$$1, function () {
  16805. return printJSXElement(path$$1, options, print);
  16806. }, options);
  16807. return maybeWrapJSXElementInParens(path$$1, elem);
  16808. }
  16809. case "JSXOpeningElement":
  16810. {
  16811. var _n = path$$1.getValue();
  16812. var nameHasComments = _n.name && _n.name.comments && _n.name.comments.length > 0; // Don't break self-closing elements with no attributes and no comments
  16813. if (_n.selfClosing && !_n.attributes.length && !nameHasComments) {
  16814. return concat$4(["<", path$$1.call(print, "name"), path$$1.call(print, "typeParameters"), " />"]);
  16815. } // don't break up opening elements with a single long text attribute
  16816. if (_n.attributes && _n.attributes.length === 1 && _n.attributes[0].value && isStringLiteral(_n.attributes[0].value) && !_n.attributes[0].value.value.includes("\n") && // We should break for the following cases:
  16817. // <div
  16818. // // comment
  16819. // attr="value"
  16820. // >
  16821. // <div
  16822. // attr="value"
  16823. // // comment
  16824. // >
  16825. !nameHasComments && (!_n.attributes[0].comments || !_n.attributes[0].comments.length)) {
  16826. return group$1(concat$4(["<", path$$1.call(print, "name"), path$$1.call(print, "typeParameters"), " ", concat$4(path$$1.map(print, "attributes")), _n.selfClosing ? " />" : ">"]));
  16827. }
  16828. var lastAttrHasTrailingComments = _n.attributes.length && hasTrailingComment(getLast$4(_n.attributes));
  16829. var bracketSameLine = options.jsxBracketSameLine && ( // We should print the bracket in a new line for the following cases:
  16830. // <div
  16831. // // comment
  16832. // >
  16833. // <div
  16834. // attr // comment
  16835. // >
  16836. !nameHasComments || _n.attributes.length) && !lastAttrHasTrailingComments; // We should print the opening element expanded if any prop value is a
  16837. // string literal with newlines
  16838. var _shouldBreak = _n.attributes && _n.attributes.some(function (attr) {
  16839. return attr.value && isStringLiteral(attr.value) && attr.value.value.includes("\n");
  16840. });
  16841. return group$1(concat$4(["<", path$$1.call(print, "name"), path$$1.call(print, "typeParameters"), concat$4([indent$2(concat$4(path$$1.map(function (attr) {
  16842. return concat$4([line$3, print(attr)]);
  16843. }, "attributes"))), _n.selfClosing ? line$3 : bracketSameLine ? ">" : softline$1]), _n.selfClosing ? "/>" : bracketSameLine ? "" : ">"]), {
  16844. shouldBreak: _shouldBreak
  16845. });
  16846. }
  16847. case "JSXClosingElement":
  16848. return concat$4(["</", path$$1.call(print, "name"), ">"]);
  16849. case "JSXOpeningFragment":
  16850. case "JSXClosingFragment":
  16851. case "TSJsxOpeningFragment":
  16852. case "TSJsxClosingFragment":
  16853. {
  16854. var hasComment = n.comments && n.comments.length;
  16855. var hasOwnLineComment = hasComment && !n.comments.every(comments$3.isBlockComment);
  16856. var isOpeningFragment = n.type === "JSXOpeningFragment" || n.type === "TSJsxOpeningFragment";
  16857. return concat$4([isOpeningFragment ? "<" : "</", indent$2(concat$4([hasOwnLineComment ? hardline$3 : hasComment && !isOpeningFragment ? " " : "", comments.printDanglingComments(path$$1, options, true)])), hasOwnLineComment ? hardline$3 : "", ">"]);
  16858. }
  16859. case "JSXText":
  16860. /* istanbul ignore next */
  16861. throw new Error("JSXTest should be handled by JSXElement");
  16862. case "JSXEmptyExpression":
  16863. {
  16864. var requiresHardline = n.comments && !n.comments.every(comments$3.isBlockComment);
  16865. return concat$4([comments.printDanglingComments(path$$1, options,
  16866. /* sameIndent */
  16867. !requiresHardline), requiresHardline ? hardline$3 : ""]);
  16868. }
  16869. case "ClassBody":
  16870. if (!n.comments && n.body.length === 0) {
  16871. return "{}";
  16872. }
  16873. return concat$4(["{", n.body.length > 0 ? indent$2(concat$4([hardline$3, path$$1.call(function (bodyPath) {
  16874. return printStatementSequence(bodyPath, options, print);
  16875. }, "body")])) : comments.printDanglingComments(path$$1, options), hardline$3, "}"]);
  16876. case "ClassProperty":
  16877. case "TSAbstractClassProperty":
  16878. case "ClassPrivateProperty":
  16879. {
  16880. if (n.accessibility) {
  16881. parts.push(n.accessibility + " ");
  16882. }
  16883. if (n.static) {
  16884. parts.push("static ");
  16885. }
  16886. if (n.type === "TSAbstractClassProperty") {
  16887. parts.push("abstract ");
  16888. }
  16889. if (n.readonly) {
  16890. parts.push("readonly ");
  16891. }
  16892. var variance = getFlowVariance(n);
  16893. if (variance) {
  16894. parts.push(variance);
  16895. }
  16896. if (n.computed) {
  16897. parts.push("[", path$$1.call(print, "key"), "]");
  16898. } else {
  16899. parts.push(printPropertyKey(path$$1, options, print));
  16900. }
  16901. parts.push(printTypeAnnotation(path$$1, options, print));
  16902. if (n.value) {
  16903. parts.push(" =", printAssignmentRight(n.key, n.value, path$$1.call(print, "value"), options));
  16904. }
  16905. parts.push(semi);
  16906. return group$1(concat$4(parts));
  16907. }
  16908. case "ClassDeclaration":
  16909. case "ClassExpression":
  16910. case "TSAbstractClassDeclaration":
  16911. if (isNodeStartingWithDeclare(n, options)) {
  16912. parts.push("declare ");
  16913. }
  16914. parts.push(concat$4(printClass(path$$1, options, print)));
  16915. return concat$4(parts);
  16916. case "TSInterfaceHeritage":
  16917. parts.push(path$$1.call(print, "id"));
  16918. if (n.typeParameters) {
  16919. parts.push(path$$1.call(print, "typeParameters"));
  16920. }
  16921. return concat$4(parts);
  16922. case "TemplateElement":
  16923. return join$2(literalline$1, n.value.raw.split(/\r?\n/g));
  16924. case "TemplateLiteral":
  16925. {
  16926. var expressions = path$$1.map(print, "expressions");
  16927. var _parentNode = path$$1.getParentNode();
  16928. /**
  16929. * describe.each`table`(name, fn)
  16930. * describe.only.each`table`(name, fn)
  16931. * describe.skip.each`table`(name, fn)
  16932. * test.each`table`(name, fn)
  16933. * test.only.each`table`(name, fn)
  16934. * test.skip.each`table`(name, fn)
  16935. *
  16936. * Ref: https://github.com/facebook/jest/pull/6102
  16937. */
  16938. var jestEachTriggerRegex = /^[xf]?(describe|it|test)$/;
  16939. if (_parentNode.type === "TaggedTemplateExpression" && _parentNode.quasi === n && _parentNode.tag.type === "MemberExpression" && _parentNode.tag.property.type === "Identifier" && _parentNode.tag.property.name === "each" && (_parentNode.tag.object.type === "Identifier" && jestEachTriggerRegex.test(_parentNode.tag.object.name) || _parentNode.tag.object.type === "MemberExpression" && _parentNode.tag.object.property.type === "Identifier" && (_parentNode.tag.object.property.name === "only" || _parentNode.tag.object.property.name === "skip") && _parentNode.tag.object.object.type === "Identifier" && jestEachTriggerRegex.test(_parentNode.tag.object.object.name))) {
  16940. /**
  16941. * a | b | expected
  16942. * ${1} | ${1} | ${2}
  16943. * ${1} | ${2} | ${3}
  16944. * ${2} | ${1} | ${3}
  16945. */
  16946. var headerNames = n.quasis[0].value.raw.trim().split(/\s*\|\s*/);
  16947. if (headerNames.length > 1 || headerNames.some(function (headerName) {
  16948. return headerName.length !== 0;
  16949. })) {
  16950. var stringifiedExpressions = expressions.map(function (doc$$2) {
  16951. return "${" + printDocToString$2(doc$$2, Object.assign({}, options, {
  16952. printWidth: Infinity
  16953. })).formatted + "}";
  16954. });
  16955. var tableBody = [{
  16956. hasLineBreak: false,
  16957. cells: []
  16958. }];
  16959. for (var _i = 1; _i < n.quasis.length; _i++) {
  16960. var row = tableBody[tableBody.length - 1];
  16961. var correspondingExpression = stringifiedExpressions[_i - 1];
  16962. row.cells.push(correspondingExpression);
  16963. if (correspondingExpression.indexOf("\n") !== -1) {
  16964. row.hasLineBreak = true;
  16965. }
  16966. if (n.quasis[_i].value.raw.indexOf("\n") !== -1) {
  16967. tableBody.push({
  16968. hasLineBreak: false,
  16969. cells: []
  16970. });
  16971. }
  16972. }
  16973. var maxColumnCount = tableBody.reduce(function (maxColumnCount, row) {
  16974. return Math.max(maxColumnCount, row.cells.length);
  16975. }, headerNames.length);
  16976. var maxColumnWidths = Array.from(new Array(maxColumnCount), function () {
  16977. return 0;
  16978. });
  16979. var table = [{
  16980. cells: headerNames
  16981. }].concat(tableBody.filter(function (row) {
  16982. return row.cells.length !== 0;
  16983. }));
  16984. table.filter(function (row) {
  16985. return !row.hasLineBreak;
  16986. }).forEach(function (row) {
  16987. row.cells.forEach(function (cell, index) {
  16988. maxColumnWidths[index] = Math.max(maxColumnWidths[index], getStringWidth$1(cell));
  16989. });
  16990. });
  16991. parts.push("`", indent$2(concat$4([hardline$3, join$2(hardline$3, table.map(function (row) {
  16992. return join$2(" | ", row.cells.map(function (cell, index) {
  16993. return row.hasLineBreak ? cell : cell + " ".repeat(maxColumnWidths[index] - getStringWidth$1(cell));
  16994. }));
  16995. }))])), hardline$3, "`");
  16996. return concat$4(parts);
  16997. }
  16998. }
  16999. parts.push("`");
  17000. path$$1.each(function (childPath) {
  17001. var i = childPath.getName();
  17002. parts.push(print(childPath));
  17003. if (i < expressions.length) {
  17004. // For a template literal of the following form:
  17005. // `someQuery {
  17006. // ${call({
  17007. // a,
  17008. // b,
  17009. // })}
  17010. // }`
  17011. // the expression is on its own line (there is a \n in the previous
  17012. // quasi literal), therefore we want to indent the JavaScript
  17013. // expression inside at the beginning of ${ instead of the beginning
  17014. // of the `.
  17015. var tabWidth = options.tabWidth;
  17016. var indentSize = getIndentSize$1(childPath.getValue().value.raw, tabWidth);
  17017. var _printed = expressions[i];
  17018. if (n.expressions[i].comments && n.expressions[i].comments.length || n.expressions[i].type === "MemberExpression" || n.expressions[i].type === "OptionalMemberExpression" || n.expressions[i].type === "ConditionalExpression") {
  17019. _printed = concat$4([indent$2(concat$4([softline$1, _printed])), softline$1]);
  17020. }
  17021. var aligned = addAlignmentToDoc$2(_printed, indentSize, tabWidth);
  17022. parts.push(group$1(concat$4(["${", aligned, lineSuffixBoundary$1, "}"])));
  17023. }
  17024. }, "quasis");
  17025. parts.push("`");
  17026. return concat$4(parts);
  17027. }
  17028. // These types are unprintable because they serve as abstract
  17029. // supertypes for other (printable) types.
  17030. case "TaggedTemplateExpression":
  17031. return concat$4([path$$1.call(print, "tag"), path$$1.call(print, "typeParameters"), path$$1.call(print, "quasi")]);
  17032. case "Node":
  17033. case "Printable":
  17034. case "SourceLocation":
  17035. case "Position":
  17036. case "Statement":
  17037. case "Function":
  17038. case "Pattern":
  17039. case "Expression":
  17040. case "Declaration":
  17041. case "Specifier":
  17042. case "NamedSpecifier":
  17043. case "Comment":
  17044. case "MemberTypeAnnotation": // Flow
  17045. case "Type":
  17046. /* istanbul ignore next */
  17047. throw new Error("unprintable type: " + JSON.stringify(n.type));
  17048. // Type Annotations for Facebook Flow, typically stripped out or
  17049. // transformed away before printing.
  17050. case "TypeAnnotation":
  17051. case "TSTypeAnnotation":
  17052. if (n.typeAnnotation) {
  17053. return path$$1.call(print, "typeAnnotation");
  17054. }
  17055. /* istanbul ignore next */
  17056. return "";
  17057. case "TSTupleType":
  17058. case "TupleTypeAnnotation":
  17059. {
  17060. var typesField = n.type === "TSTupleType" ? "elementTypes" : "types";
  17061. return group$1(concat$4(["[", indent$2(concat$4([softline$1, printArrayItems(path$$1, options, typesField, print)])), // TypeScript doesn't support trailing commas in tuple types
  17062. n.type === "TSTupleType" ? "" : ifBreak$1(shouldPrintComma(options) ? "," : ""), comments.printDanglingComments(path$$1, options,
  17063. /* sameIndent */
  17064. true), softline$1, "]"]));
  17065. }
  17066. case "ExistsTypeAnnotation":
  17067. return "*";
  17068. case "EmptyTypeAnnotation":
  17069. return "empty";
  17070. case "AnyTypeAnnotation":
  17071. return "any";
  17072. case "MixedTypeAnnotation":
  17073. return "mixed";
  17074. case "ArrayTypeAnnotation":
  17075. return concat$4([path$$1.call(print, "elementType"), "[]"]);
  17076. case "BooleanTypeAnnotation":
  17077. return "boolean";
  17078. case "BooleanLiteralTypeAnnotation":
  17079. return "" + n.value;
  17080. case "DeclareClass":
  17081. return printFlowDeclaration(path$$1, printClass(path$$1, options, print));
  17082. case "DeclareFunction":
  17083. // For TypeScript the DeclareFunction node shares the AST
  17084. // structure with FunctionDeclaration
  17085. if (n.params) {
  17086. return concat$4(["declare ", printFunctionDeclaration(path$$1, print, options), semi]);
  17087. }
  17088. return printFlowDeclaration(path$$1, ["function ", path$$1.call(print, "id"), n.predicate ? " " : "", path$$1.call(print, "predicate"), semi]);
  17089. case "DeclareModule":
  17090. return printFlowDeclaration(path$$1, ["module ", path$$1.call(print, "id"), " ", path$$1.call(print, "body")]);
  17091. case "DeclareModuleExports":
  17092. return printFlowDeclaration(path$$1, ["module.exports", ": ", path$$1.call(print, "typeAnnotation"), semi]);
  17093. case "DeclareVariable":
  17094. return printFlowDeclaration(path$$1, ["var ", path$$1.call(print, "id"), semi]);
  17095. case "DeclareExportAllDeclaration":
  17096. return concat$4(["declare export * from ", path$$1.call(print, "source")]);
  17097. case "DeclareExportDeclaration":
  17098. return concat$4(["declare ", printExportDeclaration(path$$1, options, print)]);
  17099. case "DeclareOpaqueType":
  17100. case "OpaqueType":
  17101. {
  17102. parts.push("opaque type ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"));
  17103. if (n.supertype) {
  17104. parts.push(": ", path$$1.call(print, "supertype"));
  17105. }
  17106. if (n.impltype) {
  17107. parts.push(" = ", path$$1.call(print, "impltype"));
  17108. }
  17109. parts.push(semi);
  17110. if (n.type === "DeclareOpaqueType") {
  17111. return printFlowDeclaration(path$$1, parts);
  17112. }
  17113. return concat$4(parts);
  17114. }
  17115. case "FunctionTypeAnnotation":
  17116. case "TSFunctionType":
  17117. {
  17118. // FunctionTypeAnnotation is ambiguous:
  17119. // declare function foo(a: B): void; OR
  17120. // var A: (a: B) => void;
  17121. var _parent6 = path$$1.getParentNode(0);
  17122. var _parentParent2 = path$$1.getParentNode(1);
  17123. var _parentParentParent = path$$1.getParentNode(2);
  17124. var isArrowFunctionTypeAnnotation = n.type === "TSFunctionType" || !(_parent6.type === "ObjectTypeProperty" && !getFlowVariance(_parent6) && !_parent6.optional && options.locStart(_parent6) === options.locStart(n) || _parent6.type === "ObjectTypeCallProperty" || _parentParentParent && _parentParentParent.type === "DeclareFunction");
  17125. var needsColon = isArrowFunctionTypeAnnotation && (_parent6.type === "TypeAnnotation" || _parent6.type === "TSTypeAnnotation"); // Sadly we can't put it inside of FastPath::needsColon because we are
  17126. // printing ":" as part of the expression and it would put parenthesis
  17127. // around :(
  17128. var needsParens = needsColon && isArrowFunctionTypeAnnotation && (_parent6.type === "TypeAnnotation" || _parent6.type === "TSTypeAnnotation") && _parentParent2.type === "ArrowFunctionExpression";
  17129. if (isObjectTypePropertyAFunction(_parent6, options)) {
  17130. isArrowFunctionTypeAnnotation = true;
  17131. needsColon = true;
  17132. }
  17133. if (needsParens) {
  17134. parts.push("(");
  17135. }
  17136. parts.push(printFunctionParams(path$$1, print, options,
  17137. /* expandArg */
  17138. false,
  17139. /* printTypeParams */
  17140. true)); // The returnType is not wrapped in a TypeAnnotation, so the colon
  17141. // needs to be added separately.
  17142. if (n.returnType || n.predicate || n.typeAnnotation) {
  17143. parts.push(isArrowFunctionTypeAnnotation ? " => " : ": ", path$$1.call(print, "returnType"), path$$1.call(print, "predicate"), path$$1.call(print, "typeAnnotation"));
  17144. }
  17145. if (needsParens) {
  17146. parts.push(")");
  17147. }
  17148. return group$1(concat$4(parts));
  17149. }
  17150. case "FunctionTypeParam":
  17151. return concat$4([path$$1.call(print, "name"), printOptionalToken(path$$1), n.name ? ": " : "", path$$1.call(print, "typeAnnotation")]);
  17152. case "GenericTypeAnnotation":
  17153. return concat$4([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]);
  17154. case "DeclareInterface":
  17155. case "InterfaceDeclaration":
  17156. case "InterfaceTypeAnnotation":
  17157. {
  17158. if (n.type === "DeclareInterface" || isNodeStartingWithDeclare(n, options)) {
  17159. parts.push("declare ");
  17160. }
  17161. parts.push("interface");
  17162. if (n.type === "DeclareInterface" || n.type === "InterfaceDeclaration") {
  17163. parts.push(" ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"));
  17164. }
  17165. if (n["extends"].length > 0) {
  17166. parts.push(group$1(indent$2(concat$4([line$3, "extends ", join$2(", ", path$$1.map(print, "extends"))]))));
  17167. }
  17168. parts.push(" ", path$$1.call(print, "body"));
  17169. return group$1(concat$4(parts));
  17170. }
  17171. case "ClassImplements":
  17172. case "InterfaceExtends":
  17173. return concat$4([path$$1.call(print, "id"), path$$1.call(print, "typeParameters")]);
  17174. case "TSIntersectionType":
  17175. case "IntersectionTypeAnnotation":
  17176. {
  17177. var types = path$$1.map(print, "types");
  17178. var result = [];
  17179. var wasIndented = false;
  17180. for (var _i2 = 0; _i2 < types.length; ++_i2) {
  17181. if (_i2 === 0) {
  17182. result.push(types[_i2]);
  17183. } else if (isObjectType(n.types[_i2 - 1]) && isObjectType(n.types[_i2])) {
  17184. // If both are objects, don't indent
  17185. result.push(concat$4([" & ", wasIndented ? indent$2(types[_i2]) : types[_i2]]));
  17186. } else if (!isObjectType(n.types[_i2 - 1]) && !isObjectType(n.types[_i2])) {
  17187. // If no object is involved, go to the next line if it breaks
  17188. result.push(indent$2(concat$4([" &", line$3, types[_i2]])));
  17189. } else {
  17190. // If you go from object to non-object or vis-versa, then inline it
  17191. if (_i2 > 1) {
  17192. wasIndented = true;
  17193. }
  17194. result.push(" & ", _i2 > 1 ? indent$2(types[_i2]) : types[_i2]);
  17195. }
  17196. }
  17197. return group$1(concat$4(result));
  17198. }
  17199. case "TSUnionType":
  17200. case "UnionTypeAnnotation":
  17201. {
  17202. // single-line variation
  17203. // A | B | C
  17204. // multi-line variation
  17205. // | A
  17206. // | B
  17207. // | C
  17208. var _parent7 = path$$1.getParentNode();
  17209. var _parentParent3 = path$$1.getParentNode(1); // If there's a leading comment, the parent is doing the indentation
  17210. var shouldIndent = _parent7.type !== "TypeParameterInstantiation" && _parent7.type !== "TSTypeParameterInstantiation" && _parent7.type !== "GenericTypeAnnotation" && _parent7.type !== "TSTypeReference" && !(_parent7.type === "FunctionTypeParam" && !_parent7.name) && _parentParent3.type !== "TSTypeAssertionExpression" && !((_parent7.type === "TypeAlias" || _parent7.type === "VariableDeclarator") && hasLeadingOwnLineComment(options.originalText, n, options)); // {
  17211. // a: string
  17212. // } | null | void
  17213. // should be inlined and not be printed in the multi-line variant
  17214. var shouldHug = shouldHugType(n); // We want to align the children but without its comment, so it looks like
  17215. // | child1
  17216. // // comment
  17217. // | child2
  17218. var _printed2 = path$$1.map(function (typePath) {
  17219. var printedType = typePath.call(print);
  17220. if (!shouldHug) {
  17221. printedType = align$1(2, printedType);
  17222. }
  17223. return comments.printComments(typePath, function () {
  17224. return printedType;
  17225. }, options);
  17226. }, "types");
  17227. if (shouldHug) {
  17228. return join$2(" | ", _printed2);
  17229. }
  17230. var code = concat$4([ifBreak$1(concat$4([shouldIndent ? line$3 : "", "| "])), join$2(concat$4([line$3, "| "]), _printed2)]);
  17231. var hasParens;
  17232. if (n.type === "TSUnionType") {
  17233. var greatGrandParent = path$$1.getParentNode(2);
  17234. var greatGreatGrandParent = path$$1.getParentNode(3);
  17235. hasParens = greatGrandParent && greatGrandParent.type === "TSParenthesizedType" && greatGreatGrandParent && (greatGreatGrandParent.type === "TSUnionType" || greatGreatGrandParent.type === "TSIntersectionType");
  17236. } else {
  17237. hasParens = needsParens_1(path$$1, options);
  17238. }
  17239. if (hasParens) {
  17240. return group$1(concat$4([indent$2(code), softline$1]));
  17241. }
  17242. return group$1(shouldIndent ? indent$2(code) : code);
  17243. }
  17244. case "NullableTypeAnnotation":
  17245. return concat$4(["?", path$$1.call(print, "typeAnnotation")]);
  17246. case "TSNullKeyword":
  17247. case "NullLiteralTypeAnnotation":
  17248. return "null";
  17249. case "ThisTypeAnnotation":
  17250. return "this";
  17251. case "NumberTypeAnnotation":
  17252. return "number";
  17253. case "ObjectTypeCallProperty":
  17254. if (n.static) {
  17255. parts.push("static ");
  17256. }
  17257. parts.push(path$$1.call(print, "value"));
  17258. return concat$4(parts);
  17259. case "ObjectTypeIndexer":
  17260. {
  17261. var _variance = getFlowVariance(n);
  17262. return concat$4([_variance || "", "[", path$$1.call(print, "id"), n.id ? ": " : "", path$$1.call(print, "key"), "]: ", path$$1.call(print, "value")]);
  17263. }
  17264. case "ObjectTypeProperty":
  17265. {
  17266. var _variance2 = getFlowVariance(n);
  17267. var modifier = "";
  17268. if (n.proto) {
  17269. modifier = "proto ";
  17270. } else if (n.static) {
  17271. modifier = "static ";
  17272. }
  17273. return concat$4([modifier, isGetterOrSetter(n) ? n.kind + " " : "", _variance2 || "", printPropertyKey(path$$1, options, print), printOptionalToken(path$$1), isFunctionNotation(n, options) ? "" : ": ", path$$1.call(print, "value")]);
  17274. }
  17275. case "QualifiedTypeIdentifier":
  17276. return concat$4([path$$1.call(print, "qualification"), ".", path$$1.call(print, "id")]);
  17277. case "StringLiteralTypeAnnotation":
  17278. return nodeStr(n, options);
  17279. case "NumberLiteralTypeAnnotation":
  17280. assert.strictEqual(typeof n.value, "number");
  17281. if (n.extra != null) {
  17282. return printNumber$1(n.extra.raw);
  17283. }
  17284. return printNumber$1(n.raw);
  17285. case "StringTypeAnnotation":
  17286. return "string";
  17287. case "DeclareTypeAlias":
  17288. case "TypeAlias":
  17289. {
  17290. if (n.type === "DeclareTypeAlias" || isNodeStartingWithDeclare(n, options)) {
  17291. parts.push("declare ");
  17292. }
  17293. var _printed3 = printAssignmentRight(n.id, n.right, path$$1.call(print, "right"), options);
  17294. parts.push("type ", path$$1.call(print, "id"), path$$1.call(print, "typeParameters"), " =", _printed3, semi);
  17295. return group$1(concat$4(parts));
  17296. }
  17297. case "TypeCastExpression":
  17298. return concat$4(["(", path$$1.call(print, "expression"), ": ", path$$1.call(print, "typeAnnotation"), ")"]);
  17299. case "TypeParameterDeclaration":
  17300. case "TypeParameterInstantiation":
  17301. case "TSTypeParameterDeclaration":
  17302. case "TSTypeParameterInstantiation":
  17303. return printTypeParameters(path$$1, options, print, "params");
  17304. case "TSTypeParameter":
  17305. case "TypeParameter":
  17306. {
  17307. var _parent8 = path$$1.getParentNode();
  17308. if (_parent8.type === "TSMappedType") {
  17309. parts.push("[", path$$1.call(print, "name"));
  17310. if (n.constraint) {
  17311. parts.push(" in ", path$$1.call(print, "constraint"));
  17312. }
  17313. parts.push("]");
  17314. return concat$4(parts);
  17315. }
  17316. var _variance3 = getFlowVariance(n);
  17317. if (_variance3) {
  17318. parts.push(_variance3);
  17319. }
  17320. parts.push(path$$1.call(print, "name"));
  17321. if (n.bound) {
  17322. parts.push(": ");
  17323. parts.push(path$$1.call(print, "bound"));
  17324. }
  17325. if (n.constraint) {
  17326. parts.push(" extends ", path$$1.call(print, "constraint"));
  17327. }
  17328. if (n["default"]) {
  17329. parts.push(" = ", path$$1.call(print, "default"));
  17330. }
  17331. return concat$4(parts);
  17332. }
  17333. case "TypeofTypeAnnotation":
  17334. return concat$4(["typeof ", path$$1.call(print, "argument")]);
  17335. case "VoidTypeAnnotation":
  17336. return "void";
  17337. case "InferredPredicate":
  17338. return "%checks";
  17339. // Unhandled types below. If encountered, nodes of these types should
  17340. // be either left alone or desugared into AST types that are fully
  17341. // supported by the pretty-printer.
  17342. case "DeclaredPredicate":
  17343. return concat$4(["%checks(", path$$1.call(print, "value"), ")"]);
  17344. case "TSAbstractKeyword":
  17345. return "abstract";
  17346. case "TSAnyKeyword":
  17347. return "any";
  17348. case "TSAsyncKeyword":
  17349. return "async";
  17350. case "TSBooleanKeyword":
  17351. return "boolean";
  17352. case "TSConstKeyword":
  17353. return "const";
  17354. case "TSDeclareKeyword":
  17355. return "declare";
  17356. case "TSExportKeyword":
  17357. return "export";
  17358. case "TSNeverKeyword":
  17359. return "never";
  17360. case "TSNumberKeyword":
  17361. return "number";
  17362. case "TSObjectKeyword":
  17363. return "object";
  17364. case "TSProtectedKeyword":
  17365. return "protected";
  17366. case "TSPrivateKeyword":
  17367. return "private";
  17368. case "TSPublicKeyword":
  17369. return "public";
  17370. case "TSReadonlyKeyword":
  17371. return "readonly";
  17372. case "TSSymbolKeyword":
  17373. return "symbol";
  17374. case "TSStaticKeyword":
  17375. return "static";
  17376. case "TSStringKeyword":
  17377. return "string";
  17378. case "TSUndefinedKeyword":
  17379. return "undefined";
  17380. case "TSVoidKeyword":
  17381. return "void";
  17382. case "TSAsExpression":
  17383. return concat$4([path$$1.call(print, "expression"), " as ", path$$1.call(print, "typeAnnotation")]);
  17384. case "TSArrayType":
  17385. return concat$4([path$$1.call(print, "elementType"), "[]"]);
  17386. case "TSPropertySignature":
  17387. {
  17388. if (n.export) {
  17389. parts.push("export ");
  17390. }
  17391. if (n.accessibility) {
  17392. parts.push(n.accessibility + " ");
  17393. }
  17394. if (n.static) {
  17395. parts.push("static ");
  17396. }
  17397. if (n.readonly) {
  17398. parts.push("readonly ");
  17399. }
  17400. if (n.computed) {
  17401. parts.push("[");
  17402. }
  17403. parts.push(printPropertyKey(path$$1, options, print));
  17404. if (n.computed) {
  17405. parts.push("]");
  17406. }
  17407. parts.push(printOptionalToken(path$$1));
  17408. if (n.typeAnnotation) {
  17409. parts.push(": ");
  17410. parts.push(path$$1.call(print, "typeAnnotation"));
  17411. } // This isn't valid semantically, but it's in the AST so we can print it.
  17412. if (n.initializer) {
  17413. parts.push(" = ", path$$1.call(print, "initializer"));
  17414. }
  17415. return concat$4(parts);
  17416. }
  17417. case "TSParameterProperty":
  17418. if (n.accessibility) {
  17419. parts.push(n.accessibility + " ");
  17420. }
  17421. if (n.export) {
  17422. parts.push("export ");
  17423. }
  17424. if (n.static) {
  17425. parts.push("static ");
  17426. }
  17427. if (n.readonly) {
  17428. parts.push("readonly ");
  17429. }
  17430. parts.push(path$$1.call(print, "parameter"));
  17431. return concat$4(parts);
  17432. case "TSTypeReference":
  17433. return concat$4([path$$1.call(print, "typeName"), printTypeParameters(path$$1, options, print, "typeParameters")]);
  17434. case "TSTypeQuery":
  17435. return concat$4(["typeof ", path$$1.call(print, "exprName")]);
  17436. case "TSParenthesizedType":
  17437. {
  17438. return path$$1.call(print, "typeAnnotation");
  17439. }
  17440. case "TSIndexSignature":
  17441. {
  17442. var _parent9 = path$$1.getParentNode();
  17443. return concat$4([n.export ? "export " : "", n.accessibility ? concat$4([n.accessibility, " "]) : "", n.static ? "static " : "", n.readonly ? "readonly " : "", "[", path$$1.call(print, "index"), "]: ", path$$1.call(print, "typeAnnotation"), _parent9.type === "ClassBody" ? semi : ""]);
  17444. }
  17445. case "TSTypePredicate":
  17446. return concat$4([path$$1.call(print, "parameterName"), " is ", path$$1.call(print, "typeAnnotation")]);
  17447. case "TSNonNullExpression":
  17448. return concat$4([path$$1.call(print, "expression"), "!"]);
  17449. case "TSThisType":
  17450. return "this";
  17451. case "TSLastTypeNode":
  17452. // TSImportType
  17453. return concat$4([!n.isTypeOf ? "" : "typeof ", "import(", path$$1.call(print, "argument"), ")", !n.qualifier ? "" : concat$4([".", path$$1.call(print, "qualifier")]), printTypeParameters(path$$1, options, print, "typeParameters")]);
  17454. case "TSLiteralType":
  17455. return path$$1.call(print, "literal");
  17456. case "TSIndexedAccessType":
  17457. return concat$4([path$$1.call(print, "objectType"), "[", path$$1.call(print, "indexType"), "]"]);
  17458. case "TSConstructSignature":
  17459. case "TSConstructorType":
  17460. case "TSCallSignature":
  17461. {
  17462. if (n.type !== "TSCallSignature") {
  17463. parts.push("new ");
  17464. }
  17465. parts.push(group$1(printFunctionParams(path$$1, print, options,
  17466. /* expandArg */
  17467. false,
  17468. /* printTypeParams */
  17469. true)));
  17470. if (n.typeAnnotation) {
  17471. var isType = n.type === "TSConstructorType";
  17472. parts.push(isType ? " => " : ": ", path$$1.call(print, "typeAnnotation"));
  17473. }
  17474. return concat$4(parts);
  17475. }
  17476. case "TSTypeOperator":
  17477. return concat$4([n.operator, " ", path$$1.call(print, "typeAnnotation")]);
  17478. case "TSMappedType":
  17479. return group$1(concat$4(["{", indent$2(concat$4([options.bracketSpacing ? line$3 : softline$1, n.readonlyToken ? concat$4([getTypeScriptMappedTypeModifier(n.readonlyToken, "readonly"), " "]) : "", printTypeScriptModifiers(path$$1, options, print), path$$1.call(print, "typeParameter"), n.questionToken ? getTypeScriptMappedTypeModifier(n.questionToken, "?") : "", ": ", path$$1.call(print, "typeAnnotation")])), comments.printDanglingComments(path$$1, options,
  17480. /* sameIndent */
  17481. true), options.bracketSpacing ? line$3 : softline$1, "}"]));
  17482. case "TSMethodSignature":
  17483. parts.push(n.accessibility ? concat$4([n.accessibility, " "]) : "", n.export ? "export " : "", n.static ? "static " : "", n.readonly ? "readonly " : "", n.computed ? "[" : "", path$$1.call(print, "key"), n.computed ? "]" : "", printOptionalToken(path$$1), printFunctionParams(path$$1, print, options,
  17484. /* expandArg */
  17485. false,
  17486. /* printTypeParams */
  17487. true));
  17488. if (n.typeAnnotation) {
  17489. parts.push(": ", path$$1.call(print, "typeAnnotation"));
  17490. }
  17491. return group$1(concat$4(parts));
  17492. case "TSNamespaceExportDeclaration":
  17493. parts.push("export as namespace ", path$$1.call(print, "name"));
  17494. if (options.semi) {
  17495. parts.push(";");
  17496. }
  17497. return group$1(concat$4(parts));
  17498. case "TSEnumDeclaration":
  17499. if (isNodeStartingWithDeclare(n, options)) {
  17500. parts.push("declare ");
  17501. }
  17502. if (n.modifiers) {
  17503. parts.push(printTypeScriptModifiers(path$$1, options, print));
  17504. }
  17505. if (n.const) {
  17506. parts.push("const ");
  17507. }
  17508. parts.push("enum ", path$$1.call(print, "id"), " ");
  17509. if (n.members.length === 0) {
  17510. parts.push(group$1(concat$4(["{", comments.printDanglingComments(path$$1, options), softline$1, "}"])));
  17511. } else {
  17512. parts.push(group$1(concat$4(["{", indent$2(concat$4([hardline$3, printArrayItems(path$$1, options, "members", print), shouldPrintComma(options, "es5") ? "," : ""])), comments.printDanglingComments(path$$1, options,
  17513. /* sameIndent */
  17514. true), hardline$3, "}"])));
  17515. }
  17516. return concat$4(parts);
  17517. case "TSEnumMember":
  17518. parts.push(path$$1.call(print, "id"));
  17519. if (n.initializer) {
  17520. parts.push(" = ", path$$1.call(print, "initializer"));
  17521. }
  17522. return concat$4(parts);
  17523. case "TSImportEqualsDeclaration":
  17524. parts.push(printTypeScriptModifiers(path$$1, options, print), "import ", path$$1.call(print, "name"), " = ", path$$1.call(print, "moduleReference"));
  17525. if (options.semi) {
  17526. parts.push(";");
  17527. }
  17528. return group$1(concat$4(parts));
  17529. case "TSExternalModuleReference":
  17530. return concat$4(["require(", path$$1.call(print, "expression"), ")"]);
  17531. case "TSModuleDeclaration":
  17532. {
  17533. var _parent10 = path$$1.getParentNode();
  17534. var isExternalModule = isLiteral(n.id);
  17535. var parentIsDeclaration = _parent10.type === "TSModuleDeclaration";
  17536. var bodyIsDeclaration = n.body && n.body.type === "TSModuleDeclaration";
  17537. if (parentIsDeclaration) {
  17538. parts.push(".");
  17539. } else {
  17540. if (n.declare === true) {
  17541. parts.push("declare ");
  17542. }
  17543. parts.push(printTypeScriptModifiers(path$$1, options, print)); // Global declaration looks like this:
  17544. // (declare)? global { ... }
  17545. var isGlobalDeclaration = n.id.type === "Identifier" && n.id.name === "global" && !/namespace|module/.test(options.originalText.slice(options.locStart(n), options.locStart(n.id)));
  17546. if (!isGlobalDeclaration) {
  17547. parts.push(isExternalModule ? "module " : "namespace ");
  17548. }
  17549. }
  17550. parts.push(path$$1.call(print, "id"));
  17551. if (bodyIsDeclaration) {
  17552. parts.push(path$$1.call(print, "body"));
  17553. } else if (n.body) {
  17554. parts.push(" {", indent$2(concat$4([line$3, path$$1.call(function (bodyPath) {
  17555. return comments.printDanglingComments(bodyPath, options, true);
  17556. }, "body"), group$1(path$$1.call(print, "body"))])), line$3, "}");
  17557. } else {
  17558. parts.push(semi);
  17559. }
  17560. return concat$4(parts);
  17561. }
  17562. case "TSModuleBlock":
  17563. return path$$1.call(function (bodyPath) {
  17564. return printStatementSequence(bodyPath, options, print);
  17565. }, "body");
  17566. case "PrivateName":
  17567. return concat$4(["#", path$$1.call(print, "id")]);
  17568. case "TSConditionalType":
  17569. return formatTernaryOperator(path$$1, options, print, {
  17570. beforeParts: function beforeParts() {
  17571. return [path$$1.call(print, "checkType"), " ", "extends", " ", path$$1.call(print, "extendsType")];
  17572. },
  17573. shouldCheckJsx: false,
  17574. operatorName: "TSConditionalType",
  17575. consequentNode: "trueType",
  17576. alternateNode: "falseType",
  17577. testNode: "checkType",
  17578. breakNested: false
  17579. });
  17580. case "TSInferType":
  17581. return concat$4(["infer", " ", path$$1.call(print, "typeParameter")]);
  17582. case "InterpreterDirective":
  17583. parts.push("#!", n.value, hardline$3);
  17584. if (isNextLineEmpty$2(options.originalText, n, options)) {
  17585. parts.push(hardline$3);
  17586. }
  17587. return concat$4(parts);
  17588. default:
  17589. /* istanbul ignore next */
  17590. throw new Error("unknown type: " + JSON.stringify(n.type));
  17591. }
  17592. }
  17593. function printStatementSequence(path$$1, options, print) {
  17594. var printed = [];
  17595. var bodyNode = path$$1.getNode();
  17596. var isClass = bodyNode.type === "ClassBody";
  17597. path$$1.map(function (stmtPath, i) {
  17598. var stmt = stmtPath.getValue(); // Just in case the AST has been modified to contain falsy
  17599. // "statements," it's safer simply to skip them.
  17600. /* istanbul ignore if */
  17601. if (!stmt) {
  17602. return;
  17603. } // Skip printing EmptyStatement nodes to avoid leaving stray
  17604. // semicolons lying around.
  17605. if (stmt.type === "EmptyStatement") {
  17606. return;
  17607. }
  17608. var stmtPrinted = print(stmtPath);
  17609. var text = options.originalText;
  17610. var parts = []; // in no-semi mode, prepend statement with semicolon if it might break ASI
  17611. // don't prepend the only JSX element in a program with semicolon
  17612. if (!options.semi && !isClass && !isTheOnlyJSXElementInMarkdown(options, stmtPath) && stmtNeedsASIProtection(stmtPath, options)) {
  17613. if (stmt.comments && stmt.comments.some(function (comment) {
  17614. return comment.leading;
  17615. })) {
  17616. parts.push(print(stmtPath, {
  17617. needsSemi: true
  17618. }));
  17619. } else {
  17620. parts.push(";", stmtPrinted);
  17621. }
  17622. } else {
  17623. parts.push(stmtPrinted);
  17624. }
  17625. if (!options.semi && isClass) {
  17626. if (classPropMayCauseASIProblems(stmtPath)) {
  17627. parts.push(";");
  17628. } else if (stmt.type === "ClassProperty") {
  17629. var nextChild = bodyNode.body[i + 1];
  17630. if (classChildNeedsASIProtection(nextChild)) {
  17631. parts.push(";");
  17632. }
  17633. }
  17634. }
  17635. if (isNextLineEmpty$2(text, stmt, options) && !isLastStatement(stmtPath)) {
  17636. parts.push(hardline$3);
  17637. }
  17638. printed.push(concat$4(parts));
  17639. });
  17640. return join$2(hardline$3, printed);
  17641. }
  17642. function printPropertyKey(path$$1, options, print) {
  17643. var node = path$$1.getNode();
  17644. var key = node.key;
  17645. if (key.type === "Identifier" && !node.computed && options.parser === "json") {
  17646. // a -> "a"
  17647. return path$$1.call(function (keyPath) {
  17648. return comments.printComments(keyPath, function () {
  17649. return JSON.stringify(key.name);
  17650. }, options);
  17651. }, "key");
  17652. }
  17653. if (isStringLiteral(key) && isIdentifierName(key.value) && !node.computed && options.parser !== "json" && !(options.parser === "typescript" && node.type === "ClassProperty")) {
  17654. // 'a' -> a
  17655. return path$$1.call(function (keyPath) {
  17656. return comments.printComments(keyPath, function () {
  17657. return key.value;
  17658. }, options);
  17659. }, "key");
  17660. }
  17661. return path$$1.call(print, "key");
  17662. }
  17663. function printMethod(path$$1, options, print) {
  17664. var node = path$$1.getNode();
  17665. var semi = options.semi ? ";" : "";
  17666. var kind = node.kind;
  17667. var parts = [];
  17668. if (node.type === "ObjectMethod" || node.type === "ClassMethod") {
  17669. node.value = node;
  17670. }
  17671. if (node.value.async) {
  17672. parts.push("async ");
  17673. }
  17674. if (!kind || kind === "init" || kind === "method" || kind === "constructor") {
  17675. if (node.value.generator) {
  17676. parts.push("*");
  17677. }
  17678. } else {
  17679. assert.ok(kind === "get" || kind === "set");
  17680. parts.push(kind, " ");
  17681. }
  17682. var key = printPropertyKey(path$$1, options, print);
  17683. if (node.computed) {
  17684. key = concat$4(["[", key, "]"]);
  17685. }
  17686. parts.push(key, concat$4(path$$1.call(function (valuePath) {
  17687. return [printFunctionTypeParameters(valuePath, options, print), group$1(concat$4([printFunctionParams(valuePath, print, options), printReturnType(valuePath, print, options)]))];
  17688. }, "value")));
  17689. if (!node.value.body || node.value.body.length === 0) {
  17690. parts.push(semi);
  17691. } else {
  17692. parts.push(" ", path$$1.call(print, "value", "body"));
  17693. }
  17694. return concat$4(parts);
  17695. }
  17696. function couldGroupArg(arg) {
  17697. return arg.type === "ObjectExpression" && (arg.properties.length > 0 || arg.comments) || arg.type === "ArrayExpression" && (arg.elements.length > 0 || arg.comments) || arg.type === "TSTypeAssertionExpression" || arg.type === "TSAsExpression" || arg.type === "FunctionExpression" || arg.type === "ArrowFunctionExpression" && !arg.returnType && (arg.body.type === "BlockStatement" || arg.body.type === "ArrowFunctionExpression" || arg.body.type === "ObjectExpression" || arg.body.type === "ArrayExpression" || arg.body.type === "CallExpression" || arg.body.type === "OptionalCallExpression" || isJSXNode(arg.body));
  17698. }
  17699. function shouldGroupLastArg(args) {
  17700. var lastArg = getLast$4(args);
  17701. var penultimateArg = getPenultimate$1(args);
  17702. return !hasLeadingComment(lastArg) && !hasTrailingComment(lastArg) && couldGroupArg(lastArg) && ( // If the last two arguments are of the same type,
  17703. // disable last element expansion.
  17704. !penultimateArg || penultimateArg.type !== lastArg.type);
  17705. }
  17706. function shouldGroupFirstArg(args) {
  17707. if (args.length !== 2) {
  17708. return false;
  17709. }
  17710. var firstArg = args[0];
  17711. var secondArg = args[1];
  17712. return (!firstArg.comments || !firstArg.comments.length) && (firstArg.type === "FunctionExpression" || firstArg.type === "ArrowFunctionExpression" && firstArg.body.type === "BlockStatement") && !couldGroupArg(secondArg);
  17713. }
  17714. var functionCompositionFunctionNames = new Set(["pipe", // RxJS, Ramda
  17715. "pipeP", // Ramda
  17716. "pipeK", // Ramda
  17717. "compose", // Ramda, Redux
  17718. "composeFlipped", // Not from any library, but common in Haskell, so supported
  17719. "composeP", // Ramda
  17720. "composeK", // Ramda
  17721. "flow", // Lodash
  17722. "flowRight", // Lodash
  17723. "connect" // Redux
  17724. ]);
  17725. function isFunctionCompositionFunction(node) {
  17726. switch (node.type) {
  17727. case "OptionalMemberExpression":
  17728. case "MemberExpression":
  17729. {
  17730. return isFunctionCompositionFunction(node.property);
  17731. }
  17732. case "Identifier":
  17733. {
  17734. return functionCompositionFunctionNames.has(node.name);
  17735. }
  17736. case "StringLiteral":
  17737. case "Literal":
  17738. {
  17739. return functionCompositionFunctionNames.has(node.value);
  17740. }
  17741. }
  17742. }
  17743. function printArgumentsList(path$$1, options, print) {
  17744. var node = path$$1.getValue();
  17745. var args = node.arguments;
  17746. if (args.length === 0) {
  17747. return concat$4(["(", comments.printDanglingComments(path$$1, options,
  17748. /* sameIndent */
  17749. true), ")"]);
  17750. }
  17751. var anyArgEmptyLine = false;
  17752. var hasEmptyLineFollowingFirstArg = false;
  17753. var lastArgIndex = args.length - 1;
  17754. var printedArguments = path$$1.map(function (argPath, index) {
  17755. var arg = argPath.getNode();
  17756. var parts = [print(argPath)];
  17757. if (index === lastArgIndex) {// do nothing
  17758. } else if (isNextLineEmpty$2(options.originalText, arg, options)) {
  17759. if (index === 0) {
  17760. hasEmptyLineFollowingFirstArg = true;
  17761. }
  17762. anyArgEmptyLine = true;
  17763. parts.push(",", hardline$3, hardline$3);
  17764. } else {
  17765. parts.push(",", line$3);
  17766. }
  17767. return concat$4(parts);
  17768. }, "arguments");
  17769. var maybeTrailingComma = shouldPrintComma(options, "all") ? "," : "";
  17770. function allArgsBrokenOut() {
  17771. return group$1(concat$4(["(", indent$2(concat$4([line$3, concat$4(printedArguments)])), maybeTrailingComma, line$3, ")"]), {
  17772. shouldBreak: true
  17773. });
  17774. } // We want to get
  17775. // pipe(
  17776. // x => x + 1,
  17777. // x => x - 1
  17778. // )
  17779. // here, but not
  17780. // process.stdout.pipe(socket)
  17781. if (isFunctionCompositionFunction(node.callee) && args.length > 1) {
  17782. return allArgsBrokenOut();
  17783. }
  17784. var shouldGroupFirst = shouldGroupFirstArg(args);
  17785. var shouldGroupLast = shouldGroupLastArg(args);
  17786. if (shouldGroupFirst || shouldGroupLast) {
  17787. var shouldBreak = (shouldGroupFirst ? printedArguments.slice(1).some(willBreak$1) : printedArguments.slice(0, -1).some(willBreak$1)) || anyArgEmptyLine; // We want to print the last argument with a special flag
  17788. var printedExpanded;
  17789. var i = 0;
  17790. path$$1.each(function (argPath) {
  17791. if (shouldGroupFirst && i === 0) {
  17792. printedExpanded = [concat$4([argPath.call(function (p) {
  17793. return print(p, {
  17794. expandFirstArg: true
  17795. });
  17796. }), printedArguments.length > 1 ? "," : "", hasEmptyLineFollowingFirstArg ? hardline$3 : line$3, hasEmptyLineFollowingFirstArg ? hardline$3 : ""])].concat(printedArguments.slice(1));
  17797. }
  17798. if (shouldGroupLast && i === args.length - 1) {
  17799. printedExpanded = printedArguments.slice(0, -1).concat(argPath.call(function (p) {
  17800. return print(p, {
  17801. expandLastArg: true
  17802. });
  17803. }));
  17804. }
  17805. i++;
  17806. }, "arguments");
  17807. var somePrintedArgumentsWillBreak = printedArguments.some(willBreak$1);
  17808. return concat$4([somePrintedArgumentsWillBreak ? breakParent$2 : "", conditionalGroup$1([concat$4([ifBreak$1(indent$2(concat$4(["(", softline$1, concat$4(printedExpanded)])), concat$4(["(", concat$4(printedExpanded)])), somePrintedArgumentsWillBreak ? concat$4([ifBreak$1(maybeTrailingComma), softline$1]) : "", ")"]), shouldGroupFirst ? concat$4(["(", group$1(printedExpanded[0], {
  17809. shouldBreak: true
  17810. }), concat$4(printedExpanded.slice(1)), ")"]) : concat$4(["(", concat$4(printedArguments.slice(0, -1)), group$1(getLast$4(printedExpanded), {
  17811. shouldBreak: true
  17812. }), ")"]), allArgsBrokenOut()], {
  17813. shouldBreak
  17814. })]);
  17815. }
  17816. return group$1(concat$4(["(", indent$2(concat$4([softline$1, concat$4(printedArguments)])), ifBreak$1(shouldPrintComma(options, "all") ? "," : ""), softline$1, ")"]), {
  17817. shouldBreak: printedArguments.some(willBreak$1) || anyArgEmptyLine
  17818. });
  17819. }
  17820. function printTypeAnnotation(path$$1, options, print) {
  17821. var node = path$$1.getValue();
  17822. if (!node.typeAnnotation) {
  17823. return "";
  17824. }
  17825. var parentNode = path$$1.getParentNode();
  17826. var isDefinite = node.definite || parentNode && parentNode.type === "VariableDeclarator" && parentNode.definite;
  17827. var isFunctionDeclarationIdentifier = parentNode.type === "DeclareFunction" && parentNode.id === node;
  17828. if (isFlowAnnotationComment(options.originalText, node.typeAnnotation, options)) {
  17829. return concat$4([" /*: ", path$$1.call(print, "typeAnnotation"), " */"]);
  17830. }
  17831. return concat$4([isFunctionDeclarationIdentifier ? "" : isDefinite ? "!: " : ": ", path$$1.call(print, "typeAnnotation")]);
  17832. }
  17833. function printFunctionTypeParameters(path$$1, options, print) {
  17834. var fun = path$$1.getValue();
  17835. if (fun.typeArguments) {
  17836. return path$$1.call(print, "typeArguments");
  17837. }
  17838. if (fun.typeParameters) {
  17839. return path$$1.call(print, "typeParameters");
  17840. }
  17841. return "";
  17842. }
  17843. function printFunctionParams(path$$1, print, options, expandArg, printTypeParams) {
  17844. var fun = path$$1.getValue();
  17845. var paramsField = fun.parameters ? "parameters" : "params";
  17846. var typeParams = printTypeParams ? printFunctionTypeParameters(path$$1, options, print) : "";
  17847. var printed = [];
  17848. if (fun[paramsField]) {
  17849. printed = path$$1.map(print, paramsField);
  17850. }
  17851. if (fun.rest) {
  17852. printed.push(concat$4(["...", path$$1.call(print, "rest")]));
  17853. }
  17854. if (printed.length === 0) {
  17855. return concat$4([typeParams, "(", comments.printDanglingComments(path$$1, options,
  17856. /* sameIndent */
  17857. true, function (comment) {
  17858. return getNextNonSpaceNonCommentCharacter$1(options.originalText, comment, options.locEnd) === ")";
  17859. }), ")"]);
  17860. }
  17861. var lastParam = getLast$4(fun[paramsField]); // If the parent is a call with the first/last argument expansion and this is the
  17862. // params of the first/last argument, we dont want the arguments to break and instead
  17863. // want the whole expression to be on a new line.
  17864. //
  17865. // Good: Bad:
  17866. // verylongcall( verylongcall((
  17867. // (a, b) => { a,
  17868. // } b,
  17869. // }) ) => {
  17870. // })
  17871. if (expandArg && !(fun[paramsField] && fun[paramsField].some(function (n) {
  17872. return n.comments;
  17873. }))) {
  17874. return group$1(concat$4([removeLines$1(typeParams), "(", join$2(", ", printed.map(removeLines$1)), ")"]));
  17875. } // Single object destructuring should hug
  17876. //
  17877. // function({
  17878. // a,
  17879. // b,
  17880. // c
  17881. // }) {}
  17882. if (shouldHugArguments(fun)) {
  17883. return concat$4([typeParams, "(", join$2(", ", printed), ")"]);
  17884. }
  17885. var parent = path$$1.getParentNode(); // don't break in specs, eg; `it("should maintain parens around done even when long", (done) => {})`
  17886. if (isTestCall(parent)) {
  17887. return concat$4([typeParams, "(", join$2(", ", printed), ")"]);
  17888. }
  17889. var flowTypeAnnotations = ["AnyTypeAnnotation", "NullLiteralTypeAnnotation", "GenericTypeAnnotation", "ThisTypeAnnotation", "NumberTypeAnnotation", "VoidTypeAnnotation", "EmptyTypeAnnotation", "MixedTypeAnnotation", "BooleanTypeAnnotation", "BooleanLiteralTypeAnnotation", "StringTypeAnnotation"];
  17890. var isFlowShorthandWithOneArg = (isObjectTypePropertyAFunction(parent, options) || isTypeAnnotationAFunction(parent, options) || parent.type === "TypeAlias" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || parent.type === "IntersectionTypeAnnotation" || parent.type === "FunctionTypeAnnotation" && parent.returnType === fun) && fun[paramsField].length === 1 && fun[paramsField][0].name === null && fun[paramsField][0].typeAnnotation && fun.typeParameters === null && flowTypeAnnotations.indexOf(fun[paramsField][0].typeAnnotation.type) !== -1 && !(fun[paramsField][0].typeAnnotation.type === "GenericTypeAnnotation" && fun[paramsField][0].typeAnnotation.typeParameters) && !fun.rest;
  17891. if (isFlowShorthandWithOneArg) {
  17892. if (options.arrowParens === "always") {
  17893. return concat$4(["(", concat$4(printed), ")"]);
  17894. }
  17895. return concat$4(printed);
  17896. }
  17897. var canHaveTrailingComma = !(lastParam && lastParam.type === "RestElement") && !fun.rest;
  17898. return concat$4([typeParams, "(", indent$2(concat$4([softline$1, join$2(concat$4([",", line$3]), printed)])), ifBreak$1(canHaveTrailingComma && shouldPrintComma(options, "all") ? "," : ""), softline$1, ")"]);
  17899. }
  17900. function shouldPrintParamsWithoutParens(path$$1, options) {
  17901. if (options.arrowParens === "always") {
  17902. return false;
  17903. }
  17904. if (options.arrowParens === "avoid") {
  17905. var node = path$$1.getValue();
  17906. return canPrintParamsWithoutParens(node);
  17907. } // Fallback default; should be unreachable
  17908. return false;
  17909. }
  17910. function canPrintParamsWithoutParens(node) {
  17911. return node.params.length === 1 && !node.rest && !node.typeParameters && !hasDanglingComments(node) && node.params[0].type === "Identifier" && !node.params[0].typeAnnotation && !node.params[0].comments && !node.params[0].optional && !node.predicate && !node.returnType;
  17912. }
  17913. function printFunctionDeclaration(path$$1, print, options) {
  17914. var n = path$$1.getValue();
  17915. var parts = [];
  17916. if (n.async) {
  17917. parts.push("async ");
  17918. }
  17919. parts.push("function");
  17920. if (n.generator) {
  17921. parts.push("*");
  17922. }
  17923. if (n.id) {
  17924. parts.push(" ", path$$1.call(print, "id"));
  17925. }
  17926. parts.push(printFunctionTypeParameters(path$$1, options, print), group$1(concat$4([printFunctionParams(path$$1, print, options), printReturnType(path$$1, print, options)])), n.body ? " " : "", path$$1.call(print, "body"));
  17927. return concat$4(parts);
  17928. }
  17929. function printObjectMethod(path$$1, options, print) {
  17930. var objMethod = path$$1.getValue();
  17931. var parts = [];
  17932. if (objMethod.async) {
  17933. parts.push("async ");
  17934. }
  17935. if (objMethod.generator) {
  17936. parts.push("*");
  17937. }
  17938. if (objMethod.method || objMethod.kind === "get" || objMethod.kind === "set") {
  17939. return printMethod(path$$1, options, print);
  17940. }
  17941. var key = printPropertyKey(path$$1, options, print);
  17942. if (objMethod.computed) {
  17943. parts.push("[", key, "]");
  17944. } else {
  17945. parts.push(key);
  17946. }
  17947. parts.push(printFunctionTypeParameters(path$$1, options, print), group$1(concat$4([printFunctionParams(path$$1, print, options), printReturnType(path$$1, print, options)])), " ", path$$1.call(print, "body"));
  17948. return concat$4(parts);
  17949. }
  17950. function printReturnType(path$$1, print, options) {
  17951. var n = path$$1.getValue();
  17952. var returnType = path$$1.call(print, "returnType");
  17953. if (n.returnType && isFlowAnnotationComment(options.originalText, n.returnType, options)) {
  17954. return concat$4([" /*: ", returnType, " */"]);
  17955. }
  17956. var parts = [returnType]; // prepend colon to TypeScript type annotation
  17957. if (n.returnType && n.returnType.typeAnnotation) {
  17958. parts.unshift(": ");
  17959. }
  17960. if (n.predicate) {
  17961. // The return type will already add the colon, but otherwise we
  17962. // need to do it ourselves
  17963. parts.push(n.returnType ? " " : ": ", path$$1.call(print, "predicate"));
  17964. }
  17965. return concat$4(parts);
  17966. }
  17967. function printExportDeclaration(path$$1, options, print) {
  17968. var decl = path$$1.getValue();
  17969. var semi = options.semi ? ";" : "";
  17970. var parts = ["export "];
  17971. var isDefault = decl["default"] || decl.type === "ExportDefaultDeclaration";
  17972. if (isDefault) {
  17973. parts.push("default ");
  17974. }
  17975. parts.push(comments.printDanglingComments(path$$1, options,
  17976. /* sameIndent */
  17977. true));
  17978. if (needsHardlineAfterDanglingComment(decl)) {
  17979. parts.push(hardline$3);
  17980. }
  17981. if (decl.declaration) {
  17982. parts.push(path$$1.call(print, "declaration"));
  17983. if (isDefault && decl.declaration.type !== "ClassDeclaration" && decl.declaration.type !== "FunctionDeclaration" && decl.declaration.type !== "TSAbstractClassDeclaration" && decl.declaration.type !== "TSInterfaceDeclaration" && decl.declaration.type !== "DeclareClass" && decl.declaration.type !== "DeclareFunction") {
  17984. parts.push(semi);
  17985. }
  17986. } else {
  17987. if (decl.specifiers && decl.specifiers.length > 0) {
  17988. var specifiers = [];
  17989. var defaultSpecifiers = [];
  17990. var namespaceSpecifiers = [];
  17991. path$$1.each(function (specifierPath) {
  17992. var specifierType = path$$1.getValue().type;
  17993. if (specifierType === "ExportSpecifier") {
  17994. specifiers.push(print(specifierPath));
  17995. } else if (specifierType === "ExportDefaultSpecifier") {
  17996. defaultSpecifiers.push(print(specifierPath));
  17997. } else if (specifierType === "ExportNamespaceSpecifier") {
  17998. namespaceSpecifiers.push(concat$4(["* as ", print(specifierPath)]));
  17999. }
  18000. }, "specifiers");
  18001. var isNamespaceFollowed = namespaceSpecifiers.length !== 0 && specifiers.length !== 0;
  18002. var isDefaultFollowed = defaultSpecifiers.length !== 0 && (namespaceSpecifiers.length !== 0 || specifiers.length !== 0);
  18003. parts.push(decl.exportKind === "type" ? "type " : "", concat$4(defaultSpecifiers), concat$4([isDefaultFollowed ? ", " : ""]), concat$4(namespaceSpecifiers), concat$4([isNamespaceFollowed ? ", " : ""]), specifiers.length !== 0 ? group$1(concat$4(["{", indent$2(concat$4([options.bracketSpacing ? line$3 : softline$1, join$2(concat$4([",", line$3]), specifiers)])), ifBreak$1(shouldPrintComma(options) ? "," : ""), options.bracketSpacing ? line$3 : softline$1, "}"])) : "");
  18004. } else {
  18005. parts.push("{}");
  18006. }
  18007. if (decl.source) {
  18008. parts.push(" from ", path$$1.call(print, "source"));
  18009. }
  18010. parts.push(semi);
  18011. }
  18012. return concat$4(parts);
  18013. }
  18014. function printFlowDeclaration(path$$1, parts) {
  18015. var parentExportDecl = getParentExportDeclaration$1(path$$1);
  18016. if (parentExportDecl) {
  18017. assert.strictEqual(parentExportDecl.type, "DeclareExportDeclaration");
  18018. } else {
  18019. // If the parent node has type DeclareExportDeclaration, then it
  18020. // will be responsible for printing the "declare" token. Otherwise
  18021. // it needs to be printed with this non-exported declaration node.
  18022. parts.unshift("declare ");
  18023. }
  18024. return concat$4(parts);
  18025. }
  18026. function getFlowVariance(path$$1) {
  18027. if (!path$$1.variance) {
  18028. return null;
  18029. } // Babylon 7.0 currently uses variance node type, and flow should
  18030. // follow suit soon:
  18031. // https://github.com/babel/babel/issues/4722
  18032. var variance = path$$1.variance.kind || path$$1.variance;
  18033. switch (variance) {
  18034. case "plus":
  18035. return "+";
  18036. case "minus":
  18037. return "-";
  18038. default:
  18039. /* istanbul ignore next */
  18040. return variance;
  18041. }
  18042. }
  18043. function printTypeScriptModifiers(path$$1, options, print) {
  18044. var n = path$$1.getValue();
  18045. if (!n.modifiers || !n.modifiers.length) {
  18046. return "";
  18047. }
  18048. return concat$4([join$2(" ", path$$1.map(print, "modifiers")), " "]);
  18049. }
  18050. function printTypeParameters(path$$1, options, print, paramsKey) {
  18051. var n = path$$1.getValue();
  18052. if (!n[paramsKey]) {
  18053. return "";
  18054. } // for TypeParameterDeclaration typeParameters is a single node
  18055. if (!Array.isArray(n[paramsKey])) {
  18056. return path$$1.call(print, paramsKey);
  18057. }
  18058. var grandparent = path$$1.getNode(2);
  18059. var isParameterInTestCall = grandparent != null && isTestCall(grandparent);
  18060. var shouldInline = isParameterInTestCall || n[paramsKey].length === 0 || n[paramsKey].length === 1 && (shouldHugType(n[paramsKey][0]) || n[paramsKey][0].type === "GenericTypeAnnotation" && shouldHugType(n[paramsKey][0].id) || n[paramsKey][0].type === "TSTypeReference" && shouldHugType(n[paramsKey][0].typeName) || n[paramsKey][0].type === "NullableTypeAnnotation");
  18061. if (shouldInline) {
  18062. return concat$4(["<", join$2(", ", path$$1.map(print, paramsKey)), ">"]);
  18063. }
  18064. return group$1(concat$4(["<", indent$2(concat$4([softline$1, join$2(concat$4([",", line$3]), path$$1.map(print, paramsKey))])), ifBreak$1(options.parser !== "typescript" && shouldPrintComma(options, "all") ? "," : ""), softline$1, ">"]));
  18065. }
  18066. function printClass(path$$1, options, print) {
  18067. var n = path$$1.getValue();
  18068. var parts = [];
  18069. if (n.type === "TSAbstractClassDeclaration") {
  18070. parts.push("abstract ");
  18071. }
  18072. parts.push("class");
  18073. if (n.id) {
  18074. parts.push(" ", path$$1.call(print, "id"));
  18075. }
  18076. parts.push(path$$1.call(print, "typeParameters"));
  18077. var partsGroup = [];
  18078. if (n.superClass) {
  18079. var printed = concat$4(["extends ", path$$1.call(print, "superClass"), path$$1.call(print, "superTypeParameters")]); // Keep old behaviour of extends in same line
  18080. // If there is only on extends and there are not comments
  18081. if ((!n.implements || n.implements.length === 0) && (!n.superClass.comments || n.superClass.comments.length === 0)) {
  18082. parts.push(concat$4([" ", path$$1.call(function (superClass) {
  18083. return comments.printComments(superClass, function () {
  18084. return printed;
  18085. }, options);
  18086. }, "superClass")]));
  18087. } else {
  18088. partsGroup.push(group$1(concat$4([line$3, path$$1.call(function (superClass) {
  18089. return comments.printComments(superClass, function () {
  18090. return printed;
  18091. }, options);
  18092. }, "superClass")])));
  18093. }
  18094. } else if (n.extends && n.extends.length > 0) {
  18095. parts.push(" extends ", join$2(", ", path$$1.map(print, "extends")));
  18096. }
  18097. if (n["mixins"] && n["mixins"].length > 0) {
  18098. partsGroup.push(line$3, "mixins ", group$1(indent$2(join$2(concat$4([",", line$3]), path$$1.map(print, "mixins")))));
  18099. }
  18100. if (n["implements"] && n["implements"].length > 0) {
  18101. partsGroup.push(line$3, "implements", group$1(indent$2(concat$4([line$3, join$2(concat$4([",", line$3]), path$$1.map(print, "implements"))]))));
  18102. }
  18103. if (partsGroup.length > 0) {
  18104. parts.push(group$1(indent$2(concat$4(partsGroup))));
  18105. }
  18106. if (n.body && n.body.comments && hasLeadingOwnLineComment(options.originalText, n.body, options)) {
  18107. parts.push(hardline$3);
  18108. } else {
  18109. parts.push(" ");
  18110. }
  18111. parts.push(path$$1.call(print, "body"));
  18112. return parts;
  18113. }
  18114. function printOptionalToken(path$$1) {
  18115. var node = path$$1.getValue();
  18116. if (!node.optional) {
  18117. return "";
  18118. }
  18119. if (node.type === "OptionalCallExpression" || node.type === "OptionalMemberExpression" && node.computed) {
  18120. return "?.";
  18121. }
  18122. return "?";
  18123. }
  18124. function printMemberLookup(path$$1, options, print) {
  18125. var property = path$$1.call(print, "property");
  18126. var n = path$$1.getValue();
  18127. var optional = printOptionalToken(path$$1);
  18128. if (!n.computed) {
  18129. return concat$4([optional, ".", property]);
  18130. }
  18131. if (!n.property || isNumericLiteral(n.property)) {
  18132. return concat$4([optional, "[", property, "]"]);
  18133. }
  18134. return group$1(concat$4([optional, "[", indent$2(concat$4([softline$1, property])), softline$1, "]"]));
  18135. }
  18136. function printBindExpressionCallee(path$$1, options, print) {
  18137. return concat$4(["::", path$$1.call(print, "callee")]);
  18138. } // We detect calls on member expressions specially to format a
  18139. // common pattern better. The pattern we are looking for is this:
  18140. //
  18141. // arr
  18142. // .map(x => x + 1)
  18143. // .filter(x => x > 10)
  18144. // .some(x => x % 2)
  18145. //
  18146. // The way it is structured in the AST is via a nested sequence of
  18147. // MemberExpression and CallExpression. We need to traverse the AST
  18148. // and make groups out of it to print it in the desired way.
  18149. function printMemberChain(path$$1, options, print) {
  18150. // The first phase is to linearize the AST by traversing it down.
  18151. //
  18152. // a().b()
  18153. // has the following AST structure:
  18154. // CallExpression(MemberExpression(CallExpression(Identifier)))
  18155. // and we transform it into
  18156. // [Identifier, CallExpression, MemberExpression, CallExpression]
  18157. var printedNodes = []; // Here we try to retain one typed empty line after each call expression or
  18158. // the first group whether it is in parentheses or not
  18159. function shouldInsertEmptyLineAfter(node) {
  18160. var originalText = options.originalText;
  18161. var nextCharIndex = getNextNonSpaceNonCommentCharacterIndex$2(originalText, node, options);
  18162. var nextChar = originalText.charAt(nextCharIndex); // if it is cut off by a parenthesis, we only account for one typed empty
  18163. // line after that parenthesis
  18164. if (nextChar == ")") {
  18165. return isNextLineEmptyAfterIndex$1(originalText, nextCharIndex + 1, options);
  18166. }
  18167. return isNextLineEmpty$2(originalText, node, options);
  18168. }
  18169. function rec(path$$1) {
  18170. var node = path$$1.getValue();
  18171. if ((node.type === "CallExpression" || node.type === "OptionalCallExpression") && (isMemberish(node.callee) || node.callee.type === "CallExpression" || node.callee.type === "OptionalCallExpression")) {
  18172. printedNodes.unshift({
  18173. node: node,
  18174. printed: concat$4([comments.printComments(path$$1, function () {
  18175. return concat$4([printOptionalToken(path$$1), printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)]);
  18176. }, options), shouldInsertEmptyLineAfter(node) ? hardline$3 : ""])
  18177. });
  18178. path$$1.call(function (callee) {
  18179. return rec(callee);
  18180. }, "callee");
  18181. } else if (isMemberish(node)) {
  18182. printedNodes.unshift({
  18183. node: node,
  18184. needsParens: needsParens_1(path$$1, options),
  18185. printed: comments.printComments(path$$1, function () {
  18186. return node.type === "OptionalMemberExpression" || node.type === "MemberExpression" ? printMemberLookup(path$$1, options, print) : printBindExpressionCallee(path$$1, options, print);
  18187. }, options)
  18188. });
  18189. path$$1.call(function (object) {
  18190. return rec(object);
  18191. }, "object");
  18192. } else if (node.type === "TSNonNullExpression") {
  18193. printedNodes.unshift({
  18194. node: node,
  18195. printed: comments.printComments(path$$1, function () {
  18196. return "!";
  18197. }, options)
  18198. });
  18199. path$$1.call(function (expression) {
  18200. return rec(expression);
  18201. }, "expression");
  18202. } else {
  18203. printedNodes.unshift({
  18204. node: node,
  18205. printed: path$$1.call(print)
  18206. });
  18207. }
  18208. } // Note: the comments of the root node have already been printed, so we
  18209. // need to extract this first call without printing them as they would
  18210. // if handled inside of the recursive call.
  18211. var node = path$$1.getValue();
  18212. printedNodes.unshift({
  18213. node,
  18214. printed: concat$4([printOptionalToken(path$$1), printFunctionTypeParameters(path$$1, options, print), printArgumentsList(path$$1, options, print)])
  18215. });
  18216. path$$1.call(function (callee) {
  18217. return rec(callee);
  18218. }, "callee"); // Once we have a linear list of printed nodes, we want to create groups out
  18219. // of it.
  18220. //
  18221. // a().b.c().d().e
  18222. // will be grouped as
  18223. // [
  18224. // [Identifier, CallExpression],
  18225. // [MemberExpression, MemberExpression, CallExpression],
  18226. // [MemberExpression, CallExpression],
  18227. // [MemberExpression],
  18228. // ]
  18229. // so that we can print it as
  18230. // a()
  18231. // .b.c()
  18232. // .d()
  18233. // .e
  18234. // The first group is the first node followed by
  18235. // - as many CallExpression as possible
  18236. // < fn()()() >.something()
  18237. // - as many array acessors as possible
  18238. // < fn()[0][1][2] >.something()
  18239. // - then, as many MemberExpression as possible but the last one
  18240. // < this.items >.something()
  18241. var groups = [];
  18242. var currentGroup = [printedNodes[0]];
  18243. var i = 1;
  18244. for (; i < printedNodes.length; ++i) {
  18245. if (printedNodes[i].node.type === "TSNonNullExpression" || printedNodes[i].node.type === "OptionalCallExpression" || printedNodes[i].node.type === "CallExpression" || (printedNodes[i].node.type === "MemberExpression" || printedNodes[i].node.type === "OptionalMemberExpression") && printedNodes[i].node.computed && isNumericLiteral(printedNodes[i].node.property)) {
  18246. currentGroup.push(printedNodes[i]);
  18247. } else {
  18248. break;
  18249. }
  18250. }
  18251. if (printedNodes[0].node.type !== "CallExpression" && printedNodes[0].node.type !== "OptionalCallExpression") {
  18252. for (; i + 1 < printedNodes.length; ++i) {
  18253. if (isMemberish(printedNodes[i].node) && isMemberish(printedNodes[i + 1].node)) {
  18254. currentGroup.push(printedNodes[i]);
  18255. } else {
  18256. break;
  18257. }
  18258. }
  18259. }
  18260. groups.push(currentGroup);
  18261. currentGroup = []; // Then, each following group is a sequence of MemberExpression followed by
  18262. // a sequence of CallExpression. To compute it, we keep adding things to the
  18263. // group until we has seen a CallExpression in the past and reach a
  18264. // MemberExpression
  18265. var hasSeenCallExpression = false;
  18266. for (; i < printedNodes.length; ++i) {
  18267. if (hasSeenCallExpression && isMemberish(printedNodes[i].node)) {
  18268. // [0] should be appended at the end of the group instead of the
  18269. // beginning of the next one
  18270. if (printedNodes[i].node.computed && isNumericLiteral(printedNodes[i].node.property)) {
  18271. currentGroup.push(printedNodes[i]);
  18272. continue;
  18273. }
  18274. groups.push(currentGroup);
  18275. currentGroup = [];
  18276. hasSeenCallExpression = false;
  18277. }
  18278. if (printedNodes[i].node.type === "CallExpression" || printedNodes[i].node.type === "OptionalCallExpression") {
  18279. hasSeenCallExpression = true;
  18280. }
  18281. currentGroup.push(printedNodes[i]);
  18282. if (printedNodes[i].node.comments && printedNodes[i].node.comments.some(function (comment) {
  18283. return comment.trailing;
  18284. })) {
  18285. groups.push(currentGroup);
  18286. currentGroup = [];
  18287. hasSeenCallExpression = false;
  18288. }
  18289. }
  18290. if (currentGroup.length > 0) {
  18291. groups.push(currentGroup);
  18292. } // There are cases like Object.keys(), Observable.of(), _.values() where
  18293. // they are the subject of all the chained calls and therefore should
  18294. // be kept on the same line:
  18295. //
  18296. // Object.keys(items)
  18297. // .filter(x => x)
  18298. // .map(x => x)
  18299. //
  18300. // In order to detect those cases, we use an heuristic: if the first
  18301. // node is an identifier with the name starting with a capital
  18302. // letter or just a sequence of _$. The rationale is that they are
  18303. // likely to be factories.
  18304. function isFactory(name) {
  18305. return /^[A-Z]|^[_$]+$/.test(name);
  18306. } // In case the Identifier is shorter than tab width, we can keep the
  18307. // first call in a single line, if it's an ExpressionStatement.
  18308. //
  18309. // d3.scaleLinear()
  18310. // .domain([0, 100])
  18311. // .range([0, width]);
  18312. //
  18313. function isShort(name) {
  18314. return name.length <= options.tabWidth;
  18315. }
  18316. function shouldNotWrap(groups) {
  18317. var parent = path$$1.getParentNode();
  18318. var isExpression = parent && parent.type === "ExpressionStatement";
  18319. var hasComputed = groups[1].length && groups[1][0].node.computed;
  18320. if (groups[0].length === 1) {
  18321. var firstNode = groups[0][0].node;
  18322. return firstNode.type === "ThisExpression" || firstNode.type === "Identifier" && (isFactory(firstNode.name) || isExpression && isShort(firstNode.name) || hasComputed);
  18323. }
  18324. var lastNode = getLast$4(groups[0]).node;
  18325. return (lastNode.type === "MemberExpression" || lastNode.type === "OptionalMemberExpression") && lastNode.property.type === "Identifier" && (isFactory(lastNode.property.name) || hasComputed);
  18326. }
  18327. var shouldMerge = groups.length >= 2 && !groups[1][0].node.comments && shouldNotWrap(groups);
  18328. function printGroup(printedGroup) {
  18329. var result = [];
  18330. for (var _i3 = 0; _i3 < printedGroup.length; _i3++) {
  18331. // Checks if the next node (i.e. the parent node) needs parens
  18332. // and print accordingl y
  18333. if (printedGroup[_i3 + 1] && printedGroup[_i3 + 1].needsParens) {
  18334. result.push("(", printedGroup[_i3].printed, printedGroup[_i3 + 1].printed, ")");
  18335. _i3++;
  18336. } else {
  18337. result.push(printedGroup[_i3].printed);
  18338. }
  18339. }
  18340. return concat$4(result);
  18341. }
  18342. function printIndentedGroup(groups) {
  18343. if (groups.length === 0) {
  18344. return "";
  18345. }
  18346. return indent$2(group$1(concat$4([hardline$3, join$2(hardline$3, groups.map(printGroup))])));
  18347. }
  18348. var printedGroups = groups.map(printGroup);
  18349. var oneLine = concat$4(printedGroups);
  18350. var cutoff = shouldMerge ? 3 : 2;
  18351. var flatGroups = groups.slice(0, cutoff).reduce(function (res, group) {
  18352. return res.concat(group);
  18353. }, []);
  18354. var hasComment = flatGroups.slice(1, -1).some(function (node) {
  18355. return hasLeadingComment(node.node);
  18356. }) || flatGroups.slice(0, -1).some(function (node) {
  18357. return hasTrailingComment(node.node);
  18358. }) || groups[cutoff] && hasLeadingComment(groups[cutoff][0].node); // If we only have a single `.`, we shouldn't do anything fancy and just
  18359. // render everything concatenated together.
  18360. if (groups.length <= cutoff && !hasComment) {
  18361. return group$1(oneLine);
  18362. } // Find out the last node in the first group and check if it has an
  18363. // empty line after
  18364. var lastNodeBeforeIndent = getLast$4(shouldMerge ? groups.slice(1, 2)[0] : groups[0]).node;
  18365. var shouldHaveEmptyLineBeforeIndent = lastNodeBeforeIndent.type !== "CallExpression" && lastNodeBeforeIndent.type !== "OptionalCallExpression" && shouldInsertEmptyLineAfter(lastNodeBeforeIndent);
  18366. var expanded = concat$4([printGroup(groups[0]), shouldMerge ? concat$4(groups.slice(1, 2).map(printGroup)) : "", shouldHaveEmptyLineBeforeIndent ? hardline$3 : "", printIndentedGroup(groups.slice(shouldMerge ? 2 : 1))]);
  18367. var callExpressionCount = printedNodes.filter(function (tuple) {
  18368. return tuple.node.type === "CallExpression" || tuple.node.type === "OptionalCallExpression";
  18369. }).length; // We don't want to print in one line if there's:
  18370. // * A comment.
  18371. // * 3 or more chained calls.
  18372. // * Any group but the last one has a hard line.
  18373. // If the last group is a function it's okay to inline if it fits.
  18374. if (hasComment || callExpressionCount >= 3 || printedGroups.slice(0, -1).some(willBreak$1)) {
  18375. return group$1(expanded);
  18376. }
  18377. return concat$4([// We only need to check `oneLine` because if `expanded` is chosen
  18378. // that means that the parent group has already been broken
  18379. // naturally
  18380. willBreak$1(oneLine) || shouldHaveEmptyLineBeforeIndent ? breakParent$2 : "", conditionalGroup$1([oneLine, expanded])]);
  18381. }
  18382. function isJSXNode(node) {
  18383. return node.type === "JSXElement" || node.type === "JSXFragment" || node.type === "TSJsxFragment";
  18384. }
  18385. function isEmptyJSXElement(node) {
  18386. if (node.children.length === 0) {
  18387. return true;
  18388. }
  18389. if (node.children.length > 1) {
  18390. return false;
  18391. } // if there is one text child and does not contain any meaningful text
  18392. // we can treat the element as empty.
  18393. var child = node.children[0];
  18394. return isLiteral(child) && !isMeaningfulJSXText(child);
  18395. } // Only space, newline, carriage return, and tab are treated as whitespace
  18396. // inside JSX.
  18397. var jsxWhitespaceChars = " \n\r\t";
  18398. var containsNonJsxWhitespaceRegex = new RegExp("[^" + jsxWhitespaceChars + "]");
  18399. var matchJsxWhitespaceRegex = new RegExp("([" + jsxWhitespaceChars + "]+)"); // Meaningful if it contains non-whitespace characters,
  18400. // or it contains whitespace without a new line.
  18401. function isMeaningfulJSXText(node) {
  18402. return isLiteral(node) && (containsNonJsxWhitespaceRegex.test(rawText(node)) || !/\n/.test(rawText(node)));
  18403. }
  18404. function conditionalExpressionChainContainsJSX(node) {
  18405. return Boolean(getConditionalChainContents(node).find(isJSXNode));
  18406. } // If we have nested conditional expressions, we want to print them in JSX mode
  18407. // if there's at least one JSXElement somewhere in the tree.
  18408. //
  18409. // A conditional expression chain like this should be printed in normal mode,
  18410. // because there aren't JSXElements anywhere in it:
  18411. //
  18412. // isA ? "A" : isB ? "B" : isC ? "C" : "Unknown";
  18413. //
  18414. // But a conditional expression chain like this should be printed in JSX mode,
  18415. // because there is a JSXElement in the last ConditionalExpression:
  18416. //
  18417. // isA ? "A" : isB ? "B" : isC ? "C" : <span className="warning">Unknown</span>;
  18418. //
  18419. // This type of ConditionalExpression chain is structured like this in the AST:
  18420. //
  18421. // ConditionalExpression {
  18422. // test: ...,
  18423. // consequent: ...,
  18424. // alternate: ConditionalExpression {
  18425. // test: ...,
  18426. // consequent: ...,
  18427. // alternate: ConditionalExpression {
  18428. // test: ...,
  18429. // consequent: ...,
  18430. // alternate: ...,
  18431. // }
  18432. // }
  18433. // }
  18434. //
  18435. // We want to traverse over that shape and convert it into a flat structure so
  18436. // that we can find if there's a JSXElement somewhere inside.
  18437. function getConditionalChainContents(node) {
  18438. // Given this code:
  18439. //
  18440. // // Using a ConditionalExpression as the consequent is uncommon, but should
  18441. // // be handled.
  18442. // A ? B : C ? D : E ? F ? G : H : I
  18443. //
  18444. // which has this AST:
  18445. //
  18446. // ConditionalExpression {
  18447. // test: Identifier(A),
  18448. // consequent: Identifier(B),
  18449. // alternate: ConditionalExpression {
  18450. // test: Identifier(C),
  18451. // consequent: Identifier(D),
  18452. // alternate: ConditionalExpression {
  18453. // test: Identifier(E),
  18454. // consequent: ConditionalExpression {
  18455. // test: Identifier(F),
  18456. // consequent: Identifier(G),
  18457. // alternate: Identifier(H),
  18458. // },
  18459. // alternate: Identifier(I),
  18460. // }
  18461. // }
  18462. // }
  18463. //
  18464. // we should return this Array:
  18465. //
  18466. // [
  18467. // Identifier(A),
  18468. // Identifier(B),
  18469. // Identifier(C),
  18470. // Identifier(D),
  18471. // Identifier(E),
  18472. // Identifier(F),
  18473. // Identifier(G),
  18474. // Identifier(H),
  18475. // Identifier(I)
  18476. // ];
  18477. //
  18478. // This loses the information about whether each node was the test,
  18479. // consequent, or alternate, but we don't care about that here- we are only
  18480. // flattening this structure to find if there's any JSXElements inside.
  18481. var nonConditionalExpressions = [];
  18482. function recurse(node) {
  18483. if (node.type === "ConditionalExpression") {
  18484. recurse(node.test);
  18485. recurse(node.consequent);
  18486. recurse(node.alternate);
  18487. } else {
  18488. nonConditionalExpressions.push(node);
  18489. }
  18490. }
  18491. recurse(node);
  18492. return nonConditionalExpressions;
  18493. } // Detect an expression node representing `{" "}`
  18494. function isJSXWhitespaceExpression(node) {
  18495. return node.type === "JSXExpressionContainer" && isLiteral(node.expression) && node.expression.value === " " && !node.expression.comments;
  18496. } // JSX Children are strange, mostly for two reasons:
  18497. // 1. JSX reads newlines into string values, instead of skipping them like JS
  18498. // 2. up to one whitespace between elements within a line is significant,
  18499. // but not between lines.
  18500. //
  18501. // Leading, trailing, and lone whitespace all need to
  18502. // turn themselves into the rather ugly `{' '}` when breaking.
  18503. //
  18504. // We print JSX using the `fill` doc primitive.
  18505. // This requires that we give it an array of alternating
  18506. // content and whitespace elements.
  18507. // To ensure this we add dummy `""` content elements as needed.
  18508. function printJSXChildren(path$$1, options, print, jsxWhitespace) {
  18509. var n = path$$1.getValue();
  18510. var children = []; // using `map` instead of `each` because it provides `i`
  18511. path$$1.map(function (childPath, i) {
  18512. var child = childPath.getValue();
  18513. if (isLiteral(child)) {
  18514. var text = rawText(child); // Contains a non-whitespace character
  18515. if (isMeaningfulJSXText(child)) {
  18516. var words = text.split(matchJsxWhitespaceRegex); // Starts with whitespace
  18517. if (words[0] === "") {
  18518. children.push("");
  18519. words.shift();
  18520. if (/\n/.test(words[0])) {
  18521. children.push(hardline$3);
  18522. } else {
  18523. children.push(jsxWhitespace);
  18524. }
  18525. words.shift();
  18526. }
  18527. var endWhitespace; // Ends with whitespace
  18528. if (getLast$4(words) === "") {
  18529. words.pop();
  18530. endWhitespace = words.pop();
  18531. } // This was whitespace only without a new line.
  18532. if (words.length === 0) {
  18533. return;
  18534. }
  18535. words.forEach(function (word, i) {
  18536. if (i % 2 === 1) {
  18537. children.push(line$3);
  18538. } else {
  18539. children.push(word);
  18540. }
  18541. });
  18542. if (endWhitespace !== undefined) {
  18543. if (/\n/.test(endWhitespace)) {
  18544. children.push(hardline$3);
  18545. } else {
  18546. children.push(jsxWhitespace);
  18547. }
  18548. } else {
  18549. // Ideally this would be a `hardline` to allow a break between
  18550. // tags and text.
  18551. // Unfortunately Facebook have a custom translation pipeline
  18552. // (https://github.com/prettier/prettier/issues/1581#issuecomment-300975032)
  18553. // that uses the JSX syntax, but does not follow the React whitespace
  18554. // rules.
  18555. // Ensuring that we never have a break between tags and text in JSX
  18556. // will allow Facebook to adopt Prettier without too much of an
  18557. // adverse effect on formatting algorithm.
  18558. children.push("");
  18559. }
  18560. } else if (/\n/.test(text)) {
  18561. // Keep (up to one) blank line between tags/expressions/text.
  18562. // Note: We don't keep blank lines between text elements.
  18563. if (text.match(/\n/g).length > 1) {
  18564. children.push("");
  18565. children.push(hardline$3);
  18566. }
  18567. } else {
  18568. children.push("");
  18569. children.push(jsxWhitespace);
  18570. }
  18571. } else {
  18572. var printedChild = print(childPath);
  18573. children.push(printedChild);
  18574. var next = n.children[i + 1];
  18575. var directlyFollowedByMeaningfulText = next && isMeaningfulJSXText(next) && !/^[ \n\r\t]/.test(rawText(next));
  18576. if (directlyFollowedByMeaningfulText) {
  18577. // Potentially this could be a hardline as well.
  18578. // See the comment above about the Facebook translation pipeline as
  18579. // to why this is an empty string.
  18580. children.push("");
  18581. } else {
  18582. children.push(hardline$3);
  18583. }
  18584. }
  18585. }, "children");
  18586. return children;
  18587. } // JSX expands children from the inside-out, instead of the outside-in.
  18588. // This is both to break children before attributes,
  18589. // and to ensure that when children break, their parents do as well.
  18590. //
  18591. // Any element that is written without any newlines and fits on a single line
  18592. // is left that way.
  18593. // Not only that, any user-written-line containing multiple JSX siblings
  18594. // should also be kept on one line if possible,
  18595. // so each user-written-line is wrapped in its own group.
  18596. //
  18597. // Elements that contain newlines or don't fit on a single line (recursively)
  18598. // are fully-split, using hardline and shouldBreak: true.
  18599. //
  18600. // To support that case properly, all leading and trailing spaces
  18601. // are stripped from the list of children, and replaced with a single hardline.
  18602. function printJSXElement(path$$1, options, print) {
  18603. var n = path$$1.getValue(); // Turn <div></div> into <div />
  18604. if (n.type === "JSXElement" && isEmptyJSXElement(n)) {
  18605. n.openingElement.selfClosing = true;
  18606. return path$$1.call(print, "openingElement");
  18607. }
  18608. var openingLines = n.type === "JSXElement" ? path$$1.call(print, "openingElement") : path$$1.call(print, "openingFragment");
  18609. var closingLines = n.type === "JSXElement" ? path$$1.call(print, "closingElement") : path$$1.call(print, "closingFragment");
  18610. if (n.children.length === 1 && n.children[0].type === "JSXExpressionContainer" && (n.children[0].expression.type === "TemplateLiteral" || n.children[0].expression.type === "TaggedTemplateExpression")) {
  18611. return concat$4([openingLines, concat$4(path$$1.map(print, "children")), closingLines]);
  18612. } // Convert `{" "}` to text nodes containing a space.
  18613. // This makes it easy to turn them into `jsxWhitespace` which
  18614. // can then print as either a space or `{" "}` when breaking.
  18615. n.children = n.children.map(function (child) {
  18616. if (isJSXWhitespaceExpression(child)) {
  18617. return {
  18618. type: "JSXText",
  18619. value: " ",
  18620. raw: " "
  18621. };
  18622. }
  18623. return child;
  18624. });
  18625. var containsTag = n.children.filter(isJSXNode).length > 0;
  18626. var containsMultipleExpressions = n.children.filter(function (child) {
  18627. return child.type === "JSXExpressionContainer";
  18628. }).length > 1;
  18629. var containsMultipleAttributes = n.type === "JSXElement" && n.openingElement.attributes.length > 1; // Record any breaks. Should never go from true to false, only false to true.
  18630. var forcedBreak = willBreak$1(openingLines) || containsTag || containsMultipleAttributes || containsMultipleExpressions;
  18631. var rawJsxWhitespace = options.singleQuote ? "{' '}" : '{" "}';
  18632. var jsxWhitespace = ifBreak$1(concat$4([rawJsxWhitespace, softline$1]), " ");
  18633. var children = printJSXChildren(path$$1, options, print, jsxWhitespace);
  18634. var containsText = n.children.filter(function (child) {
  18635. return isMeaningfulJSXText(child);
  18636. }).length > 0; // We can end up we multiple whitespace elements with empty string
  18637. // content between them.
  18638. // We need to remove empty whitespace and softlines before JSX whitespace
  18639. // to get the correct output.
  18640. for (var i = children.length - 2; i >= 0; i--) {
  18641. var isPairOfEmptyStrings = children[i] === "" && children[i + 1] === "";
  18642. var isPairOfHardlines = children[i] === hardline$3 && children[i + 1] === "" && children[i + 2] === hardline$3;
  18643. var isLineFollowedByJSXWhitespace = (children[i] === softline$1 || children[i] === hardline$3) && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  18644. var isJSXWhitespaceFollowedByLine = children[i] === jsxWhitespace && children[i + 1] === "" && (children[i + 2] === softline$1 || children[i + 2] === hardline$3);
  18645. var isDoubleJSXWhitespace = children[i] === jsxWhitespace && children[i + 1] === "" && children[i + 2] === jsxWhitespace;
  18646. if (isPairOfHardlines && containsText || isPairOfEmptyStrings || isLineFollowedByJSXWhitespace || isDoubleJSXWhitespace) {
  18647. children.splice(i, 2);
  18648. } else if (isJSXWhitespaceFollowedByLine) {
  18649. children.splice(i + 1, 2);
  18650. }
  18651. } // Trim trailing lines (or empty strings)
  18652. while (children.length && (isLineNext$1(getLast$4(children)) || isEmpty$1(getLast$4(children)))) {
  18653. children.pop();
  18654. } // Trim leading lines (or empty strings)
  18655. while (children.length && (isLineNext$1(children[0]) || isEmpty$1(children[0])) && (isLineNext$1(children[1]) || isEmpty$1(children[1]))) {
  18656. children.shift();
  18657. children.shift();
  18658. } // Tweak how we format children if outputting this element over multiple lines.
  18659. // Also detect whether we will force this element to output over multiple lines.
  18660. var multilineChildren = [];
  18661. children.forEach(function (child, i) {
  18662. // There are a number of situations where we need to ensure we display
  18663. // whitespace as `{" "}` when outputting this element over multiple lines.
  18664. if (child === jsxWhitespace) {
  18665. if (i === 1 && children[i - 1] === "") {
  18666. if (children.length === 2) {
  18667. // Solitary whitespace
  18668. multilineChildren.push(rawJsxWhitespace);
  18669. return;
  18670. } // Leading whitespace
  18671. multilineChildren.push(concat$4([rawJsxWhitespace, hardline$3]));
  18672. return;
  18673. } else if (i === children.length - 1) {
  18674. // Trailing whitespace
  18675. multilineChildren.push(rawJsxWhitespace);
  18676. return;
  18677. } else if (children[i - 1] === "" && children[i - 2] === hardline$3) {
  18678. // Whitespace after line break
  18679. multilineChildren.push(rawJsxWhitespace);
  18680. return;
  18681. }
  18682. }
  18683. multilineChildren.push(child);
  18684. if (willBreak$1(child)) {
  18685. forcedBreak = true;
  18686. }
  18687. }); // If there is text we use `fill` to fit as much onto each line as possible.
  18688. // When there is no text (just tags and expressions) we use `group`
  18689. // to output each on a separate line.
  18690. var content = containsText ? fill$2(multilineChildren) : group$1(concat$4(multilineChildren), {
  18691. shouldBreak: true
  18692. });
  18693. var multiLineElem = group$1(concat$4([openingLines, indent$2(concat$4([hardline$3, content])), hardline$3, closingLines]));
  18694. if (forcedBreak) {
  18695. return multiLineElem;
  18696. }
  18697. return conditionalGroup$1([group$1(concat$4([openingLines, concat$4(children), closingLines])), multiLineElem]);
  18698. }
  18699. function maybeWrapJSXElementInParens(path$$1, elem) {
  18700. var parent = path$$1.getParentNode();
  18701. if (!parent) {
  18702. return elem;
  18703. }
  18704. var NO_WRAP_PARENTS = {
  18705. ArrayExpression: true,
  18706. JSXAttribute: true,
  18707. JSXElement: true,
  18708. JSXExpressionContainer: true,
  18709. JSXFragment: true,
  18710. TSJsxFragment: true,
  18711. ExpressionStatement: true,
  18712. CallExpression: true,
  18713. OptionalCallExpression: true,
  18714. ConditionalExpression: true
  18715. };
  18716. if (NO_WRAP_PARENTS[parent.type]) {
  18717. return elem;
  18718. }
  18719. return group$1(concat$4([ifBreak$1("("), indent$2(concat$4([softline$1, elem])), softline$1, ifBreak$1(")")]));
  18720. }
  18721. function isBinaryish(node) {
  18722. return node.type === "BinaryExpression" || node.type === "LogicalExpression";
  18723. }
  18724. function isMemberish(node) {
  18725. return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "BindExpression" && node.object;
  18726. }
  18727. function shouldInlineLogicalExpression(node) {
  18728. if (node.type !== "LogicalExpression") {
  18729. return false;
  18730. }
  18731. if (node.right.type === "ObjectExpression" && node.right.properties.length !== 0) {
  18732. return true;
  18733. }
  18734. if (node.right.type === "ArrayExpression" && node.right.elements.length !== 0) {
  18735. return true;
  18736. }
  18737. if (isJSXNode(node.right)) {
  18738. return true;
  18739. }
  18740. return false;
  18741. } // For binary expressions to be consistent, we need to group
  18742. // subsequent operators with the same precedence level under a single
  18743. // group. Otherwise they will be nested such that some of them break
  18744. // onto new lines but not all. Operators with the same precedence
  18745. // level should either all break or not. Because we group them by
  18746. // precedence level and the AST is structured based on precedence
  18747. // level, things are naturally broken up correctly, i.e. `&&` is
  18748. // broken before `+`.
  18749. function printBinaryishExpressions(path$$1, print, options, isNested, isInsideParenthesis) {
  18750. var parts = [];
  18751. var node = path$$1.getValue(); // We treat BinaryExpression and LogicalExpression nodes the same.
  18752. if (isBinaryish(node)) {
  18753. // Put all operators with the same precedence level in the same
  18754. // group. The reason we only need to do this with the `left`
  18755. // expression is because given an expression like `1 + 2 - 3`, it
  18756. // is always parsed like `((1 + 2) - 3)`, meaning the `left` side
  18757. // is where the rest of the expression will exist. Binary
  18758. // expressions on the right side mean they have a difference
  18759. // precedence level and should be treated as a separate group, so
  18760. // print them normally. (This doesn't hold for the `**` operator,
  18761. // which is unique in that it is right-associative.)
  18762. if (shouldFlatten$1(node.operator, node.left.operator)) {
  18763. // Flatten them out by recursively calling this function.
  18764. parts = parts.concat(path$$1.call(function (left) {
  18765. return printBinaryishExpressions(left, print, options,
  18766. /* isNested */
  18767. true, isInsideParenthesis);
  18768. }, "left"));
  18769. } else {
  18770. parts.push(path$$1.call(print, "left"));
  18771. }
  18772. var shouldInline = shouldInlineLogicalExpression(node);
  18773. var lineBeforeOperator = node.operator === "|>";
  18774. var right = shouldInline ? concat$4([node.operator, " ", path$$1.call(print, "right")]) : concat$4([lineBeforeOperator ? softline$1 : "", node.operator, lineBeforeOperator ? " " : line$3, path$$1.call(print, "right")]); // If there's only a single binary expression, we want to create a group
  18775. // in order to avoid having a small right part like -1 be on its own line.
  18776. var parent = path$$1.getParentNode();
  18777. var shouldGroup = !(isInsideParenthesis && node.type === "LogicalExpression") && parent.type !== node.type && node.left.type !== node.type && node.right.type !== node.type;
  18778. parts.push(" ", shouldGroup ? group$1(right) : right); // The root comments are already printed, but we need to manually print
  18779. // the other ones since we don't call the normal print on BinaryExpression,
  18780. // only for the left and right parts
  18781. if (isNested && node.comments) {
  18782. parts = comments.printComments(path$$1, function () {
  18783. return concat$4(parts);
  18784. }, options);
  18785. }
  18786. } else {
  18787. // Our stopping case. Simply print the node normally.
  18788. parts.push(path$$1.call(print));
  18789. }
  18790. return parts;
  18791. }
  18792. function printAssignmentRight(leftNode, rightNode, printedRight, options) {
  18793. if (hasLeadingOwnLineComment(options.originalText, rightNode, options)) {
  18794. return indent$2(concat$4([hardline$3, printedRight]));
  18795. }
  18796. var canBreak = isBinaryish(rightNode) && !shouldInlineLogicalExpression(rightNode) || rightNode.type === "ConditionalExpression" && isBinaryish(rightNode.test) && !shouldInlineLogicalExpression(rightNode.test) || rightNode.type === "StringLiteralTypeAnnotation" || (leftNode.type === "Identifier" || isStringLiteral(leftNode) || leftNode.type === "MemberExpression") && (isStringLiteral(rightNode) || isMemberExpressionChain(rightNode));
  18797. if (canBreak) {
  18798. return indent$2(concat$4([line$3, printedRight]));
  18799. }
  18800. return concat$4([" ", printedRight]);
  18801. }
  18802. function printAssignment(leftNode, printedLeft, operator, rightNode, printedRight, options) {
  18803. if (!rightNode) {
  18804. return printedLeft;
  18805. }
  18806. var printed = printAssignmentRight(leftNode, rightNode, printedRight, options);
  18807. return group$1(concat$4([printedLeft, operator, printed]));
  18808. }
  18809. function adjustClause(node, clause, forceSpace) {
  18810. if (node.type === "EmptyStatement") {
  18811. return ";";
  18812. }
  18813. if (node.type === "BlockStatement" || forceSpace) {
  18814. return concat$4([" ", clause]);
  18815. }
  18816. return indent$2(concat$4([line$3, clause]));
  18817. }
  18818. function nodeStr(node, options, isFlowOrTypeScriptDirectiveLiteral) {
  18819. var raw = rawText(node);
  18820. var isDirectiveLiteral = isFlowOrTypeScriptDirectiveLiteral || node.type === "DirectiveLiteral";
  18821. return printString$1(raw, options, isDirectiveLiteral);
  18822. }
  18823. function printRegex(node) {
  18824. var flags = node.flags.split("").sort().join("");
  18825. return `/${node.pattern}/${flags}`;
  18826. }
  18827. function isLastStatement(path$$1) {
  18828. var parent = path$$1.getParentNode();
  18829. if (!parent) {
  18830. return true;
  18831. }
  18832. var node = path$$1.getValue();
  18833. var body = (parent.body || parent.consequent).filter(function (stmt) {
  18834. return stmt.type !== "EmptyStatement";
  18835. });
  18836. return body && body[body.length - 1] === node;
  18837. }
  18838. function hasLeadingComment(node) {
  18839. return node.comments && node.comments.some(function (comment) {
  18840. return comment.leading;
  18841. });
  18842. }
  18843. function hasTrailingComment(node) {
  18844. return node.comments && node.comments.some(function (comment) {
  18845. return comment.trailing;
  18846. });
  18847. }
  18848. function hasLeadingOwnLineComment(text, node, options) {
  18849. if (isJSXNode(node)) {
  18850. return hasNodeIgnoreComment$1(node);
  18851. }
  18852. var res = node.comments && node.comments.some(function (comment) {
  18853. return comment.leading && hasNewline$2(text, options.locEnd(comment));
  18854. });
  18855. return res;
  18856. }
  18857. function hasNakedLeftSide(node) {
  18858. return node.type === "AssignmentExpression" || node.type === "BinaryExpression" || node.type === "LogicalExpression" || node.type === "ConditionalExpression" || node.type === "CallExpression" || node.type === "OptionalCallExpression" || node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "SequenceExpression" || node.type === "TaggedTemplateExpression" || node.type === "BindExpression" && !node.object || node.type === "UpdateExpression" && !node.prefix;
  18859. }
  18860. function isFlowAnnotationComment(text, typeAnnotation, options) {
  18861. var start = options.locStart(typeAnnotation);
  18862. var end = skipWhitespace$1(text, options.locEnd(typeAnnotation));
  18863. return text.substr(start, 2) === "/*" && text.substr(end, 2) === "*/";
  18864. }
  18865. function getLeftSide(node) {
  18866. if (node.expressions) {
  18867. return node.expressions[0];
  18868. }
  18869. return node.left || node.test || node.callee || node.object || node.tag || node.argument || node.expression;
  18870. }
  18871. function getLeftSidePathName(path$$1, node) {
  18872. if (node.expressions) {
  18873. return ["expressions", 0];
  18874. }
  18875. if (node.left) {
  18876. return ["left"];
  18877. }
  18878. if (node.test) {
  18879. return ["test"];
  18880. }
  18881. if (node.callee) {
  18882. return ["callee"];
  18883. }
  18884. if (node.object) {
  18885. return ["object"];
  18886. }
  18887. if (node.tag) {
  18888. return ["tag"];
  18889. }
  18890. if (node.argument) {
  18891. return ["argument"];
  18892. }
  18893. if (node.expression) {
  18894. return ["expression"];
  18895. }
  18896. throw new Error("Unexpected node has no left side", node);
  18897. }
  18898. function exprNeedsASIProtection(path$$1, options) {
  18899. var node = path$$1.getValue();
  18900. var maybeASIProblem = needsParens_1(path$$1, options) || node.type === "ParenthesizedExpression" || node.type === "TypeCastExpression" || node.type === "ArrowFunctionExpression" && !shouldPrintParamsWithoutParens(path$$1, options) || node.type === "ArrayExpression" || node.type === "ArrayPattern" || node.type === "UnaryExpression" && node.prefix && (node.operator === "+" || node.operator === "-") || node.type === "TemplateLiteral" || node.type === "TemplateElement" || isJSXNode(node) || node.type === "BindExpression" || node.type === "RegExpLiteral" || node.type === "Literal" && node.pattern || node.type === "Literal" && node.regex;
  18901. if (maybeASIProblem) {
  18902. return true;
  18903. }
  18904. if (!hasNakedLeftSide(node)) {
  18905. return false;
  18906. }
  18907. return path$$1.call.apply(path$$1, [function (childPath) {
  18908. return exprNeedsASIProtection(childPath, options);
  18909. }].concat(getLeftSidePathName(path$$1, node)));
  18910. }
  18911. function stmtNeedsASIProtection(path$$1, options) {
  18912. var node = path$$1.getNode();
  18913. if (node.type !== "ExpressionStatement") {
  18914. return false;
  18915. }
  18916. return path$$1.call(function (childPath) {
  18917. return exprNeedsASIProtection(childPath, options);
  18918. }, "expression");
  18919. }
  18920. function classPropMayCauseASIProblems(path$$1) {
  18921. var node = path$$1.getNode();
  18922. if (node.type !== "ClassProperty") {
  18923. return false;
  18924. }
  18925. var name = node.key && node.key.name; // this isn't actually possible yet with most parsers available today
  18926. // so isn't properly tested yet.
  18927. if ((name === "static" || name === "get" || name === "set") && !node.value && !node.typeAnnotation) {
  18928. return true;
  18929. }
  18930. }
  18931. function classChildNeedsASIProtection(node) {
  18932. if (!node) {
  18933. return;
  18934. }
  18935. if (!node.computed) {
  18936. var name = node.key && node.key.name;
  18937. if (name === "in" || name === "instanceof") {
  18938. return true;
  18939. }
  18940. }
  18941. switch (node.type) {
  18942. case "ClassProperty":
  18943. case "TSAbstractClassProperty":
  18944. return node.computed;
  18945. case "MethodDefinition": // Flow
  18946. case "TSAbstractMethodDefinition": // TypeScript
  18947. case "ClassMethod":
  18948. {
  18949. // Babylon
  18950. var isAsync = node.value ? node.value.async : node.async;
  18951. var isGenerator = node.value ? node.value.generator : node.generator;
  18952. if (isAsync || node.static || node.kind === "get" || node.kind === "set") {
  18953. return false;
  18954. }
  18955. if (node.computed || isGenerator) {
  18956. return true;
  18957. }
  18958. return false;
  18959. }
  18960. default:
  18961. /* istanbul ignore next */
  18962. return false;
  18963. }
  18964. } // This recurses the return argument, looking for the first token
  18965. // (the leftmost leaf node) and, if it (or its parents) has any
  18966. // leadingComments, returns true (so it can be wrapped in parens).
  18967. function returnArgumentHasLeadingComment(options, argument) {
  18968. if (hasLeadingOwnLineComment(options.originalText, argument, options)) {
  18969. return true;
  18970. }
  18971. if (hasNakedLeftSide(argument)) {
  18972. var leftMost = argument;
  18973. var newLeftMost;
  18974. while (newLeftMost = getLeftSide(leftMost)) {
  18975. leftMost = newLeftMost;
  18976. if (hasLeadingOwnLineComment(options.originalText, leftMost, options)) {
  18977. return true;
  18978. }
  18979. }
  18980. }
  18981. return false;
  18982. }
  18983. function isMemberExpressionChain(node) {
  18984. if (node.type !== "MemberExpression" && node.type !== "OptionalMemberExpression") {
  18985. return false;
  18986. }
  18987. if (node.object.type === "Identifier") {
  18988. return true;
  18989. }
  18990. return isMemberExpressionChain(node.object);
  18991. } // Hack to differentiate between the following two which have the same ast
  18992. // type T = { method: () => void };
  18993. // type T = { method(): void };
  18994. function isObjectTypePropertyAFunction(node, options) {
  18995. return node.type === "ObjectTypeProperty" && node.value.type === "FunctionTypeAnnotation" && !node.static && !isFunctionNotation(node, options);
  18996. } // TODO: This is a bad hack and we need a better way to distinguish between
  18997. // arrow functions and otherwise
  18998. function isFunctionNotation(node, options) {
  18999. return isGetterOrSetter(node) || sameLocStart(node, node.value, options);
  19000. }
  19001. function isGetterOrSetter(node) {
  19002. return node.kind === "get" || node.kind === "set";
  19003. }
  19004. function sameLocStart(nodeA, nodeB, options) {
  19005. return options.locStart(nodeA) === options.locStart(nodeB);
  19006. } // Hack to differentiate between the following two which have the same ast
  19007. // declare function f(a): void;
  19008. // var f: (a) => void;
  19009. function isTypeAnnotationAFunction(node, options) {
  19010. return (node.type === "TypeAnnotation" || node.type === "TSTypeAnnotation") && node.typeAnnotation.type === "FunctionTypeAnnotation" && !node.static && !sameLocStart(node, node.typeAnnotation, options);
  19011. }
  19012. function isNodeStartingWithDeclare(node, options) {
  19013. if (!(options.parser === "flow" || options.parser === "typescript")) {
  19014. return false;
  19015. }
  19016. return options.originalText.slice(0, options.locStart(node)).match(/declare[ \t]*$/) || options.originalText.slice(node.range[0], node.range[1]).startsWith("declare ");
  19017. }
  19018. function shouldHugType(node) {
  19019. if (isObjectType(node)) {
  19020. return true;
  19021. }
  19022. if (node.type === "UnionTypeAnnotation" || node.type === "TSUnionType") {
  19023. var voidCount = node.types.filter(function (n) {
  19024. return n.type === "VoidTypeAnnotation" || n.type === "TSVoidKeyword" || n.type === "NullLiteralTypeAnnotation" || n.type === "TSNullKeyword";
  19025. }).length;
  19026. var objectCount = node.types.filter(function (n) {
  19027. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral" || // This is a bit aggressive but captures Array<{x}>
  19028. n.type === "GenericTypeAnnotation" || n.type === "TSTypeReference";
  19029. }).length;
  19030. if (node.types.length - 1 === voidCount && objectCount > 0) {
  19031. return true;
  19032. }
  19033. }
  19034. return false;
  19035. }
  19036. function shouldHugArguments(fun) {
  19037. return fun && fun.params && fun.params.length === 1 && !fun.params[0].comments && (fun.params[0].type === "ObjectPattern" || fun.params[0].type === "ArrayPattern" || fun.params[0].type === "Identifier" && fun.params[0].typeAnnotation && (fun.params[0].typeAnnotation.type === "TypeAnnotation" || fun.params[0].typeAnnotation.type === "TSTypeAnnotation") && isObjectType(fun.params[0].typeAnnotation.typeAnnotation) || fun.params[0].type === "FunctionTypeParam" && isObjectType(fun.params[0].typeAnnotation) || fun.params[0].type === "AssignmentPattern" && (fun.params[0].left.type === "ObjectPattern" || fun.params[0].left.type === "ArrayPattern") && (fun.params[0].right.type === "Identifier" || fun.params[0].right.type === "ObjectExpression" && fun.params[0].right.properties.length === 0 || fun.params[0].right.type === "ArrayExpression" && fun.params[0].right.elements.length === 0)) && !fun.rest;
  19038. }
  19039. function templateLiteralHasNewLines(template) {
  19040. return template.quasis.some(function (quasi) {
  19041. return quasi.value.raw.includes("\n");
  19042. });
  19043. }
  19044. function isTemplateOnItsOwnLine(n, text, options) {
  19045. return (n.type === "TemplateLiteral" && templateLiteralHasNewLines(n) || n.type === "TaggedTemplateExpression" && templateLiteralHasNewLines(n.quasi)) && !hasNewline$2(text, options.locStart(n), {
  19046. backwards: true
  19047. });
  19048. }
  19049. function printArrayItems(path$$1, options, printPath, print) {
  19050. var printedElements = [];
  19051. var separatorParts = [];
  19052. path$$1.each(function (childPath) {
  19053. printedElements.push(concat$4(separatorParts));
  19054. printedElements.push(group$1(print(childPath)));
  19055. separatorParts = [",", line$3];
  19056. if (childPath.getValue() && isNextLineEmpty$2(options.originalText, childPath.getValue(), options)) {
  19057. separatorParts.push(softline$1);
  19058. }
  19059. }, printPath);
  19060. return concat$4(printedElements);
  19061. }
  19062. function hasDanglingComments(node) {
  19063. return node.comments && node.comments.some(function (comment) {
  19064. return !comment.leading && !comment.trailing;
  19065. });
  19066. }
  19067. function needsHardlineAfterDanglingComment(node) {
  19068. if (!node.comments) {
  19069. return false;
  19070. }
  19071. var lastDanglingComment = getLast$4(node.comments.filter(function (comment) {
  19072. return !comment.leading && !comment.trailing;
  19073. }));
  19074. return lastDanglingComment && !comments$3.isBlockComment(lastDanglingComment);
  19075. }
  19076. function isLiteral(node) {
  19077. return node.type === "BooleanLiteral" || node.type === "DirectiveLiteral" || node.type === "Literal" || node.type === "NullLiteral" || node.type === "NumericLiteral" || node.type === "RegExpLiteral" || node.type === "StringLiteral" || node.type === "TemplateLiteral" || node.type === "TSTypeLiteral" || node.type === "JSXText";
  19078. }
  19079. function isNumericLiteral(node) {
  19080. return node.type === "NumericLiteral" || node.type === "Literal" && typeof node.value === "number";
  19081. }
  19082. function isStringLiteral(node) {
  19083. return node.type === "StringLiteral" || node.type === "Literal" && typeof node.value === "string";
  19084. }
  19085. function isObjectType(n) {
  19086. return n.type === "ObjectTypeAnnotation" || n.type === "TSTypeLiteral";
  19087. }
  19088. var unitTestRe = /^(skip|[fx]?(it|describe|test))$/; // eg; `describe("some string", (done) => {})`
  19089. function isTestCall(n, parent) {
  19090. if (n.type !== "CallExpression") {
  19091. return false;
  19092. }
  19093. if (n.arguments.length === 1) {
  19094. if (isAngularTestWrapper(n) && parent && isTestCall(parent)) {
  19095. return isFunctionOrArrowExpression(n.arguments[0].type);
  19096. }
  19097. if (isUnitTestSetUp(n)) {
  19098. return isFunctionOrArrowExpression(n.arguments[0].type) || isAngularTestWrapper(n.arguments[0]);
  19099. }
  19100. } else if (n.arguments.length === 2) {
  19101. if ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name) || isSkipOrOnlyBlock(n)) && (isTemplateLiteral(n.arguments[0]) || isStringLiteral(n.arguments[0]))) {
  19102. return isFunctionOrArrowExpression(n.arguments[1].type) && n.arguments[1].params.length <= 1 || isAngularTestWrapper(n.arguments[1]);
  19103. }
  19104. }
  19105. return false;
  19106. }
  19107. function isSkipOrOnlyBlock(node) {
  19108. return (node.callee.type === "MemberExpression" || node.callee.type === "OptionalMemberExpression") && node.callee.object.type === "Identifier" && node.callee.property.type === "Identifier" && unitTestRe.test(node.callee.object.name) && (node.callee.property.name === "only" || node.callee.property.name === "skip");
  19109. }
  19110. function isTemplateLiteral(node) {
  19111. return node.type === "TemplateLiteral";
  19112. } // `inject` is used in AngularJS 1.x, `async` in Angular 2+
  19113. // example: https://docs.angularjs.org/guide/unit-testing#using-beforeall-
  19114. function isAngularTestWrapper(node) {
  19115. return (node.type === "CallExpression" || node.type === "OptionalCallExpression") && node.callee.type === "Identifier" && (node.callee.name === "async" || node.callee.name === "inject");
  19116. }
  19117. function isFunctionOrArrowExpression(type) {
  19118. return type === "FunctionExpression" || type === "ArrowFunctionExpression";
  19119. }
  19120. function isUnitTestSetUp(n) {
  19121. var unitTestSetUpRe = /^(before|after)(Each|All)$/;
  19122. return n.callee.type === "Identifier" && unitTestSetUpRe.test(n.callee.name) && n.arguments.length === 1;
  19123. }
  19124. function isTheOnlyJSXElementInMarkdown(options, path$$1) {
  19125. if (options.parentParser !== "markdown") {
  19126. return false;
  19127. }
  19128. var node = path$$1.getNode();
  19129. if (!node.expression || !isJSXNode(node.expression)) {
  19130. return false;
  19131. }
  19132. var parent = path$$1.getParentNode();
  19133. return parent.type === "Program" && parent.body.length == 1;
  19134. }
  19135. function willPrintOwnComments(path$$1) {
  19136. var node = path$$1.getValue();
  19137. var parent = path$$1.getParentNode();
  19138. return (node && isJSXNode(node) || parent && (parent.type === "JSXSpreadAttribute" || parent.type === "JSXSpreadChild" || parent.type === "UnionTypeAnnotation" || parent.type === "TSUnionType" || (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.superClass === node)) && !hasIgnoreComment$1(path$$1);
  19139. }
  19140. function canAttachComment(node) {
  19141. return node.type && node.type !== "CommentBlock" && node.type !== "CommentLine" && node.type !== "Line" && node.type !== "Block" && node.type !== "EmptyStatement" && node.type !== "TemplateElement" && node.type !== "Import" && !(node.callee && node.callee.type === "Import");
  19142. }
  19143. function printComment$1(commentPath, options) {
  19144. var comment = commentPath.getValue();
  19145. switch (comment.type) {
  19146. case "CommentBlock":
  19147. case "Block":
  19148. {
  19149. if (isJsDocComment(comment)) {
  19150. var printed = printJsDocComment(comment); // We need to prevent an edge case of a previous trailing comment
  19151. // printed as a `lineSuffix` which causes the comments to be
  19152. // interleaved. See https://github.com/prettier/prettier/issues/4412
  19153. if (comment.trailing && !hasNewline$2(options.originalText, options.locStart(comment), {
  19154. backwards: true
  19155. })) {
  19156. return concat$4([hardline$3, printed]);
  19157. }
  19158. return printed;
  19159. }
  19160. var isInsideFlowComment = options.originalText.substr(options.locEnd(comment) - 3, 3) === "*-/";
  19161. return "/*" + comment.value + (isInsideFlowComment ? "*-/" : "*/");
  19162. }
  19163. case "CommentLine":
  19164. case "Line":
  19165. // Print shebangs with the proper comment characters
  19166. if (options.originalText.slice(options.locStart(comment)).startsWith("#!")) {
  19167. return "#!" + comment.value.trimRight();
  19168. }
  19169. return "//" + comment.value.trimRight();
  19170. default:
  19171. throw new Error("Not a comment: " + JSON.stringify(comment));
  19172. }
  19173. }
  19174. function isJsDocComment(comment) {
  19175. var lines = comment.value.split("\n");
  19176. return lines.length > 1 && lines.slice(0, lines.length - 1).every(function (line) {
  19177. return line.trim()[0] === "*";
  19178. });
  19179. }
  19180. function printJsDocComment(comment) {
  19181. var lines = comment.value.split("\n");
  19182. return concat$4(["/*", join$2(hardline$3, lines.map(function (line, index) {
  19183. return (index > 0 ? " " : "") + (index < lines.length - 1 ? line.trim() : line.trimLeft());
  19184. })), "*/"]);
  19185. }
  19186. function rawText(node) {
  19187. return node.extra ? node.extra.raw : node.raw;
  19188. }
  19189. var printerEstree = {
  19190. print: genericPrint$1,
  19191. embed: embed_1,
  19192. insertPragma,
  19193. massageAstNode: clean_1,
  19194. hasPrettierIgnore,
  19195. willPrintOwnComments,
  19196. canAttachComment,
  19197. printComment: printComment$1,
  19198. isBlockComment: comments$3.isBlockComment,
  19199. handleComments: {
  19200. ownLine: comments$3.handleOwnLineComment,
  19201. endOfLine: comments$3.handleEndOfLineComment,
  19202. remaining: comments$3.handleRemainingComment
  19203. }
  19204. };
  19205. var _require$$0$builders$2 = doc.builders;
  19206. var concat$6 = _require$$0$builders$2.concat;
  19207. var hardline$5 = _require$$0$builders$2.hardline;
  19208. var indent$4 = _require$$0$builders$2.indent;
  19209. var join$4 = _require$$0$builders$2.join;
  19210. function genericPrint$2(path$$1, options, print) {
  19211. var node = path$$1.getValue();
  19212. switch (node.type) {
  19213. case "ArrayExpression":
  19214. return node.elements.length === 0 ? "[]" : concat$6(["[", indent$4(concat$6([hardline$5, join$4(concat$6([",", hardline$5]), path$$1.map(print, "elements"))])), hardline$5, "]"]);
  19215. case "ObjectExpression":
  19216. return node.properties.length === 0 ? "{}" : concat$6(["{", indent$4(concat$6([hardline$5, join$4(concat$6([",", hardline$5]), path$$1.map(print, "properties"))])), hardline$5, "}"]);
  19217. case "ObjectProperty":
  19218. return concat$6([path$$1.call(print, "key"), ": ", path$$1.call(print, "value")]);
  19219. case "UnaryExpression":
  19220. return concat$6([node.operator === "+" ? "" : node.operator, path$$1.call(print, "argument")]);
  19221. case "NullLiteral":
  19222. return "null";
  19223. case "BooleanLiteral":
  19224. return node.value ? "true" : "false";
  19225. case "StringLiteral":
  19226. case "NumericLiteral":
  19227. return JSON.stringify(node.value);
  19228. case "Identifier":
  19229. return JSON.stringify(node.name);
  19230. default:
  19231. /* istanbul ignore next */
  19232. throw new Error("unknown type: " + JSON.stringify(node.type));
  19233. }
  19234. }
  19235. function clean$2(node, newNode
  19236. /*, parent*/
  19237. ) {
  19238. delete newNode.start;
  19239. delete newNode.end;
  19240. delete newNode.extra;
  19241. delete newNode.loc;
  19242. delete newNode.comments;
  19243. if (node.type === "Identifier") {
  19244. return {
  19245. type: "StringLiteral",
  19246. value: node.name
  19247. };
  19248. }
  19249. if (node.type === "UnaryExpression" && node.operator === "+") {
  19250. return newNode.argument;
  19251. }
  19252. }
  19253. var printerEstreeJson = {
  19254. print: genericPrint$2,
  19255. massageAstNode: clean$2
  19256. };
  19257. var CATEGORY_COMMON = "Common"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  19258. var commonOptions = {
  19259. bracketSpacing: {
  19260. since: "0.0.0",
  19261. category: CATEGORY_COMMON,
  19262. type: "boolean",
  19263. default: true,
  19264. description: "Print spaces between brackets.",
  19265. oppositeDescription: "Do not print spaces between brackets."
  19266. },
  19267. singleQuote: {
  19268. since: "0.0.0",
  19269. category: CATEGORY_COMMON,
  19270. type: "boolean",
  19271. default: false,
  19272. description: "Use single quotes instead of double quotes."
  19273. }
  19274. };
  19275. var CATEGORY_JAVASCRIPT = "JavaScript"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  19276. var options$3 = {
  19277. arrowParens: {
  19278. since: "1.9.0",
  19279. category: CATEGORY_JAVASCRIPT,
  19280. type: "choice",
  19281. default: "avoid",
  19282. description: "Include parentheses around a sole arrow function parameter.",
  19283. choices: [{
  19284. value: "avoid",
  19285. description: "Omit parens when possible. Example: `x => x`"
  19286. }, {
  19287. value: "always",
  19288. description: "Always include parens. Example: `(x) => x`"
  19289. }]
  19290. },
  19291. bracketSpacing: commonOptions.bracketSpacing,
  19292. jsxBracketSameLine: {
  19293. since: "0.17.0",
  19294. category: CATEGORY_JAVASCRIPT,
  19295. type: "boolean",
  19296. default: false,
  19297. description: "Put > on the last line instead of at a new line."
  19298. },
  19299. semi: {
  19300. since: "1.0.0",
  19301. category: CATEGORY_JAVASCRIPT,
  19302. type: "boolean",
  19303. default: true,
  19304. description: "Print semicolons.",
  19305. oppositeDescription: "Do not print semicolons, except at the beginning of lines which may need them."
  19306. },
  19307. singleQuote: commonOptions.singleQuote,
  19308. trailingComma: {
  19309. since: "0.0.0",
  19310. category: CATEGORY_JAVASCRIPT,
  19311. type: "choice",
  19312. default: [{
  19313. since: "0.0.0",
  19314. value: false
  19315. }, {
  19316. since: "0.19.0",
  19317. value: "none"
  19318. }],
  19319. description: "Print trailing commas wherever possible when multi-line.",
  19320. choices: [{
  19321. value: "none",
  19322. description: "No trailing commas."
  19323. }, {
  19324. value: "es5",
  19325. description: "Trailing commas where valid in ES5 (objects, arrays, etc.)"
  19326. }, {
  19327. value: "all",
  19328. description: "Trailing commas wherever possible (including function arguments)."
  19329. }, {
  19330. value: true,
  19331. deprecated: "0.19.0",
  19332. redirect: "es5"
  19333. }, {
  19334. value: false,
  19335. deprecated: "0.19.0",
  19336. redirect: "none"
  19337. }]
  19338. }
  19339. };
  19340. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  19341. var languages = [{
  19342. name: "JavaScript",
  19343. since: "0.0.0",
  19344. parsers: ["babylon", "flow"],
  19345. group: "JavaScript",
  19346. tmScope: "source.js",
  19347. aceMode: "javascript",
  19348. codemirrorMode: "javascript",
  19349. codemirrorMimeType: "text/javascript",
  19350. aliases: ["js", "node"],
  19351. extensions: [".js", "._js", ".bones", ".es", ".es6", ".frag", ".gs", ".jake", ".jsb", ".jscad", ".jsfl", ".jsm", ".jss", ".mjs", ".njs", ".pac", ".sjs", ".ssjs", ".xsjs", ".xsjslib"],
  19352. filenames: ["Jakefile"],
  19353. linguistLanguageId: 183,
  19354. vscodeLanguageIds: ["javascript"]
  19355. }, {
  19356. name: "JSX",
  19357. since: "0.0.0",
  19358. parsers: ["babylon", "flow"],
  19359. group: "JavaScript",
  19360. extensions: [".jsx"],
  19361. tmScope: "source.js.jsx",
  19362. aceMode: "javascript",
  19363. codemirrorMode: "jsx",
  19364. codemirrorMimeType: "text/jsx",
  19365. liguistLanguageId: 178,
  19366. vscodeLanguageIds: ["javascriptreact"]
  19367. }, {
  19368. name: "TypeScript",
  19369. since: "1.4.0",
  19370. parsers: ["typescript-eslint"],
  19371. group: "JavaScript",
  19372. aliases: ["ts"],
  19373. extensions: [".ts", ".tsx"],
  19374. tmScope: "source.ts",
  19375. aceMode: "typescript",
  19376. codemirrorMode: "javascript",
  19377. codemirrorMimeType: "application/typescript",
  19378. liguistLanguageId: 378,
  19379. vscodeLanguageIds: ["typescript", "typescriptreact"]
  19380. }, {
  19381. name: "JSON.stringify",
  19382. since: "1.13.0",
  19383. parsers: ["json-stringify"],
  19384. group: "JavaScript",
  19385. tmScope: "source.json",
  19386. aceMode: "json",
  19387. codemirrorMode: "javascript",
  19388. codemirrorMimeType: "application/json",
  19389. extensions: [],
  19390. // .json file defaults to json instead of json-stringify
  19391. filenames: ["package.json", "package-lock.json", "composer.json"],
  19392. linguistLanguageId: 174,
  19393. vscodeLanguageIds: ["json"]
  19394. }, {
  19395. name: "JSON",
  19396. since: "1.5.0",
  19397. parsers: ["json"],
  19398. group: "JavaScript",
  19399. tmScope: "source.json",
  19400. aceMode: "json",
  19401. codemirrorMode: "javascript",
  19402. codemirrorMimeType: "application/json",
  19403. extensions: [".json", ".geojson", ".JSON-tmLanguage", ".topojson"],
  19404. filenames: [".arcconfig", ".jshintrc", ".eslintrc", ".prettierrc", "composer.lock", "mcmod.info"],
  19405. linguistLanguageId: 174,
  19406. vscodeLanguageIds: ["json", "jsonc"]
  19407. }, {
  19408. name: "JSON5",
  19409. since: "1.13.0",
  19410. parsers: ["json5"],
  19411. group: "JavaScript",
  19412. tmScope: "source.json",
  19413. aceMode: "json",
  19414. codemirrorMode: "javascript",
  19415. codemirrorMimeType: "application/json",
  19416. extensions: [".json5"],
  19417. filenames: [".babelrc"],
  19418. linguistLanguageId: 175,
  19419. vscodeLanguageIds: ["json5"]
  19420. }];
  19421. var printers = {
  19422. estree: printerEstree,
  19423. "estree-json": printerEstreeJson
  19424. };
  19425. var languageJs = {
  19426. languages,
  19427. options: options$3,
  19428. printers
  19429. };
  19430. var index$5 = ["a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "command", "content", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "element", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "iframe", "image", "img", "input", "ins", "isindex", "kbd", "keygen", "label", "legend", "li", "link", "listing", "main", "map", "mark", "marquee", "math", "menu", "menuitem", "meta", "meter", "multicol", "nav", "nextid", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "plaintext", "pre", "progress", "q", "rb", "rbc", "rp", "rt", "rtc", "ruby", "s", "samp", "script", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "svg", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp"];
  19431. var htmlTagNames = Object.freeze({
  19432. default: index$5
  19433. });
  19434. var htmlTagNames$1 = ( htmlTagNames && index$5 ) || htmlTagNames;
  19435. function clean$3(ast, newObj) {
  19436. ["raws", "sourceIndex", "source", "before", "after", "trailingComma"].forEach(function (name) {
  19437. delete newObj[name];
  19438. });
  19439. if (ast.type === "media-query" || ast.type === "media-query-list" || ast.type === "media-feature-expression") {
  19440. delete newObj.value;
  19441. }
  19442. if (ast.type === "css-rule") {
  19443. delete newObj.params;
  19444. }
  19445. if (ast.type === "selector-combinator") {
  19446. newObj.value = newObj.value.replace(/\s+/g, " ");
  19447. }
  19448. if (ast.type === "media-feature") {
  19449. newObj.value = newObj.value.replace(/ /g, "");
  19450. }
  19451. if (ast.type === "value-word" && (ast.isColor && ast.isHex || ["initial", "inherit", "unset", "revert"].indexOf(newObj.value.replace().toLowerCase()) !== -1) || ast.type === "media-feature" || ast.type === "selector-root-invalid" || ast.type === "selector-pseudo") {
  19452. newObj.value = newObj.value.toLowerCase();
  19453. }
  19454. if (ast.type === "css-decl") {
  19455. newObj.prop = newObj.prop.toLowerCase();
  19456. }
  19457. if (ast.type === "css-atrule" || ast.type === "css-import") {
  19458. newObj.name = newObj.name.toLowerCase();
  19459. }
  19460. if (ast.type === "value-number") {
  19461. newObj.unit = newObj.unit.toLowerCase();
  19462. }
  19463. if ((ast.type === "media-feature" || ast.type === "media-keyword" || ast.type === "media-type" || ast.type === "media-unknown" || ast.type === "media-url" || ast.type === "media-value" || ast.type === "selector-attribute" || ast.type === "selector-string" || ast.type === "selector-class" || ast.type === "selector-combinator" || ast.type === "value-string") && newObj.value) {
  19464. newObj.value = cleanCSSStrings(newObj.value);
  19465. }
  19466. if (ast.type === "selector-attribute") {
  19467. newObj.attribute = newObj.attribute.trim();
  19468. if (newObj.namespace) {
  19469. if (typeof newObj.namespace === "string") {
  19470. newObj.namespace = newObj.namespace.trim();
  19471. if (newObj.namespace.length === 0) {
  19472. newObj.namespace = true;
  19473. }
  19474. }
  19475. }
  19476. if (newObj.value) {
  19477. newObj.value = newObj.value.trim().replace(/^['"]|['"]$/g, "");
  19478. delete newObj.quoted;
  19479. }
  19480. }
  19481. if ((ast.type === "media-value" || ast.type === "media-type" || ast.type === "value-number" || ast.type === "selector-root-invalid" || ast.type === "selector-class" || ast.type === "selector-combinator" || ast.type === "selector-tag") && newObj.value) {
  19482. newObj.value = newObj.value.replace(/([\d.eE+-]+)([a-zA-Z]*)/g, function (match, numStr, unit) {
  19483. var num = Number(numStr);
  19484. return isNaN(num) ? match : num + unit.toLowerCase();
  19485. });
  19486. }
  19487. if (ast.type === "selector-tag") {
  19488. var lowercasedValue = ast.value.toLowerCase();
  19489. if (htmlTagNames$1.indexOf(lowercasedValue) !== -1) {
  19490. newObj.value = lowercasedValue;
  19491. }
  19492. if (["from", "to"].indexOf(lowercasedValue) !== -1) {
  19493. newObj.value = lowercasedValue;
  19494. }
  19495. } // Workaround when `postcss-values-parser` parse `not`, `and` or `or` keywords as `value-func`
  19496. if (ast.type === "css-atrule" && ast.name.toLowerCase() === "supports") {
  19497. delete newObj.value;
  19498. } // Workaround for SCSS nested properties
  19499. if (ast.type === "selector-unknown") {
  19500. delete newObj.value;
  19501. }
  19502. }
  19503. function cleanCSSStrings(value) {
  19504. return value.replace(/'/g, '"').replace(/\\([^a-fA-F\d])/g, "$1");
  19505. }
  19506. var clean_1$2 = clean$3;
  19507. var colorAdjusterFunctions = ["red", "green", "blue", "alpha", "a", "rgb", "hue", "h", "saturation", "s", "lightness", "l", "whiteness", "w", "blackness", "b", "tint", "shade", "blend", "blenda", "contrast", "hsl", "hsla", "hwb", "hwba"];
  19508. function getAncestorCounter(path$$1, typeOrTypes) {
  19509. var types = [].concat(typeOrTypes);
  19510. var counter = -1;
  19511. var ancestorNode;
  19512. while (ancestorNode = path$$1.getParentNode(++counter)) {
  19513. if (types.indexOf(ancestorNode.type) !== -1) {
  19514. return counter;
  19515. }
  19516. }
  19517. return -1;
  19518. }
  19519. function getAncestorNode$1(path$$1, typeOrTypes) {
  19520. var counter = getAncestorCounter(path$$1, typeOrTypes);
  19521. return counter === -1 ? null : path$$1.getParentNode(counter);
  19522. }
  19523. function getPropOfDeclNode$1(path$$1) {
  19524. var declAncestorNode = getAncestorNode$1(path$$1, "css-decl");
  19525. return declAncestorNode && declAncestorNode.prop && declAncestorNode.prop.toLowerCase();
  19526. }
  19527. function isSCSS$1(parser, text) {
  19528. var hasExplicitParserChoice = parser === "less" || parser === "scss";
  19529. var IS_POSSIBLY_SCSS = /(\w\s*: [^}:]+|#){|@import[^\n]+(url|,)/;
  19530. return hasExplicitParserChoice ? parser === "scss" : IS_POSSIBLY_SCSS.test(text);
  19531. }
  19532. function isWideKeywords$1(value) {
  19533. return ["initial", "inherit", "unset", "revert"].indexOf(value.toLowerCase()) !== -1;
  19534. }
  19535. function isKeyframeAtRuleKeywords$1(path$$1, value) {
  19536. var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
  19537. return atRuleAncestorNode && atRuleAncestorNode.name && atRuleAncestorNode.name.toLowerCase().endsWith("keyframes") && ["from", "to"].indexOf(value.toLowerCase()) !== -1;
  19538. }
  19539. function maybeToLowerCase$1(value) {
  19540. return value.includes("$") || value.includes("@") || value.includes("#") || value.startsWith("%") || value.startsWith("--") || value.startsWith(":--") || value.includes("(") && value.includes(")") ? value : value.toLowerCase();
  19541. }
  19542. function insideValueFunctionNode$1(path$$1, functionName) {
  19543. var funcAncestorNode = getAncestorNode$1(path$$1, "value-func");
  19544. return funcAncestorNode && funcAncestorNode.value && funcAncestorNode.value.toLowerCase() === functionName;
  19545. }
  19546. function insideICSSRuleNode$1(path$$1) {
  19547. var ruleAncestorNode = getAncestorNode$1(path$$1, "css-rule");
  19548. return ruleAncestorNode && ruleAncestorNode.raws && ruleAncestorNode.raws.selector && (ruleAncestorNode.raws.selector.startsWith(":import") || ruleAncestorNode.raws.selector.startsWith(":export"));
  19549. }
  19550. function insideAtRuleNode$1(path$$1, atRuleNameOrAtRuleNames) {
  19551. var atRuleNames = [].concat(atRuleNameOrAtRuleNames);
  19552. var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
  19553. return atRuleAncestorNode && atRuleNames.indexOf(atRuleAncestorNode.name.toLowerCase()) !== -1;
  19554. }
  19555. function insideURLFunctionInImportAtRuleNode$1(path$$1) {
  19556. var node = path$$1.getValue();
  19557. var atRuleAncestorNode = getAncestorNode$1(path$$1, "css-atrule");
  19558. return atRuleAncestorNode && atRuleAncestorNode.name === "import" && node.groups[0].value === "url" && node.groups.length === 2;
  19559. }
  19560. function isURLFunctionNode$1(node) {
  19561. return node.type === "value-func" && node.value.toLowerCase() === "url";
  19562. }
  19563. function isLastNode$1(path$$1, node) {
  19564. var parentNode = path$$1.getParentNode();
  19565. if (!parentNode) {
  19566. return false;
  19567. }
  19568. var nodes = parentNode.nodes;
  19569. return nodes && nodes.indexOf(node) === nodes.length - 1;
  19570. }
  19571. function isHTMLTag$1(value) {
  19572. return htmlTagNames$1.indexOf(value.toLowerCase()) !== -1;
  19573. }
  19574. function isDetachedRulesetDeclarationNode$1(node) {
  19575. // If a Less file ends up being parsed with the SCSS parser, Less
  19576. // variable declarations will be parsed as atrules with names ending
  19577. // with a colon, so keep the original case then.
  19578. if (!node.selector) {
  19579. return false;
  19580. }
  19581. return typeof node.selector === "string" && /^@.+:.*$/.test(node.selector) || node.selector.value && /^@.+:.*$/.test(node.selector.value);
  19582. }
  19583. function isForKeywordNode$1(node) {
  19584. return node.type === "value-word" && ["from", "through", "end"].indexOf(node.value) !== -1;
  19585. }
  19586. function isIfElseKeywordNode$1(node) {
  19587. return node.type === "value-word" && ["and", "or", "not"].indexOf(node.value) !== -1;
  19588. }
  19589. function isEachKeywordNode$1(node) {
  19590. return node.type === "value-word" && node.value === "in";
  19591. }
  19592. function isMultiplicationNode$1(node) {
  19593. return node.type === "value-operator" && node.value === "*";
  19594. }
  19595. function isDivisionNode$1(node) {
  19596. return node.type === "value-operator" && node.value === "/";
  19597. }
  19598. function isAdditionNode$1(node) {
  19599. return node.type === "value-operator" && node.value === "+";
  19600. }
  19601. function isSubtractionNode$1(node) {
  19602. return node.type === "value-operator" && node.value === "-";
  19603. }
  19604. function isModuloNode(node) {
  19605. return node.type === "value-operator" && node.value === "%";
  19606. }
  19607. function isMathOperatorNode$1(node) {
  19608. return isMultiplicationNode$1(node) || isDivisionNode$1(node) || isAdditionNode$1(node) || isSubtractionNode$1(node) || isModuloNode(node);
  19609. }
  19610. function isEqualityOperatorNode$1(node) {
  19611. return node.type === "value-word" && ["==", "!="].indexOf(node.value) !== -1;
  19612. }
  19613. function isRelationalOperatorNode$1(node) {
  19614. return node.type === "value-word" && ["<", ">", "<=", ">="].indexOf(node.value) !== -1;
  19615. }
  19616. function isSCSSControlDirectiveNode$1(node) {
  19617. return node.type === "css-atrule" && ["if", "else", "for", "each", "while"].indexOf(node.name) !== -1;
  19618. }
  19619. function isSCSSNestedPropertyNode(node) {
  19620. if (!node.selector) {
  19621. return false;
  19622. }
  19623. return node.selector.replace(/\/\*.*?\*\//, "").replace(/\/\/.*?\n/, "").trim().endsWith(":");
  19624. }
  19625. function isDetachedRulesetCallNode$1(node) {
  19626. return node.raws && node.raws.params && /^\(\s*\)$/.test(node.raws.params);
  19627. }
  19628. function isPostcssSimpleVarNode$1(currentNode, nextNode) {
  19629. return currentNode.value === "$$" && currentNode.type === "value-func" && nextNode && nextNode.type === "value-word" && !nextNode.raws.before;
  19630. }
  19631. function hasComposesNode$1(node) {
  19632. return node.value && node.value.type === "value-root" && node.value.group && node.value.group.type === "value-value" && node.prop.toLowerCase() === "composes";
  19633. }
  19634. function hasParensAroundNode$1(node) {
  19635. return node.value && node.value.group && node.value.group.group && node.value.group.group.type === "value-paren_group" && node.value.group.group.open !== null && node.value.group.group.close !== null;
  19636. }
  19637. function hasEmptyRawBefore$1(node) {
  19638. return node.raws && node.raws.before === "";
  19639. }
  19640. function isKeyValuePairNode$1(node) {
  19641. return node.type === "value-comma_group" && node.groups && node.groups[1] && node.groups[1].type === "value-colon";
  19642. }
  19643. function isKeyValuePairInParenGroupNode(node) {
  19644. return node.type === "value-paren_group" && node.groups && node.groups[0] && isKeyValuePairNode$1(node.groups[0]);
  19645. }
  19646. function isSCSSMapItemNode$1(path$$1) {
  19647. var node = path$$1.getValue(); // Ignore empty item (i.e. `$key: ()`)
  19648. if (node.groups.length === 0) {
  19649. return false;
  19650. }
  19651. var parentParentNode = path$$1.getParentNode(1); // Check open parens contain key/value pair (i.e. `(key: value)` and `(key: (value, other-value)`)
  19652. if (!isKeyValuePairInParenGroupNode(node) && !(parentParentNode && isKeyValuePairInParenGroupNode(parentParentNode))) {
  19653. return false;
  19654. }
  19655. var declNode = getAncestorNode$1(path$$1, "css-decl"); // SCSS map declaration (i.e. `$map: (key: value, other-key: other-value)`)
  19656. if (declNode && declNode.prop && declNode.prop.startsWith("$")) {
  19657. return true;
  19658. } // List as value of key inside SCSS map (i.e. `$map: (key: (value other-value other-other-value))`)
  19659. if (isKeyValuePairInParenGroupNode(parentParentNode)) {
  19660. return true;
  19661. } // SCSS Map is argument of function (i.e. `func((key: value, other-key: other-value))`)
  19662. if (parentParentNode.type === "value-func") {
  19663. return true;
  19664. }
  19665. return false;
  19666. }
  19667. function isInlineValueCommentNode$1(node) {
  19668. return node.type === "value-comment" && node.inline;
  19669. }
  19670. function isHashNode$1(node) {
  19671. return node.type === "value-word" && node.value === "#";
  19672. }
  19673. function isLeftCurlyBraceNode$1(node) {
  19674. return node.type === "value-word" && node.value === "{";
  19675. }
  19676. function isRightCurlyBraceNode$1(node) {
  19677. return node.type === "value-word" && node.value === "}";
  19678. }
  19679. function isWordNode$1(node) {
  19680. return ["value-word", "value-atword"].indexOf(node.type) !== -1;
  19681. }
  19682. function isColonNode$1(node) {
  19683. return node.type === "value-colon";
  19684. }
  19685. function isMediaAndSupportsKeywords$1(node) {
  19686. return node.value && ["not", "and", "or"].indexOf(node.value.toLowerCase()) !== -1;
  19687. }
  19688. function isColorAdjusterFuncNode$1(node) {
  19689. if (node.type !== "value-func") {
  19690. return false;
  19691. }
  19692. return colorAdjusterFunctions.indexOf(node.value.toLowerCase()) !== -1;
  19693. }
  19694. var utils$4 = {
  19695. getAncestorCounter,
  19696. getAncestorNode: getAncestorNode$1,
  19697. getPropOfDeclNode: getPropOfDeclNode$1,
  19698. maybeToLowerCase: maybeToLowerCase$1,
  19699. insideValueFunctionNode: insideValueFunctionNode$1,
  19700. insideICSSRuleNode: insideICSSRuleNode$1,
  19701. insideAtRuleNode: insideAtRuleNode$1,
  19702. insideURLFunctionInImportAtRuleNode: insideURLFunctionInImportAtRuleNode$1,
  19703. isKeyframeAtRuleKeywords: isKeyframeAtRuleKeywords$1,
  19704. isHTMLTag: isHTMLTag$1,
  19705. isWideKeywords: isWideKeywords$1,
  19706. isSCSS: isSCSS$1,
  19707. isLastNode: isLastNode$1,
  19708. isSCSSControlDirectiveNode: isSCSSControlDirectiveNode$1,
  19709. isDetachedRulesetDeclarationNode: isDetachedRulesetDeclarationNode$1,
  19710. isRelationalOperatorNode: isRelationalOperatorNode$1,
  19711. isEqualityOperatorNode: isEqualityOperatorNode$1,
  19712. isMultiplicationNode: isMultiplicationNode$1,
  19713. isDivisionNode: isDivisionNode$1,
  19714. isAdditionNode: isAdditionNode$1,
  19715. isSubtractionNode: isSubtractionNode$1,
  19716. isModuloNode,
  19717. isMathOperatorNode: isMathOperatorNode$1,
  19718. isEachKeywordNode: isEachKeywordNode$1,
  19719. isForKeywordNode: isForKeywordNode$1,
  19720. isURLFunctionNode: isURLFunctionNode$1,
  19721. isIfElseKeywordNode: isIfElseKeywordNode$1,
  19722. hasComposesNode: hasComposesNode$1,
  19723. hasParensAroundNode: hasParensAroundNode$1,
  19724. hasEmptyRawBefore: hasEmptyRawBefore$1,
  19725. isSCSSNestedPropertyNode,
  19726. isDetachedRulesetCallNode: isDetachedRulesetCallNode$1,
  19727. isPostcssSimpleVarNode: isPostcssSimpleVarNode$1,
  19728. isKeyValuePairNode: isKeyValuePairNode$1,
  19729. isKeyValuePairInParenGroupNode,
  19730. isSCSSMapItemNode: isSCSSMapItemNode$1,
  19731. isInlineValueCommentNode: isInlineValueCommentNode$1,
  19732. isHashNode: isHashNode$1,
  19733. isLeftCurlyBraceNode: isLeftCurlyBraceNode$1,
  19734. isRightCurlyBraceNode: isRightCurlyBraceNode$1,
  19735. isWordNode: isWordNode$1,
  19736. isColonNode: isColonNode$1,
  19737. isMediaAndSupportsKeywords: isMediaAndSupportsKeywords$1,
  19738. isColorAdjusterFuncNode: isColorAdjusterFuncNode$1
  19739. };
  19740. var printNumber$2 = util$1.printNumber;
  19741. var printString$2 = util$1.printString;
  19742. var hasIgnoreComment$2 = util$1.hasIgnoreComment;
  19743. var hasNewline$3 = util$1.hasNewline;
  19744. var isNextLineEmpty$3 = utilShared.isNextLineEmpty;
  19745. var _require$$2$builders = doc.builders;
  19746. var concat$7 = _require$$2$builders.concat;
  19747. var join$5 = _require$$2$builders.join;
  19748. var line$4 = _require$$2$builders.line;
  19749. var hardline$6 = _require$$2$builders.hardline;
  19750. var softline$3 = _require$$2$builders.softline;
  19751. var group$2 = _require$$2$builders.group;
  19752. var fill$3 = _require$$2$builders.fill;
  19753. var indent$5 = _require$$2$builders.indent;
  19754. var dedent$3 = _require$$2$builders.dedent;
  19755. var ifBreak$2 = _require$$2$builders.ifBreak;
  19756. var removeLines$2 = doc.utils.removeLines;
  19757. var getAncestorNode = utils$4.getAncestorNode;
  19758. var getPropOfDeclNode = utils$4.getPropOfDeclNode;
  19759. var maybeToLowerCase = utils$4.maybeToLowerCase;
  19760. var insideValueFunctionNode = utils$4.insideValueFunctionNode;
  19761. var insideICSSRuleNode = utils$4.insideICSSRuleNode;
  19762. var insideAtRuleNode = utils$4.insideAtRuleNode;
  19763. var insideURLFunctionInImportAtRuleNode = utils$4.insideURLFunctionInImportAtRuleNode;
  19764. var isKeyframeAtRuleKeywords = utils$4.isKeyframeAtRuleKeywords;
  19765. var isHTMLTag = utils$4.isHTMLTag;
  19766. var isWideKeywords = utils$4.isWideKeywords;
  19767. var isSCSS = utils$4.isSCSS;
  19768. var isLastNode = utils$4.isLastNode;
  19769. var isSCSSControlDirectiveNode = utils$4.isSCSSControlDirectiveNode;
  19770. var isDetachedRulesetDeclarationNode = utils$4.isDetachedRulesetDeclarationNode;
  19771. var isRelationalOperatorNode = utils$4.isRelationalOperatorNode;
  19772. var isEqualityOperatorNode = utils$4.isEqualityOperatorNode;
  19773. var isMultiplicationNode = utils$4.isMultiplicationNode;
  19774. var isDivisionNode = utils$4.isDivisionNode;
  19775. var isAdditionNode = utils$4.isAdditionNode;
  19776. var isSubtractionNode = utils$4.isSubtractionNode;
  19777. var isMathOperatorNode = utils$4.isMathOperatorNode;
  19778. var isEachKeywordNode = utils$4.isEachKeywordNode;
  19779. var isForKeywordNode = utils$4.isForKeywordNode;
  19780. var isURLFunctionNode = utils$4.isURLFunctionNode;
  19781. var isIfElseKeywordNode = utils$4.isIfElseKeywordNode;
  19782. var hasComposesNode = utils$4.hasComposesNode;
  19783. var hasParensAroundNode = utils$4.hasParensAroundNode;
  19784. var hasEmptyRawBefore = utils$4.hasEmptyRawBefore;
  19785. var isKeyValuePairNode = utils$4.isKeyValuePairNode;
  19786. var isDetachedRulesetCallNode = utils$4.isDetachedRulesetCallNode;
  19787. var isPostcssSimpleVarNode = utils$4.isPostcssSimpleVarNode;
  19788. var isSCSSMapItemNode = utils$4.isSCSSMapItemNode;
  19789. var isInlineValueCommentNode = utils$4.isInlineValueCommentNode;
  19790. var isHashNode = utils$4.isHashNode;
  19791. var isLeftCurlyBraceNode = utils$4.isLeftCurlyBraceNode;
  19792. var isRightCurlyBraceNode = utils$4.isRightCurlyBraceNode;
  19793. var isWordNode = utils$4.isWordNode;
  19794. var isColonNode = utils$4.isColonNode;
  19795. var isMediaAndSupportsKeywords = utils$4.isMediaAndSupportsKeywords;
  19796. var isColorAdjusterFuncNode = utils$4.isColorAdjusterFuncNode;
  19797. function shouldPrintComma$1(options) {
  19798. switch (options.trailingComma) {
  19799. case "all":
  19800. case "es5":
  19801. return true;
  19802. case "none":
  19803. default:
  19804. return false;
  19805. }
  19806. }
  19807. function genericPrint$3(path$$1, options, print) {
  19808. var node = path$$1.getValue();
  19809. /* istanbul ignore if */
  19810. if (!node) {
  19811. return "";
  19812. }
  19813. if (typeof node === "string") {
  19814. return node;
  19815. }
  19816. switch (node.type) {
  19817. case "front-matter":
  19818. return concat$7([node.value, hardline$6]);
  19819. case "css-root":
  19820. {
  19821. var nodes = printNodeSequence(path$$1, options, print);
  19822. if (nodes.parts.length) {
  19823. return concat$7([nodes, hardline$6]);
  19824. }
  19825. return nodes;
  19826. }
  19827. case "css-comment":
  19828. {
  19829. if (node.raws.content) {
  19830. return node.raws.content;
  19831. }
  19832. var text = options.originalText.slice(options.locStart(node), options.locEnd(node));
  19833. var rawText = node.raws.text || node.text; // Workaround a bug where the location is off.
  19834. // https://github.com/postcss/postcss-scss/issues/63
  19835. if (text.indexOf(rawText) === -1) {
  19836. if (node.raws.inline) {
  19837. return concat$7(["// ", rawText]);
  19838. }
  19839. return concat$7(["/* ", rawText, " */"]);
  19840. }
  19841. return text;
  19842. }
  19843. case "css-rule":
  19844. {
  19845. return concat$7([path$$1.call(print, "selector"), node.important ? " !important" : "", node.nodes ? concat$7([" {", node.nodes.length > 0 ? indent$5(concat$7([hardline$6, printNodeSequence(path$$1, options, print)])) : "", hardline$6, "}", isDetachedRulesetDeclarationNode(node) ? ";" : ""]) : ";"]);
  19846. }
  19847. case "css-decl":
  19848. {
  19849. return concat$7([node.raws.before.replace(/[\s;]/g, ""), insideICSSRuleNode(path$$1) ? node.prop : maybeToLowerCase(node.prop), node.raws.between.trim() === ":" ? ":" : node.raws.between.trim(), node.extend ? "" : " ", hasComposesNode(node) ? removeLines$2(path$$1.call(print, "value")) : path$$1.call(print, "value"), node.raws.important ? node.raws.important.replace(/\s*!\s*important/i, " !important") : node.important ? " !important" : "", node.raws.scssDefault ? node.raws.scssDefault.replace(/\s*!default/i, " !default") : node.scssDefault ? " !default" : "", node.raws.scssGlobal ? node.raws.scssGlobal.replace(/\s*!global/i, " !global") : node.scssGlobal ? " !global" : "", node.nodes ? concat$7([" {", indent$5(concat$7([softline$3, printNodeSequence(path$$1, options, print)])), softline$3, "}"]) : ";"]);
  19850. }
  19851. case "css-atrule":
  19852. {
  19853. return concat$7(["@", // If a Less file ends up being parsed with the SCSS parser, Less
  19854. // variable declarations will be parsed as at-rules with names ending
  19855. // with a colon, so keep the original case then.
  19856. isDetachedRulesetCallNode(node) || node.name.endsWith(":") ? node.name : maybeToLowerCase(node.name), node.params ? concat$7([isDetachedRulesetCallNode(node) ? "" : " ", path$$1.call(print, "params")]) : "", node.selector ? indent$5(concat$7([" ", path$$1.call(print, "selector")])) : "", node.value ? group$2(concat$7([" ", path$$1.call(print, "value"), isSCSSControlDirectiveNode(node) ? hasParensAroundNode(node) ? " " : line$4 : ""])) : node.name === "else" ? " " : "", node.nodes ? concat$7([isSCSSControlDirectiveNode(node) ? "" : " ", "{", indent$5(concat$7([node.nodes.length > 0 ? softline$3 : "", printNodeSequence(path$$1, options, print)])), softline$3, "}"]) : ";"]);
  19857. }
  19858. // postcss-media-query-parser
  19859. case "media-query-list":
  19860. {
  19861. var parts = [];
  19862. path$$1.each(function (childPath) {
  19863. var node = childPath.getValue();
  19864. if (node.type === "media-query" && node.value === "") {
  19865. return;
  19866. }
  19867. parts.push(childPath.call(print));
  19868. }, "nodes");
  19869. return group$2(indent$5(join$5(line$4, parts)));
  19870. }
  19871. case "media-query":
  19872. {
  19873. return concat$7([join$5(" ", path$$1.map(print, "nodes")), isLastNode(path$$1, node) ? "" : ","]);
  19874. }
  19875. case "media-type":
  19876. {
  19877. return adjustNumbers(adjustStrings(node.value, options));
  19878. }
  19879. case "media-feature-expression":
  19880. {
  19881. if (!node.nodes) {
  19882. return node.value;
  19883. }
  19884. return concat$7(["(", concat$7(path$$1.map(print, "nodes")), ")"]);
  19885. }
  19886. case "media-feature":
  19887. {
  19888. return maybeToLowerCase(adjustStrings(node.value.replace(/ +/g, " "), options));
  19889. }
  19890. case "media-colon":
  19891. {
  19892. return concat$7([node.value, " "]);
  19893. }
  19894. case "media-value":
  19895. {
  19896. return adjustNumbers(adjustStrings(node.value, options));
  19897. }
  19898. case "media-keyword":
  19899. {
  19900. return adjustStrings(node.value, options);
  19901. }
  19902. case "media-url":
  19903. {
  19904. return adjustStrings(node.value.replace(/^url\(\s+/gi, "url(").replace(/\s+\)$/gi, ")"), options);
  19905. }
  19906. case "media-unknown":
  19907. {
  19908. return node.value;
  19909. }
  19910. // postcss-selector-parser
  19911. case "selector-root":
  19912. {
  19913. return group$2(concat$7([insideAtRuleNode(path$$1, "custom-selector") ? concat$7([getAncestorNode(path$$1, "css-atrule").customSelector, line$4]) : "", join$5(concat$7([",", insideAtRuleNode(path$$1, ["extend", "custom-selector", "nest"]) ? line$4 : hardline$6]), path$$1.map(print, "nodes"))]));
  19914. }
  19915. case "selector-selector":
  19916. {
  19917. return group$2(indent$5(concat$7(path$$1.map(print, "nodes"))));
  19918. }
  19919. case "selector-comment":
  19920. {
  19921. return node.value;
  19922. }
  19923. case "selector-string":
  19924. {
  19925. return adjustStrings(node.value, options);
  19926. }
  19927. case "selector-tag":
  19928. {
  19929. var parentNode = path$$1.getParentNode();
  19930. var index = parentNode && parentNode.nodes.indexOf(node);
  19931. var prevNode = index && parentNode.nodes[index - 1];
  19932. return concat$7([node.namespace ? concat$7([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", prevNode.type === "selector-nesting" ? node.value : adjustNumbers(isHTMLTag(node.value) || isKeyframeAtRuleKeywords(path$$1, node.value) ? node.value.toLowerCase() : node.value)]);
  19933. }
  19934. case "selector-id":
  19935. {
  19936. return concat$7(["#", node.value]);
  19937. }
  19938. case "selector-class":
  19939. {
  19940. return concat$7([".", adjustNumbers(adjustStrings(node.value, options))]);
  19941. }
  19942. case "selector-attribute":
  19943. {
  19944. return concat$7(["[", node.namespace ? concat$7([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", node.attribute.trim(), node.operator ? node.operator : "", node.value ? quoteAttributeValue(adjustStrings(node.value.trim(), options), options) : "", node.insensitive ? " i" : "", "]"]);
  19945. }
  19946. case "selector-combinator":
  19947. {
  19948. if (node.value === "+" || node.value === ">" || node.value === "~" || node.value === ">>>") {
  19949. var _parentNode = path$$1.getParentNode();
  19950. var _leading = _parentNode.type === "selector-selector" && _parentNode.nodes[0] === node ? "" : line$4;
  19951. return concat$7([_leading, node.value, isLastNode(path$$1, node) ? "" : " "]);
  19952. }
  19953. var leading = node.value.trim().startsWith("(") ? line$4 : "";
  19954. var value = adjustNumbers(adjustStrings(node.value.trim(), options)) || line$4;
  19955. return concat$7([leading, value]);
  19956. }
  19957. case "selector-universal":
  19958. {
  19959. return concat$7([node.namespace ? concat$7([node.namespace === true ? "" : node.namespace.trim(), "|"]) : "", adjustNumbers(node.value)]);
  19960. }
  19961. case "selector-pseudo":
  19962. {
  19963. return concat$7([maybeToLowerCase(node.value), node.nodes && node.nodes.length > 0 ? concat$7(["(", join$5(", ", path$$1.map(print, "nodes")), ")"]) : ""]);
  19964. }
  19965. case "selector-nesting":
  19966. {
  19967. return node.value;
  19968. }
  19969. case "selector-unknown":
  19970. {
  19971. var ruleAncestorNode = getAncestorNode(path$$1, "css-rule"); // Nested SCSS property
  19972. if (ruleAncestorNode && ruleAncestorNode.isSCSSNesterProperty) {
  19973. return adjustNumbers(adjustStrings(maybeToLowerCase(node.value), options));
  19974. }
  19975. return node.value;
  19976. }
  19977. // postcss-values-parser
  19978. case "value-value":
  19979. case "value-root":
  19980. {
  19981. return path$$1.call(print, "group");
  19982. }
  19983. case "value-comment":
  19984. {
  19985. return concat$7([node.inline ? "//" : "/*", node.value, node.inline ? "" : "*/"]);
  19986. }
  19987. case "value-comma_group":
  19988. {
  19989. var _parentNode2 = path$$1.getParentNode();
  19990. var parentParentNode = path$$1.getParentNode(1);
  19991. var declAncestorProp = getPropOfDeclNode(path$$1);
  19992. var isGridValue = declAncestorProp && _parentNode2.type === "value-value" && (declAncestorProp === "grid" || declAncestorProp.startsWith("grid-template"));
  19993. var atRuleAncestorNode = getAncestorNode(path$$1, "css-atrule");
  19994. var isControlDirective = atRuleAncestorNode && isSCSSControlDirectiveNode(atRuleAncestorNode);
  19995. var printed = path$$1.map(print, "groups");
  19996. var _parts = [];
  19997. var insideURLFunction = insideValueFunctionNode(path$$1, "url");
  19998. var insideSCSSInterpolationInString = false;
  19999. var didBreak = false;
  20000. for (var i = 0; i < node.groups.length; ++i) {
  20001. _parts.push(printed[i]); // Ignore value inside `url()`
  20002. if (insideURLFunction) {
  20003. continue;
  20004. }
  20005. var iPrevNode = node.groups[i - 1];
  20006. var iNode = node.groups[i];
  20007. var iNextNode = node.groups[i + 1];
  20008. var iNextNextNode = node.groups[i + 2]; // Ignore after latest node (i.e. before semicolon)
  20009. if (!iNextNode) {
  20010. continue;
  20011. } // Ignore spaces before/after string interpolation (i.e. `"#{my-fn("_")}"`)
  20012. var isStartSCSSinterpolationInString = iNode.type === "value-string" && iNode.value.startsWith("#{");
  20013. var isEndingSCSSinterpolationInString = insideSCSSInterpolationInString && iNextNode.type === "value-string" && iNextNode.value.endsWith("}");
  20014. if (isStartSCSSinterpolationInString || isEndingSCSSinterpolationInString) {
  20015. insideSCSSInterpolationInString = !insideSCSSInterpolationInString;
  20016. continue;
  20017. }
  20018. if (insideSCSSInterpolationInString) {
  20019. continue;
  20020. } // Ignore colon (i.e. `:`)
  20021. if (isColonNode(iNode) || isColonNode(iNextNode)) {
  20022. continue;
  20023. } // Ignore `@` in Less (i.e. `@@var;`)
  20024. if (iNode.type === "value-atword" && iNode.value === "") {
  20025. continue;
  20026. } // Ignore `~` in Less (i.e. `content: ~"^//* some horrible but needed css hack";`)
  20027. if (iNode.value === "~") {
  20028. continue;
  20029. } // Ignore `\` (i.e. `$variable: \@small;`)
  20030. if (iNode.value === "\\") {
  20031. continue;
  20032. } // Ignore `$$` (i.e. `background-color: $$(style)Color;`)
  20033. if (isPostcssSimpleVarNode(iNode, iNextNode)) {
  20034. continue;
  20035. } // Ignore spaces after `#` and after `{` and before `}` in SCSS interpolation (i.e. `#{variable}`)
  20036. if (isHashNode(iNode) || isLeftCurlyBraceNode(iNode) || isRightCurlyBraceNode(iNextNode) || isLeftCurlyBraceNode(iNextNode) && hasEmptyRawBefore(iNextNode) || isRightCurlyBraceNode(iNode) && hasEmptyRawBefore(iNextNode)) {
  20037. continue;
  20038. } // Ignore css variables and interpolation in SCSS (i.e. `--#{$var}`)
  20039. if (iNode.value === "--" && isHashNode(iNextNode)) {
  20040. continue;
  20041. } // Formatting math operations
  20042. var isMathOperator = isMathOperatorNode(iNode);
  20043. var isNextMathOperator = isMathOperatorNode(iNextNode); // Print spaces before and after math operators beside SCSS interpolation as is
  20044. // (i.e. `#{$var}+5`, `#{$var} +5`, `#{$var}+ 5`, `#{$var} + 5`)
  20045. // (i.e. `5+#{$var}`, `5 +#{$var}`, `5+ #{$var}`, `5 + #{$var}`)
  20046. if ((isMathOperator && isHashNode(iNextNode) || isNextMathOperator && isRightCurlyBraceNode(iNode)) && hasEmptyRawBefore(iNextNode)) {
  20047. continue;
  20048. } // Print spaces before and after addition and subtraction math operators as is in `calc` function
  20049. // due to the fact that it is not valid syntax
  20050. // (i.e. `calc(1px+1px)`, `calc(1px+ 1px)`, `calc(1px +1px)`, `calc(1px + 1px)`)
  20051. if (insideValueFunctionNode(path$$1, "calc") && (isAdditionNode(iNode) || isAdditionNode(iNextNode) || isSubtractionNode(iNode) || isSubtractionNode(iNextNode)) && hasEmptyRawBefore(iNextNode)) {
  20052. continue;
  20053. } // Print spaces after `+` and `-` in color adjuster functions as is (e.g. `color(red l(+ 20%))`)
  20054. // Adjusters with signed numbers (e.g. `color(red l(+20%))`) output as-is.
  20055. var isColorAdjusterNode = (isAdditionNode(iNode) || isSubtractionNode(iNode)) && i === 0 && (iNextNode.type === "value-number" || iNextNode.isHex) && parentParentNode && isColorAdjusterFuncNode(parentParentNode) && !hasEmptyRawBefore(iNextNode);
  20056. var requireSpaceBeforeOperator = iNextNextNode && iNextNextNode.type === "value-func" || iNextNextNode && isWordNode(iNextNextNode) || iNode.type === "value-func" || isWordNode(iNode);
  20057. var requireSpaceAfterOperator = iNextNode.type === "value-func" || isWordNode(iNextNode) || iPrevNode && iPrevNode.type === "value-func" || iPrevNode && isWordNode(iPrevNode); // Formatting `/`, `+`, `-` sign
  20058. if (!(isMultiplicationNode(iNextNode) || isMultiplicationNode(iNode)) && !insideValueFunctionNode(path$$1, "calc") && !isColorAdjusterNode && (isDivisionNode(iNextNode) && !requireSpaceBeforeOperator || isDivisionNode(iNode) && !requireSpaceAfterOperator || isAdditionNode(iNextNode) && !requireSpaceBeforeOperator || isAdditionNode(iNode) && !requireSpaceAfterOperator || isSubtractionNode(iNextNode) || isSubtractionNode(iNode)) && (hasEmptyRawBefore(iNextNode) || isMathOperator && (!iPrevNode || iPrevNode && isMathOperatorNode(iPrevNode)))) {
  20059. continue;
  20060. } // Ignore inline comment, they already contain newline at end (i.e. `// Comment`)
  20061. // Add `hardline` after inline comment (i.e. `// comment\n foo: bar;`)
  20062. var isInlineComment = isInlineValueCommentNode(iNode);
  20063. if (iPrevNode && isInlineValueCommentNode(iPrevNode) || isInlineComment || isInlineValueCommentNode(iNextNode)) {
  20064. if (isInlineComment) {
  20065. _parts.push(hardline$6);
  20066. }
  20067. continue;
  20068. } // Handle keywords in SCSS control directive
  20069. if (isControlDirective && (isEqualityOperatorNode(iNextNode) || isRelationalOperatorNode(iNextNode) || isIfElseKeywordNode(iNextNode) || isEachKeywordNode(iNode) || isForKeywordNode(iNode))) {
  20070. _parts.push(" ");
  20071. continue;
  20072. } // At-rule `namespace` should be in one line
  20073. if (atRuleAncestorNode && atRuleAncestorNode.name.toLowerCase() === "namespace") {
  20074. _parts.push(" ");
  20075. continue;
  20076. } // Formatting `grid` property
  20077. if (isGridValue) {
  20078. if (iNode.source.start.line !== iNextNode.source.start.line) {
  20079. _parts.push(hardline$6);
  20080. didBreak = true;
  20081. } else {
  20082. _parts.push(" ");
  20083. }
  20084. continue;
  20085. } // Add `space` before next math operation
  20086. // Note: `grip` property have `/` delimiter and it is not math operation, so
  20087. // `grid` property handles above
  20088. if (isNextMathOperator) {
  20089. _parts.push(" ");
  20090. continue;
  20091. } // Be default all values go through `line`
  20092. _parts.push(line$4);
  20093. }
  20094. if (didBreak) {
  20095. _parts.unshift(hardline$6);
  20096. }
  20097. if (isControlDirective) {
  20098. return group$2(indent$5(concat$7(_parts)));
  20099. } // Indent is not needed for import url when url is very long
  20100. // and node has two groups
  20101. // when type is value-comma_group
  20102. // example @import url("verylongurl") projection,tv
  20103. if (insideURLFunctionInImportAtRuleNode(path$$1)) {
  20104. return group$2(fill$3(_parts));
  20105. }
  20106. return group$2(indent$5(fill$3(_parts)));
  20107. }
  20108. case "value-paren_group":
  20109. {
  20110. var _parentNode3 = path$$1.getParentNode();
  20111. if (_parentNode3 && isURLFunctionNode(_parentNode3) && (node.groups.length === 1 || node.groups.length > 0 && node.groups[0].type === "value-comma_group" && node.groups[0].groups.length > 0 && node.groups[0].groups[0].type === "value-word" && node.groups[0].groups[0].value.startsWith("data:"))) {
  20112. return concat$7([node.open ? path$$1.call(print, "open") : "", join$5(",", path$$1.map(print, "groups")), node.close ? path$$1.call(print, "close") : ""]);
  20113. }
  20114. if (!node.open) {
  20115. var _printed = path$$1.map(print, "groups");
  20116. var res = [];
  20117. for (var _i = 0; _i < _printed.length; _i++) {
  20118. if (_i !== 0) {
  20119. res.push(concat$7([",", line$4]));
  20120. }
  20121. res.push(_printed[_i]);
  20122. }
  20123. return group$2(indent$5(fill$3(res)));
  20124. }
  20125. var isSCSSMapItem = isSCSSMapItemNode(path$$1);
  20126. return group$2(concat$7([node.open ? path$$1.call(print, "open") : "", indent$5(concat$7([softline$3, join$5(concat$7([",", line$4]), path$$1.map(function (childPath) {
  20127. var node = childPath.getValue();
  20128. var printed = print(childPath); // Key/Value pair in open paren already indented
  20129. if (isKeyValuePairNode(node) && node.type === "value-comma_group" && node.groups && node.groups[2] && node.groups[2].type === "value-paren_group") {
  20130. printed.contents.contents.parts[1] = group$2(printed.contents.contents.parts[1]);
  20131. return group$2(dedent$3(printed));
  20132. }
  20133. return printed;
  20134. }, "groups"))])), ifBreak$2(isSCSS(options.parser, options.originalText) && isSCSSMapItem && shouldPrintComma$1(options) ? "," : ""), softline$3, node.close ? path$$1.call(print, "close") : ""]), {
  20135. shouldBreak: isSCSSMapItem
  20136. });
  20137. }
  20138. case "value-func":
  20139. {
  20140. return concat$7([node.value, insideAtRuleNode(path$$1, "supports") && isMediaAndSupportsKeywords(node) ? " " : "", path$$1.call(print, "group")]);
  20141. }
  20142. case "value-paren":
  20143. {
  20144. return node.value;
  20145. }
  20146. case "value-number":
  20147. {
  20148. return concat$7([printCssNumber(node.value), maybeToLowerCase(node.unit)]);
  20149. }
  20150. case "value-operator":
  20151. {
  20152. return node.value;
  20153. }
  20154. case "value-word":
  20155. {
  20156. if (node.isColor && node.isHex || isWideKeywords(node.value)) {
  20157. return node.value.toLowerCase();
  20158. }
  20159. return node.value;
  20160. }
  20161. case "value-colon":
  20162. {
  20163. return concat$7([node.value, // Don't add spaces on `:` in `url` function (i.e. `url(fbglyph: cross-outline, fig-white)`)
  20164. insideValueFunctionNode(path$$1, "url") ? "" : line$4]);
  20165. }
  20166. case "value-comma":
  20167. {
  20168. return concat$7([node.value, " "]);
  20169. }
  20170. case "value-string":
  20171. {
  20172. return printString$2(node.raws.quote + node.value + node.raws.quote, options);
  20173. }
  20174. case "value-atword":
  20175. {
  20176. return concat$7(["@", node.value]);
  20177. }
  20178. case "value-unicode-range":
  20179. {
  20180. return node.value;
  20181. }
  20182. case "value-unknown":
  20183. {
  20184. return node.value;
  20185. }
  20186. default:
  20187. /* istanbul ignore next */
  20188. throw new Error(`Unknown postcss type ${JSON.stringify(node.type)}`);
  20189. }
  20190. }
  20191. function printNodeSequence(path$$1, options, print) {
  20192. var node = path$$1.getValue();
  20193. var parts = [];
  20194. var i = 0;
  20195. path$$1.map(function (pathChild) {
  20196. var prevNode = node.nodes[i - 1];
  20197. if (prevNode && prevNode.type === "css-comment" && prevNode.text.trim() === "prettier-ignore") {
  20198. var childNode = pathChild.getValue();
  20199. parts.push(options.originalText.slice(options.locStart(childNode), options.locEnd(childNode)));
  20200. } else {
  20201. parts.push(pathChild.call(print));
  20202. }
  20203. if (i !== node.nodes.length - 1) {
  20204. if (node.nodes[i + 1].type === "css-comment" && !hasNewline$3(options.originalText, options.locStart(node.nodes[i + 1]), {
  20205. backwards: true
  20206. }) || node.nodes[i + 1].type === "css-atrule" && node.nodes[i + 1].name === "else" && node.nodes[i].type !== "css-comment") {
  20207. parts.push(" ");
  20208. } else {
  20209. parts.push(hardline$6);
  20210. if (isNextLineEmpty$3(options.originalText, pathChild.getValue(), options)) {
  20211. parts.push(hardline$6);
  20212. }
  20213. }
  20214. }
  20215. i++;
  20216. }, "nodes");
  20217. return concat$7(parts);
  20218. }
  20219. var STRING_REGEX = /(['"])(?:(?!\1)[^\\]|\\[\s\S])*\1/g;
  20220. var NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g;
  20221. var STANDARD_UNIT_REGEX = /[a-zA-Z]+/g;
  20222. var WORD_PART_REGEX = /[$@]?[a-zA-Z_\u0080-\uFFFF][\w\-\u0080-\uFFFF]*/g;
  20223. var ADJUST_NUMBERS_REGEX = RegExp(STRING_REGEX.source + `|` + `(${WORD_PART_REGEX.source})?` + `(${NUMBER_REGEX.source})` + `(${STANDARD_UNIT_REGEX.source})?`, "g");
  20224. function adjustStrings(value, options) {
  20225. return value.replace(STRING_REGEX, function (match) {
  20226. return printString$2(match, options);
  20227. });
  20228. }
  20229. function quoteAttributeValue(value, options) {
  20230. var quote = options.singleQuote ? "'" : '"';
  20231. return value.includes('"') || value.includes("'") ? value : quote + value + quote;
  20232. }
  20233. function adjustNumbers(value) {
  20234. return value.replace(ADJUST_NUMBERS_REGEX, function (match, quote, wordPart, number, unit) {
  20235. return !wordPart && number ? (wordPart || "") + printCssNumber(number) + maybeToLowerCase(unit || "") : match;
  20236. });
  20237. }
  20238. function printCssNumber(rawNumber) {
  20239. return printNumber$2(rawNumber) // Remove trailing `.0`.
  20240. .replace(/\.0(?=$|e)/, "");
  20241. }
  20242. var printerPostcss = {
  20243. print: genericPrint$3,
  20244. hasPrettierIgnore: hasIgnoreComment$2,
  20245. massageAstNode: clean_1$2
  20246. };
  20247. var options$6 = {
  20248. singleQuote: commonOptions.singleQuote
  20249. };
  20250. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  20251. var languages$1 = [{
  20252. name: "CSS",
  20253. since: "1.4.0",
  20254. parsers: ["css"],
  20255. group: "CSS",
  20256. tmScope: "source.css",
  20257. aceMode: "css",
  20258. codemirrorMode: "css",
  20259. codemirrorMimeType: "text/css",
  20260. extensions: [".css", ".pcss", ".postcss"],
  20261. liguistLanguageId: 50,
  20262. vscodeLanguageIds: ["css", "postcss"]
  20263. }, {
  20264. name: "Less",
  20265. since: "1.4.0",
  20266. parsers: ["less"],
  20267. group: "CSS",
  20268. extensions: [".less"],
  20269. tmScope: "source.css.less",
  20270. aceMode: "less",
  20271. codemirrorMode: "css",
  20272. codemirrorMimeType: "text/css",
  20273. liguistLanguageId: 198,
  20274. vscodeLanguageIds: ["less"]
  20275. }, {
  20276. name: "SCSS",
  20277. since: "1.4.0",
  20278. parsers: ["scss"],
  20279. group: "CSS",
  20280. tmScope: "source.scss",
  20281. aceMode: "scss",
  20282. codemirrorMode: "css",
  20283. codemirrorMimeType: "text/x-scss",
  20284. extensions: [".scss"],
  20285. liguistLanguageId: 329,
  20286. vscodeLanguageIds: ["scss"]
  20287. }];
  20288. var printers$1 = {
  20289. postcss: printerPostcss
  20290. };
  20291. var languageCss = {
  20292. languages: languages$1,
  20293. options: options$6,
  20294. printers: printers$1
  20295. };
  20296. var _require$$0$builders$3 = doc.builders;
  20297. var concat$8 = _require$$0$builders$3.concat;
  20298. var join$6 = _require$$0$builders$3.join;
  20299. var softline$4 = _require$$0$builders$3.softline;
  20300. var hardline$7 = _require$$0$builders$3.hardline;
  20301. var line$5 = _require$$0$builders$3.line;
  20302. var group$3 = _require$$0$builders$3.group;
  20303. var indent$6 = _require$$0$builders$3.indent;
  20304. var ifBreak$3 = _require$$0$builders$3.ifBreak; // http://w3c.github.io/html/single-page.html#void-elements
  20305. var voidTags = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]; // Formatter based on @glimmerjs/syntax's built-in test formatter:
  20306. // https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/syntax/lib/generation/print.ts
  20307. function print(path$$1, options, print) {
  20308. var n = path$$1.getValue();
  20309. /* istanbul ignore if*/
  20310. if (!n) {
  20311. return "";
  20312. }
  20313. switch (n.type) {
  20314. case "Program":
  20315. {
  20316. return group$3(join$6(softline$4, path$$1.map(print, "body").filter(function (text) {
  20317. return text !== "";
  20318. })));
  20319. }
  20320. case "ElementNode":
  20321. {
  20322. var isVoid = voidTags.indexOf(n.tag) !== -1;
  20323. var closeTag = isVoid ? concat$8([" />", softline$4]) : ">";
  20324. var hasChildren = n.children.length > 0;
  20325. var _getParams = function _getParams(path$$1, print) {
  20326. return indent$6(concat$8([n.attributes.length ? line$5 : "", join$6(line$5, path$$1.map(print, "attributes")), n.modifiers.length ? line$5 : "", join$6(line$5, path$$1.map(print, "modifiers")), n.comments.length ? line$5 : "", join$6(line$5, path$$1.map(print, "comments"))]));
  20327. }; // The problem here is that I want to not break at all if the children
  20328. // would not break but I need to force an indent, so I use a hardline.
  20329. /**
  20330. * What happens now:
  20331. * <div>
  20332. * Hello
  20333. * </div>
  20334. * ==>
  20335. * <div>Hello</div>
  20336. * This is due to me using hasChildren to decide to put the hardline in.
  20337. * I would rather use a {DOES THE WHOLE THING NEED TO BREAK}
  20338. */
  20339. return concat$8([group$3(concat$8(["<", n.tag, _getParams(path$$1, print), ifBreak$3(softline$4, ""), closeTag])), group$3(concat$8([indent$6(join$6(softline$4, [""].concat(path$$1.map(print, "children")))), ifBreak$3(hasChildren ? hardline$7 : "", ""), !isVoid ? concat$8(["</", n.tag, ">"]) : ""]))]);
  20340. }
  20341. case "BlockStatement":
  20342. {
  20343. var pp = path$$1.getParentNode(1);
  20344. var isElseIf = pp && pp.inverse && pp.inverse.body[0] === n && pp.inverse.body[0].path.parts[0] === "if";
  20345. var hasElseIf = n.inverse && n.inverse.body[0] && n.inverse.body[0].type === "BlockStatement" && n.inverse.body[0].path.parts[0] === "if";
  20346. var indentElse = hasElseIf ? function (a) {
  20347. return a;
  20348. } : indent$6;
  20349. if (n.inverse) {
  20350. return concat$8([isElseIf ? concat$8(["{{else ", printPathParams(path$$1, print), "}}"]) : printOpenBlock(path$$1, print), indent$6(concat$8([hardline$7, path$$1.call(print, "program")])), n.inverse && !hasElseIf ? concat$8([hardline$7, "{{else}}"]) : "", n.inverse ? indentElse(concat$8([hardline$7, path$$1.call(print, "inverse")])) : "", isElseIf ? "" : concat$8([hardline$7, printCloseBlock(path$$1, print)])]);
  20351. } else if (isElseIf) {
  20352. return concat$8([concat$8(["{{else ", printPathParams(path$$1, print), "}}"]), indent$6(concat$8([hardline$7, path$$1.call(print, "program")]))]);
  20353. }
  20354. /**
  20355. * I want this boolean to be: if params are going to cause a break,
  20356. * not that it has params.
  20357. */
  20358. var hasParams = n.params.length > 0 || n.hash.pairs.length > 0;
  20359. var _hasChildren = n.program.body.length > 0;
  20360. return concat$8([printOpenBlock(path$$1, print), group$3(concat$8([indent$6(concat$8([softline$4, path$$1.call(print, "program")])), hasParams && _hasChildren ? hardline$7 : "", printCloseBlock(path$$1, print)]))]);
  20361. }
  20362. case "ElementModifierStatement":
  20363. case "MustacheStatement":
  20364. {
  20365. var _pp = path$$1.getParentNode(1);
  20366. var isConcat = _pp && _pp.type === "ConcatStatement";
  20367. return group$3(concat$8([n.escaped === false ? "{{{" : "{{", printPathParams(path$$1, print), isConcat ? "" : softline$4, n.escaped === false ? "}}}" : "}}"]));
  20368. }
  20369. case "SubExpression":
  20370. {
  20371. return group$3(concat$8(["(", printPath(path$$1, print), indent$6(concat$8([line$5, group$3(join$6(line$5, getParams(path$$1, print)))])), softline$4, ")"]));
  20372. }
  20373. case "AttrNode":
  20374. {
  20375. var quote = n.value.type === "TextNode" ? '"' : "";
  20376. return concat$8([n.name, "=", quote, path$$1.call(print, "value"), quote]);
  20377. }
  20378. case "ConcatStatement":
  20379. {
  20380. return concat$8(['"', group$3(indent$6(join$6(softline$4, path$$1.map(function (partPath) {
  20381. return print(partPath);
  20382. }, "parts").filter(function (a) {
  20383. return a !== "";
  20384. })))), '"']);
  20385. }
  20386. case "Hash":
  20387. {
  20388. return concat$8([join$6(line$5, path$$1.map(print, "pairs"))]);
  20389. }
  20390. case "HashPair":
  20391. {
  20392. return concat$8([n.key, "=", path$$1.call(print, "value")]);
  20393. }
  20394. case "TextNode":
  20395. {
  20396. var leadingSpace = "";
  20397. var trailingSpace = ""; // preserve a space inside of an attribute node where whitespace present, when next to mustache statement.
  20398. var inAttrNode = path$$1.stack.indexOf("attributes") >= 0;
  20399. if (inAttrNode) {
  20400. var parentNode = path$$1.getParentNode(0);
  20401. var _isConcat = parentNode.type === "ConcatStatement";
  20402. if (_isConcat) {
  20403. var parts = parentNode.parts;
  20404. var partIndex = parts.indexOf(n);
  20405. if (partIndex > 0) {
  20406. var partType = parts[partIndex - 1].type;
  20407. var isMustache = partType === "MustacheStatement";
  20408. if (isMustache) {
  20409. leadingSpace = " ";
  20410. }
  20411. }
  20412. if (partIndex < parts.length - 1) {
  20413. var _partType = parts[partIndex + 1].type;
  20414. var _isMustache = _partType === "MustacheStatement";
  20415. if (_isMustache) {
  20416. trailingSpace = " ";
  20417. }
  20418. }
  20419. }
  20420. }
  20421. return n.chars.replace(/^\s+/, leadingSpace).replace(/\s+$/, trailingSpace);
  20422. }
  20423. case "MustacheCommentStatement":
  20424. {
  20425. var dashes = n.value.indexOf("}}") > -1 ? "--" : "";
  20426. return concat$8(["{{!", dashes, n.value, dashes, "}}"]);
  20427. }
  20428. case "PathExpression":
  20429. {
  20430. return n.original;
  20431. }
  20432. case "BooleanLiteral":
  20433. {
  20434. return String(n.value);
  20435. }
  20436. case "CommentStatement":
  20437. {
  20438. return concat$8(["<!--", n.value, "-->"]);
  20439. }
  20440. case "StringLiteral":
  20441. {
  20442. return `"${n.value}"`;
  20443. }
  20444. case "NumberLiteral":
  20445. {
  20446. return String(n.value);
  20447. }
  20448. case "UndefinedLiteral":
  20449. {
  20450. return "undefined";
  20451. }
  20452. case "NullLiteral":
  20453. {
  20454. return "null";
  20455. }
  20456. /* istanbul ignore next */
  20457. default:
  20458. throw new Error("unknown glimmer type: " + JSON.stringify(n.type));
  20459. }
  20460. }
  20461. function printPath(path$$1, print) {
  20462. return path$$1.call(print, "path");
  20463. }
  20464. function getParams(path$$1, print) {
  20465. var node = path$$1.getValue();
  20466. var parts = [];
  20467. if (node.params.length > 0) {
  20468. parts = parts.concat(path$$1.map(print, "params"));
  20469. }
  20470. if (node.hash && node.hash.pairs.length > 0) {
  20471. parts.push(path$$1.call(print, "hash"));
  20472. }
  20473. return parts;
  20474. }
  20475. function printPathParams(path$$1, print) {
  20476. var parts = [];
  20477. parts.push(printPath(path$$1, print));
  20478. parts = parts.concat(getParams(path$$1, print));
  20479. return indent$6(group$3(join$6(line$5, parts)));
  20480. }
  20481. function printBlockParams(path$$1) {
  20482. var block = path$$1.getValue();
  20483. if (!block.program || !block.program.blockParams.length) {
  20484. return "";
  20485. }
  20486. return concat$8([" as |", block.program.blockParams.join(" "), "|"]);
  20487. }
  20488. function printOpenBlock(path$$1, print) {
  20489. return group$3(concat$8(["{{#", printPathParams(path$$1, print), printBlockParams(path$$1, print), softline$4, "}}"]));
  20490. }
  20491. function printCloseBlock(path$$1, print) {
  20492. return concat$8(["{{/", path$$1.call(print, "path"), "}}"]);
  20493. }
  20494. function clean$5(ast, newObj) {
  20495. delete newObj.loc; // (Glimmer/HTML) ignore TextNode whitespace
  20496. if (ast.type === "TextNode") {
  20497. if (ast.chars.replace(/\s+/, "") === "") {
  20498. return null;
  20499. }
  20500. newObj.chars = ast.chars.replace(/^\s+/, "").replace(/\s+$/, "");
  20501. }
  20502. }
  20503. var printerGlimmer = {
  20504. print,
  20505. massageAstNode: clean$5
  20506. };
  20507. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  20508. var languages$2 = [{
  20509. type: "markup",
  20510. group: "HTML",
  20511. aliases: ["hbs", "htmlbars"],
  20512. extensions: [".handlebars", ".hbs"],
  20513. tm_scope: "text.html.handlebars",
  20514. ace_mode: "handlebars",
  20515. language_id: 155,
  20516. since: null // unreleased
  20517. }];
  20518. var printers$2 = {
  20519. glimmer: printerGlimmer
  20520. };
  20521. var languageHandlebars = {
  20522. languages: languages$2,
  20523. printers: printers$2
  20524. };
  20525. var _require$$0$builders$4 = doc.builders;
  20526. var concat$9 = _require$$0$builders$4.concat;
  20527. var join$7 = _require$$0$builders$4.join;
  20528. var hardline$8 = _require$$0$builders$4.hardline;
  20529. var line$6 = _require$$0$builders$4.line;
  20530. var softline$5 = _require$$0$builders$4.softline;
  20531. var group$4 = _require$$0$builders$4.group;
  20532. var indent$7 = _require$$0$builders$4.indent;
  20533. var ifBreak$4 = _require$$0$builders$4.ifBreak;
  20534. var hasIgnoreComment$3 = util$1.hasIgnoreComment;
  20535. var isNextLineEmpty$4 = utilShared.isNextLineEmpty;
  20536. function genericPrint$4(path$$1, options, print) {
  20537. var n = path$$1.getValue();
  20538. if (!n) {
  20539. return "";
  20540. }
  20541. if (typeof n === "string") {
  20542. return n;
  20543. }
  20544. switch (n.kind) {
  20545. case "Document":
  20546. {
  20547. var parts = [];
  20548. path$$1.map(function (pathChild, index) {
  20549. parts.push(concat$9([pathChild.call(print)]));
  20550. if (index !== n.definitions.length - 1) {
  20551. parts.push(hardline$8);
  20552. if (isNextLineEmpty$4(options.originalText, pathChild.getValue(), options)) {
  20553. parts.push(hardline$8);
  20554. }
  20555. }
  20556. }, "definitions");
  20557. return concat$9([concat$9(parts), hardline$8]);
  20558. }
  20559. case "OperationDefinition":
  20560. {
  20561. var hasOperation = options.originalText[options.locStart(n)] !== "{";
  20562. var hasName = !!n.name;
  20563. return concat$9([hasOperation ? n.operation : "", hasOperation && hasName ? concat$9([" ", path$$1.call(print, "name")]) : "", n.variableDefinitions && n.variableDefinitions.length ? group$4(concat$9(["(", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.map(print, "variableDefinitions"))])), softline$5, ")"])) : "", printDirectives(path$$1, print, n), n.selectionSet ? !hasOperation && !hasName ? "" : " " : "", path$$1.call(print, "selectionSet")]);
  20564. }
  20565. case "FragmentDefinition":
  20566. {
  20567. return concat$9(["fragment ", path$$1.call(print, "name"), " on ", path$$1.call(print, "typeCondition"), printDirectives(path$$1, print, n), " ", path$$1.call(print, "selectionSet")]);
  20568. }
  20569. case "SelectionSet":
  20570. {
  20571. return concat$9(["{", indent$7(concat$9([hardline$8, join$7(hardline$8, path$$1.call(function (selectionsPath) {
  20572. return printSequence(selectionsPath, options, print);
  20573. }, "selections"))])), hardline$8, "}"]);
  20574. }
  20575. case "Field":
  20576. {
  20577. return group$4(concat$9([n.alias ? concat$9([path$$1.call(print, "alias"), ": "]) : "", path$$1.call(print, "name"), n.arguments.length > 0 ? group$4(concat$9(["(", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
  20578. return printSequence(argsPath, options, print);
  20579. }, "arguments"))])), softline$5, ")"])) : "", printDirectives(path$$1, print, n), n.selectionSet ? " " : "", path$$1.call(print, "selectionSet")]));
  20580. }
  20581. case "Name":
  20582. {
  20583. return n.value;
  20584. }
  20585. case "StringValue":
  20586. {
  20587. if (n.block) {
  20588. return concat$9(['"""', hardline$8, join$7(hardline$8, n.value.replace(/"""/g, "\\$&").split("\n")), hardline$8, '"""']);
  20589. }
  20590. return concat$9(['"', n.value.replace(/["\\]/g, "\\$&"), '"']);
  20591. }
  20592. case "IntValue":
  20593. case "FloatValue":
  20594. case "EnumValue":
  20595. {
  20596. return n.value;
  20597. }
  20598. case "BooleanValue":
  20599. {
  20600. return n.value ? "true" : "false";
  20601. }
  20602. case "NullValue":
  20603. {
  20604. return "null";
  20605. }
  20606. case "Variable":
  20607. {
  20608. return concat$9(["$", path$$1.call(print, "name")]);
  20609. }
  20610. case "ListValue":
  20611. {
  20612. return group$4(concat$9(["[", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.map(print, "values"))])), softline$5, "]"]));
  20613. }
  20614. case "ObjectValue":
  20615. {
  20616. return group$4(concat$9(["{", options.bracketSpacing && n.fields.length > 0 ? " " : "", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.map(print, "fields"))])), softline$5, ifBreak$4("", options.bracketSpacing && n.fields.length > 0 ? " " : ""), "}"]));
  20617. }
  20618. case "ObjectField":
  20619. case "Argument":
  20620. {
  20621. return concat$9([path$$1.call(print, "name"), ": ", path$$1.call(print, "value")]);
  20622. }
  20623. case "Directive":
  20624. {
  20625. return concat$9(["@", path$$1.call(print, "name"), n.arguments.length > 0 ? group$4(concat$9(["(", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
  20626. return printSequence(argsPath, options, print);
  20627. }, "arguments"))])), softline$5, ")"])) : ""]);
  20628. }
  20629. case "NamedType":
  20630. {
  20631. return path$$1.call(print, "name");
  20632. }
  20633. case "VariableDefinition":
  20634. {
  20635. return concat$9([path$$1.call(print, "variable"), ": ", path$$1.call(print, "type"), n.defaultValue ? concat$9([" = ", path$$1.call(print, "defaultValue")]) : ""]);
  20636. }
  20637. case "TypeExtensionDefinition":
  20638. {
  20639. return concat$9(["extend ", path$$1.call(print, "definition")]);
  20640. }
  20641. case "ObjectTypeExtension":
  20642. case "ObjectTypeDefinition":
  20643. {
  20644. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", n.kind === "ObjectTypeExtension" ? "extend " : "", "type ", path$$1.call(print, "name"), n.interfaces.length > 0 ? concat$9([" implements ", join$7(determineInterfaceSeparator(options.originalText.substr(options.locStart(n), options.locEnd(n))), path$$1.map(print, "interfaces"))]) : "", printDirectives(path$$1, print, n), n.fields.length > 0 ? concat$9([" {", indent$7(concat$9([hardline$8, join$7(hardline$8, path$$1.call(function (fieldsPath) {
  20645. return printSequence(fieldsPath, options, print);
  20646. }, "fields"))])), hardline$8, "}"]) : ""]);
  20647. }
  20648. case "FieldDefinition":
  20649. {
  20650. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", path$$1.call(print, "name"), n.arguments.length > 0 ? group$4(concat$9(["(", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
  20651. return printSequence(argsPath, options, print);
  20652. }, "arguments"))])), softline$5, ")"])) : "", ": ", path$$1.call(print, "type"), printDirectives(path$$1, print, n)]);
  20653. }
  20654. case "DirectiveDefinition":
  20655. {
  20656. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", "directive ", "@", path$$1.call(print, "name"), n.arguments.length > 0 ? group$4(concat$9(["(", indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", ", "), softline$5]), path$$1.call(function (argsPath) {
  20657. return printSequence(argsPath, options, print);
  20658. }, "arguments"))])), softline$5, ")"])) : "", concat$9([" on ", join$7(" | ", path$$1.map(print, "locations"))])]);
  20659. }
  20660. case "EnumTypeExtension":
  20661. case "EnumTypeDefinition":
  20662. {
  20663. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", n.kind === "EnumTypeExtension" ? "extend " : "", "enum ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.values.length > 0 ? concat$9([" {", indent$7(concat$9([hardline$8, join$7(hardline$8, path$$1.call(function (valuesPath) {
  20664. return printSequence(valuesPath, options, print);
  20665. }, "values"))])), hardline$8, "}"]) : ""]);
  20666. }
  20667. case "EnumValueDefinition":
  20668. {
  20669. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
  20670. }
  20671. case "InputValueDefinition":
  20672. {
  20673. return concat$9([path$$1.call(print, "description"), n.description ? n.description.block ? hardline$8 : line$6 : "", path$$1.call(print, "name"), ": ", path$$1.call(print, "type"), n.defaultValue ? concat$9([" = ", path$$1.call(print, "defaultValue")]) : "", printDirectives(path$$1, print, n)]);
  20674. }
  20675. case "InputObjectTypeExtension":
  20676. case "InputObjectTypeDefinition":
  20677. {
  20678. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", n.kind === "InputObjectTypeExtension" ? "extend " : "", "input ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.fields.length > 0 ? concat$9([" {", indent$7(concat$9([hardline$8, join$7(hardline$8, path$$1.call(function (fieldsPath) {
  20679. return printSequence(fieldsPath, options, print);
  20680. }, "fields"))])), hardline$8, "}"]) : ""]);
  20681. }
  20682. case "SchemaDefinition":
  20683. {
  20684. return concat$9(["schema", printDirectives(path$$1, print, n), " {", n.operationTypes.length > 0 ? indent$7(concat$9([hardline$8, join$7(hardline$8, path$$1.call(function (opsPath) {
  20685. return printSequence(opsPath, options, print);
  20686. }, "operationTypes"))])) : "", hardline$8, "}"]);
  20687. }
  20688. case "OperationTypeDefinition":
  20689. {
  20690. return concat$9([path$$1.call(print, "operation"), ": ", path$$1.call(print, "type")]);
  20691. }
  20692. case "InterfaceTypeExtension":
  20693. case "InterfaceTypeDefinition":
  20694. {
  20695. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", n.kind === "InterfaceTypeExtension" ? "extend " : "", "interface ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.fields.length > 0 ? concat$9([" {", indent$7(concat$9([hardline$8, join$7(hardline$8, path$$1.call(function (fieldsPath) {
  20696. return printSequence(fieldsPath, options, print);
  20697. }, "fields"))])), hardline$8, "}"]) : ""]);
  20698. }
  20699. case "FragmentSpread":
  20700. {
  20701. return concat$9(["...", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
  20702. }
  20703. case "InlineFragment":
  20704. {
  20705. return concat$9(["...", n.typeCondition ? concat$9([" on ", path$$1.call(print, "typeCondition")]) : "", printDirectives(path$$1, print, n), " ", path$$1.call(print, "selectionSet")]);
  20706. }
  20707. case "UnionTypeExtension":
  20708. case "UnionTypeDefinition":
  20709. {
  20710. return group$4(concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", group$4(concat$9([n.kind === "UnionTypeExtension" ? "extend " : "", "union ", path$$1.call(print, "name"), printDirectives(path$$1, print, n), n.types.length > 0 ? concat$9([" =", ifBreak$4("", " "), indent$7(concat$9([ifBreak$4(concat$9([line$6, " "])), join$7(concat$9([line$6, "| "]), path$$1.map(print, "types"))]))]) : ""]))]));
  20711. }
  20712. case "ScalarTypeExtension":
  20713. case "ScalarTypeDefinition":
  20714. {
  20715. return concat$9([path$$1.call(print, "description"), n.description ? hardline$8 : "", n.kind === "ScalarTypeExtension" ? "extend " : "", "scalar ", path$$1.call(print, "name"), printDirectives(path$$1, print, n)]);
  20716. }
  20717. case "NonNullType":
  20718. {
  20719. return concat$9([path$$1.call(print, "type"), "!"]);
  20720. }
  20721. case "ListType":
  20722. {
  20723. return concat$9(["[", path$$1.call(print, "type"), "]"]);
  20724. }
  20725. default:
  20726. /* istanbul ignore next */
  20727. throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
  20728. }
  20729. }
  20730. function printDirectives(path$$1, print, n) {
  20731. if (n.directives.length === 0) {
  20732. return "";
  20733. }
  20734. return concat$9([" ", group$4(indent$7(concat$9([softline$5, join$7(concat$9([ifBreak$4("", " "), softline$5]), path$$1.map(print, "directives"))])))]);
  20735. }
  20736. function printSequence(sequencePath, options, print) {
  20737. var count = sequencePath.getValue().length;
  20738. return sequencePath.map(function (path$$1, i) {
  20739. var printed = print(path$$1);
  20740. if (isNextLineEmpty$4(options.originalText, path$$1.getValue(), options) && i < count - 1) {
  20741. return concat$9([printed, hardline$8]);
  20742. }
  20743. return printed;
  20744. });
  20745. }
  20746. function canAttachComment$1(node) {
  20747. return node.kind && node.kind !== "Comment";
  20748. }
  20749. function printComment$2(commentPath) {
  20750. var comment = commentPath.getValue();
  20751. switch (comment.kind) {
  20752. case "Comment":
  20753. return "#" + comment.value.trimRight();
  20754. default:
  20755. throw new Error("Not a comment: " + JSON.stringify(comment));
  20756. }
  20757. }
  20758. function determineInterfaceSeparator(originalSource) {
  20759. var start = originalSource.indexOf("implements");
  20760. if (start === -1) {
  20761. throw new Error("Must implement interfaces: " + originalSource);
  20762. }
  20763. var end = originalSource.indexOf("{");
  20764. if (end === -1) {
  20765. end = originalSource.length;
  20766. }
  20767. return originalSource.substr(start, end).includes("&") ? " & " : ", ";
  20768. }
  20769. function clean$6(node, newNode
  20770. /*, parent*/
  20771. ) {
  20772. delete newNode.loc;
  20773. delete newNode.comments;
  20774. }
  20775. var printerGraphql = {
  20776. print: genericPrint$4,
  20777. massageAstNode: clean$6,
  20778. hasPrettierIgnore: hasIgnoreComment$3,
  20779. printComment: printComment$2,
  20780. canAttachComment: canAttachComment$1
  20781. };
  20782. var options$9 = {
  20783. bracketSpacing: commonOptions.bracketSpacing
  20784. };
  20785. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  20786. var languages$3 = [{
  20787. name: "GraphQL",
  20788. since: "1.5.0",
  20789. parsers: ["graphql"],
  20790. extensions: [".graphql", ".gql"],
  20791. tmScope: "source.graphql",
  20792. aceMode: "text",
  20793. liguistLanguageId: 139,
  20794. vscodeLanguageIds: ["graphql"]
  20795. }];
  20796. var printers$3 = {
  20797. graphql: printerGraphql
  20798. };
  20799. var languageGraphql = {
  20800. languages: languages$3,
  20801. options: options$9,
  20802. printers: printers$3
  20803. };
  20804. var _require$$0$builders$6 = doc.builders;
  20805. var hardline$10 = _require$$0$builders$6.hardline;
  20806. var literalline$4 = _require$$0$builders$6.literalline;
  20807. var concat$11 = _require$$0$builders$6.concat;
  20808. var markAsRoot$2 = _require$$0$builders$6.markAsRoot;
  20809. var mapDoc$4 = doc.utils.mapDoc;
  20810. function embed$2(path$$1, print, textToDoc, options) {
  20811. var node = path$$1.getValue();
  20812. if (node.type === "code" && node.lang !== null) {
  20813. // only look for the first string so as to support [markdown-preview-enhanced](https://shd101wyy.github.io/markdown-preview-enhanced/#/code-chunk)
  20814. var lang = node.lang.split(/\s/, 1)[0];
  20815. var parser = getParserName(lang);
  20816. if (parser) {
  20817. var styleUnit = options.__inJsTemplate ? "~" : "`";
  20818. var style = styleUnit.repeat(Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1));
  20819. var doc$$2 = textToDoc(node.value, {
  20820. parser
  20821. });
  20822. return markAsRoot$2(concat$11([style, node.lang, hardline$10, replaceNewlinesWithLiterallines(doc$$2), style]));
  20823. }
  20824. }
  20825. return null;
  20826. function getParserName(lang) {
  20827. var supportInfo = support.getSupportInfo(null, {
  20828. plugins: options.plugins
  20829. });
  20830. var language = supportInfo.languages.find(function (language) {
  20831. return language.name.toLowerCase() === lang || language.extensions && language.extensions.find(function (ext) {
  20832. return ext.substring(1) === lang;
  20833. });
  20834. });
  20835. if (language) {
  20836. return language.parsers[0];
  20837. }
  20838. return null;
  20839. }
  20840. function replaceNewlinesWithLiterallines(doc$$2) {
  20841. return mapDoc$4(doc$$2, function (currentDoc) {
  20842. return typeof currentDoc === "string" && currentDoc.includes("\n") ? concat$11(currentDoc.split(/(\n)/g).map(function (v, i) {
  20843. return i % 2 === 0 ? v : literalline$4;
  20844. })) : currentDoc;
  20845. });
  20846. }
  20847. }
  20848. var embed_1$2 = embed$2;
  20849. function parse$5(text) {
  20850. var delimiter;
  20851. if (text.indexOf("---") === 0) {
  20852. delimiter = "---";
  20853. } else if (text.indexOf("+++") === 0) {
  20854. delimiter = "+++";
  20855. }
  20856. var end = -1;
  20857. if (!delimiter || (end = text.indexOf(`\n${delimiter}`, 3)) === -1) {
  20858. return {
  20859. frontMatter: null,
  20860. content: text
  20861. };
  20862. }
  20863. end = end + 4;
  20864. return {
  20865. frontMatter: text.slice(0, end),
  20866. content: text.slice(end)
  20867. };
  20868. }
  20869. var frontMatter = parse$5;
  20870. var pragma$2 = createCommonjsModule(function (module) {
  20871. "use strict";
  20872. var pragmas = ["format", "prettier"];
  20873. function startWithPragma(text) {
  20874. var pragma = `@(${pragmas.join("|")})`;
  20875. var regex = new RegExp([`<!--\\s*${pragma}\\s*-->`, `<!--.*\n[\\s\\S]*(^|\n)[^\\S\n]*${pragma}[^\\S\n]*($|\n)[\\s\\S]*\n.*-->`].join("|"), "m");
  20876. var matched = text.match(regex);
  20877. return matched && matched.index === 0;
  20878. }
  20879. module.exports = {
  20880. startWithPragma,
  20881. hasPragma: function hasPragma(text) {
  20882. return startWithPragma(frontMatter(text).content.trimLeft());
  20883. },
  20884. insertPragma: function insertPragma(text) {
  20885. var extracted = frontMatter(text);
  20886. var pragma = `<!-- @${pragmas[0]} -->`;
  20887. return extracted.frontMatter ? `${extracted.frontMatter}\n\n${pragma}\n\n${extracted.content}` : `${pragma}\n\n${extracted.content}`;
  20888. }
  20889. };
  20890. });
  20891. var _require$$0$builders$5 = doc.builders;
  20892. var concat$10 = _require$$0$builders$5.concat;
  20893. var join$8 = _require$$0$builders$5.join;
  20894. var line$7 = _require$$0$builders$5.line;
  20895. var literalline$3 = _require$$0$builders$5.literalline;
  20896. var markAsRoot$1 = _require$$0$builders$5.markAsRoot;
  20897. var hardline$9 = _require$$0$builders$5.hardline;
  20898. var softline$6 = _require$$0$builders$5.softline;
  20899. var fill$4 = _require$$0$builders$5.fill;
  20900. var align$2 = _require$$0$builders$5.align;
  20901. var indent$8 = _require$$0$builders$5.indent;
  20902. var group$5 = _require$$0$builders$5.group;
  20903. var mapDoc$3 = doc.utils.mapDoc;
  20904. var printDocToString$3 = doc.printer.printDocToString;
  20905. var SINGLE_LINE_NODE_TYPES = ["heading", "tableCell", "link"];
  20906. var SIBLING_NODE_TYPES = ["listItem", "definition", "footnoteDefinition"];
  20907. var INLINE_NODE_TYPES = ["liquidNode", "inlineCode", "emphasis", "strong", "delete", "link", "linkReference", "image", "imageReference", "footnote", "footnoteReference", "sentence", "whitespace", "word", "break"];
  20908. var INLINE_NODE_WRAPPER_TYPES = INLINE_NODE_TYPES.concat(["tableCell", "paragraph", "heading"]);
  20909. function genericPrint$5(path$$1, options, print) {
  20910. var node = path$$1.getValue();
  20911. if (shouldRemainTheSameContent(path$$1)) {
  20912. return concat$10(util$1.splitText(options.originalText.slice(node.position.start.offset, node.position.end.offset), options).map(function (node) {
  20913. return node.type === "word" ? node.value : node.value === "" ? "" : printLine(path$$1, node.value, options);
  20914. }));
  20915. }
  20916. switch (node.type) {
  20917. case "root":
  20918. if (node.children.length === 0) {
  20919. return "";
  20920. }
  20921. return concat$10([normalizeDoc(printRoot(path$$1, options, print)), hardline$9]);
  20922. case "paragraph":
  20923. return printChildren(path$$1, options, print, {
  20924. postprocessor: fill$4
  20925. });
  20926. case "sentence":
  20927. return printChildren(path$$1, options, print);
  20928. case "word":
  20929. return node.value.replace(/[*]/g, "\\*") // escape all `*`
  20930. .replace(new RegExp([`(^|[${util$1.punctuationCharRange}])(_+)`, `(_+)([${util$1.punctuationCharRange}]|$)`].join("|"), "g"), function (_, text1, underscore1, underscore2, text2) {
  20931. return (underscore1 ? `${text1}${underscore1}` : `${underscore2}${text2}`).replace(/_/g, "\\_");
  20932. });
  20933. // escape all `_` except concating with non-punctuation, e.g. `1_2_3` is not considered emphasis
  20934. case "whitespace":
  20935. {
  20936. var parentNode = path$$1.getParentNode();
  20937. var index = parentNode.children.indexOf(node);
  20938. var nextNode = parentNode.children[index + 1];
  20939. var proseWrap = // leading char that may cause different syntax
  20940. nextNode && /^>|^([-+*]|#{1,6}|[0-9]+[.)])$/.test(nextNode.value) ? "never" : options.proseWrap;
  20941. return printLine(path$$1, node.value, {
  20942. proseWrap
  20943. });
  20944. }
  20945. case "emphasis":
  20946. {
  20947. var _parentNode = path$$1.getParentNode();
  20948. var _index = _parentNode.children.indexOf(node);
  20949. var prevNode = _parentNode.children[_index - 1];
  20950. var _nextNode = _parentNode.children[_index + 1];
  20951. var hasPrevOrNextWord = // `1*2*3` is considered emphais but `1_2_3` is not
  20952. prevNode && prevNode.type === "sentence" && prevNode.children.length > 0 && util$1.getLast(prevNode.children).type === "word" && !util$1.getLast(prevNode.children).hasTrailingPunctuation || _nextNode && _nextNode.type === "sentence" && _nextNode.children.length > 0 && _nextNode.children[0].type === "word" && !_nextNode.children[0].hasLeadingPunctuation;
  20953. var style = hasPrevOrNextWord || getAncestorNode$2(path$$1, "emphasis") ? "*" : "_";
  20954. return concat$10([style, printChildren(path$$1, options, print), style]);
  20955. }
  20956. case "strong":
  20957. return concat$10(["**", printChildren(path$$1, options, print), "**"]);
  20958. case "delete":
  20959. return concat$10(["~~", printChildren(path$$1, options, print), "~~"]);
  20960. case "inlineCode":
  20961. {
  20962. var backtickCount = util$1.getMaxContinuousCount(node.value, "`");
  20963. var _style = backtickCount === 1 ? "``" : "`";
  20964. var gap = backtickCount ? " " : "";
  20965. return concat$10([_style, gap, node.value, gap, _style]);
  20966. }
  20967. case "link":
  20968. switch (options.originalText[node.position.start.offset]) {
  20969. case "<":
  20970. return concat$10(["<", node.url, ">"]);
  20971. case "[":
  20972. return concat$10(["[", printChildren(path$$1, options, print), "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  20973. default:
  20974. return options.originalText.slice(node.position.start.offset, node.position.end.offset);
  20975. }
  20976. case "image":
  20977. return concat$10(["![", node.alt || "", "](", printUrl(node.url, ")"), printTitle(node.title, options), ")"]);
  20978. case "blockquote":
  20979. return concat$10(["> ", align$2("> ", printChildren(path$$1, options, print))]);
  20980. case "heading":
  20981. return concat$10(["#".repeat(node.depth) + " ", printChildren(path$$1, options, print)]);
  20982. case "code":
  20983. {
  20984. if ( // the first char may point to `\n`, e.g. `\n\t\tbar`, just ignore it
  20985. /^\n?( {4,}|\t)/.test(options.originalText.slice(node.position.start.offset, node.position.end.offset))) {
  20986. // indented code block
  20987. var alignment = " ".repeat(4);
  20988. return align$2(alignment, concat$10([alignment, join$8(hardline$9, node.value.split("\n"))]));
  20989. } // fenced code block
  20990. var styleUnit = options.__inJsTemplate ? "~" : "`";
  20991. var _style2 = styleUnit.repeat(Math.max(3, util$1.getMaxContinuousCount(node.value, styleUnit) + 1));
  20992. return concat$10([_style2, node.lang || "", hardline$9, join$8(hardline$9, node.value.split("\n")), hardline$9, _style2]);
  20993. }
  20994. case "front-matter":
  20995. return node.value;
  20996. case "html":
  20997. {
  20998. var _parentNode2 = path$$1.getParentNode();
  20999. var value = _parentNode2.type === "root" && util$1.getLast(_parentNode2.children) === node ? node.value.trimRight() : node.value;
  21000. var isHtmlComment = /^<!--[\s\S]*-->$/.test(value);
  21001. return replaceNewlinesWith(value, isHtmlComment ? hardline$9 : markAsRoot$1(literalline$3));
  21002. }
  21003. case "list":
  21004. {
  21005. var nthSiblingIndex = getNthListSiblingIndex(node, path$$1.getParentNode());
  21006. var isGitDiffFriendlyOrderedList = node.ordered && node.children.length > 1 && /^\s*1(\.|\))/.test(options.originalText.slice(node.children[1].position.start.offset, node.children[1].position.end.offset));
  21007. return printChildren(path$$1, options, print, {
  21008. processor: function processor(childPath, index) {
  21009. var prefix = getPrefix();
  21010. return concat$10([prefix, align$2(" ".repeat(prefix.length), printListItem(childPath, options, print, prefix))]);
  21011. function getPrefix() {
  21012. var rawPrefix = node.ordered ? (index === 0 ? node.start : isGitDiffFriendlyOrderedList ? 1 : node.start + index) + (nthSiblingIndex % 2 === 0 ? ". " : ") ") : nthSiblingIndex % 2 === 0 ? "- " : "* "; // do not print trailing spaces for empty list item since it might be treated as `break` node
  21013. // by [doc-printer](https://github.com/prettier/prettier/blob/1.10.2/src/doc/doc-printer.js#L395-L405),
  21014. // we don't want to preserve unnecessary trailing spaces.
  21015. var listItem = childPath.getValue();
  21016. return listItem.children.length ? alignListPrefix(rawPrefix, options) : rawPrefix;
  21017. }
  21018. }
  21019. });
  21020. }
  21021. case "thematicBreak":
  21022. {
  21023. var counter = getAncestorCounter$1(path$$1, "list");
  21024. if (counter === -1) {
  21025. return "---";
  21026. }
  21027. var _nthSiblingIndex = getNthListSiblingIndex(path$$1.getParentNode(counter), path$$1.getParentNode(counter + 1));
  21028. return _nthSiblingIndex % 2 === 0 ? "***" : "---";
  21029. }
  21030. case "linkReference":
  21031. return concat$10(["[", printChildren(path$$1, options, print), "]", node.referenceType === "full" ? concat$10(["[", node.identifier, "]"]) : node.referenceType === "collapsed" ? "[]" : ""]);
  21032. case "imageReference":
  21033. switch (node.referenceType) {
  21034. case "full":
  21035. return concat$10(["![", node.alt || "", "][", node.identifier, "]"]);
  21036. default:
  21037. return concat$10(["![", node.alt, "]", node.referenceType === "collapsed" ? "[]" : ""]);
  21038. }
  21039. case "definition":
  21040. {
  21041. var lineOrSpace = options.proseWrap === "always" ? line$7 : " ";
  21042. return group$5(concat$10([concat$10(["[", node.identifier, "]:"]), indent$8(concat$10([lineOrSpace, printUrl(node.url), node.title === null ? "" : concat$10([lineOrSpace, printTitle(node.title, options, false)])]))]));
  21043. }
  21044. case "footnote":
  21045. return concat$10(["[^", printChildren(path$$1, options, print), "]"]);
  21046. case "footnoteReference":
  21047. return concat$10(["[^", node.identifier, "]"]);
  21048. case "footnoteDefinition":
  21049. {
  21050. var _nextNode2 = path$$1.getParentNode().children[path$$1.getName() + 1];
  21051. return concat$10(["[^", node.identifier, "]: ", group$5(concat$10([align$2(" ".repeat(options.tabWidth), printChildren(path$$1, options, print, {
  21052. processor: function processor(childPath, index) {
  21053. return index === 0 ? group$5(concat$10([softline$6, softline$6, childPath.call(print)])) : childPath.call(print);
  21054. }
  21055. })), _nextNode2 && _nextNode2.type === "footnoteDefinition" ? softline$6 : ""]))]);
  21056. }
  21057. case "table":
  21058. return printTable(path$$1, options, print);
  21059. case "tableCell":
  21060. return printChildren(path$$1, options, print);
  21061. case "break":
  21062. return /\s/.test(options.originalText[node.position.start.offset]) ? concat$10([" ", markAsRoot$1(literalline$3)]) : concat$10(["\\", hardline$9]);
  21063. case "liquidNode":
  21064. return replaceNewlinesWith(node.value, hardline$9);
  21065. case "tableRow": // handled in "table"
  21066. case "listItem": // handled in "list"
  21067. default:
  21068. throw new Error(`Unknown markdown type ${JSON.stringify(node.type)}`);
  21069. }
  21070. }
  21071. function printListItem(path$$1, options, print, listPrefix) {
  21072. var node = path$$1.getValue();
  21073. var prefix = node.checked === null ? "" : node.checked ? "[x] " : "[ ] ";
  21074. return concat$10([prefix, printChildren(path$$1, options, print, {
  21075. processor: function processor(childPath, index) {
  21076. if (index === 0 && childPath.getValue().type !== "list") {
  21077. return align$2(" ".repeat(prefix.length), childPath.call(print));
  21078. }
  21079. var alignment = " ".repeat(clamp(options.tabWidth - listPrefix.length, 0, 3) // 4+ will cause indented code block
  21080. );
  21081. return concat$10([alignment, align$2(alignment, childPath.call(print))]);
  21082. }
  21083. })]);
  21084. }
  21085. function alignListPrefix(prefix, options) {
  21086. var additionalSpaces = getAdditionalSpaces();
  21087. return prefix + " ".repeat(additionalSpaces >= 4 ? 0 : additionalSpaces // 4+ will cause indented code block
  21088. );
  21089. function getAdditionalSpaces() {
  21090. var restSpaces = prefix.length % options.tabWidth;
  21091. return restSpaces === 0 ? 0 : options.tabWidth - restSpaces;
  21092. }
  21093. }
  21094. function getNthListSiblingIndex(node, parentNode) {
  21095. return getNthSiblingIndex(node, parentNode, function (siblingNode) {
  21096. return siblingNode.ordered === node.ordered;
  21097. });
  21098. }
  21099. function replaceNewlinesWith(str, doc$$2) {
  21100. return join$8(doc$$2, str.split("\n"));
  21101. }
  21102. function getNthSiblingIndex(node, parentNode, condition) {
  21103. condition = condition || function () {
  21104. return true;
  21105. };
  21106. var index = -1;
  21107. var _iteratorNormalCompletion = true;
  21108. var _didIteratorError = false;
  21109. var _iteratorError = undefined;
  21110. try {
  21111. for (var _iterator = parentNode.children[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  21112. var childNode = _step.value;
  21113. if (childNode.type === node.type && condition(childNode)) {
  21114. index++;
  21115. } else {
  21116. index = -1;
  21117. }
  21118. if (childNode === node) {
  21119. return index;
  21120. }
  21121. }
  21122. } catch (err) {
  21123. _didIteratorError = true;
  21124. _iteratorError = err;
  21125. } finally {
  21126. try {
  21127. if (!_iteratorNormalCompletion && _iterator.return != null) {
  21128. _iterator.return();
  21129. }
  21130. } finally {
  21131. if (_didIteratorError) {
  21132. throw _iteratorError;
  21133. }
  21134. }
  21135. }
  21136. }
  21137. function getAncestorCounter$1(path$$1, typeOrTypes) {
  21138. var types = [].concat(typeOrTypes);
  21139. var counter = -1;
  21140. var ancestorNode;
  21141. while (ancestorNode = path$$1.getParentNode(++counter)) {
  21142. if (types.indexOf(ancestorNode.type) !== -1) {
  21143. return counter;
  21144. }
  21145. }
  21146. return -1;
  21147. }
  21148. function getAncestorNode$2(path$$1, typeOrTypes) {
  21149. var counter = getAncestorCounter$1(path$$1, typeOrTypes);
  21150. return counter === -1 ? null : path$$1.getParentNode(counter);
  21151. }
  21152. function printLine(path$$1, value, options) {
  21153. if (options.proseWrap === "preserve" && value === "\n") {
  21154. return hardline$9;
  21155. }
  21156. var isBreakable = options.proseWrap === "always" && !getAncestorNode$2(path$$1, SINGLE_LINE_NODE_TYPES);
  21157. return value !== "" ? isBreakable ? line$7 : " " : isBreakable ? softline$6 : "";
  21158. }
  21159. function printTable(path$$1, options, print) {
  21160. var node = path$$1.getValue();
  21161. var contents = []; // { [rowIndex: number]: { [columnIndex: number]: string } }
  21162. path$$1.map(function (rowPath) {
  21163. var rowContents = [];
  21164. rowPath.map(function (cellPath) {
  21165. rowContents.push(printDocToString$3(cellPath.call(print), options).formatted);
  21166. }, "children");
  21167. contents.push(rowContents);
  21168. }, "children");
  21169. var columnMaxWidths = contents.reduce(function (currentWidths, rowContents) {
  21170. return currentWidths.map(function (width, columnIndex) {
  21171. return Math.max(width, util$1.getStringWidth(rowContents[columnIndex]));
  21172. });
  21173. }, contents[0].map(function () {
  21174. return 3;
  21175. }) // minimum width = 3 (---, :--, :-:, --:)
  21176. );
  21177. return join$8(hardline$9, [printRow(contents[0]), printSeparator(), join$8(hardline$9, contents.slice(1).map(printRow))]);
  21178. function printSeparator() {
  21179. return concat$10(["| ", join$8(" | ", columnMaxWidths.map(function (width, index) {
  21180. switch (node.align[index]) {
  21181. case "left":
  21182. return ":" + "-".repeat(width - 1);
  21183. case "right":
  21184. return "-".repeat(width - 1) + ":";
  21185. case "center":
  21186. return ":" + "-".repeat(width - 2) + ":";
  21187. default:
  21188. return "-".repeat(width);
  21189. }
  21190. })), " |"]);
  21191. }
  21192. function printRow(rowContents) {
  21193. return concat$10(["| ", join$8(" | ", rowContents.map(function (rowContent, columnIndex) {
  21194. switch (node.align[columnIndex]) {
  21195. case "right":
  21196. return alignRight(rowContent, columnMaxWidths[columnIndex]);
  21197. case "center":
  21198. return alignCenter(rowContent, columnMaxWidths[columnIndex]);
  21199. default:
  21200. return alignLeft(rowContent, columnMaxWidths[columnIndex]);
  21201. }
  21202. })), " |"]);
  21203. }
  21204. function alignLeft(text, width) {
  21205. return concat$10([text, " ".repeat(width - util$1.getStringWidth(text))]);
  21206. }
  21207. function alignRight(text, width) {
  21208. return concat$10([" ".repeat(width - util$1.getStringWidth(text)), text]);
  21209. }
  21210. function alignCenter(text, width) {
  21211. var spaces = width - util$1.getStringWidth(text);
  21212. var left = Math.floor(spaces / 2);
  21213. var right = spaces - left;
  21214. return concat$10([" ".repeat(left), text, " ".repeat(right)]);
  21215. }
  21216. }
  21217. function printRoot(path$$1, options, print) {
  21218. /** @typedef {{ index: number, offset: number }} IgnorePosition */
  21219. /** @type {Array<{start: IgnorePosition, end: IgnorePosition}>} */
  21220. var ignoreRanges = [];
  21221. /** @type {IgnorePosition | null} */
  21222. var ignoreStart = null;
  21223. var children = path$$1.getValue().children;
  21224. children.forEach(function (childNode, index) {
  21225. switch (isPrettierIgnore(childNode)) {
  21226. case "start":
  21227. if (ignoreStart === null) {
  21228. ignoreStart = {
  21229. index,
  21230. offset: childNode.position.end.offset
  21231. };
  21232. }
  21233. break;
  21234. case "end":
  21235. if (ignoreStart !== null) {
  21236. ignoreRanges.push({
  21237. start: ignoreStart,
  21238. end: {
  21239. index,
  21240. offset: childNode.position.start.offset
  21241. }
  21242. });
  21243. ignoreStart = null;
  21244. }
  21245. break;
  21246. default:
  21247. // do nothing
  21248. break;
  21249. }
  21250. });
  21251. return printChildren(path$$1, options, print, {
  21252. processor: function processor(childPath, index) {
  21253. if (ignoreRanges.length !== 0) {
  21254. var ignoreRange = ignoreRanges[0];
  21255. if (index === ignoreRange.start.index) {
  21256. return concat$10([children[ignoreRange.start.index].value, options.originalText.slice(ignoreRange.start.offset, ignoreRange.end.offset), children[ignoreRange.end.index].value]);
  21257. }
  21258. if (ignoreRange.start.index < index && index < ignoreRange.end.index) {
  21259. return false;
  21260. }
  21261. if (index === ignoreRange.end.index) {
  21262. ignoreRanges.shift();
  21263. return false;
  21264. }
  21265. }
  21266. return childPath.call(print);
  21267. }
  21268. });
  21269. }
  21270. function printChildren(path$$1, options, print, events$$1) {
  21271. events$$1 = events$$1 || {};
  21272. var postprocessor = events$$1.postprocessor || concat$10;
  21273. var processor = events$$1.processor || function (childPath) {
  21274. return childPath.call(print);
  21275. };
  21276. var node = path$$1.getValue();
  21277. var parts = [];
  21278. var lastChildNode;
  21279. path$$1.map(function (childPath, index) {
  21280. var childNode = childPath.getValue();
  21281. var result = processor(childPath, index);
  21282. if (result !== false) {
  21283. var data = {
  21284. parts,
  21285. prevNode: lastChildNode,
  21286. parentNode: node,
  21287. options
  21288. };
  21289. if (!shouldNotPrePrintHardline(childNode, data)) {
  21290. parts.push(hardline$9);
  21291. if (shouldPrePrintDoubleHardline(childNode, data) || shouldPrePrintTripleHardline(childNode, data)) {
  21292. parts.push(hardline$9);
  21293. }
  21294. if (shouldPrePrintTripleHardline(childNode, data)) {
  21295. parts.push(hardline$9);
  21296. }
  21297. }
  21298. parts.push(result);
  21299. lastChildNode = childNode;
  21300. }
  21301. }, "children");
  21302. return postprocessor(parts);
  21303. }
  21304. /** @return {false | 'next' | 'start' | 'end'} */
  21305. function isPrettierIgnore(node) {
  21306. if (node.type !== "html") {
  21307. return false;
  21308. }
  21309. var match = node.value.match(/^<!--\s*prettier-ignore(?:-(start|end))?\s*-->$/);
  21310. return match === null ? false : match[1] ? match[1] : "next";
  21311. }
  21312. function shouldNotPrePrintHardline(node, data) {
  21313. var isFirstNode = data.parts.length === 0;
  21314. var isInlineNode = INLINE_NODE_TYPES.indexOf(node.type) !== -1;
  21315. var isInlineHTML = node.type === "html" && INLINE_NODE_WRAPPER_TYPES.indexOf(data.parentNode.type) !== -1;
  21316. return isFirstNode || isInlineNode || isInlineHTML;
  21317. }
  21318. function shouldPrePrintDoubleHardline(node, data) {
  21319. var isSequence = (data.prevNode && data.prevNode.type) === node.type;
  21320. var isSiblingNode = isSequence && SIBLING_NODE_TYPES.indexOf(node.type) !== -1;
  21321. var isInTightListItem = data.parentNode.type === "listItem" && !data.parentNode.loose;
  21322. var isPrevNodeLooseListItem = data.prevNode && data.prevNode.type === "listItem" && data.prevNode.loose;
  21323. var isPrevNodePrettierIgnore = isPrettierIgnore(data.prevNode) === "next";
  21324. var isBlockHtmlWithoutBlankLineBetweenPrevHtml = node.type === "html" && data.prevNode && data.prevNode.type === "html" && data.prevNode.position.end.line + 1 === node.position.start.line;
  21325. return isPrevNodeLooseListItem || !(isSiblingNode || isInTightListItem || isPrevNodePrettierIgnore || isBlockHtmlWithoutBlankLineBetweenPrevHtml);
  21326. }
  21327. function shouldPrePrintTripleHardline(node, data) {
  21328. var isPrevNodeList = data.prevNode && data.prevNode.type === "list";
  21329. var isIndentedCode = node.type === "code" && /\s/.test(data.options.originalText[node.position.start.offset]);
  21330. return isPrevNodeList && isIndentedCode;
  21331. }
  21332. function shouldRemainTheSameContent(path$$1) {
  21333. var ancestorNode = getAncestorNode$2(path$$1, ["linkReference", "imageReference"]);
  21334. return ancestorNode && (ancestorNode.type !== "linkReference" || ancestorNode.referenceType !== "full");
  21335. }
  21336. function normalizeDoc(doc$$2) {
  21337. return mapDoc$3(doc$$2, function (currentDoc) {
  21338. if (!currentDoc.parts) {
  21339. return currentDoc;
  21340. }
  21341. if (currentDoc.type === "concat" && currentDoc.parts.length === 1) {
  21342. return currentDoc.parts[0];
  21343. }
  21344. var parts = [];
  21345. currentDoc.parts.forEach(function (part) {
  21346. if (part.type === "concat") {
  21347. parts.push.apply(parts, part.parts);
  21348. } else if (part !== "") {
  21349. parts.push(part);
  21350. }
  21351. });
  21352. return Object.assign({}, currentDoc, {
  21353. parts: normalizeParts(parts)
  21354. });
  21355. });
  21356. }
  21357. function printUrl(url, dangerousCharOrChars) {
  21358. var dangerousChars = [" "].concat(dangerousCharOrChars || []);
  21359. return new RegExp(dangerousChars.map(function (x) {
  21360. return `\\${x}`;
  21361. }).join("|")).test(url) ? `<${url}>` : url;
  21362. }
  21363. function printTitle(title, options, printSpace) {
  21364. if (printSpace == null) {
  21365. printSpace = true;
  21366. }
  21367. if (!title) {
  21368. return "";
  21369. }
  21370. if (printSpace) {
  21371. return " " + printTitle(title, options, false);
  21372. }
  21373. if (title.includes('"') && title.includes("'") && !title.includes(")")) {
  21374. return `(${title})`; // avoid escaped quotes
  21375. } // faster than using RegExps: https://jsperf.com/performance-of-match-vs-split
  21376. var singleCount = title.split("'").length - 1;
  21377. var doubleCount = title.split('"').length - 1;
  21378. var quote = singleCount > doubleCount ? '"' : doubleCount > singleCount ? "'" : options.singleQuote ? "'" : '"';
  21379. title = title.replace(new RegExp(`(${quote})`, "g"), "\\$1");
  21380. return `${quote}${title}${quote}`;
  21381. }
  21382. function normalizeParts(parts) {
  21383. return parts.reduce(function (current, part) {
  21384. var lastPart = util$1.getLast(current);
  21385. if (typeof lastPart === "string" && typeof part === "string") {
  21386. current.splice(-1, 1, lastPart + part);
  21387. } else {
  21388. current.push(part);
  21389. }
  21390. return current;
  21391. }, []);
  21392. }
  21393. function clamp(value, min, max) {
  21394. return value < min ? min : value > max ? max : value;
  21395. }
  21396. function clean$7(ast, newObj, parent) {
  21397. delete newObj.position; // for codeblock
  21398. if (ast.type === "code") {
  21399. delete newObj.value;
  21400. } // for whitespace: "\n" and " " are considered the same
  21401. if (ast.type === "whitespace" && ast.value === "\n") {
  21402. newObj.value = " ";
  21403. } // for insert pragma
  21404. if (parent && parent.type === "root" && parent.children.length > 0 && (parent.children[0] === ast || parent.children[0].type === "front-matter" && parent.children[1] === ast) && ast.type === "html" && pragma$2.startWithPragma(ast.value)) {
  21405. return null;
  21406. }
  21407. }
  21408. function hasPrettierIgnore$1(path$$1) {
  21409. var index = +path$$1.getName();
  21410. if (index === 0) {
  21411. return false;
  21412. }
  21413. var prevNode = path$$1.getParentNode().children[index - 1];
  21414. return isPrettierIgnore(prevNode) === "next";
  21415. }
  21416. var printerMarkdown = {
  21417. print: genericPrint$5,
  21418. embed: embed_1$2,
  21419. massageAstNode: clean$7,
  21420. hasPrettierIgnore: hasPrettierIgnore$1,
  21421. insertPragma: pragma$2.insertPragma
  21422. };
  21423. var CATEGORY_MARKDOWN = "Markdown"; // format based on https://github.com/prettier/prettier/blob/master/src/main/core-options.js
  21424. var options$12 = {
  21425. proseWrap: {
  21426. since: "1.8.2",
  21427. category: CATEGORY_MARKDOWN,
  21428. type: "choice",
  21429. default: [{
  21430. since: "1.8.2",
  21431. value: true
  21432. }, {
  21433. since: "1.9.0",
  21434. value: "preserve"
  21435. }],
  21436. description: "How to wrap prose. (markdown)",
  21437. choices: [{
  21438. since: "1.9.0",
  21439. value: "always",
  21440. description: "Wrap prose if it exceeds the print width."
  21441. }, {
  21442. since: "1.9.0",
  21443. value: "never",
  21444. description: "Do not wrap prose."
  21445. }, {
  21446. since: "1.9.0",
  21447. value: "preserve",
  21448. description: "Wrap prose as-is."
  21449. }, {
  21450. value: false,
  21451. deprecated: "1.9.0",
  21452. redirect: "never"
  21453. }, {
  21454. value: true,
  21455. deprecated: "1.9.0",
  21456. redirect: "always"
  21457. }]
  21458. },
  21459. singleQuote: commonOptions.singleQuote
  21460. };
  21461. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  21462. var languages$4 = [{
  21463. name: "Markdown",
  21464. since: "1.8.0",
  21465. parsers: ["remark"],
  21466. aliases: ["pandoc"],
  21467. aceMode: "markdown",
  21468. codemirrorMode: "gfm",
  21469. codemirrorMimeType: "text/x-gfm",
  21470. wrap: true,
  21471. extensions: [".md", ".markdown", ".mdown", ".mdwn", ".mkd", ".mkdn", ".mkdown", ".ron", ".workbook"],
  21472. filenames: ["README"],
  21473. tmScope: "source.gfm",
  21474. linguistLanguageId: 222,
  21475. vscodeLanguageIds: ["markdown"]
  21476. }];
  21477. var printers$4 = {
  21478. mdast: printerMarkdown
  21479. };
  21480. var languageMarkdown = {
  21481. languages: languages$4,
  21482. options: options$12,
  21483. printers: printers$4
  21484. };
  21485. var hasNewlineInRange$3 = util$1.hasNewlineInRange;
  21486. var _require$$1$builders$1 = doc.builders;
  21487. var hardline$12 = _require$$1$builders$1.hardline;
  21488. var concat$13 = _require$$1$builders$1.concat;
  21489. var _require$$1$utils = doc.utils;
  21490. var stripTrailingHardline$2 = _require$$1$utils.stripTrailingHardline;
  21491. var removeLines$3 = _require$$1$utils.removeLines;
  21492. function embed$4(path$$1, print, textToDoc, options) {
  21493. var node = path$$1.getValue();
  21494. switch (node.type) {
  21495. case "text":
  21496. {
  21497. var parent = path$$1.getParentNode(); // Inline JavaScript
  21498. if (parent.type === "script" && (!parent.attribs.lang && !parent.attribs.lang || parent.attribs.type === "text/javascript" || parent.attribs.type === "application/javascript")) {
  21499. var parser = options.parser === "flow" ? "flow" : "babylon";
  21500. var doc$$2 = textToDoc(getText(options, node), {
  21501. parser
  21502. });
  21503. return concat$13([hardline$12, doc$$2]);
  21504. } // Inline TypeScript
  21505. if (parent.type === "script" && (parent.attribs.type === "application/x-typescript" || parent.attribs.lang === "ts")) {
  21506. var _doc = textToDoc(getText(options, node), {
  21507. parser: "typescript"
  21508. }, options);
  21509. return concat$13([hardline$12, _doc]);
  21510. } // Inline Styles
  21511. if (parent.type === "style") {
  21512. var _doc2 = textToDoc(getText(options, node), {
  21513. parser: "css"
  21514. });
  21515. return concat$13([hardline$12, stripTrailingHardline$2(_doc2)]);
  21516. }
  21517. break;
  21518. }
  21519. case "attribute":
  21520. {
  21521. /*
  21522. * Vue binding sytax: JS expressions
  21523. * :class="{ 'some-key': value }"
  21524. * v-bind:id="'list-' + id"
  21525. * v-if="foo && !bar"
  21526. * @click="someFunction()"
  21527. */
  21528. if (/(^@)|(^v-)|:/.test(node.key) && !/^\w+$/.test(node.value)) {
  21529. var _doc3 = textToDoc(node.value, {
  21530. parser: parseJavaScriptExpression,
  21531. // Use singleQuote since HTML attributes use double-quotes.
  21532. // TODO(azz): We still need to do an entity escape on the attribute.
  21533. singleQuote: true
  21534. });
  21535. return concat$13([node.key, '="', hasNewlineInRange$3(node.value, 0, node.value.length) ? _doc3 : removeLines$3(_doc3), '"']);
  21536. }
  21537. }
  21538. }
  21539. }
  21540. function parseJavaScriptExpression(text, parsers) {
  21541. // Force parsing as an expression
  21542. var ast = parsers.babylon(`(${text})`); // Extract expression from the declaration
  21543. return {
  21544. type: "File",
  21545. program: ast.program.body[0].expression
  21546. };
  21547. }
  21548. function getText(options, node) {
  21549. return options.originalText.slice(options.locStart(node), options.locEnd(node));
  21550. }
  21551. var embed_1$4 = embed$4;
  21552. var clean$8 = function clean(ast, newNode) {
  21553. delete newNode.__location;
  21554. if (ast.type === "text") {
  21555. return null;
  21556. }
  21557. };
  21558. var hasNewlineInRange$2 = util$1.hasNewlineInRange;
  21559. var hasIgnoreComment$4 = util$1.hasIgnoreComment;
  21560. var _require$$1$builders = doc.builders;
  21561. var concat$12 = _require$$1$builders.concat;
  21562. var join$9 = _require$$1$builders.join;
  21563. var hardline$11 = _require$$1$builders.hardline;
  21564. var line$8 = _require$$1$builders.line;
  21565. var softline$7 = _require$$1$builders.softline;
  21566. var group$6 = _require$$1$builders.group;
  21567. var indent$9 = _require$$1$builders.indent; // http://w3c.github.io/html/single-page.html#void-elements
  21568. var voidTags$1 = {
  21569. area: true,
  21570. base: true,
  21571. br: true,
  21572. col: true,
  21573. embed: true,
  21574. hr: true,
  21575. img: true,
  21576. input: true,
  21577. link: true,
  21578. meta: true,
  21579. param: true,
  21580. source: true,
  21581. track: true,
  21582. wbr: true
  21583. };
  21584. function genericPrint$6(path$$1, options, print) {
  21585. var n = path$$1.getValue();
  21586. if (!n) {
  21587. return "";
  21588. }
  21589. if (typeof n === "string") {
  21590. return n;
  21591. }
  21592. switch (n.type) {
  21593. case "root":
  21594. {
  21595. return printChildren$1(path$$1, print);
  21596. }
  21597. case "directive":
  21598. {
  21599. return concat$12(["<", n.data, ">", hardline$11]);
  21600. }
  21601. case "text":
  21602. {
  21603. return n.data.replace(/\s+/g, " ").trim();
  21604. }
  21605. case "script":
  21606. case "style":
  21607. case "tag":
  21608. {
  21609. var selfClose = voidTags$1[n.name] ? ">" : " />";
  21610. var children = printChildren$1(path$$1, print);
  21611. var hasNewline = hasNewlineInRange$2(options.originalText, options.locStart(n), options.locEnd(n));
  21612. return group$6(concat$12([hasNewline ? hardline$11 : "", "<", n.name, printAttributes(path$$1, print), n.children.length ? ">" : selfClose, n.name.toLowerCase() === "html" ? concat$12([hardline$11, children]) : indent$9(children), n.children.length ? concat$12([softline$7, "</", n.name, ">"]) : hardline$11]));
  21613. }
  21614. case "comment":
  21615. {
  21616. return concat$12(["<!-- ", n.data.trim(), " -->"]);
  21617. }
  21618. case "attribute":
  21619. {
  21620. if (!n.value) {
  21621. return n.key;
  21622. }
  21623. return concat$12([n.key, '="', n.value, '"']);
  21624. }
  21625. default:
  21626. /* istanbul ignore next */
  21627. throw new Error("unknown htmlparser2 type: " + n.type);
  21628. }
  21629. }
  21630. function printAttributes(path$$1, print) {
  21631. var node = path$$1.getValue();
  21632. return concat$12([node.attributes.length ? " " : "", indent$9(join$9(line$8, path$$1.map(print, "attributes")))]);
  21633. }
  21634. function printChildren$1(path$$1, print) {
  21635. var children = [];
  21636. path$$1.each(function (childPath) {
  21637. var child = childPath.getValue();
  21638. if (child.type !== "text") {
  21639. children.push(hardline$11);
  21640. }
  21641. children.push(childPath.call(print));
  21642. }, "children");
  21643. return concat$12(children);
  21644. }
  21645. var printerHtmlparser2 = {
  21646. print: genericPrint$6,
  21647. massageAstNode: clean$8,
  21648. embed: embed_1$4,
  21649. hasPrettierIgnore: hasIgnoreComment$4
  21650. };
  21651. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  21652. var languages$5 = [{
  21653. name: "HTML",
  21654. since: null,
  21655. // unreleased
  21656. parsers: ["parse5"],
  21657. group: "HTML",
  21658. tmScope: "text.html.basic",
  21659. aceMode: "html",
  21660. codemirrorMode: "htmlmixed",
  21661. codemirrorMimeType: "text/html",
  21662. aliases: ["xhtml"],
  21663. extensions: [".html", ".htm", ".html.hl", ".inc", ".st", ".xht", ".xhtml"],
  21664. linguistLanguageId: 146,
  21665. vscodeLanguageIds: ["html"]
  21666. }];
  21667. var printers$5 = {
  21668. htmlparser2: printerHtmlparser2
  21669. };
  21670. var languageHtml = {
  21671. languages: languages$5,
  21672. printers: printers$5
  21673. };
  21674. var _require$$0$builders$8 = doc.builders;
  21675. var concat$15 = _require$$0$builders$8.concat;
  21676. var hardline$14 = _require$$0$builders$8.hardline;
  21677. function embed$6(path$$1, print, textToDoc, options) {
  21678. var node = path$$1.getValue();
  21679. var parent = path$$1.getParentNode();
  21680. if (!parent || parent.tag !== "root" || node.unary) {
  21681. return null;
  21682. }
  21683. var parser;
  21684. if (node.tag === "style") {
  21685. var langAttr = node.attrs.find(function (attr) {
  21686. return attr.name === "lang";
  21687. });
  21688. if (!langAttr || langAttr.value === "postcss") {
  21689. parser = "css";
  21690. } else if (langAttr.value === "scss") {
  21691. parser = "scss";
  21692. } else if (langAttr.value === "less") {
  21693. parser = "less";
  21694. }
  21695. }
  21696. if (node.tag === "script") {
  21697. var _langAttr = node.attrs.find(function (attr) {
  21698. return attr.name === "lang";
  21699. });
  21700. if (!_langAttr) {
  21701. parser = "babylon";
  21702. } else if (_langAttr.value === "ts" || _langAttr.value === "tsx") {
  21703. parser = "typescript";
  21704. }
  21705. }
  21706. if (!parser) {
  21707. return null;
  21708. }
  21709. return concat$15([options.originalText.slice(node.start, node.contentStart), hardline$14, textToDoc(options.originalText.slice(node.contentStart, node.contentEnd), {
  21710. parser
  21711. }), options.originalText.slice(node.contentEnd, node.end)]);
  21712. }
  21713. var embed_1$6 = embed$6;
  21714. var _require$$0$builders$7 = doc.builders;
  21715. var concat$14 = _require$$0$builders$7.concat;
  21716. var hardline$13 = _require$$0$builders$7.hardline;
  21717. function genericPrint$7(path$$1, options, print) {
  21718. var n = path$$1.getValue();
  21719. var res = [];
  21720. var index = n.start;
  21721. path$$1.each(function (childPath) {
  21722. var child = childPath.getValue();
  21723. res.push(options.originalText.slice(index, child.start));
  21724. res.push(childPath.call(print));
  21725. index = child.end;
  21726. }, "children"); // If there are no children, we just print the node from start to end.
  21727. // Otherwise, index should point to the end of the last child, and we
  21728. // need to print the closing tag.
  21729. res.push(options.originalText.slice(index, n.end)); // Only force a trailing newline if there were any contents.
  21730. if (n.tag === "root" && n.children.length) {
  21731. res.push(hardline$13);
  21732. }
  21733. return concat$14(res);
  21734. }
  21735. var clean$11 = function clean(ast, newObj) {
  21736. delete newObj.start;
  21737. delete newObj.end;
  21738. delete newObj.contentStart;
  21739. delete newObj.contentEnd;
  21740. };
  21741. var printerVue = {
  21742. print: genericPrint$7,
  21743. embed: embed_1$6,
  21744. massageAstNode: clean$11
  21745. };
  21746. // https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
  21747. var languages$6 = [{
  21748. name: "Vue",
  21749. since: "1.10.0",
  21750. parsers: ["vue"],
  21751. group: "HTML",
  21752. tmScope: "text.html.vue",
  21753. aceMode: "html",
  21754. codemirrorMode: "htmlmixed",
  21755. codemirrorMimeType: "text/html",
  21756. extensions: [".vue"],
  21757. linguistLanguageId: 146,
  21758. vscodeLanguageIds: ["vue"]
  21759. }];
  21760. var printers$6 = {
  21761. vue: printerVue
  21762. };
  21763. var languageVue = {
  21764. languages: languages$6,
  21765. printers: printers$6
  21766. };
  21767. // plugin will look for `eval("require")()` and transform to `require()` in the bundle,
  21768. // and rewrite the paths to require from the top-level.
  21769. // We need to list the parsers and getters so we can load them only when necessary.
  21770. var internalPlugins = [// JS
  21771. languageJs, {
  21772. parsers: {
  21773. // JS - Babylon
  21774. get babylon() {
  21775. return require("./parser-babylon").parsers.babylon;
  21776. },
  21777. get json() {
  21778. return require("./parser-babylon").parsers.json;
  21779. },
  21780. get json5() {
  21781. return require("./parser-babylon").parsers.json5;
  21782. },
  21783. get "json-stringify"() {
  21784. return require("./parser-babylon").parsers["json-stringify"];
  21785. },
  21786. // JS - Flow
  21787. get flow() {
  21788. return require("./parser-flow").parsers.flow;
  21789. },
  21790. // JS - TypeScript
  21791. get typescript() {
  21792. return require("./parser-typescript").parsers.typescript;
  21793. },
  21794. get "typescript-eslint"() {
  21795. return require("./parser-typescript").parsers["typescript-eslint"];
  21796. }
  21797. }
  21798. }, // CSS
  21799. languageCss, {
  21800. parsers: {
  21801. // TODO: switch these to just `postcss` and use `language` instead.
  21802. get css() {
  21803. return require("./parser-postcss").parsers.css;
  21804. },
  21805. get less() {
  21806. return require("./parser-postcss").parsers.css;
  21807. },
  21808. get scss() {
  21809. return require("./parser-postcss").parsers.css;
  21810. }
  21811. }
  21812. }, // Handlebars
  21813. languageHandlebars, {
  21814. parsers: {
  21815. get glimmer() {
  21816. return require("./parser-glimmer").parsers.glimmer;
  21817. }
  21818. }
  21819. }, // GraphQL
  21820. languageGraphql, {
  21821. parsers: {
  21822. get graphql() {
  21823. return require("./parser-graphql").parsers.graphql;
  21824. }
  21825. }
  21826. }, // Markdown
  21827. languageMarkdown, {
  21828. parsers: {
  21829. get remark() {
  21830. return require("./parser-markdown").parsers.remark;
  21831. },
  21832. // TODO: Delete this in 2.0
  21833. get markdown() {
  21834. return require("./parser-markdown").parsers.remark;
  21835. }
  21836. }
  21837. }, // HTML
  21838. languageHtml, {
  21839. parsers: {
  21840. get parse5() {
  21841. return require("./parser-parse5").parsers.parse5;
  21842. }
  21843. }
  21844. }, // Vue
  21845. languageVue, {
  21846. parsers: {
  21847. get vue() {
  21848. return require("./parser-vue").parsers.vue;
  21849. }
  21850. }
  21851. }];
  21852. var thirdParty$1 = ( thirdParty && thirdParty__default ) || thirdParty;
  21853. function loadPlugins(plugins, pluginSearchDirs) {
  21854. if (!plugins) {
  21855. plugins = [];
  21856. }
  21857. if (!pluginSearchDirs) {
  21858. pluginSearchDirs = [];
  21859. } // unless pluginSearchDirs are provided, auto-load plugins from node_modules that are parent to Prettier
  21860. if (!pluginSearchDirs.length) {
  21861. var autoLoadDir = thirdParty$1.findParentDir(thirdParty$1.findParentDir(__dirname, "prettier"), "node_modules");
  21862. if (autoLoadDir) {
  21863. pluginSearchDirs = [autoLoadDir];
  21864. }
  21865. }
  21866. var externalManualLoadPluginInfos = plugins.map(function (pluginName) {
  21867. var requirePath;
  21868. try {
  21869. // try local files
  21870. requirePath = resolve$1.sync(path.resolve(process.cwd(), pluginName));
  21871. } catch (e) {
  21872. // try node modules
  21873. requirePath = resolve$1.sync(pluginName, {
  21874. basedir: process.cwd()
  21875. });
  21876. }
  21877. return {
  21878. name: pluginName,
  21879. requirePath
  21880. };
  21881. });
  21882. var externalAutoLoadPluginInfos = pluginSearchDirs.map(function (pluginSearchDir) {
  21883. var resolvedPluginSearchDir = path.resolve(process.cwd(), pluginSearchDir);
  21884. if (!isDirectory(resolvedPluginSearchDir)) {
  21885. throw new Error(`${pluginSearchDir} does not exist or is not a directory`);
  21886. }
  21887. var nodeModulesDir = path.resolve(resolvedPluginSearchDir, "node_modules");
  21888. return findPluginsInNodeModules(nodeModulesDir).map(function (pluginName) {
  21889. return {
  21890. name: pluginName,
  21891. requirePath: resolve$1.sync(pluginName, {
  21892. basedir: resolvedPluginSearchDir
  21893. })
  21894. };
  21895. });
  21896. }).reduce(function (a, b) {
  21897. return a.concat(b);
  21898. }, []);
  21899. var externalPlugins = lodash_uniqby(externalManualLoadPluginInfos.concat(externalAutoLoadPluginInfos), "requirePath").map(function (externalPluginInfo) {
  21900. return Object.assign({
  21901. name: externalPluginInfo.name
  21902. }, require(externalPluginInfo.requirePath));
  21903. });
  21904. return internalPlugins.concat(externalPlugins);
  21905. }
  21906. function findPluginsInNodeModules(nodeModulesDir) {
  21907. var pluginPackageJsonPaths = globby.sync(["prettier-plugin-*/package.json", "@prettier/plugin-*/package.json"], {
  21908. cwd: nodeModulesDir
  21909. });
  21910. return pluginPackageJsonPaths.map(path.dirname);
  21911. }
  21912. function isDirectory(dir) {
  21913. try {
  21914. return fs.statSync(dir).isDirectory();
  21915. } catch (e) {
  21916. return false;
  21917. }
  21918. }
  21919. var loadPlugins_1 = loadPlugins;
  21920. var mimicFn = function mimicFn(to, from) {
  21921. // TODO: use `Reflect.ownKeys()` when targeting Node.js 6
  21922. var _iteratorNormalCompletion = true;
  21923. var _didIteratorError = false;
  21924. var _iteratorError = undefined;
  21925. try {
  21926. for (var _iterator = Object.getOwnPropertyNames(from).concat(Object.getOwnPropertySymbols(from))[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  21927. var prop = _step.value;
  21928. Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
  21929. }
  21930. } catch (err) {
  21931. _didIteratorError = true;
  21932. _iteratorError = err;
  21933. } finally {
  21934. try {
  21935. if (!_iteratorNormalCompletion && _iterator.return != null) {
  21936. _iterator.return();
  21937. }
  21938. } finally {
  21939. if (_didIteratorError) {
  21940. throw _iteratorError;
  21941. }
  21942. }
  21943. }
  21944. };
  21945. var mem = createCommonjsModule(function (module) {
  21946. 'use strict';
  21947. var cacheStore = new WeakMap();
  21948. var defaultCacheKey = function defaultCacheKey(x) {
  21949. if (arguments.length === 1 && (x === null || x === undefined || typeof x !== 'function' && typeof x !== 'object')) {
  21950. return x;
  21951. }
  21952. return JSON.stringify(arguments);
  21953. };
  21954. module.exports = function (fn, opts) {
  21955. opts = Object.assign({
  21956. cacheKey: defaultCacheKey,
  21957. cache: new Map()
  21958. }, opts);
  21959. var memoized = function memoized() {
  21960. var cache = cacheStore.get(memoized);
  21961. var key = opts.cacheKey.apply(null, arguments);
  21962. if (cache.has(key)) {
  21963. var c = cache.get(key);
  21964. if (typeof opts.maxAge !== 'number' || Date.now() < c.maxAge) {
  21965. return c.data;
  21966. }
  21967. }
  21968. var ret = fn.apply(null, arguments);
  21969. cache.set(key, {
  21970. data: ret,
  21971. maxAge: Date.now() + (opts.maxAge || 0)
  21972. });
  21973. return ret;
  21974. };
  21975. mimicFn(memoized, fn);
  21976. cacheStore.set(memoized, opts.cache);
  21977. return memoized;
  21978. };
  21979. module.exports.clear = function (fn) {
  21980. var cache = cacheStore.get(fn);
  21981. if (cache && typeof cache.clear === 'function') {
  21982. cache.clear();
  21983. }
  21984. };
  21985. });
  21986. var semver$3 = createCommonjsModule(function (module, exports) {
  21987. exports = module.exports = SemVer; // The debug function is excluded entirely from the minified version.
  21988. /* nomin */
  21989. var debug;
  21990. /* nomin */
  21991. if (typeof process === 'object' &&
  21992. /* nomin */
  21993. process.env &&
  21994. /* nomin */
  21995. process.env.NODE_DEBUG &&
  21996. /* nomin */
  21997. /\bsemver\b/i.test(process.env.NODE_DEBUG))
  21998. /* nomin */
  21999. debug = function debug() {
  22000. /* nomin */
  22001. var args = Array.prototype.slice.call(arguments, 0);
  22002. /* nomin */
  22003. args.unshift('SEMVER');
  22004. /* nomin */
  22005. console.log.apply(console, args);
  22006. /* nomin */
  22007. };
  22008. /* nomin */
  22009. else
  22010. /* nomin */
  22011. debug = function debug() {}; // Note: this is the semver.org version of the spec that it implements
  22012. // Not necessarily the package version of this code.
  22013. exports.SEMVER_SPEC_VERSION = '2.0.0';
  22014. var MAX_LENGTH = 256;
  22015. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; // Max safe segment length for coercion.
  22016. var MAX_SAFE_COMPONENT_LENGTH = 16; // The actual regexps go on exports.re
  22017. var re = exports.re = [];
  22018. var src = exports.src = [];
  22019. var R = 0; // The following Regular Expressions can be used for tokenizing,
  22020. // validating, and parsing SemVer version strings.
  22021. // ## Numeric Identifier
  22022. // A single `0`, or a non-zero digit followed by zero or more digits.
  22023. var NUMERICIDENTIFIER = R++;
  22024. src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
  22025. var NUMERICIDENTIFIERLOOSE = R++;
  22026. src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier
  22027. // Zero or more digits, followed by a letter or hyphen, and then zero or
  22028. // more letters, digits, or hyphens.
  22029. var NONNUMERICIDENTIFIER = R++;
  22030. src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version
  22031. // Three dot-separated numeric identifiers.
  22032. var MAINVERSION = R++;
  22033. src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')';
  22034. var MAINVERSIONLOOSE = R++;
  22035. src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier
  22036. // A numeric identifier, or a non-numeric identifier.
  22037. var PRERELEASEIDENTIFIER = R++;
  22038. src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + '|' + src[NONNUMERICIDENTIFIER] + ')';
  22039. var PRERELEASEIDENTIFIERLOOSE = R++;
  22040. src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + '|' + src[NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version
  22041. // Hyphen, followed by one or more dot-separated pre-release version
  22042. // identifiers.
  22043. var PRERELEASE = R++;
  22044. src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
  22045. var PRERELEASELOOSE = R++;
  22046. src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier
  22047. // Any combination of digits, letters, or hyphens.
  22048. var BUILDIDENTIFIER = R++;
  22049. src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata
  22050. // Plus sign, followed by one or more period-separated build metadata
  22051. // identifiers.
  22052. var BUILD = R++;
  22053. src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'; // ## Full Version String
  22054. // A main version, followed optionally by a pre-release version and
  22055. // build metadata.
  22056. // Note that the only major, minor, patch, and pre-release sections of
  22057. // the version string are capturing groups. The build metadata is not a
  22058. // capturing group, because it should not ever be used in version
  22059. // comparison.
  22060. var FULL = R++;
  22061. var FULLPLAIN = 'v?' + src[MAINVERSION] + src[PRERELEASE] + '?' + src[BUILD] + '?';
  22062. src[FULL] = '^' + FULLPLAIN + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
  22063. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
  22064. // common in the npm registry.
  22065. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + src[PRERELEASELOOSE] + '?' + src[BUILD] + '?';
  22066. var LOOSE = R++;
  22067. src[LOOSE] = '^' + LOOSEPLAIN + '$';
  22068. var GTLT = R++;
  22069. src[GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x".
  22070. // Note that "x.x" is a valid xRange identifer, meaning "any version"
  22071. // Only the first item is strictly required.
  22072. var XRANGEIDENTIFIERLOOSE = R++;
  22073. src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
  22074. var XRANGEIDENTIFIER = R++;
  22075. src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
  22076. var XRANGEPLAIN = R++;
  22077. src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:' + src[PRERELEASE] + ')?' + src[BUILD] + '?' + ')?)?';
  22078. var XRANGEPLAINLOOSE = R++;
  22079. src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:' + src[PRERELEASELOOSE] + ')?' + src[BUILD] + '?' + ')?)?';
  22080. var XRANGE = R++;
  22081. src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
  22082. var XRANGELOOSE = R++;
  22083. src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'; // Coercion.
  22084. // Extract anything that could conceivably be a part of a valid semver
  22085. var COERCE = R++;
  22086. src[COERCE] = '(?:^|[^\\d])' + '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + '(?:$|[^\\d])'; // Tilde ranges.
  22087. // Meaning is "reasonably at or greater than"
  22088. var LONETILDE = R++;
  22089. src[LONETILDE] = '(?:~>?)';
  22090. var TILDETRIM = R++;
  22091. src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
  22092. re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
  22093. var tildeTrimReplace = '$1~';
  22094. var TILDE = R++;
  22095. src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
  22096. var TILDELOOSE = R++;
  22097. src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'; // Caret ranges.
  22098. // Meaning is "at least and backwards compatible with"
  22099. var LONECARET = R++;
  22100. src[LONECARET] = '(?:\\^)';
  22101. var CARETTRIM = R++;
  22102. src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
  22103. re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
  22104. var caretTrimReplace = '$1^';
  22105. var CARET = R++;
  22106. src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
  22107. var CARETLOOSE = R++;
  22108. src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version"
  22109. var COMPARATORLOOSE = R++;
  22110. src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
  22111. var COMPARATOR = R++;
  22112. src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing
  22113. // it modifies, so that `> 1.2.3` ==> `>1.2.3`
  22114. var COMPARATORTRIM = R++;
  22115. src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'; // this one has to use the /g flag
  22116. re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
  22117. var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4`
  22118. // Note that these all use the loose form, because they'll be
  22119. // checked against either the strict or loose comparator form
  22120. // later.
  22121. var HYPHENRANGE = R++;
  22122. src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAIN] + ')' + '\\s*$';
  22123. var HYPHENRANGELOOSE = R++;
  22124. src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all.
  22125. var STAR = R++;
  22126. src[STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects.
  22127. // All are flag-free, unless they were created above with a flag.
  22128. for (var i = 0; i < R; i++) {
  22129. debug(i, src[i]);
  22130. if (!re[i]) re[i] = new RegExp(src[i]);
  22131. }
  22132. exports.parse = parse;
  22133. function parse(version, loose) {
  22134. if (version instanceof SemVer) return version;
  22135. if (typeof version !== 'string') return null;
  22136. if (version.length > MAX_LENGTH) return null;
  22137. var r = loose ? re[LOOSE] : re[FULL];
  22138. if (!r.test(version)) return null;
  22139. try {
  22140. return new SemVer(version, loose);
  22141. } catch (er) {
  22142. return null;
  22143. }
  22144. }
  22145. exports.valid = valid;
  22146. function valid(version, loose) {
  22147. var v = parse(version, loose);
  22148. return v ? v.version : null;
  22149. }
  22150. exports.clean = clean;
  22151. function clean(version, loose) {
  22152. var s = parse(version.trim().replace(/^[=v]+/, ''), loose);
  22153. return s ? s.version : null;
  22154. }
  22155. exports.SemVer = SemVer;
  22156. function SemVer(version, loose) {
  22157. if (version instanceof SemVer) {
  22158. if (version.loose === loose) return version;else version = version.version;
  22159. } else if (typeof version !== 'string') {
  22160. throw new TypeError('Invalid Version: ' + version);
  22161. }
  22162. if (version.length > MAX_LENGTH) throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters');
  22163. if (!(this instanceof SemVer)) return new SemVer(version, loose);
  22164. debug('SemVer', version, loose);
  22165. this.loose = loose;
  22166. var m = version.trim().match(loose ? re[LOOSE] : re[FULL]);
  22167. if (!m) throw new TypeError('Invalid Version: ' + version);
  22168. this.raw = version; // these are actually numbers
  22169. this.major = +m[1];
  22170. this.minor = +m[2];
  22171. this.patch = +m[3];
  22172. if (this.major > MAX_SAFE_INTEGER || this.major < 0) throw new TypeError('Invalid major version');
  22173. if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) throw new TypeError('Invalid minor version');
  22174. if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) throw new TypeError('Invalid patch version'); // numberify any prerelease numeric ids
  22175. if (!m[4]) this.prerelease = [];else this.prerelease = m[4].split('.').map(function (id) {
  22176. if (/^[0-9]+$/.test(id)) {
  22177. var num = +id;
  22178. if (num >= 0 && num < MAX_SAFE_INTEGER) return num;
  22179. }
  22180. return id;
  22181. });
  22182. this.build = m[5] ? m[5].split('.') : [];
  22183. this.format();
  22184. }
  22185. SemVer.prototype.format = function () {
  22186. this.version = this.major + '.' + this.minor + '.' + this.patch;
  22187. if (this.prerelease.length) this.version += '-' + this.prerelease.join('.');
  22188. return this.version;
  22189. };
  22190. SemVer.prototype.toString = function () {
  22191. return this.version;
  22192. };
  22193. SemVer.prototype.compare = function (other) {
  22194. debug('SemVer.compare', this.version, this.loose, other);
  22195. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose);
  22196. return this.compareMain(other) || this.comparePre(other);
  22197. };
  22198. SemVer.prototype.compareMain = function (other) {
  22199. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose);
  22200. return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
  22201. };
  22202. SemVer.prototype.comparePre = function (other) {
  22203. if (!(other instanceof SemVer)) other = new SemVer(other, this.loose); // NOT having a prerelease is > having one
  22204. if (this.prerelease.length && !other.prerelease.length) return -1;else if (!this.prerelease.length && other.prerelease.length) return 1;else if (!this.prerelease.length && !other.prerelease.length) return 0;
  22205. var i = 0;
  22206. do {
  22207. var a = this.prerelease[i];
  22208. var b = other.prerelease[i];
  22209. debug('prerelease compare', i, a, b);
  22210. if (a === undefined && b === undefined) return 0;else if (b === undefined) return 1;else if (a === undefined) return -1;else if (a === b) continue;else return compareIdentifiers(a, b);
  22211. } while (++i);
  22212. }; // preminor will bump the version up to the next minor release, and immediately
  22213. // down to pre-release. premajor and prepatch work the same way.
  22214. SemVer.prototype.inc = function (release, identifier) {
  22215. switch (release) {
  22216. case 'premajor':
  22217. this.prerelease.length = 0;
  22218. this.patch = 0;
  22219. this.minor = 0;
  22220. this.major++;
  22221. this.inc('pre', identifier);
  22222. break;
  22223. case 'preminor':
  22224. this.prerelease.length = 0;
  22225. this.patch = 0;
  22226. this.minor++;
  22227. this.inc('pre', identifier);
  22228. break;
  22229. case 'prepatch':
  22230. // If this is already a prerelease, it will bump to the next version
  22231. // drop any prereleases that might already exist, since they are not
  22232. // relevant at this point.
  22233. this.prerelease.length = 0;
  22234. this.inc('patch', identifier);
  22235. this.inc('pre', identifier);
  22236. break;
  22237. // If the input is a non-prerelease version, this acts the same as
  22238. // prepatch.
  22239. case 'prerelease':
  22240. if (this.prerelease.length === 0) this.inc('patch', identifier);
  22241. this.inc('pre', identifier);
  22242. break;
  22243. case 'major':
  22244. // If this is a pre-major version, bump up to the same major version.
  22245. // Otherwise increment major.
  22246. // 1.0.0-5 bumps to 1.0.0
  22247. // 1.1.0 bumps to 2.0.0
  22248. if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) this.major++;
  22249. this.minor = 0;
  22250. this.patch = 0;
  22251. this.prerelease = [];
  22252. break;
  22253. case 'minor':
  22254. // If this is a pre-minor version, bump up to the same minor version.
  22255. // Otherwise increment minor.
  22256. // 1.2.0-5 bumps to 1.2.0
  22257. // 1.2.1 bumps to 1.3.0
  22258. if (this.patch !== 0 || this.prerelease.length === 0) this.minor++;
  22259. this.patch = 0;
  22260. this.prerelease = [];
  22261. break;
  22262. case 'patch':
  22263. // If this is not a pre-release version, it will increment the patch.
  22264. // If it is a pre-release it will bump up to the same patch version.
  22265. // 1.2.0-5 patches to 1.2.0
  22266. // 1.2.0 patches to 1.2.1
  22267. if (this.prerelease.length === 0) this.patch++;
  22268. this.prerelease = [];
  22269. break;
  22270. // This probably shouldn't be used publicly.
  22271. // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
  22272. case 'pre':
  22273. if (this.prerelease.length === 0) this.prerelease = [0];else {
  22274. var i = this.prerelease.length;
  22275. while (--i >= 0) {
  22276. if (typeof this.prerelease[i] === 'number') {
  22277. this.prerelease[i]++;
  22278. i = -2;
  22279. }
  22280. }
  22281. if (i === -1) // didn't increment anything
  22282. this.prerelease.push(0);
  22283. }
  22284. if (identifier) {
  22285. // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
  22286. // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
  22287. if (this.prerelease[0] === identifier) {
  22288. if (isNaN(this.prerelease[1])) this.prerelease = [identifier, 0];
  22289. } else this.prerelease = [identifier, 0];
  22290. }
  22291. break;
  22292. default:
  22293. throw new Error('invalid increment argument: ' + release);
  22294. }
  22295. this.format();
  22296. this.raw = this.version;
  22297. return this;
  22298. };
  22299. exports.inc = inc;
  22300. function inc(version, release, loose, identifier) {
  22301. if (typeof loose === 'string') {
  22302. identifier = loose;
  22303. loose = undefined;
  22304. }
  22305. try {
  22306. return new SemVer(version, loose).inc(release, identifier).version;
  22307. } catch (er) {
  22308. return null;
  22309. }
  22310. }
  22311. exports.diff = diff;
  22312. function diff(version1, version2) {
  22313. if (eq(version1, version2)) {
  22314. return null;
  22315. } else {
  22316. var v1 = parse(version1);
  22317. var v2 = parse(version2);
  22318. if (v1.prerelease.length || v2.prerelease.length) {
  22319. for (var key in v1) {
  22320. if (key === 'major' || key === 'minor' || key === 'patch') {
  22321. if (v1[key] !== v2[key]) {
  22322. return 'pre' + key;
  22323. }
  22324. }
  22325. }
  22326. return 'prerelease';
  22327. }
  22328. for (var key in v1) {
  22329. if (key === 'major' || key === 'minor' || key === 'patch') {
  22330. if (v1[key] !== v2[key]) {
  22331. return key;
  22332. }
  22333. }
  22334. }
  22335. }
  22336. }
  22337. exports.compareIdentifiers = compareIdentifiers;
  22338. var numeric = /^[0-9]+$/;
  22339. function compareIdentifiers(a, b) {
  22340. var anum = numeric.test(a);
  22341. var bnum = numeric.test(b);
  22342. if (anum && bnum) {
  22343. a = +a;
  22344. b = +b;
  22345. }
  22346. return anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : a > b ? 1 : 0;
  22347. }
  22348. exports.rcompareIdentifiers = rcompareIdentifiers;
  22349. function rcompareIdentifiers(a, b) {
  22350. return compareIdentifiers(b, a);
  22351. }
  22352. exports.major = major;
  22353. function major(a, loose) {
  22354. return new SemVer(a, loose).major;
  22355. }
  22356. exports.minor = minor;
  22357. function minor(a, loose) {
  22358. return new SemVer(a, loose).minor;
  22359. }
  22360. exports.patch = patch;
  22361. function patch(a, loose) {
  22362. return new SemVer(a, loose).patch;
  22363. }
  22364. exports.compare = compare;
  22365. function compare(a, b, loose) {
  22366. return new SemVer(a, loose).compare(new SemVer(b, loose));
  22367. }
  22368. exports.compareLoose = compareLoose;
  22369. function compareLoose(a, b) {
  22370. return compare(a, b, true);
  22371. }
  22372. exports.rcompare = rcompare;
  22373. function rcompare(a, b, loose) {
  22374. return compare(b, a, loose);
  22375. }
  22376. exports.sort = sort;
  22377. function sort(list, loose) {
  22378. return list.sort(function (a, b) {
  22379. return exports.compare(a, b, loose);
  22380. });
  22381. }
  22382. exports.rsort = rsort;
  22383. function rsort(list, loose) {
  22384. return list.sort(function (a, b) {
  22385. return exports.rcompare(a, b, loose);
  22386. });
  22387. }
  22388. exports.gt = gt;
  22389. function gt(a, b, loose) {
  22390. return compare(a, b, loose) > 0;
  22391. }
  22392. exports.lt = lt;
  22393. function lt(a, b, loose) {
  22394. return compare(a, b, loose) < 0;
  22395. }
  22396. exports.eq = eq;
  22397. function eq(a, b, loose) {
  22398. return compare(a, b, loose) === 0;
  22399. }
  22400. exports.neq = neq;
  22401. function neq(a, b, loose) {
  22402. return compare(a, b, loose) !== 0;
  22403. }
  22404. exports.gte = gte;
  22405. function gte(a, b, loose) {
  22406. return compare(a, b, loose) >= 0;
  22407. }
  22408. exports.lte = lte;
  22409. function lte(a, b, loose) {
  22410. return compare(a, b, loose) <= 0;
  22411. }
  22412. exports.cmp = cmp;
  22413. function cmp(a, op, b, loose) {
  22414. var ret;
  22415. switch (op) {
  22416. case '===':
  22417. if (typeof a === 'object') a = a.version;
  22418. if (typeof b === 'object') b = b.version;
  22419. ret = a === b;
  22420. break;
  22421. case '!==':
  22422. if (typeof a === 'object') a = a.version;
  22423. if (typeof b === 'object') b = b.version;
  22424. ret = a !== b;
  22425. break;
  22426. case '':
  22427. case '=':
  22428. case '==':
  22429. ret = eq(a, b, loose);
  22430. break;
  22431. case '!=':
  22432. ret = neq(a, b, loose);
  22433. break;
  22434. case '>':
  22435. ret = gt(a, b, loose);
  22436. break;
  22437. case '>=':
  22438. ret = gte(a, b, loose);
  22439. break;
  22440. case '<':
  22441. ret = lt(a, b, loose);
  22442. break;
  22443. case '<=':
  22444. ret = lte(a, b, loose);
  22445. break;
  22446. default:
  22447. throw new TypeError('Invalid operator: ' + op);
  22448. }
  22449. return ret;
  22450. }
  22451. exports.Comparator = Comparator;
  22452. function Comparator(comp, loose) {
  22453. if (comp instanceof Comparator) {
  22454. if (comp.loose === loose) return comp;else comp = comp.value;
  22455. }
  22456. if (!(this instanceof Comparator)) return new Comparator(comp, loose);
  22457. debug('comparator', comp, loose);
  22458. this.loose = loose;
  22459. this.parse(comp);
  22460. if (this.semver === ANY) this.value = '';else this.value = this.operator + this.semver.version;
  22461. debug('comp', this);
  22462. }
  22463. var ANY = {};
  22464. Comparator.prototype.parse = function (comp) {
  22465. var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  22466. var m = comp.match(r);
  22467. if (!m) throw new TypeError('Invalid comparator: ' + comp);
  22468. this.operator = m[1];
  22469. if (this.operator === '=') this.operator = ''; // if it literally is just '>' or '' then allow anything.
  22470. if (!m[2]) this.semver = ANY;else this.semver = new SemVer(m[2], this.loose);
  22471. };
  22472. Comparator.prototype.toString = function () {
  22473. return this.value;
  22474. };
  22475. Comparator.prototype.test = function (version) {
  22476. debug('Comparator.test', version, this.loose);
  22477. if (this.semver === ANY) return true;
  22478. if (typeof version === 'string') version = new SemVer(version, this.loose);
  22479. return cmp(version, this.operator, this.semver, this.loose);
  22480. };
  22481. Comparator.prototype.intersects = function (comp, loose) {
  22482. if (!(comp instanceof Comparator)) {
  22483. throw new TypeError('a Comparator is required');
  22484. }
  22485. var rangeTmp;
  22486. if (this.operator === '') {
  22487. rangeTmp = new Range(comp.value, loose);
  22488. return satisfies(this.value, rangeTmp, loose);
  22489. } else if (comp.operator === '') {
  22490. rangeTmp = new Range(this.value, loose);
  22491. return satisfies(comp.semver, rangeTmp, loose);
  22492. }
  22493. var sameDirectionIncreasing = (this.operator === '>=' || this.operator === '>') && (comp.operator === '>=' || comp.operator === '>');
  22494. var sameDirectionDecreasing = (this.operator === '<=' || this.operator === '<') && (comp.operator === '<=' || comp.operator === '<');
  22495. var sameSemVer = this.semver.version === comp.semver.version;
  22496. var differentDirectionsInclusive = (this.operator === '>=' || this.operator === '<=') && (comp.operator === '>=' || comp.operator === '<=');
  22497. var oppositeDirectionsLessThan = cmp(this.semver, '<', comp.semver, loose) && (this.operator === '>=' || this.operator === '>') && (comp.operator === '<=' || comp.operator === '<');
  22498. var oppositeDirectionsGreaterThan = cmp(this.semver, '>', comp.semver, loose) && (this.operator === '<=' || this.operator === '<') && (comp.operator === '>=' || comp.operator === '>');
  22499. return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
  22500. };
  22501. exports.Range = Range;
  22502. function Range(range, loose) {
  22503. if (range instanceof Range) {
  22504. if (range.loose === loose) {
  22505. return range;
  22506. } else {
  22507. return new Range(range.raw, loose);
  22508. }
  22509. }
  22510. if (range instanceof Comparator) {
  22511. return new Range(range.value, loose);
  22512. }
  22513. if (!(this instanceof Range)) return new Range(range, loose);
  22514. this.loose = loose; // First, split based on boolean or ||
  22515. this.raw = range;
  22516. this.set = range.split(/\s*\|\|\s*/).map(function (range) {
  22517. return this.parseRange(range.trim());
  22518. }, this).filter(function (c) {
  22519. // throw out any that are not relevant for whatever reason
  22520. return c.length;
  22521. });
  22522. if (!this.set.length) {
  22523. throw new TypeError('Invalid SemVer Range: ' + range);
  22524. }
  22525. this.format();
  22526. }
  22527. Range.prototype.format = function () {
  22528. this.range = this.set.map(function (comps) {
  22529. return comps.join(' ').trim();
  22530. }).join('||').trim();
  22531. return this.range;
  22532. };
  22533. Range.prototype.toString = function () {
  22534. return this.range;
  22535. };
  22536. Range.prototype.parseRange = function (range) {
  22537. var loose = this.loose;
  22538. range = range.trim();
  22539. debug('range', range, loose); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
  22540. var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
  22541. range = range.replace(hr, hyphenReplace);
  22542. debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
  22543. range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
  22544. debug('comparator trim', range, re[COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3`
  22545. range = range.replace(re[TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3`
  22546. range = range.replace(re[CARETTRIM], caretTrimReplace); // normalize spaces
  22547. range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and
  22548. // ready to be split into comparators.
  22549. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
  22550. var set = range.split(' ').map(function (comp) {
  22551. return parseComparator(comp, loose);
  22552. }).join(' ').split(/\s+/);
  22553. if (this.loose) {
  22554. // in loose mode, throw out any that are not valid comparators
  22555. set = set.filter(function (comp) {
  22556. return !!comp.match(compRe);
  22557. });
  22558. }
  22559. set = set.map(function (comp) {
  22560. return new Comparator(comp, loose);
  22561. });
  22562. return set;
  22563. };
  22564. Range.prototype.intersects = function (range, loose) {
  22565. if (!(range instanceof Range)) {
  22566. throw new TypeError('a Range is required');
  22567. }
  22568. return this.set.some(function (thisComparators) {
  22569. return thisComparators.every(function (thisComparator) {
  22570. return range.set.some(function (rangeComparators) {
  22571. return rangeComparators.every(function (rangeComparator) {
  22572. return thisComparator.intersects(rangeComparator, loose);
  22573. });
  22574. });
  22575. });
  22576. });
  22577. }; // Mostly just for testing and legacy API reasons
  22578. exports.toComparators = toComparators;
  22579. function toComparators(range, loose) {
  22580. return new Range(range, loose).set.map(function (comp) {
  22581. return comp.map(function (c) {
  22582. return c.value;
  22583. }).join(' ').trim().split(' ');
  22584. });
  22585. } // comprised of xranges, tildes, stars, and gtlt's at this point.
  22586. // already replaced the hyphen ranges
  22587. // turn into a set of JUST comparators.
  22588. function parseComparator(comp, loose) {
  22589. debug('comp', comp);
  22590. comp = replaceCarets(comp, loose);
  22591. debug('caret', comp);
  22592. comp = replaceTildes(comp, loose);
  22593. debug('tildes', comp);
  22594. comp = replaceXRanges(comp, loose);
  22595. debug('xrange', comp);
  22596. comp = replaceStars(comp, loose);
  22597. debug('stars', comp);
  22598. return comp;
  22599. }
  22600. function isX(id) {
  22601. return !id || id.toLowerCase() === 'x' || id === '*';
  22602. } // ~, ~> --> * (any, kinda silly)
  22603. // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
  22604. // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
  22605. // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
  22606. // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
  22607. // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
  22608. function replaceTildes(comp, loose) {
  22609. return comp.trim().split(/\s+/).map(function (comp) {
  22610. return replaceTilde(comp, loose);
  22611. }).join(' ');
  22612. }
  22613. function replaceTilde(comp, loose) {
  22614. var r = loose ? re[TILDELOOSE] : re[TILDE];
  22615. return comp.replace(r, function (_, M, m, p, pr) {
  22616. debug('tilde', comp, _, M, m, p, pr);
  22617. var ret;
  22618. if (isX(M)) ret = '';else if (isX(m)) ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';else if (isX(p)) // ~1.2 == >=1.2.0 <1.3.0
  22619. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else if (pr) {
  22620. debug('replaceTilde pr', pr);
  22621. if (pr.charAt(0) !== '-') pr = '-' + pr;
  22622. ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  22623. } else // ~1.2.3 == >=1.2.3 <1.3.0
  22624. ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  22625. debug('tilde return', ret);
  22626. return ret;
  22627. });
  22628. } // ^ --> * (any, kinda silly)
  22629. // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
  22630. // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
  22631. // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
  22632. // ^1.2.3 --> >=1.2.3 <2.0.0
  22633. // ^1.2.0 --> >=1.2.0 <2.0.0
  22634. function replaceCarets(comp, loose) {
  22635. return comp.trim().split(/\s+/).map(function (comp) {
  22636. return replaceCaret(comp, loose);
  22637. }).join(' ');
  22638. }
  22639. function replaceCaret(comp, loose) {
  22640. debug('caret', comp, loose);
  22641. var r = loose ? re[CARETLOOSE] : re[CARET];
  22642. return comp.replace(r, function (_, M, m, p, pr) {
  22643. debug('caret', comp, _, M, m, p, pr);
  22644. var ret;
  22645. if (isX(M)) ret = '';else if (isX(m)) ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';else if (isX(p)) {
  22646. if (M === '0') ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';else ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
  22647. } else if (pr) {
  22648. debug('replaceCaret pr', pr);
  22649. if (pr.charAt(0) !== '-') pr = '-' + pr;
  22650. if (M === '0') {
  22651. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0';
  22652. } else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + (+M + 1) + '.0.0';
  22653. } else {
  22654. debug('no pr');
  22655. if (M === '0') {
  22656. if (m === '0') ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + m + '.' + (+p + 1);else ret = '>=' + M + '.' + m + '.' + p + ' <' + M + '.' + (+m + 1) + '.0';
  22657. } else ret = '>=' + M + '.' + m + '.' + p + ' <' + (+M + 1) + '.0.0';
  22658. }
  22659. debug('caret return', ret);
  22660. return ret;
  22661. });
  22662. }
  22663. function replaceXRanges(comp, loose) {
  22664. debug('replaceXRanges', comp, loose);
  22665. return comp.split(/\s+/).map(function (comp) {
  22666. return replaceXRange(comp, loose);
  22667. }).join(' ');
  22668. }
  22669. function replaceXRange(comp, loose) {
  22670. comp = comp.trim();
  22671. var r = loose ? re[XRANGELOOSE] : re[XRANGE];
  22672. return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
  22673. debug('xRange', comp, ret, gtlt, M, m, p, pr);
  22674. var xM = isX(M);
  22675. var xm = xM || isX(m);
  22676. var xp = xm || isX(p);
  22677. var anyX = xp;
  22678. if (gtlt === '=' && anyX) gtlt = '';
  22679. if (xM) {
  22680. if (gtlt === '>' || gtlt === '<') {
  22681. // nothing is allowed
  22682. ret = '<0.0.0';
  22683. } else {
  22684. // nothing is forbidden
  22685. ret = '*';
  22686. }
  22687. } else if (gtlt && anyX) {
  22688. // replace X with 0
  22689. if (xm) m = 0;
  22690. if (xp) p = 0;
  22691. if (gtlt === '>') {
  22692. // >1 => >=2.0.0
  22693. // >1.2 => >=1.3.0
  22694. // >1.2.3 => >= 1.2.4
  22695. gtlt = '>=';
  22696. if (xm) {
  22697. M = +M + 1;
  22698. m = 0;
  22699. p = 0;
  22700. } else if (xp) {
  22701. m = +m + 1;
  22702. p = 0;
  22703. }
  22704. } else if (gtlt === '<=') {
  22705. // <=0.7.x is actually <0.8.0, since any 0.7.x should
  22706. // pass. Similarly, <=7.x is actually <8.0.0, etc.
  22707. gtlt = '<';
  22708. if (xm) M = +M + 1;else m = +m + 1;
  22709. }
  22710. ret = gtlt + M + '.' + m + '.' + p;
  22711. } else if (xm) {
  22712. ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
  22713. } else if (xp) {
  22714. ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
  22715. }
  22716. debug('xRange return', ret);
  22717. return ret;
  22718. });
  22719. } // Because * is AND-ed with everything else in the comparator,
  22720. // and '' means "any version", just remove the *s entirely.
  22721. function replaceStars(comp, loose) {
  22722. debug('replaceStars', comp, loose); // Looseness is ignored here. star is always as loose as it gets!
  22723. return comp.trim().replace(re[STAR], '');
  22724. } // This function is passed to string.replace(re[HYPHENRANGE])
  22725. // M, m, patch, prerelease, build
  22726. // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
  22727. // 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
  22728. // 1.2 - 3.4 => >=1.2.0 <3.5.0
  22729. function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
  22730. if (isX(fM)) from = '';else if (isX(fm)) from = '>=' + fM + '.0.0';else if (isX(fp)) from = '>=' + fM + '.' + fm + '.0';else from = '>=' + from;
  22731. if (isX(tM)) to = '';else if (isX(tm)) to = '<' + (+tM + 1) + '.0.0';else if (isX(tp)) to = '<' + tM + '.' + (+tm + 1) + '.0';else if (tpr) to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;else to = '<=' + to;
  22732. return (from + ' ' + to).trim();
  22733. } // if ANY of the sets match ALL of its comparators, then pass
  22734. Range.prototype.test = function (version) {
  22735. if (!version) return false;
  22736. if (typeof version === 'string') version = new SemVer(version, this.loose);
  22737. for (var i = 0; i < this.set.length; i++) {
  22738. if (testSet(this.set[i], version)) return true;
  22739. }
  22740. return false;
  22741. };
  22742. function testSet(set, version) {
  22743. for (var i = 0; i < set.length; i++) {
  22744. if (!set[i].test(version)) return false;
  22745. }
  22746. if (version.prerelease.length) {
  22747. // Find the set of versions that are allowed to have prereleases
  22748. // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
  22749. // That should allow `1.2.3-pr.2` to pass.
  22750. // However, `1.2.4-alpha.notready` should NOT be allowed,
  22751. // even though it's within the range set by the comparators.
  22752. for (var i = 0; i < set.length; i++) {
  22753. debug(set[i].semver);
  22754. if (set[i].semver === ANY) continue;
  22755. if (set[i].semver.prerelease.length > 0) {
  22756. var allowed = set[i].semver;
  22757. if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) return true;
  22758. }
  22759. } // Version has a -pre, but it's not one of the ones we like.
  22760. return false;
  22761. }
  22762. return true;
  22763. }
  22764. exports.satisfies = satisfies;
  22765. function satisfies(version, range, loose) {
  22766. try {
  22767. range = new Range(range, loose);
  22768. } catch (er) {
  22769. return false;
  22770. }
  22771. return range.test(version);
  22772. }
  22773. exports.maxSatisfying = maxSatisfying;
  22774. function maxSatisfying(versions, range, loose) {
  22775. var max = null;
  22776. var maxSV = null;
  22777. try {
  22778. var rangeObj = new Range(range, loose);
  22779. } catch (er) {
  22780. return null;
  22781. }
  22782. versions.forEach(function (v) {
  22783. if (rangeObj.test(v)) {
  22784. // satisfies(v, range, loose)
  22785. if (!max || maxSV.compare(v) === -1) {
  22786. // compare(max, v, true)
  22787. max = v;
  22788. maxSV = new SemVer(max, loose);
  22789. }
  22790. }
  22791. });
  22792. return max;
  22793. }
  22794. exports.minSatisfying = minSatisfying;
  22795. function minSatisfying(versions, range, loose) {
  22796. var min = null;
  22797. var minSV = null;
  22798. try {
  22799. var rangeObj = new Range(range, loose);
  22800. } catch (er) {
  22801. return null;
  22802. }
  22803. versions.forEach(function (v) {
  22804. if (rangeObj.test(v)) {
  22805. // satisfies(v, range, loose)
  22806. if (!min || minSV.compare(v) === 1) {
  22807. // compare(min, v, true)
  22808. min = v;
  22809. minSV = new SemVer(min, loose);
  22810. }
  22811. }
  22812. });
  22813. return min;
  22814. }
  22815. exports.validRange = validRange;
  22816. function validRange(range, loose) {
  22817. try {
  22818. // Return '*' instead of '' so that truthiness works.
  22819. // This will throw if it's invalid anyway
  22820. return new Range(range, loose).range || '*';
  22821. } catch (er) {
  22822. return null;
  22823. }
  22824. } // Determine if version is less than all the versions possible in the range
  22825. exports.ltr = ltr;
  22826. function ltr(version, range, loose) {
  22827. return outside(version, range, '<', loose);
  22828. } // Determine if version is greater than all the versions possible in the range.
  22829. exports.gtr = gtr;
  22830. function gtr(version, range, loose) {
  22831. return outside(version, range, '>', loose);
  22832. }
  22833. exports.outside = outside;
  22834. function outside(version, range, hilo, loose) {
  22835. version = new SemVer(version, loose);
  22836. range = new Range(range, loose);
  22837. var gtfn, ltefn, ltfn, comp, ecomp;
  22838. switch (hilo) {
  22839. case '>':
  22840. gtfn = gt;
  22841. ltefn = lte;
  22842. ltfn = lt;
  22843. comp = '>';
  22844. ecomp = '>=';
  22845. break;
  22846. case '<':
  22847. gtfn = lt;
  22848. ltefn = gte;
  22849. ltfn = gt;
  22850. comp = '<';
  22851. ecomp = '<=';
  22852. break;
  22853. default:
  22854. throw new TypeError('Must provide a hilo val of "<" or ">"');
  22855. } // If it satisifes the range it is not outside
  22856. if (satisfies(version, range, loose)) {
  22857. return false;
  22858. } // From now on, variable terms are as if we're in "gtr" mode.
  22859. // but note that everything is flipped for the "ltr" function.
  22860. for (var i = 0; i < range.set.length; ++i) {
  22861. var comparators = range.set[i];
  22862. var high = null;
  22863. var low = null;
  22864. comparators.forEach(function (comparator) {
  22865. if (comparator.semver === ANY) {
  22866. comparator = new Comparator('>=0.0.0');
  22867. }
  22868. high = high || comparator;
  22869. low = low || comparator;
  22870. if (gtfn(comparator.semver, high.semver, loose)) {
  22871. high = comparator;
  22872. } else if (ltfn(comparator.semver, low.semver, loose)) {
  22873. low = comparator;
  22874. }
  22875. }); // If the edge version comparator has a operator then our version
  22876. // isn't outside it
  22877. if (high.operator === comp || high.operator === ecomp) {
  22878. return false;
  22879. } // If the lowest version comparator has an operator and our version
  22880. // is less than it then it isn't higher than the range
  22881. if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
  22882. return false;
  22883. } else if (low.operator === ecomp && ltfn(version, low.semver)) {
  22884. return false;
  22885. }
  22886. }
  22887. return true;
  22888. }
  22889. exports.prerelease = prerelease;
  22890. function prerelease(version, loose) {
  22891. var parsed = parse(version, loose);
  22892. return parsed && parsed.prerelease.length ? parsed.prerelease : null;
  22893. }
  22894. exports.intersects = intersects;
  22895. function intersects(r1, r2, loose) {
  22896. r1 = new Range(r1, loose);
  22897. r2 = new Range(r2, loose);
  22898. return r1.intersects(r2);
  22899. }
  22900. exports.coerce = coerce;
  22901. function coerce(version) {
  22902. if (version instanceof SemVer) return version;
  22903. if (typeof version !== 'string') return null;
  22904. var match = version.match(re[COERCE]);
  22905. if (match == null) return null;
  22906. return parse((match[1] || '0') + '.' + (match[2] || '0') + '.' + (match[3] || '0'));
  22907. }
  22908. });
  22909. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  22910. var pseudomap = PseudoMap;
  22911. function PseudoMap(set) {
  22912. if (!(this instanceof PseudoMap)) // whyyyyyyy
  22913. throw new TypeError("Constructor PseudoMap requires 'new'");
  22914. this.clear();
  22915. if (set) {
  22916. if (set instanceof PseudoMap || typeof Map === 'function' && set instanceof Map) set.forEach(function (value, key) {
  22917. this.set(key, value);
  22918. }, this);else if (Array.isArray(set)) set.forEach(function (kv) {
  22919. this.set(kv[0], kv[1]);
  22920. }, this);else throw new TypeError('invalid argument');
  22921. }
  22922. }
  22923. PseudoMap.prototype.forEach = function (fn, thisp) {
  22924. thisp = thisp || this;
  22925. Object.keys(this._data).forEach(function (k) {
  22926. if (k !== 'size') fn.call(thisp, this._data[k].value, this._data[k].key);
  22927. }, this);
  22928. };
  22929. PseudoMap.prototype.has = function (k) {
  22930. return !!find(this._data, k);
  22931. };
  22932. PseudoMap.prototype.get = function (k) {
  22933. var res = find(this._data, k);
  22934. return res && res.value;
  22935. };
  22936. PseudoMap.prototype.set = function (k, v) {
  22937. set$1(this._data, k, v);
  22938. };
  22939. PseudoMap.prototype.delete = function (k) {
  22940. var res = find(this._data, k);
  22941. if (res) {
  22942. delete this._data[res._index];
  22943. this._data.size--;
  22944. }
  22945. };
  22946. PseudoMap.prototype.clear = function () {
  22947. var data = Object.create(null);
  22948. data.size = 0;
  22949. Object.defineProperty(this, '_data', {
  22950. value: data,
  22951. enumerable: false,
  22952. configurable: true,
  22953. writable: false
  22954. });
  22955. };
  22956. Object.defineProperty(PseudoMap.prototype, 'size', {
  22957. get: function get() {
  22958. return this._data.size;
  22959. },
  22960. set: function set(n) {},
  22961. enumerable: true,
  22962. configurable: true
  22963. });
  22964. PseudoMap.prototype.values = PseudoMap.prototype.keys = PseudoMap.prototype.entries = function () {
  22965. throw new Error('iterators are not implemented in this version');
  22966. }; // Either identical, or both NaN
  22967. function same(a, b) {
  22968. return a === b || a !== a && b !== b;
  22969. }
  22970. function Entry$1(k, v, i) {
  22971. this.key = k;
  22972. this.value = v;
  22973. this._index = i;
  22974. }
  22975. function find(data, k) {
  22976. for (var i = 0, s = '_' + k, key = s; hasOwnProperty$1.call(data, key); key = s + i++) {
  22977. if (same(data[key].key, k)) return data[key];
  22978. }
  22979. }
  22980. function set$1(data, k, v) {
  22981. for (var i = 0, s = '_' + k, key = s; hasOwnProperty$1.call(data, key); key = s + i++) {
  22982. if (same(data[key].key, k)) {
  22983. data[key].value = v;
  22984. return;
  22985. }
  22986. }
  22987. data.size++;
  22988. data[key] = new Entry$1(k, v, key);
  22989. }
  22990. var map = createCommonjsModule(function (module) {
  22991. if (process.env.npm_package_name === 'pseudomap' && process.env.npm_lifecycle_script === 'test') process.env.TEST_PSEUDOMAP = 'true';
  22992. if (typeof Map === 'function' && !process.env.TEST_PSEUDOMAP) {
  22993. module.exports = Map;
  22994. } else {
  22995. module.exports = pseudomap;
  22996. }
  22997. });
  22998. var yallist = Yallist;
  22999. Yallist.Node = Node;
  23000. Yallist.create = Yallist;
  23001. function Yallist(list) {
  23002. var self = this;
  23003. if (!(self instanceof Yallist)) {
  23004. self = new Yallist();
  23005. }
  23006. self.tail = null;
  23007. self.head = null;
  23008. self.length = 0;
  23009. if (list && typeof list.forEach === 'function') {
  23010. list.forEach(function (item) {
  23011. self.push(item);
  23012. });
  23013. } else if (arguments.length > 0) {
  23014. for (var i = 0, l = arguments.length; i < l; i++) {
  23015. self.push(arguments[i]);
  23016. }
  23017. }
  23018. return self;
  23019. }
  23020. Yallist.prototype.removeNode = function (node) {
  23021. if (node.list !== this) {
  23022. throw new Error('removing node which does not belong to this list');
  23023. }
  23024. var next = node.next;
  23025. var prev = node.prev;
  23026. if (next) {
  23027. next.prev = prev;
  23028. }
  23029. if (prev) {
  23030. prev.next = next;
  23031. }
  23032. if (node === this.head) {
  23033. this.head = next;
  23034. }
  23035. if (node === this.tail) {
  23036. this.tail = prev;
  23037. }
  23038. node.list.length--;
  23039. node.next = null;
  23040. node.prev = null;
  23041. node.list = null;
  23042. };
  23043. Yallist.prototype.unshiftNode = function (node) {
  23044. if (node === this.head) {
  23045. return;
  23046. }
  23047. if (node.list) {
  23048. node.list.removeNode(node);
  23049. }
  23050. var head = this.head;
  23051. node.list = this;
  23052. node.next = head;
  23053. if (head) {
  23054. head.prev = node;
  23055. }
  23056. this.head = node;
  23057. if (!this.tail) {
  23058. this.tail = node;
  23059. }
  23060. this.length++;
  23061. };
  23062. Yallist.prototype.pushNode = function (node) {
  23063. if (node === this.tail) {
  23064. return;
  23065. }
  23066. if (node.list) {
  23067. node.list.removeNode(node);
  23068. }
  23069. var tail = this.tail;
  23070. node.list = this;
  23071. node.prev = tail;
  23072. if (tail) {
  23073. tail.next = node;
  23074. }
  23075. this.tail = node;
  23076. if (!this.head) {
  23077. this.head = node;
  23078. }
  23079. this.length++;
  23080. };
  23081. Yallist.prototype.push = function () {
  23082. for (var i = 0, l = arguments.length; i < l; i++) {
  23083. push(this, arguments[i]);
  23084. }
  23085. return this.length;
  23086. };
  23087. Yallist.prototype.unshift = function () {
  23088. for (var i = 0, l = arguments.length; i < l; i++) {
  23089. unshift(this, arguments[i]);
  23090. }
  23091. return this.length;
  23092. };
  23093. Yallist.prototype.pop = function () {
  23094. if (!this.tail) {
  23095. return undefined;
  23096. }
  23097. var res = this.tail.value;
  23098. this.tail = this.tail.prev;
  23099. if (this.tail) {
  23100. this.tail.next = null;
  23101. } else {
  23102. this.head = null;
  23103. }
  23104. this.length--;
  23105. return res;
  23106. };
  23107. Yallist.prototype.shift = function () {
  23108. if (!this.head) {
  23109. return undefined;
  23110. }
  23111. var res = this.head.value;
  23112. this.head = this.head.next;
  23113. if (this.head) {
  23114. this.head.prev = null;
  23115. } else {
  23116. this.tail = null;
  23117. }
  23118. this.length--;
  23119. return res;
  23120. };
  23121. Yallist.prototype.forEach = function (fn, thisp) {
  23122. thisp = thisp || this;
  23123. for (var walker = this.head, i = 0; walker !== null; i++) {
  23124. fn.call(thisp, walker.value, i, this);
  23125. walker = walker.next;
  23126. }
  23127. };
  23128. Yallist.prototype.forEachReverse = function (fn, thisp) {
  23129. thisp = thisp || this;
  23130. for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
  23131. fn.call(thisp, walker.value, i, this);
  23132. walker = walker.prev;
  23133. }
  23134. };
  23135. Yallist.prototype.get = function (n) {
  23136. for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
  23137. // abort out of the list early if we hit a cycle
  23138. walker = walker.next;
  23139. }
  23140. if (i === n && walker !== null) {
  23141. return walker.value;
  23142. }
  23143. };
  23144. Yallist.prototype.getReverse = function (n) {
  23145. for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
  23146. // abort out of the list early if we hit a cycle
  23147. walker = walker.prev;
  23148. }
  23149. if (i === n && walker !== null) {
  23150. return walker.value;
  23151. }
  23152. };
  23153. Yallist.prototype.map = function (fn, thisp) {
  23154. thisp = thisp || this;
  23155. var res = new Yallist();
  23156. for (var walker = this.head; walker !== null;) {
  23157. res.push(fn.call(thisp, walker.value, this));
  23158. walker = walker.next;
  23159. }
  23160. return res;
  23161. };
  23162. Yallist.prototype.mapReverse = function (fn, thisp) {
  23163. thisp = thisp || this;
  23164. var res = new Yallist();
  23165. for (var walker = this.tail; walker !== null;) {
  23166. res.push(fn.call(thisp, walker.value, this));
  23167. walker = walker.prev;
  23168. }
  23169. return res;
  23170. };
  23171. Yallist.prototype.reduce = function (fn, initial) {
  23172. var acc;
  23173. var walker = this.head;
  23174. if (arguments.length > 1) {
  23175. acc = initial;
  23176. } else if (this.head) {
  23177. walker = this.head.next;
  23178. acc = this.head.value;
  23179. } else {
  23180. throw new TypeError('Reduce of empty list with no initial value');
  23181. }
  23182. for (var i = 0; walker !== null; i++) {
  23183. acc = fn(acc, walker.value, i);
  23184. walker = walker.next;
  23185. }
  23186. return acc;
  23187. };
  23188. Yallist.prototype.reduceReverse = function (fn, initial) {
  23189. var acc;
  23190. var walker = this.tail;
  23191. if (arguments.length > 1) {
  23192. acc = initial;
  23193. } else if (this.tail) {
  23194. walker = this.tail.prev;
  23195. acc = this.tail.value;
  23196. } else {
  23197. throw new TypeError('Reduce of empty list with no initial value');
  23198. }
  23199. for (var i = this.length - 1; walker !== null; i--) {
  23200. acc = fn(acc, walker.value, i);
  23201. walker = walker.prev;
  23202. }
  23203. return acc;
  23204. };
  23205. Yallist.prototype.toArray = function () {
  23206. var arr = new Array(this.length);
  23207. for (var i = 0, walker = this.head; walker !== null; i++) {
  23208. arr[i] = walker.value;
  23209. walker = walker.next;
  23210. }
  23211. return arr;
  23212. };
  23213. Yallist.prototype.toArrayReverse = function () {
  23214. var arr = new Array(this.length);
  23215. for (var i = 0, walker = this.tail; walker !== null; i++) {
  23216. arr[i] = walker.value;
  23217. walker = walker.prev;
  23218. }
  23219. return arr;
  23220. };
  23221. Yallist.prototype.slice = function (from, to) {
  23222. to = to || this.length;
  23223. if (to < 0) {
  23224. to += this.length;
  23225. }
  23226. from = from || 0;
  23227. if (from < 0) {
  23228. from += this.length;
  23229. }
  23230. var ret = new Yallist();
  23231. if (to < from || to < 0) {
  23232. return ret;
  23233. }
  23234. if (from < 0) {
  23235. from = 0;
  23236. }
  23237. if (to > this.length) {
  23238. to = this.length;
  23239. }
  23240. for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
  23241. walker = walker.next;
  23242. }
  23243. for (; walker !== null && i < to; i++, walker = walker.next) {
  23244. ret.push(walker.value);
  23245. }
  23246. return ret;
  23247. };
  23248. Yallist.prototype.sliceReverse = function (from, to) {
  23249. to = to || this.length;
  23250. if (to < 0) {
  23251. to += this.length;
  23252. }
  23253. from = from || 0;
  23254. if (from < 0) {
  23255. from += this.length;
  23256. }
  23257. var ret = new Yallist();
  23258. if (to < from || to < 0) {
  23259. return ret;
  23260. }
  23261. if (from < 0) {
  23262. from = 0;
  23263. }
  23264. if (to > this.length) {
  23265. to = this.length;
  23266. }
  23267. for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
  23268. walker = walker.prev;
  23269. }
  23270. for (; walker !== null && i > from; i--, walker = walker.prev) {
  23271. ret.push(walker.value);
  23272. }
  23273. return ret;
  23274. };
  23275. Yallist.prototype.reverse = function () {
  23276. var head = this.head;
  23277. var tail = this.tail;
  23278. for (var walker = head; walker !== null; walker = walker.prev) {
  23279. var p = walker.prev;
  23280. walker.prev = walker.next;
  23281. walker.next = p;
  23282. }
  23283. this.head = tail;
  23284. this.tail = head;
  23285. return this;
  23286. };
  23287. function push(self, item) {
  23288. self.tail = new Node(item, self.tail, null, self);
  23289. if (!self.head) {
  23290. self.head = self.tail;
  23291. }
  23292. self.length++;
  23293. }
  23294. function unshift(self, item) {
  23295. self.head = new Node(item, null, self.head, self);
  23296. if (!self.tail) {
  23297. self.tail = self.head;
  23298. }
  23299. self.length++;
  23300. }
  23301. function Node(value, prev, next, list) {
  23302. if (!(this instanceof Node)) {
  23303. return new Node(value, prev, next, list);
  23304. }
  23305. this.list = list;
  23306. this.value = value;
  23307. if (prev) {
  23308. prev.next = this;
  23309. this.prev = prev;
  23310. } else {
  23311. this.prev = null;
  23312. }
  23313. if (next) {
  23314. next.prev = this;
  23315. this.next = next;
  23316. } else {
  23317. this.next = null;
  23318. }
  23319. }
  23320. var lruCache = LRUCache; // This will be a proper iterable 'Map' in engines that support it,
  23321. // or a fakey-fake PseudoMap in older versions.
  23322. // A linked list to keep track of recently-used-ness
  23323. // use symbols if possible, otherwise just _props
  23324. var hasSymbol = typeof Symbol === 'function';
  23325. var makeSymbol;
  23326. if (hasSymbol) {
  23327. makeSymbol = function makeSymbol(key) {
  23328. return Symbol.for(key);
  23329. };
  23330. } else {
  23331. makeSymbol = function makeSymbol(key) {
  23332. return '_' + key;
  23333. };
  23334. }
  23335. var MAX = makeSymbol('max');
  23336. var LENGTH = makeSymbol('length');
  23337. var LENGTH_CALCULATOR = makeSymbol('lengthCalculator');
  23338. var ALLOW_STALE = makeSymbol('allowStale');
  23339. var MAX_AGE = makeSymbol('maxAge');
  23340. var DISPOSE = makeSymbol('dispose');
  23341. var NO_DISPOSE_ON_SET = makeSymbol('noDisposeOnSet');
  23342. var LRU_LIST = makeSymbol('lruList');
  23343. var CACHE = makeSymbol('cache');
  23344. function naiveLength() {
  23345. return 1;
  23346. } // lruList is a yallist where the head is the youngest
  23347. // item, and the tail is the oldest. the list contains the Hit
  23348. // objects as the entries.
  23349. // Each Hit object has a reference to its Yallist.Node. This
  23350. // never changes.
  23351. //
  23352. // cache is a Map (or PseudoMap) that matches the keys to
  23353. // the Yallist.Node object.
  23354. function LRUCache(options) {
  23355. if (!(this instanceof LRUCache)) {
  23356. return new LRUCache(options);
  23357. }
  23358. if (typeof options === 'number') {
  23359. options = {
  23360. max: options
  23361. };
  23362. }
  23363. if (!options) {
  23364. options = {};
  23365. }
  23366. var max = this[MAX] = options.max; // Kind of weird to have a default max of Infinity, but oh well.
  23367. if (!max || !(typeof max === 'number') || max <= 0) {
  23368. this[MAX] = Infinity;
  23369. }
  23370. var lc = options.length || naiveLength;
  23371. if (typeof lc !== 'function') {
  23372. lc = naiveLength;
  23373. }
  23374. this[LENGTH_CALCULATOR] = lc;
  23375. this[ALLOW_STALE] = options.stale || false;
  23376. this[MAX_AGE] = options.maxAge || 0;
  23377. this[DISPOSE] = options.dispose;
  23378. this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
  23379. this.reset();
  23380. } // resize the cache when the max changes.
  23381. Object.defineProperty(LRUCache.prototype, 'max', {
  23382. set: function set(mL) {
  23383. if (!mL || !(typeof mL === 'number') || mL <= 0) {
  23384. mL = Infinity;
  23385. }
  23386. this[MAX] = mL;
  23387. trim(this);
  23388. },
  23389. get: function get() {
  23390. return this[MAX];
  23391. },
  23392. enumerable: true
  23393. });
  23394. Object.defineProperty(LRUCache.prototype, 'allowStale', {
  23395. set: function set(allowStale) {
  23396. this[ALLOW_STALE] = !!allowStale;
  23397. },
  23398. get: function get() {
  23399. return this[ALLOW_STALE];
  23400. },
  23401. enumerable: true
  23402. });
  23403. Object.defineProperty(LRUCache.prototype, 'maxAge', {
  23404. set: function set(mA) {
  23405. if (!mA || !(typeof mA === 'number') || mA < 0) {
  23406. mA = 0;
  23407. }
  23408. this[MAX_AGE] = mA;
  23409. trim(this);
  23410. },
  23411. get: function get() {
  23412. return this[MAX_AGE];
  23413. },
  23414. enumerable: true
  23415. }); // resize the cache when the lengthCalculator changes.
  23416. Object.defineProperty(LRUCache.prototype, 'lengthCalculator', {
  23417. set: function set(lC) {
  23418. if (typeof lC !== 'function') {
  23419. lC = naiveLength;
  23420. }
  23421. if (lC !== this[LENGTH_CALCULATOR]) {
  23422. this[LENGTH_CALCULATOR] = lC;
  23423. this[LENGTH] = 0;
  23424. this[LRU_LIST].forEach(function (hit) {
  23425. hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
  23426. this[LENGTH] += hit.length;
  23427. }, this);
  23428. }
  23429. trim(this);
  23430. },
  23431. get: function get() {
  23432. return this[LENGTH_CALCULATOR];
  23433. },
  23434. enumerable: true
  23435. });
  23436. Object.defineProperty(LRUCache.prototype, 'length', {
  23437. get: function get() {
  23438. return this[LENGTH];
  23439. },
  23440. enumerable: true
  23441. });
  23442. Object.defineProperty(LRUCache.prototype, 'itemCount', {
  23443. get: function get() {
  23444. return this[LRU_LIST].length;
  23445. },
  23446. enumerable: true
  23447. });
  23448. LRUCache.prototype.rforEach = function (fn, thisp) {
  23449. thisp = thisp || this;
  23450. for (var walker = this[LRU_LIST].tail; walker !== null;) {
  23451. var prev = walker.prev;
  23452. forEachStep(this, fn, walker, thisp);
  23453. walker = prev;
  23454. }
  23455. };
  23456. function forEachStep(self, fn, node, thisp) {
  23457. var hit = node.value;
  23458. if (isStale(self, hit)) {
  23459. del(self, node);
  23460. if (!self[ALLOW_STALE]) {
  23461. hit = undefined;
  23462. }
  23463. }
  23464. if (hit) {
  23465. fn.call(thisp, hit.value, hit.key, self);
  23466. }
  23467. }
  23468. LRUCache.prototype.forEach = function (fn, thisp) {
  23469. thisp = thisp || this;
  23470. for (var walker = this[LRU_LIST].head; walker !== null;) {
  23471. var next = walker.next;
  23472. forEachStep(this, fn, walker, thisp);
  23473. walker = next;
  23474. }
  23475. };
  23476. LRUCache.prototype.keys = function () {
  23477. return this[LRU_LIST].toArray().map(function (k) {
  23478. return k.key;
  23479. }, this);
  23480. };
  23481. LRUCache.prototype.values = function () {
  23482. return this[LRU_LIST].toArray().map(function (k) {
  23483. return k.value;
  23484. }, this);
  23485. };
  23486. LRUCache.prototype.reset = function () {
  23487. if (this[DISPOSE] && this[LRU_LIST] && this[LRU_LIST].length) {
  23488. this[LRU_LIST].forEach(function (hit) {
  23489. this[DISPOSE](hit.key, hit.value);
  23490. }, this);
  23491. }
  23492. this[CACHE] = new map(); // hash of items by key
  23493. this[LRU_LIST] = new yallist(); // list of items in order of use recency
  23494. this[LENGTH] = 0; // length of items in the list
  23495. };
  23496. LRUCache.prototype.dump = function () {
  23497. return this[LRU_LIST].map(function (hit) {
  23498. if (!isStale(this, hit)) {
  23499. return {
  23500. k: hit.key,
  23501. v: hit.value,
  23502. e: hit.now + (hit.maxAge || 0)
  23503. };
  23504. }
  23505. }, this).toArray().filter(function (h) {
  23506. return h;
  23507. });
  23508. };
  23509. LRUCache.prototype.dumpLru = function () {
  23510. return this[LRU_LIST];
  23511. };
  23512. LRUCache.prototype.inspect = function (n, opts) {
  23513. var str = 'LRUCache {';
  23514. var extras = false;
  23515. var as = this[ALLOW_STALE];
  23516. if (as) {
  23517. str += '\n allowStale: true';
  23518. extras = true;
  23519. }
  23520. var max = this[MAX];
  23521. if (max && max !== Infinity) {
  23522. if (extras) {
  23523. str += ',';
  23524. }
  23525. str += '\n max: ' + util.inspect(max, opts);
  23526. extras = true;
  23527. }
  23528. var maxAge = this[MAX_AGE];
  23529. if (maxAge) {
  23530. if (extras) {
  23531. str += ',';
  23532. }
  23533. str += '\n maxAge: ' + util.inspect(maxAge, opts);
  23534. extras = true;
  23535. }
  23536. var lc = this[LENGTH_CALCULATOR];
  23537. if (lc && lc !== naiveLength) {
  23538. if (extras) {
  23539. str += ',';
  23540. }
  23541. str += '\n length: ' + util.inspect(this[LENGTH], opts);
  23542. extras = true;
  23543. }
  23544. var didFirst = false;
  23545. this[LRU_LIST].forEach(function (item) {
  23546. if (didFirst) {
  23547. str += ',\n ';
  23548. } else {
  23549. if (extras) {
  23550. str += ',\n';
  23551. }
  23552. didFirst = true;
  23553. str += '\n ';
  23554. }
  23555. var key = util.inspect(item.key).split('\n').join('\n ');
  23556. var val = {
  23557. value: item.value
  23558. };
  23559. if (item.maxAge !== maxAge) {
  23560. val.maxAge = item.maxAge;
  23561. }
  23562. if (lc !== naiveLength) {
  23563. val.length = item.length;
  23564. }
  23565. if (isStale(this, item)) {
  23566. val.stale = true;
  23567. }
  23568. val = util.inspect(val, opts).split('\n').join('\n ');
  23569. str += key + ' => ' + val;
  23570. });
  23571. if (didFirst || extras) {
  23572. str += '\n';
  23573. }
  23574. str += '}';
  23575. return str;
  23576. };
  23577. LRUCache.prototype.set = function (key, value, maxAge) {
  23578. maxAge = maxAge || this[MAX_AGE];
  23579. var now = maxAge ? Date.now() : 0;
  23580. var len = this[LENGTH_CALCULATOR](value, key);
  23581. if (this[CACHE].has(key)) {
  23582. if (len > this[MAX]) {
  23583. del(this, this[CACHE].get(key));
  23584. return false;
  23585. }
  23586. var node = this[CACHE].get(key);
  23587. var item = node.value; // dispose of the old one before overwriting
  23588. // split out into 2 ifs for better coverage tracking
  23589. if (this[DISPOSE]) {
  23590. if (!this[NO_DISPOSE_ON_SET]) {
  23591. this[DISPOSE](key, item.value);
  23592. }
  23593. }
  23594. item.now = now;
  23595. item.maxAge = maxAge;
  23596. item.value = value;
  23597. this[LENGTH] += len - item.length;
  23598. item.length = len;
  23599. this.get(key);
  23600. trim(this);
  23601. return true;
  23602. }
  23603. var hit = new Entry(key, value, len, now, maxAge); // oversized objects fall out of cache automatically.
  23604. if (hit.length > this[MAX]) {
  23605. if (this[DISPOSE]) {
  23606. this[DISPOSE](key, value);
  23607. }
  23608. return false;
  23609. }
  23610. this[LENGTH] += hit.length;
  23611. this[LRU_LIST].unshift(hit);
  23612. this[CACHE].set(key, this[LRU_LIST].head);
  23613. trim(this);
  23614. return true;
  23615. };
  23616. LRUCache.prototype.has = function (key) {
  23617. if (!this[CACHE].has(key)) return false;
  23618. var hit = this[CACHE].get(key).value;
  23619. if (isStale(this, hit)) {
  23620. return false;
  23621. }
  23622. return true;
  23623. };
  23624. LRUCache.prototype.get = function (key) {
  23625. return get(this, key, true);
  23626. };
  23627. LRUCache.prototype.peek = function (key) {
  23628. return get(this, key, false);
  23629. };
  23630. LRUCache.prototype.pop = function () {
  23631. var node = this[LRU_LIST].tail;
  23632. if (!node) return null;
  23633. del(this, node);
  23634. return node.value;
  23635. };
  23636. LRUCache.prototype.del = function (key) {
  23637. del(this, this[CACHE].get(key));
  23638. };
  23639. LRUCache.prototype.load = function (arr) {
  23640. // reset the cache
  23641. this.reset();
  23642. var now = Date.now(); // A previous serialized cache has the most recent items first
  23643. for (var l = arr.length - 1; l >= 0; l--) {
  23644. var hit = arr[l];
  23645. var expiresAt = hit.e || 0;
  23646. if (expiresAt === 0) {
  23647. // the item was created without expiration in a non aged cache
  23648. this.set(hit.k, hit.v);
  23649. } else {
  23650. var maxAge = expiresAt - now; // dont add already expired items
  23651. if (maxAge > 0) {
  23652. this.set(hit.k, hit.v, maxAge);
  23653. }
  23654. }
  23655. }
  23656. };
  23657. LRUCache.prototype.prune = function () {
  23658. var self = this;
  23659. this[CACHE].forEach(function (value, key) {
  23660. get(self, key, false);
  23661. });
  23662. };
  23663. function get(self, key, doUse) {
  23664. var node = self[CACHE].get(key);
  23665. if (node) {
  23666. var hit = node.value;
  23667. if (isStale(self, hit)) {
  23668. del(self, node);
  23669. if (!self[ALLOW_STALE]) hit = undefined;
  23670. } else {
  23671. if (doUse) {
  23672. self[LRU_LIST].unshiftNode(node);
  23673. }
  23674. }
  23675. if (hit) hit = hit.value;
  23676. }
  23677. return hit;
  23678. }
  23679. function isStale(self, hit) {
  23680. if (!hit || !hit.maxAge && !self[MAX_AGE]) {
  23681. return false;
  23682. }
  23683. var stale = false;
  23684. var diff = Date.now() - hit.now;
  23685. if (hit.maxAge) {
  23686. stale = diff > hit.maxAge;
  23687. } else {
  23688. stale = self[MAX_AGE] && diff > self[MAX_AGE];
  23689. }
  23690. return stale;
  23691. }
  23692. function trim(self) {
  23693. if (self[LENGTH] > self[MAX]) {
  23694. for (var walker = self[LRU_LIST].tail; self[LENGTH] > self[MAX] && walker !== null;) {
  23695. // We know that we're about to delete this one, and also
  23696. // what the next least recently used key will be, so just
  23697. // go ahead and set it now.
  23698. var prev = walker.prev;
  23699. del(self, walker);
  23700. walker = prev;
  23701. }
  23702. }
  23703. }
  23704. function del(self, node) {
  23705. if (node) {
  23706. var hit = node.value;
  23707. if (self[DISPOSE]) {
  23708. self[DISPOSE](hit.key, hit.value);
  23709. }
  23710. self[LENGTH] -= hit.length;
  23711. self[CACHE].delete(hit.key);
  23712. self[LRU_LIST].removeNode(node);
  23713. }
  23714. } // classy, since V8 prefers predictable objects.
  23715. function Entry(key, value, length, now, maxAge) {
  23716. this.key = key;
  23717. this.value = value;
  23718. this.length = length;
  23719. this.now = now;
  23720. this.maxAge = maxAge || 0;
  23721. }
  23722. var sigmund_1 = sigmund;
  23723. function sigmund(subject, maxSessions) {
  23724. maxSessions = maxSessions || 10;
  23725. var notes = [];
  23726. var analysis = '';
  23727. var RE = RegExp;
  23728. function psychoAnalyze(subject, session) {
  23729. if (session > maxSessions) return;
  23730. if (typeof subject === 'function' || typeof subject === 'undefined') {
  23731. return;
  23732. }
  23733. if (typeof subject !== 'object' || !subject || subject instanceof RE) {
  23734. analysis += subject;
  23735. return;
  23736. }
  23737. if (notes.indexOf(subject) !== -1 || session === maxSessions) return;
  23738. notes.push(subject);
  23739. analysis += '{';
  23740. Object.keys(subject).forEach(function (issue, _, __) {
  23741. // pseudo-private values. skip those.
  23742. if (issue.charAt(0) === '_') return;
  23743. var to = typeof subject[issue];
  23744. if (to === 'function' || to === 'undefined') return;
  23745. analysis += issue;
  23746. psychoAnalyze(subject[issue], session + 1);
  23747. });
  23748. }
  23749. psychoAnalyze(subject, 0);
  23750. return analysis;
  23751. } // vim: set softtabstop=4 shiftwidth=4:
  23752. var fnmatch = createCommonjsModule(function (module, exports) {
  23753. // Based on minimatch.js by isaacs <https://npmjs.org/package/minimatch>
  23754. var platform = typeof process === "object" ? process.platform : "win32";
  23755. if (module) module.exports = minimatch;else exports.minimatch = minimatch;
  23756. minimatch.Minimatch = Minimatch;
  23757. var cache = minimatch.cache = new lruCache({
  23758. max: 100
  23759. }),
  23760. GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
  23761. var qmark = "[^/]" // * => any number of characters
  23762. ,
  23763. star = qmark + "*?" // ** when dots are allowed. Anything goes, except .. and .
  23764. // not (^ or / followed by one or two dots followed by $ or /),
  23765. // followed by anything, any number of times.
  23766. ,
  23767. twoStarDot = "(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?" // not a ^ or / followed by a dot,
  23768. // followed by anything, any number of times.
  23769. ,
  23770. twoStarNoDot = "(?:(?!(?:\\\/|^)\\.).)*?" // characters that need to be escaped in RegExp.
  23771. ,
  23772. reSpecials = charSet("().*{}+?[]^$\\!"); // "abc" -> { a:true, b:true, c:true }
  23773. function charSet(s) {
  23774. return s.split("").reduce(function (set, c) {
  23775. set[c] = true;
  23776. return set;
  23777. }, {});
  23778. } // normalizes slashes.
  23779. var slashSplit = /\/+/;
  23780. minimatch.monkeyPatch = monkeyPatch;
  23781. function monkeyPatch() {
  23782. var desc = Object.getOwnPropertyDescriptor(String.prototype, "match");
  23783. var orig = desc.value;
  23784. desc.value = function (p) {
  23785. if (p instanceof Minimatch) return p.match(this);
  23786. return orig.call(this, p);
  23787. };
  23788. Object.defineProperty(String.prototype, desc);
  23789. }
  23790. minimatch.filter = filter;
  23791. function filter(pattern, options) {
  23792. options = options || {};
  23793. return function (p, i, list) {
  23794. return minimatch(p, pattern, options);
  23795. };
  23796. }
  23797. function ext(a, b) {
  23798. a = a || {};
  23799. b = b || {};
  23800. var t = {};
  23801. Object.keys(b).forEach(function (k) {
  23802. t[k] = b[k];
  23803. });
  23804. Object.keys(a).forEach(function (k) {
  23805. t[k] = a[k];
  23806. });
  23807. return t;
  23808. }
  23809. minimatch.defaults = function (def) {
  23810. if (!def || !Object.keys(def).length) return minimatch;
  23811. var orig = minimatch;
  23812. var m = function minimatch(p, pattern, options) {
  23813. return orig.minimatch(p, pattern, ext(def, options));
  23814. };
  23815. m.Minimatch = function Minimatch(pattern, options) {
  23816. return new orig.Minimatch(pattern, ext(def, options));
  23817. };
  23818. return m;
  23819. };
  23820. Minimatch.defaults = function (def) {
  23821. if (!def || !Object.keys(def).length) return Minimatch;
  23822. return minimatch.defaults(def).Minimatch;
  23823. };
  23824. function minimatch(p, pattern, options) {
  23825. if (typeof pattern !== "string") {
  23826. throw new TypeError("glob pattern string required");
  23827. }
  23828. if (!options) options = {}; // shortcut: comments match nothing.
  23829. if (!options.nocomment && pattern.charAt(0) === "#") {
  23830. return false;
  23831. } // "" only matches ""
  23832. if (pattern.trim() === "") return p === "";
  23833. return new Minimatch(pattern, options).match(p);
  23834. }
  23835. function Minimatch(pattern, options) {
  23836. if (!(this instanceof Minimatch)) {
  23837. return new Minimatch(pattern, options, cache);
  23838. }
  23839. if (typeof pattern !== "string") {
  23840. throw new TypeError("glob pattern string required");
  23841. }
  23842. if (!options) options = {}; // windows: need to use /, not \
  23843. // On other platforms, \ is a valid (albeit bad) filename char.
  23844. if (platform === "win32") {
  23845. pattern = pattern.split("\\").join("/");
  23846. } // lru storage.
  23847. // these things aren't particularly big, but walking down the string
  23848. // and turning it into a regexp can get pretty costly.
  23849. var cacheKey = pattern + "\n" + sigmund_1(options);
  23850. var cached = minimatch.cache.get(cacheKey);
  23851. if (cached) return cached;
  23852. minimatch.cache.set(cacheKey, this);
  23853. this.options = options;
  23854. this.set = [];
  23855. this.pattern = pattern;
  23856. this.regexp = null;
  23857. this.negate = false;
  23858. this.comment = false;
  23859. this.empty = false; // make the set of regexps etc.
  23860. this.make();
  23861. }
  23862. Minimatch.prototype.make = make;
  23863. function make() {
  23864. // don't do it more than once.
  23865. if (this._made) return;
  23866. var pattern = this.pattern;
  23867. var options = this.options; // empty patterns and comments match nothing.
  23868. if (!options.nocomment && pattern.charAt(0) === "#") {
  23869. this.comment = true;
  23870. return;
  23871. }
  23872. if (!pattern) {
  23873. this.empty = true;
  23874. return;
  23875. } // step 1: figure out negation, etc.
  23876. this.parseNegate(); // step 2: expand braces
  23877. var set = this.globSet = this.braceExpand();
  23878. if (options.debug) console.error(this.pattern, set); // step 3: now we have a set, so turn each one into a series of path-portion
  23879. // matching patterns.
  23880. // These will be regexps, except in the case of "**", which is
  23881. // set to the GLOBSTAR object for globstar behavior,
  23882. // and will not contain any / characters
  23883. set = this.globParts = set.map(function (s) {
  23884. return s.split(slashSplit);
  23885. });
  23886. if (options.debug) console.error(this.pattern, set); // glob --> regexps
  23887. set = set.map(function (s, si, set) {
  23888. return s.map(this.parse, this);
  23889. }, this);
  23890. if (options.debug) console.error(this.pattern, set); // filter out everything that didn't compile properly.
  23891. set = set.filter(function (s) {
  23892. return -1 === s.indexOf(false);
  23893. });
  23894. if (options.debug) console.error(this.pattern, set);
  23895. this.set = set;
  23896. }
  23897. Minimatch.prototype.parseNegate = parseNegate;
  23898. function parseNegate() {
  23899. var pattern = this.pattern,
  23900. negate = false,
  23901. options = this.options,
  23902. negateOffset = 0;
  23903. if (options.nonegate) return;
  23904. for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === "!"; i++) {
  23905. negate = !negate;
  23906. negateOffset++;
  23907. }
  23908. if (negateOffset) this.pattern = pattern.substr(negateOffset);
  23909. this.negate = negate;
  23910. } // Brace expansion:
  23911. // a{b,c}d -> abd acd
  23912. // a{b,}c -> abc ac
  23913. // a{0..3}d -> a0d a1d a2d a3d
  23914. // a{b,c{d,e}f}g -> abg acdfg acefg
  23915. // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
  23916. //
  23917. // Invalid sets are not expanded.
  23918. // a{2..}b -> a{2..}b
  23919. // a{b}c -> a{b}c
  23920. minimatch.braceExpand = function (pattern, options) {
  23921. return new Minimatch(pattern, options).braceExpand();
  23922. };
  23923. Minimatch.prototype.braceExpand = braceExpand;
  23924. function braceExpand(pattern, options) {
  23925. options = options || this.options;
  23926. pattern = typeof pattern === "undefined" ? this.pattern : pattern;
  23927. if (typeof pattern === "undefined") {
  23928. throw new Error("undefined pattern");
  23929. }
  23930. if (options.nobrace || !pattern.match(/\{.*\}/)) {
  23931. // shortcut. no need to expand.
  23932. return [pattern];
  23933. }
  23934. var escaping = false; // examples and comments refer to this crazy pattern:
  23935. // a{b,c{d,e},{f,g}h}x{y,z}
  23936. // expected:
  23937. // abxy
  23938. // abxz
  23939. // acdxy
  23940. // acdxz
  23941. // acexy
  23942. // acexz
  23943. // afhxy
  23944. // afhxz
  23945. // aghxy
  23946. // aghxz
  23947. // everything before the first \{ is just a prefix.
  23948. // So, we pluck that off, and work with the rest,
  23949. // and then prepend it to everything we find.
  23950. if (pattern.charAt(0) !== "{") {
  23951. // console.error(pattern)
  23952. var prefix = null;
  23953. for (var i = 0, l = pattern.length; i < l; i++) {
  23954. var c = pattern.charAt(i); // console.error(i, c)
  23955. if (c === "\\") {
  23956. escaping = !escaping;
  23957. } else if (c === "{" && !escaping) {
  23958. prefix = pattern.substr(0, i);
  23959. break;
  23960. }
  23961. } // actually no sets, all { were escaped.
  23962. if (prefix === null) {
  23963. // console.error("no sets")
  23964. return [pattern];
  23965. }
  23966. var tail = braceExpand(pattern.substr(i), options);
  23967. return tail.map(function (t) {
  23968. return prefix + t;
  23969. });
  23970. } // now we have something like:
  23971. // {b,c{d,e},{f,g}h}x{y,z}
  23972. // walk through the set, expanding each part, until
  23973. // the set ends. then, we'll expand the suffix.
  23974. // If the set only has a single member, then'll put the {} back
  23975. // first, handle numeric sets, since they're easier
  23976. var numset = pattern.match(/^\{(-?[0-9]+)\.\.(-?[0-9]+)\}/);
  23977. if (numset) {
  23978. // console.error("numset", numset[1], numset[2])
  23979. var suf = braceExpand(pattern.substr(numset[0].length), options),
  23980. start = +numset[1],
  23981. end = +numset[2],
  23982. inc = start > end ? -1 : 1,
  23983. set = [];
  23984. for (var i = start; i != end + inc; i += inc) {
  23985. // append all the suffixes
  23986. for (var ii = 0, ll = suf.length; ii < ll; ii++) {
  23987. set.push(i + suf[ii]);
  23988. }
  23989. }
  23990. return set;
  23991. } // ok, walk through the set
  23992. // We hope, somewhat optimistically, that there
  23993. // will be a } at the end.
  23994. // If the closing brace isn't found, then the pattern is
  23995. // interpreted as braceExpand("\\" + pattern) so that
  23996. // the leading \{ will be interpreted literally.
  23997. var i = 1 // skip the \{
  23998. ,
  23999. depth = 1,
  24000. set = [],
  24001. member = "",
  24002. sawEnd = false,
  24003. escaping = false;
  24004. function addMember() {
  24005. set.push(member);
  24006. member = "";
  24007. } // console.error("Entering for")
  24008. FOR: for (i = 1, l = pattern.length; i < l; i++) {
  24009. var c = pattern.charAt(i); // console.error("", i, c)
  24010. if (escaping) {
  24011. escaping = false;
  24012. member += "\\" + c;
  24013. } else {
  24014. switch (c) {
  24015. case "\\":
  24016. escaping = true;
  24017. continue;
  24018. case "{":
  24019. depth++;
  24020. member += "{";
  24021. continue;
  24022. case "}":
  24023. depth--; // if this closes the actual set, then we're done
  24024. if (depth === 0) {
  24025. addMember(); // pluck off the close-brace
  24026. i++;
  24027. break FOR;
  24028. } else {
  24029. member += c;
  24030. continue;
  24031. }
  24032. case ",":
  24033. if (depth === 1) {
  24034. addMember();
  24035. } else {
  24036. member += c;
  24037. }
  24038. continue;
  24039. default:
  24040. member += c;
  24041. continue;
  24042. } // switch
  24043. } // else
  24044. } // for
  24045. // now we've either finished the set, and the suffix is
  24046. // pattern.substr(i), or we have *not* closed the set,
  24047. // and need to escape the leading brace
  24048. if (depth !== 0) {
  24049. // console.error("didn't close", pattern)
  24050. return braceExpand("\\" + pattern, options);
  24051. } // x{y,z} -> ["xy", "xz"]
  24052. // console.error("set", set)
  24053. // console.error("suffix", pattern.substr(i))
  24054. var suf = braceExpand(pattern.substr(i), options); // ["b", "c{d,e}","{f,g}h"] ->
  24055. // [["b"], ["cd", "ce"], ["fh", "gh"]]
  24056. var addBraces = set.length === 1; // console.error("set pre-expanded", set)
  24057. set = set.map(function (p) {
  24058. return braceExpand(p, options);
  24059. }); // console.error("set expanded", set)
  24060. // [["b"], ["cd", "ce"], ["fh", "gh"]] ->
  24061. // ["b", "cd", "ce", "fh", "gh"]
  24062. set = set.reduce(function (l, r) {
  24063. return l.concat(r);
  24064. });
  24065. if (addBraces) {
  24066. set = set.map(function (s) {
  24067. return "{" + s + "}";
  24068. });
  24069. } // now attach the suffixes.
  24070. var ret = [];
  24071. for (var i = 0, l = set.length; i < l; i++) {
  24072. for (var ii = 0, ll = suf.length; ii < ll; ii++) {
  24073. ret.push(set[i] + suf[ii]);
  24074. }
  24075. }
  24076. return ret;
  24077. } // parse a component of the expanded set.
  24078. // At this point, no pattern may contain "/" in it
  24079. // so we're going to return a 2d array, where each entry is the full
  24080. // pattern, split on '/', and then turned into a regular expression.
  24081. // A regexp is made at the end which joins each array with an
  24082. // escaped /, and another full one which joins each regexp with |.
  24083. //
  24084. // Following the lead of Bash 4.1, note that "**" only has special meaning
  24085. // when it is the *only* thing in a path portion. Otherwise, any series
  24086. // of * is equivalent to a single *. Globstar behavior is enabled by
  24087. // default, and can be disabled by setting options.noglobstar.
  24088. Minimatch.prototype.parse = parse;
  24089. var SUBPARSE = {};
  24090. function parse(pattern, isSub) {
  24091. var options = this.options; // shortcuts
  24092. if (!options.noglobstar && pattern === "**") return GLOBSTAR;
  24093. if (pattern === "") return "";
  24094. var re = "",
  24095. hasMagic = !!options.nocase,
  24096. escaping = false // ? => one single character
  24097. ,
  24098. patternListStack = [],
  24099. plType,
  24100. stateChar,
  24101. inClass = false,
  24102. reClassStart = -1,
  24103. classStart = -1 // . and .. never match anything that doesn't start with .,
  24104. // even when options.dot is set.
  24105. ,
  24106. patternStart = pattern.charAt(0) === "." ? "" // anything
  24107. // not (start or / followed by . or .. followed by / or end)
  24108. : options.dot ? "(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))" : "(?!\\.)";
  24109. function clearStateChar() {
  24110. if (stateChar) {
  24111. // we had some state-tracking character
  24112. // that wasn't consumed by this pass.
  24113. switch (stateChar) {
  24114. case "*":
  24115. re += star;
  24116. hasMagic = true;
  24117. break;
  24118. case "?":
  24119. re += qmark;
  24120. hasMagic = true;
  24121. break;
  24122. default:
  24123. re += "\\" + stateChar;
  24124. break;
  24125. }
  24126. stateChar = false;
  24127. }
  24128. }
  24129. for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
  24130. if (options.debug) {
  24131. console.error("%s\t%s %s %j", pattern, i, re, c);
  24132. } // skip over any that are escaped.
  24133. if (escaping && reSpecials[c]) {
  24134. re += "\\" + c;
  24135. escaping = false;
  24136. continue;
  24137. }
  24138. SWITCH: switch (c) {
  24139. case "/":
  24140. // completely not allowed, even escaped.
  24141. // Should already be path-split by now.
  24142. return false;
  24143. case "\\":
  24144. clearStateChar();
  24145. escaping = true;
  24146. continue;
  24147. // the various stateChar values
  24148. // for the "extglob" stuff.
  24149. case "?":
  24150. case "*":
  24151. case "+":
  24152. case "@":
  24153. case "!":
  24154. if (options.debug) {
  24155. console.error("%s\t%s %s %j <-- stateChar", pattern, i, re, c);
  24156. } // all of those are literals inside a class, except that
  24157. // the glob [!a] means [^a] in regexp
  24158. if (inClass) {
  24159. if (c === "!" && i === classStart + 1) c = "^";
  24160. re += c;
  24161. continue;
  24162. } // if we already have a stateChar, then it means
  24163. // that there was something like ** or +? in there.
  24164. // Handle the stateChar, then proceed with this one.
  24165. clearStateChar();
  24166. stateChar = c; // if extglob is disabled, then +(asdf|foo) isn't a thing.
  24167. // just clear the statechar *now*, rather than even diving into
  24168. // the patternList stuff.
  24169. if (options.noext) clearStateChar();
  24170. continue;
  24171. case "(":
  24172. if (inClass) {
  24173. re += "(";
  24174. continue;
  24175. }
  24176. if (!stateChar) {
  24177. re += "\\(";
  24178. continue;
  24179. }
  24180. plType = stateChar;
  24181. patternListStack.push({
  24182. type: plType,
  24183. start: i - 1,
  24184. reStart: re.length
  24185. }); // negation is (?:(?!js)[^/]*)
  24186. re += stateChar === "!" ? "(?:(?!" : "(?:";
  24187. stateChar = false;
  24188. continue;
  24189. case ")":
  24190. if (inClass || !patternListStack.length) {
  24191. re += "\\)";
  24192. continue;
  24193. }
  24194. hasMagic = true;
  24195. re += ")";
  24196. plType = patternListStack.pop().type; // negation is (?:(?!js)[^/]*)
  24197. // The others are (?:<pattern>)<type>
  24198. switch (plType) {
  24199. case "!":
  24200. re += "[^/]*?)";
  24201. break;
  24202. case "?":
  24203. case "+":
  24204. case "*":
  24205. re += plType;
  24206. case "@":
  24207. break;
  24208. // the default anyway
  24209. }
  24210. continue;
  24211. case "|":
  24212. if (inClass || !patternListStack.length || escaping) {
  24213. re += "\\|";
  24214. escaping = false;
  24215. continue;
  24216. }
  24217. re += "|";
  24218. continue;
  24219. // these are mostly the same in regexp and glob
  24220. case "[":
  24221. // swallow any state-tracking char before the [
  24222. clearStateChar();
  24223. if (inClass) {
  24224. re += "\\" + c;
  24225. continue;
  24226. }
  24227. inClass = true;
  24228. classStart = i;
  24229. reClassStart = re.length;
  24230. re += c;
  24231. continue;
  24232. case "]":
  24233. // a right bracket shall lose its special
  24234. // meaning and represent itself in
  24235. // a bracket expression if it occurs
  24236. // first in the list. -- POSIX.2 2.8.3.2
  24237. if (i === classStart + 1 || !inClass) {
  24238. re += "\\" + c;
  24239. escaping = false;
  24240. continue;
  24241. } // finish up the class.
  24242. hasMagic = true;
  24243. inClass = false;
  24244. re += c;
  24245. continue;
  24246. default:
  24247. // swallow any state char that wasn't consumed
  24248. clearStateChar();
  24249. if (escaping) {
  24250. // no need
  24251. escaping = false;
  24252. } else if (reSpecials[c] && !(c === "^" && inClass)) {
  24253. re += "\\";
  24254. }
  24255. re += c;
  24256. } // switch
  24257. } // for
  24258. // handle the case where we left a class open.
  24259. // "[abc" is valid, equivalent to "\[abc"
  24260. if (inClass) {
  24261. // split where the last [ was, and escape it
  24262. // this is a huge pita. We now have to re-walk
  24263. // the contents of the would-be class to re-translate
  24264. // any characters that were passed through as-is
  24265. var cs = pattern.substr(classStart + 1),
  24266. sp = this.parse(cs, SUBPARSE);
  24267. re = re.substr(0, reClassStart) + "\\[" + sp[0];
  24268. hasMagic = hasMagic || sp[1];
  24269. } // handle the case where we had a +( thing at the *end*
  24270. // of the pattern.
  24271. // each pattern list stack adds 3 chars, and we need to go through
  24272. // and escape any | chars that were passed through as-is for the regexp.
  24273. // Go through and escape them, taking care not to double-escape any
  24274. // | chars that were already escaped.
  24275. var pl;
  24276. while (pl = patternListStack.pop()) {
  24277. var tail = re.slice(pl.reStart + 3); // maybe some even number of \, then maybe 1 \, followed by a |
  24278. tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) {
  24279. if (!$2) {
  24280. // the | isn't already escaped, so escape it.
  24281. $2 = "\\";
  24282. } // need to escape all those slashes *again*, without escaping the
  24283. // one that we need for escaping the | character. As it works out,
  24284. // escaping an even number of slashes can be done by simply repeating
  24285. // it exactly after itself. That's why this trick works.
  24286. //
  24287. // I am sorry that you have to see this.
  24288. return $1 + $1 + $2 + "|";
  24289. }); // console.error("tail=%j\n %s", tail, tail)
  24290. var t = pl.type === "*" ? star : pl.type === "?" ? qmark : "\\" + pl.type;
  24291. hasMagic = true;
  24292. re = re.slice(0, pl.reStart) + t + "\\(" + tail;
  24293. } // handle trailing things that only matter at the very end.
  24294. clearStateChar();
  24295. if (escaping) {
  24296. // trailing \\
  24297. re += "\\\\";
  24298. } // only need to apply the nodot start if the re starts with
  24299. // something that could conceivably capture a dot
  24300. var addPatternStart = false;
  24301. switch (re.charAt(0)) {
  24302. case ".":
  24303. case "[":
  24304. case "(":
  24305. addPatternStart = true;
  24306. } // if the re is not "" at this point, then we need to make sure
  24307. // it doesn't match against an empty path part.
  24308. // Otherwise a/* will match a/, which it should not.
  24309. if (re !== "" && hasMagic) re = "(?=.)" + re;
  24310. if (addPatternStart) re = patternStart + re; // parsing just a piece of a larger pattern.
  24311. if (isSub === SUBPARSE) {
  24312. return [re, hasMagic];
  24313. } // skip the regexp for non-magical patterns
  24314. // unescape anything in it, though, so that it'll be
  24315. // an exact match against a file etc.
  24316. if (!hasMagic) {
  24317. return globUnescape(pattern);
  24318. }
  24319. var flags = options.nocase ? "i" : "",
  24320. regExp = new RegExp("^" + re + "$", flags);
  24321. regExp._glob = pattern;
  24322. regExp._src = re;
  24323. return regExp;
  24324. }
  24325. minimatch.makeRe = function (pattern, options) {
  24326. return new Minimatch(pattern, options || {}).makeRe();
  24327. };
  24328. Minimatch.prototype.makeRe = makeRe;
  24329. function makeRe() {
  24330. if (this.regexp || this.regexp === false) return this.regexp; // at this point, this.set is a 2d array of partial
  24331. // pattern strings, or "**".
  24332. //
  24333. // It's better to use .match(). This function shouldn't
  24334. // be used, really, but it's pretty convenient sometimes,
  24335. // when you just want to work with a regex.
  24336. var set = this.set;
  24337. if (!set.length) return this.regexp = false;
  24338. var options = this.options;
  24339. var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot,
  24340. flags = options.nocase ? "i" : "";
  24341. var re = set.map(function (pattern) {
  24342. return pattern.map(function (p) {
  24343. return p === GLOBSTAR ? twoStar : typeof p === "string" ? regExpEscape(p) : p._src;
  24344. }).join("\\\/");
  24345. }).join("|"); // must match entire pattern
  24346. // ending in a * or ** will make it less strict.
  24347. re = "^(?:" + re + ")$"; // can match anything, as long as it's not this.
  24348. if (this.negate) re = "^(?!" + re + ").*$";
  24349. try {
  24350. return this.regexp = new RegExp(re, flags);
  24351. } catch (ex) {
  24352. return this.regexp = false;
  24353. }
  24354. }
  24355. minimatch.match = function (list, pattern, options) {
  24356. var mm = new Minimatch(pattern, options);
  24357. list = list.filter(function (f) {
  24358. return mm.match(f);
  24359. });
  24360. if (options.nonull && !list.length) {
  24361. list.push(pattern);
  24362. }
  24363. return list;
  24364. };
  24365. Minimatch.prototype.match = match;
  24366. function match(f, partial) {
  24367. // console.error("match", f, this.pattern)
  24368. // short-circuit in the case of busted things.
  24369. // comments, etc.
  24370. if (this.comment) return false;
  24371. if (this.empty) return f === "";
  24372. if (f === "/" && partial) return true;
  24373. var options = this.options; // windows: need to use /, not \
  24374. // On other platforms, \ is a valid (albeit bad) filename char.
  24375. if (platform === "win32") {
  24376. f = f.split("\\").join("/");
  24377. } // treat the test path as a set of pathparts.
  24378. f = f.split(slashSplit);
  24379. if (options.debug) {
  24380. console.error(this.pattern, "split", f);
  24381. } // just ONE of the pattern sets in this.set needs to match
  24382. // in order for it to be valid. If negating, then just one
  24383. // match means that we have failed.
  24384. // Either way, return on the first hit.
  24385. var set = this.set; // console.error(this.pattern, "set", set)
  24386. for (var i = 0, l = set.length; i < l; i++) {
  24387. var pattern = set[i];
  24388. var hit = this.matchOne(f, pattern, partial);
  24389. if (hit) {
  24390. if (options.flipNegate) return true;
  24391. return !this.negate;
  24392. }
  24393. } // didn't get any hits. this is success if it's a negative
  24394. // pattern, failure otherwise.
  24395. if (options.flipNegate) return false;
  24396. return this.negate;
  24397. } // set partial to true to test if, for example,
  24398. // "/a/b" matches the start of "/*/b/*/d"
  24399. // Partial means, if you run out of file before you run
  24400. // out of pattern, then that's fine, as long as all
  24401. // the parts match.
  24402. Minimatch.prototype.matchOne = function (file, pattern, partial) {
  24403. var options = this.options;
  24404. if (options.debug) {
  24405. console.error("matchOne", {
  24406. "this": this,
  24407. file: file,
  24408. pattern: pattern
  24409. });
  24410. }
  24411. if (options.matchBase && pattern.length === 1) {
  24412. file = path.basename(file.join("/")).split("/");
  24413. }
  24414. if (options.debug) {
  24415. console.error("matchOne", file.length, pattern.length);
  24416. }
  24417. for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
  24418. if (options.debug) {
  24419. console.error("matchOne loop");
  24420. }
  24421. var p = pattern[pi],
  24422. f = file[fi];
  24423. if (options.debug) {
  24424. console.error(pattern, p, f);
  24425. } // should be impossible.
  24426. // some invalid regexp stuff in the set.
  24427. if (p === false) return false;
  24428. if (p === GLOBSTAR) {
  24429. if (options.debug) console.error('GLOBSTAR', [pattern, p, f]); // "**"
  24430. // a/**/b/**/c would match the following:
  24431. // a/b/x/y/z/c
  24432. // a/x/y/z/b/c
  24433. // a/b/x/b/x/c
  24434. // a/b/c
  24435. // To do this, take the rest of the pattern after
  24436. // the **, and see if it would match the file remainder.
  24437. // If so, return success.
  24438. // If not, the ** "swallows" a segment, and try again.
  24439. // This is recursively awful.
  24440. //
  24441. // a/**/b/**/c matching a/b/x/y/z/c
  24442. // - a matches a
  24443. // - doublestar
  24444. // - matchOne(b/x/y/z/c, b/**/c)
  24445. // - b matches b
  24446. // - doublestar
  24447. // - matchOne(x/y/z/c, c) -> no
  24448. // - matchOne(y/z/c, c) -> no
  24449. // - matchOne(z/c, c) -> no
  24450. // - matchOne(c, c) yes, hit
  24451. var fr = fi,
  24452. pr = pi + 1;
  24453. if (pr === pl) {
  24454. if (options.debug) console.error('** at the end'); // a ** at the end will just swallow the rest.
  24455. // We have found a match.
  24456. // however, it will not swallow /.x, unless
  24457. // options.dot is set.
  24458. // . and .. are *never* matched by **, for explosively
  24459. // exponential reasons.
  24460. for (; fi < fl; fi++) {
  24461. if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".") return false;
  24462. }
  24463. return true;
  24464. } // ok, let's see if we can swallow whatever we can.
  24465. WHILE: while (fr < fl) {
  24466. var swallowee = file[fr];
  24467. if (options.debug) {
  24468. console.error('\nglobstar while', file, fr, pattern, pr, swallowee);
  24469. } // XXX remove this slice. Just pass the start index.
  24470. if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
  24471. if (options.debug) console.error('globstar found match!', fr, fl, swallowee); // found a match.
  24472. return true;
  24473. } else {
  24474. // can't swallow "." or ".." ever.
  24475. // can only swallow ".foo" when explicitly asked.
  24476. if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
  24477. if (options.debug) console.error("dot detected!", file, fr, pattern, pr);
  24478. break WHILE;
  24479. } // ** swallows a segment, and continue.
  24480. if (options.debug) console.error('globstar swallow a segment, and continue');
  24481. fr++;
  24482. }
  24483. } // no match was found.
  24484. // However, in partial mode, we can't say this is necessarily over.
  24485. // If there's more *pattern* left, then
  24486. if (partial) {
  24487. // ran out of file
  24488. // console.error("\n>>> no match, partial?", file, fr, pattern, pr)
  24489. if (fr === fl) return true;
  24490. }
  24491. return false;
  24492. } // something other than **
  24493. // non-magic patterns just have to match exactly
  24494. // patterns with magic have been turned into regexps.
  24495. var hit;
  24496. if (typeof p === "string") {
  24497. if (options.nocase) {
  24498. hit = f.toLowerCase() === p.toLowerCase();
  24499. } else {
  24500. hit = f === p;
  24501. }
  24502. if (options.debug) {
  24503. console.error("string match", p, f, hit);
  24504. }
  24505. } else {
  24506. hit = f.match(p);
  24507. if (options.debug) {
  24508. console.error("pattern match", p, f, hit);
  24509. }
  24510. }
  24511. if (!hit) return false;
  24512. } // Note: ending in / means that we'll get a final ""
  24513. // at the end of the pattern. This can only match a
  24514. // corresponding "" at the end of the file.
  24515. // If the file ends in /, then it can only match a
  24516. // a pattern that ends in /, unless the pattern just
  24517. // doesn't have any more for it. But, a/b/ should *not*
  24518. // match "a/b/*", even though "" matches against the
  24519. // [^/]*? pattern, except in partial mode, where it might
  24520. // simply not be reached yet.
  24521. // However, a/b/ should still satisfy a/*
  24522. // now either we fell off the end of the pattern, or we're done.
  24523. if (fi === fl && pi === pl) {
  24524. // ran out of pattern and filename at the same time.
  24525. // an exact hit!
  24526. return true;
  24527. } else if (fi === fl) {
  24528. // ran out of file, but still had pattern left.
  24529. // this is ok if we're doing the match as part of
  24530. // a glob fs traversal.
  24531. return partial;
  24532. } else if (pi === pl) {
  24533. // ran out of pattern, still have file left.
  24534. // this is only acceptable if we're on the very last
  24535. // empty segment of a file with a trailing slash.
  24536. // a/* should match a/b/
  24537. var emptyFileEnd = fi === fl - 1 && file[fi] === "";
  24538. return emptyFileEnd;
  24539. } // should be unreachable.
  24540. throw new Error("wtf?");
  24541. }; // replace stuff like \* with *
  24542. function globUnescape(s) {
  24543. return s.replace(/\\(.)/g, "$1");
  24544. }
  24545. function regExpEscape(s) {
  24546. return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
  24547. }
  24548. });
  24549. var ini = createCommonjsModule(function (module, exports) {
  24550. "use strict"; // Based on iniparser by shockie <https://npmjs.org/package/iniparser>
  24551. var __awaiter = commonjsGlobal && commonjsGlobal.__awaiter || function (thisArg, _arguments, P, generator) {
  24552. return new (P || (P = Promise))(function (resolve, reject) {
  24553. function fulfilled(value) {
  24554. try {
  24555. step(generator.next(value));
  24556. } catch (e) {
  24557. reject(e);
  24558. }
  24559. }
  24560. function rejected(value) {
  24561. try {
  24562. step(generator["throw"](value));
  24563. } catch (e) {
  24564. reject(e);
  24565. }
  24566. }
  24567. function step(result) {
  24568. result.done ? resolve(result.value) : new P(function (resolve) {
  24569. resolve(result.value);
  24570. }).then(fulfilled, rejected);
  24571. }
  24572. step((generator = generator.apply(thisArg, _arguments || [])).next());
  24573. });
  24574. };
  24575. var __generator = commonjsGlobal && commonjsGlobal.__generator || function (thisArg, body) {
  24576. var _ = {
  24577. label: 0,
  24578. sent: function sent() {
  24579. if (t[0] & 1) throw t[1];
  24580. return t[1];
  24581. },
  24582. trys: [],
  24583. ops: []
  24584. },
  24585. f,
  24586. y,
  24587. t,
  24588. g;
  24589. return g = {
  24590. next: verb(0),
  24591. "throw": verb(1),
  24592. "return": verb(2)
  24593. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  24594. return this;
  24595. }), g;
  24596. function verb(n) {
  24597. return function (v) {
  24598. return step([n, v]);
  24599. };
  24600. }
  24601. function step(op) {
  24602. if (f) throw new TypeError("Generator is already executing.");
  24603. while (_) {
  24604. try {
  24605. if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
  24606. if (y = 0, t) op = [0, t.value];
  24607. switch (op[0]) {
  24608. case 0:
  24609. case 1:
  24610. t = op;
  24611. break;
  24612. case 4:
  24613. _.label++;
  24614. return {
  24615. value: op[1],
  24616. done: false
  24617. };
  24618. case 5:
  24619. _.label++;
  24620. y = op[1];
  24621. op = [0];
  24622. continue;
  24623. case 7:
  24624. op = _.ops.pop();
  24625. _.trys.pop();
  24626. continue;
  24627. default:
  24628. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  24629. _ = 0;
  24630. continue;
  24631. }
  24632. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  24633. _.label = op[1];
  24634. break;
  24635. }
  24636. if (op[0] === 6 && _.label < t[1]) {
  24637. _.label = t[1];
  24638. t = op;
  24639. break;
  24640. }
  24641. if (t && _.label < t[2]) {
  24642. _.label = t[2];
  24643. _.ops.push(op);
  24644. break;
  24645. }
  24646. if (t[2]) _.ops.pop();
  24647. _.trys.pop();
  24648. continue;
  24649. }
  24650. op = body.call(thisArg, _);
  24651. } catch (e) {
  24652. op = [6, e];
  24653. y = 0;
  24654. } finally {
  24655. f = t = 0;
  24656. }
  24657. }
  24658. if (op[0] & 5) throw op[1];
  24659. return {
  24660. value: op[0] ? op[1] : void 0,
  24661. done: true
  24662. };
  24663. }
  24664. };
  24665. Object.defineProperty(exports, "__esModule", {
  24666. value: true
  24667. });
  24668. /**
  24669. * define the possible values:
  24670. * section: [section]
  24671. * param: key=value
  24672. * comment: ;this is a comment
  24673. */
  24674. var regex = {
  24675. section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
  24676. param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
  24677. comment: /^\s*[#;].*$/
  24678. };
  24679. /**
  24680. * Parses an .ini file
  24681. * @param file The location of the .ini file
  24682. */
  24683. function parse(file) {
  24684. return __awaiter(this, void 0, void 0, function () {
  24685. return __generator(this, function (_a) {
  24686. return [2
  24687. /*return*/
  24688. , new Promise(function (resolve, reject) {
  24689. fs.readFile(file, 'utf8', function (err, data) {
  24690. if (err) {
  24691. reject(err);
  24692. return;
  24693. }
  24694. resolve(parseString(data));
  24695. });
  24696. })];
  24697. });
  24698. });
  24699. }
  24700. exports.parse = parse;
  24701. function parseSync(file) {
  24702. return parseString(fs.readFileSync(file, 'utf8'));
  24703. }
  24704. exports.parseSync = parseSync;
  24705. function parseString(data) {
  24706. var sectionBody = {};
  24707. var sectionName = null;
  24708. var value = [[sectionName, sectionBody]];
  24709. var lines = data.split(/\r\n|\r|\n/);
  24710. lines.forEach(function (line) {
  24711. var match;
  24712. if (regex.comment.test(line)) {
  24713. return;
  24714. }
  24715. if (regex.param.test(line)) {
  24716. match = line.match(regex.param);
  24717. sectionBody[match[1]] = match[2];
  24718. } else if (regex.section.test(line)) {
  24719. match = line.match(regex.section);
  24720. sectionName = match[1];
  24721. sectionBody = {};
  24722. value.push([sectionName, sectionBody]);
  24723. }
  24724. });
  24725. return value;
  24726. }
  24727. exports.parseString = parseString;
  24728. });
  24729. unwrapExports(ini);
  24730. var name$1 = "editorconfig";
  24731. var version$3 = "0.15.0";
  24732. var description$1 = "EditorConfig File Locator and Interpreter for Node.js";
  24733. var keywords = ["editorconfig", "core"];
  24734. var main$1 = "index.js";
  24735. var bin$1 = {
  24736. "editorconfig": "bin/editorconfig"
  24737. };
  24738. var contributors = ["Hong Xu (topbug.net)", "Jed Mao (https://github.com/jedmao/)", "Trey Hunner (http://treyhunner.com)"];
  24739. var directories = {
  24740. "bin": "./bin",
  24741. "lib": "./lib"
  24742. };
  24743. var scripts$1 = {
  24744. "clean": "rimraf dist",
  24745. "prebuild": "npm run clean",
  24746. "build": "tsc",
  24747. "pretest": "npm run lint && npm run build && npm run copy && cmake .",
  24748. "test": "ctest .",
  24749. "pretest:ci": "npm run pretest",
  24750. "test:ci": "ctest -VV --output-on-failure .",
  24751. "lint": "npm run eclint && npm run tslint",
  24752. "eclint": "eclint check --indent_size ignore \"src/**\"",
  24753. "tslint": "tslint --project tslint.json",
  24754. "copy": "cpy package.json .npmignore LICENSE README.md CHANGELOG.md dist && cpy src/bin/* dist/bin && cpy src/lib/fnmatch*.* dist/lib",
  24755. "prepub": "npm run lint && npm run build && npm run copy",
  24756. "pub": "npm publish ./dist"
  24757. };
  24758. var repository$1 = {
  24759. "type": "git",
  24760. "url": "git://github.com/editorconfig/editorconfig-core-js.git"
  24761. };
  24762. var bugs = "https://github.com/editorconfig/editorconfig-core-js/issues";
  24763. var author$1 = "EditorConfig Team";
  24764. var license$1 = "MIT";
  24765. var dependencies$1 = {
  24766. "@types/commander": "^2.11.0",
  24767. "@types/semver": "^5.4.0",
  24768. "commander": "^2.11.0",
  24769. "lru-cache": "^4.1.1",
  24770. "semver": "^5.4.1",
  24771. "sigmund": "^1.0.1"
  24772. };
  24773. var devDependencies$1 = {
  24774. "@types/mocha": "^2.2.43",
  24775. "cpy-cli": "^1.0.1",
  24776. "eclint": "^2.4.3",
  24777. "mocha": "^4.0.1",
  24778. "rimraf": "^2.6.2",
  24779. "should": "^13.1.2",
  24780. "tslint": "^5.7.0",
  24781. "typescript": "^2.5.3"
  24782. };
  24783. var _package$2 = {
  24784. name: name$1,
  24785. version: version$3,
  24786. description: description$1,
  24787. keywords: keywords,
  24788. main: main$1,
  24789. bin: bin$1,
  24790. contributors: contributors,
  24791. directories: directories,
  24792. scripts: scripts$1,
  24793. repository: repository$1,
  24794. bugs: bugs,
  24795. author: author$1,
  24796. license: license$1,
  24797. dependencies: dependencies$1,
  24798. devDependencies: devDependencies$1
  24799. };
  24800. var _package$3 = Object.freeze({
  24801. name: name$1,
  24802. version: version$3,
  24803. description: description$1,
  24804. keywords: keywords,
  24805. main: main$1,
  24806. bin: bin$1,
  24807. contributors: contributors,
  24808. directories: directories,
  24809. scripts: scripts$1,
  24810. repository: repository$1,
  24811. bugs: bugs,
  24812. author: author$1,
  24813. license: license$1,
  24814. dependencies: dependencies$1,
  24815. devDependencies: devDependencies$1,
  24816. default: _package$2
  24817. });
  24818. var pkg = ( _package$3 && _package$2 ) || _package$3;
  24819. var editorconfig = createCommonjsModule(function (module, exports) {
  24820. "use strict";
  24821. var __awaiter = commonjsGlobal && commonjsGlobal.__awaiter || function (thisArg, _arguments, P, generator) {
  24822. return new (P || (P = Promise))(function (resolve, reject) {
  24823. function fulfilled(value) {
  24824. try {
  24825. step(generator.next(value));
  24826. } catch (e) {
  24827. reject(e);
  24828. }
  24829. }
  24830. function rejected(value) {
  24831. try {
  24832. step(generator["throw"](value));
  24833. } catch (e) {
  24834. reject(e);
  24835. }
  24836. }
  24837. function step(result) {
  24838. result.done ? resolve(result.value) : new P(function (resolve) {
  24839. resolve(result.value);
  24840. }).then(fulfilled, rejected);
  24841. }
  24842. step((generator = generator.apply(thisArg, _arguments || [])).next());
  24843. });
  24844. };
  24845. var __generator = commonjsGlobal && commonjsGlobal.__generator || function (thisArg, body) {
  24846. var _ = {
  24847. label: 0,
  24848. sent: function sent() {
  24849. if (t[0] & 1) throw t[1];
  24850. return t[1];
  24851. },
  24852. trys: [],
  24853. ops: []
  24854. },
  24855. f,
  24856. y,
  24857. t,
  24858. g;
  24859. return g = {
  24860. next: verb(0),
  24861. "throw": verb(1),
  24862. "return": verb(2)
  24863. }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
  24864. return this;
  24865. }), g;
  24866. function verb(n) {
  24867. return function (v) {
  24868. return step([n, v]);
  24869. };
  24870. }
  24871. function step(op) {
  24872. if (f) throw new TypeError("Generator is already executing.");
  24873. while (_) {
  24874. try {
  24875. if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
  24876. if (y = 0, t) op = [0, t.value];
  24877. switch (op[0]) {
  24878. case 0:
  24879. case 1:
  24880. t = op;
  24881. break;
  24882. case 4:
  24883. _.label++;
  24884. return {
  24885. value: op[1],
  24886. done: false
  24887. };
  24888. case 5:
  24889. _.label++;
  24890. y = op[1];
  24891. op = [0];
  24892. continue;
  24893. case 7:
  24894. op = _.ops.pop();
  24895. _.trys.pop();
  24896. continue;
  24897. default:
  24898. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  24899. _ = 0;
  24900. continue;
  24901. }
  24902. if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
  24903. _.label = op[1];
  24904. break;
  24905. }
  24906. if (op[0] === 6 && _.label < t[1]) {
  24907. _.label = t[1];
  24908. t = op;
  24909. break;
  24910. }
  24911. if (t && _.label < t[2]) {
  24912. _.label = t[2];
  24913. _.ops.push(op);
  24914. break;
  24915. }
  24916. if (t[2]) _.ops.pop();
  24917. _.trys.pop();
  24918. continue;
  24919. }
  24920. op = body.call(thisArg, _);
  24921. } catch (e) {
  24922. op = [6, e];
  24923. y = 0;
  24924. } finally {
  24925. f = t = 0;
  24926. }
  24927. }
  24928. if (op[0] & 5) throw op[1];
  24929. return {
  24930. value: op[0] ? op[1] : void 0,
  24931. done: true
  24932. };
  24933. }
  24934. };
  24935. Object.defineProperty(exports, "__esModule", {
  24936. value: true
  24937. });
  24938. exports.parseString = ini.parseString; // tslint:disable-next-line:no-var-requires
  24939. var knownProps = {
  24940. end_of_line: true,
  24941. indent_style: true,
  24942. indent_size: true,
  24943. insert_final_newline: true,
  24944. trim_trailing_whitespace: true,
  24945. charset: true
  24946. };
  24947. function fnmatch$$1(filepath, glob) {
  24948. var matchOptions = {
  24949. matchBase: true,
  24950. dot: true,
  24951. noext: true
  24952. };
  24953. glob = glob.replace(/\*\*/g, '{*,**/**/**}');
  24954. return fnmatch(filepath, glob, matchOptions);
  24955. }
  24956. function getConfigFileNames(filepath, options) {
  24957. var paths = [];
  24958. do {
  24959. filepath = path.dirname(filepath);
  24960. paths.push(path.join(filepath, options.config));
  24961. } while (filepath !== options.root);
  24962. return paths;
  24963. }
  24964. function processMatches(matches, version) {
  24965. // Set indent_size to 'tab' if indent_size is unspecified and
  24966. // indent_style is set to 'tab'.
  24967. if ('indent_style' in matches && matches.indent_style === 'tab' && !('indent_size' in matches) && semver$3.gte(version, '0.10.0')) {
  24968. matches.indent_size = 'tab';
  24969. } // Set tab_width to indent_size if indent_size is specified and
  24970. // tab_width is unspecified
  24971. if ('indent_size' in matches && !('tab_width' in matches) && matches.indent_size !== 'tab') {
  24972. matches.tab_width = matches.indent_size;
  24973. } // Set indent_size to tab_width if indent_size is 'tab'
  24974. if ('indent_size' in matches && 'tab_width' in matches && matches.indent_size === 'tab') {
  24975. matches.indent_size = matches.tab_width;
  24976. }
  24977. return matches;
  24978. }
  24979. function processOptions(options, filepath) {
  24980. if (options === void 0) {
  24981. options = {};
  24982. }
  24983. return {
  24984. config: options.config || '.editorconfig',
  24985. version: options.version || pkg.version,
  24986. root: path.resolve(options.root || path.parse(filepath).root)
  24987. };
  24988. }
  24989. function buildFullGlob(pathPrefix, glob) {
  24990. switch (glob.indexOf('/')) {
  24991. case -1:
  24992. glob = '**/' + glob;
  24993. break;
  24994. case 0:
  24995. glob = glob.substring(1);
  24996. break;
  24997. default:
  24998. break;
  24999. }
  25000. return path.join(pathPrefix, glob);
  25001. }
  25002. function extendProps(props, options) {
  25003. if (props === void 0) {
  25004. props = {};
  25005. }
  25006. if (options === void 0) {
  25007. options = {};
  25008. }
  25009. for (var key in options) {
  25010. if (options.hasOwnProperty(key)) {
  25011. var value = options[key];
  25012. var key2 = key.toLowerCase();
  25013. var value2 = value;
  25014. if (knownProps[key2]) {
  25015. value2 = value.toLowerCase();
  25016. }
  25017. try {
  25018. value2 = JSON.parse(value);
  25019. } catch (e) {}
  25020. if (typeof value === 'undefined' || value === null) {
  25021. // null and undefined are values specific to JSON (no special meaning
  25022. // in editorconfig) & should just be returned as regular strings.
  25023. value2 = String(value);
  25024. }
  25025. props[key2] = value2;
  25026. }
  25027. }
  25028. return props;
  25029. }
  25030. function parseFromConfigs(configs, filepath, options) {
  25031. return processMatches(configs.reverse().reduce(function (matches, file) {
  25032. var pathPrefix = path.dirname(file.name);
  25033. file.contents.forEach(function (section) {
  25034. var glob = section[0];
  25035. var options2 = section[1];
  25036. if (!glob) {
  25037. return;
  25038. }
  25039. var fullGlob = buildFullGlob(pathPrefix, glob);
  25040. if (!fnmatch$$1(filepath, fullGlob)) {
  25041. return;
  25042. }
  25043. matches = extendProps(matches, options2);
  25044. });
  25045. return matches;
  25046. }, {}), options.version);
  25047. }
  25048. function getConfigsForFiles(files) {
  25049. var configs = [];
  25050. for (var i in files) {
  25051. if (files.hasOwnProperty(i)) {
  25052. var file = files[i];
  25053. var contents = ini.parseString(file.contents);
  25054. configs.push({
  25055. name: file.name,
  25056. contents: contents
  25057. });
  25058. if ((contents[0][1].root || '').toLowerCase() === 'true') {
  25059. break;
  25060. }
  25061. }
  25062. }
  25063. return configs;
  25064. }
  25065. function readConfigFiles(filepaths) {
  25066. return __awaiter(this, void 0, void 0, function () {
  25067. return __generator(this, function (_a) {
  25068. return [2
  25069. /*return*/
  25070. , Promise.all(filepaths.map(function (name) {
  25071. return new Promise(function (resolve) {
  25072. fs.readFile(name, 'utf8', function (err, data) {
  25073. resolve({
  25074. name: name,
  25075. contents: err ? '' : data
  25076. });
  25077. });
  25078. });
  25079. }))];
  25080. });
  25081. });
  25082. }
  25083. function readConfigFilesSync(filepaths) {
  25084. var files = [];
  25085. var file;
  25086. filepaths.forEach(function (filepath) {
  25087. try {
  25088. file = fs.readFileSync(filepath, 'utf8');
  25089. } catch (e) {
  25090. file = '';
  25091. }
  25092. files.push({
  25093. name: filepath,
  25094. contents: file
  25095. });
  25096. });
  25097. return files;
  25098. }
  25099. function opts(filepath, options) {
  25100. if (options === void 0) {
  25101. options = {};
  25102. }
  25103. var resolvedFilePath = path.resolve(filepath);
  25104. return [resolvedFilePath, processOptions(options, resolvedFilePath)];
  25105. }
  25106. function parseFromFiles(filepath, files, options) {
  25107. if (options === void 0) {
  25108. options = {};
  25109. }
  25110. return __awaiter(this, void 0, void 0, function () {
  25111. var _a, resolvedFilePath, processedOptions;
  25112. return __generator(this, function (_b) {
  25113. _a = opts(filepath, options), resolvedFilePath = _a[0], processedOptions = _a[1];
  25114. return [2
  25115. /*return*/
  25116. , files.then(getConfigsForFiles).then(function (configs) {
  25117. return parseFromConfigs(configs, resolvedFilePath, processedOptions);
  25118. })];
  25119. });
  25120. });
  25121. }
  25122. exports.parseFromFiles = parseFromFiles;
  25123. function parseFromFilesSync(filepath, files, options) {
  25124. if (options === void 0) {
  25125. options = {};
  25126. }
  25127. var _a = opts(filepath, options),
  25128. resolvedFilePath = _a[0],
  25129. processedOptions = _a[1];
  25130. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  25131. }
  25132. exports.parseFromFilesSync = parseFromFilesSync;
  25133. function parse(_filepath, _options) {
  25134. if (_options === void 0) {
  25135. _options = {};
  25136. }
  25137. return __awaiter(this, void 0, void 0, function () {
  25138. var _a, resolvedFilePath, processedOptions, filepaths;
  25139. return __generator(this, function (_b) {
  25140. _a = opts(_filepath, _options), resolvedFilePath = _a[0], processedOptions = _a[1];
  25141. filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  25142. return [2
  25143. /*return*/
  25144. , readConfigFiles(filepaths).then(getConfigsForFiles).then(function (configs) {
  25145. return parseFromConfigs(configs, resolvedFilePath, processedOptions);
  25146. })];
  25147. });
  25148. });
  25149. }
  25150. exports.parse = parse;
  25151. function parseSync(_filepath, _options) {
  25152. if (_options === void 0) {
  25153. _options = {};
  25154. }
  25155. var _a = opts(_filepath, _options),
  25156. resolvedFilePath = _a[0],
  25157. processedOptions = _a[1];
  25158. var filepaths = getConfigFileNames(resolvedFilePath, processedOptions);
  25159. var files = readConfigFilesSync(filepaths);
  25160. return parseFromConfigs(getConfigsForFiles(files), resolvedFilePath, processedOptions);
  25161. }
  25162. exports.parseSync = parseSync;
  25163. });
  25164. unwrapExports(editorconfig);
  25165. var editorconfigToPrettier = editorConfigToPrettier;
  25166. function editorConfigToPrettier(editorConfig) {
  25167. if (!editorConfig || Object.keys(editorConfig).length === 0) {
  25168. return null;
  25169. }
  25170. var result = {};
  25171. if (editorConfig.indent_style) {
  25172. result.useTabs = editorConfig.indent_style === "tab";
  25173. }
  25174. if (editorConfig.indent_size === "tab") {
  25175. result.useTabs = true;
  25176. }
  25177. if (result.useTabs && editorConfig.tab_width) {
  25178. result.tabWidth = editorConfig.tab_width;
  25179. } else if (editorConfig.indent_style === "space" && editorConfig.indent_size && editorConfig.indent_size !== "tab") {
  25180. result.tabWidth = editorConfig.indent_size;
  25181. } else if (editorConfig.tab_width !== undefined) {
  25182. result.tabWidth = editorConfig.tab_width;
  25183. }
  25184. if (editorConfig.max_line_length && editorConfig.max_line_length !== "off") {
  25185. result.printWidth = editorConfig.max_line_length;
  25186. }
  25187. if (editorConfig.quote_type === "single") {
  25188. result.singleQuote = true;
  25189. } else if (editorConfig.quote_type === "double") {
  25190. result.singleQuote = false;
  25191. }
  25192. return result;
  25193. }
  25194. function markerExists(files, markers) {
  25195. return markers.some(function (marker) {
  25196. return files.some(function (file) {
  25197. return file === marker;
  25198. });
  25199. });
  25200. }
  25201. function traverseFolder(directory, levels, markers) {
  25202. var files = fs.readdirSync(directory);
  25203. if (levels === 0) {
  25204. return null;
  25205. } else if (markerExists(files, markers)) {
  25206. return directory;
  25207. } else {
  25208. return traverseFolder(path.resolve(directory, '..'), levels - 1, markers);
  25209. }
  25210. }
  25211. var findProjectRoot = function findRoot(dir, opts) {
  25212. if (!dir) throw new Error("Directory not defined");
  25213. opts = opts || {};
  25214. var levels = opts.maxDepth || findRoot.MAX_DEPTH;
  25215. var markers = opts.markers || findRoot.MARKERS;
  25216. return traverseFolder(dir, levels, markers);
  25217. };
  25218. var MAX_DEPTH = 9;
  25219. var MARKERS = ['.git', '.hg'];
  25220. findProjectRoot.MAX_DEPTH = MAX_DEPTH;
  25221. findProjectRoot.MARKERS = MARKERS;
  25222. var resolveConfigEditorconfig = createCommonjsModule(function (module) {
  25223. "use strict";
  25224. var maybeParse = function maybeParse(filePath, config, parse) {
  25225. var root = findProjectRoot(path.dirname(path.resolve(filePath)));
  25226. return filePath && parse(filePath, {
  25227. root
  25228. });
  25229. };
  25230. var editorconfigAsyncNoCache = function editorconfigAsyncNoCache(filePath, config) {
  25231. return Promise.resolve(maybeParse(filePath, config, editorconfig.parse)).then(editorconfigToPrettier);
  25232. };
  25233. var editorconfigAsyncWithCache = mem(editorconfigAsyncNoCache);
  25234. var editorconfigSyncNoCache = function editorconfigSyncNoCache(filePath, config) {
  25235. return editorconfigToPrettier(maybeParse(filePath, config, editorconfig.parseSync));
  25236. };
  25237. var editorconfigSyncWithCache = mem(editorconfigSyncNoCache);
  25238. function getLoadFunction(opts) {
  25239. if (!opts.editorconfig) {
  25240. return function () {
  25241. return null;
  25242. };
  25243. }
  25244. if (opts.sync) {
  25245. return opts.cache ? editorconfigSyncWithCache : editorconfigSyncNoCache;
  25246. }
  25247. return opts.cache ? editorconfigAsyncWithCache : editorconfigAsyncNoCache;
  25248. }
  25249. function clearCache() {
  25250. mem.clear(editorconfigSyncWithCache);
  25251. mem.clear(editorconfigAsyncWithCache);
  25252. }
  25253. module.exports = {
  25254. getLoadFunction,
  25255. clearCache
  25256. };
  25257. });
  25258. var resolveConfig_1 = createCommonjsModule(function (module) {
  25259. "use strict";
  25260. var getExplorerMemoized = mem(function (opts) {
  25261. return thirdParty$1.cosmiconfig("prettier", {
  25262. sync: opts.sync,
  25263. cache: opts.cache,
  25264. rcExtensions: true,
  25265. transform: function transform(result) {
  25266. if (result && result.config) {
  25267. delete result.config.$schema;
  25268. }
  25269. return result;
  25270. }
  25271. });
  25272. });
  25273. /** @param {{ cache: boolean, sync: boolean }} opts */
  25274. function getLoadFunction(opts) {
  25275. // Normalize opts before passing to a memoized function
  25276. opts = Object.assign({
  25277. sync: false,
  25278. cache: false
  25279. }, opts);
  25280. return getExplorerMemoized(opts).load;
  25281. }
  25282. function _resolveConfig(filePath, opts, sync) {
  25283. opts = Object.assign({
  25284. useCache: true
  25285. }, opts);
  25286. var loadOpts = {
  25287. cache: !!opts.useCache,
  25288. sync: !!sync,
  25289. editorconfig: !!opts.editorconfig
  25290. };
  25291. var load = getLoadFunction(loadOpts);
  25292. var loadEditorConfig = resolveConfigEditorconfig.getLoadFunction(loadOpts);
  25293. var arr = [load, loadEditorConfig].map(function (l) {
  25294. return l(filePath, opts.config);
  25295. });
  25296. var unwrapAndMerge = function unwrapAndMerge(arr) {
  25297. var result = arr[0];
  25298. var editorConfigured = arr[1];
  25299. var merged = Object.assign({}, editorConfigured, mergeOverrides(Object.assign({}, result), filePath));
  25300. if (!result && !editorConfigured) {
  25301. return null;
  25302. }
  25303. return merged;
  25304. };
  25305. if (loadOpts.sync) {
  25306. return unwrapAndMerge(arr);
  25307. }
  25308. return Promise.all(arr).then(unwrapAndMerge);
  25309. }
  25310. var resolveConfig = function resolveConfig(filePath, opts) {
  25311. return _resolveConfig(filePath, opts, false);
  25312. };
  25313. resolveConfig.sync = function (filePath, opts) {
  25314. return _resolveConfig(filePath, opts, true);
  25315. };
  25316. function clearCache() {
  25317. mem.clear(getExplorerMemoized);
  25318. resolveConfigEditorconfig.clearCache();
  25319. }
  25320. function resolveConfigFile(filePath) {
  25321. var load = getLoadFunction({
  25322. sync: false
  25323. });
  25324. return load(filePath).then(function (result) {
  25325. return result ? result.filepath : null;
  25326. });
  25327. }
  25328. resolveConfigFile.sync = function (filePath) {
  25329. var load = getLoadFunction({
  25330. sync: true
  25331. });
  25332. var result = load(filePath);
  25333. return result ? result.filepath : null;
  25334. };
  25335. function mergeOverrides(configResult, filePath) {
  25336. var options = Object.assign({}, configResult.config);
  25337. if (filePath && options.overrides) {
  25338. var relativeFilePath = path.relative(path.dirname(configResult.filepath), filePath);
  25339. var _iteratorNormalCompletion = true;
  25340. var _didIteratorError = false;
  25341. var _iteratorError = undefined;
  25342. try {
  25343. for (var _iterator = options.overrides[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  25344. var override = _step.value;
  25345. if (pathMatchesGlobs(relativeFilePath, override.files, override.excludeFiles)) {
  25346. Object.assign(options, override.options);
  25347. }
  25348. }
  25349. } catch (err) {
  25350. _didIteratorError = true;
  25351. _iteratorError = err;
  25352. } finally {
  25353. try {
  25354. if (!_iteratorNormalCompletion && _iterator.return != null) {
  25355. _iterator.return();
  25356. }
  25357. } finally {
  25358. if (_didIteratorError) {
  25359. throw _iteratorError;
  25360. }
  25361. }
  25362. }
  25363. }
  25364. delete options.overrides;
  25365. return options;
  25366. } // Based on eslint: https://github.com/eslint/eslint/blob/master/lib/config/config-ops.js
  25367. function pathMatchesGlobs(filePath, patterns, excludedPatterns) {
  25368. var patternList = [].concat(patterns);
  25369. var excludedPatternList = [].concat(excludedPatterns || []);
  25370. var opts = {
  25371. matchBase: true
  25372. };
  25373. return patternList.some(function (pattern) {
  25374. return minimatch_1(filePath, pattern, opts);
  25375. }) && !excludedPatternList.some(function (excludedPattern) {
  25376. return minimatch_1(filePath, excludedPattern, opts);
  25377. });
  25378. }
  25379. module.exports = {
  25380. resolveConfig,
  25381. resolveConfigFile,
  25382. clearCache
  25383. };
  25384. });
  25385. var version = require$$0.version;
  25386. var getSupportInfo = support.getSupportInfo; // Luckily `opts` is always the 2nd argument
  25387. function _withPlugins(fn) {
  25388. return function () {
  25389. var args = Array.from(arguments);
  25390. var opts = args[1] || {};
  25391. args[1] = Object.assign({}, opts, {
  25392. plugins: loadPlugins_1(opts.plugins, opts.pluginSearchDirs)
  25393. });
  25394. return fn.apply(null, args);
  25395. };
  25396. }
  25397. function withPlugins(fn) {
  25398. var resultingFn = _withPlugins(fn);
  25399. if (fn.sync) {
  25400. resultingFn.sync = _withPlugins(fn.sync);
  25401. }
  25402. return resultingFn;
  25403. }
  25404. var formatWithCursor = withPlugins(core.formatWithCursor);
  25405. var prettier$2 = {
  25406. formatWithCursor,
  25407. format(text, opts) {
  25408. return formatWithCursor(text, opts).formatted;
  25409. },
  25410. check: function check(text, opts) {
  25411. var formatted = formatWithCursor(text, opts).formatted;
  25412. return formatted === text;
  25413. },
  25414. doc,
  25415. resolveConfig: resolveConfig_1.resolveConfig,
  25416. resolveConfigFile: resolveConfig_1.resolveConfigFile,
  25417. clearConfigCache: resolveConfig_1.clearCache,
  25418. getFileInfo: withPlugins(getFileInfo_1),
  25419. getSupportInfo: withPlugins(getSupportInfo),
  25420. version,
  25421. util: utilShared,
  25422. /* istanbul ignore next */
  25423. __debug: {
  25424. parse: withPlugins(core.parse),
  25425. formatAST: withPlugins(core.formatAST),
  25426. formatDoc: withPlugins(core.formatDoc),
  25427. printToDoc: withPlugins(core.printToDoc),
  25428. printDocToString: withPlugins(core.printDocToString)
  25429. }
  25430. };
  25431. var at;
  25432. var ch;
  25433. var escapee = {
  25434. '"': '"',
  25435. '\\': '\\',
  25436. '/': '/',
  25437. b: '\b',
  25438. f: '\f',
  25439. n: '\n',
  25440. r: '\r',
  25441. t: '\t'
  25442. };
  25443. var text;
  25444. var error = function error(m) {
  25445. // Call error when something is wrong.
  25446. throw {
  25447. name: 'SyntaxError',
  25448. message: m,
  25449. at: at,
  25450. text: text
  25451. };
  25452. };
  25453. var next = function next(c) {
  25454. // If a c parameter is provided, verify that it matches the current character.
  25455. if (c && c !== ch) {
  25456. error("Expected '" + c + "' instead of '" + ch + "'");
  25457. } // Get the next character. When there are no more characters,
  25458. // return the empty string.
  25459. ch = text.charAt(at);
  25460. at += 1;
  25461. return ch;
  25462. };
  25463. var number = function number() {
  25464. // Parse a number value.
  25465. var number,
  25466. string = '';
  25467. if (ch === '-') {
  25468. string = '-';
  25469. next('-');
  25470. }
  25471. while (ch >= '0' && ch <= '9') {
  25472. string += ch;
  25473. next();
  25474. }
  25475. if (ch === '.') {
  25476. string += '.';
  25477. while (next() && ch >= '0' && ch <= '9') {
  25478. string += ch;
  25479. }
  25480. }
  25481. if (ch === 'e' || ch === 'E') {
  25482. string += ch;
  25483. next();
  25484. if (ch === '-' || ch === '+') {
  25485. string += ch;
  25486. next();
  25487. }
  25488. while (ch >= '0' && ch <= '9') {
  25489. string += ch;
  25490. next();
  25491. }
  25492. }
  25493. number = +string;
  25494. if (!isFinite(number)) {
  25495. error("Bad number");
  25496. } else {
  25497. return number;
  25498. }
  25499. };
  25500. var string = function string() {
  25501. // Parse a string value.
  25502. var hex,
  25503. i,
  25504. string = '',
  25505. uffff; // When parsing for string values, we must look for " and \ characters.
  25506. if (ch === '"') {
  25507. while (next()) {
  25508. if (ch === '"') {
  25509. next();
  25510. return string;
  25511. } else if (ch === '\\') {
  25512. next();
  25513. if (ch === 'u') {
  25514. uffff = 0;
  25515. for (i = 0; i < 4; i += 1) {
  25516. hex = parseInt(next(), 16);
  25517. if (!isFinite(hex)) {
  25518. break;
  25519. }
  25520. uffff = uffff * 16 + hex;
  25521. }
  25522. string += String.fromCharCode(uffff);
  25523. } else if (typeof escapee[ch] === 'string') {
  25524. string += escapee[ch];
  25525. } else {
  25526. break;
  25527. }
  25528. } else {
  25529. string += ch;
  25530. }
  25531. }
  25532. }
  25533. error("Bad string");
  25534. };
  25535. var white = function white() {
  25536. // Skip whitespace.
  25537. while (ch && ch <= ' ') {
  25538. next();
  25539. }
  25540. };
  25541. var word$2 = function word() {
  25542. // true, false, or null.
  25543. switch (ch) {
  25544. case 't':
  25545. next('t');
  25546. next('r');
  25547. next('u');
  25548. next('e');
  25549. return true;
  25550. case 'f':
  25551. next('f');
  25552. next('a');
  25553. next('l');
  25554. next('s');
  25555. next('e');
  25556. return false;
  25557. case 'n':
  25558. next('n');
  25559. next('u');
  25560. next('l');
  25561. next('l');
  25562. return null;
  25563. }
  25564. error("Unexpected '" + ch + "'");
  25565. };
  25566. var value;
  25567. var array$2 = function array() {
  25568. // Parse an array value.
  25569. var array = [];
  25570. if (ch === '[') {
  25571. next('[');
  25572. white();
  25573. if (ch === ']') {
  25574. next(']');
  25575. return array; // empty array
  25576. }
  25577. while (ch) {
  25578. array.push(value());
  25579. white();
  25580. if (ch === ']') {
  25581. next(']');
  25582. return array;
  25583. }
  25584. next(',');
  25585. white();
  25586. }
  25587. }
  25588. error("Bad array");
  25589. };
  25590. var object = function object() {
  25591. // Parse an object value.
  25592. var key,
  25593. object = {};
  25594. if (ch === '{') {
  25595. next('{');
  25596. white();
  25597. if (ch === '}') {
  25598. next('}');
  25599. return object; // empty object
  25600. }
  25601. while (ch) {
  25602. key = string();
  25603. white();
  25604. next(':');
  25605. if (Object.hasOwnProperty.call(object, key)) {
  25606. error('Duplicate key "' + key + '"');
  25607. }
  25608. object[key] = value();
  25609. white();
  25610. if (ch === '}') {
  25611. next('}');
  25612. return object;
  25613. }
  25614. next(',');
  25615. white();
  25616. }
  25617. }
  25618. error("Bad object");
  25619. };
  25620. value = function value() {
  25621. // Parse a JSON value. It could be an object, an array, a string, a number,
  25622. // or a word.
  25623. white();
  25624. switch (ch) {
  25625. case '{':
  25626. return object();
  25627. case '[':
  25628. return array$2();
  25629. case '"':
  25630. return string();
  25631. case '-':
  25632. return number();
  25633. default:
  25634. return ch >= '0' && ch <= '9' ? number() : word$2();
  25635. }
  25636. }; // Return the json_parse function. It will have access to all of the above
  25637. // functions and variables.
  25638. var parse$7 = function parse(source, reviver) {
  25639. var result;
  25640. text = source;
  25641. at = 0;
  25642. ch = ' ';
  25643. result = value();
  25644. white();
  25645. if (ch) {
  25646. error("Syntax error");
  25647. } // If there is a reviver function, we recursively walk the new structure,
  25648. // passing each name/value pair to the reviver function for possible
  25649. // transformation, starting with a temporary root object that holds the result
  25650. // in an empty key. If there is not a reviver function, we simply return the
  25651. // result.
  25652. return typeof reviver === 'function' ? function walk(holder, key) {
  25653. var k,
  25654. v,
  25655. value = holder[key];
  25656. if (value && typeof value === 'object') {
  25657. for (k in value) {
  25658. if (Object.prototype.hasOwnProperty.call(value, k)) {
  25659. v = walk(value, k);
  25660. if (v !== undefined) {
  25661. value[k] = v;
  25662. } else {
  25663. delete value[k];
  25664. }
  25665. }
  25666. }
  25667. }
  25668. return reviver.call(holder, key, value);
  25669. }({
  25670. '': result
  25671. }, '') : result;
  25672. };
  25673. var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  25674. var gap;
  25675. var indent$10;
  25676. var meta = {
  25677. // table of character substitutions
  25678. '\b': '\\b',
  25679. '\t': '\\t',
  25680. '\n': '\\n',
  25681. '\f': '\\f',
  25682. '\r': '\\r',
  25683. '"': '\\"',
  25684. '\\': '\\\\'
  25685. };
  25686. var rep;
  25687. function quote(string) {
  25688. // If the string contains no control characters, no quote characters, and no
  25689. // backslash characters, then we can safely slap some quotes around it.
  25690. // Otherwise we must also replace the offending characters with safe escape
  25691. // sequences.
  25692. escapable.lastIndex = 0;
  25693. return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
  25694. var c = meta[a];
  25695. return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  25696. }) + '"' : '"' + string + '"';
  25697. }
  25698. function str(key, holder) {
  25699. // Produce a string from holder[key].
  25700. var i,
  25701. // The loop counter.
  25702. k,
  25703. // The member key.
  25704. v,
  25705. // The member value.
  25706. length,
  25707. mind = gap,
  25708. partial,
  25709. value = holder[key]; // If the value has a toJSON method, call it to obtain a replacement value.
  25710. if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
  25711. value = value.toJSON(key);
  25712. } // If we were called with a replacer function, then call the replacer to
  25713. // obtain a replacement value.
  25714. if (typeof rep === 'function') {
  25715. value = rep.call(holder, key, value);
  25716. } // What happens next depends on the value's type.
  25717. switch (typeof value) {
  25718. case 'string':
  25719. return quote(value);
  25720. case 'number':
  25721. // JSON numbers must be finite. Encode non-finite numbers as null.
  25722. return isFinite(value) ? String(value) : 'null';
  25723. case 'boolean':
  25724. case 'null':
  25725. // If the value is a boolean or null, convert it to a string. Note:
  25726. // typeof null does not produce 'null'. The case is included here in
  25727. // the remote chance that this gets fixed someday.
  25728. return String(value);
  25729. case 'object':
  25730. if (!value) return 'null';
  25731. gap += indent$10;
  25732. partial = []; // Array.isArray
  25733. if (Object.prototype.toString.apply(value) === '[object Array]') {
  25734. length = value.length;
  25735. for (i = 0; i < length; i += 1) {
  25736. partial[i] = str(i, value) || 'null';
  25737. } // Join all of the elements together, separated with commas, and
  25738. // wrap them in brackets.
  25739. v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';
  25740. gap = mind;
  25741. return v;
  25742. } // If the replacer is an array, use it to select the members to be
  25743. // stringified.
  25744. if (rep && typeof rep === 'object') {
  25745. length = rep.length;
  25746. for (i = 0; i < length; i += 1) {
  25747. k = rep[i];
  25748. if (typeof k === 'string') {
  25749. v = str(k, value);
  25750. if (v) {
  25751. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  25752. }
  25753. }
  25754. }
  25755. } else {
  25756. // Otherwise, iterate through all of the keys in the object.
  25757. for (k in value) {
  25758. if (Object.prototype.hasOwnProperty.call(value, k)) {
  25759. v = str(k, value);
  25760. if (v) {
  25761. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  25762. }
  25763. }
  25764. }
  25765. } // Join all of the member texts together, separated with commas,
  25766. // and wrap them in braces.
  25767. v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}';
  25768. gap = mind;
  25769. return v;
  25770. }
  25771. }
  25772. var stringify$1 = function stringify(value, replacer, space) {
  25773. var i;
  25774. gap = '';
  25775. indent$10 = ''; // If the space parameter is a number, make an indent string containing that
  25776. // many spaces.
  25777. if (typeof space === 'number') {
  25778. for (i = 0; i < space; i += 1) {
  25779. indent$10 += ' ';
  25780. }
  25781. } // If the space parameter is a string, it will be used as the indent string.
  25782. else if (typeof space === 'string') {
  25783. indent$10 = space;
  25784. } // If there is a replacer, it must be a function or an array.
  25785. // Otherwise, throw an error.
  25786. rep = replacer;
  25787. if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
  25788. throw new Error('JSON.stringify');
  25789. } // Make a fake root object containing our value under the key of ''.
  25790. // Return the result of stringifying the value.
  25791. return str('', {
  25792. '': value
  25793. });
  25794. };
  25795. var parse$6 = parse$7;
  25796. var stringify = stringify$1;
  25797. var jsonify = {
  25798. parse: parse$6,
  25799. stringify: stringify
  25800. };
  25801. var json$2 = typeof JSON !== 'undefined' ? JSON : jsonify;
  25802. var jsonStableStringify = function jsonStableStringify(obj, opts) {
  25803. if (!opts) opts = {};
  25804. if (typeof opts === 'function') opts = {
  25805. cmp: opts
  25806. };
  25807. var space = opts.space || '';
  25808. if (typeof space === 'number') space = Array(space + 1).join(' ');
  25809. var cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
  25810. var replacer = opts.replacer || function (key, value) {
  25811. return value;
  25812. };
  25813. var cmp = opts.cmp && function (f) {
  25814. return function (node) {
  25815. return function (a, b) {
  25816. var aobj = {
  25817. key: a,
  25818. value: node[a]
  25819. };
  25820. var bobj = {
  25821. key: b,
  25822. value: node[b]
  25823. };
  25824. return f(aobj, bobj);
  25825. };
  25826. };
  25827. }(opts.cmp);
  25828. var seen = [];
  25829. return function stringify(parent, key, node, level) {
  25830. var indent = space ? '\n' + new Array(level + 1).join(space) : '';
  25831. var colonSeparator = space ? ': ' : ':';
  25832. if (node && node.toJSON && typeof node.toJSON === 'function') {
  25833. node = node.toJSON();
  25834. }
  25835. node = replacer.call(parent, key, node);
  25836. if (node === undefined) {
  25837. return;
  25838. }
  25839. if (typeof node !== 'object' || node === null) {
  25840. return json$2.stringify(node);
  25841. }
  25842. if (isArray$1(node)) {
  25843. var out = [];
  25844. for (var i = 0; i < node.length; i++) {
  25845. var item = stringify(node, i, node[i], level + 1) || json$2.stringify(null);
  25846. out.push(indent + space + item);
  25847. }
  25848. return '[' + out.join(',') + indent + ']';
  25849. } else {
  25850. if (seen.indexOf(node) !== -1) {
  25851. if (cycles) return json$2.stringify('__cycle__');
  25852. throw new TypeError('Converting circular structure to JSON');
  25853. } else seen.push(node);
  25854. var keys = objectKeys(node).sort(cmp && cmp(node));
  25855. var out = [];
  25856. for (var i = 0; i < keys.length; i++) {
  25857. var key = keys[i];
  25858. var value = stringify(node, key, node[key], level + 1);
  25859. if (!value) continue;
  25860. var keyValue = json$2.stringify(key) + colonSeparator + value;
  25861. out.push(indent + space + keyValue);
  25862. }
  25863. seen.splice(seen.indexOf(node), 1);
  25864. return '{' + out.join(',') + indent + '}';
  25865. }
  25866. }({
  25867. '': obj
  25868. }, '', obj, 0);
  25869. };
  25870. var isArray$1 = Array.isArray || function (x) {
  25871. return {}.toString.call(x) === '[object Array]';
  25872. };
  25873. var objectKeys = Object.keys || function (obj) {
  25874. var has = Object.prototype.hasOwnProperty || function () {
  25875. return true;
  25876. };
  25877. var keys = [];
  25878. for (var key in obj) {
  25879. if (has.call(obj, key)) keys.push(key);
  25880. }
  25881. return keys;
  25882. };
  25883. function preserveCamelCase(str) {
  25884. var isLastCharLower = false;
  25885. var isLastCharUpper = false;
  25886. var isLastLastCharUpper = false;
  25887. for (var i = 0; i < str.length; i++) {
  25888. var c = str[i];
  25889. if (isLastCharLower && /[a-zA-Z]/.test(c) && c.toUpperCase() === c) {
  25890. str = str.substr(0, i) + '-' + str.substr(i);
  25891. isLastCharLower = false;
  25892. isLastLastCharUpper = isLastCharUpper;
  25893. isLastCharUpper = true;
  25894. i++;
  25895. } else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(c) && c.toLowerCase() === c) {
  25896. str = str.substr(0, i - 1) + '-' + str.substr(i - 1);
  25897. isLastLastCharUpper = isLastCharUpper;
  25898. isLastCharUpper = false;
  25899. isLastCharLower = true;
  25900. } else {
  25901. isLastCharLower = c.toLowerCase() === c;
  25902. isLastLastCharUpper = isLastCharUpper;
  25903. isLastCharUpper = c.toUpperCase() === c;
  25904. }
  25905. }
  25906. return str;
  25907. }
  25908. var camelcase = function camelcase(str) {
  25909. if (arguments.length > 1) {
  25910. str = Array.from(arguments).map(function (x) {
  25911. return x.trim();
  25912. }).filter(function (x) {
  25913. return x.length;
  25914. }).join('-');
  25915. } else {
  25916. str = str.trim();
  25917. }
  25918. if (str.length === 0) {
  25919. return '';
  25920. }
  25921. if (str.length === 1) {
  25922. return str.toLowerCase();
  25923. }
  25924. if (/^[a-z0-9]+$/.test(str)) {
  25925. return str;
  25926. }
  25927. var hasUpperCase = str !== str.toLowerCase();
  25928. if (hasUpperCase) {
  25929. str = preserveCamelCase(str);
  25930. }
  25931. return str.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, function (m, p1) {
  25932. return p1.toUpperCase();
  25933. });
  25934. };
  25935. /*!
  25936. * dashify <https://github.com/jonschlinkert/dashify>
  25937. *
  25938. * Copyright (c) 2015 Jon Schlinkert.
  25939. * Licensed under the MIT license.
  25940. */
  25941. var dashify = function dashify(str) {
  25942. if (typeof str !== 'string') {
  25943. throw new TypeError('expected a string');
  25944. }
  25945. str = str.replace(/([a-z])([A-Z])/g, '$1-$2');
  25946. str = str.replace(/[ \t\W]/g, '-');
  25947. str = str.replace(/^-+|-+$/g, '');
  25948. return str.toLowerCase();
  25949. };
  25950. var ansiStyles$3 = createCommonjsModule(function (module) {
  25951. 'use strict';
  25952. var wrapAnsi16 = function wrapAnsi16(fn, offset) {
  25953. return function () {
  25954. var code = fn.apply(colorConvert, arguments);
  25955. return `\u001B[${code + offset}m`;
  25956. };
  25957. };
  25958. var wrapAnsi256 = function wrapAnsi256(fn, offset) {
  25959. return function () {
  25960. var code = fn.apply(colorConvert, arguments);
  25961. return `\u001B[${38 + offset};5;${code}m`;
  25962. };
  25963. };
  25964. var wrapAnsi16m = function wrapAnsi16m(fn, offset) {
  25965. return function () {
  25966. var rgb = fn.apply(colorConvert, arguments);
  25967. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  25968. };
  25969. };
  25970. function assembleStyles() {
  25971. var styles = {
  25972. modifier: {
  25973. reset: [0, 0],
  25974. // 21 isn't widely supported and 22 does the same thing
  25975. bold: [1, 22],
  25976. dim: [2, 22],
  25977. italic: [3, 23],
  25978. underline: [4, 24],
  25979. inverse: [7, 27],
  25980. hidden: [8, 28],
  25981. strikethrough: [9, 29]
  25982. },
  25983. color: {
  25984. black: [30, 39],
  25985. red: [31, 39],
  25986. green: [32, 39],
  25987. yellow: [33, 39],
  25988. blue: [34, 39],
  25989. magenta: [35, 39],
  25990. cyan: [36, 39],
  25991. white: [37, 39],
  25992. gray: [90, 39],
  25993. // Bright color
  25994. redBright: [91, 39],
  25995. greenBright: [92, 39],
  25996. yellowBright: [93, 39],
  25997. blueBright: [94, 39],
  25998. magentaBright: [95, 39],
  25999. cyanBright: [96, 39],
  26000. whiteBright: [97, 39]
  26001. },
  26002. bgColor: {
  26003. bgBlack: [40, 49],
  26004. bgRed: [41, 49],
  26005. bgGreen: [42, 49],
  26006. bgYellow: [43, 49],
  26007. bgBlue: [44, 49],
  26008. bgMagenta: [45, 49],
  26009. bgCyan: [46, 49],
  26010. bgWhite: [47, 49],
  26011. // Bright color
  26012. bgBlackBright: [100, 49],
  26013. bgRedBright: [101, 49],
  26014. bgGreenBright: [102, 49],
  26015. bgYellowBright: [103, 49],
  26016. bgBlueBright: [104, 49],
  26017. bgMagentaBright: [105, 49],
  26018. bgCyanBright: [106, 49],
  26019. bgWhiteBright: [107, 49]
  26020. }
  26021. }; // Fix humans
  26022. styles.color.grey = styles.color.gray;
  26023. Object.keys(styles).forEach(function (groupName) {
  26024. var group = styles[groupName];
  26025. Object.keys(group).forEach(function (styleName) {
  26026. var style = group[styleName];
  26027. styles[styleName] = {
  26028. open: `\u001B[${style[0]}m`,
  26029. close: `\u001B[${style[1]}m`
  26030. };
  26031. group[styleName] = styles[styleName];
  26032. });
  26033. Object.defineProperty(styles, groupName, {
  26034. value: group,
  26035. enumerable: false
  26036. });
  26037. });
  26038. var rgb2rgb = function rgb2rgb(r, g, b) {
  26039. return [r, g, b];
  26040. };
  26041. styles.color.close = '\u001B[39m';
  26042. styles.bgColor.close = '\u001B[49m';
  26043. styles.color.ansi = {};
  26044. styles.color.ansi256 = {};
  26045. styles.color.ansi16m = {
  26046. rgb: wrapAnsi16m(rgb2rgb, 0)
  26047. };
  26048. styles.bgColor.ansi = {};
  26049. styles.bgColor.ansi256 = {};
  26050. styles.bgColor.ansi16m = {
  26051. rgb: wrapAnsi16m(rgb2rgb, 10)
  26052. };
  26053. var _arr = Object.keys(colorConvert);
  26054. for (var _i = 0; _i < _arr.length; _i++) {
  26055. var key = _arr[_i];
  26056. if (typeof colorConvert[key] !== 'object') {
  26057. continue;
  26058. }
  26059. var suite = colorConvert[key];
  26060. if ('ansi16' in suite) {
  26061. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  26062. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  26063. }
  26064. if ('ansi256' in suite) {
  26065. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  26066. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  26067. }
  26068. if ('rgb' in suite) {
  26069. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  26070. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  26071. }
  26072. }
  26073. return styles;
  26074. }
  26075. Object.defineProperty(module, 'exports', {
  26076. enumerable: true,
  26077. get: assembleStyles
  26078. });
  26079. });
  26080. var hasFlag$3 = function hasFlag(flag, argv) {
  26081. argv = argv || process.argv;
  26082. var terminatorPos = argv.indexOf('--');
  26083. var prefix = /^-{1,2}/.test(flag) ? '' : '--';
  26084. var pos = argv.indexOf(prefix + flag);
  26085. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  26086. };
  26087. var supportsColor$3 = createCommonjsModule(function (module) {
  26088. 'use strict';
  26089. var env = process.env;
  26090. var support = function support(level) {
  26091. if (level === 0) {
  26092. return false;
  26093. }
  26094. return {
  26095. level,
  26096. hasBasic: true,
  26097. has256: level >= 2,
  26098. has16m: level >= 3
  26099. };
  26100. };
  26101. var supportLevel = function () {
  26102. if (hasFlag$3('no-color') || hasFlag$3('no-colors') || hasFlag$3('color=false')) {
  26103. return 0;
  26104. }
  26105. if (hasFlag$3('color=16m') || hasFlag$3('color=full') || hasFlag$3('color=truecolor')) {
  26106. return 3;
  26107. }
  26108. if (hasFlag$3('color=256')) {
  26109. return 2;
  26110. }
  26111. if (hasFlag$3('color') || hasFlag$3('colors') || hasFlag$3('color=true') || hasFlag$3('color=always')) {
  26112. return 1;
  26113. }
  26114. if (process.stdout && !process.stdout.isTTY) {
  26115. return 0;
  26116. }
  26117. if (process.platform === 'win32') {
  26118. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  26119. // libuv that enables 256 color output on Windows. Anything earlier and it
  26120. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  26121. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  26122. // release that supports 256 colors.
  26123. var osRelease = os.release().split('.');
  26124. if (Number(process.version.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  26125. return 2;
  26126. }
  26127. return 1;
  26128. }
  26129. if ('CI' in env) {
  26130. if ('TRAVIS' in env || env.CI === 'Travis' || 'CIRCLECI' in env) {
  26131. return 1;
  26132. }
  26133. return 0;
  26134. }
  26135. if ('TEAMCITY_VERSION' in env) {
  26136. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  26137. }
  26138. if ('TERM_PROGRAM' in env) {
  26139. var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  26140. switch (env.TERM_PROGRAM) {
  26141. case 'iTerm.app':
  26142. return version >= 3 ? 3 : 2;
  26143. case 'Hyper':
  26144. return 3;
  26145. case 'Apple_Terminal':
  26146. return 2;
  26147. // No default
  26148. }
  26149. }
  26150. if (/^(screen|xterm)-256(?:color)?/.test(env.TERM)) {
  26151. return 2;
  26152. }
  26153. if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) {
  26154. return 1;
  26155. }
  26156. if ('COLORTERM' in env) {
  26157. return 1;
  26158. }
  26159. if (env.TERM === 'dumb') {
  26160. return 0;
  26161. }
  26162. return 0;
  26163. }();
  26164. if ('FORCE_COLOR' in env) {
  26165. supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : supportLevel || 1;
  26166. }
  26167. module.exports = process && support(supportLevel);
  26168. });
  26169. var templates$2 = createCommonjsModule(function (module) {
  26170. 'use strict';
  26171. var TEMPLATE_REGEX = /(?:\\(u[a-f0-9]{4}|x[a-f0-9]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  26172. var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  26173. var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  26174. var ESCAPE_REGEX = /\\(u[0-9a-f]{4}|x[0-9a-f]{2}|.)|([^\\])/gi;
  26175. var ESCAPES = {
  26176. n: '\n',
  26177. r: '\r',
  26178. t: '\t',
  26179. b: '\b',
  26180. f: '\f',
  26181. v: '\v',
  26182. 0: '\0',
  26183. '\\': '\\',
  26184. e: '\u001b',
  26185. a: '\u0007'
  26186. };
  26187. function unescape(c) {
  26188. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  26189. return String.fromCharCode(parseInt(c.slice(1), 16));
  26190. }
  26191. return ESCAPES[c] || c;
  26192. }
  26193. function parseArguments(name, args) {
  26194. var results = [];
  26195. var chunks = args.trim().split(/\s*,\s*/g);
  26196. var matches;
  26197. var _iteratorNormalCompletion = true;
  26198. var _didIteratorError = false;
  26199. var _iteratorError = undefined;
  26200. try {
  26201. for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  26202. var chunk = _step.value;
  26203. if (!isNaN(chunk)) {
  26204. results.push(Number(chunk));
  26205. } else if (matches = chunk.match(STRING_REGEX)) {
  26206. results.push(matches[2].replace(ESCAPE_REGEX, function (m, escape, chr) {
  26207. return escape ? unescape(escape) : chr;
  26208. }));
  26209. } else {
  26210. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  26211. }
  26212. }
  26213. } catch (err) {
  26214. _didIteratorError = true;
  26215. _iteratorError = err;
  26216. } finally {
  26217. try {
  26218. if (!_iteratorNormalCompletion && _iterator.return != null) {
  26219. _iterator.return();
  26220. }
  26221. } finally {
  26222. if (_didIteratorError) {
  26223. throw _iteratorError;
  26224. }
  26225. }
  26226. }
  26227. return results;
  26228. }
  26229. function parseStyle(style) {
  26230. STYLE_REGEX.lastIndex = 0;
  26231. var results = [];
  26232. var matches;
  26233. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  26234. var name = matches[1];
  26235. if (matches[2]) {
  26236. var args = parseArguments(name, matches[2]);
  26237. results.push([name].concat(args));
  26238. } else {
  26239. results.push([name]);
  26240. }
  26241. }
  26242. return results;
  26243. }
  26244. function buildStyle(chalk, styles) {
  26245. var enabled = {};
  26246. var _iteratorNormalCompletion2 = true;
  26247. var _didIteratorError2 = false;
  26248. var _iteratorError2 = undefined;
  26249. try {
  26250. for (var _iterator2 = styles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  26251. var layer = _step2.value;
  26252. var _iteratorNormalCompletion3 = true;
  26253. var _didIteratorError3 = false;
  26254. var _iteratorError3 = undefined;
  26255. try {
  26256. for (var _iterator3 = layer.styles[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  26257. var style = _step3.value;
  26258. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  26259. }
  26260. } catch (err) {
  26261. _didIteratorError3 = true;
  26262. _iteratorError3 = err;
  26263. } finally {
  26264. try {
  26265. if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
  26266. _iterator3.return();
  26267. }
  26268. } finally {
  26269. if (_didIteratorError3) {
  26270. throw _iteratorError3;
  26271. }
  26272. }
  26273. }
  26274. }
  26275. } catch (err) {
  26276. _didIteratorError2 = true;
  26277. _iteratorError2 = err;
  26278. } finally {
  26279. try {
  26280. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  26281. _iterator2.return();
  26282. }
  26283. } finally {
  26284. if (_didIteratorError2) {
  26285. throw _iteratorError2;
  26286. }
  26287. }
  26288. }
  26289. var current = chalk;
  26290. var _arr = Object.keys(enabled);
  26291. for (var _i = 0; _i < _arr.length; _i++) {
  26292. var styleName = _arr[_i];
  26293. if (Array.isArray(enabled[styleName])) {
  26294. if (!(styleName in current)) {
  26295. throw new Error(`Unknown Chalk style: ${styleName}`);
  26296. }
  26297. if (enabled[styleName].length > 0) {
  26298. current = current[styleName].apply(current, enabled[styleName]);
  26299. } else {
  26300. current = current[styleName];
  26301. }
  26302. }
  26303. }
  26304. return current;
  26305. }
  26306. module.exports = function (chalk, tmp) {
  26307. var styles = [];
  26308. var chunks = [];
  26309. var chunk = []; // eslint-disable-next-line max-params
  26310. tmp.replace(TEMPLATE_REGEX, function (m, escapeChar, inverse, style, close, chr) {
  26311. if (escapeChar) {
  26312. chunk.push(unescape(escapeChar));
  26313. } else if (style) {
  26314. var str = chunk.join('');
  26315. chunk = [];
  26316. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  26317. styles.push({
  26318. inverse,
  26319. styles: parseStyle(style)
  26320. });
  26321. } else if (close) {
  26322. if (styles.length === 0) {
  26323. throw new Error('Found extraneous } in Chalk template literal');
  26324. }
  26325. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  26326. chunk = [];
  26327. styles.pop();
  26328. } else {
  26329. chunk.push(chr);
  26330. }
  26331. });
  26332. chunks.push(chunk.join(''));
  26333. if (styles.length > 0) {
  26334. var errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  26335. throw new Error(errMsg);
  26336. }
  26337. return chunks.join('');
  26338. };
  26339. });
  26340. var isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  26341. var levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  26342. var skipModels = new Set(['gray']);
  26343. var styles = Object.create(null);
  26344. function applyOptions(obj, options) {
  26345. options = options || {}; // Detect level if not set manually
  26346. var scLevel = supportsColor$3 ? supportsColor$3.level : 0;
  26347. obj.level = options.level === undefined ? scLevel : options.level;
  26348. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  26349. }
  26350. function Chalk(options) {
  26351. // We check for this.template here since calling `chalk.constructor()`
  26352. // by itself will have a `this` of a previously constructed chalk object
  26353. if (!this || !(this instanceof Chalk) || this.template) {
  26354. var _chalk = {};
  26355. applyOptions(_chalk, options);
  26356. _chalk.template = function () {
  26357. var args = [].slice.call(arguments);
  26358. return chalkTag.apply(null, [_chalk.template].concat(args));
  26359. };
  26360. Object.setPrototypeOf(_chalk, Chalk.prototype);
  26361. Object.setPrototypeOf(_chalk.template, _chalk);
  26362. _chalk.template.constructor = Chalk;
  26363. return _chalk.template;
  26364. }
  26365. applyOptions(this, options);
  26366. } // Use bright blue on Windows as the normal blue color is illegible
  26367. if (isSimpleWindowsTerm) {
  26368. ansiStyles$3.blue.open = '\u001B[94m';
  26369. }
  26370. var _arr = Object.keys(ansiStyles$3);
  26371. var _loop = function _loop() {
  26372. var key = _arr[_i];
  26373. ansiStyles$3[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles$3[key].close), 'g');
  26374. styles[key] = {
  26375. get() {
  26376. var codes = ansiStyles$3[key];
  26377. return build$1.call(this, this._styles ? this._styles.concat(codes) : [codes], key);
  26378. }
  26379. };
  26380. };
  26381. for (var _i = 0; _i < _arr.length; _i++) {
  26382. _loop();
  26383. }
  26384. ansiStyles$3.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles$3.color.close), 'g');
  26385. var _arr2 = Object.keys(ansiStyles$3.color.ansi);
  26386. var _loop2 = function _loop2() {
  26387. var model = _arr2[_i2];
  26388. if (skipModels.has(model)) {
  26389. return "continue";
  26390. }
  26391. styles[model] = {
  26392. get() {
  26393. var level = this.level;
  26394. return function () {
  26395. var open = ansiStyles$3.color[levelMapping[level]][model].apply(null, arguments);
  26396. var codes = {
  26397. open,
  26398. close: ansiStyles$3.color.close,
  26399. closeRe: ansiStyles$3.color.closeRe
  26400. };
  26401. return build$1.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
  26402. };
  26403. }
  26404. };
  26405. };
  26406. for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
  26407. var _ret = _loop2();
  26408. if (_ret === "continue") continue;
  26409. }
  26410. ansiStyles$3.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles$3.bgColor.close), 'g');
  26411. var _arr3 = Object.keys(ansiStyles$3.bgColor.ansi);
  26412. var _loop3 = function _loop3() {
  26413. var model = _arr3[_i3];
  26414. if (skipModels.has(model)) {
  26415. return "continue";
  26416. }
  26417. var bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  26418. styles[bgModel] = {
  26419. get() {
  26420. var level = this.level;
  26421. return function () {
  26422. var open = ansiStyles$3.bgColor[levelMapping[level]][model].apply(null, arguments);
  26423. var codes = {
  26424. open,
  26425. close: ansiStyles$3.bgColor.close,
  26426. closeRe: ansiStyles$3.bgColor.closeRe
  26427. };
  26428. return build$1.call(this, this._styles ? this._styles.concat(codes) : [codes], model);
  26429. };
  26430. }
  26431. };
  26432. };
  26433. for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
  26434. var _ret2 = _loop3();
  26435. if (_ret2 === "continue") continue;
  26436. }
  26437. var proto = Object.defineProperties(function () {}, styles);
  26438. function build$1(_styles, key) {
  26439. var builder = function builder() {
  26440. return applyStyle.apply(builder, arguments);
  26441. };
  26442. builder._styles = _styles;
  26443. var self = this;
  26444. Object.defineProperty(builder, 'level', {
  26445. enumerable: true,
  26446. get() {
  26447. return self.level;
  26448. },
  26449. set(level) {
  26450. self.level = level;
  26451. }
  26452. });
  26453. Object.defineProperty(builder, 'enabled', {
  26454. enumerable: true,
  26455. get() {
  26456. return self.enabled;
  26457. },
  26458. set(enabled) {
  26459. self.enabled = enabled;
  26460. }
  26461. }); // See below for fix regarding invisible grey/dim combination on Windows
  26462. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  26463. // no way to create a function with a different prototype
  26464. builder.__proto__ = proto; // eslint-disable-line no-proto
  26465. return builder;
  26466. }
  26467. function applyStyle() {
  26468. // Support varags, but simply cast to string in case there's only one arg
  26469. var args = arguments;
  26470. var argsLen = args.length;
  26471. var str = String(arguments[0]);
  26472. if (argsLen === 0) {
  26473. return '';
  26474. }
  26475. if (argsLen > 1) {
  26476. // Don't slice `arguments`, it prevents V8 optimizations
  26477. for (var a = 1; a < argsLen; a++) {
  26478. str += ' ' + args[a];
  26479. }
  26480. }
  26481. if (!this.enabled || this.level <= 0 || !str) {
  26482. return str;
  26483. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  26484. // see https://github.com/chalk/chalk/issues/58
  26485. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  26486. var originalDim = ansiStyles$3.dim.open;
  26487. if (isSimpleWindowsTerm && this.hasGrey) {
  26488. ansiStyles$3.dim.open = '';
  26489. }
  26490. var _iteratorNormalCompletion = true;
  26491. var _didIteratorError = false;
  26492. var _iteratorError = undefined;
  26493. try {
  26494. for (var _iterator = this._styles.slice().reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  26495. var code = _step.value;
  26496. // Replace any instances already present with a re-opening code
  26497. // otherwise only the part of the string until said closing code
  26498. // will be colored, and the rest will simply be 'plain'.
  26499. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  26500. // after next line to fix a bleed issue on macOS
  26501. // https://github.com/chalk/chalk/pull/92
  26502. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  26503. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  26504. } catch (err) {
  26505. _didIteratorError = true;
  26506. _iteratorError = err;
  26507. } finally {
  26508. try {
  26509. if (!_iteratorNormalCompletion && _iterator.return != null) {
  26510. _iterator.return();
  26511. }
  26512. } finally {
  26513. if (_didIteratorError) {
  26514. throw _iteratorError;
  26515. }
  26516. }
  26517. }
  26518. ansiStyles$3.dim.open = originalDim;
  26519. return str;
  26520. }
  26521. function chalkTag(chalk, strings) {
  26522. if (!Array.isArray(strings)) {
  26523. // If chalk() was called by itself or with a string,
  26524. // return the string itself as a string.
  26525. return [].slice.call(arguments, 1).join(' ');
  26526. }
  26527. var args = [].slice.call(arguments, 2);
  26528. var parts = [strings.raw[0]];
  26529. for (var i = 1; i < strings.length; i++) {
  26530. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  26531. parts.push(String(strings.raw[i]));
  26532. }
  26533. return templates$2(chalk, parts.join(''));
  26534. }
  26535. Object.defineProperties(Chalk.prototype, styles);
  26536. var chalk$2 = Chalk(); // eslint-disable-line new-cap
  26537. var supportsColor_1 = supportsColor$3;
  26538. chalk$2.supportsColor = supportsColor_1;
  26539. var minimist = function minimist(args, opts) {
  26540. if (!opts) opts = {};
  26541. var flags = {
  26542. bools: {},
  26543. strings: {},
  26544. unknownFn: null
  26545. };
  26546. if (typeof opts['unknown'] === 'function') {
  26547. flags.unknownFn = opts['unknown'];
  26548. }
  26549. if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {
  26550. flags.allBools = true;
  26551. } else {
  26552. [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {
  26553. flags.bools[key] = true;
  26554. });
  26555. }
  26556. var aliases = {};
  26557. Object.keys(opts.alias || {}).forEach(function (key) {
  26558. aliases[key] = [].concat(opts.alias[key]);
  26559. aliases[key].forEach(function (x) {
  26560. aliases[x] = [key].concat(aliases[key].filter(function (y) {
  26561. return x !== y;
  26562. }));
  26563. });
  26564. });
  26565. [].concat(opts.string).filter(Boolean).forEach(function (key) {
  26566. flags.strings[key] = true;
  26567. if (aliases[key]) {
  26568. flags.strings[aliases[key]] = true;
  26569. }
  26570. });
  26571. var defaults = opts['default'] || {};
  26572. var argv = {
  26573. _: []
  26574. };
  26575. Object.keys(flags.bools).forEach(function (key) {
  26576. setArg(key, defaults[key] === undefined ? false : defaults[key]);
  26577. });
  26578. var notFlags = [];
  26579. if (args.indexOf('--') !== -1) {
  26580. notFlags = args.slice(args.indexOf('--') + 1);
  26581. args = args.slice(0, args.indexOf('--'));
  26582. }
  26583. function argDefined(key, arg) {
  26584. return flags.allBools && /^--[^=]+$/.test(arg) || flags.strings[key] || flags.bools[key] || aliases[key];
  26585. }
  26586. function setArg(key, val, arg) {
  26587. if (arg && flags.unknownFn && !argDefined(key, arg)) {
  26588. if (flags.unknownFn(arg) === false) return;
  26589. }
  26590. var value = !flags.strings[key] && isNumber(val) ? Number(val) : val;
  26591. setKey(argv, key.split('.'), value);
  26592. (aliases[key] || []).forEach(function (x) {
  26593. setKey(argv, x.split('.'), value);
  26594. });
  26595. }
  26596. function setKey(obj, keys, value) {
  26597. var o = obj;
  26598. keys.slice(0, -1).forEach(function (key) {
  26599. if (o[key] === undefined) o[key] = {};
  26600. o = o[key];
  26601. });
  26602. var key = keys[keys.length - 1];
  26603. if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {
  26604. o[key] = value;
  26605. } else if (Array.isArray(o[key])) {
  26606. o[key].push(value);
  26607. } else {
  26608. o[key] = [o[key], value];
  26609. }
  26610. }
  26611. function aliasIsBoolean(key) {
  26612. return aliases[key].some(function (x) {
  26613. return flags.bools[x];
  26614. });
  26615. }
  26616. for (var i = 0; i < args.length; i++) {
  26617. var arg = args[i];
  26618. if (/^--.+=/.test(arg)) {
  26619. // Using [\s\S] instead of . because js doesn't support the
  26620. // 'dotall' regex modifier. See:
  26621. // http://stackoverflow.com/a/1068308/13216
  26622. var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
  26623. var key = m[1];
  26624. var value = m[2];
  26625. if (flags.bools[key]) {
  26626. value = value !== 'false';
  26627. }
  26628. setArg(key, value, arg);
  26629. } else if (/^--no-.+/.test(arg)) {
  26630. var key = arg.match(/^--no-(.+)/)[1];
  26631. setArg(key, false, arg);
  26632. } else if (/^--.+/.test(arg)) {
  26633. var key = arg.match(/^--(.+)/)[1];
  26634. var next = args[i + 1];
  26635. if (next !== undefined && !/^-/.test(next) && !flags.bools[key] && !flags.allBools && (aliases[key] ? !aliasIsBoolean(key) : true)) {
  26636. setArg(key, next, arg);
  26637. i++;
  26638. } else if (/^(true|false)$/.test(next)) {
  26639. setArg(key, next === 'true', arg);
  26640. i++;
  26641. } else {
  26642. setArg(key, flags.strings[key] ? '' : true, arg);
  26643. }
  26644. } else if (/^-[^-]+/.test(arg)) {
  26645. var letters = arg.slice(1, -1).split('');
  26646. var broken = false;
  26647. for (var j = 0; j < letters.length; j++) {
  26648. var next = arg.slice(j + 2);
  26649. if (next === '-') {
  26650. setArg(letters[j], next, arg);
  26651. continue;
  26652. }
  26653. if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
  26654. setArg(letters[j], next.split('=')[1], arg);
  26655. broken = true;
  26656. break;
  26657. }
  26658. if (/[A-Za-z]/.test(letters[j]) && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
  26659. setArg(letters[j], next, arg);
  26660. broken = true;
  26661. break;
  26662. }
  26663. if (letters[j + 1] && letters[j + 1].match(/\W/)) {
  26664. setArg(letters[j], arg.slice(j + 2), arg);
  26665. broken = true;
  26666. break;
  26667. } else {
  26668. setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
  26669. }
  26670. }
  26671. var key = arg.slice(-1)[0];
  26672. if (!broken && key !== '-') {
  26673. if (args[i + 1] && !/^(-|--)[^-]/.test(args[i + 1]) && !flags.bools[key] && (aliases[key] ? !aliasIsBoolean(key) : true)) {
  26674. setArg(key, args[i + 1], arg);
  26675. i++;
  26676. } else if (args[i + 1] && /true|false/.test(args[i + 1])) {
  26677. setArg(key, args[i + 1] === 'true', arg);
  26678. i++;
  26679. } else {
  26680. setArg(key, flags.strings[key] ? '' : true, arg);
  26681. }
  26682. }
  26683. } else {
  26684. if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
  26685. argv._.push(flags.strings['_'] || !isNumber(arg) ? arg : Number(arg));
  26686. }
  26687. if (opts.stopEarly) {
  26688. argv._.push.apply(argv._, args.slice(i + 1));
  26689. break;
  26690. }
  26691. }
  26692. }
  26693. Object.keys(defaults).forEach(function (key) {
  26694. if (!hasKey(argv, key.split('.'))) {
  26695. setKey(argv, key.split('.'), defaults[key]);
  26696. (aliases[key] || []).forEach(function (x) {
  26697. setKey(argv, x.split('.'), defaults[key]);
  26698. });
  26699. }
  26700. });
  26701. if (opts['--']) {
  26702. argv['--'] = new Array();
  26703. notFlags.forEach(function (key) {
  26704. argv['--'].push(key);
  26705. });
  26706. } else {
  26707. notFlags.forEach(function (key) {
  26708. argv._.push(key);
  26709. });
  26710. }
  26711. return argv;
  26712. };
  26713. function hasKey(obj, keys) {
  26714. var o = obj;
  26715. keys.slice(0, -1).forEach(function (key) {
  26716. o = o[key] || {};
  26717. });
  26718. var key = keys[keys.length - 1];
  26719. return key in o;
  26720. }
  26721. function isNumber(x) {
  26722. if (typeof x === 'number') return true;
  26723. if (/^0x[0-9a-f]+$/i.test(x)) return true;
  26724. return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
  26725. }
  26726. var PLACEHOLDER = null;
  26727. /**
  26728. * unspecified boolean flag without default value is parsed as `undefined` instead of `false`
  26729. */
  26730. var minimist_1 = function minimist_1(args, options) {
  26731. var boolean = options.boolean || [];
  26732. var defaults = options.default || {};
  26733. var booleanWithoutDefault = boolean.filter(function (key) {
  26734. return !(key in defaults);
  26735. });
  26736. var newDefaults = Object.assign({}, defaults, booleanWithoutDefault.reduce(function (reduced, key) {
  26737. return Object.assign(reduced, {
  26738. [key]: PLACEHOLDER
  26739. });
  26740. }, {}));
  26741. var parsed = minimist(args, Object.assign({}, options, {
  26742. default: newDefaults
  26743. }));
  26744. return Object.keys(parsed).reduce(function (reduced, key) {
  26745. if (parsed[key] !== PLACEHOLDER) {
  26746. reduced[key] = parsed[key];
  26747. }
  26748. return reduced;
  26749. }, {});
  26750. };
  26751. var categoryOrder = [coreOptions$1.CATEGORY_OUTPUT, coreOptions$1.CATEGORY_FORMAT, coreOptions$1.CATEGORY_CONFIG, coreOptions$1.CATEGORY_EDITOR, coreOptions$1.CATEGORY_OTHER];
  26752. /**
  26753. * {
  26754. * [optionName]: {
  26755. * // The type of the option. For 'choice', see also `choices` below.
  26756. * // When passing a type other than the ones listed below, the option is
  26757. * // treated as taking any string as argument, and `--option <${type}>` will
  26758. * // be displayed in --help.
  26759. * type: "boolean" | "choice" | "int" | string;
  26760. *
  26761. * // Default value to be passed to the minimist option `default`.
  26762. * default?: any;
  26763. *
  26764. * // Alias name to be passed to the minimist option `alias`.
  26765. * alias?: string;
  26766. *
  26767. * // For grouping options by category in --help.
  26768. * category?: string;
  26769. *
  26770. * // Description to be displayed in --help. If omitted, the option won't be
  26771. * // shown at all in --help (but see also `oppositeDescription` below).
  26772. * description?: string;
  26773. *
  26774. * // Description for `--no-${name}` to be displayed in --help. If omitted,
  26775. * // `--no-${name}` won't be shown.
  26776. * oppositeDescription?: string;
  26777. *
  26778. * // Indicate if this option is simply passed to the API.
  26779. * // true: use camelified name as the API option name.
  26780. * // string: use this value as the API option name.
  26781. * forwardToApi?: boolean | string;
  26782. *
  26783. * // Indicate that a CLI flag should be an array when forwarded to the API.
  26784. * array?: boolean;
  26785. *
  26786. * // Specify available choices for validation. They will also be displayed
  26787. * // in --help as <a|b|c>.
  26788. * // Use an object instead of a string if a choice is deprecated and should
  26789. * // be treated as `redirect` instead, or if you'd like to add description for
  26790. * // the choice.
  26791. * choices?: Array<
  26792. * | string
  26793. * | { value: string, description?: string, deprecated?: boolean, redirect?: string }
  26794. * >;
  26795. *
  26796. * // If the option has a value that is an exception to the regular value
  26797. * // constraints, indicate that value here (or use a function for more
  26798. * // flexibility).
  26799. * exception?: ((value: any) => boolean);
  26800. *
  26801. * // Indicate that the option is deprecated. Use a string to add an extra
  26802. * // message to --help for the option, for example to suggest a replacement
  26803. * // option.
  26804. * deprecated?: true | string;
  26805. * }
  26806. * }
  26807. *
  26808. * Note: The options below are sorted alphabetically.
  26809. */
  26810. var options$15 = {
  26811. color: {
  26812. // The supports-color package (a sub sub dependency) looks directly at
  26813. // `process.argv` for `--no-color` and such-like options. The reason it is
  26814. // listed here is to avoid "Ignored unknown option: --no-color" warnings.
  26815. // See https://github.com/chalk/supports-color/#info for more information.
  26816. type: "boolean",
  26817. default: true,
  26818. description: "Colorize error messages.",
  26819. oppositeDescription: "Do not colorize error messages."
  26820. },
  26821. config: {
  26822. type: "path",
  26823. category: coreOptions$1.CATEGORY_CONFIG,
  26824. description: "Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js).",
  26825. oppositeDescription: "Do not look for a configuration file."
  26826. },
  26827. "config-precedence": {
  26828. type: "choice",
  26829. category: coreOptions$1.CATEGORY_CONFIG,
  26830. default: "cli-override",
  26831. choices: [{
  26832. value: "cli-override",
  26833. description: "CLI options take precedence over config file"
  26834. }, {
  26835. value: "file-override",
  26836. description: "Config file take precedence over CLI options"
  26837. }, {
  26838. value: "prefer-file",
  26839. description: dedent_1`
  26840. If a config file is found will evaluate it and ignore other CLI options.
  26841. If no config file is found CLI options will evaluate as normal.
  26842. `
  26843. }],
  26844. description: "Define in which order config files and CLI options should be evaluated."
  26845. },
  26846. "debug-check": {
  26847. type: "boolean"
  26848. },
  26849. "debug-print-doc": {
  26850. type: "boolean"
  26851. },
  26852. editorconfig: {
  26853. type: "boolean",
  26854. category: coreOptions$1.CATEGORY_CONFIG,
  26855. description: "Take .editorconfig into account when parsing configuration.",
  26856. oppositeDescription: "Don't take .editorconfig into account when parsing configuration.",
  26857. default: true
  26858. },
  26859. "find-config-path": {
  26860. type: "path",
  26861. category: coreOptions$1.CATEGORY_CONFIG,
  26862. description: "Find and print the path to a configuration file for the given input file."
  26863. },
  26864. "file-info": {
  26865. type: "path",
  26866. description: dedent_1`
  26867. Extract the following info (as JSON) for a given file path. Reported fields:
  26868. * ignored (boolean) - true if file path is filtered by --ignore-path
  26869. * inferredParser (string | null) - name of parser inferred from file path
  26870. `
  26871. },
  26872. help: {
  26873. type: "flag",
  26874. alias: "h",
  26875. description: dedent_1`
  26876. Show CLI usage, or details about the given flag.
  26877. Example: --help write
  26878. `
  26879. },
  26880. "ignore-path": {
  26881. type: "path",
  26882. category: coreOptions$1.CATEGORY_CONFIG,
  26883. default: ".prettierignore",
  26884. description: "Path to a file with patterns describing files to ignore."
  26885. },
  26886. "list-different": {
  26887. type: "boolean",
  26888. category: coreOptions$1.CATEGORY_OUTPUT,
  26889. alias: "l",
  26890. description: "Print the names of files that are different from Prettier's formatting."
  26891. },
  26892. loglevel: {
  26893. type: "choice",
  26894. description: "What level of logs to report.",
  26895. default: "log",
  26896. choices: ["silent", "error", "warn", "log", "debug"]
  26897. },
  26898. stdin: {
  26899. type: "boolean",
  26900. description: "Force reading input from stdin."
  26901. },
  26902. "support-info": {
  26903. type: "boolean",
  26904. description: "Print support information as JSON."
  26905. },
  26906. version: {
  26907. type: "boolean",
  26908. alias: "v",
  26909. description: "Print Prettier version."
  26910. },
  26911. "with-node-modules": {
  26912. type: "boolean",
  26913. category: coreOptions$1.CATEGORY_CONFIG,
  26914. description: "Process files inside 'node_modules' directory."
  26915. },
  26916. write: {
  26917. type: "boolean",
  26918. category: coreOptions$1.CATEGORY_OUTPUT,
  26919. description: "Edit files in-place. (Beware!)"
  26920. }
  26921. };
  26922. var usageSummary = dedent_1`
  26923. Usage: prettier [options] [file/glob ...]
  26924. By default, output is written to stdout.
  26925. Stdin is read if it is piped to Prettier and no files are given.
  26926. `;
  26927. var constant = {
  26928. categoryOrder,
  26929. options: options$15,
  26930. usageSummary
  26931. };
  26932. var OPTION_USAGE_THRESHOLD = 25;
  26933. var CHOICE_USAGE_MARGIN = 3;
  26934. var CHOICE_USAGE_INDENTATION = 2;
  26935. function getOptions(argv, detailedOptions) {
  26936. return detailedOptions.filter(function (option) {
  26937. return option.forwardToApi;
  26938. }).reduce(function (current, option) {
  26939. return Object.assign(current, {
  26940. [option.forwardToApi]: argv[option.name]
  26941. });
  26942. }, {});
  26943. }
  26944. function cliifyOptions(object, apiDetailedOptionMap) {
  26945. return Object.keys(object || {}).reduce(function (output, key) {
  26946. var apiOption = apiDetailedOptionMap[key];
  26947. var cliKey = apiOption ? apiOption.name : key;
  26948. output[dashify(cliKey)] = object[key];
  26949. return output;
  26950. }, {});
  26951. }
  26952. function diff(a, b) {
  26953. return lib.createTwoFilesPatch("", "", a, b, "", "", {
  26954. context: 2
  26955. });
  26956. }
  26957. function handleError(context, filename, error) {
  26958. if (error instanceof errors.UndefinedParserError) {
  26959. if (context.argv["write"] && process.stdout.isTTY) {
  26960. readline.clearLine(process.stdout, 0);
  26961. readline.cursorTo(process.stdout, 0, null);
  26962. }
  26963. if (!context.argv["list-different"]) {
  26964. process.exitCode = 2;
  26965. }
  26966. context.logger.error(error.message);
  26967. return;
  26968. }
  26969. if (context.argv["write"]) {
  26970. // Add newline to split errors from filename line.
  26971. process.stdout.write("\n");
  26972. }
  26973. var isParseError = Boolean(error && error.loc);
  26974. var isValidationError = /Validation Error/.test(error && error.message); // For parse errors and validation errors, we only want to show the error
  26975. // message formatted in a nice way. `String(error)` takes care of that. Other
  26976. // (unexpected) errors are passed as-is as a separate argument to
  26977. // `console.error`. That includes the stack trace (if any), and shows a nice
  26978. // `util.inspect` of throws things that aren't `Error` objects. (The Flow
  26979. // parser has mistakenly thrown arrays sometimes.)
  26980. if (isParseError) {
  26981. context.logger.error(`${filename}: ${String(error)}`);
  26982. } else if (isValidationError || error instanceof errors.ConfigError) {
  26983. context.logger.error(String(error)); // If validation fails for one file, it will fail for all of them.
  26984. process.exit(1);
  26985. } else if (error instanceof errors.DebugError) {
  26986. context.logger.error(`${filename}: ${error.message}`);
  26987. } else {
  26988. context.logger.error(filename + ": " + (error.stack || error));
  26989. } // Don't exit the process if one file failed
  26990. process.exitCode = 2;
  26991. }
  26992. function logResolvedConfigPathOrDie(context) {
  26993. var configFile = prettier$2.resolveConfigFile.sync(context.argv["find-config-path"]);
  26994. if (configFile) {
  26995. context.logger.log(path.relative(process.cwd(), configFile));
  26996. } else {
  26997. process.exit(1);
  26998. }
  26999. }
  27000. function logFileInfoOrDie(context) {
  27001. var options$$2 = {
  27002. ignorePath: context.argv["ignore-path"],
  27003. withNodeModules: context.argv["with-node-modules"],
  27004. plugins: context.argv["plugin"],
  27005. pluginSearchDirs: context.argv["plugin-search-dir"]
  27006. };
  27007. context.logger.log(prettier$2.format(jsonStableStringify(prettier$2.getFileInfo.sync(context.argv["file-info"], options$$2)), {
  27008. parser: "json"
  27009. }));
  27010. }
  27011. function writeOutput(context, result, options$$2) {
  27012. // Don't use `console.log` here since it adds an extra newline at the end.
  27013. process.stdout.write(context.argv["debug-check"] ? result.filepath : result.formatted);
  27014. if (options$$2 && options$$2.cursorOffset >= 0) {
  27015. process.stderr.write(result.cursorOffset + "\n");
  27016. }
  27017. }
  27018. function listDifferent(context, input, options$$2, filename) {
  27019. if (!context.argv["list-different"]) {
  27020. return;
  27021. }
  27022. try {
  27023. if (!options$$2.filepath && !options$$2.parser) {
  27024. throw new errors.UndefinedParserError("No parser and no file path given, couldn't infer a parser.");
  27025. }
  27026. if (!prettier$2.check(input, options$$2)) {
  27027. if (!context.argv["write"]) {
  27028. context.logger.log(filename);
  27029. }
  27030. process.exitCode = 1;
  27031. }
  27032. } catch (error) {
  27033. context.logger.error(error.message);
  27034. }
  27035. return true;
  27036. }
  27037. function format$1(context, input, opt) {
  27038. if (!opt.parser && !opt.filepath) {
  27039. throw new errors.UndefinedParserError("No parser and no file path given, couldn't infer a parser.");
  27040. }
  27041. if (context.argv["debug-print-doc"]) {
  27042. var doc = prettier$2.__debug.printToDoc(input, opt);
  27043. return {
  27044. formatted: prettier$2.__debug.formatDoc(doc)
  27045. };
  27046. }
  27047. if (context.argv["debug-check"]) {
  27048. var pp = prettier$2.format(input, opt);
  27049. var pppp = prettier$2.format(pp, opt);
  27050. if (pp !== pppp) {
  27051. throw new errors.DebugError("prettier(input) !== prettier(prettier(input))\n" + diff(pp, pppp));
  27052. } else {
  27053. var _stringify = function _stringify(obj) {
  27054. return JSON.stringify(obj, null, 2);
  27055. };
  27056. var ast = _stringify(prettier$2.__debug.parse(input, opt,
  27057. /* massage */
  27058. true).ast);
  27059. var past = _stringify(prettier$2.__debug.parse(pp, opt,
  27060. /* massage */
  27061. true).ast);
  27062. if (ast !== past) {
  27063. var MAX_AST_SIZE = 2097152; // 2MB
  27064. var astDiff = ast.length > MAX_AST_SIZE || past.length > MAX_AST_SIZE ? "AST diff too large to render" : diff(ast, past);
  27065. throw new errors.DebugError("ast(input) !== ast(prettier(input))\n" + astDiff + "\n" + diff(input, pp));
  27066. }
  27067. }
  27068. return {
  27069. formatted: pp,
  27070. filepath: opt.filepath || "(stdin)\n"
  27071. };
  27072. }
  27073. return prettier$2.formatWithCursor(input, opt);
  27074. }
  27075. function getOptionsOrDie(context, filePath) {
  27076. try {
  27077. if (context.argv["config"] === false) {
  27078. context.logger.debug("'--no-config' option found, skip loading config file.");
  27079. return null;
  27080. }
  27081. context.logger.debug(context.argv["config"] ? `load config file from '${context.argv["config"]}'` : `resolve config from '${filePath}'`);
  27082. var options$$2 = prettier$2.resolveConfig.sync(filePath, {
  27083. editorconfig: context.argv["editorconfig"],
  27084. config: context.argv["config"]
  27085. });
  27086. context.logger.debug("loaded options `" + JSON.stringify(options$$2) + "`");
  27087. return options$$2;
  27088. } catch (error) {
  27089. context.logger.error("Invalid configuration file: " + error.message);
  27090. process.exit(2);
  27091. }
  27092. }
  27093. function getOptionsForFile(context, filepath) {
  27094. var options$$2 = getOptionsOrDie(context, filepath);
  27095. var hasPlugins = options$$2 && options$$2.plugins;
  27096. if (hasPlugins) {
  27097. pushContextPlugins(context, options$$2.plugins);
  27098. }
  27099. var appliedOptions = Object.assign({
  27100. filepath
  27101. }, applyConfigPrecedence(context, options$$2 && optionsNormalizer.normalizeApiOptions(options$$2, context.supportOptions, {
  27102. logger: context.logger
  27103. })));
  27104. context.logger.debug(`applied config-precedence (${context.argv["config-precedence"]}): ` + `${JSON.stringify(appliedOptions)}`);
  27105. if (hasPlugins) {
  27106. popContextPlugins(context);
  27107. }
  27108. return appliedOptions;
  27109. }
  27110. function parseArgsToOptions(context, overrideDefaults) {
  27111. var minimistOptions = createMinimistOptions(context.detailedOptions);
  27112. var apiDetailedOptionMap = createApiDetailedOptionMap(context.detailedOptions);
  27113. return getOptions(optionsNormalizer.normalizeCliOptions(minimist_1(context.args, Object.assign({
  27114. string: minimistOptions.string,
  27115. boolean: minimistOptions.boolean,
  27116. default: cliifyOptions(overrideDefaults, apiDetailedOptionMap)
  27117. })), context.detailedOptions, {
  27118. logger: false
  27119. }), context.detailedOptions);
  27120. }
  27121. function applyConfigPrecedence(context, options$$2) {
  27122. try {
  27123. switch (context.argv["config-precedence"]) {
  27124. case "cli-override":
  27125. return parseArgsToOptions(context, options$$2);
  27126. case "file-override":
  27127. return Object.assign({}, parseArgsToOptions(context), options$$2);
  27128. case "prefer-file":
  27129. return options$$2 || parseArgsToOptions(context);
  27130. }
  27131. } catch (error) {
  27132. context.logger.error(error.toString());
  27133. process.exit(2);
  27134. }
  27135. }
  27136. function formatStdin(context) {
  27137. var filepath = context.argv["stdin-filepath"] ? path.resolve(process.cwd(), context.argv["stdin-filepath"]) : process.cwd();
  27138. var ignorer = createIgnorerFromContextOrDie(context);
  27139. var relativeFilepath = path.relative(process.cwd(), filepath);
  27140. thirdParty$1.getStream(process.stdin).then(function (input) {
  27141. if (relativeFilepath && ignorer.filter([relativeFilepath]).length === 0) {
  27142. writeOutput(context, {
  27143. formatted: input
  27144. });
  27145. return;
  27146. }
  27147. var options$$2 = getOptionsForFile(context, filepath);
  27148. try {
  27149. if (listDifferent(context, input, options$$2, "(stdin)")) {
  27150. return;
  27151. }
  27152. writeOutput(context, format$1(context, input, options$$2), options$$2);
  27153. } catch (error) {
  27154. handleError(context, "stdin", error);
  27155. }
  27156. });
  27157. }
  27158. function createIgnorerFromContextOrDie(context) {
  27159. try {
  27160. return createIgnorer_1.sync(context.argv["ignore-path"], context.argv["with-node-modules"]);
  27161. } catch (e) {
  27162. context.logger.error(e.message);
  27163. process.exit(2);
  27164. }
  27165. }
  27166. function eachFilename(context, patterns, callback) {
  27167. var ignoreNodeModules = context.argv["with-node-modules"] !== true;
  27168. if (ignoreNodeModules) {
  27169. patterns = patterns.concat(["!**/node_modules/**", "!./node_modules/**"]);
  27170. }
  27171. try {
  27172. var filePaths = globby.sync(patterns, {
  27173. dot: true,
  27174. nodir: true
  27175. }).map(function (filePath) {
  27176. return path.relative(process.cwd(), filePath);
  27177. });
  27178. if (filePaths.length === 0) {
  27179. context.logger.error(`No matching files. Patterns tried: ${patterns.join(" ")}`);
  27180. process.exitCode = 2;
  27181. return;
  27182. }
  27183. filePaths.forEach(function (filePath) {
  27184. return callback(filePath, Object.assign(getOptionsForFile(context, filePath), {
  27185. filepath: filePath
  27186. }));
  27187. });
  27188. } catch (error) {
  27189. context.logger.error(`Unable to expand glob patterns: ${patterns.join(" ")}\n${error.message}`); // Don't exit the process if one pattern failed
  27190. process.exitCode = 2;
  27191. }
  27192. }
  27193. function formatFiles(context) {
  27194. // The ignorer will be used to filter file paths after the glob is checked,
  27195. // before any files are actually written
  27196. var ignorer = createIgnorerFromContextOrDie(context);
  27197. eachFilename(context, context.filePatterns, function (filename, options$$2) {
  27198. var fileIgnored = ignorer.filter([filename]).length === 0;
  27199. if (fileIgnored && (context.argv["debug-check"] || context.argv["write"] || context.argv["list-different"])) {
  27200. return;
  27201. }
  27202. if (context.argv["write"] && process.stdout.isTTY) {
  27203. // Don't use `console.log` here since we need to replace this line.
  27204. context.logger.log(filename, {
  27205. newline: false
  27206. });
  27207. }
  27208. var input;
  27209. try {
  27210. input = fs.readFileSync(filename, "utf8");
  27211. } catch (error) {
  27212. // Add newline to split errors from filename line.
  27213. context.logger.log("");
  27214. context.logger.error(`Unable to read file: ${filename}\n${error.message}`); // Don't exit the process if one file failed
  27215. process.exitCode = 2;
  27216. return;
  27217. }
  27218. if (fileIgnored) {
  27219. writeOutput(context, {
  27220. formatted: input
  27221. }, options$$2);
  27222. return;
  27223. }
  27224. var start = Date.now();
  27225. var result;
  27226. var output;
  27227. try {
  27228. result = format$1(context, input, Object.assign({}, options$$2, {
  27229. filepath: filename
  27230. }));
  27231. output = result.formatted;
  27232. } catch (error) {
  27233. handleError(context, filename, error);
  27234. return;
  27235. }
  27236. var isDifferent = output !== input;
  27237. if (context.argv["list-different"] && isDifferent) {
  27238. context.logger.log(filename);
  27239. process.exitCode = 1;
  27240. }
  27241. if (context.argv["write"]) {
  27242. if (process.stdout.isTTY) {
  27243. // Remove previously printed filename to log it with duration.
  27244. readline.clearLine(process.stdout, 0);
  27245. readline.cursorTo(process.stdout, 0, null);
  27246. } // Don't write the file if it won't change in order not to invalidate
  27247. // mtime based caches.
  27248. if (isDifferent) {
  27249. if (!context.argv["list-different"]) {
  27250. context.logger.log(`${filename} ${Date.now() - start}ms`);
  27251. }
  27252. try {
  27253. fs.writeFileSync(filename, output, "utf8");
  27254. } catch (error) {
  27255. context.logger.error(`Unable to write file: ${filename}\n${error.message}`); // Don't exit the process if one file failed
  27256. process.exitCode = 2;
  27257. }
  27258. } else if (!context.argv["list-different"]) {
  27259. context.logger.log(`${chalk$2.grey(filename)} ${Date.now() - start}ms`);
  27260. }
  27261. } else if (context.argv["debug-check"]) {
  27262. if (result.filepath) {
  27263. context.logger.log(result.filepath);
  27264. } else {
  27265. process.exitCode = 2;
  27266. }
  27267. } else if (!context.argv["list-different"]) {
  27268. writeOutput(context, result, options$$2);
  27269. }
  27270. });
  27271. }
  27272. function getOptionsWithOpposites(options$$2) {
  27273. // Add --no-foo after --foo.
  27274. var optionsWithOpposites = options$$2.map(function (option) {
  27275. return [option.description ? option : null, option.oppositeDescription ? Object.assign({}, option, {
  27276. name: `no-${option.name}`,
  27277. type: "boolean",
  27278. description: option.oppositeDescription
  27279. }) : null];
  27280. });
  27281. return flattenArray(optionsWithOpposites).filter(Boolean);
  27282. }
  27283. function createUsage(context) {
  27284. var options$$2 = getOptionsWithOpposites(context.detailedOptions).filter( // remove unnecessary option (e.g. `semi`, `color`, etc.), which is only used for --help <flag>
  27285. function (option) {
  27286. return !(option.type === "boolean" && option.oppositeDescription && !option.name.startsWith("no-"));
  27287. });
  27288. var groupedOptions = groupBy(options$$2, function (option) {
  27289. return option.category;
  27290. });
  27291. var firstCategories = constant.categoryOrder.slice(0, -1);
  27292. var lastCategories = constant.categoryOrder.slice(-1);
  27293. var restCategories = Object.keys(groupedOptions).filter(function (category) {
  27294. return firstCategories.indexOf(category) === -1 && lastCategories.indexOf(category) === -1;
  27295. });
  27296. var allCategories = firstCategories.concat(restCategories, lastCategories);
  27297. var optionsUsage = allCategories.map(function (category) {
  27298. var categoryOptions = groupedOptions[category].map(function (option) {
  27299. return createOptionUsage(context, option, OPTION_USAGE_THRESHOLD);
  27300. }).join("\n");
  27301. return `${category} options:\n\n${indent$11(categoryOptions, 2)}`;
  27302. });
  27303. return [constant.usageSummary].concat(optionsUsage, [""]).join("\n\n");
  27304. }
  27305. function createOptionUsage(context, option, threshold) {
  27306. var header = createOptionUsageHeader(option);
  27307. var optionDefaultValue = getOptionDefaultValue(context, option.name);
  27308. return createOptionUsageRow(header, `${option.description}${optionDefaultValue === undefined ? "" : `\nDefaults to ${createDefaultValueDisplay(optionDefaultValue)}.`}`, threshold);
  27309. }
  27310. function createDefaultValueDisplay(value) {
  27311. return Array.isArray(value) ? `[${value.map(createDefaultValueDisplay).join(", ")}]` : value;
  27312. }
  27313. function createOptionUsageHeader(option) {
  27314. var name = `--${option.name}`;
  27315. var alias = option.alias ? `-${option.alias},` : null;
  27316. var type = createOptionUsageType(option);
  27317. return [alias, name, type].filter(Boolean).join(" ");
  27318. }
  27319. function createOptionUsageRow(header, content, threshold) {
  27320. var separator = header.length >= threshold ? `\n${" ".repeat(threshold)}` : " ".repeat(threshold - header.length);
  27321. var description = content.replace(/\n/g, `\n${" ".repeat(threshold)}`);
  27322. return `${header}${separator}${description}`;
  27323. }
  27324. function createOptionUsageType(option) {
  27325. switch (option.type) {
  27326. case "boolean":
  27327. return null;
  27328. case "choice":
  27329. return `<${option.choices.filter(function (choice) {
  27330. return !choice.deprecated;
  27331. }).map(function (choice) {
  27332. return choice.value;
  27333. }).join("|")}>`;
  27334. default:
  27335. return `<${option.type}>`;
  27336. }
  27337. }
  27338. function flattenArray(array) {
  27339. return [].concat.apply([], array);
  27340. }
  27341. function getOptionWithLevenSuggestion(context, options$$2, optionName) {
  27342. // support aliases
  27343. var optionNameContainers = flattenArray(options$$2.map(function (option, index) {
  27344. return [{
  27345. value: option.name,
  27346. index
  27347. }, option.alias ? {
  27348. value: option.alias,
  27349. index
  27350. } : null];
  27351. })).filter(Boolean);
  27352. var optionNameContainer = optionNameContainers.find(function (optionNameContainer) {
  27353. return optionNameContainer.value === optionName;
  27354. });
  27355. if (optionNameContainer !== undefined) {
  27356. return options$$2[optionNameContainer.index];
  27357. }
  27358. var suggestedOptionNameContainer = optionNameContainers.find(function (optionNameContainer) {
  27359. return leven(optionNameContainer.value, optionName) < 3;
  27360. });
  27361. if (suggestedOptionNameContainer !== undefined) {
  27362. var suggestedOptionName = suggestedOptionNameContainer.value;
  27363. context.logger.warn(`Unknown option name "${optionName}", did you mean "${suggestedOptionName}"?`);
  27364. return options$$2[suggestedOptionNameContainer.index];
  27365. }
  27366. context.logger.warn(`Unknown option name "${optionName}"`);
  27367. return options$$2.find(function (option) {
  27368. return option.name === "help";
  27369. });
  27370. }
  27371. function createChoiceUsages(choices, margin, indentation) {
  27372. var activeChoices = choices.filter(function (choice) {
  27373. return !choice.deprecated;
  27374. });
  27375. var threshold = activeChoices.map(function (choice) {
  27376. return choice.value.length;
  27377. }).reduce(function (current, length) {
  27378. return Math.max(current, length);
  27379. }, 0) + margin;
  27380. return activeChoices.map(function (choice) {
  27381. return indent$11(createOptionUsageRow(choice.value, choice.description, threshold), indentation);
  27382. });
  27383. }
  27384. function createDetailedUsage(context, optionName) {
  27385. var option = getOptionWithLevenSuggestion(context, getOptionsWithOpposites(context.detailedOptions), optionName);
  27386. var header = createOptionUsageHeader(option);
  27387. var description = `\n\n${indent$11(option.description, 2)}`;
  27388. var choices = option.type !== "choice" ? "" : `\n\nValid options:\n\n${createChoiceUsages(option.choices, CHOICE_USAGE_MARGIN, CHOICE_USAGE_INDENTATION).join("\n")}`;
  27389. var optionDefaultValue = getOptionDefaultValue(context, option.name);
  27390. var defaults = optionDefaultValue !== undefined ? `\n\nDefault: ${createDefaultValueDisplay(optionDefaultValue)}` : "";
  27391. var pluginDefaults = option.pluginDefaults && Object.keys(option.pluginDefaults).length ? `\nPlugin defaults:${Object.keys(option.pluginDefaults).map(function (key) {
  27392. return `\n* ${key}: ${createDefaultValueDisplay(option.pluginDefaults[key])}`;
  27393. })}` : "";
  27394. return `${header}${description}${choices}${defaults}${pluginDefaults}`;
  27395. }
  27396. function getOptionDefaultValue(context, optionName) {
  27397. // --no-option
  27398. if (!(optionName in context.detailedOptionMap)) {
  27399. return undefined;
  27400. }
  27401. var option = context.detailedOptionMap[optionName];
  27402. if (option.default !== undefined) {
  27403. return option.default;
  27404. }
  27405. var optionCamelName = camelcase(optionName);
  27406. if (optionCamelName in context.apiDefaultOptions) {
  27407. return context.apiDefaultOptions[optionCamelName];
  27408. }
  27409. return undefined;
  27410. }
  27411. function indent$11(str, spaces) {
  27412. return str.replace(/^/gm, " ".repeat(spaces));
  27413. }
  27414. function groupBy(array, getKey) {
  27415. return array.reduce(function (obj, item) {
  27416. var key = getKey(item);
  27417. var previousItems = key in obj ? obj[key] : [];
  27418. return Object.assign({}, obj, {
  27419. [key]: previousItems.concat(item)
  27420. });
  27421. }, Object.create(null));
  27422. }
  27423. function pick(object, keys) {
  27424. return !keys ? object : keys.reduce(function (reduced, key) {
  27425. return Object.assign(reduced, {
  27426. [key]: object[key]
  27427. });
  27428. }, {});
  27429. }
  27430. function createLogger(logLevel) {
  27431. return {
  27432. warn: createLogFunc("warn", "yellow"),
  27433. error: createLogFunc("error", "red"),
  27434. debug: createLogFunc("debug", "blue"),
  27435. log: createLogFunc("log")
  27436. };
  27437. function createLogFunc(loggerName, color) {
  27438. if (!shouldLog(loggerName)) {
  27439. return function () {};
  27440. }
  27441. var prefix = color ? `[${chalk$2[color](loggerName)}] ` : "";
  27442. return function (message, opts) {
  27443. opts = Object.assign({
  27444. newline: true
  27445. }, opts);
  27446. var stream = process[loggerName === "log" ? "stdout" : "stderr"];
  27447. stream.write(message.replace(/^/gm, prefix) + (opts.newline ? "\n" : ""));
  27448. };
  27449. }
  27450. function shouldLog(loggerName) {
  27451. switch (logLevel) {
  27452. case "silent":
  27453. return false;
  27454. default:
  27455. return true;
  27456. case "debug":
  27457. if (loggerName === "debug") {
  27458. return true;
  27459. }
  27460. // fall through
  27461. case "log":
  27462. if (loggerName === "log") {
  27463. return true;
  27464. }
  27465. // fall through
  27466. case "warn":
  27467. if (loggerName === "warn") {
  27468. return true;
  27469. }
  27470. // fall through
  27471. case "error":
  27472. return loggerName === "error";
  27473. }
  27474. }
  27475. }
  27476. function normalizeDetailedOption(name, option) {
  27477. return Object.assign({
  27478. category: coreOptions$1.CATEGORY_OTHER
  27479. }, option, {
  27480. choices: option.choices && option.choices.map(function (choice) {
  27481. var newChoice = Object.assign({
  27482. description: "",
  27483. deprecated: false
  27484. }, typeof choice === "object" ? choice : {
  27485. value: choice
  27486. });
  27487. if (newChoice.value === true) {
  27488. newChoice.value = ""; // backward compability for original boolean option
  27489. }
  27490. return newChoice;
  27491. })
  27492. });
  27493. }
  27494. function normalizeDetailedOptionMap(detailedOptionMap) {
  27495. return Object.keys(detailedOptionMap).sort().reduce(function (normalized, name) {
  27496. var option = detailedOptionMap[name];
  27497. return Object.assign(normalized, {
  27498. [name]: normalizeDetailedOption(name, option)
  27499. });
  27500. }, {});
  27501. }
  27502. function createMinimistOptions(detailedOptions) {
  27503. return {
  27504. boolean: detailedOptions.filter(function (option) {
  27505. return option.type === "boolean";
  27506. }).map(function (option) {
  27507. return option.name;
  27508. }),
  27509. string: detailedOptions.filter(function (option) {
  27510. return option.type !== "boolean";
  27511. }).map(function (option) {
  27512. return option.name;
  27513. }),
  27514. default: detailedOptions.filter(function (option) {
  27515. return !option.deprecated;
  27516. }).filter(function (option) {
  27517. return !option.forwardToApi || option.name === "plugin" || option.name === "plugin-search-dir";
  27518. }).filter(function (option) {
  27519. return option.default !== undefined;
  27520. }).reduce(function (current, option) {
  27521. return Object.assign({
  27522. [option.name]: option.default
  27523. }, current);
  27524. }, {}),
  27525. alias: detailedOptions.filter(function (option) {
  27526. return option.alias !== undefined;
  27527. }).reduce(function (current, option) {
  27528. return Object.assign({
  27529. [option.name]: option.alias
  27530. }, current);
  27531. }, {})
  27532. };
  27533. }
  27534. function createApiDetailedOptionMap(detailedOptions) {
  27535. return detailedOptions.reduce(function (current, option) {
  27536. return option.forwardToApi && option.forwardToApi !== option.name ? Object.assign(current, {
  27537. [option.forwardToApi]: option
  27538. }) : current;
  27539. }, {});
  27540. }
  27541. function createDetailedOptionMap(supportOptions) {
  27542. return supportOptions.reduce(function (reduced, option) {
  27543. var newOption = Object.assign({}, option, {
  27544. name: option.cliName || dashify(option.name),
  27545. description: option.cliDescription || option.description,
  27546. category: option.cliCategory || coreOptions$1.CATEGORY_FORMAT,
  27547. forwardToApi: option.name
  27548. });
  27549. if (option.deprecated) {
  27550. delete newOption.forwardToApi;
  27551. delete newOption.description;
  27552. delete newOption.oppositeDescription;
  27553. newOption.deprecated = true;
  27554. }
  27555. return Object.assign(reduced, {
  27556. [newOption.name]: newOption
  27557. });
  27558. }, {});
  27559. } //-----------------------------context-util-start-------------------------------
  27560. /**
  27561. * @typedef {Object} Context
  27562. * @property logger
  27563. * @property args
  27564. * @property argv
  27565. * @property filePatterns
  27566. * @property supportOptions
  27567. * @property detailedOptions
  27568. * @property detailedOptionMap
  27569. * @property apiDefaultOptions
  27570. */
  27571. function createContext(args) {
  27572. var context = {
  27573. args
  27574. };
  27575. updateContextArgv(context);
  27576. normalizeContextArgv(context, ["loglevel", "plugin", "plugin-search-dir"]);
  27577. context.logger = createLogger(context.argv["loglevel"]);
  27578. updateContextArgv(context, context.argv["plugin"], context.argv["plugin-search-dir"]);
  27579. return context;
  27580. }
  27581. function initContext(context) {
  27582. // split into 2 step so that we could wrap this in a `try..catch` in cli/index.js
  27583. normalizeContextArgv(context);
  27584. }
  27585. function updateContextOptions(context, plugins, pluginSearchDirs) {
  27586. var supportOptions = prettier$2.getSupportInfo(null, {
  27587. showDeprecated: true,
  27588. showUnreleased: true,
  27589. showInternal: true,
  27590. plugins,
  27591. pluginSearchDirs
  27592. }).options;
  27593. var detailedOptionMap = normalizeDetailedOptionMap(Object.assign({}, createDetailedOptionMap(supportOptions), constant.options));
  27594. var detailedOptions = arrayify(detailedOptionMap, "name");
  27595. var apiDefaultOptions = supportOptions.filter(function (optionInfo) {
  27596. return !optionInfo.deprecated;
  27597. }).reduce(function (reduced, optionInfo) {
  27598. return Object.assign(reduced, {
  27599. [optionInfo.name]: optionInfo.default
  27600. });
  27601. }, Object.assign({}, options.hiddenDefaults));
  27602. context.supportOptions = supportOptions;
  27603. context.detailedOptions = detailedOptions;
  27604. context.detailedOptionMap = detailedOptionMap;
  27605. context.apiDefaultOptions = apiDefaultOptions;
  27606. }
  27607. function pushContextPlugins(context, plugins, pluginSearchDirs) {
  27608. context._supportOptions = context.supportOptions;
  27609. context._detailedOptions = context.detailedOptions;
  27610. context._detailedOptionMap = context.detailedOptionMap;
  27611. context._apiDefaultOptions = context.apiDefaultOptions;
  27612. updateContextOptions(context, plugins, pluginSearchDirs);
  27613. }
  27614. function popContextPlugins(context) {
  27615. context.supportOptions = context._supportOptions;
  27616. context.detailedOptions = context._detailedOptions;
  27617. context.detailedOptionMap = context._detailedOptionMap;
  27618. context.apiDefaultOptions = context._apiDefaultOptions;
  27619. }
  27620. function updateContextArgv(context, plugins, pluginSearchDirs) {
  27621. pushContextPlugins(context, plugins, pluginSearchDirs);
  27622. var minimistOptions = createMinimistOptions(context.detailedOptions);
  27623. var argv = minimist_1(context.args, minimistOptions);
  27624. context.argv = argv;
  27625. context.filePatterns = argv["_"];
  27626. }
  27627. function normalizeContextArgv(context, keys) {
  27628. var detailedOptions = !keys ? context.detailedOptions : context.detailedOptions.filter(function (option) {
  27629. return keys.indexOf(option.name) !== -1;
  27630. });
  27631. var argv = !keys ? context.argv : pick(context.argv, keys);
  27632. context.argv = optionsNormalizer.normalizeCliOptions(argv, detailedOptions, {
  27633. logger: context.logger
  27634. });
  27635. } //------------------------------context-util-end--------------------------------
  27636. var util$5 = {
  27637. createContext,
  27638. createDetailedOptionMap,
  27639. createDetailedUsage,
  27640. createUsage,
  27641. format: format$1,
  27642. formatFiles,
  27643. formatStdin,
  27644. initContext,
  27645. logResolvedConfigPathOrDie,
  27646. logFileInfoOrDie,
  27647. normalizeDetailedOptionMap
  27648. };
  27649. function run(args) {
  27650. var context = util$5.createContext(args);
  27651. try {
  27652. util$5.initContext(context);
  27653. context.logger.debug(`normalized argv: ${JSON.stringify(context.argv)}`);
  27654. if (context.argv["write"] && context.argv["debug-check"]) {
  27655. context.logger.error("Cannot use --write and --debug-check together.");
  27656. process.exit(1);
  27657. }
  27658. if (context.argv["find-config-path"] && context.filePatterns.length) {
  27659. context.logger.error("Cannot use --find-config-path with multiple files");
  27660. process.exit(1);
  27661. }
  27662. if (context.argv["file-info"] && context.filePatterns.length) {
  27663. context.logger.error("Cannot use --file-info with multiple files");
  27664. process.exit(1);
  27665. }
  27666. if (context.argv["version"]) {
  27667. context.logger.log(prettier$2.version);
  27668. process.exit(0);
  27669. }
  27670. if (context.argv["help"] !== undefined) {
  27671. context.logger.log(typeof context.argv["help"] === "string" && context.argv["help"] !== "" ? util$5.createDetailedUsage(context, context.argv["help"]) : util$5.createUsage(context));
  27672. process.exit(0);
  27673. }
  27674. if (context.argv["support-info"]) {
  27675. context.logger.log(prettier$2.format(jsonStableStringify(prettier$2.getSupportInfo()), {
  27676. parser: "json"
  27677. }));
  27678. process.exit(0);
  27679. }
  27680. var hasFilePatterns = context.filePatterns.length !== 0;
  27681. var useStdin = context.argv["stdin"] || !hasFilePatterns && !process.stdin.isTTY;
  27682. if (context.argv["find-config-path"]) {
  27683. util$5.logResolvedConfigPathOrDie(context);
  27684. } else if (context.argv["file-info"]) {
  27685. util$5.logFileInfoOrDie(context);
  27686. } else if (useStdin) {
  27687. util$5.formatStdin(context);
  27688. } else if (hasFilePatterns) {
  27689. util$5.formatFiles(context);
  27690. } else {
  27691. context.logger.log(util$5.createUsage(context));
  27692. process.exit(1);
  27693. }
  27694. } catch (error) {
  27695. context.logger.error(error.message);
  27696. process.exit(1);
  27697. }
  27698. }
  27699. var cli = {
  27700. run
  27701. };
  27702. cli.run(process.argv.slice(2));
  27703. var prettier = {};
  27704. module.exports = prettier;